summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/multikeyapplet/multikey.cpp2
-rw-r--r--core/apps/taboapp/main.cpp4
-rw-r--r--core/launcher/inputmethods.cpp6
-rw-r--r--core/launcher/irserver.cpp4
-rw-r--r--core/launcher/startmenu.cpp4
-rw-r--r--core/launcher/systray.cpp4
-rw-r--r--core/multimedia/opieplayer/mediaplayerstate.cpp2
-rw-r--r--core/multimedia/opieplayer/playlistwidget.cpp2
-rw-r--r--core/multimedia/opieplayer/videowidget.cpp2
-rw-r--r--core/opie-login/main.cpp2
-rw-r--r--core/settings/launcher/menusettings.cpp4
-rw-r--r--core/settings/launcher/taskbarsettings.cpp4
-rw-r--r--core/settings/security/multiauthconfig.cpp8
-rw-r--r--core/tools/quicklauncher/dropins.h4
-rw-r--r--inputmethods/multikey/configdlg.cpp4
-rw-r--r--inputmethods/multikey/keyboard.cpp4
-rw-r--r--libopie2/opiecore/opluginloader.cpp4
-rw-r--r--libopie2/opienet/omanufacturerdb.cpp2
-rw-r--r--libopie2/opiesecurity/multiauthcommon.cpp2
-rw-r--r--library/fontdatabase.cpp2
-rw-r--r--library/network.cpp6
-rw-r--r--library/qpedecoration_qws.cpp2
-rw-r--r--libslcompat/slmisc.h2
-rw-r--r--noncore/applets/zkbapplet/applet/zkbwidget.cpp2
-rw-r--r--noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp4
-rw-r--r--noncore/applets/zkbapplet/keyzcfg/main.cpp2
-rw-r--r--noncore/apps/opie-bartender/bartender.cpp2
-rw-r--r--noncore/apps/opie-console/fixit.cpp6
-rw-r--r--noncore/apps/opie-gutenbrowser/LibraryDialog.cpp6
-rw-r--r--noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp2
-rw-r--r--noncore/apps/opie-gutenbrowser/gutenbrowser.cpp4
-rw-r--r--noncore/apps/opie-gutenbrowser/helpme.cpp2
-rw-r--r--noncore/apps/zsafe/zsafe.cpp10
-rw-r--r--noncore/games/backgammon/backgammon.cpp14
-rw-r--r--noncore/games/backgammon/filedialog.cpp2
-rw-r--r--noncore/games/backgammon/themedialog.cpp2
-rw-r--r--noncore/multimedia/opieplayer2/playlistwidget.cpp2
-rw-r--r--noncore/settings/language/language.cpp2
-rw-r--r--noncore/settings/networksettings/mainwindow/mainwindowimp.cpp2
-rw-r--r--noncore/settings/sysinfo/benchmarkinfo.cpp2
-rw-r--r--noncore/settings/tabmanager/tabmanager.cpp4
-rw-r--r--noncore/styles/theme/othemebase.cpp2
-rw-r--r--noncore/styles/theme/themeset.cpp2
-rw-r--r--noncore/tools/calc2/calc.cpp2
-rw-r--r--x11/libqpe-x11/qpe/qpeapplication.cpp4
45 files changed, 80 insertions, 80 deletions
diff --git a/core/applets/multikeyapplet/multikey.cpp b/core/applets/multikeyapplet/multikey.cpp
index 195d8a4..8cb9083 100644
--- a/core/applets/multikeyapplet/multikey.cpp
+++ b/core/applets/multikeyapplet/multikey.cpp
@@ -1,142 +1,142 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2004 Anton Kachalov mouse@altlinux.ru 2** Copyright (C) 2004 Anton Kachalov mouse@altlinux.ru
3** All rights reserved. 3** All rights reserved.
4** 4**
5** This file may be distributed and/or modified under the terms of the 5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software 6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file. 8** packaging of this file.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12** 12**
13**********************************************************************/ 13**********************************************************************/
14 14
15#include "multikey.h" 15#include "multikey.h"
16 16
17/* OPIE */ 17/* OPIE */
18#include <opie2/otaskbarapplet.h> 18#include <opie2/otaskbarapplet.h>
19#include <qpe/qcopenvelope_qws.h> 19#include <qpe/qcopenvelope_qws.h>
20#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21 21
22/* QT */ 22/* QT */
23#include <qdir.h> 23#include <qdir.h>
24 24
25using namespace Opie::Ui; 25using namespace Opie::Ui;
26Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN") 26Multikey::Multikey(QWidget *parent) : QLabel(parent), popupMenu(this), current("EN")
27{ 27{
28 QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this); 28 QCopChannel* swChannel = new QCopChannel("MultiKey/Switcher", this);
29 connect( swChannel, SIGNAL(received(const QCString&,const QByteArray&)), 29 connect( swChannel, SIGNAL(received(const QCString&,const QByteArray&)),
30 this, SLOT(message(const QCString&,const QByteArray&))); 30 this, SLOT(message(const QCString&,const QByteArray&)));
31 31
32 setFont( QFont( "Helvetica", 10, QFont::Normal ) ); 32 setFont( QFont( "Helvetica", 10, QFont::Normal ) );
33 QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold); 33 QPEApplication::setStylusOperation(this, QPEApplication::RightOnHold);
34 lang = 0; 34 lang = 0;
35 QCopEnvelope e("MultiKey/Keyboard", "getmultikey()"); 35 QCopEnvelope e("MultiKey/Keyboard", "getmultikey()");
36 setText("EN"); 36 setText("EN");
37 popupMenu.insertItem("EN", 0); 37 popupMenu.insertItem("EN", 0);
38 show(); 38 show();
39} 39}
40 40
41void Multikey::mousePressEvent(QMouseEvent *ev) 41void Multikey::mousePressEvent(QMouseEvent *ev)
42{ 42{
43 if (!sw_maps.count()) 43 if (!sw_maps.count())
44 return; 44 return;
45 45
46 if (ev->button() == RightButton) { 46 if (ev->button() == RightButton) {
47 47
48 QPoint p = mapToGlobal(QPoint(0, 0)); 48 QPoint p = mapToGlobal(QPoint(0, 0));
49 QSize s = popupMenu.sizeHint(); 49 QSize s = popupMenu.sizeHint();
50 int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2), 50 int opt = popupMenu.exec(QPoint(p.x() + (width() / 2) - (s.width() / 2),
51 p.y() - s.height()), 0); 51 p.y() - s.height()), 0);
52 52
53 if (opt == -1) 53 if (opt == -1)
54 return; 54 return;
55 lang = opt; 55 lang = opt;
56 56
57 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); 57 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)");
58 e << sw_maps[lang]; 58 e << sw_maps[lang];
59 setText(labels[lang]); 59 setText(labels[lang]);
60 } 60 }
61 QWidget::mousePressEvent(ev); 61 QWidget::mousePressEvent(ev);
62} 62}
63 63
64void Multikey::mouseReleaseEvent(QMouseEvent *ev) 64void Multikey::mouseReleaseEvent(QMouseEvent *ev)
65{ 65{
66 if (!sw_maps.count()) 66 if (!sw_maps.count())
67 return; 67 return;
68 68
69 lang = lang < sw_maps.count()-1 ? lang+1 : 0; 69 lang = lang < sw_maps.count()-1 ? lang+1 : 0;
70 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)"); 70 QCopEnvelope e("MultiKey/Keyboard", "setmultikey(QString)");
71 //odebug << "Lang=" << lang << ", count=" << sw_maps.count() << ", lab=" << labels[lang].ascii() << "" << oendl; 71 //odebug << "Lang=" << lang << ", count=" << sw_maps.count() << ", lab=" << labels[lang].ascii() << "" << oendl;
72 e << sw_maps[lang]; 72 e << sw_maps[lang];
73 setText(labels[lang]); 73 setText(labels[lang]);
74} 74}
75 75
76void Multikey::message(const QCString &message, const QByteArray &data) 76void Multikey::message(const QCString &message, const QByteArray &data)
77{ 77{
78 if ( message == "setsw(QString,QString)" ) { 78 if ( message == "setsw(QString,QString)" ) {
79 79
80 QDataStream stream(data, IO_ReadOnly); 80 QDataStream stream(data, IO_ReadOnly);
81 QString maps, current_map; 81 QString maps, current_map;
82 stream >> maps >> current_map; 82 stream >> maps >> current_map;
83 QStringList sw = QStringList::split(QChar('|'), maps); 83 QStringList sw = QStringList::split(QChar('|'), maps);
84 sw.append(current_map); 84 sw.append(current_map);
85 85
86 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey/", "*.keymap"); 86 QDir map_dir(QPEApplication::qpeDir() + "share/multikey/", "*.keymap");
87 lang = 0; 87 lang = 0;
88 labels.clear(); 88 labels.clear();
89 sw_maps.clear(); 89 sw_maps.clear();
90 popupMenu.clear(); 90 popupMenu.clear();
91 91
92 for (uint i = 0; i < sw.count(); ++i) { 92 for (uint i = 0; i < sw.count(); ++i) {
93 QString keymap_map; 93 QString keymap_map;
94 if (sw[i][0] != '/') { 94 if (sw[i][0] != '/') {
95 95
96 keymap_map = map_dir.absPath() + "/" + sw[i]; 96 keymap_map = map_dir.absPath() + "/" + sw[i];
97 } else { 97 } else {
98 98
99 if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false) 99 if ((map_dir.exists(QFileInfo(sw[i]).fileName(), false)
100 && i != sw.count()-1) || !QFile::exists(sw[i])) { 100 && i != sw.count()-1) || !QFile::exists(sw[i])) {
101 continue; 101 continue;
102 } 102 }
103 keymap_map = sw[i]; 103 keymap_map = sw[i];
104 } 104 }
105 105
106 QFile map(keymap_map); 106 QFile map(keymap_map);
107 if (map.open(IO_ReadOnly)) { 107 if (map.open(IO_ReadOnly)) {
108 QString line; 108 QString line;
109 109
110 map.readLine(line, 1024); 110 map.readLine(line, 1024);
111 while (!map.atEnd()) { 111 while (!map.atEnd()) {
112 112
113 if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) { 113 if (line.find(QRegExp("^sw\\s*=\\s*")) != -1) {
114 114
115 if (i != sw.count()-1) { 115 if (i != sw.count()-1) {
116 if (keymap_map == current_map) { 116 if (keymap_map == current_map) {
117 lang = i; 117 lang = i;
118 } 118 }
119 sw_maps.append(keymap_map); 119 sw_maps.append(keymap_map);
120 labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); 120 labels.append(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
121 popupMenu.insertItem(labels[labels.count()-1], labels.count()-1); 121 popupMenu.insertItem(labels[labels.count()-1], labels.count()-1);
122 } else { 122 } else {
123 current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace(); 123 current = line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace();
124 } 124 }
125 break; 125 break;
126 } 126 }
127 map.readLine(line, 1024); 127 map.readLine(line, 1024);
128 } 128 }
129 map.close(); 129 map.close();
130 } 130 }
131 } 131 }
132 132
133 setText(current); 133 setText(current);
134 } 134 }
135} 135}
136 136
137int Multikey::position() 137int Multikey::position()
138{ 138{
139 return 10; 139 return 10;
140} 140}
141 141
142EXPORT_OPIE_APPLET_v1( Multikey ) 142EXPORT_OPIE_APPLET_v1( Multikey )
diff --git a/core/apps/taboapp/main.cpp b/core/apps/taboapp/main.cpp
index e43f118..e999803 100644
--- a/core/apps/taboapp/main.cpp
+++ b/core/apps/taboapp/main.cpp
@@ -1,57 +1,57 @@
1/* OPIE */ 1/* OPIE */
2#include <oappinterface.h> 2#include <oappinterface.h>
3#include <oappplugin.h> 3#include <oappplugin.h>
4#include <opie2/odebug.h> 4#include <opie2/odebug.h>
5#include <opie2/otabwidget.h> 5#include <opie2/otabwidget.h>
6#include <qpe/qpeapplication.h> 6#include <qpe/qpeapplication.h>
7#include <qpe/qlibrary.h> 7#include <qpe/qlibrary.h>
8using namespace Opie::Core; 8using namespace Opie::Core;
9using namespace Opie::Ui; 9using namespace Opie::Ui;
10 10
11/* QT */ 11/* QT */
12#include <qdir.h> 12#include <qdir.h>
13 13
14int main( int argc, char **argv ) 14int main( int argc, char **argv )
15{ 15{
16 QPEApplication a( argc, argv ); 16 QPEApplication a( argc, argv );
17 17
18 OTabWidget *tabwidget = new OTabWidget(0, "tab widget"); 18 OTabWidget *tabwidget = new OTabWidget(0, "tab widget");
19 19
20 QString path = QPEApplication::qpeDir() + "/plugins/app"; 20 QString path = QPEApplication::qpeDir() + "plugins/app";
21 QDir dir( path, "lib*.so" ); 21 QDir dir( path, "lib*.so" );
22 22
23 QStringList list = dir.entryList(); 23 QStringList list = dir.entryList();
24 QStringList::Iterator it; 24 QStringList::Iterator it;
25 25
26 QInterfacePtr<OAppInterface> iface; 26 QInterfacePtr<OAppInterface> iface;
27 for ( it = list.begin(); it != list.end(); ++it ) { 27 for ( it = list.begin(); it != list.end(); ++it ) {
28 QLibrary *lib = new QLibrary( path + "/" + *it ); 28 QLibrary *lib = new QLibrary( path + "/" + *it );
29 29
30 odebug << "querying: " << QString( path + "/" + *it ) << "" << oendl; 30 odebug << "querying: " << QString( path + "/" + *it ) << "" << oendl;
31 if ( lib->queryInterface( IID_OAppInterface, (QUnknownInterface**)&iface ) == QS_OK ) { 31 if ( lib->queryInterface( IID_OAppInterface, (QUnknownInterface**)&iface ) == QS_OK ) {
32 odebug << "accepted: " << QString( path + "/" + *it ) << "" << oendl; 32 odebug << "accepted: " << QString( path + "/" + *it ) << "" << oendl;
33 33
34 QList<QWidget> list = iface->widgets(); 34 QList<QWidget> list = iface->widgets();
35 QWidget *widget; 35 QWidget *widget;
36 for ( widget = list.first(); widget != 0; widget = list.next() ) 36 for ( widget = list.first(); widget != 0; widget = list.next() )
37 tabwidget->addTab(widget, QString(*it), QString(*it)); 37 tabwidget->addTab(widget, QString(*it), QString(*it));
38 38
39 QString lang = getenv( "LANG" ); 39 QString lang = getenv( "LANG" );
40 if (lang.isNull()) 40 if (lang.isNull())
41 lang = "en"; 41 lang = "en";
42 QTranslator *trans = new QTranslator(qApp); 42 QTranslator *trans = new QTranslator(qApp);
43 QString type = (*it).left( (*it).find(".") ); 43 QString type = (*it).left( (*it).find(".") );
44 if (type.left(3) == "lib") 44 if (type.left(3) == "lib")
45 type = type.mid(3); 45 type = type.mid(3);
46 type = type.right( type.find("lib") ); 46 type = type.right( type.find("lib") );
47 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 47 QString tfn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+type+".qm";
48 if ( trans->load( tfn )) 48 if ( trans->load( tfn ))
49 qApp->installTranslator( trans ); 49 qApp->installTranslator( trans );
50 else 50 else
51 delete trans; 51 delete trans;
52 } 52 }
53 } 53 }
54 54
55 a.showMainDocumentWidget(tabwidget); 55 a.showMainDocumentWidget(tabwidget);
56 return a.exec(); 56 return a.exec();
57} 57}
diff --git a/core/launcher/inputmethods.cpp b/core/launcher/inputmethods.cpp
index 586628b..24669ac 100644
--- a/core/launcher/inputmethods.cpp
+++ b/core/launcher/inputmethods.cpp
@@ -1,631 +1,631 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22#include "inputmethods.h" 22#include "inputmethods.h"
23 23
24/* OPIE */ 24/* OPIE */
25#include <opie2/odebug.h> 25#include <opie2/odebug.h>
26#include <qpe/config.h> 26#include <qpe/config.h>
27#include <qpe/global.h> 27#include <qpe/global.h>
28#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
29using namespace Opie::Core; 29using namespace Opie::Core;
30 30
31/* QT */ 31/* QT */
32#include <qpopupmenu.h> 32#include <qpopupmenu.h>
33#include <qtoolbutton.h> 33#include <qtoolbutton.h>
34#include <qwidgetstack.h> 34#include <qwidgetstack.h>
35#include <qlayout.h> 35#include <qlayout.h>
36#include <qdir.h> 36#include <qdir.h>
37#include <qtl.h> 37#include <qtl.h>
38#ifdef Q_WS_QWS 38#ifdef Q_WS_QWS
39#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
40#include <qwsevent_qws.h> 40#include <qwsevent_qws.h>
41#include <qcopchannel_qws.h> 41#include <qcopchannel_qws.h>
42#endif 42#endif
43 43
44/* STD */ 44/* STD */
45#include <stdlib.h> 45#include <stdlib.h>
46 46
47/* XPM */ 47/* XPM */
48static const char * tri_xpm[]={ 48static const char * tri_xpm[]={
49"9 9 2 1", 49"9 9 2 1",
50"a c #000000", 50"a c #000000",
51". c None", 51". c None",
52".........", 52".........",
53".........", 53".........",
54".........", 54".........",
55"....a....", 55"....a....",
56"...aaa...", 56"...aaa...",
57"..aaaaa..", 57"..aaaaa..",
58".aaaaaaa.", 58".aaaaaaa.",
59".........", 59".........",
60"........."}; 60"........."};
61 61
62int InputMethod::operator <(const InputMethod& o) const 62int InputMethod::operator <(const InputMethod& o) const
63{ 63{
64 return name() < o.name(); 64 return name() < o.name();
65} 65}
66int InputMethod::operator >(const InputMethod& o) const 66int InputMethod::operator >(const InputMethod& o) const
67{ 67{
68 return name() > o.name(); 68 return name() > o.name();
69} 69}
70int InputMethod::operator <=(const InputMethod& o) const 70int InputMethod::operator <=(const InputMethod& o) const
71{ 71{
72 return name() <= o.name(); 72 return name() <= o.name();
73} 73}
74 74
75 75
76/* 76/*
77 Slightly hacky: We use WStyle_Tool as a flag to say "this widget 77 Slightly hacky: We use WStyle_Tool as a flag to say "this widget
78 belongs to the IM system, so clicking it should not cause a reset". 78 belongs to the IM system, so clicking it should not cause a reset".
79 */ 79 */
80class IMToolButton : public QToolButton 80class IMToolButton : public QToolButton
81{ 81{
82public: 82public:
83 IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent ) 83 IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent )
84 { setWFlags( WStyle_Tool ); 84 { setWFlags( WStyle_Tool );
85 setBackgroundOrigin( ParentOrigin ); 85 setBackgroundOrigin( ParentOrigin );
86 setBackgroundMode( PaletteBackground ); 86 setBackgroundMode( PaletteBackground );
87 } 87 }
88}; 88};
89 89
90 90
91InputMethods::InputMethods( QWidget *parent ) : 91InputMethods::InputMethods( QWidget *parent ) :
92 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ), 92 QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ),
93 mkeyboard(0), imethod(0) 93 mkeyboard(0), imethod(0)
94{ 94{
95 readConfig(); 95 readConfig();
96 96
97 setBackgroundOrigin( ParentOrigin ); 97 setBackgroundOrigin( ParentOrigin );
98 setBackgroundMode( PaletteBackground ); 98 setBackgroundMode( PaletteBackground );
99 QHBoxLayout *hbox = new QHBoxLayout( this ); 99 QHBoxLayout *hbox = new QHBoxLayout( this );
100 100
101 kbdButton = new IMToolButton( this); 101 kbdButton = new IMToolButton( this);
102 kbdButton->setFocusPolicy(NoFocus); 102 kbdButton->setFocusPolicy(NoFocus);
103 kbdButton->setToggleButton( TRUE ); 103 kbdButton->setToggleButton( TRUE );
104 if (parent->sizeHint().height() > 0) 104 if (parent->sizeHint().height() > 0)
105 kbdButton->setFixedHeight( parent->sizeHint().height() ); 105 kbdButton->setFixedHeight( parent->sizeHint().height() );
106 kbdButton->setFixedWidth( 32 ); 106 kbdButton->setFixedWidth( 32 );
107 kbdButton->setAutoRaise( TRUE ); 107 kbdButton->setAutoRaise( TRUE );
108 kbdButton->setUsesBigPixmap( TRUE ); 108 kbdButton->setUsesBigPixmap( TRUE );
109 hbox->addWidget( kbdButton ); 109 hbox->addWidget( kbdButton );
110 connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) ); 110 connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) );
111 111
112 kbdChoice = new IMToolButton( this ); 112 kbdChoice = new IMToolButton( this );
113 kbdChoice->setFocusPolicy(NoFocus); 113 kbdChoice->setFocusPolicy(NoFocus);
114 kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); 114 kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) );
115 if (parent->sizeHint().height() > 0) 115 if (parent->sizeHint().height() > 0)
116 kbdChoice->setFixedHeight( parent->sizeHint().height() ); 116 kbdChoice->setFixedHeight( parent->sizeHint().height() );
117 kbdChoice->setFixedWidth( 13 ); 117 kbdChoice->setFixedWidth( 13 );
118 kbdChoice->setAutoRaise( TRUE ); 118 kbdChoice->setAutoRaise( TRUE );
119 hbox->addWidget( kbdChoice ); 119 hbox->addWidget( kbdChoice );
120 connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) ); 120 connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) );
121 121
122 connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), 122 connect( (QPEApplication*)qApp, SIGNAL(clientMoused()),
123 this, SLOT(resetStates()) ); 123 this, SLOT(resetStates()) );
124 124
125 125
126 imButton = new QWidgetStack( this ); // later a widget stack 126 imButton = new QWidgetStack( this ); // later a widget stack
127 imButton->setFocusPolicy(NoFocus); 127 imButton->setFocusPolicy(NoFocus);
128 if (parent->sizeHint().height() > 0) 128 if (parent->sizeHint().height() > 0)
129 imButton->setFixedHeight( parent->sizeHint().height() ); 129 imButton->setFixedHeight( parent->sizeHint().height() );
130 hbox->addWidget(imButton); 130 hbox->addWidget(imButton);
131 131
132 imChoice = new QToolButton( this ); 132 imChoice = new QToolButton( this );
133 imChoice->setFocusPolicy(NoFocus); 133 imChoice->setFocusPolicy(NoFocus);
134 imChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); 134 imChoice->setPixmap( QPixmap( (const char **)tri_xpm ) );
135 if (parent->sizeHint().height() > 0) 135 if (parent->sizeHint().height() > 0)
136 imChoice->setFixedHeight( parent->sizeHint().height() ); 136 imChoice->setFixedHeight( parent->sizeHint().height() );
137 imChoice->setFixedWidth( 13 ); 137 imChoice->setFixedWidth( 13 );
138 imChoice->setAutoRaise( TRUE ); 138 imChoice->setAutoRaise( TRUE );
139 hbox->addWidget( imChoice ); 139 hbox->addWidget( imChoice );
140 connect( imChoice, SIGNAL(clicked()), this, SLOT(chooseIm()) ); 140 connect( imChoice, SIGNAL(clicked()), this, SLOT(chooseIm()) );
141 141
142 loadInputMethods(); 142 loadInputMethods();
143 143
144 QCopChannel *channel = new QCopChannel( "QPE/IME", this ); 144 QCopChannel *channel = new QCopChannel( "QPE/IME", this );
145 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 145 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
146 this, SLOT(qcopReceive(const QCString&,const QByteArray&)) ); 146 this, SLOT(qcopReceive(const QCString&,const QByteArray&)) );
147} 147}
148 148
149InputMethods::~InputMethods() 149InputMethods::~InputMethods()
150{ 150{
151 Config cfg("qpe"); 151 Config cfg("qpe");
152 cfg.setGroup("InputMethod"); 152 cfg.setGroup("InputMethod");
153 if (imethod) 153 if (imethod)
154 cfg.writeEntry("im", imethod->name() ); 154 cfg.writeEntry("im", imethod->name() );
155 if (mkeyboard) 155 if (mkeyboard)
156 cfg.writeEntry("current", mkeyboard->name() ); 156 cfg.writeEntry("current", mkeyboard->name() );
157 157
158 unloadInputMethods(); 158 unloadInputMethods();
159} 159}
160 160
161void InputMethods::hideInputMethod() 161void InputMethods::hideInputMethod()
162{ 162{
163 kbdButton->setOn( FALSE ); 163 kbdButton->setOn( FALSE );
164} 164}
165 165
166void InputMethods::showInputMethod() 166void InputMethods::showInputMethod()
167{ 167{
168 kbdButton->setOn( TRUE ); 168 kbdButton->setOn( TRUE );
169} 169}
170 170
171void InputMethods::showInputMethod(const QString& name) 171void InputMethods::showInputMethod(const QString& name)
172{ 172{
173 int i = 0; 173 int i = 0;
174 QValueList<InputMethod>::Iterator it; 174 QValueList<InputMethod>::Iterator it;
175 InputMethod *im = 0; 175 InputMethod *im = 0;
176 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 176 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
177 QString lname = (*it).libName.mid((*it).libName.findRev('/') + 1); 177 QString lname = (*it).libName.mid((*it).libName.findRev('/') + 1);
178 if ( (*it).name() == name || lname == name ) { 178 if ( (*it).name() == name || lname == name ) {
179 im = &(*it); 179 im = &(*it);
180 break; 180 break;
181 } 181 }
182 } 182 }
183 if ( im ) 183 if ( im )
184 chooseKeyboard(im); 184 chooseKeyboard(im);
185} 185}
186 186
187void InputMethods::resetStates() 187void InputMethods::resetStates()
188{ 188{
189 if ( mkeyboard && !mkeyboard->newIM ) 189 if ( mkeyboard && !mkeyboard->newIM )
190 mkeyboard->interface->resetState(); 190 mkeyboard->interface->resetState();
191} 191}
192 192
193QRect InputMethods::inputRect() const 193QRect InputMethods::inputRect() const
194{ 194{
195 if ( !mkeyboard || !mkeyboard->widget || !mkeyboard->widget->isVisible() ) 195 if ( !mkeyboard || !mkeyboard->widget || !mkeyboard->widget->isVisible() )
196 return QRect(); 196 return QRect();
197 else 197 else
198 return mkeyboard->widget->geometry(); 198 return mkeyboard->widget->geometry();
199} 199}
200 200
201void InputMethods::unloadInputMethods() 201void InputMethods::unloadInputMethods()
202{ 202{
203 unloadMethod( inputMethodList ); 203 unloadMethod( inputMethodList );
204 unloadMethod( inputModifierList ); 204 unloadMethod( inputModifierList );
205 inputMethodList.clear(); 205 inputMethodList.clear();
206 inputModifierList.clear(); 206 inputModifierList.clear();
207 207
208} 208}
209 209
210void InputMethods::unloadMethod( QValueList<InputMethod>& list ) { 210void InputMethods::unloadMethod( QValueList<InputMethod>& list ) {
211 QValueList<InputMethod>::Iterator it; 211 QValueList<InputMethod>::Iterator it;
212 212
213 for (it = list.begin(); it != list.end(); ++it ) 213 for (it = list.begin(); it != list.end(); ++it )
214 (*it).releaseInterface(); 214 (*it).releaseInterface();
215 215
216} 216}
217 217
218 218
219QStringList InputMethods::plugins()const { 219QStringList InputMethods::plugins()const {
220 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; 220 QString path = QPEApplication::qpeDir() + "plugins/inputmethods";
221#ifdef Q_OS_MACX 221#ifdef Q_OS_MACX
222 QDir dir( path, "lib*.dylib" ); 222 QDir dir( path, "lib*.dylib" );
223#else 223#else
224 QDir dir( path, "lib*.so" ); 224 QDir dir( path, "lib*.so" );
225#endif /* Q_OS_MACX */ 225#endif /* Q_OS_MACX */
226 return dir.entryList(); 226 return dir.entryList();
227} 227}
228 228
229void InputMethods::installTranslator( const QString& type ) { 229void InputMethods::installTranslator( const QString& type ) {
230 QStringList langs = Global::languageList(); 230 QStringList langs = Global::languageList();
231 QStringList::ConstIterator lit; 231 QStringList::ConstIterator lit;
232 for ( lit= langs.begin(); lit!=langs.end(); ++lit) { 232 for ( lit= langs.begin(); lit!=langs.end(); ++lit) {
233 QString lang = *lit; 233 QString lang = *lit;
234 QTranslator * trans = new QTranslator(qApp); 234 QTranslator * trans = new QTranslator(qApp);
235 235
236 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 236 QString tfn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+type+".qm";
237 237
238 if ( trans->load( tfn )) 238 if ( trans->load( tfn ))
239 qApp->installTranslator( trans ); 239 qApp->installTranslator( trans );
240 else 240 else
241 delete trans; 241 delete trans;
242 } 242 }
243} 243}
244 244
245void InputMethods::setPreferedHandlers() { 245void InputMethods::setPreferedHandlers() {
246 Config cfg("qpe"); 246 Config cfg("qpe");
247 cfg.setGroup("InputMethod"); 247 cfg.setGroup("InputMethod");
248 QString current = cfg.readEntry("current"); 248 QString current = cfg.readEntry("current");
249 QString im = cfg.readEntry("im"); 249 QString im = cfg.readEntry("im");
250 250
251 QValueList<InputMethod>::Iterator it; 251 QValueList<InputMethod>::Iterator it;
252 if (!inputModifierList.isEmpty() && !im.isEmpty() ) { 252 if (!inputModifierList.isEmpty() && !im.isEmpty() ) {
253 for (it = inputModifierList.begin(); it != inputModifierList.end(); ++it ) 253 for (it = inputModifierList.begin(); it != inputModifierList.end(); ++it )
254 if ( (*it).name() == im ) { 254 if ( (*it).name() == im ) {
255 imethod = &(*it); break; 255 imethod = &(*it); break;
256 } 256 }
257 257
258 } 258 }
259 if (!inputMethodList.isEmpty() && !current.isEmpty() ) { 259 if (!inputMethodList.isEmpty() && !current.isEmpty() ) {
260 for (it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) 260 for (it = inputMethodList.begin(); it != inputMethodList.end(); ++it )
261 if ( (*it).name() == current ) { 261 if ( (*it).name() == current ) {
262 owarn << "preferred keyboard is " << current << "" << oendl; 262 owarn << "preferred keyboard is " << current << "" << oendl;
263 mkeyboard = &(*it); 263 mkeyboard = &(*it);
264 kbdButton->setPixmap( *mkeyboard->icon() ); 264 kbdButton->setPixmap( *mkeyboard->icon() );
265 break; 265 break;
266 } 266 }
267 } 267 }
268 268
269} 269}
270 270
271void InputMethods::loadInputMethods() 271void InputMethods::loadInputMethods()
272{ 272{
273#ifndef QT_NO_COMPONENT 273#ifndef QT_NO_COMPONENT
274 hideInputMethod(); 274 hideInputMethod();
275 mkeyboard = 0; 275 mkeyboard = 0;
276 276
277 unloadInputMethods(); 277 unloadInputMethods();
278 278
279 QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; 279 QString path = QPEApplication::qpeDir() + "plugins/inputmethods";
280 QStringList list = plugins(); 280 QStringList list = plugins();
281 QStringList::Iterator it; 281 QStringList::Iterator it;
282 for ( it = list.begin(); it != list.end(); ++it ) { 282 for ( it = list.begin(); it != list.end(); ++it ) {
283 InputMethodInterface *iface = 0; 283 InputMethodInterface *iface = 0;
284 ExtInputMethodInterface *eface = 0; 284 ExtInputMethodInterface *eface = 0;
285 QLibrary *lib = new QLibrary( path + "/" + *it ); 285 QLibrary *lib = new QLibrary( path + "/" + *it );
286 286
287 if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) { 287 if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) {
288 InputMethod input; 288 InputMethod input;
289 input.newIM = FALSE; 289 input.newIM = FALSE;
290 input.library = lib; 290 input.library = lib;
291 input.libName = *it; 291 input.libName = *it;
292 input.interface = iface; 292 input.interface = iface;
293 input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); 293 input.widget = input.interface->inputMethod( 0, inputWidgetStyle );
294 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); 294 input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) );
295 inputMethodList.append( input ); 295 inputMethodList.append( input );
296 } else if ( lib->queryInterface( IID_ExtInputMethod, (QUnknownInterface**)&eface ) == QS_OK ) { 296 } else if ( lib->queryInterface( IID_ExtInputMethod, (QUnknownInterface**)&eface ) == QS_OK ) {
297 InputMethod input; 297 InputMethod input;
298 input.newIM = TRUE; 298 input.newIM = TRUE;
299 input.library = lib; 299 input.library = lib;
300 input.libName = *it; 300 input.libName = *it;
301 input.extInterface = eface; 301 input.extInterface = eface;
302 input.widget = input.extInterface->keyboardWidget( 0, inputWidgetStyle ); 302 input.widget = input.extInterface->keyboardWidget( 0, inputWidgetStyle );
303 // may be either a simple, or advanced. 303 // may be either a simple, or advanced.
304 if (input.widget) { 304 if (input.widget) {
305 //odebug << "its a keyboard" << oendl; 305 //odebug << "its a keyboard" << oendl;
306 inputMethodList.append( input ); 306 inputMethodList.append( input );
307 } else { 307 } else {
308 //odebug << "its a real im" << oendl; 308 //odebug << "its a real im" << oendl;
309 input.widget = input.extInterface->statusWidget( 0, 0 ); 309 input.widget = input.extInterface->statusWidget( 0, 0 );
310 if (input.widget) { 310 if (input.widget) {
311 //odebug << "blah" << oendl; 311 //odebug << "blah" << oendl;
312 inputModifierList.append( input ); 312 inputModifierList.append( input );
313 imButton->addWidget(input.widget, inputModifierList.count()); 313 imButton->addWidget(input.widget, inputModifierList.count());
314 } 314 }
315 } 315 }
316 }else{ 316 }else{
317 delete lib; 317 delete lib;
318 lib = 0l; 318 lib = 0l;
319 } 319 }
320 installTranslator( (*it).left( (*it).find(".") ) ); 320 installTranslator( (*it).left( (*it).find(".") ) );
321 } 321 }
322 qHeapSort( inputMethodList ); 322 qHeapSort( inputMethodList );
323#endif /* killed BUILT in cause they would not compile */ 323#endif /* killed BUILT in cause they would not compile */
324 324
325 QWSServer::setCurrentInputMethod( 0 ); 325 QWSServer::setCurrentInputMethod( 0 );
326 326
327 /* set the prefered IM + handler */ 327 /* set the prefered IM + handler */
328 setPreferedHandlers(); 328 setPreferedHandlers();
329 if ( !inputModifierList.isEmpty() ) { 329 if ( !inputModifierList.isEmpty() ) {
330 if (!imethod) 330 if (!imethod)
331 imethod = &inputModifierList[0]; 331 imethod = &inputModifierList[0];
332 imButton->raiseWidget(imethod->widget); 332 imButton->raiseWidget(imethod->widget);
333 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); 333 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() );
334 } else { 334 } else {
335 imethod = 0; 335 imethod = 0;
336 } 336 }
337 337
338 // we need to update keyboards afterwards, as some of them may not be compatible with 338 // we need to update keyboards afterwards, as some of them may not be compatible with
339 // the current input method 339 // the current input method
340 updateKeyboards(imethod); 340 updateKeyboards(imethod);
341 341
342 if ( !inputModifierList.isEmpty() ) 342 if ( !inputModifierList.isEmpty() )
343 imButton->show(); 343 imButton->show();
344 else 344 else
345 imButton->hide(); 345 imButton->hide();
346 346
347 if ( inputModifierList.count() > 1 ) 347 if ( inputModifierList.count() > 1 )
348 imChoice->show(); 348 imChoice->show();
349 else 349 else
350 imChoice->hide(); 350 imChoice->hide();
351} 351}
352 352
353void InputMethods::chooseKbd() 353void InputMethods::chooseKbd()
354{ 354{
355 QPopupMenu pop( this ); 355 QPopupMenu pop( this );
356 pop.setFocusPolicy( NoFocus ); //don't reset IM 356 pop.setFocusPolicy( NoFocus ); //don't reset IM
357 357
358 QString imname; 358 QString imname;
359 if (imethod) 359 if (imethod)
360 imname = imethod->libName.mid(imethod->libName.findRev('/') + 1); 360 imname = imethod->libName.mid(imethod->libName.findRev('/') + 1);
361 361
362 int i = 0; 362 int i = 0;
363 int firstDepKbd = 0; 363 int firstDepKbd = 0;
364 364
365 QValueList<InputMethod>::Iterator it; 365 QValueList<InputMethod>::Iterator it;
366 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { 366 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) {
367 // add empty new items, all old items. 367 // add empty new items, all old items.
368 if (!(*it).newIM || (*it).extInterface->compatible().count() == 0 ) { 368 if (!(*it).newIM || (*it).extInterface->compatible().count() == 0 ) {
369 pop.insertItem( (*it).name(), i, firstDepKbd); 369 pop.insertItem( (*it).name(), i, firstDepKbd);
370 if ( mkeyboard == &(*it) ) 370 if ( mkeyboard == &(*it) )
371 pop.setItemChecked( i, TRUE ); 371 pop.setItemChecked( i, TRUE );
372 372
373 firstDepKbd++; 373 firstDepKbd++;
374 } else if ( (*it).extInterface->compatible().contains(imname)) { 374 } else if ( (*it).extInterface->compatible().contains(imname)) {
375 // check if we need to insert a sep. 375 // check if we need to insert a sep.
376 if (firstDepKbd == i) 376 if (firstDepKbd == i)
377 pop.insertSeparator(); 377 pop.insertSeparator();
378 pop.insertItem( (*it).name(), i, -1); 378 pop.insertItem( (*it).name(), i, -1);
379 if ( mkeyboard == &(*it) ) 379 if ( mkeyboard == &(*it) )
380 pop.setItemChecked( i, TRUE ); 380 pop.setItemChecked( i, TRUE );
381 } 381 }
382 } 382 }
383 383
384 QPoint pt = mapToGlobal(kbdChoice->geometry().topRight()); 384 QPoint pt = mapToGlobal(kbdChoice->geometry().topRight());
385 QSize s = pop.sizeHint(); 385 QSize s = pop.sizeHint();
386 pt.ry() -= s.height(); 386 pt.ry() -= s.height();
387 pt.rx() -= s.width(); 387 pt.rx() -= s.width();
388 i = pop.exec( pt ); 388 i = pop.exec( pt );
389 if ( i == -1 ) 389 if ( i == -1 )
390 return; 390 return;
391 InputMethod *im = &inputMethodList[i]; 391 InputMethod *im = &inputMethodList[i];
392 chooseKeyboard(im); 392 chooseKeyboard(im);
393} 393}
394 394
395void InputMethods::chooseIm() 395void InputMethods::chooseIm()
396{ 396{
397 QPopupMenu pop( this ); 397 QPopupMenu pop( this );
398 398
399 int i = 0; 399 int i = 0;
400 QValueList<InputMethod>::Iterator it; 400 QValueList<InputMethod>::Iterator it;
401 for ( it = inputModifierList.begin(); it != inputModifierList.end(); ++it, i++ ) { 401 for ( it = inputModifierList.begin(); it != inputModifierList.end(); ++it, i++ ) {
402 pop.insertItem( (*it).name(), i ); 402 pop.insertItem( (*it).name(), i );
403 if ( imethod == &(*it) ) 403 if ( imethod == &(*it) )
404 pop.setItemChecked( i, TRUE ); 404 pop.setItemChecked( i, TRUE );
405 } 405 }
406 406
407 QPoint pt = mapToGlobal(imChoice->geometry().topRight()); 407 QPoint pt = mapToGlobal(imChoice->geometry().topRight());
408 QSize s = pop.sizeHint(); 408 QSize s = pop.sizeHint();
409 pt.ry() -= s.height(); 409 pt.ry() -= s.height();
410 pt.rx() -= s.width(); 410 pt.rx() -= s.width();
411 i = pop.exec( pt ); 411 i = pop.exec( pt );
412 if ( i == -1 ) 412 if ( i == -1 )
413 return; 413 return;
414 InputMethod *im = &inputModifierList[i]; 414 InputMethod *im = &inputModifierList[i];
415 415
416 chooseMethod(im); 416 chooseMethod(im);
417} 417}
418 418
419void InputMethods::chooseKeyboard(InputMethod* im) 419void InputMethods::chooseKeyboard(InputMethod* im)
420{ 420{
421 if ( im != mkeyboard ) { 421 if ( im != mkeyboard ) {
422 if ( mkeyboard && mkeyboard->widget->isVisible() ) 422 if ( mkeyboard && mkeyboard->widget->isVisible() )
423 mkeyboard->widget->hide(); 423 mkeyboard->widget->hide();
424 mkeyboard = im; 424 mkeyboard = im;
425 kbdButton->setPixmap( *mkeyboard->icon() ); 425 kbdButton->setPixmap( *mkeyboard->icon() );
426 } 426 }
427 if ( !kbdButton->isOn() ) 427 if ( !kbdButton->isOn() )
428 kbdButton->setOn( TRUE ); 428 kbdButton->setOn( TRUE );
429 else 429 else
430 showKbd( TRUE ); 430 showKbd( TRUE );
431} 431}
432 432
433static bool keyboardCompatible(InputMethod *keyb, const QString &imname ) 433static bool keyboardCompatible(InputMethod *keyb, const QString &imname )
434{ 434{
435 if ( !keyb || !keyb->newIM || !keyb->extInterface->compatible().count() ) 435 if ( !keyb || !keyb->newIM || !keyb->extInterface->compatible().count() )
436 return TRUE; 436 return TRUE;
437 437
438 if ( keyb->extInterface->compatible().contains(imname) ) 438 if ( keyb->extInterface->compatible().contains(imname) )
439 return TRUE; 439 return TRUE;
440 440
441 return FALSE; 441 return FALSE;
442} 442}
443 443
444// Updates the display of the soft keyboards available to the current input method 444// Updates the display of the soft keyboards available to the current input method
445void InputMethods::updateKeyboards(InputMethod *im ) 445void InputMethods::updateKeyboards(InputMethod *im )
446{ 446{
447 uint count; 447 uint count;
448 448
449 if ( im ) { 449 if ( im ) {
450 QString imname = im->libName.mid(im->libName.findRev('/') + 1); 450 QString imname = im->libName.mid(im->libName.findRev('/') + 1);
451 451
452 if ( mkeyboard && !keyboardCompatible(mkeyboard, imname) ) { 452 if ( mkeyboard && !keyboardCompatible(mkeyboard, imname) ) {
453 kbdButton->setOn( FALSE ); 453 kbdButton->setOn( FALSE );
454 showKbd( FALSE ); 454 showKbd( FALSE );
455 mkeyboard = 0; 455 mkeyboard = 0;
456 } 456 }
457 457
458 count = 0; 458 count = 0;
459 459
460 QValueList<InputMethod>::Iterator it; 460 QValueList<InputMethod>::Iterator it;
461 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) { 461 for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) {
462 if ( keyboardCompatible( &(*it), imname ) ) { 462 if ( keyboardCompatible( &(*it), imname ) ) {
463 if ( !mkeyboard ) { 463 if ( !mkeyboard ) {
464 mkeyboard = &(*it); 464 mkeyboard = &(*it);
465 kbdButton->setPixmap( *mkeyboard->icon() ); 465 kbdButton->setPixmap( *mkeyboard->icon() );
466 } 466 }
467 467
468 count++; 468 count++;
469 } 469 }
470 } 470 }
471 } else { 471 } else {
472 count = inputMethodList.count(); 472 count = inputMethodList.count();
473 if ( count && !mkeyboard ) { 473 if ( count && !mkeyboard ) {
474 mkeyboard = &inputMethodList[0]; 474 mkeyboard = &inputMethodList[0];
475 kbdButton->setPixmap( *mkeyboard->icon() ); 475 kbdButton->setPixmap( *mkeyboard->icon() );
476 } else if (!count){ 476 } else if (!count){
477 mkeyboard = 0; //might be redundant 477 mkeyboard = 0; //might be redundant
478 } 478 }
479 } 479 }
480 480
481 if ( count > 1 ) 481 if ( count > 1 )
482 kbdChoice->show(); 482 kbdChoice->show();
483 else 483 else
484 kbdChoice->hide(); 484 kbdChoice->hide();
485 485
486 if ( count ) 486 if ( count )
487 kbdButton->show(); 487 kbdButton->show();
488 else 488 else
489 kbdButton->hide(); 489 kbdButton->hide();
490} 490}
491 491
492void InputMethods::chooseMethod(InputMethod* im) 492void InputMethods::chooseMethod(InputMethod* im)
493{ 493{
494 if ( im != imethod ) { 494 if ( im != imethod ) {
495 updateKeyboards( im ); 495 updateKeyboards( im );
496 496
497 Config cfg("qpe"); 497 Config cfg("qpe");
498 cfg.setGroup("InputMethod"); 498 cfg.setGroup("InputMethod");
499 if (im ) 499 if (im )
500 cfg.writeEntry("im", im->name() ); 500 cfg.writeEntry("im", im->name() );
501 if (mkeyboard) 501 if (mkeyboard)
502 cfg.writeEntry("current", mkeyboard->name() ); 502 cfg.writeEntry("current", mkeyboard->name() );
503 503
504 QWSServer::setCurrentInputMethod( 0 ); 504 QWSServer::setCurrentInputMethod( 0 );
505 imethod = im; 505 imethod = im;
506 if ( imethod && imethod->newIM ) 506 if ( imethod && imethod->newIM )
507 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); 507 QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() );
508 else 508 else
509 QWSServer::setCurrentInputMethod( 0 ); 509 QWSServer::setCurrentInputMethod( 0 );
510 510
511 if ( im ) 511 if ( im )
512 imButton->raiseWidget(im->widget); 512 imButton->raiseWidget(im->widget);
513 else 513 else
514 imButton->hide(); //### good UI? make sure it is shown again! 514 imButton->hide(); //### good UI? make sure it is shown again!
515 } 515 }
516} 516}
517 517
518void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data ) 518void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data )
519{ 519{
520 if ( imethod && imethod->newIM ) 520 if ( imethod && imethod->newIM )
521 imethod->extInterface->qcopReceive( msg, data ); 521 imethod->extInterface->qcopReceive( msg, data );
522} 522}
523 523
524 524
525void InputMethods::showKbd( bool on ) 525void InputMethods::showKbd( bool on )
526{ 526{
527 if ( !mkeyboard ) 527 if ( !mkeyboard )
528 return; 528 return;
529 529
530 if ( on ) 530 if ( on )
531 { 531 {
532 mkeyboard->resetState(); 532 mkeyboard->resetState();
533 533
534 int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 ); 534 int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 );
535 int width = static_cast<int>( qApp->desktop()->width() * (inputWidgetWidth*0.01) ); 535 int width = static_cast<int>( qApp->desktop()->width() * (inputWidgetWidth*0.01) );
536 int left = 0; 536 int left = 0;
537 int top = mapToGlobal( QPoint() ).y() - height; 537 int top = mapToGlobal( QPoint() ).y() - height;
538 538
539 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) 539 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder )
540 { 540 {
541 odebug << "InputMethods: reading geometry." << oendl; 541 odebug << "InputMethods: reading geometry." << oendl;
542 Config cfg( "Launcher" ); 542 Config cfg( "Launcher" );
543 cfg.setGroup( "InputMethods" ); 543 cfg.setGroup( "InputMethods" );
544 int l = cfg.readNumEntry( "absX", -1 ); 544 int l = cfg.readNumEntry( "absX", -1 );
545 int t = cfg.readNumEntry( "absY", -1 ); 545 int t = cfg.readNumEntry( "absY", -1 );
546 int w = cfg.readNumEntry( "absWidth", -1 ); 546 int w = cfg.readNumEntry( "absWidth", -1 );
547 int h = cfg.readNumEntry( "absHeight", -1 ); 547 int h = cfg.readNumEntry( "absHeight", -1 );
548 548
549 if ( l > -1 && t > -1 && w > -1 && h > -1 ) 549 if ( l > -1 && t > -1 && w > -1 && h > -1 )
550 { 550 {
551 odebug << "InputMethods: config values ( " << l << ", " << t << ", " << w << ", " << h << " ) are ok." << oendl; 551 odebug << "InputMethods: config values ( " << l << ", " << t << ", " << w << ", " << h << " ) are ok." << oendl;
552 left = l; 552 left = l;
553 top = t; 553 top = t;
554 width = w; 554 width = w;
555 height = h; 555 height = h;
556 } 556 }
557 else 557 else
558 { 558 {
559 odebug << "InputMethods: config values are new or not ok." << oendl; 559 odebug << "InputMethods: config values are new or not ok." << oendl;
560 } 560 }
561 } 561 }
562 else 562 else
563 { 563 {
564 odebug << "InputMethods: no floating selected." << oendl; 564 odebug << "InputMethods: no floating selected." << oendl;
565 } 565 }
566 mkeyboard->widget->resize( width, height ); 566 mkeyboard->widget->resize( width, height );
567 mkeyboard->widget->move( left, top ); 567 mkeyboard->widget->move( left, top );
568 mkeyboard->widget->show(); 568 mkeyboard->widget->show();
569 mkeyboard->widget->installEventFilter( this ); 569 mkeyboard->widget->installEventFilter( this );
570 } 570 }
571 else 571 else
572 { 572 {
573 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) 573 if ( inputWidgetStyle & QWidget::WStyle_DialogBorder )
574 { 574 {
575 QPoint pos = mkeyboard->widget->pos(); 575 QPoint pos = mkeyboard->widget->pos();
576 QSize siz = mkeyboard->widget->size(); 576 QSize siz = mkeyboard->widget->size();
577 odebug << "InputMethods: saving geometry." << oendl; 577 odebug << "InputMethods: saving geometry." << oendl;
578 Config cfg( "Launcher" ); 578 Config cfg( "Launcher" );
579 cfg.setGroup( "InputMethods" ); 579 cfg.setGroup( "InputMethods" );
580 cfg.writeEntry( "absX", pos.x() ); 580 cfg.writeEntry( "absX", pos.x() );
581 cfg.writeEntry( "absY", pos.y() ); 581 cfg.writeEntry( "absY", pos.y() );
582 cfg.writeEntry( "absWidth", siz.width() ); 582 cfg.writeEntry( "absWidth", siz.width() );
583 cfg.writeEntry( "absHeight", siz.height() ); 583 cfg.writeEntry( "absHeight", siz.height() );
584 cfg.write(); 584 cfg.write();
585 mkeyboard->widget->removeEventFilter( this ); 585 mkeyboard->widget->removeEventFilter( this );
586 } 586 }
587 mkeyboard->widget->hide(); 587 mkeyboard->widget->hide();
588 } 588 }
589 589
590 emit inputToggled( on ); 590 emit inputToggled( on );
591} 591}
592 592
593bool InputMethods::shown() const 593bool InputMethods::shown() const
594{ 594{
595 return mkeyboard && mkeyboard->widget->isVisible(); 595 return mkeyboard && mkeyboard->widget->isVisible();
596} 596}
597 597
598QString InputMethods::currentShown() const 598QString InputMethods::currentShown() const
599{ 599{
600 return mkeyboard && mkeyboard->widget->isVisible() 600 return mkeyboard && mkeyboard->widget->isVisible()
601 ? mkeyboard->name() : QString::null; 601 ? mkeyboard->name() : QString::null;
602} 602}
603 603
604void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) 604void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat )
605{ 605{
606#if defined(Q_WS_QWS) 606#if defined(Q_WS_QWS)
607 QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat ); 607 QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat );
608#endif 608#endif
609} 609}
610 610
611bool InputMethods::eventFilter( QObject* , QEvent* e ) 611bool InputMethods::eventFilter( QObject* , QEvent* e )
612{ 612{
613 if ( e->type() == QEvent::Close ) 613 if ( e->type() == QEvent::Close )
614 { 614 {
615 ( (QCloseEvent*) e )->ignore(); 615 ( (QCloseEvent*) e )->ignore();
616 showKbd( false ); 616 showKbd( false );
617 kbdButton->setOn( false ); 617 kbdButton->setOn( false );
618 return true; 618 return true;
619 } 619 }
620 return false; 620 return false;
621} 621}
622 622
623void InputMethods::readConfig() { 623void InputMethods::readConfig() {
624 Config cfg( "Launcher" ); 624 Config cfg( "Launcher" );
625 cfg.setGroup( "InputMethods" ); 625 cfg.setGroup( "InputMethods" );
626 626
627 inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool; 627 inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool;
628 inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? 628 inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ?
629 QWidget::WStyle_DialogBorder : 0; 629 QWidget::WStyle_DialogBorder : 0;
630 inputWidgetWidth = cfg.readNumEntry( "Width", 100 ); 630 inputWidgetWidth = cfg.readNumEntry( "Width", 100 );
631} 631}
diff --git a/core/launcher/irserver.cpp b/core/launcher/irserver.cpp
index 092eb0c..19cf904 100644
--- a/core/launcher/irserver.cpp
+++ b/core/launcher/irserver.cpp
@@ -1,76 +1,76 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "irserver.h" 21#include "irserver.h"
22#include "obexinterface.h" 22#include "obexinterface.h"
23 23
24/* OPIE */ 24/* OPIE */
25#include <opie2/odebug.h> 25#include <opie2/odebug.h>
26#include <qtopia/qlibrary.h> 26#include <qtopia/qlibrary.h>
27#include <qtopia/qpeapplication.h> 27#include <qtopia/qpeapplication.h>
28 28
29/* QT */ 29/* QT */
30#include <qdir.h> 30#include <qdir.h>
31 31
32IrServer::IrServer( QObject *parent, const char *name ) 32IrServer::IrServer( QObject *parent, const char *name )
33 : QObject( parent, name ), obexIface(0) 33 : QObject( parent, name ), obexIface(0)
34{ 34{
35 lib = 0; 35 lib = 0;
36 obexIface = 0; 36 obexIface = 0;
37 QString path = QPEApplication::qpeDir() + "/plugins/obex/"; 37 QString path = QPEApplication::qpeDir() + "plugins/obex/";
38#ifdef Q_OS_MACX 38#ifdef Q_OS_MACX
39 QDir dir( path, "lib*.dylib" ); 39 QDir dir( path, "lib*.dylib" );
40#else 40#else
41 QDir dir( path, "lib*.so" ); 41 QDir dir( path, "lib*.so" );
42#endif /* Q_OS_MACX */ 42#endif /* Q_OS_MACX */
43 QStringList list = dir.entryList(); 43 QStringList list = dir.entryList();
44 QStringList::Iterator it; 44 QStringList::Iterator it;
45 for ( it = list.begin(); it != list.end(); ++it ) { 45 for ( it = list.begin(); it != list.end(); ++it ) {
46 QLibrary *trylib = new QLibrary( path + *it ); 46 QLibrary *trylib = new QLibrary( path + *it );
47 //odebug << "trying lib " << (path + (*it)) << "" << oendl; 47 //odebug << "trying lib " << (path + (*it)) << "" << oendl;
48 if ( trylib->queryInterface( IID_ObexInterface, (QUnknownInterface**)&obexIface ) == QS_OK ) { 48 if ( trylib->queryInterface( IID_ObexInterface, (QUnknownInterface**)&obexIface ) == QS_OK ) {
49 lib = trylib; 49 lib = trylib;
50 //odebug << "found obex lib" << oendl; 50 //odebug << "found obex lib" << oendl;
51 QString lang = getenv( "LANG" ); 51 QString lang = getenv( "LANG" );
52 QTranslator * trans = new QTranslator(qApp); 52 QTranslator * trans = new QTranslator(qApp);
53 QString type = (*it).left( (*it).find(".") ); 53 QString type = (*it).left( (*it).find(".") );
54 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 54 QString tfn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+type+".qm";
55 //odebug << "tr fpr obex: " << tfn << "" << oendl; 55 //odebug << "tr fpr obex: " << tfn << "" << oendl;
56 if ( trans->load( tfn )) 56 if ( trans->load( tfn ))
57 qApp->installTranslator( trans ); 57 qApp->installTranslator( trans );
58 else 58 else
59 delete trans; 59 delete trans;
60 60
61 break; 61 break;
62 } else { 62 } else {
63 delete lib; 63 delete lib;
64 } 64 }
65 } 65 }
66 if ( !lib ) 66 if ( !lib )
67 odebug << "could not load IR plugin" << oendl; 67 odebug << "could not load IR plugin" << oendl;
68} 68}
69 69
70IrServer::~IrServer() 70IrServer::~IrServer()
71{ 71{
72 if ( obexIface ) 72 if ( obexIface )
73 obexIface->release(); 73 obexIface->release();
74 delete lib; 74 delete lib;
75} 75}
76 76
diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp
index f3a7651..66f665f 100644
--- a/core/launcher/startmenu.cpp
+++ b/core/launcher/startmenu.cpp
@@ -1,390 +1,390 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21// TODO. During startup 21// TODO. During startup
22// Launcher::typeAdded 22// Launcher::typeAdded
23// is called for each new tab and calls then each time the refresh of startmenu 23// is called for each new tab and calls then each time the refresh of startmenu
24// suboptimal 24// suboptimal
25 25
26#define INCLUDE_MENUITEM_DEF 26#define INCLUDE_MENUITEM_DEF
27 27
28#include "startmenu.h" 28#include "startmenu.h"
29 29
30#include <qtopia/qpeapplication.h> 30#include <qtopia/qpeapplication.h>
31#include <qtopia/config.h> 31#include <qtopia/config.h>
32#include <qtopia/resource.h> 32#include <qtopia/resource.h>
33#include <qtopia/mimetype.h> 33#include <qtopia/mimetype.h>
34#include <qtopia/qlibrary.h> 34#include <qtopia/qlibrary.h>
35 35
36//#include <qpainter.h> 36//#include <qpainter.h>
37 37
38//#include <stdlib.h> 38//#include <stdlib.h>
39 39
40 40
41#define APPLNK_ID_OFFSET 250 41#define APPLNK_ID_OFFSET 250
42#define NO_ID -1 42#define NO_ID -1
43 43
44 44
45void StartPopupMenu::keyPressEvent( QKeyEvent *e ) 45void StartPopupMenu::keyPressEvent( QKeyEvent *e )
46{ 46{
47 if ( e->key() == Key_F33 || e->key() == Key_Space ) { 47 if ( e->key() == Key_F33 || e->key() == Key_Space ) {
48 // "OK" button, little hacky 48 // "OK" button, little hacky
49 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0); 49 QKeyEvent ke(QEvent::KeyPress, Key_Enter, 13, 0);
50 QPopupMenu::keyPressEvent( &ke ); 50 QPopupMenu::keyPressEvent( &ke );
51 } else { 51 } else {
52 QPopupMenu::keyPressEvent( e ); 52 QPopupMenu::keyPressEvent( e );
53 } 53 }
54} 54}
55 55
56//--------------------------------------------------------------------------- 56//---------------------------------------------------------------------------
57 57
58StartMenu::StartMenu(QWidget *parent) : QLabel( parent ) 58StartMenu::StartMenu(QWidget *parent) : QLabel( parent )
59{ 59{
60 startButtonPixmap = "go"; // No tr 60 startButtonPixmap = "go"; // No tr
61 61
62 int sz = AppLnk::smallIconSize()+3; 62 int sz = AppLnk::smallIconSize()+3;
63 QPixmap pm; 63 QPixmap pm;
64 pm.convertFromImage(Resource::loadImage( startButtonPixmap).smoothScale( sz,sz) ); 64 pm.convertFromImage(Resource::loadImage( startButtonPixmap).smoothScale( sz,sz) );
65 setPixmap(pm); 65 setPixmap(pm);
66 setFocusPolicy( NoFocus ); 66 setFocusPolicy( NoFocus );
67 67
68 useWidePopupMenu = true; 68 useWidePopupMenu = true;
69 launchMenu = 0; 69 launchMenu = 0;
70 refreshMenu(); 70 refreshMenu();
71} 71}
72 72
73 73
74void StartMenu::mousePressEvent( QMouseEvent * ) 74void StartMenu::mousePressEvent( QMouseEvent * )
75{ 75{
76 launch(); 76 launch();
77} 77}
78 78
79 79
80StartMenu::~StartMenu() 80StartMenu::~StartMenu()
81{ 81{
82 clearApplets(); 82 clearApplets();
83} 83}
84 84
85void StartMenu::createMenu() 85void StartMenu::createMenu()
86{ 86{
87 clearApplets(); 87 clearApplets();
88 delete launchMenu; 88 delete launchMenu;
89 89
90 launchMenu = new StartPopupMenu( this ); 90 launchMenu = new StartPopupMenu( this );
91 loadMenu( launchMenu ); 91 loadMenu( launchMenu );
92 loadApplets(); 92 loadApplets();
93 93
94 bool result = currentItem || menuApplets.count(); 94 bool result = currentItem || menuApplets.count();
95 if ( result ) 95 if ( result )
96 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 96 connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
97} 97}
98 98
99void StartMenu::refreshMenu() 99void StartMenu::refreshMenu()
100{ 100{
101 Config cfg( "StartMenu" ); 101 Config cfg( "StartMenu" );
102 cfg.setGroup( "Menu" ); 102 cfg.setGroup( "Menu" );
103 bool ltabs = cfg.readBoolEntry( "LauncherTabs", TRUE ); 103 bool ltabs = cfg.readBoolEntry( "LauncherTabs", TRUE );
104 bool lot = cfg.readBoolEntry( "LauncherOther", TRUE ); 104 bool lot = cfg.readBoolEntry( "LauncherOther", TRUE );
105 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE ); 105 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
106 106
107 if ( launchMenu && !(ltabs || lot) ) return; // nothing to do 107 if ( launchMenu && !(ltabs || lot) ) return; // nothing to do
108 108
109 createMenu(); 109 createMenu();
110} 110}
111 111
112void StartMenu::itemSelected( int id ) 112void StartMenu::itemSelected( int id )
113{ 113{
114 if ( id == NO_ID ) return; 114 if ( id == NO_ID ) return;
115 115
116 if ( id < 0 ) { 116 if ( id < 0 ) {
117 MenuApplet *applet = menuApplets.find( id ); 117 MenuApplet *applet = menuApplets.find( id );
118 if ( applet ) { 118 if ( applet ) {
119 applet->iface->activated(); 119 applet->iface->activated();
120 } 120 }
121 } else if ( id >= APPLNK_ID_OFFSET ) { 121 } else if ( id >= APPLNK_ID_OFFSET ) {
122 AppLnk * appLnk = appLnks.find( id ); 122 AppLnk * appLnk = appLnks.find( id );
123 if ( appLnk ) { 123 if ( appLnk ) {
124 appLnk->execute(); 124 appLnk->execute();
125 } 125 }
126 } else { 126 } else {
127 QString *tabName = tabNames.find( id ); 127 QString *tabName = tabNames.find( id );
128 if ( tabName ) { 128 if ( tabName ) {
129 emit tabSelected( *tabName ); 129 emit tabSelected( *tabName );
130 } 130 }
131 } 131 }
132} 132}
133 133
134void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file ) 134void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file )
135{ 135{
136 if ( file.right(8) == ".desktop" ) { 136 if ( file.right(8) == ".desktop" ) {
137 AppLnk* applnk = new AppLnk( dir.path() + "/" + file ); 137 AppLnk* applnk = new AppLnk( dir.path() + "/" + file );
138 if ( !applnk->isValid() ) { 138 if ( !applnk->isValid() ) {
139 delete applnk; 139 delete applnk;
140 return; 140 return;
141 } 141 }
142 142
143 if ( applnk->type() == "Separator" ) { // No tr 143 if ( applnk->type() == "Separator" ) { // No tr
144 menu->insertSeparator(); 144 menu->insertSeparator();
145 delete applnk; 145 delete applnk;
146 } else { 146 } else {
147 QPixmap test; 147 QPixmap test;
148 QImage img = Resource::loadImage( applnk->icon() ); 148 QImage img = Resource::loadImage( applnk->icon() );
149 if(!img.isNull() ) 149 if(!img.isNull() )
150 test.convertFromImage( 150 test.convertFromImage(
151 img.smoothScale( 151 img.smoothScale(
152 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 ); 152 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
153 153
154 menu->insertItem( test, applnk->name(), 154 menu->insertItem( test, applnk->name(),
155 currentItem + APPLNK_ID_OFFSET ); 155 currentItem + APPLNK_ID_OFFSET );
156 appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk ); 156 appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk );
157 currentItem++; 157 currentItem++;
158 } 158 }
159 } 159 }
160 160
161} 161}
162 162
163void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot ) 163void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot )
164{ 164{
165 // do some sanity checks and collect information 165 // do some sanity checks and collect information
166 166
167 if ( file == "." || file == ".." ) return; 167 if ( file == "." || file == ".." ) return;
168 168
169 Config cfg( dir.path() + "/" + file + "/.directory", Config::File ); 169 Config cfg( dir.path() + "/" + file + "/.directory", Config::File );
170 if ( !cfg.isValid() ) return; 170 if ( !cfg.isValid() ) return;
171 171
172 QString name = cfg.readEntry( "Name" ); 172 QString name = cfg.readEntry( "Name" );
173 QString icon = cfg.readEntry( "Icon" ); 173 QString icon = cfg.readEntry( "Icon" );
174 if ( !name || !icon ) return; 174 if ( !name || !icon ) return;
175 175
176 QDir subdir = QDir( dir ); 176 QDir subdir = QDir( dir );
177 subdir.cd( file ); 177 subdir.cd( file );
178 subdir.setFilter( QDir::Files ); 178 subdir.setFilter( QDir::Files );
179 subdir.setNameFilter( "*.desktop" ); 179 subdir.setNameFilter( "*.desktop" );
180 // we don' t show the menu if there are no entries 180 // we don' t show the menu if there are no entries
181 // perhaps one should check if there exist subsubdirs with entries... 181 // perhaps one should check if there exist subsubdirs with entries...
182 if ( subdir.entryList().isEmpty() ) return; 182 if ( subdir.entryList().isEmpty() ) return;
183 183
184 // checks were ok 184 // checks were ok
185 185
186 QPixmap test; 186 QPixmap test;
187 test.convertFromImage( Resource::loadImage( icon ).smoothScale( 187 test.convertFromImage( Resource::loadImage( icon ).smoothScale(
188 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 ); 188 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
189 189
190 if ( useWidePopupMenu ) { 190 if ( useWidePopupMenu ) {
191 // generate submenu 191 // generate submenu
192 QPopupMenu *submenu = new QPopupMenu( menu ); 192 QPopupMenu *submenu = new QPopupMenu( menu );
193 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 193 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
194 menu->insertItem( test, name, submenu, NO_ID ); 194 menu->insertItem( test, name, submenu, NO_ID );
195 195
196 // ltabs is true cause else we wouldn't stuck around.. 196 // ltabs is true cause else we wouldn't stuck around..
197 createMenuEntries( submenu, subdir, true, lot ); 197 createMenuEntries( submenu, subdir, true, lot );
198 } else { 198 } else {
199 // no submenus - just bring corresponding tab to front 199 // no submenus - just bring corresponding tab to front
200 menu->insertItem( test, name, currentItem ); 200 menu->insertItem( test, name, currentItem );
201 tabNames.insert( currentItem, new QString( file ) ); 201 tabNames.insert( currentItem, new QString( file ) );
202 currentItem++; 202 currentItem++;
203 } 203 }
204} 204}
205 205
206void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot ) 206void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot )
207{ 207{
208 if ( lot ) { 208 if ( lot ) {
209 dir.setFilter( QDir::Files ); 209 dir.setFilter( QDir::Files );
210 dir.setNameFilter( "*.desktop" ); 210 dir.setNameFilter( "*.desktop" );
211 QStringList files = dir.entryList(); 211 QStringList files = dir.entryList();
212 files.sort(); 212 files.sort();
213 213
214 for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) { 214 for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) {
215 createAppEntry( menu, dir, *it ); 215 createAppEntry( menu, dir, *it );
216 } 216 }
217 } 217 }
218 if ( ltabs ) { 218 if ( ltabs ) {
219 dir.setNameFilter( "*" ); 219 dir.setNameFilter( "*" );
220 dir.setFilter( QDir::Dirs ); 220 dir.setFilter( QDir::Dirs );
221 QStringList dirs = dir.entryList(); 221 QStringList dirs = dir.entryList();
222 dirs.sort(); 222 dirs.sort();
223 223
224 for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) { 224 for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) {
225 createDirEntry( menu, dir, *it, lot ); 225 createDirEntry( menu, dir, *it, lot );
226 } 226 }
227 } 227 }
228} 228}
229 229
230bool StartMenu::loadMenu( QPopupMenu *menu ) 230bool StartMenu::loadMenu( QPopupMenu *menu )
231{ 231{
232 Config cfg("StartMenu"); 232 Config cfg("StartMenu");
233 cfg.setGroup("Menu"); 233 cfg.setGroup("Menu");
234 234
235 bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE); 235 bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE);
236 bool lot = cfg.readBoolEntry("LauncherOther", TRUE); 236 bool lot = cfg.readBoolEntry("LauncherOther", TRUE);
237 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE ); 237 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
238 bool sepfirst = !ltabs && !lot; 238 bool sepfirst = !ltabs && !lot;
239 239
240 currentItem = 0; 240 currentItem = 0;
241 launchMenu->clear(); 241 launchMenu->clear();
242 242
243 appLnks.setAutoDelete( true ); 243 appLnks.setAutoDelete( true );
244 tabNames.setAutoDelete( true ); 244 tabNames.setAutoDelete( true );
245 appLnks.clear(); 245 appLnks.clear();
246 tabNames.clear(); 246 tabNames.clear();
247 appLnks.setAutoDelete( false ); 247 appLnks.setAutoDelete( false );
248 tabNames.setAutoDelete( false ); 248 tabNames.setAutoDelete( false );
249 249
250 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name ); 250 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name );
251 createMenuEntries( menu, dir, ltabs, lot ); 251 createMenuEntries( menu, dir, ltabs, lot );
252 252
253 if ( !menu->count() ) sepfirst = TRUE; 253 if ( !menu->count() ) sepfirst = TRUE;
254 254
255 launchMenu->setName( sepfirst ? "accessories" : "accessories_need_sep" ); // No tr 255 launchMenu->setName( sepfirst ? "accessories" : "accessories_need_sep" ); // No tr
256 256
257 return currentItem; 257 return currentItem;
258} 258}
259 259
260 260
261void StartMenu::launch() 261void StartMenu::launch()
262{ 262{
263 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height(); 263 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height();
264 264
265 if ( launchMenu->isVisible() ) 265 if ( launchMenu->isVisible() )
266 launchMenu->hide(); 266 launchMenu->hide();
267 else 267 else
268 launchMenu->popup( QPoint( 1, y ) ); 268 launchMenu->popup( QPoint( 1, y ) );
269} 269}
270 270
271 271
272 272
273 273
274static int compareAppletPositions(const void *b, const void *a) 274static int compareAppletPositions(const void *b, const void *a)
275{ 275{
276 const MenuApplet* aa = *(const MenuApplet**)a; 276 const MenuApplet* aa = *(const MenuApplet**)a;
277 const MenuApplet* ab = *(const MenuApplet**)b; 277 const MenuApplet* ab = *(const MenuApplet**)b;
278 int d = aa->iface->position() - ab->iface->position(); 278 int d = aa->iface->position() - ab->iface->position();
279 if ( d ) return d; 279 if ( d ) return d;
280 return QString::compare(aa->library->library(),ab->library->library()); 280 return QString::compare(aa->library->library(),ab->library->library());
281} 281}
282 282
283void StartMenu::clearApplets() 283void StartMenu::clearApplets()
284{ 284{
285 if ( launchMenu ) 285 if ( launchMenu )
286 launchMenu-> hide(); 286 launchMenu-> hide();
287 287
288 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) { 288 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
289 MenuApplet *applet = it.current(); 289 MenuApplet *applet = it.current();
290 if ( launchMenu ) { 290 if ( launchMenu ) {
291 launchMenu->removeItem( applet-> id ); 291 launchMenu->removeItem( applet-> id );
292 delete applet->popup; 292 delete applet->popup;
293 } 293 }
294 294
295 applet->iface->release(); 295 applet->iface->release();
296 applet->library->unload(); 296 applet->library->unload();
297 delete applet-> library; 297 delete applet-> library;
298 } 298 }
299 menuApplets.clear(); 299 menuApplets.clear();
300} 300}
301 301
302 302
303 303
304 304
305void StartMenu::loadApplets() 305void StartMenu::loadApplets()
306{ 306{
307 Config cfg( "StartMenu" ); 307 Config cfg( "StartMenu" );
308 cfg.setGroup( "Applets" ); 308 cfg.setGroup( "Applets" );
309 309
310 // SafeMode causes too much problems, so we disable it for now -- 310 // SafeMode causes too much problems, so we disable it for now --
311 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02 311 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02
312 // removed in the remerge PluginManager could handle it 312 // removed in the remerge PluginManager could handle it
313 // we don't currently use it -zecke 313 // we don't currently use it -zecke
314 314
315 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); 315 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' );
316 316
317 QString lang = getenv( "LANG" ); 317 QString lang = getenv( "LANG" );
318 QString path = QPEApplication::qpeDir() + "/plugins/applets"; 318 QString path = QPEApplication::qpeDir() + "plugins/applets";
319 QDir dir( path, "lib*.so" ); 319 QDir dir( path, "lib*.so" );
320 QStringList list = dir.entryList(); 320 QStringList list = dir.entryList();
321 QStringList::Iterator it; 321 QStringList::Iterator it;
322 int napplets = 0; 322 int napplets = 0;
323 MenuApplet* *xapplets = new MenuApplet*[list.count()]; 323 MenuApplet* *xapplets = new MenuApplet*[list.count()];
324 for ( it = list.begin(); it != list.end(); ++it ) { 324 for ( it = list.begin(); it != list.end(); ++it ) {
325 if ( exclude.find( *it ) != exclude.end() ) 325 if ( exclude.find( *it ) != exclude.end() )
326 continue; 326 continue;
327 MenuAppletInterface *iface = 0; 327 MenuAppletInterface *iface = 0;
328 QLibrary *lib = new QLibrary( path + "/" + *it ); 328 QLibrary *lib = new QLibrary( path + "/" + *it );
329 if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { 329 if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) {
330 MenuApplet *applet = new MenuApplet; 330 MenuApplet *applet = new MenuApplet;
331 xapplets[napplets++] = applet; 331 xapplets[napplets++] = applet;
332 applet->library = lib; 332 applet->library = lib;
333 applet->iface = iface; 333 applet->iface = iface;
334 334
335 QTranslator *trans = new QTranslator(qApp); 335 QTranslator *trans = new QTranslator(qApp);
336 QString type = (*it).left( (*it).find(".") ); 336 QString type = (*it).left( (*it).find(".") );
337 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 337 QString tfn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+type+".qm";
338 if ( trans->load( tfn )) 338 if ( trans->load( tfn ))
339 qApp->installTranslator( trans ); 339 qApp->installTranslator( trans );
340 else 340 else
341 delete trans; 341 delete trans;
342 } else { 342 } else {
343 exclude += *it; 343 exclude += *it;
344 delete lib; 344 delete lib;
345 } 345 }
346 } 346 }
347 cfg.writeEntry( "ExcludeApplets", exclude, ',' ); 347 cfg.writeEntry( "ExcludeApplets", exclude, ',' );
348 qsort(xapplets, napplets, sizeof(menuApplets[0]), compareAppletPositions); 348 qsort(xapplets, napplets, sizeof(menuApplets[0]), compareAppletPositions);
349 349
350 350
351 while ( napplets-- ) { 351 while ( napplets-- ) {
352 MenuApplet *applet = xapplets[napplets]; 352 MenuApplet *applet = xapplets[napplets];
353 applet->popup = applet->iface->popup( this ); 353 applet->popup = applet->iface->popup( this );
354 354
355 // menuApplets got an id < -1 355 // menuApplets got an id < -1
356 menuApplets.insert( -( currentItem + 2 ), new MenuApplet( *applet ) ); 356 menuApplets.insert( -( currentItem + 2 ), new MenuApplet( *applet ) );
357 currentItem++; 357 currentItem++;
358 } 358 }
359 delete [] xapplets; 359 delete [] xapplets;
360 360
361 addApplets( launchMenu ); 361 addApplets( launchMenu );
362} 362}
363 363
364 364
365/* 365/*
366 * Launcher calls loadMenu too often fix that 366 * Launcher calls loadMenu too often fix that
367 */ 367 */
368void StartMenu::addApplets(QPopupMenu* pop) { 368void StartMenu::addApplets(QPopupMenu* pop) {
369 QIntDict<MenuApplet> dict; 369 QIntDict<MenuApplet> dict;
370 if( pop-> count ( )) 370 if( pop-> count ( ))
371 pop-> insertSeparator ( ); 371 pop-> insertSeparator ( );
372 372
373 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) { 373 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
374 MenuApplet *applet = it.current(); 374 MenuApplet *applet = it.current();
375 if ( applet->popup ) 375 if ( applet->popup )
376 applet->id = pop->insertItem( applet->iface->icon(), 376 applet->id = pop->insertItem( applet->iface->icon(),
377 applet->iface->text(), applet->popup ); 377 applet->iface->text(), applet->popup );
378 else 378 else
379 applet->id = pop->insertItem( applet->iface->icon(), 379 applet->id = pop->insertItem( applet->iface->icon(),
380 applet->iface->text() ); 380 applet->iface->text() );
381 381
382 382
383 dict.insert( applet->id, new MenuApplet( *applet ) ); 383 dict.insert( applet->id, new MenuApplet( *applet ) );
384 } 384 }
385 /* need to update the key */ 385 /* need to update the key */
386 menuApplets.setAutoDelete( true ); 386 menuApplets.setAutoDelete( true );
387 menuApplets.clear(); 387 menuApplets.clear();
388 menuApplets.setAutoDelete( false ); 388 menuApplets.setAutoDelete( false );
389 menuApplets = dict; 389 menuApplets = dict;
390} 390}
diff --git a/core/launcher/systray.cpp b/core/launcher/systray.cpp
index 3c72d25..d0f1808 100644
--- a/core/launcher/systray.cpp
+++ b/core/launcher/systray.cpp
@@ -1,150 +1,150 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "systray.h" 21#include "systray.h"
22 22
23/* OPIE */ 23/* OPIE */
24#include <opie2/odebug.h> 24#include <opie2/odebug.h>
25#include <qtopia/qpeapplication.h> 25#include <qtopia/qpeapplication.h>
26#include <qtopia/qlibrary.h> 26#include <qtopia/qlibrary.h>
27#include <qtopia/config.h> 27#include <qtopia/config.h>
28using namespace Opie::Core; 28using namespace Opie::Core;
29 29
30/* QT */ 30/* QT */
31#include <qlayout.h> 31#include <qlayout.h>
32#include <qdir.h> 32#include <qdir.h>
33 33
34/* STD */ 34/* STD */
35#include <stdlib.h> 35#include <stdlib.h>
36 36
37SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0) 37SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0)
38{ 38{
39 //setFrameStyle( QFrame::Panel | QFrame::Sunken ); 39 //setFrameStyle( QFrame::Panel | QFrame::Sunken );
40 loadApplets(); 40 loadApplets();
41} 41}
42 42
43SysTray::~SysTray() 43SysTray::~SysTray()
44{ 44{
45 clearApplets(); 45 clearApplets();
46} 46}
47 47
48static int compareAppletPositions(const void *a, const void *b) 48static int compareAppletPositions(const void *a, const void *b)
49{ 49{
50 const TaskbarApplet* aa = *(const TaskbarApplet**)a; 50 const TaskbarApplet* aa = *(const TaskbarApplet**)a;
51 const TaskbarApplet* ab = *(const TaskbarApplet**)b; 51 const TaskbarApplet* ab = *(const TaskbarApplet**)b;
52 int d = ab->iface->position() - aa->iface->position(); 52 int d = ab->iface->position() - aa->iface->position();
53 if ( d ) return d; 53 if ( d ) return d;
54 return QString::compare(ab->name,aa->name); 54 return QString::compare(ab->name,aa->name);
55} 55}
56 56
57void SysTray::loadApplets() 57void SysTray::loadApplets()
58{ 58{
59 hide(); 59 hide();
60 clearApplets(); 60 clearApplets();
61 addApplets(); 61 addApplets();
62} 62}
63 63
64void SysTray::clearApplets() 64void SysTray::clearApplets()
65{ 65{
66#ifndef QT_NO_COMPONENTS 66#ifndef QT_NO_COMPONENTS
67 67
68 /* 68 /*
69 * Note on clearing. SOme applets delete their 69 * Note on clearing. SOme applets delete their
70 * applets themselves some don't do it 70 * applets themselves some don't do it
71 * and on restart this can crash. If we delete it 71 * and on restart this can crash. If we delete it
72 * here we might end up in a double deletion. We could 72 * here we might end up in a double deletion. We could
73 * use QGuardedPtr but that would be one QOBject 73 * use QGuardedPtr but that would be one QOBject
74 * for every applet more but only useful for restart 74 * for every applet more but only useful for restart
75 */ 75 */
76 QValueList<TaskbarApplet>::Iterator mit; 76 QValueList<TaskbarApplet>::Iterator mit;
77 for ( mit = appletList.begin(); mit != appletList.end(); ++mit ) { 77 for ( mit = appletList.begin(); mit != appletList.end(); ++mit ) {
78 (*mit).iface->release(); 78 (*mit).iface->release();
79 (*mit).library->unload(); 79 (*mit).library->unload();
80 delete (*mit).library; 80 delete (*mit).library;
81 } 81 }
82 82
83#endif 83#endif
84 appletList.clear(); 84 appletList.clear();
85 if ( layout ) 85 if ( layout )
86 delete layout; 86 delete layout;
87 layout = new QHBoxLayout( this, 0, 1 ); 87 layout = new QHBoxLayout( this, 0, 1 );
88 layout->setAutoAdd(TRUE); 88 layout->setAutoAdd(TRUE);
89} 89}
90 90
91void SysTray::addApplets() 91void SysTray::addApplets()
92{ 92{
93 hide(); 93 hide();
94#ifndef QT_NO_COMPONENTS 94#ifndef QT_NO_COMPONENTS
95 Config cfg( "Taskbar" ); 95 Config cfg( "Taskbar" );
96 cfg.setGroup( "Applets" ); 96 cfg.setGroup( "Applets" );
97 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); 97 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' );
98 98
99 QString lang = getenv( "LANG" ); 99 QString lang = getenv( "LANG" );
100 QString path = QPEApplication::qpeDir() + "/plugins/applets"; 100 QString path = QPEApplication::qpeDir() + "plugins/applets";
101#ifdef Q_OS_MACX 101#ifdef Q_OS_MACX
102 QDir dir( path, "lib*.dylib" ); 102 QDir dir( path, "lib*.dylib" );
103#else 103#else
104 QDir dir( path, "lib*.so" ); 104 QDir dir( path, "lib*.so" );
105#endif /* Q_OS_MACX */ 105#endif /* Q_OS_MACX */
106 QStringList list = dir.entryList(); 106 QStringList list = dir.entryList();
107 QStringList::Iterator it; 107 QStringList::Iterator it;
108 int napplets=0; 108 int napplets=0;
109 TaskbarApplet* *applets = new TaskbarApplet*[list.count()]; 109 TaskbarApplet* *applets = new TaskbarApplet*[list.count()];
110 for ( it = list.begin(); it != list.end(); ++it ) { 110 for ( it = list.begin(); it != list.end(); ++it ) {
111 if ( exclude.find( *it ) != exclude.end() ) 111 if ( exclude.find( *it ) != exclude.end() )
112 continue; 112 continue;
113 owarn << "Found Applet: " << (*it) << "" << oendl; 113 owarn << "Found Applet: " << (*it) << "" << oendl;
114 TaskbarAppletInterface *iface = 0; 114 TaskbarAppletInterface *iface = 0;
115 QLibrary *lib = new QLibrary( path + "/" + *it ); 115 QLibrary *lib = new QLibrary( path + "/" + *it );
116 if (( lib->queryInterface( IID_TaskbarApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { 116 if (( lib->queryInterface( IID_TaskbarApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) {
117 TaskbarApplet *applet = new TaskbarApplet; 117 TaskbarApplet *applet = new TaskbarApplet;
118 applets[napplets++] = applet; 118 applets[napplets++] = applet;
119 applet->library = lib; 119 applet->library = lib;
120 applet->iface = iface; 120 applet->iface = iface;
121 121
122 QTranslator *trans = new QTranslator(qApp); 122 QTranslator *trans = new QTranslator(qApp);
123 QString type = (*it).left( (*it).find(".") ); 123 QString type = (*it).left( (*it).find(".") );
124 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 124 QString tfn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+type+".qm";
125 if ( trans->load( tfn )) 125 if ( trans->load( tfn ))
126 qApp->installTranslator( trans ); 126 qApp->installTranslator( trans );
127 else 127 else
128 delete trans; 128 delete trans;
129 } else { 129 } else {
130 exclude += *it; 130 exclude += *it;
131 delete lib; 131 delete lib;
132 } 132 }
133 } 133 }
134 cfg.writeEntry( "ExcludeApplets", exclude, ',' ); 134 cfg.writeEntry( "ExcludeApplets", exclude, ',' );
135 qsort(applets,napplets,sizeof(applets[0]),compareAppletPositions); 135 qsort(applets,napplets,sizeof(applets[0]),compareAppletPositions);
136 while (napplets--) { 136 while (napplets--) {
137 TaskbarApplet *applet = applets[napplets]; 137 TaskbarApplet *applet = applets[napplets];
138 applet->applet = applet->iface->applet( this ); 138 applet->applet = applet->iface->applet( this );
139 appletList.append(*applet); 139 appletList.append(*applet);
140 } 140 }
141 delete [] applets; 141 delete [] applets;
142#else /* ## FIXME single app */ 142#else /* ## FIXME single app */
143 TaskbarApplet * const applet = new TaskbarApplet(); 143 TaskbarApplet * const applet = new TaskbarApplet();
144 applet->iface = new ClockAppletImpl(); 144 applet->iface = new ClockAppletImpl();
145 applet->applet = applet->iface->applet( this ); 145 applet->applet = applet->iface->applet( this );
146 appletList.append( applet ); 146 appletList.append( applet );
147#endif 147#endif
148 show(); 148 show();
149} 149}
150 150
diff --git a/core/multimedia/opieplayer/mediaplayerstate.cpp b/core/multimedia/opieplayer/mediaplayerstate.cpp
index b700cd1..8b0fbbc 100644
--- a/core/multimedia/opieplayer/mediaplayerstate.cpp
+++ b/core/multimedia/opieplayer/mediaplayerstate.cpp
@@ -1,197 +1,197 @@
1/********************************************************************** 1/**********************************************************************
2 ** Copyright (C) 2000 Trolltech AS. All rights reserved. 2 ** Copyright (C) 2000 Trolltech AS. All rights reserved.
3 ** 3 **
4 ** This file is part of Qtopia Environment. 4 ** This file is part of Qtopia Environment.
5 ** 5 **
6 ** This file may be distributed and/or modified under the terms of the 6 ** This file may be distributed and/or modified under the terms of the
7 ** GNU General Public License version 2 as published by the Free Software 7 ** GNU General Public License version 2 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.GPL included in the 8 ** Foundation and appearing in the file LICENSE.GPL included in the
9 ** packaging of this file. 9 ** packaging of this file.
10 ** 10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 ** 13 **
14 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 14 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
15 ** 15 **
16 ** Contact info@trolltech.com if any conditions of this licensing are 16 ** Contact info@trolltech.com if any conditions of this licensing are
17 ** not clear to you. 17 ** not clear to you.
18 ** 18 **
19 **********************************************************************/ 19 **********************************************************************/
20 20
21#ifdef QT_NO_COMPONENT 21#ifdef QT_NO_COMPONENT
22// Plugins which are compiled in when no plugin architecture available 22// Plugins which are compiled in when no plugin architecture available
23#include "libmad/libmadpluginimpl.h" 23#include "libmad/libmadpluginimpl.h"
24#include "libmpeg3/libmpeg3pluginimpl.h" 24#include "libmpeg3/libmpeg3pluginimpl.h"
25#include "wavplugin/wavpluginimpl.h" 25#include "wavplugin/wavpluginimpl.h"
26#endif 26#endif
27 27
28#include "mediaplayerstate.h" 28#include "mediaplayerstate.h"
29 29
30/* OPIE */ 30/* OPIE */
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#include <qpe/qlibrary.h> 32#include <qpe/qlibrary.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/mediaplayerplugininterface.h> 34#include <qpe/mediaplayerplugininterface.h>
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36 36
37/* QT */ 37/* QT */
38#include <qdir.h> 38#include <qdir.h>
39 39
40 40
41//#define MediaPlayerDebug(x) qDebug x 41//#define MediaPlayerDebug(x) qDebug x
42#define MediaPlayerDebug(x) 42#define MediaPlayerDebug(x)
43 43
44 44
45MediaPlayerState::MediaPlayerState( QObject *parent, const char *name ) 45MediaPlayerState::MediaPlayerState( QObject *parent, const char *name )
46 : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) { 46 : QObject( parent, name ), decoder( NULL ), libmpeg3decoder( NULL ) {
47 Config cfg( "OpiePlayer" ); 47 Config cfg( "OpiePlayer" );
48 readConfig( cfg ); 48 readConfig( cfg );
49 loadPlugins(); 49 loadPlugins();
50} 50}
51 51
52 52
53MediaPlayerState::~MediaPlayerState() { 53MediaPlayerState::~MediaPlayerState() {
54 Config cfg( "OpiePlayer" ); 54 Config cfg( "OpiePlayer" );
55 writeConfig( cfg ); 55 writeConfig( cfg );
56} 56}
57 57
58 58
59void MediaPlayerState::readConfig( Config& cfg ) { 59void MediaPlayerState::readConfig( Config& cfg ) {
60 cfg.setGroup("Options"); 60 cfg.setGroup("Options");
61 isFullscreen = cfg.readBoolEntry( "FullScreen" ); 61 isFullscreen = cfg.readBoolEntry( "FullScreen" );
62 isScaled = cfg.readBoolEntry( "Scaling" ); 62 isScaled = cfg.readBoolEntry( "Scaling" );
63 isLooping = cfg.readBoolEntry( "Looping" ); 63 isLooping = cfg.readBoolEntry( "Looping" );
64 isShuffled = cfg.readBoolEntry( "Shuffle" ); 64 isShuffled = cfg.readBoolEntry( "Shuffle" );
65 usePlaylist = cfg.readBoolEntry( "UsePlayList" ); 65 usePlaylist = cfg.readBoolEntry( "UsePlayList" );
66 usePlaylist = TRUE; 66 usePlaylist = TRUE;
67 isPlaying = FALSE; 67 isPlaying = FALSE;
68 isPaused = FALSE; 68 isPaused = FALSE;
69 curPosition = 0; 69 curPosition = 0;
70 curLength = 0; 70 curLength = 0;
71 curView = 'l'; 71 curView = 'l';
72} 72}
73 73
74 74
75void MediaPlayerState::writeConfig( Config& cfg ) const { 75void MediaPlayerState::writeConfig( Config& cfg ) const {
76 cfg.setGroup("Options"); 76 cfg.setGroup("Options");
77 cfg.writeEntry("FullScreen", isFullscreen ); 77 cfg.writeEntry("FullScreen", isFullscreen );
78 cfg.writeEntry("Scaling", isScaled ); 78 cfg.writeEntry("Scaling", isScaled );
79 cfg.writeEntry("Looping", isLooping ); 79 cfg.writeEntry("Looping", isLooping );
80 cfg.writeEntry("Shuffle", isShuffled ); 80 cfg.writeEntry("Shuffle", isShuffled );
81 cfg.writeEntry("UsePlayList", usePlaylist ); 81 cfg.writeEntry("UsePlayList", usePlaylist );
82} 82}
83 83
84 84
85struct MediaPlayerPlugin { 85struct MediaPlayerPlugin {
86#ifndef QT_NO_COMPONENT 86#ifndef QT_NO_COMPONENT
87 QLibrary *library; 87 QLibrary *library;
88#endif 88#endif
89 MediaPlayerPluginInterface *iface; 89 MediaPlayerPluginInterface *iface;
90 MediaPlayerDecoder *decoder; 90 MediaPlayerDecoder *decoder;
91 MediaPlayerEncoder *encoder; 91 MediaPlayerEncoder *encoder;
92}; 92};
93 93
94 94
95static QValueList<MediaPlayerPlugin> pluginList; 95static QValueList<MediaPlayerPlugin> pluginList;
96 96
97 97
98// Find the first decoder which supports this type of file 98// Find the first decoder which supports this type of file
99MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) { 99MediaPlayerDecoder *MediaPlayerState::newDecoder( const QString& file ) {
100 MediaPlayerDecoder *tmpDecoder = NULL; 100 MediaPlayerDecoder *tmpDecoder = NULL;
101 QValueList<MediaPlayerPlugin>::Iterator it; 101 QValueList<MediaPlayerPlugin>::Iterator it;
102 for ( it = pluginList.begin(); it != pluginList.end(); ++it ) { 102 for ( it = pluginList.begin(); it != pluginList.end(); ++it ) {
103 if ( (*it).decoder->isFileSupported( file ) ) { 103 if ( (*it).decoder->isFileSupported( file ) ) {
104 tmpDecoder = (*it).decoder; 104 tmpDecoder = (*it).decoder;
105 break; 105 break;
106 } 106 }
107 } 107 }
108 if(file.left(4)=="http") 108 if(file.left(4)=="http")
109 isStreaming = TRUE; 109 isStreaming = TRUE;
110 else 110 else
111 isStreaming = FALSE; 111 isStreaming = FALSE;
112 return decoder = tmpDecoder; 112 return decoder = tmpDecoder;
113} 113}
114 114
115 115
116MediaPlayerDecoder *MediaPlayerState::curDecoder() { 116MediaPlayerDecoder *MediaPlayerState::curDecoder() {
117 return decoder; 117 return decoder;
118} 118}
119 119
120 120
121// ### hack to get true sample count 121// ### hack to get true sample count
122MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() { 122MediaPlayerDecoder *MediaPlayerState::libMpeg3Decoder() {
123 return libmpeg3decoder; 123 return libmpeg3decoder;
124} 124}
125 125
126// ### hack to get true sample count 126// ### hack to get true sample count
127// MediaPlayerDecoder *MediaPlayerState::libWavDecoder() { 127// MediaPlayerDecoder *MediaPlayerState::libWavDecoder() {
128// return libwavdecoder; 128// return libwavdecoder;
129// } 129// }
130 130
131void MediaPlayerState::loadPlugins() { 131void MediaPlayerState::loadPlugins() {
132 // odebug << "load plugins" << oendl; 132 // odebug << "load plugins" << oendl;
133#ifndef QT_NO_COMPONENT 133#ifndef QT_NO_COMPONENT
134 QValueList<MediaPlayerPlugin>::Iterator mit; 134 QValueList<MediaPlayerPlugin>::Iterator mit;
135 for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) { 135 for ( mit = pluginList.begin(); mit != pluginList.end(); ++mit ) {
136 (*mit).iface->release(); 136 (*mit).iface->release();
137 (*mit).library->unload(); 137 (*mit).library->unload();
138 delete (*mit).library; 138 delete (*mit).library;
139 } 139 }
140 pluginList.clear(); 140 pluginList.clear();
141 141
142 QString path = QPEApplication::qpeDir() + "/plugins/codecs"; 142 QString path = QPEApplication::qpeDir() + "plugins/codecs";
143 QDir dir( path, "lib*.so" ); 143 QDir dir( path, "lib*.so" );
144 QStringList list = dir.entryList(); 144 QStringList list = dir.entryList();
145 QStringList::Iterator it; 145 QStringList::Iterator it;
146 for ( it = list.begin(); it != list.end(); ++it ) { 146 for ( it = list.begin(); it != list.end(); ++it ) {
147 MediaPlayerPluginInterface *iface = 0; 147 MediaPlayerPluginInterface *iface = 0;
148 QLibrary *lib = new QLibrary( path + "/" + *it ); 148 QLibrary *lib = new QLibrary( path + "/" + *it );
149// odebug << "querying: " << QString( path + "/" + *it ) << "" << oendl; 149// odebug << "querying: " << QString( path + "/" + *it ) << "" << oendl;
150 150
151 if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) { 151 if ( lib->queryInterface( IID_MediaPlayerPlugin, (QUnknownInterface**)&iface ) == QS_OK ) {
152 152
153// odebug << "loading: " << QString( path + "/" + *it ) << "" << oendl; 153// odebug << "loading: " << QString( path + "/" + *it ) << "" << oendl;
154 154
155 MediaPlayerPlugin plugin; 155 MediaPlayerPlugin plugin;
156 plugin.library = lib; 156 plugin.library = lib;
157 plugin.iface = iface; 157 plugin.iface = iface;
158 plugin.decoder = plugin.iface->decoder(); 158 plugin.decoder = plugin.iface->decoder();
159 plugin.encoder = plugin.iface->encoder(); 159 plugin.encoder = plugin.iface->encoder();
160 pluginList.append( plugin ); 160 pluginList.append( plugin );
161 161
162 // ### hack to get true sample count 162 // ### hack to get true sample count
163 if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") ) 163 if ( plugin.decoder->pluginName() == QString("LibMpeg3Plugin") )
164 libmpeg3decoder = plugin.decoder; 164 libmpeg3decoder = plugin.decoder;
165 165
166 } else { 166 } else {
167 delete lib; 167 delete lib;
168 } 168 }
169 } 169 }
170#else 170#else
171 pluginList.clear(); 171 pluginList.clear();
172 172
173 MediaPlayerPlugin plugin0; 173 MediaPlayerPlugin plugin0;
174 plugin0.iface = new LibMpeg3PluginImpl; 174 plugin0.iface = new LibMpeg3PluginImpl;
175 plugin0.decoder = plugin0.iface->decoder(); 175 plugin0.decoder = plugin0.iface->decoder();
176 plugin0.encoder = plugin0.iface->encoder(); 176 plugin0.encoder = plugin0.iface->encoder();
177 pluginList.append( plugin0 ); 177 pluginList.append( plugin0 );
178 178
179 MediaPlayerPlugin plugin1; 179 MediaPlayerPlugin plugin1;
180 plugin1.iface = new LibMadPluginImpl; 180 plugin1.iface = new LibMadPluginImpl;
181 plugin1.decoder = plugin1.iface->decoder(); 181 plugin1.decoder = plugin1.iface->decoder();
182 plugin1.encoder = plugin1.iface->encoder(); 182 plugin1.encoder = plugin1.iface->encoder();
183 pluginList.append( plugin1 ); 183 pluginList.append( plugin1 );
184 184
185 MediaPlayerPlugin plugin2; 185 MediaPlayerPlugin plugin2;
186 plugin2.iface = new WavPluginImpl; 186 plugin2.iface = new WavPluginImpl;
187 plugin2.decoder = plugin2.iface->decoder(); 187 plugin2.decoder = plugin2.iface->decoder();
188 plugin2.encoder = plugin2.iface->encoder(); 188 plugin2.encoder = plugin2.iface->encoder();
189 pluginList.append( plugin2 ); 189 pluginList.append( plugin2 );
190#endif 190#endif
191 191
192 if ( pluginList.count() ) 192 if ( pluginList.count() )
193 MediaPlayerDebug(( "%i decoders found", pluginList.count() )); 193 MediaPlayerDebug(( "%i decoders found", pluginList.count() ));
194 else 194 else
195 MediaPlayerDebug(( "No decoders found" )); 195 MediaPlayerDebug(( "No decoders found" ));
196} 196}
197 197
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp
index 46aeff2..db2bf1b 100644
--- a/core/multimedia/opieplayer/playlistwidget.cpp
+++ b/core/multimedia/opieplayer/playlistwidget.cpp
@@ -1,1459 +1,1459 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// code added by L. J. Potter Sat 03-02-2002 06:17:54 20// code added by L. J. Potter Sat 03-02-2002 06:17:54
21#define QTOPIA_INTERNAL_FSLP 21#define QTOPIA_INTERNAL_FSLP
22 22
23#include "playlistselection.h" 23#include "playlistselection.h"
24#include "playlistwidget.h" 24#include "playlistwidget.h"
25#include "mediaplayerstate.h" 25#include "mediaplayerstate.h"
26#include "inputDialog.h" 26#include "inputDialog.h"
27#include "audiowidget.h" 27#include "audiowidget.h"
28#include "videowidget.h" 28#include "videowidget.h"
29 29
30/* OPIE */ 30/* OPIE */
31#include <qpe/qpemenubar.h> 31#include <qpe/qpemenubar.h>
32#include <qpe/lnkproperties.h> 32#include <qpe/lnkproperties.h>
33#include <opie2/odebug.h> 33#include <opie2/odebug.h>
34 34
35/* QT */ 35/* QT */
36#include <qtoolbar.h> 36#include <qtoolbar.h>
37#include <qaction.h> 37#include <qaction.h>
38#include <qlayout.h> 38#include <qlayout.h>
39#include <qmessagebox.h> 39#include <qmessagebox.h>
40//#include <qtimer.h> 40//#include <qtimer.h>
41 41
42/* STD */ 42/* STD */
43#include <stdlib.h> 43#include <stdlib.h>
44 44
45#include <unistd.h> 45#include <unistd.h>
46#include <sys/file.h> 46#include <sys/file.h>
47#include <sys/ioctl.h> 47#include <sys/ioctl.h>
48#include <sys/soundcard.h> 48#include <sys/soundcard.h>
49 49
50// for setBacklight() 50// for setBacklight()
51#include <linux/fb.h> 51#include <linux/fb.h>
52#include <sys/types.h> 52#include <sys/types.h>
53#include <sys/stat.h> 53#include <sys/stat.h>
54#include <stdlib.h> 54#include <stdlib.h>
55 55
56#define BUTTONS_ON_TOOLBAR 56#define BUTTONS_ON_TOOLBAR
57#define SIDE_BUTTONS 57#define SIDE_BUTTONS
58#define CAN_SAVE_LOAD_PLAYLISTS 58#define CAN_SAVE_LOAD_PLAYLISTS
59 59
60extern AudioWidget *audioUI; 60extern AudioWidget *audioUI;
61extern VideoWidget *videoUI; 61extern VideoWidget *videoUI;
62extern MediaPlayerState *mediaPlayerState; 62extern MediaPlayerState *mediaPlayerState;
63 63
64static inline QString fullBaseName ( const QFileInfo &fi ) 64static inline QString fullBaseName ( const QFileInfo &fi )
65{ 65{
66 QString str = fi. fileName ( ); 66 QString str = fi. fileName ( );
67 return str. left ( str. findRev ( '.' )); 67 return str. left ( str. findRev ( '.' ));
68} 68}
69 69
70 70
71QString audioMimes ="audio/mpeg;audio/x-wav;audio/x-ogg;audio/x-mod"; 71QString audioMimes ="audio/mpeg;audio/x-wav;audio/x-ogg;audio/x-mod";
72// class myFileSelector { 72// class myFileSelector {
73 73
74// }; 74// };
75class PlayListWidgetPrivate { 75class PlayListWidgetPrivate {
76public: 76public:
77 QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; 77 QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove;
78 QFrame *playListFrame; 78 QFrame *playListFrame;
79 FileSelector *files; 79 FileSelector *files;
80 PlayListSelection *selectedFiles; 80 PlayListSelection *selectedFiles;
81 bool setDocumentUsed; 81 bool setDocumentUsed;
82 DocLnk *current; 82 DocLnk *current;
83}; 83};
84 84
85 85
86class ToolButton : public QToolButton { 86class ToolButton : public QToolButton {
87public: 87public:
88 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) 88 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE )
89 : QToolButton( parent, name ) { 89 : QToolButton( parent, name ) {
90 setTextLabel( name ); 90 setTextLabel( name );
91 setPixmap( Resource::loadPixmap( icon ) ); 91 setPixmap( Resource::loadPixmap( icon ) );
92 setAutoRaise( TRUE ); 92 setAutoRaise( TRUE );
93 setFocusPolicy( QWidget::NoFocus ); 93 setFocusPolicy( QWidget::NoFocus );
94 setToggleButton( t ); 94 setToggleButton( t );
95 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); 95 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot );
96 QPEMenuToolFocusManager::manager()->addWidget( this ); 96 QPEMenuToolFocusManager::manager()->addWidget( this );
97 } 97 }
98}; 98};
99 99
100 100
101class MenuItem : public QAction { 101class MenuItem : public QAction {
102public: 102public:
103 MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) 103 MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot )
104 : QAction( text, QString::null, 0, 0 ) { 104 : QAction( text, QString::null, 0, 0 ) {
105 connect( this, SIGNAL( activated() ), handler, slot ); 105 connect( this, SIGNAL( activated() ), handler, slot );
106 addTo( parent ); 106 addTo( parent );
107 } 107 }
108}; 108};
109 109
110 110
111PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) 111PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl )
112 : QMainWindow( parent, name, fl ) { 112 : QMainWindow( parent, name, fl ) {
113 113
114 d = new PlayListWidgetPrivate; 114 d = new PlayListWidgetPrivate;
115 d->setDocumentUsed = FALSE; 115 d->setDocumentUsed = FALSE;
116 d->current = NULL; 116 d->current = NULL;
117 fromSetDocument = FALSE; 117 fromSetDocument = FALSE;
118 insanityBool=FALSE; 118 insanityBool=FALSE;
119 audioScan = FALSE; 119 audioScan = FALSE;
120 videoScan = FALSE; 120 videoScan = FALSE;
121// menuTimer = new QTimer( this ,"menu timer"), 121// menuTimer = new QTimer( this ,"menu timer"),
122// connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); 122// connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) );
123 channel = new QCopChannel( "QPE/Application/opieplayer", this ); 123 channel = new QCopChannel( "QPE/Application/opieplayer", this );
124 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 124 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
125 this, SLOT( qcopReceive(const QCString&,const QByteArray&)) ); 125 this, SLOT( qcopReceive(const QCString&,const QByteArray&)) );
126 126
127 setBackgroundMode( PaletteButton ); 127 setBackgroundMode( PaletteButton );
128 128
129 setCaption( tr("OpiePlayer") ); 129 setCaption( tr("OpiePlayer") );
130 setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); 130 setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) );
131 131
132 setToolBarsMovable( FALSE ); 132 setToolBarsMovable( FALSE );
133 133
134 // Create Toolbar 134 // Create Toolbar
135 QToolBar *toolbar = new QToolBar( this ); 135 QToolBar *toolbar = new QToolBar( this );
136 toolbar->setHorizontalStretchable( TRUE ); 136 toolbar->setHorizontalStretchable( TRUE );
137 137
138 // Create Menubar 138 // Create Menubar
139 QMenuBar *menu = new QMenuBar( toolbar ); 139 QMenuBar *menu = new QMenuBar( toolbar );
140 menu->setMargin( 0 ); 140 menu->setMargin( 0 );
141 141
142 QToolBar *bar = new QToolBar( this ); 142 QToolBar *bar = new QToolBar( this );
143 bar->setLabel( tr( "Play Operations" ) ); 143 bar->setLabel( tr( "Play Operations" ) );
144// d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", 144// d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list",
145// this , SLOT( addSelected()) ); 145// this , SLOT( addSelected()) );
146 tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); 146 tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close");
147 tbDeletePlaylist->setFlat(TRUE); 147 tbDeletePlaylist->setFlat(TRUE);
148 148
149 tbDeletePlaylist->setFixedSize(20,20); 149 tbDeletePlaylist->setFixedSize(20,20);
150 150
151 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", 151 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist",
152 this , SLOT(addSelected()) ); 152 this , SLOT(addSelected()) );
153 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", 153 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist",
154 this , SLOT(removeSelected()) ); 154 this , SLOT(removeSelected()) );
155// d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool)/*btnPlay()*/), TRUE ); 155// d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool)/*btnPlay()*/), TRUE );
156 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", 156 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play",
157 this , SLOT( btnPlay(bool) ), TRUE ); 157 this , SLOT( btnPlay(bool) ), TRUE );
158 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", 158 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle",
159 mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); 159 mediaPlayerState, SLOT(setShuffled(bool)), TRUE );
160 d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", 160 d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop",
161 mediaPlayerState, SLOT(setLooping(bool)), TRUE ); 161 mediaPlayerState, SLOT(setLooping(bool)), TRUE );
162 tbDeletePlaylist->hide(); 162 tbDeletePlaylist->hide();
163 163
164 QPopupMenu *pmPlayList = new QPopupMenu( this ); 164 QPopupMenu *pmPlayList = new QPopupMenu( this );
165 menu->insertItem( tr( "File" ), pmPlayList ); 165 menu->insertItem( tr( "File" ), pmPlayList );
166 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 166 new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
167 new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); 167 new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) );
168 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); 168 new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) );
169 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); 169 new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) );
170 pmPlayList->insertSeparator(-1); 170 pmPlayList->insertSeparator(-1);
171 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); 171 new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) );
172 new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); 172 new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) );
173 pmPlayList->insertSeparator(-1); 173 pmPlayList->insertSeparator(-1);
174 new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); 174 new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) );
175 new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); 175 new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) );
176 176
177 QPopupMenu *pmView = new QPopupMenu( this ); 177 QPopupMenu *pmView = new QPopupMenu( this );
178 menu->insertItem( tr( "View" ), pmView ); 178 menu->insertItem( tr( "View" ), pmView );
179 179
180 fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); 180 fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0);
181 fullScreenButton->addTo(pmView); 181 fullScreenButton->addTo(pmView);
182 scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); 182 scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0);
183 scaleButton->addTo(pmView); 183 scaleButton->addTo(pmView);
184 184
185 185
186 skinsMenu = new QPopupMenu( this ); 186 skinsMenu = new QPopupMenu( this );
187 menu->insertItem( tr( "Skins" ), skinsMenu ); 187 menu->insertItem( tr( "Skins" ), skinsMenu );
188 skinsMenu->isCheckable(); 188 skinsMenu->isCheckable();
189 connect( skinsMenu, SIGNAL( activated(int) ) , 189 connect( skinsMenu, SIGNAL( activated(int) ) ,
190 this, SLOT( skinsMenuActivated(int) ) ); 190 this, SLOT( skinsMenuActivated(int) ) );
191 populateSkinsMenu(); 191 populateSkinsMenu();
192 192
193 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); 193 QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton );
194 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); 194 QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton );
195 195
196 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); 196 QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton );
197 197
198 tabWidget = new QTabWidget( hbox6, "tabWidget" ); 198 tabWidget = new QTabWidget( hbox6, "tabWidget" );
199// tabWidget->setTabShape(QTabWidget::Triangular); 199// tabWidget->setTabShape(QTabWidget::Triangular);
200 200
201 QWidget *pTab; 201 QWidget *pTab;
202 pTab = new QWidget( tabWidget, "pTab" ); 202 pTab = new QWidget( tabWidget, "pTab" );
203// playlistView = new QListView( pTab, "playlistview" ); 203// playlistView = new QListView( pTab, "playlistview" );
204// playlistView->setMinimumSize(236,260); 204// playlistView->setMinimumSize(236,260);
205 tabWidget->insertTab( pTab,"Playlist"); 205 tabWidget->insertTab( pTab,"Playlist");
206 206
207 207
208 // Add the playlist area 208 // Add the playlist area
209 209
210 QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); 210 QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton );
211 d->playListFrame = vbox3; 211 d->playListFrame = vbox3;
212 212
213 QGridLayout *layoutF = new QGridLayout( pTab ); 213 QGridLayout *layoutF = new QGridLayout( pTab );
214 layoutF->setSpacing( 2); 214 layoutF->setSpacing( 2);
215 layoutF->setMargin( 2); 215 layoutF->setMargin( 2);
216 layoutF->addMultiCellWidget( d->playListFrame , 0, 0, 0, 1 ); 216 layoutF->addMultiCellWidget( d->playListFrame , 0, 0, 0, 1 );
217 217
218 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); 218 QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton );
219 219
220 d->selectedFiles = new PlayListSelection( hbox2); 220 d->selectedFiles = new PlayListSelection( hbox2);
221 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); 221 QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton );
222 222
223 QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); 223 QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold);
224 224
225 225
226 226
227 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch 227 QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch
228 new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); 228 new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) );
229 new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); 229 new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) );
230 new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); 230 new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) );
231 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch 231 QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch
232 232
233 QWidget *aTab; 233 QWidget *aTab;
234 aTab = new QWidget( tabWidget, "aTab" ); 234 aTab = new QWidget( tabWidget, "aTab" );
235 audioView = new QListView( aTab, "Audioview" ); 235 audioView = new QListView( aTab, "Audioview" );
236 236
237 QGridLayout *layoutA = new QGridLayout( aTab ); 237 QGridLayout *layoutA = new QGridLayout( aTab );
238 layoutA->setSpacing( 2); 238 layoutA->setSpacing( 2);
239 layoutA->setMargin( 2); 239 layoutA->setMargin( 2);
240 layoutA->addMultiCellWidget( audioView, 0, 0, 0, 1 ); 240 layoutA->addMultiCellWidget( audioView, 0, 0, 0, 1 );
241 241
242 audioView->addColumn( tr("Title"),-1); 242 audioView->addColumn( tr("Title"),-1);
243 audioView->addColumn(tr("Size"), -1); 243 audioView->addColumn(tr("Size"), -1);
244 audioView->addColumn(tr("Media"),-1); 244 audioView->addColumn(tr("Media"),-1);
245 audioView->addColumn( tr( "Path" ), -1 ); 245 audioView->addColumn( tr( "Path" ), -1 );
246 246
247 audioView->setColumnAlignment(1, Qt::AlignRight); 247 audioView->setColumnAlignment(1, Qt::AlignRight);
248 audioView->setColumnAlignment(2, Qt::AlignRight); 248 audioView->setColumnAlignment(2, Qt::AlignRight);
249 audioView->setAllColumnsShowFocus(TRUE); 249 audioView->setAllColumnsShowFocus(TRUE);
250 250
251 audioView->setMultiSelection( TRUE ); 251 audioView->setMultiSelection( TRUE );
252 audioView->setSelectionMode( QListView::Extended); 252 audioView->setSelectionMode( QListView::Extended);
253 audioView->setSorting( 3, TRUE ); 253 audioView->setSorting( 3, TRUE );
254 254
255 tabWidget->insertTab(aTab,tr("Audio")); 255 tabWidget->insertTab(aTab,tr("Audio"));
256 256
257 QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); 257 QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold);
258 258
259// audioView 259// audioView
260// populateAudioView(); 260// populateAudioView();
261// videowidget 261// videowidget
262 262
263 QWidget *vTab; 263 QWidget *vTab;
264 vTab = new QWidget( tabWidget, "vTab" ); 264 vTab = new QWidget( tabWidget, "vTab" );
265 videoView = new QListView( vTab, "Videoview" ); 265 videoView = new QListView( vTab, "Videoview" );
266 266
267 QGridLayout *layoutV = new QGridLayout( vTab ); 267 QGridLayout *layoutV = new QGridLayout( vTab );
268 layoutV->setSpacing( 2); 268 layoutV->setSpacing( 2);
269 layoutV->setMargin( 2); 269 layoutV->setMargin( 2);
270 layoutV->addMultiCellWidget( videoView, 0, 0, 0, 1 ); 270 layoutV->addMultiCellWidget( videoView, 0, 0, 0, 1 );
271 271
272 videoView->addColumn(tr("Title"),-1); 272 videoView->addColumn(tr("Title"),-1);
273 videoView->addColumn(tr("Size"),-1); 273 videoView->addColumn(tr("Size"),-1);
274 videoView->addColumn(tr("Media"),-1); 274 videoView->addColumn(tr("Media"),-1);
275 videoView->addColumn(tr( "Path" ), -1 ); 275 videoView->addColumn(tr( "Path" ), -1 );
276 videoView->setColumnAlignment(1, Qt::AlignRight); 276 videoView->setColumnAlignment(1, Qt::AlignRight);
277 videoView->setColumnAlignment(2, Qt::AlignRight); 277 videoView->setColumnAlignment(2, Qt::AlignRight);
278 videoView->setAllColumnsShowFocus(TRUE); 278 videoView->setAllColumnsShowFocus(TRUE);
279 videoView->setMultiSelection( TRUE ); 279 videoView->setMultiSelection( TRUE );
280 videoView->setSelectionMode( QListView::Extended); 280 videoView->setSelectionMode( QListView::Extended);
281 281
282 QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); 282 QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold);
283 283
284 tabWidget->insertTab( vTab,tr("Video")); 284 tabWidget->insertTab( vTab,tr("Video"));
285 285
286 QWidget *LTab; 286 QWidget *LTab;
287 LTab = new QWidget( tabWidget, "LTab" ); 287 LTab = new QWidget( tabWidget, "LTab" );
288 playLists = new FileSelector( "playlist/plain;audio/x-mpegurl", LTab, "fileselector" , FALSE, FALSE); 288 playLists = new FileSelector( "playlist/plain;audio/x-mpegurl", LTab, "fileselector" , FALSE, FALSE);
289 289
290 QGridLayout *layoutL = new QGridLayout( LTab ); 290 QGridLayout *layoutL = new QGridLayout( LTab );
291 layoutL->setSpacing( 2); 291 layoutL->setSpacing( 2);
292 layoutL->setMargin( 2); 292 layoutL->setMargin( 2);
293 layoutL->addMultiCellWidget( playLists, 0, 0, 0, 1 ); 293 layoutL->addMultiCellWidget( playLists, 0, 0, 0, 1 );
294 294
295 tabWidget->insertTab(LTab,tr("Lists")); 295 tabWidget->insertTab(LTab,tr("Lists"));
296 296
297 connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); 297 connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist()));
298 connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); 298 connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) );
299 connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); 299 connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) );
300 300
301 connect( d->selectedFiles, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)), 301 connect( d->selectedFiles, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),
302 this,SLOT( playlistViewPressed(int,QListViewItem*,const QPoint&,int)) ); 302 this,SLOT( playlistViewPressed(int,QListViewItem*,const QPoint&,int)) );
303 303
304 304
305///audioView 305///audioView
306 connect( audioView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)), 306 connect( audioView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),
307 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int)) ); 307 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int)) );
308 308
309 connect( audioView, SIGNAL( returnPressed(QListViewItem*)), 309 connect( audioView, SIGNAL( returnPressed(QListViewItem*)),
310 this,SLOT( playIt(QListViewItem*)) ); 310 this,SLOT( playIt(QListViewItem*)) );
311 connect( audioView, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( addToSelection(QListViewItem*) ) ); 311 connect( audioView, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( addToSelection(QListViewItem*) ) );
312 312
313 313
314//videoView 314//videoView
315 connect( videoView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)), 315 connect( videoView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),
316 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int)) ); 316 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int)) );
317 connect( videoView, SIGNAL( returnPressed(QListViewItem*)), 317 connect( videoView, SIGNAL( returnPressed(QListViewItem*)),
318 this,SLOT( playIt(QListViewItem*)) ); 318 this,SLOT( playIt(QListViewItem*)) );
319 connect( videoView, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( addToSelection(QListViewItem*) ) ); 319 connect( videoView, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( addToSelection(QListViewItem*) ) );
320 320
321//playlists 321//playlists
322 connect( playLists, SIGNAL( fileSelected(const DocLnk&) ), this, SLOT( loadList(const DocLnk&) ) ); 322 connect( playLists, SIGNAL( fileSelected(const DocLnk&) ), this, SLOT( loadList(const DocLnk&) ) );
323 323
324 connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); 324 connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*)));
325 325
326 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), d->tbPlay, SLOT( setOn(bool) ) ); 326 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), d->tbPlay, SLOT( setOn(bool) ) );
327 327
328 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), d->tbLoop, SLOT( setOn(bool) ) ); 328 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), d->tbLoop, SLOT( setOn(bool) ) );
329 connect( mediaPlayerState, SIGNAL( shuffledToggled(bool) ), d->tbShuffle, SLOT( setOn(bool) ) ); 329 connect( mediaPlayerState, SIGNAL( shuffledToggled(bool) ), d->tbShuffle, SLOT( setOn(bool) ) );
330 connect( mediaPlayerState, SIGNAL( playlistToggled(bool) ), this, SLOT( setPlaylist(bool) ) ); 330 connect( mediaPlayerState, SIGNAL( playlistToggled(bool) ), this, SLOT( setPlaylist(bool) ) );
331 331
332 connect( d->selectedFiles, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( playIt(QListViewItem*) ) ); 332 connect( d->selectedFiles, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( playIt(QListViewItem*) ) );
333 333
334 setCentralWidget( vbox5 ); 334 setCentralWidget( vbox5 );
335 335
336 Config cfg( "OpiePlayer" ); 336 Config cfg( "OpiePlayer" );
337 readConfig( cfg ); 337 readConfig( cfg );
338 338
339 currentPlayList = cfg.readEntry("CurrentPlaylist","default"); 339 currentPlayList = cfg.readEntry("CurrentPlaylist","default");
340 loadList(DocLnk( currentPlayList)); 340 loadList(DocLnk( currentPlayList));
341 setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlayList))); 341 setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlayList)));
342 342
343 initializeStates(); 343 initializeStates();
344} 344}
345 345
346 346
347PlayListWidget::~PlayListWidget() { 347PlayListWidget::~PlayListWidget() {
348 Config cfg( "OpiePlayer" ); 348 Config cfg( "OpiePlayer" );
349 writeConfig( cfg ); 349 writeConfig( cfg );
350 350
351 if ( d->current ) 351 if ( d->current )
352 delete d->current; 352 delete d->current;
353 if(d) delete d; 353 if(d) delete d;
354} 354}
355 355
356 356
357void PlayListWidget::initializeStates() { 357void PlayListWidget::initializeStates() {
358 358
359 d->tbPlay->setOn( mediaPlayerState->playing() ); 359 d->tbPlay->setOn( mediaPlayerState->playing() );
360 d->tbLoop->setOn( mediaPlayerState->looping() ); 360 d->tbLoop->setOn( mediaPlayerState->looping() );
361 d->tbShuffle->setOn( mediaPlayerState->shuffled() ); 361 d->tbShuffle->setOn( mediaPlayerState->shuffled() );
362 setPlaylist( true); 362 setPlaylist( true);
363} 363}
364 364
365 365
366void PlayListWidget::readConfig( Config& cfg ) { 366void PlayListWidget::readConfig( Config& cfg ) {
367 cfg.setGroup("PlayList"); 367 cfg.setGroup("PlayList");
368 QString currentString = cfg.readEntry("current", "" ); 368 QString currentString = cfg.readEntry("current", "" );
369 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 369 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
370 for ( int i = 0; i < noOfFiles; i++ ) { 370 for ( int i = 0; i < noOfFiles; i++ ) {
371 QString entryName; 371 QString entryName;
372 entryName.sprintf( "File%i", i + 1 ); 372 entryName.sprintf( "File%i", i + 1 );
373 QString linkFile = cfg.readEntry( entryName ); 373 QString linkFile = cfg.readEntry( entryName );
374 DocLnk lnk( linkFile ); 374 DocLnk lnk( linkFile );
375 if ( lnk.isValid() ) { 375 if ( lnk.isValid() ) {
376 d->selectedFiles->addToSelection( lnk ); 376 d->selectedFiles->addToSelection( lnk );
377 } 377 }
378 } 378 }
379 d->selectedFiles->setSelectedItem( currentString); 379 d->selectedFiles->setSelectedItem( currentString);
380} 380}
381 381
382 382
383void PlayListWidget::writeConfig( Config& cfg ) const { 383void PlayListWidget::writeConfig( Config& cfg ) const {
384 384
385 d->selectedFiles->writeCurrent( cfg); 385 d->selectedFiles->writeCurrent( cfg);
386 cfg.setGroup("PlayList"); 386 cfg.setGroup("PlayList");
387 int noOfFiles = 0; 387 int noOfFiles = 0;
388 d->selectedFiles->first(); 388 d->selectedFiles->first();
389 do { 389 do {
390 const DocLnk *lnk = d->selectedFiles->current(); 390 const DocLnk *lnk = d->selectedFiles->current();
391 if ( lnk ) { 391 if ( lnk ) {
392 QString entryName; 392 QString entryName;
393 entryName.sprintf( "File%i", noOfFiles + 1 ); 393 entryName.sprintf( "File%i", noOfFiles + 1 );
394// odebug << entryName << oendl; 394// odebug << entryName << oendl;
395 cfg.writeEntry( entryName, lnk->linkFile() ); 395 cfg.writeEntry( entryName, lnk->linkFile() );
396 // if this link does exist, add it so we have the file 396 // if this link does exist, add it so we have the file
397 // next time... 397 // next time...
398 if ( !QFile::exists( lnk->linkFile() ) ) { 398 if ( !QFile::exists( lnk->linkFile() ) ) {
399 // the way writing lnks doesn't really check for out 399 // the way writing lnks doesn't really check for out
400 // of disk space, but check it anyway. 400 // of disk space, but check it anyway.
401// if ( !lnk->writeLink() ) { 401// if ( !lnk->writeLink() ) {
402// QMessageBox::critical( 0, tr("Out of space"), 402// QMessageBox::critical( 0, tr("Out of space"),
403// tr( "There was a problem saving " 403// tr( "There was a problem saving "
404// "the playlist.\n" 404// "the playlist.\n"
405// "Your playlist " 405// "Your playlist "
406// "may be missing some entries\n" 406// "may be missing some entries\n"
407// "the next time you start it." ) 407// "the next time you start it." )
408// ); 408// );
409// } 409// }
410 410
411 } 411 }
412 noOfFiles++; 412 noOfFiles++;
413 } 413 }
414 } 414 }
415 while ( d->selectedFiles->next() ); 415 while ( d->selectedFiles->next() );
416 cfg.writeEntry("NumberOfFiles", noOfFiles ); 416 cfg.writeEntry("NumberOfFiles", noOfFiles );
417} 417}
418 418
419 419
420void PlayListWidget::addToSelection( const DocLnk& lnk ) { 420void PlayListWidget::addToSelection( const DocLnk& lnk ) {
421 d->setDocumentUsed = false; 421 d->setDocumentUsed = false;
422 if ( mediaPlayerState->playlist() ) { 422 if ( mediaPlayerState->playlist() ) {
423 if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) 423 if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" )
424 d->selectedFiles->addToSelection( lnk ); 424 d->selectedFiles->addToSelection( lnk );
425 } 425 }
426 else 426 else
427 mediaPlayerState->setPlaying( true); 427 mediaPlayerState->setPlaying( true);
428 428
429} 429}
430 430
431 431
432void PlayListWidget::clearList() { 432void PlayListWidget::clearList() {
433 while ( first() ) 433 while ( first() )
434 d->selectedFiles->removeSelected(); 434 d->selectedFiles->removeSelected();
435 Config cfg( "OpiePlayer" ); 435 Config cfg( "OpiePlayer" );
436 cfg.setGroup("PlayList"); 436 cfg.setGroup("PlayList");
437 cfg.writeEntry("CurrentPlaylist",""); 437 cfg.writeEntry("CurrentPlaylist","");
438 currentPlayList=""; 438 currentPlayList="";
439 439
440} 440}
441 441
442 442
443void PlayListWidget::addAllToList() { 443void PlayListWidget::addAllToList() {
444 DocLnkSet filesAll; 444 DocLnkSet filesAll;
445 Global::findDocuments(&filesAll, "video/*;audio/*"); 445 Global::findDocuments(&filesAll, "video/*;audio/*");
446 QListIterator<DocLnk> Adit( filesAll.children() ); 446 QListIterator<DocLnk> Adit( filesAll.children() );
447 for ( ; Adit.current(); ++Adit ) 447 for ( ; Adit.current(); ++Adit )
448 if(QFileInfo(Adit.current()->file()).exists()) 448 if(QFileInfo(Adit.current()->file()).exists())
449 d->selectedFiles->addToSelection( **Adit ); 449 d->selectedFiles->addToSelection( **Adit );
450 tabWidget->setCurrentPage(0); 450 tabWidget->setCurrentPage(0);
451 451
452 writeCurrentM3u(); 452 writeCurrentM3u();
453 d->selectedFiles->first(); 453 d->selectedFiles->first();
454} 454}
455 455
456 456
457void PlayListWidget::addAllMusicToList() { 457void PlayListWidget::addAllMusicToList() {
458 QListIterator<DocLnk> dit( files.children() ); 458 QListIterator<DocLnk> dit( files.children() );
459 for ( ; dit.current(); ++dit ) 459 for ( ; dit.current(); ++dit )
460 if(QFileInfo(dit.current()->file()).exists()) 460 if(QFileInfo(dit.current()->file()).exists())
461 d->selectedFiles->addToSelection( **dit ); 461 d->selectedFiles->addToSelection( **dit );
462 tabWidget->setCurrentPage(0); 462 tabWidget->setCurrentPage(0);
463 463
464 writeCurrentM3u(); 464 writeCurrentM3u();
465 d->selectedFiles->first(); 465 d->selectedFiles->first();
466} 466}
467 467
468 468
469void PlayListWidget::addAllVideoToList() { 469void PlayListWidget::addAllVideoToList() {
470 QListIterator<DocLnk> dit( vFiles.children() ); 470 QListIterator<DocLnk> dit( vFiles.children() );
471 for ( ; dit.current(); ++dit ) 471 for ( ; dit.current(); ++dit )
472 if(QFileInfo( dit.current()->file()).exists()) 472 if(QFileInfo( dit.current()->file()).exists())
473 d->selectedFiles->addToSelection( **dit ); 473 d->selectedFiles->addToSelection( **dit );
474 tabWidget->setCurrentPage(0); 474 tabWidget->setCurrentPage(0);
475 475
476 writeCurrentM3u(); 476 writeCurrentM3u();
477 d->selectedFiles->first(); 477 d->selectedFiles->first();
478} 478}
479 479
480 480
481void PlayListWidget::setDocument(const QString& fileref) { 481void PlayListWidget::setDocument(const QString& fileref) {
482 fromSetDocument = true; 482 fromSetDocument = true;
483 d->setDocumentUsed = TRUE; 483 d->setDocumentUsed = TRUE;
484 setDocumentEx(fileref); 484 setDocumentEx(fileref);
485} 485}
486 486
487void PlayListWidget::setDocumentEx(const QString& fileref) { 487void PlayListWidget::setDocumentEx(const QString& fileref) {
488 odebug << "opieplayer receive "+fileref << oendl; 488 odebug << "opieplayer receive "+fileref << oendl;
489 clearList(); 489 clearList();
490 DocLnk lnk; 490 DocLnk lnk;
491 QFileInfo fileInfo(fileref); 491 QFileInfo fileInfo(fileref);
492 if ( !fileInfo.exists() ) { 492 if ( !fileInfo.exists() ) {
493 QMessageBox::critical( 0, tr( "Invalid File" ), 493 QMessageBox::critical( 0, tr( "Invalid File" ),
494 tr( "There was a problem in getting the file." ) ); 494 tr( "There was a problem in getting the file." ) );
495 return; 495 return;
496 } 496 }
497 // odebug << "<<<<<<<<<<<<<<<<<<<<<<setDocument "+fileref << oendl; 497 // odebug << "<<<<<<<<<<<<<<<<<<<<<<setDocument "+fileref << oendl;
498 QString extension = fileInfo.extension(false); 498 QString extension = fileInfo.extension(false);
499 if( extension.find( "m3u", 0, false) != -1) { //is m3u 499 if( extension.find( "m3u", 0, false) != -1) { //is m3u
500 readm3u( fileref); 500 readm3u( fileref);
501 } 501 }
502 else if( extension.find( "pls", 0, false) != -1 ) { //is pls 502 else if( extension.find( "pls", 0, false) != -1 ) { //is pls
503 readPls( fileref); 503 readPls( fileref);
504 } 504 }
505 else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist 505 else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist
506 clearList(); 506 clearList();
507 lnk.setName( fileInfo.baseName() ); //sets name 507 lnk.setName( fileInfo.baseName() ); //sets name
508 lnk.setFile( fileref ); //sets file name 508 lnk.setFile( fileref ); //sets file name
509 lnk.setIcon("Sound"); 509 lnk.setIcon("Sound");
510 //addToSelection( lnk ); 510 //addToSelection( lnk );
511 511
512 loadList( lnk); 512 loadList( lnk);
513 d->selectedFiles->first(); 513 d->selectedFiles->first();
514 } else { 514 } else {
515 if( fileref.find(".desktop",0,TRUE) != -1) { 515 if( fileref.find(".desktop",0,TRUE) != -1) {
516 lnk = DocLnk(fileref); 516 lnk = DocLnk(fileref);
517 } else { 517 } else {
518 lnk.setName( fileInfo.baseName() ); //sets name 518 lnk.setName( fileInfo.baseName() ); //sets name
519 lnk.setFile( fileref ); //sets file name 519 lnk.setFile( fileref ); //sets file name
520 lnk.setIcon("Sound"); 520 lnk.setIcon("Sound");
521 } 521 }
522 522
523 addToSelection( lnk ); 523 addToSelection( lnk );
524 // addToSelection( DocLnk( fileref ) ); 524 // addToSelection( DocLnk( fileref ) );
525 lnk.removeLinkFile(); 525 lnk.removeLinkFile();
526 // qApp->processEvents(); 526 // qApp->processEvents();
527 } 527 }
528 setCaption(tr("OpiePlayer")); 528 setCaption(tr("OpiePlayer"));
529 d->setDocumentUsed = TRUE; 529 d->setDocumentUsed = TRUE;
530 d->selectedFiles->setSelected(d->selectedFiles->firstChild(),true ); 530 d->selectedFiles->setSelected(d->selectedFiles->firstChild(),true );
531 mediaPlayerState->setPlaying( FALSE ); 531 mediaPlayerState->setPlaying( FALSE );
532 qApp->processEvents(); 532 qApp->processEvents();
533 mediaPlayerState->setPlaying( TRUE ); 533 mediaPlayerState->setPlaying( TRUE );
534 534
535} 535}
536 536
537 537
538void PlayListWidget::setActiveWindow() { 538void PlayListWidget::setActiveWindow() {
539 // odebug << "SETTING active window" << oendl; 539 // odebug << "SETTING active window" << oendl;
540 // When we get raised we need to ensure that it switches views 540 // When we get raised we need to ensure that it switches views
541 char origView = mediaPlayerState->view(); 541 char origView = mediaPlayerState->view();
542 mediaPlayerState->setView( 'l' ); // invalidate 542 mediaPlayerState->setView( 'l' ); // invalidate
543 mediaPlayerState->setView( origView ); // now switch back 543 mediaPlayerState->setView( origView ); // now switch back
544} 544}
545 545
546 546
547void PlayListWidget::useSelectedDocument() { 547void PlayListWidget::useSelectedDocument() {
548 d->setDocumentUsed = FALSE; 548 d->setDocumentUsed = FALSE;
549} 549}
550 550
551 551
552const DocLnk *PlayListWidget::current() { // this is fugly 552const DocLnk *PlayListWidget::current() { // this is fugly
553 switch (tabWidget->currentPageIndex()) { 553 switch (tabWidget->currentPageIndex()) {
554 case 0: //playlist 554 case 0: //playlist
555 { 555 {
556 // odebug << "playlist" << oendl; 556 // odebug << "playlist" << oendl;
557 if ( mediaPlayerState->playlist() ) { 557 if ( mediaPlayerState->playlist() ) {
558 return d->selectedFiles->current(); 558 return d->selectedFiles->current();
559 } 559 }
560 else if ( d->setDocumentUsed && d->current ) { 560 else if ( d->setDocumentUsed && d->current ) {
561 return d->current; 561 return d->current;
562 } else { 562 } else {
563 return &(d->files->selectedDocument()); 563 return &(d->files->selectedDocument());
564 } 564 }
565 } 565 }
566 break; 566 break;
567 case 1://audio 567 case 1://audio
568 { 568 {
569 // odebug << "audioView" << oendl; 569 // odebug << "audioView" << oendl;
570 QListIterator<DocLnk> dit( files.children() ); 570 QListIterator<DocLnk> dit( files.children() );
571 for ( ; dit.current(); ++dit ) { 571 for ( ; dit.current(); ++dit ) {
572 if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { 572 if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) {
573 insanityBool=TRUE; 573 insanityBool=TRUE;
574 return dit; 574 return dit;
575 } 575 }
576 } 576 }
577 } 577 }
578 break; 578 break;
579 case 2: // video 579 case 2: // video
580 { 580 {
581 QListIterator<DocLnk> Vdit( vFiles.children() ); 581 QListIterator<DocLnk> Vdit( vFiles.children() );
582 for ( ; Vdit.current(); ++Vdit ) { 582 for ( ; Vdit.current(); ++Vdit ) {
583 if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { 583 if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) {
584 insanityBool=TRUE; 584 insanityBool=TRUE;
585 return Vdit; 585 return Vdit;
586 } 586 }
587 } 587 }
588 } 588 }
589 break; 589 break;
590 }; 590 };
591 return 0; 591 return 0;
592} 592}
593 593
594bool PlayListWidget::prev() { 594bool PlayListWidget::prev() {
595 if ( mediaPlayerState->playlist() ) { 595 if ( mediaPlayerState->playlist() ) {
596 if ( mediaPlayerState->shuffled() ) { 596 if ( mediaPlayerState->shuffled() ) {
597 const DocLnk *cur = current(); 597 const DocLnk *cur = current();
598 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 598 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
599 for ( int i = 0; i < j; i++ ) { 599 for ( int i = 0; i < j; i++ ) {
600 if ( !d->selectedFiles->next() ) 600 if ( !d->selectedFiles->next() )
601 d->selectedFiles->first(); 601 d->selectedFiles->first();
602 } 602 }
603 if ( cur == current() ) 603 if ( cur == current() )
604 if ( !d->selectedFiles->next() ) 604 if ( !d->selectedFiles->next() )
605 d->selectedFiles->first(); 605 d->selectedFiles->first();
606 return TRUE; 606 return TRUE;
607 } else { 607 } else {
608 if ( !d->selectedFiles->prev() ) { 608 if ( !d->selectedFiles->prev() ) {
609 if ( mediaPlayerState->looping() ) { 609 if ( mediaPlayerState->looping() ) {
610 return d->selectedFiles->last(); 610 return d->selectedFiles->last();
611 } else { 611 } else {
612 return FALSE; 612 return FALSE;
613 } 613 }
614 } 614 }
615 return TRUE; 615 return TRUE;
616 } 616 }
617 } else { 617 } else {
618 return mediaPlayerState->looping(); 618 return mediaPlayerState->looping();
619 } 619 }
620} 620}
621 621
622 622
623bool PlayListWidget::next() { 623bool PlayListWidget::next() {
624 if ( mediaPlayerState->playlist() ) { 624 if ( mediaPlayerState->playlist() ) {
625 if ( mediaPlayerState->shuffled() ) { 625 if ( mediaPlayerState->shuffled() ) {
626 return prev(); 626 return prev();
627 } else { 627 } else {
628 if ( !d->selectedFiles->next() ) { 628 if ( !d->selectedFiles->next() ) {
629 if ( mediaPlayerState->looping() ) { 629 if ( mediaPlayerState->looping() ) {
630 return d->selectedFiles->first(); 630 return d->selectedFiles->first();
631 } else { 631 } else {
632 return FALSE; 632 return FALSE;
633 } 633 }
634 } 634 }
635 return TRUE; 635 return TRUE;
636 } 636 }
637 } else { 637 } else {
638 return mediaPlayerState->looping(); 638 return mediaPlayerState->looping();
639 } 639 }
640} 640}
641 641
642 642
643bool PlayListWidget::first() { 643bool PlayListWidget::first() {
644 if ( mediaPlayerState->playlist() ) 644 if ( mediaPlayerState->playlist() )
645 return d->selectedFiles->first(); 645 return d->selectedFiles->first();
646 else 646 else
647 return mediaPlayerState->looping(); 647 return mediaPlayerState->looping();
648} 648}
649 649
650 650
651bool PlayListWidget::last() { 651bool PlayListWidget::last() {
652 if ( mediaPlayerState->playlist() ) 652 if ( mediaPlayerState->playlist() )
653 return d->selectedFiles->last(); 653 return d->selectedFiles->last();
654 else 654 else
655 return mediaPlayerState->looping(); 655 return mediaPlayerState->looping();
656} 656}
657 657
658 658
659void PlayListWidget::saveList() { 659void PlayListWidget::saveList() {
660 writem3u(); 660 writem3u();
661} 661}
662 662
663void PlayListWidget::loadList( const DocLnk & lnk) { 663void PlayListWidget::loadList( const DocLnk & lnk) {
664 QString name = lnk.name(); 664 QString name = lnk.name();
665 // odebug << "<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name << oendl; 665 // odebug << "<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name << oendl;
666 666
667 if( name.length()>0) { 667 if( name.length()>0) {
668 setCaption("OpiePlayer: "+name); 668 setCaption("OpiePlayer: "+name);
669 // odebug << "<<<<<<<<<<<<load list "+ lnk.file() << oendl; 669 // odebug << "<<<<<<<<<<<<load list "+ lnk.file() << oendl;
670 clearList(); 670 clearList();
671 readm3u(lnk.file()); 671 readm3u(lnk.file());
672 tabWidget->setCurrentPage(0); 672 tabWidget->setCurrentPage(0);
673 } 673 }
674} 674}
675 675
676void PlayListWidget::setPlaylist( bool shown ) { 676void PlayListWidget::setPlaylist( bool shown ) {
677 if ( shown ) 677 if ( shown )
678 d->playListFrame->show(); 678 d->playListFrame->show();
679 else 679 else
680 d->playListFrame->hide(); 680 d->playListFrame->hide();
681} 681}
682 682
683void PlayListWidget::setView( char view ) { 683void PlayListWidget::setView( char view ) {
684 if ( view == 'l' ) 684 if ( view == 'l' )
685 QPEApplication::showWidget( this ); 685 QPEApplication::showWidget( this );
686 else 686 else
687 hide(); 687 hide();
688} 688}
689 689
690void PlayListWidget::addSelected() { 690void PlayListWidget::addSelected() {
691 DocLnk lnk; 691 DocLnk lnk;
692 QString filename; 692 QString filename;
693 switch (tabWidget->currentPageIndex()) { 693 switch (tabWidget->currentPageIndex()) {
694 694
695 case 0: //playlist 695 case 0: //playlist
696 return; 696 return;
697 break; 697 break;
698 case 1: { //audio 698 case 1: { //audio
699 QListViewItemIterator it( audioView ); 699 QListViewItemIterator it( audioView );
700 for ( ; it.current(); ++it ) { 700 for ( ; it.current(); ++it ) {
701 if ( it.current()->isSelected() ) { 701 if ( it.current()->isSelected() ) {
702 filename = it.current()->text(3); 702 filename = it.current()->text(3);
703 lnk.setName( QFileInfo(filename).baseName() ); //sets name 703 lnk.setName( QFileInfo(filename).baseName() ); //sets name
704 lnk.setFile( filename ); //sets file name 704 lnk.setFile( filename ); //sets file name
705 d->selectedFiles->addToSelection( lnk); 705 d->selectedFiles->addToSelection( lnk);
706 } 706 }
707 } 707 }
708 audioView->clearSelection(); 708 audioView->clearSelection();
709 // d->selectedFiles->next(); 709 // d->selectedFiles->next();
710 } 710 }
711 break; 711 break;
712 712
713 case 2: { // video 713 case 2: { // video
714 QListViewItemIterator it( videoView ); 714 QListViewItemIterator it( videoView );
715 for ( ; it.current(); ++it ) { 715 for ( ; it.current(); ++it ) {
716 if ( it.current()->isSelected() ) { 716 if ( it.current()->isSelected() ) {
717 717
718 filename = it.current()->text(3); 718 filename = it.current()->text(3);
719 lnk.setName( QFileInfo(filename).baseName() ); //sets name 719 lnk.setName( QFileInfo(filename).baseName() ); //sets name
720 lnk.setFile( filename ); //sets file name 720 lnk.setFile( filename ); //sets file name
721 d->selectedFiles->addToSelection( lnk); 721 d->selectedFiles->addToSelection( lnk);
722 } 722 }
723 } 723 }
724 videoView->clearSelection(); 724 videoView->clearSelection();
725 } 725 }
726 break; 726 break;
727 }; 727 };
728 // tabWidget->setCurrentPage(0); 728 // tabWidget->setCurrentPage(0);
729 writeCurrentM3u(); 729 writeCurrentM3u();
730 730
731} 731}
732 732
733void PlayListWidget::removeSelected() { 733void PlayListWidget::removeSelected() {
734 d->selectedFiles->removeSelected( ); 734 d->selectedFiles->removeSelected( );
735} 735}
736 736
737void PlayListWidget::playIt( QListViewItem *) { 737void PlayListWidget::playIt( QListViewItem *) {
738 // d->setDocumentUsed = FALSE; 738 // d->setDocumentUsed = FALSE;
739 // mediaPlayerState->curPosition =0; 739 // mediaPlayerState->curPosition =0;
740 // mediaPlayerState->setPlaying(FALSE); 740 // mediaPlayerState->setPlaying(FALSE);
741 mediaPlayerState->setPlaying(TRUE); 741 mediaPlayerState->setPlaying(TRUE);
742 d->selectedFiles->unSelect(); 742 d->selectedFiles->unSelect();
743} 743}
744 744
745void PlayListWidget::addToSelection( QListViewItem *it) { 745void PlayListWidget::addToSelection( QListViewItem *it) {
746 d->setDocumentUsed = FALSE; 746 d->setDocumentUsed = FALSE;
747 747
748 if(it) { 748 if(it) {
749 switch ( tabWidget->currentPageIndex()) { 749 switch ( tabWidget->currentPageIndex()) {
750 case 0: //playlist 750 case 0: //playlist
751 return; 751 return;
752 break; 752 break;
753 }; 753 };
754 // case 1: { 754 // case 1: {
755 DocLnk lnk; 755 DocLnk lnk;
756 QString filename; 756 QString filename;
757 757
758 filename=it->text(3); 758 filename=it->text(3);
759 lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name 759 lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name
760 lnk.setFile( filename ); //sets file name 760 lnk.setFile( filename ); //sets file name
761 d->selectedFiles->addToSelection( lnk); 761 d->selectedFiles->addToSelection( lnk);
762 762
763 if(tabWidget->currentPageIndex() == 0) 763 if(tabWidget->currentPageIndex() == 0)
764 writeCurrentM3u(); 764 writeCurrentM3u();
765 // tabWidget->setCurrentPage(0); 765 // tabWidget->setCurrentPage(0);
766 766
767 } 767 }
768} 768}
769 769
770void PlayListWidget::tabChanged(QWidget *) { 770void PlayListWidget::tabChanged(QWidget *) {
771 771
772 switch ( tabWidget->currentPageIndex()) { 772 switch ( tabWidget->currentPageIndex()) {
773 case 0: 773 case 0:
774 { 774 {
775 if( !tbDeletePlaylist->isHidden()) 775 if( !tbDeletePlaylist->isHidden())
776 tbDeletePlaylist->hide(); 776 tbDeletePlaylist->hide();
777 d->tbRemoveFromList->setEnabled(TRUE); 777 d->tbRemoveFromList->setEnabled(TRUE);
778 d->tbAddToList->setEnabled(FALSE); 778 d->tbAddToList->setEnabled(FALSE);
779 } 779 }
780 break; 780 break;
781 case 1: 781 case 1:
782 { 782 {
783 audioView->clear(); 783 audioView->clear();
784 populateAudioView(); 784 populateAudioView();
785 785
786 if( !tbDeletePlaylist->isHidden()) 786 if( !tbDeletePlaylist->isHidden())
787 tbDeletePlaylist->hide(); 787 tbDeletePlaylist->hide();
788 d->tbRemoveFromList->setEnabled(FALSE); 788 d->tbRemoveFromList->setEnabled(FALSE);
789 d->tbAddToList->setEnabled(TRUE); 789 d->tbAddToList->setEnabled(TRUE);
790 } 790 }
791 break; 791 break;
792 case 2: 792 case 2:
793 { 793 {
794 videoView->clear(); 794 videoView->clear();
795 populateVideoView(); 795 populateVideoView();
796 if( !tbDeletePlaylist->isHidden()) 796 if( !tbDeletePlaylist->isHidden())
797 tbDeletePlaylist->hide(); 797 tbDeletePlaylist->hide();
798 d->tbRemoveFromList->setEnabled(FALSE); 798 d->tbRemoveFromList->setEnabled(FALSE);
799 d->tbAddToList->setEnabled(TRUE); 799 d->tbAddToList->setEnabled(TRUE);
800 } 800 }
801 break; 801 break;
802 case 3: 802 case 3:
803 { 803 {
804 if( tbDeletePlaylist->isHidden()) 804 if( tbDeletePlaylist->isHidden())
805 tbDeletePlaylist->show(); 805 tbDeletePlaylist->show();
806 playLists->reread(); 806 playLists->reread();
807 } 807 }
808 break; 808 break;
809 }; 809 };
810} 810}
811 811
812void PlayListWidget::btnPlay(bool b) { 812void PlayListWidget::btnPlay(bool b) {
813 // mediaPlayerState->setPlaying(b); 813 // mediaPlayerState->setPlaying(b);
814 switch ( tabWidget->currentPageIndex()) { 814 switch ( tabWidget->currentPageIndex()) {
815 case 0: 815 case 0:
816 { 816 {
817 // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 817 // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1
818 // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { 818 // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) {
819 // QMessageBox::message("Note","You are trying to play\na malformed url."); 819 // QMessageBox::message("Note","You are trying to play\na malformed url.");
820 // } else { 820 // } else {
821 mediaPlayerState->setPlaying(b); 821 mediaPlayerState->setPlaying(b);
822 insanityBool=FALSE; 822 insanityBool=FALSE;
823 odebug << "insanity" << oendl; 823 odebug << "insanity" << oendl;
824 // } 824 // }
825 } 825 }
826 break; 826 break;
827 case 1: 827 case 1:
828 { 828 {
829 // d->selectedFiles->unSelect(); 829 // d->selectedFiles->unSelect();
830 addToSelection( audioView->currentItem() ); 830 addToSelection( audioView->currentItem() );
831 mediaPlayerState->setPlaying( b); 831 mediaPlayerState->setPlaying( b);
832 d->selectedFiles->removeSelected( ); 832 d->selectedFiles->removeSelected( );
833 d->selectedFiles->unSelect(); 833 d->selectedFiles->unSelect();
834 tabWidget->setCurrentPage(1); 834 tabWidget->setCurrentPage(1);
835 insanityBool=FALSE; 835 insanityBool=FALSE;
836 }// audioView->clearSelection(); 836 }// audioView->clearSelection();
837 break; 837 break;
838 case 2: 838 case 2:
839 { 839 {
840 840
841 addToSelection( videoView->currentItem() ); 841 addToSelection( videoView->currentItem() );
842 mediaPlayerState->setPlaying( b); 842 mediaPlayerState->setPlaying( b);
843 // qApp->processEvents(); 843 // qApp->processEvents();
844 d->selectedFiles->removeSelected( ); 844 d->selectedFiles->removeSelected( );
845 d->selectedFiles->unSelect(); 845 d->selectedFiles->unSelect();
846 tabWidget->setCurrentPage(2); 846 tabWidget->setCurrentPage(2);
847 insanityBool=FALSE; 847 insanityBool=FALSE;
848 }// videoView->clearSelection(); 848 }// videoView->clearSelection();
849 break; 849 break;
850 }; 850 };
851 851
852} 852}
853 853
854void PlayListWidget::deletePlaylist() { 854void PlayListWidget::deletePlaylist() {
855 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 855 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
856 (tr("You really want to delete\nthis playlist?")), 856 (tr("You really want to delete\nthis playlist?")),
857 (tr("Yes")), (tr("No")), 0 )){ 857 (tr("Yes")), (tr("No")), 0 )){
858 case 0: // Yes clicked, 858 case 0: // Yes clicked,
859 QFile().remove(playLists->selectedDocument().file()); 859 QFile().remove(playLists->selectedDocument().file());
860 QFile().remove(playLists->selectedDocument().linkFile()); 860 QFile().remove(playLists->selectedDocument().linkFile());
861 playLists->reread(); 861 playLists->reread();
862 break; 862 break;
863 case 1: // Cancel 863 case 1: // Cancel
864 break; 864 break;
865 }; 865 };
866} 866}
867 867
868void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint&, int ) 868void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint&, int )
869{ 869{
870 switch (mouse) { 870 switch (mouse) {
871 case 1: 871 case 1:
872 break; 872 break;
873 case 2:{ 873 case 2:{
874 874
875 QPopupMenu m; 875 QPopupMenu m;
876 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 876 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
877 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); 877 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
878 m.insertSeparator(); 878 m.insertSeparator();
879 if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) 879 if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() )
880 m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); 880 m.insertItem( tr( "Properties" ), this, SLOT( listDelete() ));
881 881
882 m.exec( QCursor::pos() ); 882 m.exec( QCursor::pos() );
883 } 883 }
884 break; 884 break;
885 }; 885 };
886} 886}
887 887
888void PlayListWidget::playSelected() 888void PlayListWidget::playSelected()
889{ 889{
890 btnPlay( true); 890 btnPlay( true);
891// d->selectedFiles->unSelect(); 891// d->selectedFiles->unSelect();
892} 892}
893 893
894void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint&, int) 894void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint&, int)
895{ 895{
896 switch (mouse) { 896 switch (mouse) {
897 case 1: 897 case 1:
898 898
899 break; 899 break;
900 case 2:{ 900 case 2:{
901 QPopupMenu m; 901 QPopupMenu m;
902 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 902 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
903 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 903 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
904 // m.insertSeparator(); 904 // m.insertSeparator();
905 // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); 905 // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() ));
906 m.exec( QCursor::pos() ); 906 m.exec( QCursor::pos() );
907 } 907 }
908 break; 908 break;
909 }; 909 };
910 910
911} 911}
912 912
913void PlayListWidget::listDelete() { 913void PlayListWidget::listDelete() {
914 Config cfg( "OpiePlayer" ); 914 Config cfg( "OpiePlayer" );
915 cfg.setGroup("PlayList"); 915 cfg.setGroup("PlayList");
916 currentPlayList = cfg.readEntry("CurrentPlaylist",""); 916 currentPlayList = cfg.readEntry("CurrentPlaylist","");
917 QString file; 917 QString file;
918 // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 918 // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
919 switch ( tabWidget->currentPageIndex()) { 919 switch ( tabWidget->currentPageIndex()) {
920 case 0: 920 case 0:
921 break; 921 break;
922 case 1: 922 case 1:
923 { 923 {
924 file = audioView->currentItem()->text(0); 924 file = audioView->currentItem()->text(0);
925 QListIterator<DocLnk> Pdit( files.children() ); 925 QListIterator<DocLnk> Pdit( files.children() );
926 for ( ; Pdit.current(); ++Pdit ) { 926 for ( ; Pdit.current(); ++Pdit ) {
927 if( Pdit.current()->name() == file) { 927 if( Pdit.current()->name() == file) {
928 LnkProperties prop( Pdit.current() ); 928 LnkProperties prop( Pdit.current() );
929 QPEApplication::execDialog( &prop ); 929 QPEApplication::execDialog( &prop );
930 } 930 }
931 } 931 }
932 populateAudioView(); 932 populateAudioView();
933 } 933 }
934 break; 934 break;
935 case 2: 935 case 2:
936 { 936 {
937 // file = videoView->selectedItem()->text(0); 937 // file = videoView->selectedItem()->text(0);
938 // for ( int i = 0; i < noOfFiles; i++ ) { 938 // for ( int i = 0; i < noOfFiles; i++ ) {
939 // QString entryName; 939 // QString entryName;
940 // entryName.sprintf( "File%i", i + 1 ); 940 // entryName.sprintf( "File%i", i + 1 );
941 // QString linkFile = cfg.readEntry( entryName ); 941 // QString linkFile = cfg.readEntry( entryName );
942 // AppLnk lnk( AppLnk(linkFile)); 942 // AppLnk lnk( AppLnk(linkFile));
943 // if( lnk.name() == file ) { 943 // if( lnk.name() == file ) {
944 // LnkProperties prop( &lnk); 944 // LnkProperties prop( &lnk);
945 // // connect(&prop, SIGNAL(select(const AppLnk*)), this, SLOT(externalSelected(const AppLnk*))); 945 // // connect(&prop, SIGNAL(select(const AppLnk*)), this, SLOT(externalSelected(const AppLnk*)));
946 // prop.showMaximized(); 946 // prop.showMaximized();
947 // prop.exec(); 947 // prop.exec();
948 // } 948 // }
949 // } 949 // }
950 } 950 }
951 break; 951 break;
952 }; 952 };
953} 953}
954 954
955void PlayListWidget::scanForAudio() { 955void PlayListWidget::scanForAudio() {
956 // odebug << "scan for audio" << oendl; 956 // odebug << "scan for audio" << oendl;
957 files.detachChildren(); 957 files.detachChildren();
958 QListIterator<DocLnk> sdit( files.children() ); 958 QListIterator<DocLnk> sdit( files.children() );
959 for ( ; sdit.current(); ++sdit ) { 959 for ( ; sdit.current(); ++sdit ) {
960 delete sdit.current(); 960 delete sdit.current();
961 } 961 }
962 Global::findDocuments( &files, audioMimes); 962 Global::findDocuments( &files, audioMimes);
963 audioScan = true; 963 audioScan = true;
964} 964}
965void PlayListWidget::scanForVideo() { 965void PlayListWidget::scanForVideo() {
966 // odebug << "scan for video" << oendl; 966 // odebug << "scan for video" << oendl;
967 vFiles.detachChildren(); 967 vFiles.detachChildren();
968 QListIterator<DocLnk> sdit( vFiles.children() ); 968 QListIterator<DocLnk> sdit( vFiles.children() );
969 for ( ; sdit.current(); ++sdit ) { 969 for ( ; sdit.current(); ++sdit ) {
970 delete sdit.current(); 970 delete sdit.current();
971 } 971 }
972 Global::findDocuments(&vFiles, "video/*"); 972 Global::findDocuments(&vFiles, "video/*");
973 videoScan = true; 973 videoScan = true;
974} 974}
975 975
976void PlayListWidget::populateAudioView() { 976void PlayListWidget::populateAudioView() {
977 977
978 audioView->clear(); 978 audioView->clear();
979 StorageInfo storageInfo; 979 StorageInfo storageInfo;
980 const QList<FileSystem> &fs = storageInfo.fileSystems(); 980 const QList<FileSystem> &fs = storageInfo.fileSystems();
981 if(!audioScan) scanForAudio(); 981 if(!audioScan) scanForAudio();
982 982
983 QListIterator<DocLnk> dit( files.children() ); 983 QListIterator<DocLnk> dit( files.children() );
984 QListIterator<FileSystem> it ( fs ); 984 QListIterator<FileSystem> it ( fs );
985 985
986 QString storage; 986 QString storage;
987 for ( ; dit.current(); ++dit ) { 987 for ( ; dit.current(); ++dit ) {
988 for( ; it.current(); ++it ){ 988 for( ; it.current(); ++it ){
989 const QString name = (*it)->name(); 989 const QString name = (*it)->name();
990 const QString path = (*it)->path(); 990 const QString path = (*it)->path();
991 if(dit.current()->file().find(path) != -1 ) storage=name; 991 if(dit.current()->file().find(path) != -1 ) storage=name;
992 } 992 }
993 993
994 QListViewItem * newItem; 994 QListViewItem * newItem;
995 if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { 995 if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) {
996 long size; 996 long size;
997 if( dit.current()->file().left(4) == "http" ) 997 if( dit.current()->file().left(4) == "http" )
998 size=0; 998 size=0;
999 else 999 else
1000 size = QFile( dit.current()->file() ).size(); 1000 size = QFile( dit.current()->file() ).size();
1001 // odebug << dit.current()->name() << oendl; 1001 // odebug << dit.current()->name() << oendl;
1002 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), 1002 newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(),
1003 QString::number(size ), storage, dit.current()->file()); 1003 QString::number(size ), storage, dit.current()->file());
1004 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); 1004 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" ));
1005 } 1005 }
1006 } 1006 }
1007 1007
1008} 1008}
1009 1009
1010void PlayListWidget::populateVideoView() { 1010void PlayListWidget::populateVideoView() {
1011 videoView->clear(); 1011 videoView->clear();
1012 StorageInfo storageInfo; 1012 StorageInfo storageInfo;
1013 const QList<FileSystem> &fs = storageInfo.fileSystems(); 1013 const QList<FileSystem> &fs = storageInfo.fileSystems();
1014 1014
1015 if(!videoScan ) scanForVideo(); 1015 if(!videoScan ) scanForVideo();
1016 1016
1017 QListIterator<DocLnk> Vdit( vFiles.children() ); 1017 QListIterator<DocLnk> Vdit( vFiles.children() );
1018 QListIterator<FileSystem> it ( fs ); 1018 QListIterator<FileSystem> it ( fs );
1019 videoView->clear(); 1019 videoView->clear();
1020 QString storage; 1020 QString storage;
1021 for ( ; Vdit.current(); ++Vdit ) { 1021 for ( ; Vdit.current(); ++Vdit ) {
1022 for( ; it.current(); ++it ){ 1022 for( ; it.current(); ++it ){
1023 const QString name = (*it)->name(); 1023 const QString name = (*it)->name();
1024 const QString path = (*it)->path(); 1024 const QString path = (*it)->path();
1025 if( Vdit.current()->file().find(path) != -1 ) storage=name; 1025 if( Vdit.current()->file().find(path) != -1 ) storage=name;
1026 } 1026 }
1027 1027
1028 QListViewItem * newItem; 1028 QListViewItem * newItem;
1029 if ( QFile( Vdit.current()->file()).exists() ) { 1029 if ( QFile( Vdit.current()->file()).exists() ) {
1030 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), 1030 newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(),
1031 QString::number( QFile( Vdit.current()->file() ).size() ), 1031 QString::number( QFile( Vdit.current()->file() ).size() ),
1032 storage, Vdit.current()->file()); 1032 storage, Vdit.current()->file());
1033 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); 1033 newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" ));
1034 } 1034 }
1035 } 1035 }
1036} 1036}
1037 1037
1038void PlayListWidget::openFile() { 1038void PlayListWidget::openFile() {
1039 QString filename, name; 1039 QString filename, name;
1040 InputDialog *fileDlg; 1040 InputDialog *fileDlg;
1041 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); 1041 fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0);
1042 fileDlg->exec(); 1042 fileDlg->exec();
1043 if( fileDlg->result() == 1 ) { 1043 if( fileDlg->result() == 1 ) {
1044 filename = fileDlg->text(); 1044 filename = fileDlg->text();
1045 // odebug << "Selected filename is " + filename << oendl; 1045 // odebug << "Selected filename is " + filename << oendl;
1046 DocLnk lnk; 1046 DocLnk lnk;
1047 Config cfg( "OpiePlayer" ); 1047 Config cfg( "OpiePlayer" );
1048 cfg.setGroup("PlayList"); 1048 cfg.setGroup("PlayList");
1049 1049
1050 QString m3uFile; 1050 QString m3uFile;
1051 m3uFile = filename; 1051 m3uFile = filename;
1052 if(filename.left(4) == "http") { 1052 if(filename.left(4) == "http") {
1053 if(filename.find(":",8,TRUE) != -1) { //found a port 1053 if(filename.find(":",8,TRUE) != -1) { //found a port
1054 1054
1055 m3uFile = filename; 1055 m3uFile = filename;
1056 if( m3uFile.right( 1 ).find( '/' ) == -1) { 1056 if( m3uFile.right( 1 ).find( '/' ) == -1) {
1057 m3uFile += "/"; 1057 m3uFile += "/";
1058 } 1058 }
1059 filename = m3uFile; 1059 filename = m3uFile;
1060 } 1060 }
1061 lnk.setName( m3uFile ); //sets name 1061 lnk.setName( m3uFile ); //sets name
1062 lnk.setFile( filename ); //sets file name 1062 lnk.setFile( filename ); //sets file name
1063 lnk.setIcon("opieplayer2/musicfile"); 1063 lnk.setIcon("opieplayer2/musicfile");
1064 d->selectedFiles->addToSelection( lnk ); 1064 d->selectedFiles->addToSelection( lnk );
1065 writeCurrentM3u(); 1065 writeCurrentM3u();
1066 } 1066 }
1067 else if( filename.right( 3) == "m3u" ) { 1067 else if( filename.right( 3) == "m3u" ) {
1068 readm3u( filename ); 1068 readm3u( filename );
1069 1069
1070 } else if( filename.right(3) == "pls" ) { 1070 } else if( filename.right(3) == "pls" ) {
1071 readPls( filename ); 1071 readPls( filename );
1072 } else { 1072 } else {
1073 lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name 1073 lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name
1074 lnk.setFile( filename ); //sets file name 1074 lnk.setFile( filename ); //sets file name
1075 d->selectedFiles->addToSelection( lnk); 1075 d->selectedFiles->addToSelection( lnk);
1076 lnk.removeLinkFile(); 1076 lnk.removeLinkFile();
1077 writeCurrentM3u(); 1077 writeCurrentM3u();
1078 } 1078 }
1079 } 1079 }
1080 1080
1081 if( fileDlg ) { 1081 if( fileDlg ) {
1082 delete fileDlg; 1082 delete fileDlg;
1083 } 1083 }
1084} 1084}
1085 1085
1086 1086
1087/* 1087/*
1088reads m3u and shows files/urls to playlist widget */ 1088reads m3u and shows files/urls to playlist widget */
1089void PlayListWidget::readm3u( const QString &filename ) { 1089void PlayListWidget::readm3u( const QString &filename ) {
1090 // odebug << "read m3u filename " + filename << oendl; 1090 // odebug << "read m3u filename " + filename << oendl;
1091 1091
1092 Om3u *m3uList; 1092 Om3u *m3uList;
1093 QString s, name; 1093 QString s, name;
1094 m3uList = new Om3u( filename, IO_ReadOnly ); 1094 m3uList = new Om3u( filename, IO_ReadOnly );
1095 m3uList->readM3u(); 1095 m3uList->readM3u();
1096 DocLnk lnk; 1096 DocLnk lnk;
1097 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 1097 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
1098 s = *it; 1098 s = *it;
1099 // odebug << "reading "+ s << oendl; 1099 // odebug << "reading "+ s << oendl;
1100 if(s.left(4)=="http") { 1100 if(s.left(4)=="http") {
1101 lnk.setName( s ); //sets file name 1101 lnk.setName( s ); //sets file name
1102 lnk.setIcon("opieplayer2/musicfile"); 1102 lnk.setIcon("opieplayer2/musicfile");
1103 1103
1104 // if(s.right(4) != '.' || s.right(5) != '.') 1104 // if(s.right(4) != '.' || s.right(5) != '.')
1105 if(s.right(4) != '.' || s.right(5) != '.' ) 1105 if(s.right(4) != '.' || s.right(5) != '.' )
1106 if( s.right(1) != "/") 1106 if( s.right(1) != "/")
1107 lnk.setFile( s+"/"); //if url with no extension 1107 lnk.setFile( s+"/"); //if url with no extension
1108 else 1108 else
1109 lnk.setFile( s ); //sets file name 1109 lnk.setFile( s ); //sets file name
1110 1110
1111 } else { 1111 } else {
1112 // if( QFileInfo( s ).exists() ) { 1112 // if( QFileInfo( s ).exists() ) {
1113 lnk.setName( fullBaseName ( QFileInfo(s))); 1113 lnk.setName( fullBaseName ( QFileInfo(s)));
1114 // if(s.right(4) == '.') {//if regular file 1114 // if(s.right(4) == '.') {//if regular file
1115 if(s.left(1) != "/") { 1115 if(s.left(1) != "/") {
1116 // odebug << "set link "+QFileInfo(filename).dirPath()+"/"+s << oendl; 1116 // odebug << "set link "+QFileInfo(filename).dirPath()+"/"+s << oendl;
1117 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); 1117 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s);
1118 lnk.setIcon("SoundPlayer"); 1118 lnk.setIcon("SoundPlayer");
1119 } else { 1119 } else {
1120 // odebug << "set link2 "+s << oendl; 1120 // odebug << "set link2 "+s << oendl;
1121 lnk.setFile( s); 1121 lnk.setFile( s);
1122 lnk.setIcon("SoundPlayer"); 1122 lnk.setIcon("SoundPlayer");
1123 } 1123 }
1124 } 1124 }
1125 d->selectedFiles->addToSelection( lnk ); 1125 d->selectedFiles->addToSelection( lnk );
1126 } 1126 }
1127 Config config( "OpiePlayer" ); 1127 Config config( "OpiePlayer" );
1128 config.setGroup( "PlayList" ); 1128 config.setGroup( "PlayList" );
1129 1129
1130 config.writeEntry("CurrentPlaylist",filename); 1130 config.writeEntry("CurrentPlaylist",filename);
1131 config.write(); 1131 config.write();
1132 currentPlayList=filename; 1132 currentPlayList=filename;
1133 1133
1134// m3uList->write(); 1134// m3uList->write();
1135 m3uList->close(); 1135 m3uList->close();
1136 if(m3uList) delete m3uList; 1136 if(m3uList) delete m3uList;
1137 1137
1138 d->selectedFiles->setSelectedItem( s); 1138 d->selectedFiles->setSelectedItem( s);
1139 setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); 1139 setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename)));
1140 1140
1141} 1141}
1142 1142
1143/* 1143/*
1144reads pls and adds files/urls to playlist */ 1144reads pls and adds files/urls to playlist */
1145void PlayListWidget::readPls( const QString &filename ) { 1145void PlayListWidget::readPls( const QString &filename ) {
1146 1146
1147 // odebug << "pls filename is " + filename << oendl; 1147 // odebug << "pls filename is " + filename << oendl;
1148 Om3u *m3uList; 1148 Om3u *m3uList;
1149 QString s, name; 1149 QString s, name;
1150 m3uList = new Om3u( filename, IO_ReadOnly ); 1150 m3uList = new Om3u( filename, IO_ReadOnly );
1151 m3uList->readPls(); 1151 m3uList->readPls();
1152 1152
1153 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 1153 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
1154 s = *it; 1154 s = *it;
1155 // s.replace( QRegExp( "%20" )," " ); 1155 // s.replace( QRegExp( "%20" )," " );
1156 DocLnk lnk( s ); 1156 DocLnk lnk( s );
1157 QFileInfo f( s ); 1157 QFileInfo f( s );
1158 QString name = fullBaseName ( f); 1158 QString name = fullBaseName ( f);
1159 1159
1160 if( name.left( 4 ) == "http" ) { 1160 if( name.left( 4 ) == "http" ) {
1161 name = s.right( s.length() - 7); 1161 name = s.right( s.length() - 7);
1162 } else { 1162 } else {
1163 name = s; 1163 name = s;
1164 } 1164 }
1165 1165
1166 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); 1166 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
1167 1167
1168 lnk.setName( name ); 1168 lnk.setName( name );
1169 if( s.at( s.length() - 4) == '.') {// if this is probably a file 1169 if( s.at( s.length() - 4) == '.') {// if this is probably a file
1170 lnk.setFile( s ); 1170 lnk.setFile( s );
1171 } else { //if its a url 1171 } else { //if its a url
1172 if( name.right( 1 ).find( '/' ) == -1) { 1172 if( name.right( 1 ).find( '/' ) == -1) {
1173 s += "/"; 1173 s += "/";
1174 } 1174 }
1175 lnk.setFile( s ); 1175 lnk.setFile( s );
1176 } 1176 }
1177 lnk.setType( "audio/x-mpegurl" ); 1177 lnk.setType( "audio/x-mpegurl" );
1178 1178
1179 lnk.writeLink(); 1179 lnk.writeLink();
1180 d->selectedFiles->addToSelection( lnk ); 1180 d->selectedFiles->addToSelection( lnk );
1181 } 1181 }
1182 1182
1183 m3uList->close(); 1183 m3uList->close();
1184 if(m3uList) delete m3uList; 1184 if(m3uList) delete m3uList;
1185} 1185}
1186 1186
1187/* 1187/*
1188 writes current playlist to current m3u file */ 1188 writes current playlist to current m3u file */
1189void PlayListWidget::writeCurrentM3u() { 1189void PlayListWidget::writeCurrentM3u() {
1190 // odebug << "writing to current m3u" << oendl; 1190 // odebug << "writing to current m3u" << oendl;
1191 Config cfg( "OpiePlayer" ); 1191 Config cfg( "OpiePlayer" );
1192 cfg.setGroup("PlayList"); 1192 cfg.setGroup("PlayList");
1193 currentPlayList = cfg.readEntry("CurrentPlaylist",""); 1193 currentPlayList = cfg.readEntry("CurrentPlaylist","");
1194 Om3u *m3uList; 1194 Om3u *m3uList;
1195 m3uList = new Om3u( currentPlayList, IO_ReadWrite | IO_Truncate ); 1195 m3uList = new Om3u( currentPlayList, IO_ReadWrite | IO_Truncate );
1196 1196
1197 if( d->selectedFiles->first()) { 1197 if( d->selectedFiles->first()) {
1198 do { 1198 do {
1199 // odebug << "writeCurrentM3u " +d->selectedFiles->current()->file() << oendl; 1199 // odebug << "writeCurrentM3u " +d->selectedFiles->current()->file() << oendl;
1200 m3uList->add( d->selectedFiles->current()->file() ); 1200 m3uList->add( d->selectedFiles->current()->file() );
1201 } 1201 }
1202 while ( d->selectedFiles->next() ); 1202 while ( d->selectedFiles->next() );
1203 // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl; 1203 // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl;
1204 m3uList->write(); 1204 m3uList->write();
1205 m3uList->close(); 1205 m3uList->close();
1206 1206
1207 if(m3uList) delete m3uList; 1207 if(m3uList) delete m3uList;
1208 } 1208 }
1209} 1209}
1210 1210
1211 /* 1211 /*
1212 writes current playlist to m3u file */ 1212 writes current playlist to m3u file */
1213void PlayListWidget::writem3u() { 1213void PlayListWidget::writem3u() {
1214 InputDialog *fileDlg; 1214 InputDialog *fileDlg;
1215 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); 1215 fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0);
1216 fileDlg->exec(); 1216 fileDlg->exec();
1217 QString name, filename, list; 1217 QString name, filename, list;
1218 Om3u *m3uList; 1218 Om3u *m3uList;
1219 1219
1220 if( fileDlg->result() == 1 ) { 1220 if( fileDlg->result() == 1 ) {
1221 name = fileDlg->text(); 1221 name = fileDlg->text();
1222 // odebug << filename << oendl; 1222 // odebug << filename << oendl;
1223 if( name.find("/",0,true) != -1) {// assume they specify a file path 1223 if( name.find("/",0,true) != -1) {// assume they specify a file path
1224 filename = name; 1224 filename = name;
1225 name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); 1225 name = name.right(name.length()- name.findRev("/",-1,true) - 1 );
1226 } 1226 }
1227 else //otherwise dump it somewhere noticable 1227 else //otherwise dump it somewhere noticable
1228 filename = QPEApplication::documentDir() + "/" + name; 1228 filename = QPEApplication::documentDir() + "/" + name;
1229 1229
1230 if( filename.right( 3 ) != "m3u" ) //needs filename extension 1230 if( filename.right( 3 ) != "m3u" ) //needs filename extension
1231 filename += ".m3u"; 1231 filename += ".m3u";
1232 1232
1233 if( d->selectedFiles->first()) { 1233 if( d->selectedFiles->first()) {
1234 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); 1234 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate);
1235 1235
1236 do { 1236 do {
1237 m3uList->add( d->selectedFiles->current()->file()); 1237 m3uList->add( d->selectedFiles->current()->file());
1238 } 1238 }
1239 while ( d->selectedFiles->next() ); 1239 while ( d->selectedFiles->next() );
1240 // odebug << list << oendl; 1240 // odebug << list << oendl;
1241 m3uList->write(); 1241 m3uList->write();
1242 m3uList->close(); 1242 m3uList->close();
1243 if(m3uList) delete m3uList; 1243 if(m3uList) delete m3uList;
1244 1244
1245 if(fileDlg) delete fileDlg; 1245 if(fileDlg) delete fileDlg;
1246 1246
1247 DocLnk lnk; 1247 DocLnk lnk;
1248 lnk.setFile( filename); 1248 lnk.setFile( filename);
1249 lnk.setIcon("opieplayer2/playlist2"); 1249 lnk.setIcon("opieplayer2/playlist2");
1250 lnk.setName( name); //sets file name 1250 lnk.setName( name); //sets file name
1251 1251
1252 // odebug << filename << oendl; 1252 // odebug << filename << oendl;
1253 Config config( "OpiePlayer" ); 1253 Config config( "OpiePlayer" );
1254 config.setGroup( "PlayList" ); 1254 config.setGroup( "PlayList" );
1255 1255
1256 config.writeEntry("CurrentPlaylist",filename); 1256 config.writeEntry("CurrentPlaylist",filename);
1257 currentPlayList=filename; 1257 currentPlayList=filename;
1258 1258
1259 if(!lnk.writeLink()) { 1259 if(!lnk.writeLink()) {
1260 // odebug << "Writing doclink did not work" << oendl; 1260 // odebug << "Writing doclink did not work" << oendl;
1261 } 1261 }
1262 1262
1263 setCaption(tr("OpiePlayer: ") + name); 1263 setCaption(tr("OpiePlayer: ") + name);
1264 } 1264 }
1265 } 1265 }
1266} 1266}
1267 1267
1268 1268
1269void PlayListWidget::keyReleaseEvent( QKeyEvent *e) 1269void PlayListWidget::keyReleaseEvent( QKeyEvent *e)
1270{ 1270{
1271 switch ( e->key() ) { 1271 switch ( e->key() ) {
1272////////////////////////////// Zaurus keys 1272////////////////////////////// Zaurus keys
1273 case Key_F9: //activity 1273 case Key_F9: //activity
1274// if(audioUI->isHidden()) 1274// if(audioUI->isHidden())
1275// audioUI->showMaximized(); 1275// audioUI->showMaximized();
1276 break; 1276 break;
1277 case Key_F10: //contacts 1277 case Key_F10: //contacts
1278// if( videoUI->isHidden()) 1278// if( videoUI->isHidden())
1279// videoUI->showMaximized(); 1279// videoUI->showMaximized();
1280 break; 1280 break;
1281 case Key_F11: //menu 1281 case Key_F11: //menu
1282 break; 1282 break;
1283 case Key_F12: //home 1283 case Key_F12: //home
1284// doBlank(); 1284// doBlank();
1285 break; 1285 break;
1286 case Key_F13: //mail 1286 case Key_F13: //mail
1287// doUnblank(); 1287// doUnblank();
1288 break; 1288 break;
1289 case Key_Q: //add to playlist 1289 case Key_Q: //add to playlist
1290 addSelected(); 1290 addSelected();
1291 break; 1291 break;
1292 case Key_R: //remove from playlist 1292 case Key_R: //remove from playlist
1293 removeSelected(); 1293 removeSelected();
1294 break; 1294 break;
1295// case Key_P: //play 1295// case Key_P: //play
1296// odebug << "Play" << oendl; 1296// odebug << "Play" << oendl;
1297// playSelected(); 1297// playSelected();
1298// break; 1298// break;
1299 case Key_Space: 1299 case Key_Space:
1300// playSelected(); puh 1300// playSelected(); puh
1301 break; 1301 break;
1302 case Key_1: 1302 case Key_1:
1303 tabWidget->setCurrentPage(0); 1303 tabWidget->setCurrentPage(0);
1304 break; 1304 break;
1305 case Key_2: 1305 case Key_2:
1306 tabWidget->setCurrentPage(1); 1306 tabWidget->setCurrentPage(1);
1307 break; 1307 break;
1308 case Key_3: 1308 case Key_3:
1309 tabWidget->setCurrentPage(2); 1309 tabWidget->setCurrentPage(2);
1310 break; 1310 break;
1311 case Key_4: 1311 case Key_4:
1312 tabWidget->setCurrentPage(3); 1312 tabWidget->setCurrentPage(3);
1313 break; 1313 break;
1314 case Key_Down: 1314 case Key_Down:
1315 if ( !d->selectedFiles->next() ) 1315 if ( !d->selectedFiles->next() )
1316 d->selectedFiles->first(); 1316 d->selectedFiles->first();
1317 1317
1318 break; 1318 break;
1319 case Key_Up: 1319 case Key_Up:
1320 if ( !d->selectedFiles->prev() ) 1320 if ( !d->selectedFiles->prev() )
1321 // d->selectedFiles->last(); 1321 // d->selectedFiles->last();
1322 1322
1323 break; 1323 break;
1324 1324
1325 } 1325 }
1326} 1326}
1327 1327
1328void PlayListWidget::keyPressEvent( QKeyEvent *) 1328void PlayListWidget::keyPressEvent( QKeyEvent *)
1329{ 1329{
1330// odebug << "Key press" << oendl; 1330// odebug << "Key press" << oendl;
1331// switch ( e->key() ) { 1331// switch ( e->key() ) {
1332// ////////////////////////////// Zaurus keys 1332// ////////////////////////////// Zaurus keys
1333// case Key_A: //add to playlist 1333// case Key_A: //add to playlist
1334// odebug << "Add" << oendl; 1334// odebug << "Add" << oendl;
1335// addSelected(); 1335// addSelected();
1336// break; 1336// break;
1337// case Key_R: //remove from playlist 1337// case Key_R: //remove from playlist
1338// removeSelected(); 1338// removeSelected();
1339// break; 1339// break;
1340// case Key_P: //play 1340// case Key_P: //play
1341// odebug << "Play" << oendl; 1341// odebug << "Play" << oendl;
1342// playSelected(); 1342// playSelected();
1343// break; 1343// break;
1344// case Key_Space: 1344// case Key_Space:
1345// odebug << "Play" << oendl; 1345// odebug << "Play" << oendl;
1346// playSelected(); 1346// playSelected();
1347// break; 1347// break;
1348// } 1348// }
1349} 1349}
1350 1350
1351void PlayListWidget::doBlank() { 1351void PlayListWidget::doBlank() {
1352 // odebug << "do blanking" << oendl; 1352 // odebug << "do blanking" << oendl;
1353#ifdef QT_QWS_DEVFS 1353#ifdef QT_QWS_DEVFS
1354 fd=open("/dev/fb/0",O_RDWR); 1354 fd=open("/dev/fb/0",O_RDWR);
1355#else 1355#else
1356 fd=open("/dev/fb0",O_RDWR); 1356 fd=open("/dev/fb0",O_RDWR);
1357#endif 1357#endif
1358 if (fd != -1) { 1358 if (fd != -1) {
1359 ioctl(fd,FBIOBLANK,1); 1359 ioctl(fd,FBIOBLANK,1);
1360 // close(fd); 1360 // close(fd);
1361 } 1361 }
1362} 1362}
1363 1363
1364void PlayListWidget::doUnblank() { 1364void PlayListWidget::doUnblank() {
1365 // this crashes opieplayer with a segfault 1365 // this crashes opieplayer with a segfault
1366 // int fd; 1366 // int fd;
1367 // fd=open("/dev/fb0",O_RDWR); 1367 // fd=open("/dev/fb0",O_RDWR);
1368 // odebug << "do unblanking" << oendl; 1368 // odebug << "do unblanking" << oendl;
1369 if (fd != -1) { 1369 if (fd != -1) {
1370 ioctl(fd,FBIOBLANK,0); 1370 ioctl(fd,FBIOBLANK,0);
1371 close(fd); 1371 close(fd);
1372 } 1372 }
1373 QCopEnvelope h("QPE/System", "setBacklight(int)"); 1373 QCopEnvelope h("QPE/System", "setBacklight(int)");
1374 h <<-3;// v[1]; // -3 Force on 1374 h <<-3;// v[1]; // -3 Force on
1375} 1375}
1376 1376
1377void PlayListWidget::populateSkinsMenu() { 1377void PlayListWidget::populateSkinsMenu() {
1378 int item = 0; 1378 int item = 0;
1379 defaultSkinIndex = 0; 1379 defaultSkinIndex = 0;
1380 QString skinName; 1380 QString skinName;
1381 Config cfg( "OpiePlayer" ); 1381 Config cfg( "OpiePlayer" );
1382 cfg.setGroup("Options" ); 1382 cfg.setGroup("Options" );
1383 QString skin = cfg.readEntry( "Skin", "default" ); 1383 QString skin = cfg.readEntry( "Skin", "default" );
1384 1384
1385 QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); 1385 QDir skinsDir( QPEApplication::qpeDir() + "pics/opieplayer2/skins" );
1386 skinsDir.setFilter( QDir::Dirs ); 1386 skinsDir.setFilter( QDir::Dirs );
1387 skinsDir.setSorting(QDir::Name ); 1387 skinsDir.setSorting(QDir::Name );
1388 const QFileInfoList *skinslist = skinsDir.entryInfoList(); 1388 const QFileInfoList *skinslist = skinsDir.entryInfoList();
1389 QFileInfoListIterator it( *skinslist ); 1389 QFileInfoListIterator it( *skinslist );
1390 QFileInfo *fi; 1390 QFileInfo *fi;
1391 while ( ( fi = it.current() ) ) { 1391 while ( ( fi = it.current() ) ) {
1392 skinName = fi->fileName(); 1392 skinName = fi->fileName();
1393 // odebug << fi->fileName() << oendl; 1393 // odebug << fi->fileName() << oendl;
1394 if( skinName != "." && skinName != ".." && skinName !="CVS" ) { 1394 if( skinName != "." && skinName != ".." && skinName !="CVS" ) {
1395 item = skinsMenu->insertItem( fi->fileName() ) ; 1395 item = skinsMenu->insertItem( fi->fileName() ) ;
1396 } 1396 }
1397 if( skinName == "default" ) { 1397 if( skinName == "default" ) {
1398 defaultSkinIndex = item; 1398 defaultSkinIndex = item;
1399 } 1399 }
1400 if( skinName == skin ) { 1400 if( skinName == skin ) {
1401 skinsMenu->setItemChecked( item, TRUE ); 1401 skinsMenu->setItemChecked( item, TRUE );
1402 } 1402 }
1403 ++it; 1403 ++it;
1404 } 1404 }
1405} 1405}
1406 1406
1407void PlayListWidget::skinsMenuActivated( int item ) { 1407void PlayListWidget::skinsMenuActivated( int item ) {
1408 for( int i = defaultSkinIndex; i > defaultSkinIndex - static_cast<int>(skinsMenu->count()); i-- ) { 1408 for( int i = defaultSkinIndex; i > defaultSkinIndex - static_cast<int>(skinsMenu->count()); i-- ) {
1409 skinsMenu->setItemChecked( i, FALSE ); 1409 skinsMenu->setItemChecked( i, FALSE );
1410 } 1410 }
1411 skinsMenu->setItemChecked( item, TRUE ); 1411 skinsMenu->setItemChecked( item, TRUE );
1412 1412
1413 Config cfg( "OpiePlayer" ); 1413 Config cfg( "OpiePlayer" );
1414 cfg.setGroup("Options"); 1414 cfg.setGroup("Options");
1415 cfg.writeEntry("Skin", skinsMenu->text( item ) ); 1415 cfg.writeEntry("Skin", skinsMenu->text( item ) );
1416} 1416}
1417 1417
1418void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { 1418void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) {
1419 // odebug << "qcop message "+msg << oendl; 1419 // odebug << "qcop message "+msg << oendl;
1420 QDataStream stream ( data, IO_ReadOnly ); 1420 QDataStream stream ( data, IO_ReadOnly );
1421 if ( msg == "play()" ) { //plays current selection 1421 if ( msg == "play()" ) { //plays current selection
1422 btnPlay( true); 1422 btnPlay( true);
1423 } else if ( msg == "stop()" ) { 1423 } else if ( msg == "stop()" ) {
1424 mediaPlayerState->setPlaying( false); 1424 mediaPlayerState->setPlaying( false);
1425 } else if ( msg == "togglePause()" ) { 1425 } else if ( msg == "togglePause()" ) {
1426 mediaPlayerState->togglePaused(); 1426 mediaPlayerState->togglePaused();
1427 } else if ( msg == "next()" ) { //select next in lis 1427 } else if ( msg == "next()" ) { //select next in lis
1428 mediaPlayerState->setNext(); 1428 mediaPlayerState->setNext();
1429 } else if ( msg == "prev()" ) { //select previous in list 1429 } else if ( msg == "prev()" ) { //select previous in list
1430 mediaPlayerState->setPrev(); 1430 mediaPlayerState->setPrev();
1431 } else if ( msg == "toggleLooping()" ) { //loop or not loop 1431 } else if ( msg == "toggleLooping()" ) { //loop or not loop
1432 mediaPlayerState->toggleLooping(); 1432 mediaPlayerState->toggleLooping();
1433 } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled 1433 } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled
1434 mediaPlayerState->toggleShuffled(); 1434 mediaPlayerState->toggleShuffled();
1435 } else if ( msg == "volUp()" ) { //volume more 1435 } else if ( msg == "volUp()" ) { //volume more
1436 // emit moreClicked(); 1436 // emit moreClicked();
1437 // emit moreReleased(); 1437 // emit moreReleased();
1438 } else if ( msg == "volDown()" ) { //volume less 1438 } else if ( msg == "volDown()" ) { //volume less
1439 // emit lessClicked(); 1439 // emit lessClicked();
1440 // emit lessReleased(); 1440 // emit lessReleased();
1441 } else if ( msg == "play(QString)" ) { //play this now 1441 } else if ( msg == "play(QString)" ) { //play this now
1442 QString file; 1442 QString file;
1443 stream >> file; 1443 stream >> file;
1444 setDocumentEx( (const QString &) file); 1444 setDocumentEx( (const QString &) file);
1445 } else if ( msg == "add(QString)" ) { //add to playlist 1445 } else if ( msg == "add(QString)" ) { //add to playlist
1446 QString file; 1446 QString file;
1447 stream >> file; 1447 stream >> file;
1448 QFileInfo fileInfo(file); 1448 QFileInfo fileInfo(file);
1449 DocLnk lnk; 1449 DocLnk lnk;
1450 lnk.setName( fileInfo.baseName() ); //sets name 1450 lnk.setName( fileInfo.baseName() ); //sets name
1451 lnk.setFile( file ); //sets file name 1451 lnk.setFile( file ); //sets file name
1452 addToSelection( lnk ); 1452 addToSelection( lnk );
1453 } else if ( msg == "rem(QString)" ) { //remove from playlist 1453 } else if ( msg == "rem(QString)" ) { //remove from playlist
1454 QString file; 1454 QString file;
1455 stream >> file; 1455 stream >> file;
1456 } else if ( msg == "setDocument(QString)" ) { //loop or not loop 1456 } else if ( msg == "setDocument(QString)" ) { //loop or not loop
1457 QCopEnvelope h("QPE/Application/opieplayer", "raise()"); 1457 QCopEnvelope h("QPE/Application/opieplayer", "raise()");
1458 } 1458 }
1459} 1459}
diff --git a/core/multimedia/opieplayer/videowidget.cpp b/core/multimedia/opieplayer/videowidget.cpp
index 2396ed5..c545511 100644
--- a/core/multimedia/opieplayer/videowidget.cpp
+++ b/core/multimedia/opieplayer/videowidget.cpp
@@ -1,680 +1,680 @@
1/********************************************************************** 1/**********************************************************************
2 ** Copyright (C) 2000 Trolltech AS. All rights reserved. 2 ** Copyright (C) 2000 Trolltech AS. All rights reserved.
3 ** 3 **
4 ** This file is part of Qtopia Environment. 4 ** This file is part of Qtopia Environment.
5 ** 5 **
6 ** This file may be distributed and/or modified under the terms of the 6 ** This file may be distributed and/or modified under the terms of the
7 ** GNU General Public License version 2 as published by the Free Software 7 ** GNU General Public License version 2 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.GPL included in the 8 ** Foundation and appearing in the file LICENSE.GPL included in the
9 ** packaging of this file. 9 ** packaging of this file.
10 ** 10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 ** 13 **
14 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 14 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
15 ** 15 **
16 ** Contact info@trolltech.com if any conditions of this licensing are 16 ** Contact info@trolltech.com if any conditions of this licensing are
17 ** not clear to you. 17 ** not clear to you.
18 ** 18 **
19 **********************************************************************/ 19 **********************************************************************/
20 20
21#include "videowidget.h" 21#include "videowidget.h"
22#include "mediaplayerstate.h" 22#include "mediaplayerstate.h"
23 23
24/* OPIE */ 24/* OPIE */
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/mediaplayerplugininterface.h> 26#include <qpe/mediaplayerplugininterface.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
29#include <opie2/odebug.h> 29#include <opie2/odebug.h>
30 30
31/* QT */ 31/* QT */
32#include <qdir.h> 32#include <qdir.h>
33#include <qslider.h> 33#include <qslider.h>
34 34
35 35
36#ifdef Q_WS_QWS 36#ifdef Q_WS_QWS
37# define USE_DIRECT_PAINTER 37# define USE_DIRECT_PAINTER
38# include <qdirectpainter_qws.h> 38# include <qdirectpainter_qws.h>
39# include <qgfxraster_qws.h> 39# include <qgfxraster_qws.h>
40#endif 40#endif
41 41
42 42
43extern MediaPlayerState *mediaPlayerState; 43extern MediaPlayerState *mediaPlayerState;
44 44
45 45
46static const int xo = 2; // movable x offset 46static const int xo = 2; // movable x offset
47static const int yo = 0; // movable y offset 47static const int yo = 0; // movable y offset
48 48
49 49
50struct MediaButton { 50struct MediaButton {
51// int xPos, yPos; 51// int xPos, yPos;
52 bool isToggle, isHeld, isDown; 52 bool isToggle, isHeld, isDown;
53// int controlType; 53// int controlType;
54}; 54};
55 55
56 56
57// Layout information for the videoButtons (and if it is a toggle button or not) 57// Layout information for the videoButtons (and if it is a toggle button or not)
58MediaButton videoButtons[] = { 58MediaButton videoButtons[] = {
59 { FALSE, FALSE, FALSE }, // stop 59 { FALSE, FALSE, FALSE }, // stop
60 { FALSE, FALSE, FALSE }, // play 60 { FALSE, FALSE, FALSE }, // play
61 { FALSE, FALSE, FALSE }, // previous 61 { FALSE, FALSE, FALSE }, // previous
62 { FALSE, FALSE, FALSE }, // next 62 { FALSE, FALSE, FALSE }, // next
63 { FALSE, FALSE, FALSE }, // volUp 63 { FALSE, FALSE, FALSE }, // volUp
64 { FALSE, FALSE, FALSE }, // volDown 64 { FALSE, FALSE, FALSE }, // volDown
65 { TRUE, FALSE, FALSE } // fullscreen 65 { TRUE, FALSE, FALSE } // fullscreen
66}; 66};
67 67
68//static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton)); 68//static const int numButtons = (sizeof(videoButtons)/sizeof(MediaButton));
69 69
70const char *skinV_mask_file_names[7] = { 70const char *skinV_mask_file_names[7] = {
71 "stop","play","back","fwd","up","down","full" 71 "stop","play","back","fwd","up","down","full"
72}; 72};
73 73
74static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton)); 74static const int numVButtons = (sizeof(videoButtons)/sizeof(MediaButton));
75 75
76VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) : 76VideoWidget::VideoWidget(QWidget* parent, const char* name, WFlags f) :
77 QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 ) 77 QWidget( parent, name, f ), scaledWidth( 0 ), scaledHeight( 0 )
78{ 78{
79 setCaption( tr("OpiePlayer") ); 79 setCaption( tr("OpiePlayer") );
80 Config cfg("OpiePlayer"); 80 Config cfg("OpiePlayer");
81 81
82 cfg.setGroup("Options"); 82 cfg.setGroup("Options");
83 skin = cfg.readEntry("Skin","default"); 83 skin = cfg.readEntry("Skin","default");
84 84
85 QString skinPath; 85 QString skinPath;
86 skinPath = "opieplayer2/skins/" + skin; 86 skinPath = "opieplayer2/skins/" + skin;
87 if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists()) 87 if(!QDir(QString(getenv("OPIEDIR")) +"/pics/"+skinPath).exists())
88 skinPath = "opieplayer2/skins/default"; 88 skinPath = "opieplayer2/skins/default";
89 89
90 90
91// QString skinPath = "opieplayer2/skins/" + skin; 91// QString skinPath = "opieplayer2/skins/" + skin;
92 92
93 pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) ); 93 pixBg = new QPixmap( Resource::loadPixmap( QString("%1/background").arg(skinPath) ) );
94 imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) ); 94 imgUp = new QImage( Resource::loadImage( QString("%1/skinV_up").arg(skinPath) ) );
95 imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) ); 95 imgDn = new QImage( Resource::loadImage( QString("%1/skinV_down").arg(skinPath) ) );
96 96
97 imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 ); 97 imgButtonMask = new QImage( imgUp->width(), imgUp->height(), 8, 255 );
98 imgButtonMask->fill( 0 ); 98 imgButtonMask->fill( 0 );
99 99
100 for ( int i = 0; i < 7; i++ ) { 100 for ( int i = 0; i < 7; i++ ) {
101 QString filename = QString( QPEApplication::qpeDir() + "/pics/" + skinPath + 101 QString filename = QString( QPEApplication::qpeDir() + "pics/" + skinPath +
102 "/skinV_mask_" + skinV_mask_file_names[i] + ".png" ); 102 "/skinV_mask_" + skinV_mask_file_names[i] + ".png" );
103 // odebug << "loading "+filename << oendl; 103 // odebug << "loading "+filename << oendl;
104 masks[i] = new QBitmap( filename ); 104 masks[i] = new QBitmap( filename );
105 105
106 if ( !masks[i]->isNull() ) { 106 if ( !masks[i]->isNull() ) {
107 QImage imgMask = masks[i]->convertToImage(); 107 QImage imgMask = masks[i]->convertToImage();
108 uchar **dest = imgButtonMask->jumpTable(); 108 uchar **dest = imgButtonMask->jumpTable();
109 for ( int y = 0; y < imgUp->height(); y++ ) { 109 for ( int y = 0; y < imgUp->height(); y++ ) {
110 uchar *line = dest[y]; 110 uchar *line = dest[y];
111 for ( int x = 0; x < imgUp->width(); x++ ) { 111 for ( int x = 0; x < imgUp->width(); x++ ) {
112 if ( !qRed( imgMask.pixel( x, y ) ) ) 112 if ( !qRed( imgMask.pixel( x, y ) ) )
113 line[x] = i + 1; 113 line[x] = i + 1;
114 } 114 }
115 } 115 }
116 } 116 }
117 } 117 }
118 for ( int i = 0; i < 7; i++ ) { 118 for ( int i = 0; i < 7; i++ ) {
119 buttonPixUp[i] = NULL; 119 buttonPixUp[i] = NULL;
120 buttonPixDown[i] = NULL; 120 buttonPixDown[i] = NULL;
121 } 121 }
122 122
123 QWidget *d = QApplication::desktop(); 123 QWidget *d = QApplication::desktop();
124 int width = d->width(); 124 int width = d->width();
125 int height = d->height(); 125 int height = d->height();
126 126
127 if( (width != pixBg->width() ) || (height != pixBg->height() ) ) { 127 if( (width != pixBg->width() ) || (height != pixBg->height() ) ) {
128 QImage img; 128 QImage img;
129 img = pixBg->convertToImage(); 129 img = pixBg->convertToImage();
130 pixBg->convertFromImage( img.smoothScale( width, height)); 130 pixBg->convertFromImage( img.smoothScale( width, height));
131 } 131 }
132 132
133 setBackgroundPixmap( *pixBg ); 133 setBackgroundPixmap( *pixBg );
134 currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 ); 134 currentFrame = new QImage( 220 + 2, 160, (QPixmap::defaultDepth() == 16) ? 16 : 32 );
135 slider = new QSlider( Qt::Horizontal, this ); 135 slider = new QSlider( Qt::Horizontal, this );
136 slider->setMinValue( 0 ); 136 slider->setMinValue( 0 );
137 slider->setMaxValue( 1 ); 137 slider->setMaxValue( 1 );
138 138
139 slider->setBackgroundPixmap( *pixBg ); 139 slider->setBackgroundPixmap( *pixBg );
140 slider->setFocusPolicy( QWidget::NoFocus ); 140 slider->setFocusPolicy( QWidget::NoFocus );
141// slider->setGeometry( QRect( 7, 250, 220, 20 ) ); 141// slider->setGeometry( QRect( 7, 250, 220, 20 ) );
142 142
143 connect(slider,SIGNAL(sliderPressed()),this,SLOT(sliderPressed())); 143 connect(slider,SIGNAL(sliderPressed()),this,SLOT(sliderPressed()));
144 connect(slider,SIGNAL(sliderReleased()),this,SLOT(sliderReleased())); 144 connect(slider,SIGNAL(sliderReleased()),this,SLOT(sliderReleased()));
145 145
146 connect(mediaPlayerState,SIGNAL(lengthChanged(long)),this,SLOT(setLength(long))); 146 connect(mediaPlayerState,SIGNAL(lengthChanged(long)),this,SLOT(setLength(long)));
147 connect(mediaPlayerState,SIGNAL(positionChanged(long)),this,SLOT(setPosition(long))); 147 connect(mediaPlayerState,SIGNAL(positionChanged(long)),this,SLOT(setPosition(long)));
148 connect(mediaPlayerState,SIGNAL(positionUpdated(long)),this,SLOT(setPosition(long))); 148 connect(mediaPlayerState,SIGNAL(positionUpdated(long)),this,SLOT(setPosition(long)));
149 connect(mediaPlayerState,SIGNAL(viewChanged(char)),this,SLOT(setView(char))); 149 connect(mediaPlayerState,SIGNAL(viewChanged(char)),this,SLOT(setView(char)));
150// connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) ); 150// connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
151 connect(mediaPlayerState,SIGNAL(playingToggled(bool)),this,SLOT(setPlaying(bool))); 151 connect(mediaPlayerState,SIGNAL(playingToggled(bool)),this,SLOT(setPlaying(bool)));
152 152
153 // Intialise state 153 // Intialise state
154 setLength( mediaPlayerState->length() ); 154 setLength( mediaPlayerState->length() );
155 setPosition( mediaPlayerState->position() ); 155 setPosition( mediaPlayerState->position() );
156 setFullscreen( mediaPlayerState->fullscreen() ); 156 setFullscreen( mediaPlayerState->fullscreen() );
157// setPlaying( mediaPlayerState->playing() ); 157// setPlaying( mediaPlayerState->playing() );
158 // if(this->x() < 0 || this->y() < 0) 158 // if(this->x() < 0 || this->y() < 0)
159 // this->move(0,0); 159 // this->move(0,0);
160} 160}
161 161
162 162
163VideoWidget::~VideoWidget() { 163VideoWidget::~VideoWidget() {
164 164
165 for ( int i = 0; i < 7; i++ ) 165 for ( int i = 0; i < 7; i++ )
166 { 166 {
167 delete buttonPixUp[i]; 167 delete buttonPixUp[i];
168 delete buttonPixDown[i]; 168 delete buttonPixDown[i];
169 } 169 }
170 170
171 delete pixBg; 171 delete pixBg;
172 delete imgUp; 172 delete imgUp;
173 delete imgDn; 173 delete imgDn;
174 delete imgButtonMask; 174 delete imgButtonMask;
175 for ( int i = 0; i < 7; i++ ) 175 for ( int i = 0; i < 7; i++ )
176 { 176 {
177 delete masks[i]; 177 delete masks[i];
178 } 178 }
179 179
180// for ( int i = 0; i < 3; i++ ) 180// for ( int i = 0; i < 3; i++ )
181// delete pixmaps[i]; 181// delete pixmaps[i];
182// delete currentFrame; 182// delete currentFrame;
183} 183}
184 184
185 185
186static bool videoSliderBeingMoved = FALSE; 186static bool videoSliderBeingMoved = FALSE;
187 187
188QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) { 188QPixmap *combineVImageWithBackground( QImage img, QPixmap bg, QPoint offset ) {
189 QPixmap pix( img.width(), img.height() ); 189 QPixmap pix( img.width(), img.height() );
190 QPainter p( &pix ); 190 QPainter p( &pix );
191 p.drawTiledPixmap( pix.rect(), bg, offset ); 191 p.drawTiledPixmap( pix.rect(), bg, offset );
192 p.drawImage( 0, 0, img ); 192 p.drawImage( 0, 0, img );
193 return new QPixmap( pix ); 193 return new QPixmap( pix );
194} 194}
195 195
196QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) { 196QPixmap *maskVPixToMask( QPixmap pix, QBitmap mask ) {
197 QPixmap *pixmap = new QPixmap( pix ); 197 QPixmap *pixmap = new QPixmap( pix );
198 pixmap->setMask( mask ); 198 pixmap->setMask( mask );
199 return pixmap; 199 return pixmap;
200} 200}
201 201
202void VideoWidget::resizeEvent( QResizeEvent * ) { 202void VideoWidget::resizeEvent( QResizeEvent * ) {
203 int h = height(); 203 int h = height();
204 int w = width(); 204 int w = width();
205 //int Vh = 160; 205 //int Vh = 160;
206 //int Vw = 220; 206 //int Vw = 220;
207 207
208 slider->setFixedWidth( w - 20 ); 208 slider->setFixedWidth( w - 20 );
209 slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); 209 slider->setGeometry( QRect( 15, h - 22, w - 90, 20 ) );
210 slider->setBackgroundOrigin( QWidget::ParentOrigin ); 210 slider->setBackgroundOrigin( QWidget::ParentOrigin );
211 slider->setFocusPolicy( QWidget::NoFocus ); 211 slider->setFocusPolicy( QWidget::NoFocus );
212 slider->setBackgroundPixmap( *pixBg ); 212 slider->setBackgroundPixmap( *pixBg );
213 213
214 xoff = 0;// ( imgUp->width() ) / 2; 214 xoff = 0;// ( imgUp->width() ) / 2;
215 if(w>h) 215 if(w>h)
216 yoff = 0; 216 yoff = 0;
217 else 217 else
218 yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10; 218 yoff = 185;//(( Vh - imgUp->height() ) / 2) - 10;
219 QPoint p( xoff, yoff ); 219 QPoint p( xoff, yoff );
220 220
221 QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p ); 221 QPixmap *pixUp = combineVImageWithBackground( *imgUp, *pixBg, p );
222 QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p ); 222 QPixmap *pixDn = combineVImageWithBackground( *imgDn, *pixBg, p );
223 223
224 for ( int i = 0; i < 7; i++ ) 224 for ( int i = 0; i < 7; i++ )
225 { 225 {
226 if ( !masks[i]->isNull() ) 226 if ( !masks[i]->isNull() )
227 { 227 {
228 delete buttonPixUp[i]; 228 delete buttonPixUp[i];
229 delete buttonPixDown[i]; 229 delete buttonPixDown[i];
230 buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] ); 230 buttonPixUp[i] = maskVPixToMask( *pixUp, *masks[i] );
231 buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] ); 231 buttonPixDown[i] = maskVPixToMask( *pixDn, *masks[i] );
232 } 232 }
233 } 233 }
234 234
235 delete pixUp; 235 delete pixUp;
236 delete pixDn; 236 delete pixDn;
237} 237}
238 238
239 239
240void VideoWidget::sliderPressed() { 240void VideoWidget::sliderPressed() {
241 videoSliderBeingMoved = TRUE; 241 videoSliderBeingMoved = TRUE;
242} 242}
243 243
244 244
245void VideoWidget::sliderReleased() { 245void VideoWidget::sliderReleased() {
246 videoSliderBeingMoved = FALSE; 246 videoSliderBeingMoved = FALSE;
247 if ( slider->width() == 0 ) 247 if ( slider->width() == 0 )
248 return; 248 return;
249 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width()); 249 long val = long((double)slider->value() * mediaPlayerState->length() / slider->width());
250 mediaPlayerState->setPosition( val ); 250 mediaPlayerState->setPosition( val );
251} 251}
252 252
253 253
254void VideoWidget::setPosition( long i ) { 254void VideoWidget::setPosition( long i ) {
255 updateSlider( i, mediaPlayerState->length() ); 255 updateSlider( i, mediaPlayerState->length() );
256} 256}
257 257
258 258
259void VideoWidget::setLength( long max ) { 259void VideoWidget::setLength( long max ) {
260 updateSlider( mediaPlayerState->position(), max ); 260 updateSlider( mediaPlayerState->position(), max );
261} 261}
262 262
263 263
264void VideoWidget::setView( char view ) { 264void VideoWidget::setView( char view ) {
265 if ( view == 'v' ) 265 if ( view == 'v' )
266 { 266 {
267 makeVisible(); 267 makeVisible();
268 } 268 }
269 else 269 else
270 { 270 {
271 // Effectively blank the view next time we show it so it looks nicer 271 // Effectively blank the view next time we show it so it looks nicer
272 scaledWidth = 0; 272 scaledWidth = 0;
273 scaledHeight = 0; 273 scaledHeight = 0;
274 hide(); 274 hide();
275 } 275 }
276} 276}
277 277
278 278
279void VideoWidget::updateSlider( long i, long max ) { 279void VideoWidget::updateSlider( long i, long max ) {
280 // Will flicker too much if we don't do this 280 // Will flicker too much if we don't do this
281 if ( max == 0 ) 281 if ( max == 0 )
282 return; 282 return;
283 int width = slider->width(); 283 int width = slider->width();
284 int val = int((double)i * width / max); 284 int val = int((double)i * width / max);
285 if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved ) 285 if ( !mediaPlayerState->fullscreen() && !videoSliderBeingMoved )
286 { 286 {
287 if ( slider->value() != val ) 287 if ( slider->value() != val )
288 slider->setValue( val ); 288 slider->setValue( val );
289 if ( slider->maxValue() != width ) 289 if ( slider->maxValue() != width )
290 slider->setMaxValue( width ); 290 slider->setMaxValue( width );
291 } 291 }
292} 292}
293 293
294 294
295void VideoWidget::setToggleButton( int i, bool down ) { 295void VideoWidget::setToggleButton( int i, bool down ) {
296 if ( down != videoButtons[i].isDown ) 296 if ( down != videoButtons[i].isDown )
297 toggleButton( i ); 297 toggleButton( i );
298} 298}
299 299
300 300
301void VideoWidget::toggleButton( int i ) { 301void VideoWidget::toggleButton( int i ) {
302 videoButtons[i].isDown = !videoButtons[i].isDown; 302 videoButtons[i].isDown = !videoButtons[i].isDown;
303 QPainter p(this); 303 QPainter p(this);
304 paintButton ( &p, i ); 304 paintButton ( &p, i );
305} 305}
306 306
307 307
308void VideoWidget::paintButton( QPainter *p, int i ) { 308void VideoWidget::paintButton( QPainter *p, int i ) {
309 if ( videoButtons[i].isDown ) 309 if ( videoButtons[i].isDown )
310 { 310 {
311 p->drawPixmap( xoff, yoff, *buttonPixDown[i] ); 311 p->drawPixmap( xoff, yoff, *buttonPixDown[i] );
312 } 312 }
313 else 313 else
314 { 314 {
315 p->drawPixmap( xoff, yoff, *buttonPixUp[i] ); 315 p->drawPixmap( xoff, yoff, *buttonPixUp[i] );
316 } 316 }
317} 317}
318 318
319 319
320void VideoWidget::mouseMoveEvent( QMouseEvent *event ) { 320void VideoWidget::mouseMoveEvent( QMouseEvent *event ) {
321 for ( int i = 0; i < numVButtons; i++ ) { 321 for ( int i = 0; i < numVButtons; i++ ) {
322 if ( event->state() == QMouseEvent::LeftButton ) { 322 if ( event->state() == QMouseEvent::LeftButton ) {
323 // The test to see if the mouse click is inside the button or not 323 // The test to see if the mouse click is inside the button or not
324 int x = event->pos().x() - xoff; 324 int x = event->pos().x() - xoff;
325 int y = event->pos().y() - yoff; 325 int y = event->pos().y() - yoff;
326 326
327 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width() 327 bool isOnButton = ( x > 0 && y > 0 && x < imgButtonMask->width()
328 && y < imgButtonMask->height() 328 && y < imgButtonMask->height()
329 && imgButtonMask->pixelIndex( x, y ) == i + 1 ); 329 && imgButtonMask->pixelIndex( x, y ) == i + 1 );
330 330
331 if ( isOnButton && !videoButtons[i].isHeld ) { 331 if ( isOnButton && !videoButtons[i].isHeld ) {
332 videoButtons[i].isHeld = TRUE; 332 videoButtons[i].isHeld = TRUE;
333 toggleButton(i); 333 toggleButton(i);
334 334
335 switch (i) { 335 switch (i) {
336 case VideoVolUp: 336 case VideoVolUp:
337 emit moreClicked(); 337 emit moreClicked();
338 return; 338 return;
339 case VideoVolDown: 339 case VideoVolDown:
340 emit lessClicked(); 340 emit lessClicked();
341 return; 341 return;
342 } 342 }
343 } else if ( !isOnButton && videoButtons[i].isHeld ) { 343 } else if ( !isOnButton && videoButtons[i].isHeld ) {
344 videoButtons[i].isHeld = FALSE; 344 videoButtons[i].isHeld = FALSE;
345 toggleButton(i); 345 toggleButton(i);
346 } 346 }
347 } else { 347 } else {
348 348
349 if ( videoButtons[i].isHeld ) { 349 if ( videoButtons[i].isHeld ) {
350 videoButtons[i].isHeld = FALSE; 350 videoButtons[i].isHeld = FALSE;
351 if ( !videoButtons[i].isToggle ) { 351 if ( !videoButtons[i].isToggle ) {
352 setToggleButton( i, FALSE ); 352 setToggleButton( i, FALSE );
353 } 353 }
354 354
355 switch(i) { 355 switch(i) {
356 356
357 case VideoPlay: { 357 case VideoPlay: {
358 // odebug << "play" << oendl; 358 // odebug << "play" << oendl;
359 if( !mediaPlayerState->playing()) { 359 if( !mediaPlayerState->playing()) {
360 mediaPlayerState->setPlaying( true); 360 mediaPlayerState->setPlaying( true);
361 setToggleButton( i-1, false ); 361 setToggleButton( i-1, false );
362 setToggleButton( i, false ); 362 setToggleButton( i, false );
363 return; 363 return;
364 } 364 }
365 if( mediaPlayerState->isPaused ) { 365 if( mediaPlayerState->isPaused ) {
366 // odebug << "isPaused" << oendl; 366 // odebug << "isPaused" << oendl;
367 setToggleButton( i, FALSE ); 367 setToggleButton( i, FALSE );
368 mediaPlayerState->setPaused( FALSE ); 368 mediaPlayerState->setPaused( FALSE );
369 return; 369 return;
370 } else if( !mediaPlayerState->isPaused ) { 370 } else if( !mediaPlayerState->isPaused ) {
371 // odebug << "is not paused" << oendl; 371 // odebug << "is not paused" << oendl;
372 setToggleButton( i, TRUE ); 372 setToggleButton( i, TRUE );
373 mediaPlayerState->setPaused( TRUE ); 373 mediaPlayerState->setPaused( TRUE );
374 return; 374 return;
375 } else { 375 } else {
376 return; 376 return;
377 } 377 }
378 } 378 }
379 379
380 case VideoStop: mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return; 380 case VideoStop: mediaPlayerState->setPlaying( FALSE ); setToggleButton( i+1, true); setToggleButton( i, true ); return;
381 case VideoNext: mediaPlayerState->setNext(); return; 381 case VideoNext: mediaPlayerState->setNext(); return;
382 case VideoPrevious: mediaPlayerState->setPrev(); return; 382 case VideoPrevious: mediaPlayerState->setPrev(); return;
383 case VideoVolUp: emit moreReleased(); return; 383 case VideoVolUp: emit moreReleased(); return;
384 case VideoVolDown: emit lessReleased(); return; 384 case VideoVolDown: emit lessReleased(); return;
385 case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return; 385 case VideoFullscreen: mediaPlayerState->setFullscreen( TRUE ); makeVisible(); return;
386 } 386 }
387 } 387 }
388 } 388 }
389 } 389 }
390} 390}
391 391
392 392
393void VideoWidget::mousePressEvent( QMouseEvent *event ) { 393void VideoWidget::mousePressEvent( QMouseEvent *event ) {
394 mouseMoveEvent( event ); 394 mouseMoveEvent( event );
395} 395}
396 396
397 397
398void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) { 398void VideoWidget::mouseReleaseEvent( QMouseEvent *event ) {
399 if ( mediaPlayerState->fullscreen() ) 399 if ( mediaPlayerState->fullscreen() )
400 { 400 {
401 mediaPlayerState->setFullscreen( FALSE ); 401 mediaPlayerState->setFullscreen( FALSE );
402 makeVisible(); 402 makeVisible();
403 } 403 }
404 mouseMoveEvent( event ); 404 mouseMoveEvent( event );
405// } 405// }
406} 406}
407 407
408 408
409void VideoWidget::makeVisible() { 409void VideoWidget::makeVisible() {
410 if ( mediaPlayerState->fullscreen() ) 410 if ( mediaPlayerState->fullscreen() )
411 { 411 {
412 setBackgroundMode( QWidget::NoBackground ); 412 setBackgroundMode( QWidget::NoBackground );
413 showFullScreen(); 413 showFullScreen();
414 resize( qApp->desktop()->size() ); 414 resize( qApp->desktop()->size() );
415 slider->hide(); 415 slider->hide();
416 } 416 }
417 else 417 else
418 { 418 {
419 setBackgroundPixmap( *pixBg ); 419 setBackgroundPixmap( *pixBg );
420 showNormal(); 420 showNormal();
421 QPEApplication::showWidget( this ); 421 QPEApplication::showWidget( this );
422 slider->show(); 422 slider->show();
423 } 423 }
424} 424}
425 425
426 426
427void VideoWidget::paintEvent( QPaintEvent * pe) { 427void VideoWidget::paintEvent( QPaintEvent * pe) {
428 QPainter p( this ); 428 QPainter p( this );
429 429
430 if ( mediaPlayerState->fullscreen() ) { 430 if ( mediaPlayerState->fullscreen() ) {
431 // Clear the background 431 // Clear the background
432 p.setBrush( QBrush( Qt::black ) ); 432 p.setBrush( QBrush( Qt::black ) );
433 p.drawRect( rect() ); 433 p.drawRect( rect() );
434 } else { 434 } else {
435 if ( !pe->erased() ) { 435 if ( !pe->erased() ) {
436 // Combine with background and double buffer 436 // Combine with background and double buffer
437 QPixmap pix( pe->rect().size() ); 437 QPixmap pix( pe->rect().size() );
438 QPainter p( &pix ); 438 QPainter p( &pix );
439 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() ); 439 p.translate( -pe->rect().topLeft().x(), -pe->rect().topLeft().y() );
440 p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() ); 440 p.drawTiledPixmap( pe->rect(), *pixBg, pe->rect().topLeft() );
441 for ( int i = 0; i < numVButtons; i++ ) { 441 for ( int i = 0; i < numVButtons; i++ ) {
442 paintButton( &p, i ); 442 paintButton( &p, i );
443 } 443 }
444 QPainter p2( this ); 444 QPainter p2( this );
445 p2.drawPixmap( pe->rect().topLeft(), pix ); 445 p2.drawPixmap( pe->rect().topLeft(), pix );
446 } else { 446 } else {
447 QPainter p( this ); 447 QPainter p( this );
448 for ( int i = 0; i < numVButtons; i++ ) 448 for ( int i = 0; i < numVButtons; i++ )
449 paintButton( &p, i ); 449 paintButton( &p, i );
450 } 450 }
451 slider->repaint( TRUE ); 451 slider->repaint( TRUE );
452 } 452 }
453} 453}
454 454
455 455
456void VideoWidget::closeEvent( QCloseEvent* ) { 456void VideoWidget::closeEvent( QCloseEvent* ) {
457 mediaPlayerState->setList(); 457 mediaPlayerState->setList();
458} 458}
459 459
460 460
461bool VideoWidget::playVideo() { 461bool VideoWidget::playVideo() {
462 bool result = FALSE; 462 bool result = FALSE;
463// odebug << "<<<<<<<<<<<<<<<< play video" << oendl; 463// odebug << "<<<<<<<<<<<<<<<< play video" << oendl;
464 int stream = 0; 464 int stream = 0;
465 465
466 int sw = mediaPlayerState->curDecoder()->videoWidth( stream ); 466 int sw = mediaPlayerState->curDecoder()->videoWidth( stream );
467 int sh = mediaPlayerState->curDecoder()->videoHeight( stream ); 467 int sh = mediaPlayerState->curDecoder()->videoHeight( stream );
468 int dd = QPixmap::defaultDepth(); 468 int dd = QPixmap::defaultDepth();
469 int w = height(); 469 int w = height();
470 int h = width(); 470 int h = width();
471 471
472 QWidget *d = QApplication::desktop(); 472 QWidget *d = QApplication::desktop();
473 int d_width = d->width(); 473 int d_width = d->width();
474 int d_height = d->height(); 474 int d_height = d->height();
475 475
476 ColorFormat format = (dd == 16) ? RGB565 : BGRA8888; 476 ColorFormat format = (dd == 16) ? RGB565 : BGRA8888;
477 477
478 if ( mediaPlayerState->fullscreen() ) 478 if ( mediaPlayerState->fullscreen() )
479 { 479 {
480#ifdef USE_DIRECT_PAINTER 480#ifdef USE_DIRECT_PAINTER
481 QDirectPainter p(this); 481 QDirectPainter p(this);
482 482
483 if ( ( qt_screen->transformOrientation() == 3 ) && 483 if ( ( qt_screen->transformOrientation() == 3 ) &&
484 ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) ) 484 ( ( dd == 16 ) || ( dd == 32 ) ) && ( p.numRects() == 1 ) )
485 { 485 {
486 486
487 w = d_width; //320; 487 w = d_width; //320;
488 h = d_height; //240; 488 h = d_height; //240;
489 489
490 if ( mediaPlayerState->scaled() ) 490 if ( mediaPlayerState->scaled() )
491 { 491 {
492 // maintain aspect ratio 492 // maintain aspect ratio
493 if ( w * sh > sw * h ) 493 if ( w * sh > sw * h )
494 w = sw * h / sh; 494 w = sw * h / sh;
495 else 495 else
496 h = sh * w / sw; 496 h = sh * w / sw;
497 } 497 }
498 else 498 else
499 { 499 {
500 w = sw; 500 w = sw;
501 h = sh; 501 h = sh;
502 } 502 }
503 503
504 w--; // we can't allow libmpeg to overwrite. 504 w--; // we can't allow libmpeg to overwrite.
505 QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) ); 505 QPoint roff = qt_screen->mapToDevice( p.offset(), QSize( qt_screen->width(), qt_screen->height() ) );
506 506
507 int ox = roff.x() - height() + 2 + (height() - w) / 2; 507 int ox = roff.x() - height() + 2 + (height() - w) / 2;
508 int oy = roff.y() + (width() - h) / 2; 508 int oy = roff.y() + (width() - h) / 2;
509 int sx = 0, sy = 0; 509 int sx = 0, sy = 0;
510 510
511 uchar* fp = p.frameBuffer() + p.lineStep() * oy; 511 uchar* fp = p.frameBuffer() + p.lineStep() * oy;
512 fp += dd * ox / 8; 512 fp += dd * ox / 8;
513 uchar **jt = new uchar*[h]; 513 uchar **jt = new uchar*[h];
514 514
515 for ( int i = h; i; i-- ) 515 for ( int i = h; i; i-- )
516 { 516 {
517 jt[h - i] = fp; 517 jt[h - i] = fp;
518 fp += p.lineStep(); 518 fp += p.lineStep();
519 } 519 }
520 520
521 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0; 521 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( jt, sx, sy, sw, sh, w, h, format, 0) == 0;
522 522
523 delete [] jt; 523 delete [] jt;
524 } 524 }
525 else 525 else
526 { 526 {
527#endif 527#endif
528 QPainter p(this); 528 QPainter p(this);
529 w = d_width; //320; 529 w = d_width; //320;
530 h = d_height; //240; 530 h = d_height; //240;
531 531
532 if ( mediaPlayerState->scaled() ) 532 if ( mediaPlayerState->scaled() )
533 { 533 {
534 // maintain aspect ratio 534 // maintain aspect ratio
535 if ( w * sh > sw * h ) 535 if ( w * sh > sw * h )
536 w = sw * h / sh; 536 w = sw * h / sh;
537 else 537 else
538 h = sh * w / sw; 538 h = sh * w / sw;
539 } 539 }
540 else 540 else
541 { 541 {
542 w = sw; 542 w = sw;
543 h = sh; 543 h = sh;
544 } 544 }
545 545
546 int bytes = ( dd == 16 ) ? 2 : 4; 546 int bytes = ( dd == 16 ) ? 2 : 4;
547 QImage tempFrame( w, h, bytes << 3 ); 547 QImage tempFrame( w, h, bytes << 3 );
548 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(), 548 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( tempFrame.jumpTable(),
549 0, 0, sw, sh, w, h, format, 0) == 0; 549 0, 0, sw, sh, w, h, format, 0) == 0;
550 550
551 if ( result && mediaPlayerState->fullscreen() ) 551 if ( result && mediaPlayerState->fullscreen() )
552 { 552 {
553 553
554 int rw = h, rh = w; 554 int rw = h, rh = w;
555 QImage rotatedFrame( rw, rh, bytes << 3 ); 555 QImage rotatedFrame( rw, rh, bytes << 3 );
556 556
557 ushort* in = (ushort*)tempFrame.bits(); 557 ushort* in = (ushort*)tempFrame.bits();
558 ushort* out = (ushort*)rotatedFrame.bits(); 558 ushort* out = (ushort*)rotatedFrame.bits();
559 int spl = rotatedFrame.bytesPerLine() / bytes; 559 int spl = rotatedFrame.bytesPerLine() / bytes;
560 560
561 for (int x=0; x<h; x++) 561 for (int x=0; x<h; x++)
562 { 562 {
563 if ( bytes == 2 ) 563 if ( bytes == 2 )
564 { 564 {
565 ushort* lout = out++ + (w - 1)*spl; 565 ushort* lout = out++ + (w - 1)*spl;
566 for (int y=0; y<w; y++) { 566 for (int y=0; y<w; y++) {
567 *lout=*in++; 567 *lout=*in++;
568 lout-=spl; 568 lout-=spl;
569 } 569 }
570 } 570 }
571 else 571 else
572 { 572 {
573 ulong* _out = (ulong *)out; 573 ulong* _out = (ulong *)out;
574 ulong* lout = _out++ + (w - 1)*spl; 574 ulong* lout = _out++ + (w - 1)*spl;
575 for (int y=0; y<w; y++) 575 for (int y=0; y<w; y++)
576 { 576 {
577 ulong *_in = (ulong*)in; 577 ulong *_in = (ulong*)in;
578 *lout=*_in++; 578 *lout=*_in++;
579 lout-=spl; 579 lout-=spl;
580 } 580 }
581 } 581 }
582 } 582 }
583 583
584 p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh ); 584 p.drawImage( (240 - rw) / 2, (320 - rh) / 2, rotatedFrame, 0, 0, rw, rh );
585 } 585 }
586#ifdef USE_DIRECT_PAINTER 586#ifdef USE_DIRECT_PAINTER
587 } 587 }
588#endif 588#endif
589 } 589 }
590 else 590 else
591 { 591 {
592 592
593 w = 220; 593 w = 220;
594 h = 160; 594 h = 160;
595 595
596 // maintain aspect ratio 596 // maintain aspect ratio
597 if ( w * sh > sw * h ) 597 if ( w * sh > sw * h )
598 w = sw * h / sh; 598 w = sw * h / sh;
599 else 599 else
600 h = sh * w / sw; 600 h = sh * w / sw;
601 601
602 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0; 602 result = mediaPlayerState->curDecoder()->videoReadScaledFrame( currentFrame->jumpTable(), 0, 0, sw, sh, w, h, format, 0) == 0;
603 603
604 QPainter p( this ); 604 QPainter p( this );
605 int deskW = qApp->desktop()->width(); 605 int deskW = qApp->desktop()->width();
606 // Image changed size, therefore need to blank the possibly unpainted regions first 606 // Image changed size, therefore need to blank the possibly unpainted regions first
607 if ( scaledWidth != w || scaledHeight != h ) 607 if ( scaledWidth != w || scaledHeight != h )
608 { 608 {
609 p.setBrush( QBrush( Qt::black ) ); 609 p.setBrush( QBrush( Qt::black ) );
610 p.drawRect( ( deskW -scaledWidth)/2, 20, scaledWidth, 160 ); 610 p.drawRect( ( deskW -scaledWidth)/2, 20, scaledWidth, 160 );
611 } 611 }
612 612
613 scaledWidth = w; 613 scaledWidth = w;
614 scaledHeight = h; 614 scaledHeight = h;
615 615
616 if ( result ) 616 if ( result )
617 { 617 {
618 p.drawImage( (deskW - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight ); 618 p.drawImage( (deskW - scaledWidth) / 2, 20 + (160 - scaledHeight) / 2, *currentFrame, 0, 0, scaledWidth, scaledHeight );
619 } 619 }
620 620
621 } 621 }
622 622
623 return result; 623 return result;
624} 624}
625 625
626 626
627 627
628void VideoWidget::keyReleaseEvent( QKeyEvent *e) 628void VideoWidget::keyReleaseEvent( QKeyEvent *e)
629{ 629{
630 switch ( e->key() ) 630 switch ( e->key() )
631 { 631 {
632////////////////////////////// Zaurus keys 632////////////////////////////// Zaurus keys
633 case Key_Home: 633 case Key_Home:
634 break; 634 break;
635 case Key_F9: //activity 635 case Key_F9: //activity
636 break; 636 break;
637 case Key_F10: //contacts 637 case Key_F10: //contacts
638// hide(); 638// hide();
639 break; 639 break;
640 case Key_F11: //menu 640 case Key_F11: //menu
641 break; 641 break;
642 case Key_F12: //home 642 case Key_F12: //home
643 break; 643 break;
644 case Key_F13: //mail 644 case Key_F13: //mail
645 break; 645 break;
646 case Key_Space: 646 case Key_Space:
647 { 647 {
648 if(mediaPlayerState->playing()) 648 if(mediaPlayerState->playing())
649 { 649 {
650 mediaPlayerState->setPlaying(FALSE); 650 mediaPlayerState->setPlaying(FALSE);
651 } 651 }
652 else 652 else
653 { 653 {
654 mediaPlayerState->setPlaying(TRUE); 654 mediaPlayerState->setPlaying(TRUE);
655 } 655 }
656 } 656 }
657 break; 657 break;
658 case Key_Down: 658 case Key_Down:
659// toggleButton(6); 659// toggleButton(6);
660// emit lessClicked(); 660// emit lessClicked();
661// emit lessReleased(); 661// emit lessReleased();
662// toggleButton(6); 662// toggleButton(6);
663 break; 663 break;
664 case Key_Up: 664 case Key_Up:
665// toggleButton(5); 665// toggleButton(5);
666// emit moreClicked(); 666// emit moreClicked();
667// emit moreReleased(); 667// emit moreReleased();
668// toggleButton(5); 668// toggleButton(5);
669 break; 669 break;
670 case Key_Right: 670 case Key_Right:
671 mediaPlayerState->setNext(); 671 mediaPlayerState->setNext();
672 break; 672 break;
673 case Key_Left: 673 case Key_Left:
674 mediaPlayerState->setPrev(); 674 mediaPlayerState->setPrev();
675 break; 675 break;
676 case Key_Escape: 676 case Key_Escape:
677 break; 677 break;
678 678
679 }; 679 };
680} 680}
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp
index f0a8ba2..0699d0a 100644
--- a/core/opie-login/main.cpp
+++ b/core/opie-login/main.cpp
@@ -1,383 +1,383 @@
1/* 1/*
2 =. This file is part of the OPIE Project 2 =. This file is part of the OPIE Project
3 .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 3 .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
4 .>+-= 4 .>+-=
5_;:, .> :=|. This file is free software; you can 5_;:, .> :=|. This file is free software; you can
6.> <`_, > . <= redistribute it and/or modify it under 6.> <`_, > . <= redistribute it and/or modify it under
7:`=1 )Y*s>-.-- : the terms of the GNU General Public 7:`=1 )Y*s>-.-- : the terms of the GNU General Public
8.="- .-=="i, .._ License as published by the Free Software 8.="- .-=="i, .._ License as published by the Free Software
9- . .-<_> .<> Foundation; either version 2 of the License, 9- . .-<_> .<> Foundation; either version 2 of the License,
10 ._= =} : or (at your option) any later version. 10 ._= =} : or (at your option) any later version.
11 .%`+i> _;_. 11 .%`+i> _;_.
12 .i_,=:_. -<s. This file is distributed in the hope that 12 .i_,=:_. -<s. This file is distributed in the hope that
13 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 13 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
14 : .. .:, . . . without even the implied warranty of 14 : .. .:, . . . without even the implied warranty of
15 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 15 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
16 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General 16 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General
17..}^=.= = ; Public License for more details. 17..}^=.= = ; Public License for more details.
18++= -. .` .: 18++= -. .` .:
19: = ...= . :.=- You should have received a copy of the GNU 19: = ...= . :.=- You should have received a copy of the GNU
20-. .:....=;==+<; General Public License along with this file; 20-. .:....=;==+<; General Public License along with this file;
21 -_. . . )=. = see the file COPYING. If not, write to the 21 -_. . . )=. = see the file COPYING. If not, write to the
22 -- :-=` Free Software Foundation, Inc., 22 -- :-=` Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330, 23 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA. 24 Boston, MA 02111-1307, USA.
25 25
26*/ 26*/
27 27
28#include "loginapplication.h" 28#include "loginapplication.h"
29#include "loginwindowimpl.h" 29#include "loginwindowimpl.h"
30#include "calibrate.h" 30#include "calibrate.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/odevice.h> 33#include <opie2/odevice.h>
34#include <qpe/qpestyle.h> 34#include <qpe/qpestyle.h>
35#include <qpe/power.h> 35#include <qpe/power.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37 37
38/* QT */ 38/* QT */
39#include <qwindowsystem_qws.h> 39#include <qwindowsystem_qws.h>
40#include <qmessagebox.h> 40#include <qmessagebox.h>
41#include <qlabel.h> 41#include <qlabel.h>
42#include <qtimer.h> 42#include <qtimer.h>
43#include <qfile.h> 43#include <qfile.h>
44 44
45/* STD */ 45/* STD */
46#include <sys/types.h> 46#include <sys/types.h>
47#include <time.h> 47#include <time.h>
48#include <sys/time.h> 48#include <sys/time.h>
49#include <sys/resource.h> 49#include <sys/resource.h>
50#include <unistd.h> 50#include <unistd.h>
51#include <syslog.h> 51#include <syslog.h>
52#include <sys/wait.h> 52#include <sys/wait.h>
53#include <stdio.h> 53#include <stdio.h>
54#include <stdlib.h> 54#include <stdlib.h>
55#include <signal.h> 55#include <signal.h>
56#include <getopt.h> 56#include <getopt.h>
57#include <string.h> 57#include <string.h>
58 58
59using namespace Opie::Core; 59using namespace Opie::Core;
60 60
61int login_main ( int argc, char **argv, pid_t ppid ); 61int login_main ( int argc, char **argv, pid_t ppid );
62void sigterm ( int sig ); 62void sigterm ( int sig );
63void sigint ( int sig ); 63void sigint ( int sig );
64void exit_closelog ( ); 64void exit_closelog ( );
65 65
66static struct option long_options [] = { 66static struct option long_options [] = {
67 { "autologin", 1, 0, 'a' }, 67 { "autologin", 1, 0, 'a' },
68 { 0, 0, 0, 0 } 68 { 0, 0, 0, 0 }
69}; 69};
70 70
71 71
72int main ( int argc, char **argv ) 72int main ( int argc, char **argv )
73{ 73{
74 int userExited = 0; 74 int userExited = 0;
75 pid_t ppid = ::getpid ( ); 75 pid_t ppid = ::getpid ( );
76 76
77 if ( ::geteuid ( ) != 0 ) { 77 if ( ::geteuid ( ) != 0 ) {
78 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] ); 78 ::fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] );
79 return 1; 79 return 1;
80 } 80 }
81 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and 81 if ( ::getuid ( ) != 0 ) // qt doesn't really like SUID and
82 ::setuid ( 0 ); // messes up things like config files 82 ::setuid ( 0 ); // messes up things like config files
83 83
84 char *autolog = 0; 84 char *autolog = 0;
85 int c; 85 int c;
86 while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) { 86 while (( c = ::getopt_long ( argc, argv, "a:", long_options, 0 )) != -1 ) {
87 switch ( c ) { 87 switch ( c ) {
88 case 'a': 88 case 'a':
89 autolog = optarg; 89 autolog = optarg;
90 break; 90 break;
91 default: 91 default:
92 ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] ); 92 ::fprintf ( stderr, "Usage: %s [-a|--autologin=<user>]\n", argv [0] );
93 return 2; 93 return 2;
94 } 94 }
95 } 95 }
96 96
97 //struct rlimit rl; 97 //struct rlimit rl;
98 //::getrlimit ( RLIMIT_NOFILE, &rl ); 98 //::getrlimit ( RLIMIT_NOFILE, &rl );
99 99
100 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ ) 100 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ )
101 // ::close ( i ); 101 // ::close ( i );
102 102
103 ::setpgid ( 0, 0 ); 103 ::setpgid ( 0, 0 );
104 ::setsid ( ); 104 ::setsid ( );
105 105
106 ::signal ( SIGTERM, sigterm ); 106 ::signal ( SIGTERM, sigterm );
107 ::signal ( SIGINT, sigterm ); 107 ::signal ( SIGINT, sigterm );
108 108
109 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV ); 109 ::openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
110 ::atexit ( exit_closelog ); 110 ::atexit ( exit_closelog );
111 111
112 while ( true ) { 112 while ( true ) {
113 pid_t child = ::fork ( ); 113 pid_t child = ::fork ( );
114 114
115 if ( child < 0 ) { 115 if ( child < 0 ) {
116 ::syslog ( LOG_ERR, "Could not fork GUI process\n" ); 116 ::syslog ( LOG_ERR, "Could not fork GUI process\n" );
117 break; 117 break;
118 } 118 }
119 else if ( child > 0 ) { 119 else if ( child > 0 ) {
120 int status = 0; 120 int status = 0;
121 time_t started = ::time ( 0 ); 121 time_t started = ::time ( 0 );
122 122
123 while ( ::waitpid ( child, &status, 0 ) < 0 ) { } 123 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
124 124
125 LoginApplication::logout ( ); 125 LoginApplication::logout ( );
126 126
127 if (( ::time ( 0 ) - started ) < 3 ) { 127 if (( ::time ( 0 ) - started ) < 3 ) {
128 if ( autolog ) { 128 if ( autolog ) {
129 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" ); 129 ::syslog ( LOG_ERR, "Respawning too fast -- disabling auto-login\n" );
130 autolog = 0; 130 autolog = 0;
131 } 131 }
132 else { 132 else {
133 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" ); 133 ::syslog ( LOG_ERR, "Respawning too fast -- going down\n" );
134 break; 134 break;
135 } 135 }
136 } 136 }
137 int killedbysig = 0; 137 int killedbysig = 0;
138 userExited=0; 138 userExited=0;
139 if (WIFEXITED(status)!=0 ) { 139 if (WIFEXITED(status)!=0 ) {
140 if (WEXITSTATUS(status)==137) { 140 if (WEXITSTATUS(status)==137) {
141 userExited=1; 141 userExited=1;
142 } 142 }
143 } 143 }
144 144
145 if ( WIFSIGNALED( status )) { 145 if ( WIFSIGNALED( status )) {
146 switch ( WTERMSIG( status )) { 146 switch ( WTERMSIG( status )) {
147 case SIGTERM: 147 case SIGTERM:
148 case SIGINT : 148 case SIGINT :
149 case SIGKILL: 149 case SIGKILL:
150 break; 150 break;
151 151
152 default : 152 default :
153 killedbysig = WTERMSIG( status ); 153 killedbysig = WTERMSIG( status );
154 break; 154 break;
155 } 155 }
156 } 156 }
157 if ( killedbysig ) { // qpe was killed by an uncaught signal 157 if ( killedbysig ) { // qpe was killed by an uncaught signal
158 qApp = 0; 158 qApp = 0;
159 159
160 ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig ); 160 ::syslog ( LOG_ERR, "Opie was killed by a signal #%d", killedbysig );
161 161
162 QWSServer::setDesktopBackground ( QImage ( )); 162 QWSServer::setDesktopBackground ( QImage ( ));
163 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer ); 163 QApplication *app = new QApplication ( argc, argv, QApplication::GuiServer );
164 app-> setFont ( QFont ( "Helvetica", 10 )); 164 app-> setFont ( QFont ( "Helvetica", 10 ));
165 app-> setStyle ( new QPEStyle ( )); 165 app-> setStyle ( new QPEStyle ( ));
166 166
167 // const char *sig = ::strsignal ( killedbysig ); 167 // const char *sig = ::strsignal ( killedbysig );
168 const char *sig = ::sys_siglist[killedbysig]; 168 const char *sig = ::sys_siglist[killedbysig];
169 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool ); 169 QLabel *l = new QLabel ( 0, "sig", Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool );
170 l-> setText ( LoginWindowImpl::tr( "Opie was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig )); 170 l-> setText ( LoginWindowImpl::tr( "Opie was terminated\nby an uncaught signal\n(%1)\n" ). arg ( sig ));
171 l-> setAlignment ( Qt::AlignCenter ); 171 l-> setAlignment ( Qt::AlignCenter );
172 l-> move ( 0, 0 ); 172 l-> move ( 0, 0 );
173 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); 173 l-> resize ( app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
174 l-> show ( ); 174 l-> show ( );
175 QTimer::singleShot ( 3000, app, SLOT( quit())); 175 QTimer::singleShot ( 3000, app, SLOT( quit()));
176 app-> exec ( ); 176 app-> exec ( );
177 delete app; 177 delete app;
178 qApp = 0; 178 qApp = 0;
179 } 179 }
180 } 180 }
181 else { 181 else {
182 if ( !autolog ) { 182 if ( !autolog ) {
183 QString confFile=QPEApplication::qpeDir() + "/etc/opie-login.conf"; 183 QString confFile=QPEApplication::qpeDir() + "etc/opie-login.conf";
184 Config cfg ( confFile, Config::File ); 184 Config cfg ( confFile, Config::File );
185 cfg. setGroup ( "General" ); 185 cfg. setGroup ( "General" );
186 QString user = cfg. readEntry ( "AutoLogin" ); 186 QString user = cfg. readEntry ( "AutoLogin" );
187 187
188 if ( !user. isEmpty ( )) 188 if ( !user. isEmpty ( ))
189 autolog = ::strdup ( user. latin1 ( )); 189 autolog = ::strdup ( user. latin1 ( ));
190 } 190 }
191 191
192 if ( autolog && !userExited ) { 192 if ( autolog && !userExited ) {
193 193
194 QWSServer::setDesktopBackground( QImage() ); 194 QWSServer::setDesktopBackground( QImage() );
195 ODevice::inst ( )-> setDisplayStatus ( true ); 195 ODevice::inst ( )-> setDisplayStatus ( true );
196 ODevice::inst ( )-> setSoftSuspend ( false ); 196 ODevice::inst ( )-> setSoftSuspend ( false );
197 LoginApplication *app = new LoginApplication ( argc, argv, ppid ); 197 LoginApplication *app = new LoginApplication ( argc, argv, ppid );
198 LoginApplication::setLoginAs ( autolog ); 198 LoginApplication::setLoginAs ( autolog );
199 199
200 200
201 if ( LoginApplication::changeIdentity ( )) 201 if ( LoginApplication::changeIdentity ( ))
202 ::exit ( LoginApplication::login ( )); 202 ::exit ( LoginApplication::login ( ));
203 else 203 else
204 ::exit ( 0 ); 204 ::exit ( 0 );
205 } 205 }
206 else { 206 else {
207 ::exit ( login_main ( argc, argv, ppid )); 207 ::exit ( login_main ( argc, argv, ppid ));
208 } 208 }
209 } 209 }
210 } 210 }
211 return 0; 211 return 0;
212} 212}
213 213
214void sigterm ( int /*sig*/ ) 214void sigterm ( int /*sig*/ )
215{ 215{
216 ::exit ( 0 ); 216 ::exit ( 0 );
217} 217}
218 218
219 219
220void exit_closelog ( ) 220void exit_closelog ( )
221{ 221{
222 ::closelog ( ); 222 ::closelog ( );
223} 223}
224 224
225 225
226class LoginScreenSaver : public QWSScreenSaver 226class LoginScreenSaver : public QWSScreenSaver
227{ 227{
228public: 228public:
229 LoginScreenSaver ( ) 229 LoginScreenSaver ( )
230 { 230 {
231 m_lcd_status = true; 231 m_lcd_status = true;
232 232
233 m_backlight_bright = -1; 233 m_backlight_bright = -1;
234 m_backlight_forcedoff = false; 234 m_backlight_forcedoff = false;
235 235
236 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 236 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
237 ODevice::inst ( )-> setDisplayStatus ( true ); 237 ODevice::inst ( )-> setDisplayStatus ( true );
238 } 238 }
239 void restore() 239 void restore()
240 { 240 {
241 if ( !m_lcd_status ) // We must have turned it off 241 if ( !m_lcd_status ) // We must have turned it off
242 ODevice::inst ( ) -> setDisplayStatus ( true ); 242 ODevice::inst ( ) -> setDisplayStatus ( true );
243 243
244 setBacklight ( -3 ); 244 setBacklight ( -3 );
245 } 245 }
246 bool save( int level ) 246 bool save( int level )
247 { 247 {
248 switch ( level ) { 248 switch ( level ) {
249 case 0: 249 case 0:
250 if ( backlight() > 1 ) 250 if ( backlight() > 1 )
251 setBacklight( 1 ); // lowest non-off 251 setBacklight( 1 ); // lowest non-off
252 return true; 252 return true;
253 break; 253 break;
254 case 1: 254 case 1:
255 setBacklight( 0 ); // off 255 setBacklight( 0 ); // off
256 return true; 256 return true;
257 break; 257 break;
258 case 2: 258 case 2:
259 // We're going to suspend the whole machine 259 // We're going to suspend the whole machine
260 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { 260 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
261 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 261 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
262 return true; 262 return true;
263 } 263 }
264 break; 264 break;
265 } 265 }
266 return false; 266 return false;
267 } 267 }
268 268
269private: 269private:
270public: 270public:
271 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 ) 271 void setIntervals( int i1 = 30, int i2 = 20, int i3 = 60 )
272 { 272 {
273 int v [4]; 273 int v [4];
274 274
275 v [ 0 ] = QMAX( 1000 * i1, 100 ); 275 v [ 0 ] = QMAX( 1000 * i1, 100 );
276 v [ 1 ] = QMAX( 1000 * i2, 100 ); 276 v [ 1 ] = QMAX( 1000 * i2, 100 );
277 v [ 2 ] = QMAX( 1000 * i3, 100 ); 277 v [ 2 ] = QMAX( 1000 * i3, 100 );
278 v [ 3 ] = 0; 278 v [ 3 ] = 0;
279 279
280 if ( !i1 && !i2 && !i3 ) 280 if ( !i1 && !i2 && !i3 )
281 QWSServer::setScreenSaverInterval ( 0 ); 281 QWSServer::setScreenSaverInterval ( 0 );
282 else 282 else
283 QWSServer::setScreenSaverIntervals ( v ); 283 QWSServer::setScreenSaverIntervals ( v );
284 } 284 }
285 285
286 int backlight ( ) 286 int backlight ( )
287 { 287 {
288 if ( m_backlight_bright == -1 ) 288 if ( m_backlight_bright == -1 )
289 m_backlight_bright = 255; 289 m_backlight_bright = 255;
290 290
291 return m_backlight_bright; 291 return m_backlight_bright;
292 } 292 }
293 293
294 void setBacklight ( int bright ) 294 void setBacklight ( int bright )
295 { 295 {
296 if ( bright == -3 ) { 296 if ( bright == -3 ) {
297 // Forced on 297 // Forced on
298 m_backlight_forcedoff = false; 298 m_backlight_forcedoff = false;
299 bright = -1; 299 bright = -1;
300 } 300 }
301 if ( m_backlight_forcedoff && bright != -2 ) 301 if ( m_backlight_forcedoff && bright != -2 )
302 return ; 302 return ;
303 if ( bright == -2 ) { 303 if ( bright == -2 ) {
304 // Toggle between off and on 304 // Toggle between off and on
305 bright = m_backlight_bright ? 0 : -1; 305 bright = m_backlight_bright ? 0 : -1;
306 m_backlight_forcedoff = !bright; 306 m_backlight_forcedoff = !bright;
307 } 307 }
308 308
309 m_backlight_bright = bright; 309 m_backlight_bright = bright;
310 310
311 bright = backlight ( ); 311 bright = backlight ( );
312 ODevice::inst ( ) -> setDisplayBrightness ( bright ); 312 ODevice::inst ( ) -> setDisplayBrightness ( bright );
313 313
314 m_backlight_bright = bright; 314 m_backlight_bright = bright;
315 } 315 }
316 316
317private: 317private:
318 bool m_lcd_status; 318 bool m_lcd_status;
319 319
320 int m_backlight_bright; 320 int m_backlight_bright;
321 bool m_backlight_forcedoff; 321 bool m_backlight_forcedoff;
322}; 322};
323 323
324 324
325namespace Opie { extern int force_appearance; } // HACK to get around the force-style setting 325namespace Opie { extern int force_appearance; } // HACK to get around the force-style setting
326 326
327 327
328int login_main ( int argc, char **argv, pid_t ppid ) 328int login_main ( int argc, char **argv, pid_t ppid )
329{ 329{
330 QWSServer::setDesktopBackground( QImage() ); 330 QWSServer::setDesktopBackground( QImage() );
331 LoginApplication *app = new LoginApplication ( argc, argv, ppid ); 331 LoginApplication *app = new LoginApplication ( argc, argv, ppid );
332 332
333 Opie::force_appearance = 0; 333 Opie::force_appearance = 0;
334 334
335 app-> setFont ( QFont ( "Helvetica", 10 )); 335 app-> setFont ( QFont ( "Helvetica", 10 ));
336 app-> setStyle ( new QPEStyle ( )); 336 app-> setStyle ( new QPEStyle ( ));
337 337
338 ODevice::inst ( )-> setSoftSuspend ( true ); 338 ODevice::inst ( )-> setSoftSuspend ( true );
339 339
340 if ( QWSServer::mouseHandler() && 340 if ( QWSServer::mouseHandler() &&
341 QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { 341 QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) {
342 if ( !QFile::exists ( "/etc/pointercal" )) { 342 if ( !QFile::exists ( "/etc/pointercal" )) {
343 // Make sure calibration widget starts on top. 343 // Make sure calibration widget starts on top.
344 Calibrate *cal = new Calibrate; 344 Calibrate *cal = new Calibrate;
345 cal-> exec ( ); 345 cal-> exec ( );
346 delete cal; 346 delete cal;
347 } 347 }
348 } 348 }
349 349
350 LoginScreenSaver *saver = new LoginScreenSaver; 350 LoginScreenSaver *saver = new LoginScreenSaver;
351 351
352 saver-> setIntervals ( ); 352 saver-> setIntervals ( );
353 QWSServer::setScreenSaver ( saver ); 353 QWSServer::setScreenSaver ( saver );
354 saver-> restore ( ); 354 saver-> restore ( );
355 355
356 356
357 LoginWindowImpl *lw = new LoginWindowImpl ( ); 357 LoginWindowImpl *lw = new LoginWindowImpl ( );
358 app-> setMainWidget ( lw ); 358 app-> setMainWidget ( lw );
359 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( )); 359 lw-> setGeometry ( 0, 0, app-> desktop ( )-> width ( ), app-> desktop ( )-> height ( ));
360 lw-> show ( ); 360 lw-> show ( );
361 361
362 int rc = app-> exec ( ); 362 int rc = app-> exec ( );
363 363
364 ODevice::inst ( )-> setSoftSuspend ( false ); 364 ODevice::inst ( )-> setSoftSuspend ( false );
365 365
366 if ( app-> loginAs ( )) { 366 if ( app-> loginAs ( )) {
367 if ( app-> changeIdentity ( )) { 367 if ( app-> changeIdentity ( )) {
368 app-> login ( ); 368 app-> login ( );
369 369
370 // if login succeeds, it never comes back 370 // if login succeeds, it never comes back
371 371
372 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." )); 372 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not start Opie." ));
373 rc = 1; 373 rc = 1;
374 } 374 }
375 else { 375 else {
376 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" )); 376 QMessageBox::critical ( 0, LoginWindowImpl::tr( "Failure" ), LoginWindowImpl::tr( "Could not switch to new user identity" ));
377 rc = 2; 377 rc = 2;
378 } 378 }
379 379
380 } 380 }
381 return rc; 381 return rc;
382} 382}
383 383
diff --git a/core/settings/launcher/menusettings.cpp b/core/settings/launcher/menusettings.cpp
index 2b64c47..55bf358 100644
--- a/core/settings/launcher/menusettings.cpp
+++ b/core/settings/launcher/menusettings.cpp
@@ -1,178 +1,178 @@
1/* 1/*
2 This file is part of the OPIE Project 2 This file is part of the OPIE Project
3 =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> 3 =. Copyright (c) 2002 Trolltech AS <info@trolltech.com>
4 .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 4 .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
5 .>+-= 5 .>+-=
6_;:, .> :=|. This file is free software; you can 6_;:, .> :=|. This file is free software; you can
7.> <`_, > . <= redistribute it and/or modify it under 7.> <`_, > . <= redistribute it and/or modify it under
8:`=1 )Y*s>-.-- : the terms of the GNU General Public 8:`=1 )Y*s>-.-- : the terms of the GNU General Public
9.="- .-=="i, .._ License as published by the Free Software 9.="- .-=="i, .._ License as published by the Free Software
10- . .-<_> .<> Foundation; either version 2 of the License, 10- . .-<_> .<> Foundation; either version 2 of the License,
11 ._= =} : or (at your option) any later version. 11 ._= =} : or (at your option) any later version.
12 .%`+i> _;_. 12 .%`+i> _;_.
13 .i_,=:_. -<s. This file is distributed in the hope that 13 .i_,=:_. -<s. This file is distributed in the hope that
14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
15 : .. .:, . . . without even the implied warranty of 15 : .. .:, . . . without even the implied warranty of
16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General 17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.= = ; Public License for more details. 18..}^=.= = ; Public License for more details.
19++= -. .` .: 19++= -. .` .:
20: = ...= . :.=- You should have received a copy of the GNU 20: = ...= . :.=- You should have received a copy of the GNU
21-. .:....=;==+<; General Public License along with this file; 21-. .:....=;==+<; General Public License along with this file;
22 -_. . . )=. = see the file COPYING. If not, write to the 22 -_. . . )=. = see the file COPYING. If not, write to the
23 -- :-=` Free Software Foundation, Inc., 23 -- :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include "menusettings.h" 29#include "menusettings.h"
30 30
31#include <qpe/config.h> 31#include <qpe/config.h>
32#include <qpe/qlibrary.h> 32#include <qpe/qlibrary.h>
33#include <qpe/qpeapplication.h> 33#include <qpe/qpeapplication.h>
34#include <qpe/menuappletinterface.h> 34#include <qpe/menuappletinterface.h>
35#include <qpe/qcopenvelope_qws.h> 35#include <qpe/qcopenvelope_qws.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qlistview.h> 38#include <qlistview.h>
39#include <qcheckbox.h> 39#include <qcheckbox.h>
40#include <qheader.h> 40#include <qheader.h>
41#include <qlayout.h> 41#include <qlayout.h>
42#include <qlabel.h> 42#include <qlabel.h>
43#include <qwhatsthis.h> 43#include <qwhatsthis.h>
44 44
45#include <stdlib.h> 45#include <stdlib.h>
46 46
47 47
48MenuSettings::MenuSettings ( QWidget *parent, const char *name ) 48MenuSettings::MenuSettings ( QWidget *parent, const char *name )
49 : QWidget ( parent, name ) 49 : QWidget ( parent, name )
50{ 50{
51 m_applets_changed = false; 51 m_applets_changed = false;
52 52
53 QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 ); 53 QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 );
54 54
55 QLabel *l = new QLabel ( tr( "Load applets in O-Menu:" ), this ); 55 QLabel *l = new QLabel ( tr( "Load applets in O-Menu:" ), this );
56 lay-> addWidget ( l ); 56 lay-> addWidget ( l );
57 57
58 m_list = new QListView ( this ); 58 m_list = new QListView ( this );
59 m_list-> addColumn ( "foobar" ); 59 m_list-> addColumn ( "foobar" );
60 m_list-> header ( )-> hide ( ); 60 m_list-> header ( )-> hide ( );
61 61
62 lay-> addWidget ( m_list ); 62 lay-> addWidget ( m_list );
63 63
64 m_menutabs = new QCheckBox ( tr( "Show Launcher tabs in O-Menu" ), this ); 64 m_menutabs = new QCheckBox ( tr( "Show Launcher tabs in O-Menu" ), this );
65 lay-> addWidget ( m_menutabs ); 65 lay-> addWidget ( m_menutabs );
66 66
67 m_menusubpopup = new QCheckBox ( tr( "Show Applications in Subpopups" ), this ); 67 m_menusubpopup = new QCheckBox ( tr( "Show Applications in Subpopups" ), this );
68 lay-> addWidget ( m_menusubpopup ); 68 lay-> addWidget ( m_menusubpopup );
69 69
70 QWhatsThis::add ( m_list, tr( "Check the applets that you want to have included in the O-Menu." )); 70 QWhatsThis::add ( m_list, tr( "Check the applets that you want to have included in the O-Menu." ));
71 QWhatsThis::add ( m_menutabs, tr( "Adds the contents of the Launcher Tabs as menus in the O-Menu." )); 71 QWhatsThis::add ( m_menutabs, tr( "Adds the contents of the Launcher Tabs as menus in the O-Menu." ));
72 72
73 connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged())); 73 connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged()));
74 74
75 init ( ); 75 init ( );
76} 76}
77 77
78void MenuSettings::init ( ) 78void MenuSettings::init ( )
79{ 79{
80 Config cfg ( "StartMenu" ); 80 Config cfg ( "StartMenu" );
81 cfg. setGroup ( "Applets" ); 81 cfg. setGroup ( "Applets" );
82 QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' ); 82 QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' );
83 83
84 QString path = QPEApplication::qpeDir ( ) + "/plugins/applets"; 84 QString path = QPEApplication::qpeDir ( ) + "plugins/applets";
85#ifdef Q_OS_MACX 85#ifdef Q_OS_MACX
86 QStringList list = QDir ( path, "lib*.dylib" ). entryList ( ); 86 QStringList list = QDir ( path, "lib*.dylib" ). entryList ( );
87#else 87#else
88 QStringList list = QDir ( path, "lib*.so" ). entryList ( ); 88 QStringList list = QDir ( path, "lib*.so" ). entryList ( );
89#endif /* Q_OS_MACX */ 89#endif /* Q_OS_MACX */
90 90
91 for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) { 91 for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) {
92 QString name; 92 QString name;
93 QPixmap icon; 93 QPixmap icon;
94 MenuAppletInterface *iface = 0; 94 MenuAppletInterface *iface = 0;
95 95
96 QLibrary *lib = new QLibrary ( path + "/" + *it ); 96 QLibrary *lib = new QLibrary ( path + "/" + *it );
97 lib-> queryInterface ( IID_MenuApplet, (QUnknownInterface**) &iface ); 97 lib-> queryInterface ( IID_MenuApplet, (QUnknownInterface**) &iface );
98 if ( iface ) { 98 if ( iface ) {
99 QString lang = getenv( "LANG" ); 99 QString lang = getenv( "LANG" );
100 QTranslator *trans = new QTranslator ( qApp ); 100 QTranslator *trans = new QTranslator ( qApp );
101 QString type = (*it). left ((*it). find (".")); 101 QString type = (*it). left ((*it). find ("."));
102 QString tfn = QPEApplication::qpeDir ( ) + "/i18n/" + lang + "/" + type + ".qm"; 102 QString tfn = QPEApplication::qpeDir ( ) + "i18n/" + lang + "/" + type + ".qm";
103 if ( trans-> load ( tfn )) 103 if ( trans-> load ( tfn ))
104 qApp-> installTranslator ( trans ); 104 qApp-> installTranslator ( trans );
105 else 105 else
106 delete trans; 106 delete trans;
107 name = iface-> name ( ); 107 name = iface-> name ( );
108 icon = iface-> icon ( ). pixmap ( QIconSet::Small, QIconSet::Normal ); 108 icon = iface-> icon ( ). pixmap ( QIconSet::Small, QIconSet::Normal );
109 iface-> release ( ); 109 iface-> release ( );
110 lib-> unload ( ); 110 lib-> unload ( );
111 111
112 QCheckListItem *item; 112 QCheckListItem *item;
113 item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox ); 113 item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox );
114 if ( !icon. isNull ( )) 114 if ( !icon. isNull ( ))
115 item-> setPixmap ( 0, icon ); 115 item-> setPixmap ( 0, icon );
116 item-> setOn ( exclude. find ( *it ) == exclude. end ( )); 116 item-> setOn ( exclude. find ( *it ) == exclude. end ( ));
117 m_applets [*it] = item; 117 m_applets [*it] = item;
118 } else { 118 } else {
119 delete lib; 119 delete lib;
120 } 120 }
121 } 121 }
122 122
123 cfg. setGroup ( "Menu" ); 123 cfg. setGroup ( "Menu" );
124 m_menutabs->setChecked( cfg.readBoolEntry( "LauncherTabs", true ) ); 124 m_menutabs->setChecked( cfg.readBoolEntry( "LauncherTabs", true ) );
125 m_menusubpopup->setChecked( cfg.readBoolEntry( "LauncherSubPopup", true ) ); 125 m_menusubpopup->setChecked( cfg.readBoolEntry( "LauncherSubPopup", true ) );
126 m_menusubpopup->setEnabled( m_menutabs->isChecked() ); 126 m_menusubpopup->setEnabled( m_menutabs->isChecked() );
127 connect( m_menutabs, SIGNAL( stateChanged(int) ), m_menusubpopup, SLOT( setEnabled(bool) ) ); 127 connect( m_menutabs, SIGNAL( stateChanged(int) ), m_menusubpopup, SLOT( setEnabled(bool) ) );
128 128
129} 129}
130 130
131void MenuSettings::appletChanged() 131void MenuSettings::appletChanged()
132{ 132{
133 m_applets_changed = true; 133 m_applets_changed = true;
134} 134}
135 135
136void MenuSettings::accept ( ) 136void MenuSettings::accept ( )
137{ 137{
138 bool apps_changed = false; 138 bool apps_changed = false;
139 139
140 Config cfg ( "StartMenu" ); 140 Config cfg ( "StartMenu" );
141 cfg. setGroup ( "Applets" ); 141 cfg. setGroup ( "Applets" );
142 if ( m_applets_changed ) { 142 if ( m_applets_changed ) {
143 QStringList exclude; 143 QStringList exclude;
144 QMap <QString, QCheckListItem *>::Iterator it; 144 QMap <QString, QCheckListItem *>::Iterator it;
145 for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) { 145 for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) {
146 if ( !(*it)-> isOn ( )) 146 if ( !(*it)-> isOn ( ))
147 exclude << it. key ( ); 147 exclude << it. key ( );
148 } 148 }
149 cfg. writeEntry ( "ExcludeApplets", exclude, ',' ); 149 cfg. writeEntry ( "ExcludeApplets", exclude, ',' );
150 } 150 }
151 cfg. writeEntry ( "SafeMode", false ); 151 cfg. writeEntry ( "SafeMode", false );
152 152
153 cfg. setGroup ( "Menu" ); 153 cfg. setGroup ( "Menu" );
154 154
155 if ( m_menutabs-> isChecked ( ) != cfg. readBoolEntry ( "LauncherTabs", true )) { 155 if ( m_menutabs-> isChecked ( ) != cfg. readBoolEntry ( "LauncherTabs", true )) {
156 apps_changed = true; 156 apps_changed = true;
157 cfg. writeEntry ( "LauncherTabs", m_menutabs-> isChecked ( )); 157 cfg. writeEntry ( "LauncherTabs", m_menutabs-> isChecked ( ));
158 } 158 }
159 159
160 if ( m_menusubpopup-> isChecked ( ) != cfg. readBoolEntry ( "LauncherSubPopup", true )) { 160 if ( m_menusubpopup-> isChecked ( ) != cfg. readBoolEntry ( "LauncherSubPopup", true )) {
161 apps_changed = true; 161 apps_changed = true;
162 cfg. writeEntry ( "LauncherSubPopup", m_menusubpopup-> isChecked ( )); 162 cfg. writeEntry ( "LauncherSubPopup", m_menusubpopup-> isChecked ( ));
163 } 163 }
164 164
165 cfg. write ( ); 165 cfg. write ( );
166 166
167 if ( m_applets_changed ) { 167 if ( m_applets_changed ) {
168 QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" ); 168 QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" );
169 m_applets_changed = false; 169 m_applets_changed = false;
170 } 170 }
171 if ( apps_changed ) { 171 if ( apps_changed ) {
172 // currently use reloadApplets() since reloadApps is now used exclusive for server 172 // currently use reloadApplets() since reloadApps is now used exclusive for server
173 // to refresh the tabs. But what we want here is also a refresh of the startmenu entries 173 // to refresh the tabs. But what we want here is also a refresh of the startmenu entries
174 QCopEnvelope ( "QPE/TaskBar", "reloadApps()" ); 174 QCopEnvelope ( "QPE/TaskBar", "reloadApps()" );
175 QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" ); 175 QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" );
176 } 176 }
177} 177}
178 178
diff --git a/core/settings/launcher/taskbarsettings.cpp b/core/settings/launcher/taskbarsettings.cpp
index 8dd9e97..861ff3a 100644
--- a/core/settings/launcher/taskbarsettings.cpp
+++ b/core/settings/launcher/taskbarsettings.cpp
@@ -1,176 +1,176 @@
1/* 1/*
2 This file is part of the OPIE Project 2 This file is part of the OPIE Project
3 =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> 3 =. Copyright (c) 2002 Trolltech AS <info@trolltech.com>
4 .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> 4 .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
5 .>+-= 5 .>+-=
6_;:, .> :=|. This file is free software; you can 6_;:, .> :=|. This file is free software; you can
7.> <`_, > . <= redistribute it and/or modify it under 7.> <`_, > . <= redistribute it and/or modify it under
8:`=1 )Y*s>-.-- : the terms of the GNU General Public 8:`=1 )Y*s>-.-- : the terms of the GNU General Public
9.="- .-=="i, .._ License as published by the Free Software 9.="- .-=="i, .._ License as published by the Free Software
10- . .-<_> .<> Foundation; either version 2 of the License, 10- . .-<_> .<> Foundation; either version 2 of the License,
11 ._= =} : or (at your option) any later version. 11 ._= =} : or (at your option) any later version.
12 .%`+i> _;_. 12 .%`+i> _;_.
13 .i_,=:_. -<s. This file is distributed in the hope that 13 .i_,=:_. -<s. This file is distributed in the hope that
14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
15 : .. .:, . . . without even the implied warranty of 15 : .. .:, . . . without even the implied warranty of
16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General 17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.= = ; Public License for more details. 18..}^=.= = ; Public License for more details.
19++= -. .` .: 19++= -. .` .:
20: = ...= . :.=- You should have received a copy of the GNU 20: = ...= . :.=- You should have received a copy of the GNU
21-. .:....=;==+<; General Public License along with this file; 21-. .:....=;==+<; General Public License along with this file;
22 -_. . . )=. = see the file COPYING. If not, write to the 22 -_. . . )=. = see the file COPYING. If not, write to the
23 -- :-=` Free Software Foundation, Inc., 23 -- :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include "taskbarsettings.h" 29#include "taskbarsettings.h"
30 30
31/* OPIE */ 31/* OPIE */
32#include <qpe/config.h> 32#include <qpe/config.h>
33#include <qpe/qlibrary.h> 33#include <qpe/qlibrary.h>
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/taskbarappletinterface.h> 35#include <qpe/taskbarappletinterface.h>
36#include <qpe/qcopenvelope_qws.h> 36#include <qpe/qcopenvelope_qws.h>
37#include <opie2/odebug.h> 37#include <opie2/odebug.h>
38 38
39/* QT */ 39/* QT */
40#include <qdir.h> 40#include <qdir.h>
41#include <qlistview.h> 41#include <qlistview.h>
42#include <qheader.h> 42#include <qheader.h>
43#include <qlayout.h> 43#include <qlayout.h>
44#include <qlabel.h> 44#include <qlabel.h>
45#include <qwhatsthis.h> 45#include <qwhatsthis.h>
46 46
47/* STD */ 47/* STD */
48#include <stdlib.h> 48#include <stdlib.h>
49 49
50 50
51TaskbarSettings::TaskbarSettings ( QWidget *parent, const char *name ) 51TaskbarSettings::TaskbarSettings ( QWidget *parent, const char *name )
52 : QWidget ( parent, name ) 52 : QWidget ( parent, name )
53{ 53{
54 m_applets_changed = false; 54 m_applets_changed = false;
55 55
56 QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 ); 56 QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 );
57 57
58 QLabel *l = new QLabel ( tr( "Load applets in Taskbar:" ), this ); 58 QLabel *l = new QLabel ( tr( "Load applets in Taskbar:" ), this );
59 lay-> addWidget ( l ); 59 lay-> addWidget ( l );
60 60
61 m_list = new QListView ( this ); 61 m_list = new QListView ( this );
62 m_list-> addColumn ( "foobar" ); 62 m_list-> addColumn ( "foobar" );
63 m_list-> header ( )-> hide ( ); 63 m_list-> header ( )-> hide ( );
64 64
65 lay-> addWidget ( m_list ); 65 lay-> addWidget ( m_list );
66 66
67 QWhatsThis::add ( m_list, tr( "Check the applets that you want displayed in the Taskbar." )); 67 QWhatsThis::add ( m_list, tr( "Check the applets that you want displayed in the Taskbar." ));
68 68
69 connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged())); 69 connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged()));
70 70
71 init ( ); 71 init ( );
72} 72}
73 73
74void TaskbarSettings::init ( ) 74void TaskbarSettings::init ( )
75{ 75{
76 Config cfg ( "Taskbar" ); 76 Config cfg ( "Taskbar" );
77 cfg. setGroup ( "Applets" ); 77 cfg. setGroup ( "Applets" );
78 QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' ); 78 QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' );
79 79
80 QString path = QPEApplication::qpeDir ( ) + "/plugins/applets"; 80 QString path = QPEApplication::qpeDir ( ) + "plugins/applets";
81#ifdef Q_OS_MACX 81#ifdef Q_OS_MACX
82 QStringList list = QDir ( path, "lib*.dylib" ). entryList ( ); 82 QStringList list = QDir ( path, "lib*.dylib" ). entryList ( );
83#else 83#else
84 QStringList list = QDir ( path, "lib*.so" ). entryList ( ); 84 QStringList list = QDir ( path, "lib*.so" ). entryList ( );
85#endif /* Q_OS_MACX */ 85#endif /* Q_OS_MACX */
86 86
87 for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) { 87 for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) {
88 QString name; 88 QString name;
89 QPixmap icon; 89 QPixmap icon;
90 TaskbarNamedAppletInterface *iface = 0; 90 TaskbarNamedAppletInterface *iface = 0;
91 91
92 owarn << "Load applet: " << (*it) << "" << oendl; 92 owarn << "Load applet: " << (*it) << "" << oendl;
93 QLibrary *lib = new QLibrary ( path + "/" + *it ); 93 QLibrary *lib = new QLibrary ( path + "/" + *it );
94 lib-> queryInterface ( IID_TaskbarNamedApplet, (QUnknownInterface**) &iface ); 94 lib-> queryInterface ( IID_TaskbarNamedApplet, (QUnknownInterface**) &iface );
95 owarn << "<1>" << oendl; 95 owarn << "<1>" << oendl;
96 if ( iface ) { 96 if ( iface ) {
97 owarn << "<2>" << oendl; 97 owarn << "<2>" << oendl;
98 QString lang = getenv( "LANG" ); 98 QString lang = getenv( "LANG" );
99 QTranslator *trans = new QTranslator ( qApp ); 99 QTranslator *trans = new QTranslator ( qApp );
100 QString type = (*it). left ((*it). find (".")); 100 QString type = (*it). left ((*it). find ("."));
101 QString tfn = QPEApplication::qpeDir ( ) + "/i18n/" + lang + "/" + type + ".qm"; 101 QString tfn = QPEApplication::qpeDir ( ) + "i18n/" + lang + "/" + type + ".qm";
102 if ( trans-> load ( tfn )) 102 if ( trans-> load ( tfn ))
103 qApp-> installTranslator ( trans ); 103 qApp-> installTranslator ( trans );
104 else 104 else
105 delete trans; 105 delete trans;
106 name = iface-> name ( ); 106 name = iface-> name ( );
107 icon = iface-> icon ( ); 107 icon = iface-> icon ( );
108 iface-> release ( ); 108 iface-> release ( );
109 } 109 }
110 owarn << "<3>" << oendl; 110 owarn << "<3>" << oendl;
111 if ( !iface ) { 111 if ( !iface ) {
112 owarn << "<4>" << oendl; 112 owarn << "<4>" << oendl;
113 lib-> queryInterface ( IID_TaskbarApplet, (QUnknownInterface**) &iface ); 113 lib-> queryInterface ( IID_TaskbarApplet, (QUnknownInterface**) &iface );
114 114
115 if ( iface ) { 115 if ( iface ) {
116 owarn << "<5>" << oendl; 116 owarn << "<5>" << oendl;
117 name = (*it). mid ( 3 ); 117 name = (*it). mid ( 3 );
118 owarn << "Found applet: " << name << "" << oendl; 118 owarn << "Found applet: " << name << "" << oendl;
119#ifdef Q_OS_MACX 119#ifdef Q_OS_MACX
120 int sep = name. find( ".dylib" ); 120 int sep = name. find( ".dylib" );
121#else 121#else
122 int sep = name. find( ".so" ); 122 int sep = name. find( ".so" );
123#endif /* Q_OS_MACX */ 123#endif /* Q_OS_MACX */
124 if ( sep > 0 ) 124 if ( sep > 0 )
125 name. truncate ( sep ); 125 name. truncate ( sep );
126 sep = name. find ( "applet" ); 126 sep = name. find ( "applet" );
127 if ( sep == (int) name.length ( ) - 6 ) 127 if ( sep == (int) name.length ( ) - 6 )
128 name. truncate ( sep ); 128 name. truncate ( sep );
129 name[0] = name[0]. upper ( ); 129 name[0] = name[0]. upper ( );
130 iface-> release ( ); 130 iface-> release ( );
131 } 131 }
132 } 132 }
133 owarn << "<6>" << oendl; 133 owarn << "<6>" << oendl;
134 134
135 if ( iface ) { 135 if ( iface ) {
136 owarn << "<7>" << oendl; 136 owarn << "<7>" << oendl;
137 QCheckListItem *item; 137 QCheckListItem *item;
138 item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox ); 138 item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox );
139 if ( !icon. isNull ( )) 139 if ( !icon. isNull ( ))
140 item-> setPixmap ( 0, icon ); 140 item-> setPixmap ( 0, icon );
141 item-> setOn ( exclude. find ( *it ) == exclude. end ( )); 141 item-> setOn ( exclude. find ( *it ) == exclude. end ( ));
142 m_applets [*it] = item; 142 m_applets [*it] = item;
143 } 143 }
144 lib-> unload ( ); 144 lib-> unload ( );
145 delete lib; 145 delete lib;
146 } 146 }
147} 147}
148 148
149void TaskbarSettings::appletChanged() 149void TaskbarSettings::appletChanged()
150{ 150{
151 m_applets_changed = true; 151 m_applets_changed = true;
152} 152}
153 153
154void TaskbarSettings::accept ( ) 154void TaskbarSettings::accept ( )
155{ 155{
156 Config cfg ( "Taskbar" ); 156 Config cfg ( "Taskbar" );
157 cfg. setGroup ( "Applets" ); 157 cfg. setGroup ( "Applets" );
158 158
159 if ( m_applets_changed ) { 159 if ( m_applets_changed ) {
160 QStringList exclude; 160 QStringList exclude;
161 QMap <QString, QCheckListItem *>::Iterator it; 161 QMap <QString, QCheckListItem *>::Iterator it;
162 for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) { 162 for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) {
163 if ( !(*it)-> isOn ( )) 163 if ( !(*it)-> isOn ( ))
164 exclude << it. key ( ); 164 exclude << it. key ( );
165 } 165 }
166 cfg. writeEntry ( "ExcludeApplets", exclude, ',' ); 166 cfg. writeEntry ( "ExcludeApplets", exclude, ',' );
167 } 167 }
168 cfg. writeEntry ( "SafeMode", false ); 168 cfg. writeEntry ( "SafeMode", false );
169 cfg. write ( ); 169 cfg. write ( );
170 170
171 if ( m_applets_changed ) { 171 if ( m_applets_changed ) {
172 QCopEnvelope e ( "QPE/TaskBar", "reloadApplets()" ); 172 QCopEnvelope e ( "QPE/TaskBar", "reloadApplets()" );
173 m_applets_changed = false; 173 m_applets_changed = false;
174 } 174 }
175} 175}
176 176
diff --git a/core/settings/security/multiauthconfig.cpp b/core/settings/security/multiauthconfig.cpp
index e545e17..45d691b 100644
--- a/core/settings/security/multiauthconfig.cpp
+++ b/core/settings/security/multiauthconfig.cpp
@@ -1,756 +1,756 @@
1#include <opie2/odebug.h> 1#include <opie2/odebug.h>
2#include <opie2/multiauthpassword.h> 2#include <opie2/multiauthpassword.h>
3 3
4#include <qgroupbox.h> 4#include <qgroupbox.h>
5#include <qvgroupbox.h> 5#include <qvgroupbox.h>
6#include <qpe/resource.h> 6#include <qpe/resource.h>
7#include <qlayout.h> 7#include <qlayout.h>
8#include <qlabel.h> 8#include <qlabel.h>
9#include <qhbox.h> 9#include <qhbox.h>
10#include <qheader.h> 10#include <qheader.h>
11#include <qvbox.h> 11#include <qvbox.h>
12#include <qwhatsthis.h> 12#include <qwhatsthis.h>
13#include <qtoolbutton.h> 13#include <qtoolbutton.h>
14#include <qstringlist.h> 14#include <qstringlist.h>
15#include <qdir.h> 15#include <qdir.h>
16#include <qpe/qlibrary.h> 16#include <qpe/qlibrary.h>
17#include <qpe/qpeapplication.h> 17#include <qpe/qpeapplication.h>
18 18
19#include "multiauthconfig.h" 19#include "multiauthconfig.h"
20 20
21 21
22using Opie::Security::MultiauthPluginInterface; 22using Opie::Security::MultiauthPluginInterface;
23using Opie::Security::MultiauthPluginObject; 23using Opie::Security::MultiauthPluginObject;
24using Opie::Security::MultiauthConfigWidget; 24using Opie::Security::MultiauthConfigWidget;
25/// keeps information about MultiauthPluginObject plugins 25/// keeps information about MultiauthPluginObject plugins
26struct MultiauthPlugin { 26struct MultiauthPlugin {
27 MultiauthPlugin() : library( 0 ), iface( 0 ), pluginObject( 0 ) {} 27 MultiauthPlugin() : library( 0 ), iface( 0 ), pluginObject( 0 ) {}
28 /// plugin file 28 /// plugin file
29 QLibrary *library; 29 QLibrary *library;
30 /// the plugin object interface 30 /// the plugin object interface
31 QInterfacePtr<MultiauthPluginInterface> iface; 31 QInterfacePtr<MultiauthPluginInterface> iface;
32 /// the plugin object itself 32 /// the plugin object itself
33 MultiauthPluginObject *pluginObject; 33 MultiauthPluginObject *pluginObject;
34 /// name of the plugin file 34 /// name of the plugin file
35 QString name; 35 QString name;
36 /// should the plugin be launched during authentication or not 36 /// should the plugin be launched during authentication or not
37 bool active; 37 bool active;
38 /// order of the plugin, in the pluginListWidget and during authentication 38 /// order of the plugin, in the pluginListWidget and during authentication
39 int pos; 39 int pos;
40}; 40};
41 41
42/// list of available MultiauthPlugin objects 42/// list of available MultiauthPlugin objects
43static QValueList<MultiauthPlugin> pluginList; 43static QValueList<MultiauthPlugin> pluginList;
44 44
45 45
46/// extension of QToolButton that adds signals, icons and stuff (taken from todayconfig.cpp) 46/// extension of QToolButton that adds signals, icons and stuff (taken from todayconfig.cpp)
47class ToolButton : public QToolButton { 47class ToolButton : public QToolButton {
48 48
49 public: 49 public:
50 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) 50 ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE )
51 : QToolButton( parent, name ) { 51 : QToolButton( parent, name ) {
52 setPixmap( Resource::loadPixmap( icon ) ); 52 setPixmap( Resource::loadPixmap( icon ) );
53 setAutoRaise( TRUE ); 53 setAutoRaise( TRUE );
54 setFocusPolicy( QWidget::NoFocus ); 54 setFocusPolicy( QWidget::NoFocus );
55 setToggleButton( t ); 55 setToggleButton( t );
56 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); 56 connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot );
57 } 57 }
58}; 58};
59 59
60 MultiauthGeneralConfig::MultiauthGeneralConfig(MultiauthConfig * parentConfig, QWidget * parent, const char * name = "general Opie-multiauthentication config widget") 60 MultiauthGeneralConfig::MultiauthGeneralConfig(MultiauthConfig * parentConfig, QWidget * parent, const char * name = "general Opie-multiauthentication config widget")
61: QWidget(parent, name), m_onStart(0), m_onResume(0), m_noProtectConfig(0), m_explanScreens(0), m_nbSuccessMin(0), m_tryButton(0) 61: QWidget(parent, name), m_onStart(0), m_onResume(0), m_noProtectConfig(0), m_explanScreens(0), m_nbSuccessMin(0), m_tryButton(0)
62{ 62{
63 // keep track of the MultiauthConfig parent in one of our attributes 63 // keep track of the MultiauthConfig parent in one of our attributes
64 m_parentConfig = parentConfig; 64 m_parentConfig = parentConfig;
65 QVBoxLayout *vb = new QVBoxLayout(this); 65 QVBoxLayout *vb = new QVBoxLayout(this);
66 vb->setSpacing(11); 66 vb->setSpacing(11);
67 vb->setMargin(11); 67 vb->setMargin(11);
68 vb->setAlignment( Qt::AlignTop ); 68 vb->setAlignment( Qt::AlignTop );
69 69
70 QGroupBox *lockBox = new QGroupBox(0, Qt::Vertical, tr("When to lock Opie"), this, "lock box"); 70 QGroupBox *lockBox = new QGroupBox(0, Qt::Vertical, tr("When to lock Opie"), this, "lock box");
71 vb->addWidget(lockBox); 71 vb->addWidget(lockBox);
72 QGridLayout *boxLayout = new QGridLayout( lockBox->layout() ); 72 QGridLayout *boxLayout = new QGridLayout( lockBox->layout() );
73 m_onStart = new QCheckBox( tr( "on Opie start" ), lockBox, "lock on opie start"); 73 m_onStart = new QCheckBox( tr( "on Opie start" ), lockBox, "lock on opie start");
74 m_onResume = new QCheckBox( tr( "on Opie resume" ), lockBox, "lock on opie resume"); 74 m_onResume = new QCheckBox( tr( "on Opie resume" ), lockBox, "lock on opie resume");
75 boxLayout->addWidget(m_onStart, 0, 0); 75 boxLayout->addWidget(m_onStart, 0, 0);
76 boxLayout->addWidget(m_onResume, 0, 1); 76 boxLayout->addWidget(m_onResume, 0, 1);
77 77
78 QGroupBox *nbBox = new QGroupBox(0, Qt::Vertical, tr("Multiple plugins authentication"), this, "nb box"); 78 QGroupBox *nbBox = new QGroupBox(0, Qt::Vertical, tr("Multiple plugins authentication"), this, "nb box");
79 vb->addWidget(nbBox); 79 vb->addWidget(nbBox);
80 QGridLayout *nbBoxLayout = new QGridLayout( nbBox->layout() ); 80 QGridLayout *nbBoxLayout = new QGridLayout( nbBox->layout() );
81 m_nbSuccessMin = new QSpinBox(nbBox); 81 m_nbSuccessMin = new QSpinBox(nbBox);
82 QLabel *lNbSuccessMin = new QLabel( tr( "Required successes" ), nbBox); 82 QLabel *lNbSuccessMin = new QLabel( tr( "Required successes" ), nbBox);
83 nbBoxLayout->addWidget(m_nbSuccessMin, 0, 0); 83 nbBoxLayout->addWidget(m_nbSuccessMin, 0, 0);
84 nbBoxLayout->addWidget(lNbSuccessMin, 0, 1); 84 nbBoxLayout->addWidget(lNbSuccessMin, 0, 1);
85 m_nbSuccessMin->setMinValue(1); // the max value is defined in MultiauthConfig constructor 85 m_nbSuccessMin->setMinValue(1); // the max value is defined in MultiauthConfig constructor
86 86
87 QGroupBox *devBox = new QGroupBox(0, Qt::Vertical, tr("Options"), this, "dev box"); 87 QGroupBox *devBox = new QGroupBox(0, Qt::Vertical, tr("Options"), this, "dev box");
88 vb->addWidget(devBox); 88 vb->addWidget(devBox);
89 QGridLayout *devBoxLayout = new QGridLayout( devBox->layout() ); 89 QGridLayout *devBoxLayout = new QGridLayout( devBox->layout() );
90 m_noProtectConfig = new QCheckBox( tr("Don't protect this config screen"), devBox, "don't protect config"); 90 m_noProtectConfig = new QCheckBox( tr("Don't protect this config screen"), devBox, "don't protect config");
91 m_explanScreens = new QCheckBox( tr("Show explanatory screens"), devBox, "Show explan. screens"); 91 m_explanScreens = new QCheckBox( tr("Show explanatory screens"), devBox, "Show explan. screens");
92 devBoxLayout->addWidget(m_noProtectConfig, 0, 0); 92 devBoxLayout->addWidget(m_noProtectConfig, 0, 0);
93 devBoxLayout->addWidget(m_explanScreens, 1, 0); 93 devBoxLayout->addWidget(m_explanScreens, 1, 0);
94 94
95 QVGroupBox *tryBox = new QVGroupBox(tr("Testing"), this, "try box"); 95 QVGroupBox *tryBox = new QVGroupBox(tr("Testing"), this, "try box");
96 vb->addWidget(tryBox); 96 vb->addWidget(tryBox);
97 m_tryButton = new QPushButton( tr("Test the authentication now"), tryBox, "try button"); 97 m_tryButton = new QPushButton( tr("Test the authentication now"), tryBox, "try button");
98 connect( m_tryButton, SIGNAL(clicked()), this, SLOT(tryAuth()) ); 98 connect( m_tryButton, SIGNAL(clicked()), this, SLOT(tryAuth()) );
99 99
100} 100}
101 101
102/// nothing to do 102/// nothing to do
103MultiauthGeneralConfig::~MultiauthGeneralConfig() 103MultiauthGeneralConfig::~MultiauthGeneralConfig()
104{} 104{}
105 105
106/// launches the authentication process, as configured, with the option to bypass it 106/// launches the authentication process, as configured, with the option to bypass it
107void MultiauthGeneralConfig::tryAuth() 107void MultiauthGeneralConfig::tryAuth()
108{ 108{
109 QMessageBox confirmSave( 109 QMessageBox confirmSave(
110 tr("Attention"), 110 tr("Attention"),
111 "<p>" + tr("You must save your current settings before trying to authenticate. Press OK to accept and launch a simulated authentication process.") + "</p><p><em>" + 111 "<p>" + tr("You must save your current settings before trying to authenticate. Press OK to accept and launch a simulated authentication process.") + "</p><p><em>" +
112 tr("If you don't like the result of this test, don't forget to change your settings before you exit the configuration application!") + "</em></p>", 112 tr("If you don't like the result of this test, don't forget to change your settings before you exit the configuration application!") + "</em></p>",
113 QMessageBox::Warning, 113 QMessageBox::Warning,
114 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 114 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
115 0, QString::null, TRUE, WStyle_StaysOnTop); 115 0, QString::null, TRUE, WStyle_StaysOnTop);
116 confirmSave.setButtonText(QMessageBox::Cancel, tr("Cancel")); 116 confirmSave.setButtonText(QMessageBox::Cancel, tr("Cancel"));
117 confirmSave.setButtonText(QMessageBox::Yes, tr("OK")); 117 confirmSave.setButtonText(QMessageBox::Yes, tr("OK"));
118 118
119 if ( confirmSave.exec() == QMessageBox::Yes) 119 if ( confirmSave.exec() == QMessageBox::Yes)
120 { 120 {
121 owarn << "writing config as user accepted" << oendl; 121 owarn << "writing config as user accepted" << oendl;
122 m_parentConfig->writeConfigs(); 122 m_parentConfig->writeConfigs();
123 owarn << "testing authentication" << oendl; 123 owarn << "testing authentication" << oendl;
124 // launch the authentication in testing mode 124 // launch the authentication in testing mode
125 Opie::Security::MultiauthPassword::authenticate(Opie::Security::TestNow); 125 Opie::Security::MultiauthPassword::authenticate(Opie::Security::TestNow);
126 } 126 }
127} 127}
128 128
129 129
130/// Builds and displays the Opie multi-authentication configuration dialog 130/// Builds and displays the Opie multi-authentication configuration dialog
131static void test_and_start() { 131static void test_and_start() {
132 Config pcfg("Security"); 132 Config pcfg("Security");
133 pcfg.setGroup( "Misc" ); 133 pcfg.setGroup( "Misc" );
134 bool protectConfigDialog = ! pcfg.readBoolEntry("noProtectConfig", true); 134 bool protectConfigDialog = ! pcfg.readBoolEntry("noProtectConfig", true);
135 135
136 if (protectConfigDialog && Opie::Security::Internal::runPlugins() != 0) { 136 if (protectConfigDialog && Opie::Security::Internal::runPlugins() != 0) {
137 owarn << "authentication failed, not showing opie-security" << oendl; 137 owarn << "authentication failed, not showing opie-security" << oendl;
138 exit( -1 ); 138 exit( -1 );
139 } 139 }
140} 140}
141 141
142 142
143 143
144 MultiauthConfig::MultiauthConfig(QWidget* par, const char* w = "MultiauthConfig dialog", WFlags f = 0) 144 MultiauthConfig::MultiauthConfig(QWidget* par, const char* w = "MultiauthConfig dialog", WFlags f = 0)
145: QDialog(par, w, TRUE, f), 145: QDialog(par, w, TRUE, f),
146 m_mainTW(0), m_pluginListView(0), m_pluginListWidget(0), 146 m_mainTW(0), m_pluginListView(0), m_pluginListWidget(0),
147 m_generalConfig(0), m_loginWidget(0), m_syncWidget(0), 147 m_generalConfig(0), m_loginWidget(0), m_syncWidget(0),
148 m_nbSuccessReq(0), m_plugins_changed(false) 148 m_nbSuccessReq(0), m_plugins_changed(false)
149{ 149{
150 /* Initializes the global configuration window 150 /* Initializes the global configuration window
151 */ 151 */
152 test_and_start(); 152 test_and_start();
153 153
154 /* Checks (and memorizes) if any authentication plugins are 154 /* Checks (and memorizes) if any authentication plugins are
155 * installed on the system 155 * installed on the system
156 */ 156 */
157 QString path = QPEApplication::qpeDir() + "/plugins/security"; 157 QString path = QPEApplication::qpeDir() + "plugins/security";
158 QDir dir( path, "lib*.so" ); 158 QDir dir( path, "lib*.so" );
159 QStringList list = dir.entryList(); 159 QStringList list = dir.entryList();
160 160
161 m_pluginsInstalled = ! list.isEmpty(); 161 m_pluginsInstalled = ! list.isEmpty();
162 if (m_pluginsInstalled == false) 162 if (m_pluginsInstalled == false)
163 owarn << "no authentication plugins installed! Talking about it in the last tab..." << oendl; 163 owarn << "no authentication plugins installed! Talking about it in the last tab..." << oendl;
164 164
165 setCaption( tr( "Security configuration" ) ); 165 setCaption( tr( "Security configuration" ) );
166 QVBoxLayout *layout = new QVBoxLayout( this ); 166 QVBoxLayout *layout = new QVBoxLayout( this );
167 m_mainTW = new Opie::Ui::OTabWidget( this, "main tab widget" ); 167 m_mainTW = new Opie::Ui::OTabWidget( this, "main tab widget" );
168 layout->addWidget(m_mainTW); 168 layout->addWidget(m_mainTW);
169 169
170 if (m_pluginsInstalled) 170 if (m_pluginsInstalled)
171 { 171 {
172 m_pluginListWidget = new QWidget(m_mainTW, "plugin list widget"); 172 m_pluginListWidget = new QWidget(m_mainTW, "plugin list widget");
173 QVBoxLayout * pluginListLayout = new QVBoxLayout(m_pluginListWidget); 173 QVBoxLayout * pluginListLayout = new QVBoxLayout(m_pluginListWidget);
174 pluginListLayout->setSpacing(6); 174 pluginListLayout->setSpacing(6);
175 pluginListLayout->setMargin(11); 175 pluginListLayout->setMargin(11);
176 QLabel * pluginListTitle = new QLabel( tr( "Load which plugins in what order:" ), m_pluginListWidget ); 176 QLabel * pluginListTitle = new QLabel( tr( "Load which plugins in what order:" ), m_pluginListWidget );
177 pluginListLayout->addWidget(pluginListTitle); 177 pluginListLayout->addWidget(pluginListTitle);
178 QHBox * pluginListHB = new QHBox(m_pluginListWidget); 178 QHBox * pluginListHB = new QHBox(m_pluginListWidget);
179 pluginListLayout->addWidget(pluginListHB); 179 pluginListLayout->addWidget(pluginListHB);
180 180
181 m_pluginListView = new QListView(pluginListHB); 181 m_pluginListView = new QListView(pluginListHB);
182 m_pluginListView->addColumn("PluginList"); 182 m_pluginListView->addColumn("PluginList");
183 m_pluginListView->header()->hide(); 183 m_pluginListView->header()->hide();
184 m_pluginListView->setSorting(-1); 184 m_pluginListView->setSorting(-1);
185 QWhatsThis::add(m_pluginListView, tr( "Check a checkbox to activate/deactivate a plugin or use the arrow buttons on the right to change the order they will appear in" )); 185 QWhatsThis::add(m_pluginListView, tr( "Check a checkbox to activate/deactivate a plugin or use the arrow buttons on the right to change the order they will appear in" ));
186 186
187 QVBox * pluginListVB = new QVBox(pluginListHB); 187 QVBox * pluginListVB = new QVBox(pluginListHB);
188 new ToolButton( pluginListVB, tr( "Move Up" ), "up", this , SLOT( moveSelectedUp() ) ); 188 new ToolButton( pluginListVB, tr( "Move Up" ), "up", this , SLOT( moveSelectedUp() ) );
189 new ToolButton( pluginListVB, tr( "Move Down" ), "down", this , SLOT( moveSelectedDown() ) ); 189 new ToolButton( pluginListVB, tr( "Move Down" ), "down", this , SLOT( moveSelectedDown() ) );
190 m_mainTW->addTab( m_pluginListWidget, "pass", tr( "plugins" ) ); 190 m_mainTW->addTab( m_pluginListWidget, "pass", tr( "plugins" ) );
191 191
192 connect ( m_pluginListView , SIGNAL( clicked ( QListViewItem * ) ), this, SLOT( pluginsChanged ( ) ) ); 192 connect ( m_pluginListView , SIGNAL( clicked ( QListViewItem * ) ), this, SLOT( pluginsChanged ( ) ) );
193 193
194 // general Opie multi-authentication configuration tab 194 // general Opie multi-authentication configuration tab
195 m_generalConfig = new MultiauthGeneralConfig(this, m_mainTW); 195 m_generalConfig = new MultiauthGeneralConfig(this, m_mainTW);
196 m_mainTW->addTab(m_generalConfig, "SettingsIcon", tr( "Authentication") ); 196 m_mainTW->addTab(m_generalConfig, "SettingsIcon", tr( "Authentication") );
197 197
198 } 198 }
199 // login settings page 199 // login settings page
200 m_loginWidget = new LoginBase(m_mainTW, "login config widget"); 200 m_loginWidget = new LoginBase(m_mainTW, "login config widget");
201 m_mainTW->addTab(m_loginWidget, "security/users", tr( "Login") ); 201 m_mainTW->addTab(m_loginWidget, "security/users", tr( "Login") );
202 202
203 // sync settings page 203 // sync settings page
204 m_syncWidget = new SyncBase( m_mainTW, "sync config widget" ); 204 m_syncWidget = new SyncBase( m_mainTW, "sync config widget" );
205 m_mainTW->addTab(m_syncWidget, "security/sync", tr( "Sync") ); 205 m_mainTW->addTab(m_syncWidget, "security/sync", tr( "Sync") );
206 206
207 // read the "Security" Config file and update our UI 207 // read the "Security" Config file and update our UI
208 readConfig(); 208 readConfig();
209 209
210 210
211 if (m_pluginsInstalled) 211 if (m_pluginsInstalled)
212 { 212 {
213 /* loads plugins configuration widgets in mainTW tabs and in pluginListView 213 /* loads plugins configuration widgets in mainTW tabs and in pluginListView
214 */ 214 */
215 215
216 loadPlugins(); 216 loadPlugins();
217 217
218 for ( int i = pluginList.count() - 1; i >= 0; i-- ) { 218 for ( int i = pluginList.count() - 1; i >= 0; i-- ) {
219 MultiauthPlugin plugin = pluginList[i]; 219 MultiauthPlugin plugin = pluginList[i];
220 220
221 // load the config widgets in the tabs 221 // load the config widgets in the tabs
222 // (configWidget will return 0l if there is no configuration GUI) 222 // (configWidget will return 0l if there is no configuration GUI)
223 MultiauthConfigWidget* widget = plugin.pluginObject->configWidget(m_mainTW); 223 MultiauthConfigWidget* widget = plugin.pluginObject->configWidget(m_mainTW);
224 if ( widget != 0l ) { 224 if ( widget != 0l ) {
225 odebug << "plugin " << plugin.name << " has a configuration widget" << oendl; 225 odebug << "plugin " << plugin.name << " has a configuration widget" << oendl;
226 configWidgetList.append(widget); 226 configWidgetList.append(widget);
227 m_mainTW->addTab( widget, plugin.pluginObject->pixmapNameConfig(), 227 m_mainTW->addTab( widget, plugin.pluginObject->pixmapNameConfig(),
228 plugin.pluginObject->pluginName() ); 228 plugin.pluginObject->pluginName() );
229 } 229 }
230 // set the order/activate tab 230 // set the order/activate tab
231 QPixmap icon = Resource::loadPixmap( plugin.pluginObject->pixmapNameWidget() ); 231 QPixmap icon = Resource::loadPixmap( plugin.pluginObject->pixmapNameWidget() );
232 QCheckListItem * item = new QCheckListItem(m_pluginListView, plugin.pluginObject->pluginName(), QCheckListItem::CheckBox ); 232 QCheckListItem * item = new QCheckListItem(m_pluginListView, plugin.pluginObject->pluginName(), QCheckListItem::CheckBox );
233 if ( !icon.isNull() ) { 233 if ( !icon.isNull() ) {
234 item->setPixmap( 0, icon ); 234 item->setPixmap( 0, icon );
235 } 235 }
236 if ( m_excludePlugins.find( plugin.name ) == m_excludePlugins.end() ) { 236 if ( m_excludePlugins.find( plugin.name ) == m_excludePlugins.end() ) {
237 item->setOn( TRUE ); 237 item->setOn( TRUE );
238 } 238 }
239 m_plugins[plugin.name] = item; 239 m_plugins[plugin.name] = item;
240 } 240 }
241 241
242 // set the first tab as default. 242 // set the first tab as default.
243 m_mainTW->setCurrentTab(m_pluginListWidget); 243 m_mainTW->setCurrentTab(m_pluginListWidget);
244 244
245 // put the number of plugins as the max number of req. auth. 245 // put the number of plugins as the max number of req. auth.
246 m_generalConfig->m_nbSuccessMin->setMaxValue( pluginList.count() ); 246 m_generalConfig->m_nbSuccessMin->setMaxValue( pluginList.count() );
247 } 247 }
248 else 248 else
249 { 249 {
250 /* we don't have any installed plugin there. Let's tell 250 /* we don't have any installed plugin there. Let's tell
251 * that to the user in a third tab, using the m_pluginListWidget widget 251 * that to the user in a third tab, using the m_pluginListWidget widget
252 */ 252 */
253 m_pluginListWidget = new QWidget(m_mainTW, "plugin list widget (no plugins warning)"); 253 m_pluginListWidget = new QWidget(m_mainTW, "plugin list widget (no plugins warning)");
254 QVBoxLayout * pluginListLayout = new QVBoxLayout(m_pluginListWidget); 254 QVBoxLayout * pluginListLayout = new QVBoxLayout(m_pluginListWidget);
255 pluginListLayout->setSpacing(11); 255 pluginListLayout->setSpacing(11);
256 pluginListLayout->setMargin(11); 256 pluginListLayout->setMargin(11);
257 pluginListLayout->setAlignment( Qt::AlignTop ); 257 pluginListLayout->setAlignment( Qt::AlignTop );
258 QVGroupBox *warningBox = new QVGroupBox(tr("Important notice"), m_pluginListWidget, "noPlugins warning box"); 258 QVGroupBox *warningBox = new QVGroupBox(tr("Important notice"), m_pluginListWidget, "noPlugins warning box");
259 pluginListLayout->addWidget(warningBox); 259 pluginListLayout->addWidget(warningBox);
260 QLabel * warningText = new QLabel( "<p>" + tr("To be able to protect your PDA with one or more authentication plugins (for example, a simple PIN authentication), you must install at least one <em>opie-multiauth-*</em> package! Once you have done that, you will be able to configure your PDA protection here.") + "</p>", warningBox ); 260 QLabel * warningText = new QLabel( "<p>" + tr("To be able to protect your PDA with one or more authentication plugins (for example, a simple PIN authentication), you must install at least one <em>opie-multiauth-*</em> package! Once you have done that, you will be able to configure your PDA protection here.") + "</p>", warningBox );
261 261
262 m_mainTW->addTab(m_pluginListWidget, "security/Security", tr( "Locking") ); 262 m_mainTW->addTab(m_pluginListWidget, "security/Security", tr( "Locking") );
263 263
264 // set the first tab as default. 264 // set the first tab as default.
265 m_mainTW->setCurrentTab(m_loginWidget); 265 m_mainTW->setCurrentTab(m_loginWidget);
266 } 266 }
267 267
268 showMaximized(); 268 showMaximized();
269} 269}
270 270
271/// nothing to do 271/// nothing to do
272MultiauthConfig::~MultiauthConfig() 272MultiauthConfig::~MultiauthConfig()
273{ 273{
274} 274}
275 275
276/// saves the general and plugin(s) configurations 276/// saves the general and plugin(s) configurations
277void MultiauthConfig::writeConfigs() { 277void MultiauthConfig::writeConfigs() {
278 writeConfig(); 278 writeConfig();
279 279
280 MultiauthConfigWidget* confWidget = 0; 280 MultiauthConfigWidget* confWidget = 0;
281 for ( confWidget = configWidgetList.first(); confWidget != 0; 281 for ( confWidget = configWidgetList.first(); confWidget != 0;
282 confWidget = configWidgetList.next() ) 282 confWidget = configWidgetList.next() )
283 confWidget->writeConfig(); 283 confWidget->writeConfig();
284} 284}
285 285
286/// on QDialog::accept, we save all the configurations and exit the QDialog normally 286/// on QDialog::accept, we save all the configurations and exit the QDialog normally
287void MultiauthConfig::accept() { 287void MultiauthConfig::accept() {
288 writeConfigs(); 288 writeConfigs();
289 QDialog::accept(); 289 QDialog::accept();
290} 290}
291 291
292void MultiauthConfig::done( int r ) { 292void MultiauthConfig::done( int r ) {
293 QDialog::done( r ); 293 QDialog::done( r );
294 close(); 294 close();
295} 295}
296 296
297/// moves up the selected plugin 297/// moves up the selected plugin
298void MultiauthConfig::moveSelectedUp() 298void MultiauthConfig::moveSelectedUp()
299{ 299{
300 QListViewItem *item = m_pluginListView->selectedItem(); 300 QListViewItem *item = m_pluginListView->selectedItem();
301 if ( item && item->itemAbove() ) { 301 if ( item && item->itemAbove() ) {
302 item->itemAbove()->moveItem( item ); 302 item->itemAbove()->moveItem( item );
303 } 303 }
304} 304}
305 305
306/// moves down the selected plugin 306/// moves down the selected plugin
307void MultiauthConfig::moveSelectedDown() 307void MultiauthConfig::moveSelectedDown()
308{ 308{
309 QListViewItem *item = m_pluginListView->selectedItem(); 309 QListViewItem *item = m_pluginListView->selectedItem();
310 if ( item && item->itemBelow() ) { 310 if ( item && item->itemBelow() ) {
311 item->moveItem( item->itemBelow() ); 311 item->moveItem( item->itemBelow() );
312 } 312 }
313} 313}
314 314
315/// reads the <code>Security.conf</code> Config file, and updates parts of the user interface 315/// reads the <code>Security.conf</code> Config file, and updates parts of the user interface
316void MultiauthConfig::readConfig() 316void MultiauthConfig::readConfig()
317{ 317{
318 // pointer, so we release this Config when we want 318 // pointer, so we release this Config when we want
319 Config* pcfg = new Config("Security"); 319 Config* pcfg = new Config("Security");
320 320
321 if (m_pluginsInstalled) 321 if (m_pluginsInstalled)
322 { 322 {
323 pcfg->setGroup( "Misc" ); 323 pcfg->setGroup( "Misc" );
324 m_generalConfig->m_onStart->setChecked( pcfg->readBoolEntry( "onStart", false ) ); 324 m_generalConfig->m_onStart->setChecked( pcfg->readBoolEntry( "onStart", false ) );
325 m_generalConfig->m_onResume->setChecked( pcfg->readBoolEntry( "onResume", false ) ); 325 m_generalConfig->m_onResume->setChecked( pcfg->readBoolEntry( "onResume", false ) );
326 m_generalConfig->m_nbSuccessMin->setValue( pcfg->readNumEntry( "nbSuccessMin", 1 ) ); 326 m_generalConfig->m_nbSuccessMin->setValue( pcfg->readNumEntry( "nbSuccessMin", 1 ) );
327 m_generalConfig->m_noProtectConfig->setChecked( pcfg->readBoolEntry( "noProtectConfig", true) ); 327 m_generalConfig->m_noProtectConfig->setChecked( pcfg->readBoolEntry( "noProtectConfig", true) );
328 m_generalConfig->m_explanScreens->setChecked( pcfg->readBoolEntry( "explanScreens", true ) ); 328 m_generalConfig->m_explanScreens->setChecked( pcfg->readBoolEntry( "explanScreens", true ) );
329 329
330 pcfg->setGroup( "Plugins" ); 330 pcfg->setGroup( "Plugins" );
331 m_excludePlugins = pcfg->readListEntry( "ExcludePlugins", ',' ); 331 m_excludePlugins = pcfg->readListEntry( "ExcludePlugins", ',' );
332 m_allPlugins = pcfg->readListEntry( "AllPlugins", ',' ); 332 m_allPlugins = pcfg->readListEntry( "AllPlugins", ',' );
333 } 333 }
334 334
335 /* Login and Sync stuff */ 335 /* Login and Sync stuff */
336 pcfg->setGroup("Sync"); 336 pcfg->setGroup("Sync");
337 int auth_peer = pcfg->readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24 337 int auth_peer = pcfg->readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24
338 int auth_peer_bits = pcfg->readNumEntry("auth_peer_bits",24); 338 int auth_peer_bits = pcfg->readNumEntry("auth_peer_bits",24);
339 339
340 pcfg->setGroup("SyncMode"); 340 pcfg->setGroup("SyncMode");
341 int mode = pcfg->readNumEntry("Mode",2); // Default to Sharp 341 int mode = pcfg->readNumEntry("Mode",2); // Default to Sharp
342 switch( mode ) { 342 switch( mode ) {
343 case 0x01: 343 case 0x01:
344 m_syncWidget->syncModeCombo->setCurrentItem( 0 ); 344 m_syncWidget->syncModeCombo->setCurrentItem( 0 );
345 break; 345 break;
346 case 0x02: 346 case 0x02:
347 default: 347 default:
348 m_syncWidget->syncModeCombo->setCurrentItem( 1 ); 348 m_syncWidget->syncModeCombo->setCurrentItem( 1 );
349 break; 349 break;
350 case 0x04: 350 case 0x04:
351 m_syncWidget->syncModeCombo->setCurrentItem( 2 ); 351 m_syncWidget->syncModeCombo->setCurrentItem( 2 );
352 break; 352 break;
353 } 353 }
354 /* 354 /*
355 cfg.setGroup("Remote"); 355 cfg.setGroup("Remote");
356 if ( telnetAvailable() ) 356 if ( telnetAvailable() )
357 telnet->setChecked(cfg.readEntry("allow_telnet")); 357 telnet->setChecked(cfg.readEntry("allow_telnet"));
358 else 358 else
359 telnet->hide(); 359 telnet->hide();
360 360
361 if ( sshAvailable() ) 361 if ( sshAvailable() )
362 ssh->setChecked(cfg.readEntry("allow_ssh")); 362 ssh->setChecked(cfg.readEntry("allow_ssh"));
363 else 363 else
364 ssh->hide(); 364 ssh->hide();
365 */ 365 */
366 366
367 // release the Config handler 367 // release the Config handler
368 delete pcfg; 368 delete pcfg;
369 // indeed, selectNet will open the config file... 369 // indeed, selectNet will open the config file...
370 selectNet(auth_peer,auth_peer_bits,TRUE); 370 selectNet(auth_peer,auth_peer_bits,TRUE);
371 371
372 connect( m_syncWidget->syncnet, SIGNAL(textChanged(const QString&)), 372 connect( m_syncWidget->syncnet, SIGNAL(textChanged(const QString&)),
373 this, SLOT(setSyncNet(const QString&))); 373 this, SLOT(setSyncNet(const QString&)));
374 374
375 375
376 376
377 QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf"; 377 QString configFile = QPEApplication::qpeDir() + "etc/opie-login.conf";
378 Config loginCfg(configFile,Config::File); 378 Config loginCfg(configFile,Config::File);
379 379
380 loginCfg.setGroup("General"); 380 loginCfg.setGroup("General");
381 autoLoginName=loginCfg.readEntry("AutoLogin",""); 381 autoLoginName=loginCfg.readEntry("AutoLogin","");
382 382
383 if (autoLoginName.stripWhiteSpace().isEmpty()) { 383 if (autoLoginName.stripWhiteSpace().isEmpty()) {
384 autoLogin=false; 384 autoLogin=false;
385 } else { 385 } else {
386 autoLogin=true; 386 autoLogin=true;
387 } 387 }
388 388
389 389
390 connect(m_loginWidget->autologinToggle, SIGNAL(toggled(bool)), this, SLOT(toggleAutoLogin(bool))); 390 connect(m_loginWidget->autologinToggle, SIGNAL(toggled(bool)), this, SLOT(toggleAutoLogin(bool)));
391 connect(m_loginWidget->userlist, SIGNAL(activated(int)), this, SLOT(changeLoginName(int))); 391 connect(m_loginWidget->userlist, SIGNAL(activated(int)), this, SLOT(changeLoginName(int)));
392 connect(m_syncWidget->restoredefaults,SIGNAL(clicked()), this, SLOT(restoreDefaults())); 392 connect(m_syncWidget->restoredefaults,SIGNAL(clicked()), this, SLOT(restoreDefaults()));
393 connect(m_syncWidget->deleteentry,SIGNAL(clicked()), this, SLOT(deleteListEntry())); 393 connect(m_syncWidget->deleteentry,SIGNAL(clicked()), this, SLOT(deleteListEntry()));
394 394
395 loadUsers(); 395 loadUsers();
396 updateGUI(); 396 updateGUI();
397 397
398} 398}
399 399
400void MultiauthConfig::writeConfig() 400void MultiauthConfig::writeConfig()
401{ 401{
402 Config* pcfg = new Config("Security"); 402 Config* pcfg = new Config("Security");
403 403
404 if (m_pluginsInstalled) 404 if (m_pluginsInstalled)
405 { 405 {
406 pcfg->setGroup( "Plugins" ); 406 pcfg->setGroup( "Plugins" );
407 QStringList exclude; 407 QStringList exclude;
408 QStringList include; 408 QStringList include;
409 QStringList allPlugins; 409 QStringList allPlugins;
410 410
411 QListViewItemIterator list_it( m_pluginListView ); 411 QListViewItemIterator list_it( m_pluginListView );
412 412
413 // this makes sure the names get saved in the order selected 413 // this makes sure the names get saved in the order selected
414 for ( ; list_it.current(); ++list_it ) { 414 for ( ; list_it.current(); ++list_it ) {
415 QMap <QString, QCheckListItem *>::Iterator it; 415 QMap <QString, QCheckListItem *>::Iterator it;
416 for ( it = m_plugins.begin(); it != m_plugins. end (); ++it ) { 416 for ( it = m_plugins.begin(); it != m_plugins. end (); ++it ) {
417 if ( list_it.current() == (*it) && !(*it)-> isOn () ) { 417 if ( list_it.current() == (*it) && !(*it)-> isOn () ) {
418 exclude << it.key(); 418 exclude << it.key();
419 } else if ( list_it.current() == (*it) && (*it)-> isOn () ){ 419 } else if ( list_it.current() == (*it) && (*it)-> isOn () ){
420 include << it.key(); 420 include << it.key();
421 } 421 }
422 if ( list_it.current() == (*it) ) { 422 if ( list_it.current() == (*it) ) {
423 allPlugins << it.key(); 423 allPlugins << it.key();
424 } 424 }
425 } 425 }
426 } 426 }
427 pcfg->writeEntry( "ExcludePlugins", exclude, ',' ); 427 pcfg->writeEntry( "ExcludePlugins", exclude, ',' );
428 pcfg->writeEntry( "IncludePlugins", include, ',' ); 428 pcfg->writeEntry( "IncludePlugins", include, ',' );
429 pcfg->writeEntry( "AllPlugins", allPlugins, ',' ); 429 pcfg->writeEntry( "AllPlugins", allPlugins, ',' );
430 430
431 pcfg->setGroup( "Misc" ); 431 pcfg->setGroup( "Misc" );
432 pcfg->writeEntry( "onStart", m_generalConfig->m_onStart->isChecked() ); 432 pcfg->writeEntry( "onStart", m_generalConfig->m_onStart->isChecked() );
433 pcfg->writeEntry( "onResume", m_generalConfig->m_onResume->isChecked() ); 433 pcfg->writeEntry( "onResume", m_generalConfig->m_onResume->isChecked() );
434 pcfg->writeEntry( "nbSuccessMin", m_generalConfig->m_nbSuccessMin->text() ); 434 pcfg->writeEntry( "nbSuccessMin", m_generalConfig->m_nbSuccessMin->text() );
435 pcfg->writeEntry( "noProtectConfig", m_generalConfig->m_noProtectConfig->isChecked() ); 435 pcfg->writeEntry( "noProtectConfig", m_generalConfig->m_noProtectConfig->isChecked() );
436 pcfg->writeEntry( "explanScreens", m_generalConfig->m_explanScreens->isChecked() ); 436 pcfg->writeEntry( "explanScreens", m_generalConfig->m_explanScreens->isChecked() );
437 } 437 }
438 438
439 /* Login and Sync stuff */ 439 /* Login and Sync stuff */
440 440
441 pcfg->setGroup("Sync"); 441 pcfg->setGroup("Sync");
442 int auth_peer=0; 442 int auth_peer=0;
443 int auth_peer_bits; 443 int auth_peer_bits;
444 QString sn = m_syncWidget->syncnet->currentText(); 444 QString sn = m_syncWidget->syncnet->currentText();
445 parseNet(sn,auth_peer,auth_peer_bits); 445 parseNet(sn,auth_peer,auth_peer_bits);
446 446
447 //this is the *selected* (active) net range 447 //this is the *selected* (active) net range
448 pcfg->writeEntry("auth_peer",auth_peer); 448 pcfg->writeEntry("auth_peer",auth_peer);
449 pcfg->writeEntry("auth_peer_bits",auth_peer_bits); 449 pcfg->writeEntry("auth_peer_bits",auth_peer_bits);
450 450
451 //write back all other net ranges in *cleartext* 451 //write back all other net ranges in *cleartext*
452 for (int i=0; i<10; i++) { 452 for (int i=0; i<10; i++) {
453 QString target; 453 QString target;
454 target.sprintf("net%d", i); 454 target.sprintf("net%d", i);
455 if ( i < m_syncWidget->syncnet->count() ) 455 if ( i < m_syncWidget->syncnet->count() )
456 pcfg->writeEntry(target, m_syncWidget->syncnet->text(i)); 456 pcfg->writeEntry(target, m_syncWidget->syncnet->text(i));
457 else // no more entry in the syncnet list -> we clear the line 457 else // no more entry in the syncnet list -> we clear the line
458 pcfg->writeEntry(target, ""); 458 pcfg->writeEntry(target, "");
459 } 459 }
460 460
461#ifdef ODP 461#ifdef ODP
462#error "Use 0,1,2 and use Launcher" 462#error "Use 0,1,2 and use Launcher"
463#endif 463#endif
464 /* keep the old code so we don't use currentItem directly */ 464 /* keep the old code so we don't use currentItem directly */
465 int value = 0x02; 465 int value = 0x02;
466 switch( m_syncWidget->syncModeCombo->currentItem() ) { 466 switch( m_syncWidget->syncModeCombo->currentItem() ) {
467 case 0: 467 case 0:
468 value = 0x01; 468 value = 0x01;
469 break; 469 break;
470 case 1: 470 case 1:
471 value = 0x02; 471 value = 0x02;
472 break; 472 break;
473 case 2: 473 case 2:
474 value = 0x04; 474 value = 0x04;
475 break; 475 break;
476 } 476 }
477 pcfg->setGroup("SyncMode"); 477 pcfg->setGroup("SyncMode");
478 pcfg->writeEntry( "Mode", value ); 478 pcfg->writeEntry( "Mode", value );
479 479
480 /* 480 /*
481 pcfg->setGroup("Remote"); 481 pcfg->setGroup("Remote");
482 if ( telnetAvailable() ) 482 if ( telnetAvailable() )
483 pcfg->writeEntry("allow_telnet",telnet->isChecked()); 483 pcfg->writeEntry("allow_telnet",telnet->isChecked());
484 if ( sshAvailable() ) 484 if ( sshAvailable() )
485 pcfg->writeEntry("allow_ssh",ssh->isChecked()); 485 pcfg->writeEntry("allow_ssh",ssh->isChecked());
486 // ### write ssh/telnet sys config files 486 // ### write ssh/telnet sys config files
487 */ 487 */
488 488
489 //release the Config handler 489 //release the Config handler
490 delete pcfg; 490 delete pcfg;
491 491
492 QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf"; 492 QString configFile = QPEApplication::qpeDir() + "etc/opie-login.conf";
493 Config loginCfg(configFile,Config::File); 493 Config loginCfg(configFile,Config::File);
494 loginCfg.setGroup("General"); 494 loginCfg.setGroup("General");
495 495
496 if (autoLogin) { 496 if (autoLogin) {
497 loginCfg.writeEntry("AutoLogin",autoLoginName); 497 loginCfg.writeEntry("AutoLogin",autoLoginName);
498 } else { 498 } else {
499 loginCfg.removeEntry("AutoLogin"); 499 loginCfg.removeEntry("AutoLogin");
500 } 500 }
501 501
502} 502}
503 503
504/// slot used to record the fact plugins order has been modified 504/// slot used to record the fact plugins order has been modified
505void MultiauthConfig::pluginsChanged() { 505void MultiauthConfig::pluginsChanged() {
506 m_plugins_changed = true; 506 m_plugins_changed = true;
507} 507}
508 508
509/// loads each multiauth plugin 509/// loads each multiauth plugin
510void MultiauthConfig::loadPlugins() { 510void MultiauthConfig::loadPlugins() {
511 511
512 QString path = QPEApplication::qpeDir() + "/plugins/security"; 512 QString path = QPEApplication::qpeDir() + "plugins/security";
513 QDir dir( path, "lib*.so" ); 513 QDir dir( path, "lib*.so" );
514 514
515 QStringList list = dir.entryList(); 515 QStringList list = dir.entryList();
516 QStringList::Iterator it; 516 QStringList::Iterator it;
517 517
518 // temporary list used to sort plugins 518 // temporary list used to sort plugins
519 QMap<QString, MultiauthPlugin> sortList; 519 QMap<QString, MultiauthPlugin> sortList;
520 520
521 for ( it = list.begin(); it != list.end(); ++it ) { 521 for ( it = list.begin(); it != list.end(); ++it ) {
522 QInterfacePtr<MultiauthPluginInterface> iface; 522 QInterfacePtr<MultiauthPluginInterface> iface;
523 QLibrary *lib = new QLibrary( path + "/" + *it ); 523 QLibrary *lib = new QLibrary( path + "/" + *it );
524 QString libPath(path + "/" + *it); 524 QString libPath(path + "/" + *it);
525 525
526 if ( lib->queryInterface( IID_MultiauthPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) { 526 if ( lib->queryInterface( IID_MultiauthPluginInterface, (QUnknownInterface**)&iface ) == QS_OK ) {
527 MultiauthPlugin plugin; 527 MultiauthPlugin plugin;
528 plugin.library = lib; 528 plugin.library = lib;
529 plugin.iface = iface; 529 plugin.iface = iface;
530 plugin.name = QString(*it); 530 plugin.name = QString(*it);
531 531
532 // find out if plugins should be launched 532 // find out if plugins should be launched
533 if ( m_excludePlugins.grep( *it ).isEmpty() ) { 533 if ( m_excludePlugins.grep( *it ).isEmpty() ) {
534 plugin.active = true; 534 plugin.active = true;
535 } else { 535 } else {
536 plugin.active = false; 536 plugin.active = false;
537 } 537 }
538 538
539 plugin.pluginObject = plugin.iface->plugin(); 539 plugin.pluginObject = plugin.iface->plugin();
540 540
541 // "prebuffer" it in one more list, to get the sorting done 541 // "prebuffer" it in one more list, to get the sorting done
542 sortList.insert( plugin.name, plugin ); 542 sortList.insert( plugin.name, plugin );
543 543
544 // on first start the list is off course empty 544 // on first start the list is off course empty
545 if ( m_allPlugins.isEmpty() ) { 545 if ( m_allPlugins.isEmpty() ) {
546 pluginList.append( plugin ); 546 pluginList.append( plugin );
547 } 547 }
548 // if plugin is not yet in the list, add it to the layout too 548 // if plugin is not yet in the list, add it to the layout too
549 else if ( !m_allPlugins.contains( plugin.name ) ) { 549 else if ( !m_allPlugins.contains( plugin.name ) ) {
550 pluginList.append( plugin ); 550 pluginList.append( plugin );
551 } 551 }
552 552
553 } else { 553 } else {
554 delete lib; 554 delete lib;
555 } 555 }
556 556
557 } // end for 557 } // end for
558 558
559 // put m_allPlugins tempPlugin objects into pluginList 559 // put m_allPlugins tempPlugin objects into pluginList
560 if ( !m_allPlugins.isEmpty() ) { 560 if ( !m_allPlugins.isEmpty() ) {
561 MultiauthPlugin tempPlugin; 561 MultiauthPlugin tempPlugin;
562 QStringList::Iterator stringit; 562 QStringList::Iterator stringit;
563 for( stringit = m_allPlugins.begin(); stringit != m_allPlugins.end(); ++stringit ) { 563 for( stringit = m_allPlugins.begin(); stringit != m_allPlugins.end(); ++stringit ) {
564 tempPlugin = ( sortList.find( *stringit ) ).data(); 564 tempPlugin = ( sortList.find( *stringit ) ).data();
565 if ( !( (tempPlugin.name).isEmpty() ) ) { 565 if ( !( (tempPlugin.name).isEmpty() ) ) {
566 pluginList.append( tempPlugin ); 566 pluginList.append( tempPlugin );
567 } 567 }
568 } 568 }
569 } 569 }
570 570
571} 571}
572 572
573void MultiauthConfig::deleteListEntry() 573void MultiauthConfig::deleteListEntry()
574{ 574{
575 m_syncWidget->syncnet->removeItem(m_syncWidget->syncnet->currentItem()); 575 m_syncWidget->syncnet->removeItem(m_syncWidget->syncnet->currentItem());
576} 576}
577 577
578void MultiauthConfig::restoreDefaults() 578void MultiauthConfig::restoreDefaults()
579{ 579{
580 QMessageBox unrecbox( 580 QMessageBox unrecbox(
581 tr("Attention"), 581 tr("Attention"),
582 "<p>" + tr("All user-defined net ranges will be lost.") + "</p>", 582 "<p>" + tr("All user-defined net ranges will be lost.") + "</p>",
583 QMessageBox::Warning, 583 QMessageBox::Warning,
584 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 584 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
585 0, QString::null, TRUE, WStyle_StaysOnTop); 585 0, QString::null, TRUE, WStyle_StaysOnTop);
586 unrecbox.setButtonText(QMessageBox::Cancel, tr("Cancel")); 586 unrecbox.setButtonText(QMessageBox::Cancel, tr("Cancel"));
587 unrecbox.setButtonText(QMessageBox::Yes, tr("OK")); 587 unrecbox.setButtonText(QMessageBox::Yes, tr("OK"));
588 588
589 if ( unrecbox.exec() == QMessageBox::Yes) 589 if ( unrecbox.exec() == QMessageBox::Yes)
590 { 590 {
591 m_syncWidget->syncnet->clear(); 591 m_syncWidget->syncnet->clear();
592 insertDefaultRanges(); 592 insertDefaultRanges();
593 } 593 }
594 m_syncWidget->syncModeCombo->setCurrentItem( 2 ); 594 m_syncWidget->syncModeCombo->setCurrentItem( 2 );
595} 595}
596 596
597void MultiauthConfig::insertDefaultRanges() 597void MultiauthConfig::insertDefaultRanges()
598{ 598{
599 m_syncWidget->syncnet->insertItem( "192.168.129.0/24" ); 599 m_syncWidget->syncnet->insertItem( "192.168.129.0/24" );
600 m_syncWidget->syncnet->insertItem( "192.168.1.0/24" ); 600 m_syncWidget->syncnet->insertItem( "192.168.1.0/24" );
601 m_syncWidget->syncnet->insertItem( "192.168.0.0/16" ); 601 m_syncWidget->syncnet->insertItem( "192.168.0.0/16" );
602 m_syncWidget->syncnet->insertItem( "172.16.0.0/12" ); 602 m_syncWidget->syncnet->insertItem( "172.16.0.0/12" );
603 m_syncWidget->syncnet->insertItem( "10.0.0.0/8" ); 603 m_syncWidget->syncnet->insertItem( "10.0.0.0/8" );
604 m_syncWidget->syncnet->insertItem( "1.0.0.0/8" ); 604 m_syncWidget->syncnet->insertItem( "1.0.0.0/8" );
605 m_syncWidget->syncnet->insertItem( tr( "Any" ) ); 605 m_syncWidget->syncnet->insertItem( tr( "Any" ) );
606 m_syncWidget->syncnet->insertItem( tr( "None" ) ); 606 m_syncWidget->syncnet->insertItem( tr( "None" ) );
607} 607}
608 608
609void MultiauthConfig::updateGUI() 609void MultiauthConfig::updateGUI()
610{ 610{
611 m_loginWidget->autologinToggle->setChecked(autoLogin); 611 m_loginWidget->autologinToggle->setChecked(autoLogin);
612 m_loginWidget->userlist->setEnabled(autoLogin); 612 m_loginWidget->userlist->setEnabled(autoLogin);
613} 613}
614 614
615void MultiauthConfig::selectNet(int auth_peer,int auth_peer_bits, bool update) 615void MultiauthConfig::selectNet(int auth_peer,int auth_peer_bits, bool update)
616{ 616{
617 QString sn; 617 QString sn;
618 if ( auth_peer_bits == 0 && auth_peer == 0 ) { 618 if ( auth_peer_bits == 0 && auth_peer == 0 ) {
619 sn = tr("Any"); 619 sn = tr("Any");
620 } else if ( auth_peer_bits == 32 && auth_peer == 0 ) { 620 } else if ( auth_peer_bits == 32 && auth_peer == 0 ) {
621 sn = tr("None"); 621 sn = tr("None");
622 } else { 622 } else {
623 sn = 623 sn =
624 QString::number((auth_peer>>24)&0xff) + "." 624 QString::number((auth_peer>>24)&0xff) + "."
625 + QString::number((auth_peer>>16)&0xff) + "." 625 + QString::number((auth_peer>>16)&0xff) + "."
626 + QString::number((auth_peer>>8)&0xff) + "." 626 + QString::number((auth_peer>>8)&0xff) + "."
627 + QString::number((auth_peer>>0)&0xff) + "/" 627 + QString::number((auth_peer>>0)&0xff) + "/"
628 + QString::number(auth_peer_bits); 628 + QString::number(auth_peer_bits);
629 } 629 }
630 630
631 //insert user-defined list of netranges upon start 631 //insert user-defined list of netranges upon start
632 if (update) { 632 if (update) {
633 //User selected/active netrange first 633 //User selected/active netrange first
634 m_syncWidget->syncnet->insertItem( tr(sn) ); 634 m_syncWidget->syncnet->insertItem( tr(sn) );
635 Config cfg("Security"); 635 Config cfg("Security");
636 cfg.setGroup("Sync"); 636 cfg.setGroup("Sync");
637 637
638 //set up defaults if needed, if someone manually deletes net0 he'll get a suprise hehe 638 //set up defaults if needed, if someone manually deletes net0 he'll get a suprise hehe
639 QString test = cfg.readEntry("net0",""); 639 QString test = cfg.readEntry("net0","");
640 if (test.isEmpty()) { 640 if (test.isEmpty()) {
641 insertDefaultRanges(); 641 insertDefaultRanges();
642 } else { 642 } else {
643 // 10 ought to be enough for everybody... :) 643 // 10 ought to be enough for everybody... :)
644 // If you need more, don't forget to edit applySecurity() as well 644 // If you need more, don't forget to edit applySecurity() as well
645 bool already_there=FALSE; 645 bool already_there=FALSE;
646 for (int i=0; i<10; i++) { 646 for (int i=0; i<10; i++) {
647 QString target, netrange; 647 QString target, netrange;
648 target.sprintf("net%d", i); 648 target.sprintf("net%d", i);
649 netrange = cfg.readEntry(target,""); 649 netrange = cfg.readEntry(target,"");
650 if (! netrange.isEmpty()){ 650 if (! netrange.isEmpty()){
651 //make sure we have no "twin" entries 651 //make sure we have no "twin" entries
652 for (int i=0; i<m_syncWidget->syncnet->count(); i++) { 652 for (int i=0; i<m_syncWidget->syncnet->count(); i++) {
653 if ( m_syncWidget->syncnet->text(i) == netrange ) { 653 if ( m_syncWidget->syncnet->text(i) == netrange ) {
654 already_there=TRUE; 654 already_there=TRUE;
655 } 655 }
656 } 656 }
657 if (! already_there) { 657 if (! already_there) {
658 m_syncWidget->syncnet->insertItem( netrange ); 658 m_syncWidget->syncnet->insertItem( netrange );
659 } else { 659 } else {
660 already_there=FALSE; 660 already_there=FALSE;
661 } 661 }
662 } 662 }
663 } 663 }
664 } 664 }
665 } 665 }
666 666
667 for (int i=0; i<m_syncWidget->syncnet->count(); i++) { 667 for (int i=0; i<m_syncWidget->syncnet->count(); i++) {
668 if ( m_syncWidget->syncnet->text(i).left(sn.length()) == sn ) { 668 if ( m_syncWidget->syncnet->text(i).left(sn.length()) == sn ) {
669 m_syncWidget->syncnet->setCurrentItem(i); 669 m_syncWidget->syncnet->setCurrentItem(i);
670 return; 670 return;
671 } 671 }
672 } 672 }
673 odebug << "No match for \"" << sn << "\"" << oendl; 673 odebug << "No match for \"" << sn << "\"" << oendl;
674} 674}
675 675
676void MultiauthConfig::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits) 676void MultiauthConfig::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits)
677{ 677{
678 auth_peer=0; 678 auth_peer=0;
679 if ( sn == tr("Any") ) { 679 if ( sn == tr("Any") ) {
680 auth_peer = 0; 680 auth_peer = 0;
681 auth_peer_bits = 0; 681 auth_peer_bits = 0;
682 } else if ( sn == tr("None") ) { 682 } else if ( sn == tr("None") ) {
683 auth_peer = 0; 683 auth_peer = 0;
684 auth_peer_bits = 32; 684 auth_peer_bits = 32;
685 } else { 685 } else {
686 int x=0; 686 int x=0;
687 for (int i=0; i<4; i++) { 687 for (int i=0; i<4; i++) {
688 int nx = sn.find(QChar(i==3 ? '/' : '.'),x); 688 int nx = sn.find(QChar(i==3 ? '/' : '.'),x);
689 auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt(); 689 auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt();
690 x = nx+1; 690 x = nx+1;
691 } 691 }
692 uint n = (uint)sn.find(' ',x)-x; 692 uint n = (uint)sn.find(' ',x)-x;
693 auth_peer_bits = sn.mid(x,n).toInt(); 693 auth_peer_bits = sn.mid(x,n).toInt();
694 } 694 }
695} 695}
696 696
697void MultiauthConfig::loadUsers() 697void MultiauthConfig::loadUsers()
698{ 698{
699 QFile passwd("/etc/passwd"); 699 QFile passwd("/etc/passwd");
700 if ( passwd.open(IO_ReadOnly) ) { 700 if ( passwd.open(IO_ReadOnly) ) {
701 QTextStream t( &passwd ); 701 QTextStream t( &passwd );
702 QString s; 702 QString s;
703 QStringList account; 703 QStringList account;
704 while ( !t.eof() ) { 704 while ( !t.eof() ) {
705 account = QStringList::split(':',t.readLine()); 705 account = QStringList::split(':',t.readLine());
706 // Hide disabled accounts and some special accounts 706 // Hide disabled accounts and some special accounts
707 if (*account.at(1)!="*" && *account.at(0)!="ppp" && *account.at(0)!="messagebus") { 707 if (*account.at(1)!="*" && *account.at(0)!="ppp" && *account.at(0)!="messagebus") {
708 708
709 m_loginWidget->userlist->insertItem(*account.at(0)); 709 m_loginWidget->userlist->insertItem(*account.at(0));
710 // Highlight this item if it is set to m_loginWidget->autologinToggle 710 // Highlight this item if it is set to m_loginWidget->autologinToggle
711 if ( *account.at(0) == autoLoginName) 711 if ( *account.at(0) == autoLoginName)
712 m_loginWidget->userlist->setCurrentItem(m_loginWidget->userlist->count()-1); 712 m_loginWidget->userlist->setCurrentItem(m_loginWidget->userlist->count()-1);
713 } 713 }
714 } 714 }
715 passwd.close(); 715 passwd.close();
716 } 716 }
717 717
718} 718}
719 719
720void MultiauthConfig::toggleAutoLogin(bool val) 720void MultiauthConfig::toggleAutoLogin(bool val)
721{ 721{
722 autoLogin=val; 722 autoLogin=val;
723 m_loginWidget->userlist->setEnabled(val); 723 m_loginWidget->userlist->setEnabled(val);
724 // if autoLogin is true, we will set by default the login currently visible in the userlist 724 // if autoLogin is true, we will set by default the login currently visible in the userlist
725 if (autoLogin) 725 if (autoLogin)
726 autoLoginName=m_loginWidget->userlist->currentText(); 726 autoLoginName=m_loginWidget->userlist->currentText();
727} 727}
728 728
729 729
730 730
731 731
732void MultiauthConfig::setSyncNet(const QString& sn) 732void MultiauthConfig::setSyncNet(const QString& sn)
733{ 733{
734 int auth_peer,auth_peer_bits; 734 int auth_peer,auth_peer_bits;
735 parseNet(sn,auth_peer,auth_peer_bits); 735 parseNet(sn,auth_peer,auth_peer_bits);
736 selectNet(auth_peer,auth_peer_bits,FALSE); 736 selectNet(auth_peer,auth_peer_bits,FALSE);
737} 737}
738 738
739void MultiauthConfig::changeLoginName( int idx ) 739void MultiauthConfig::changeLoginName( int idx )
740{ 740{
741 autoLoginName = m_loginWidget->userlist->text(idx);; 741 autoLoginName = m_loginWidget->userlist->text(idx);;
742 updateGUI(); 742 updateGUI();
743} 743}
744 744
745/// \todo do implement that? who? how? 745/// \todo do implement that? who? how?
746bool MultiauthConfig::telnetAvailable() const 746bool MultiauthConfig::telnetAvailable() const
747{ 747{
748 return FALSE; 748 return FALSE;
749} 749}
750 750
751/// \todo do implement that? who? how? 751/// \todo do implement that? who? how?
752bool MultiauthConfig::sshAvailable() const 752bool MultiauthConfig::sshAvailable() const
753{ 753{
754 return FALSE; 754 return FALSE;
755} 755}
756 756
diff --git a/core/tools/quicklauncher/dropins.h b/core/tools/quicklauncher/dropins.h
index a9664f8..df364ce 100644
--- a/core/tools/quicklauncher/dropins.h
+++ b/core/tools/quicklauncher/dropins.h
@@ -1,71 +1,71 @@
1/* OPIE */ 1/* OPIE */
2#include <opie2/owait.h> 2#include <opie2/owait.h>
3using namespace Opie::Ui; 3using namespace Opie::Ui;
4 4
5#include <qtopia/qcom.h> 5#include <qtopia/qcom.h>
6#include <qtopia/qlibrary.h> 6#include <qtopia/qlibrary.h>
7#include <qtopia/qpeapplication.h> 7#include <qtopia/qpeapplication.h>
8#include <qtopia/applicationinterface.h> 8#include <qtopia/applicationinterface.h>
9#include <qtopia/resource.h> 9#include <qtopia/resource.h>
10 10
11/* QT */ 11/* QT */
12#include <qmetaobject.h> 12#include <qmetaobject.h>
13#include <qmap.h> 13#include <qmap.h>
14#include <qstring.h> 14#include <qstring.h>
15 15
16namespace QuickPrivate { 16namespace QuickPrivate {
17 17
18 struct PluginLoader { 18 struct PluginLoader {
19 PluginLoader( const char* ) { 19 PluginLoader( const char* ) {
20 } 20 }
21 21
22 QRESULT queryInterface( const QString& app, const QUuid&, QUnknownInterface** ); 22 QRESULT queryInterface( const QString& app, const QUuid&, QUnknownInterface** );
23 void releaseInterface( QUnknownInterface* ); 23 void releaseInterface( QUnknownInterface* );
24 QMap<QUnknownInterface*, QLibrary*> libs; 24 QMap<QUnknownInterface*, QLibrary*> libs;
25 }; 25 };
26 26
27 /* 27 /*
28 * We can skip installing a Translator here because Opies QPEApplication 28 * We can skip installing a Translator here because Opies QPEApplication
29 * will do that in initApp for us as well 29 * will do that in initApp for us as well
30 */ 30 */
31 QRESULT PluginLoader::queryInterface( const QString& libFile, const QUuid& uuid, QUnknownInterface** iface ) { 31 QRESULT PluginLoader::queryInterface( const QString& libFile, const QUuid& uuid, QUnknownInterface** iface ) {
32 QRESULT res = QS_FALSE; 32 QRESULT res = QS_FALSE;
33 *iface = 0; 33 *iface = 0;
34 34
35 // This code is very platform specific.. We should find better 35 // This code is very platform specific.. We should find better
36 // solutions to handle names.. Maybe one central function would be 36 // solutions to handle names.. Maybe one central function would be
37 // better than checking this ".so" stuff all around in the sources.. 37 // better than checking this ".so" stuff all around in the sources..
38 // (eilers) 38 // (eilers)
39 39
40 // Below lines from TT then mine again 40 // Below lines from TT then mine again
41 QString name = libFile; 41 QString name = libFile;
42 if ( libFile.findRev(".so") == (int)libFile.length()-3 ) { 42 if ( libFile.findRev(".so") == (int)libFile.length()-3 ) {
43 name = libFile.left( libFile.length()-3 ); 43 name = libFile.left( libFile.length()-3 );
44 if ( name.find( "lib" ) == 0 ) 44 if ( name.find( "lib" ) == 0 )
45 name = name.mid( 3 ); 45 name = name.mid( 3 );
46 } 46 }
47#ifdef Q_OS_MACX 47#ifdef Q_OS_MACX
48 QString path = QPEApplication::qpeDir() + "/plugins/application/lib"+name+".dylib"; 48 QString path = QPEApplication::qpeDir() + "plugins/application/lib"+name+".dylib";
49#else 49#else
50 QString path = QPEApplication::qpeDir() + "/plugins/application/lib"+name+".so"; 50 QString path = QPEApplication::qpeDir() + "plugins/application/lib"+name+".so";
51#endif 51#endif
52 52
53 QLibrary *lib = new QLibrary( path ); 53 QLibrary *lib = new QLibrary( path );
54 if ( lib->queryInterface( uuid, iface ) == QS_OK && iface ) { 54 if ( lib->queryInterface( uuid, iface ) == QS_OK && iface ) {
55 libs.insert( *iface, lib ); 55 libs.insert( *iface, lib );
56 res = QS_OK; 56 res = QS_OK;
57 } 57 }
58 58
59 return res; 59 return res;
60 } 60 }
61 61
62 void PluginLoader::releaseInterface( QUnknownInterface* iface ) { 62 void PluginLoader::releaseInterface( QUnknownInterface* iface ) {
63 if ( libs.contains( iface ) ) { 63 if ( libs.contains( iface ) ) {
64 iface->release(); 64 iface->release();
65 delete libs[iface]; 65 delete libs[iface];
66 libs.remove( iface ); // we only handle pointers so even if the object is not valid the address-space is 66 libs.remove( iface ); // we only handle pointers so even if the object is not valid the address-space is
67 } 67 }
68 } 68 }
69 69
70} 70}
71 71
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp
index 1fba9bc..fe5051d 100644
--- a/inputmethods/multikey/configdlg.cpp
+++ b/inputmethods/multikey/configdlg.cpp
@@ -1,508 +1,508 @@
1/* 1/*
2 * TODO 2 * TODO
3 * make a font selection thing (size too) 3 * make a font selection thing (size too)
4 * make a keymap editor 4 * make a keymap editor
5 * make keys translucent 5 * make keys translucent
6 * make vertical keys possible 6 * make vertical keys possible
7 * 7 *
8 * 8 *
9 */ 9 */
10 10
11#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
12#include <qpe/config.h> 12#include <qpe/config.h>
13#include <qpe/resource.h> 13#include <qpe/resource.h>
14 14
15#include <qlayout.h> 15#include <qlayout.h>
16#include <qwidget.h> 16#include <qwidget.h>
17#include <qdialog.h> 17#include <qdialog.h>
18#include <qtabwidget.h> 18#include <qtabwidget.h>
19#include <qvbox.h> 19#include <qvbox.h>
20#include <qgrid.h> 20#include <qgrid.h>
21#include <qgroupbox.h> 21#include <qgroupbox.h>
22#include <qlabel.h> 22#include <qlabel.h>
23#include <qcheckbox.h> 23#include <qcheckbox.h>
24#include <qsizepolicy.h> 24#include <qsizepolicy.h>
25#include <qpushbutton.h> 25#include <qpushbutton.h>
26#include <qlistbox.h> 26#include <qlistbox.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qtoolbutton.h> 28#include <qtoolbutton.h>
29#include <opie2/ofiledialog.h> 29#include <opie2/ofiledialog.h>
30#include <opie2/qcolordialog.h> 30#include <opie2/qcolordialog.h>
31#include <qdir.h> 31#include <qdir.h>
32#include <qfileinfo.h> 32#include <qfileinfo.h>
33#include "configdlg.h" 33#include "configdlg.h"
34#include "keyboard.h" 34#include "keyboard.h"
35 35
36using namespace Opie; 36using namespace Opie;
37using namespace Opie::Ui; 37using namespace Opie::Ui;
38// ConfigDlg::ConfigDlg() {{{1 38// ConfigDlg::ConfigDlg() {{{1
39ConfigDlg::ConfigDlg () : QDialog () 39ConfigDlg::ConfigDlg () : QDialog ()
40{ 40{
41 setCaption( tr("Multikey Configuration") ); 41 setCaption( tr("Multikey Configuration") );
42 Config config ("multikey"); 42 Config config ("multikey");
43 config.setGroup("keymaps"); 43 config.setGroup("keymaps");
44 QString current_map = config.readEntry("current", 0); 44 QString current_map = config.readEntry("current", 0);
45 45
46 /* 46 /*
47 * 'general config' tab 47 * 'general config' tab
48 */ 48 */
49 49
50 QVBoxLayout *base_lay = new QVBoxLayout(this); 50 QVBoxLayout *base_lay = new QVBoxLayout(this);
51 51
52 QTabWidget *tabs = new QTabWidget(this, "tabs"); 52 QTabWidget *tabs = new QTabWidget(this, "tabs");
53 53
54 QWidget *gen_box = new QWidget(tabs, "gen_tab"); 54 QWidget *gen_box = new QWidget(tabs, "gen_tab");
55 QVBoxLayout *gen_lay = new QVBoxLayout(gen_box); 55 QVBoxLayout *gen_lay = new QVBoxLayout(gen_box);
56 gen_lay->setMargin(3); 56 gen_lay->setMargin(3);
57 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); 57 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box);
58 58
59 QHBox *hbox1 = new QHBox(map_group); 59 QHBox *hbox1 = new QHBox(map_group);
60 keymaps = new QListBox(hbox1); 60 keymaps = new QListBox(hbox1);
61 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 61 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
62 QVBox *vbox1 = new QVBox(hbox1); 62 QVBox *vbox1 = new QVBox(hbox1);
63 63
64 QToolButton *tb1 = new QToolButton(vbox1, tr("Move Up")); 64 QToolButton *tb1 = new QToolButton(vbox1, tr("Move Up"));
65 tb1->setPixmap(Resource::loadPixmap("up")); 65 tb1->setPixmap(Resource::loadPixmap("up"));
66 tb1->setAutoRaise(TRUE); 66 tb1->setAutoRaise(TRUE);
67 tb1->setFocusPolicy(QWidget::NoFocus); 67 tb1->setFocusPolicy(QWidget::NoFocus);
68 tb1->setToggleButton(FALSE); 68 tb1->setToggleButton(FALSE);
69 connect(tb1, SIGNAL(clicked()), this, SLOT(moveSelectedUp())); 69 connect(tb1, SIGNAL(clicked()), this, SLOT(moveSelectedUp()));
70 70
71 QToolButton *tb2 = new QToolButton(vbox1, tr("Move Down")); 71 QToolButton *tb2 = new QToolButton(vbox1, tr("Move Down"));
72 tb2->setPixmap(Resource::loadPixmap("down")); 72 tb2->setPixmap(Resource::loadPixmap("down"));
73 tb2->setAutoRaise(TRUE); 73 tb2->setAutoRaise(TRUE);
74 tb2->setFocusPolicy(QWidget::NoFocus); 74 tb2->setFocusPolicy(QWidget::NoFocus);
75 tb2->setToggleButton(FALSE); 75 tb2->setToggleButton(FALSE);
76 connect(tb2, SIGNAL(clicked()), this, SLOT(moveSelectedDown())); 76 connect(tb2, SIGNAL(clicked()), this, SLOT(moveSelectedDown()));
77 77
78 QString cur(tr("Current Language")); 78 QString cur(tr("Current Language"));
79 keymaps->insertItem(cur); 79 keymaps->insertItem(cur);
80 keymaps->setSelected(0, true); 80 keymaps->setSelected(0, true);
81 81
82 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); 82 QDir map_dir(QPEApplication::qpeDir() + "share/multikey", "*.keymap");
83 default_maps = map_dir.entryList(); // so i can access it in other places 83 default_maps = map_dir.entryList(); // so i can access it in other places
84 custom_maps = config.readListEntry("maps", QChar('|')); 84 custom_maps = config.readListEntry("maps", QChar('|'));
85 sw_maps = ConfigDlg::loadSw(); 85 sw_maps = ConfigDlg::loadSw();
86 86
87 QStringList sw_copy(sw_maps); 87 QStringList sw_copy(sw_maps);
88 for (uint i = 0; i < sw_copy.count(); i++) { 88 for (uint i = 0; i < sw_copy.count(); i++) {
89 89
90 QString keymap_map; 90 QString keymap_map;
91 if (sw_copy[i][0] != '/') { /* share/multikey */ 91 if (sw_copy[i][0] != '/') { /* share/multikey */
92 92
93 keymap_map = map_dir.absPath() + "/" + sw_copy[i]; 93 keymap_map = map_dir.absPath() + "/" + sw_copy[i];
94 } else { 94 } else {
95 95
96 if (map_dir.exists(QFileInfo(sw_copy[i]).fileName(), false) 96 if (map_dir.exists(QFileInfo(sw_copy[i]).fileName(), false)
97 || !QFile::exists(sw_copy[i])) { 97 || !QFile::exists(sw_copy[i])) {
98 98
99 custom_maps.remove(sw_copy[i]); 99 custom_maps.remove(sw_copy[i]);
100 sw_maps.remove(sw_copy[i]); 100 sw_maps.remove(sw_copy[i]);
101 101
102 // remove it from the list too 102 // remove it from the list too
103 config.writeEntry("maps", custom_maps.join("|")); 103 config.writeEntry("maps", custom_maps.join("|"));
104 104
105 continue; 105 continue;
106 } 106 }
107 keymap_map = sw_copy[i]; 107 keymap_map = sw_copy[i];
108 } 108 }
109 109
110 QFile map(keymap_map); 110 QFile map(keymap_map);
111 if (map.open(IO_ReadOnly)) { 111 if (map.open(IO_ReadOnly)) {
112 112
113 QString line; bool found = 0; 113 QString line; bool found = 0;
114 114
115 map.readLine(line, 1024); 115 map.readLine(line, 1024);
116 while (!map.atEnd()) { 116 while (!map.atEnd()) {
117 117
118 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) { 118 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) {
119 119
120 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); 120 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
121 found = 1; 121 found = 1;
122 break; 122 break;
123 } 123 }
124 map.readLine(line, 1024); 124 map.readLine(line, 1024);
125 } 125 }
126 if (!found) 126 if (!found)
127 keymaps->insertItem(keymap_map); 127 keymaps->insertItem(keymap_map);
128 128
129 map.close(); 129 map.close();
130 } 130 }
131 131
132 if (keymap_map == current_map) { 132 if (keymap_map == current_map) {
133 keymaps->setSelected(i + 1, true); 133 keymaps->setSelected(i + 1, true);
134 } 134 }
135 } 135 }
136 136
137 // have to "+1" because the "current language" listItem... remember? 137 // have to "+1" because the "current language" listItem... remember?
138 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); 138 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int)));
139 139
140 QGrid *add_remove_grid = new QGrid(2, map_group); 140 QGrid *add_remove_grid = new QGrid(2, map_group);
141 add_remove_grid->setMargin(3); 141 add_remove_grid->setMargin(3);
142 add_remove_grid->setSpacing(3); 142 add_remove_grid->setSpacing(3);
143 143
144 add_button = new QPushButton(tr("Add"), add_remove_grid); 144 add_button = new QPushButton(tr("Add"), add_remove_grid);
145 add_button->setFlat(TRUE); 145 add_button->setFlat(TRUE);
146 connect(add_button, SIGNAL(clicked()), SLOT(addMap())); 146 connect(add_button, SIGNAL(clicked()), SLOT(addMap()));
147 147
148 remove_button = new QPushButton(tr("Remove"), add_remove_grid); 148 remove_button = new QPushButton(tr("Remove"), add_remove_grid);
149 remove_button->setFlat(TRUE); 149 remove_button->setFlat(TRUE);
150 if (keymaps->currentItem() == 0 || default_maps.find(QFileInfo(current_map).fileName()) != default_maps.end()) 150 if (keymaps->currentItem() == 0 || default_maps.find(QFileInfo(current_map).fileName()) != default_maps.end())
151 remove_button->setDisabled(true); 151 remove_button->setDisabled(true);
152 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); 152 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap()));
153 153
154 gen_lay->addWidget(map_group); 154 gen_lay->addWidget(map_group);
155 155
156 // make a box that will contain the buttons on the bottom 156 // make a box that will contain the buttons on the bottom
157 QGrid *other_grid = new QGrid(2, gen_box); 157 QGrid *other_grid = new QGrid(2, gen_box);
158 pick_button = new QCheckBox(tr("Pickboard"), other_grid); 158 pick_button = new QCheckBox(tr("Pickboard"), other_grid);
159 159
160 config.setGroup ("general"); 160 config.setGroup ("general");
161 bool pick_open = config.readBoolEntry ("usePickboard", FALSE); // default closed 161 bool pick_open = config.readBoolEntry ("usePickboard", FALSE); // default closed
162 if (pick_open) { 162 if (pick_open) {
163 163
164 pick_button->setChecked(true); 164 pick_button->setChecked(true);
165 } 165 }
166 166
167 repeat_button = new QCheckBox(tr("Key Repeat"), other_grid); 167 repeat_button = new QCheckBox(tr("Key Repeat"), other_grid);
168 bool repeat_on = config.readBoolEntry ("useRepeat", TRUE); 168 bool repeat_on = config.readBoolEntry ("useRepeat", TRUE);
169 169
170 if (repeat_on) { 170 if (repeat_on) {
171 171
172 repeat_button->setChecked(true); 172 repeat_button->setChecked(true);
173 } 173 }
174 174
175 gen_lay->addWidget(other_grid); 175 gen_lay->addWidget(other_grid);
176 tabs->addTab(gen_box, tr("General Settings")); 176 tabs->addTab(gen_box, tr("General Settings"));
177 177
178 /* 178 /*
179 * 'color' tab 179 * 'color' tab
180 */ 180 */
181 181
182 QWidget *color_box = new QWidget(tabs, "color_tab"); 182 QWidget *color_box = new QWidget(tabs, "color_tab");
183 183
184 QGridLayout *color_lay = new QGridLayout(color_box); 184 QGridLayout *color_lay = new QGridLayout(color_box);
185 QGrid *color_grid = new QGrid(2, color_box); 185 QGrid *color_grid = new QGrid(2, color_box);
186 color_lay->setAlignment(Qt::AlignTop); 186 color_lay->setAlignment(Qt::AlignTop);
187 color_grid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); 187 color_grid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
188 color_grid->layout()->setAlignment(Qt::AlignTop); 188 color_grid->layout()->setAlignment(Qt::AlignTop);
189 color_grid->setMargin(3); 189 color_grid->setMargin(3);
190 color_grid->setSpacing(3); 190 color_grid->setSpacing(3);
191 191
192 QLabel *label; 192 QLabel *label;
193 QStringList color; 193 QStringList color;
194 config.setGroup("colors"); 194 config.setGroup("colors");
195 195
196 label = new QLabel(tr("Key Color"), color_grid); 196 label = new QLabel(tr("Key Color"), color_grid);
197 keycolor_button = new QPushButton(color_grid); 197 keycolor_button = new QPushButton(color_grid);
198 connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked())); 198 connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked()));
199 keycolor_button->setFlat(TRUE); 199 keycolor_button->setFlat(TRUE);
200 color = config.readListEntry("keycolor", QChar(',')); 200 color = config.readListEntry("keycolor", QChar(','));
201 /* 201 /*
202 * hopefully not required 202 * hopefully not required
203 203
204 if (color.isEmpty()) { 204 if (color.isEmpty()) {
205 color = QStringList::split(",", "240,240,240"); 205 color = QStringList::split(",", "240,240,240");
206 config.writeEntry("keycolor", color.join(",")); 206 config.writeEntry("keycolor", color.join(","));
207 207
208 } 208 }
209 */ 209 */
210 keycolor_button->setPalette(QPalette(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))); 210 keycolor_button->setPalette(QPalette(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())));
211 211
212 212
213 label = new QLabel(tr("Key Pressed Color"), color_grid); 213 label = new QLabel(tr("Key Pressed Color"), color_grid);
214 keycolor_pressed_button = new QPushButton(color_grid); 214 keycolor_pressed_button = new QPushButton(color_grid);
215 connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked())); 215 connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked()));
216 keycolor_pressed_button->setFlat(TRUE); 216 keycolor_pressed_button->setFlat(TRUE);
217 color = config.readListEntry("keycolor_pressed", QChar(',')); 217 color = config.readListEntry("keycolor_pressed", QChar(','));
218 keycolor_pressed_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); 218 keycolor_pressed_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))));
219 219
220 label = new QLabel(tr("Line Color"), color_grid); 220 label = new QLabel(tr("Line Color"), color_grid);
221 keycolor_lines_button = new QPushButton(color_grid); 221 keycolor_lines_button = new QPushButton(color_grid);
222 connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked())); 222 connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked()));
223 keycolor_lines_button->setFlat(TRUE); 223 keycolor_lines_button->setFlat(TRUE);
224 color = config.readListEntry("keycolor_lines", QChar(',')); 224 color = config.readListEntry("keycolor_lines", QChar(','));
225 keycolor_lines_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); 225 keycolor_lines_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))));
226 226
227 227
228 label = new QLabel(tr("Text Color"), color_grid); 228 label = new QLabel(tr("Text Color"), color_grid);
229 textcolor_button = new QPushButton(color_grid); 229 textcolor_button = new QPushButton(color_grid);
230 connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked())); 230 connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked()));
231 textcolor_button->setFlat(TRUE); 231 textcolor_button->setFlat(TRUE);
232 color = config.readListEntry("textcolor", QChar(',')); 232 color = config.readListEntry("textcolor", QChar(','));
233 textcolor_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); 233 textcolor_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))));
234 234
235 label = new QLabel("", color_grid); // a spacer so the above buttons dont expand 235 label = new QLabel("", color_grid); // a spacer so the above buttons dont expand
236 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 236 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
237 /* FIXME: hacked spacer height */ 237 /* FIXME: hacked spacer height */
238 QSpacerItem *spacer = new QSpacerItem(0, 300, QSizePolicy::Expanding, QSizePolicy::Maximum); 238 QSpacerItem *spacer = new QSpacerItem(0, 300, QSizePolicy::Expanding, QSizePolicy::Maximum);
239 239
240 color_lay->addWidget(color_grid, 0, 0); 240 color_lay->addWidget(color_grid, 0, 0);
241 color_lay->addItem(spacer); 241 color_lay->addItem(spacer);
242 242
243 tabs->addTab(color_box, tr("Colors")); 243 tabs->addTab(color_box, tr("Colors"));
244 base_lay->addWidget(tabs); 244 base_lay->addWidget(tabs);
245} 245}
246 246
247QStringList ConfigDlg::loadSw() 247QStringList ConfigDlg::loadSw()
248{ 248{
249 Config *config = new Config("multikey"); 249 Config *config = new Config("multikey");
250 config->setGroup("keymaps"); 250 config->setGroup("keymaps");
251 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); 251 QDir map_dir(QPEApplication::qpeDir() + "share/multikey", "*.keymap");
252 QStringList d_maps = map_dir.entryList(); // so i can access it in other places 252 QStringList d_maps = map_dir.entryList(); // so i can access it in other places
253 QStringList c_maps = config->readListEntry("maps", QChar('|')); 253 QStringList c_maps = config->readListEntry("maps", QChar('|'));
254 QStringList s_maps = config->readListEntry("sw", QChar('|')); 254 QStringList s_maps = config->readListEntry("sw", QChar('|'));
255 delete config; 255 delete config;
256 256
257 if (!s_maps.count()) 257 if (!s_maps.count())
258 { 258 {
259 s_maps = d_maps+c_maps; 259 s_maps = d_maps+c_maps;
260 } 260 }
261 else 261 else
262 { 262 {
263 /* Clear non existents entries */ 263 /* Clear non existents entries */
264 QStringList s_copy(s_maps); 264 QStringList s_copy(s_maps);
265 for (uint i = 0; i < s_copy.count(); ++i) { 265 for (uint i = 0; i < s_copy.count(); ++i) {
266 if (d_maps.find(s_copy[i]) == d_maps.end() 266 if (d_maps.find(s_copy[i]) == d_maps.end()
267 && c_maps.find(s_copy[i]) == c_maps.end()) { 267 && c_maps.find(s_copy[i]) == c_maps.end()) {
268 s_maps.remove(s_copy[i]); 268 s_maps.remove(s_copy[i]);
269 } 269 }
270 } 270 }
271 /* Update sw_maps from default_maps */ 271 /* Update sw_maps from default_maps */
272 for (uint i = 0; i < d_maps.count(); ++i) { 272 for (uint i = 0; i < d_maps.count(); ++i) {
273 if (s_maps.find(d_maps[i]) == s_maps.end()) { 273 if (s_maps.find(d_maps[i]) == s_maps.end()) {
274 s_maps.append(d_maps[i]); 274 s_maps.append(d_maps[i]);
275 } 275 }
276 } 276 }
277 /* Update sw_maps from custom_maps */ 277 /* Update sw_maps from custom_maps */
278 for (uint i = 0; i < c_maps.count(); ++i) { 278 for (uint i = 0; i < c_maps.count(); ++i) {
279 if (s_maps.find(c_maps[i]) == s_maps.end()) { 279 if (s_maps.find(c_maps[i]) == s_maps.end()) {
280 s_maps.append(c_maps[i]); 280 s_maps.append(c_maps[i]);
281 } 281 }
282 } 282 }
283 } 283 }
284 284
285 return s_maps; 285 return s_maps;
286} 286}
287 287
288void ConfigDlg::accept() 288void ConfigDlg::accept()
289{ 289{
290 /* Writing all stuffs to config */ 290 /* Writing all stuffs to config */
291 Config *config = new Config("multikey"); 291 Config *config = new Config("multikey");
292 config->setGroup("general"); 292 config->setGroup("general");
293 config->writeEntry("usePickboard", pick_button->isChecked()); // default closed 293 config->writeEntry("usePickboard", pick_button->isChecked()); // default closed
294 config->writeEntry("useRepeat", repeat_button->isChecked()); // default closed 294 config->writeEntry("useRepeat", repeat_button->isChecked()); // default closed
295 295
296 config->setGroup("keymaps"); 296 config->setGroup("keymaps");
297 config->writeEntry("sw", sw_maps, QChar('|')); 297 config->writeEntry("sw", sw_maps, QChar('|'));
298 config->writeEntry("maps", custom_maps, QChar('|')); 298 config->writeEntry("maps", custom_maps, QChar('|'));
299 delete config; 299 delete config;
300 300
301 int index = keymaps->currentItem(); 301 int index = keymaps->currentItem();
302 if (index == 0) { 302 if (index == 0) {
303 303
304 remove_button->setDisabled(true); 304 remove_button->setDisabled(true);
305 emit setMapToDefault(); 305 emit setMapToDefault();
306 } 306 }
307 else if (default_maps.find(sw_maps[index-1]) != default_maps.end()) { 307 else if (default_maps.find(sw_maps[index-1]) != default_maps.end()) {
308 308
309 remove_button->setDisabled(true); 309 remove_button->setDisabled(true);
310 emit setMapToFile(QPEApplication::qpeDir() + "share/multikey/" + sw_maps[index - 1]); 310 emit setMapToFile(QPEApplication::qpeDir() + "share/multikey/" + sw_maps[index - 1]);
311 311
312 } else { 312 } else {
313 313
314 remove_button->setEnabled(true); 314 remove_button->setEnabled(true);
315 emit setMapToFile(sw_maps[index - 1]); 315 emit setMapToFile(sw_maps[index - 1]);
316 } 316 }
317 317
318 emit pickboardToggled(pick_button->isChecked()); 318 emit pickboardToggled(pick_button->isChecked());
319 emit repeatToggled(repeat_button->isChecked()); 319 emit repeatToggled(repeat_button->isChecked());
320 emit reloadSw(); 320 emit reloadSw();
321 321
322 QDialog::accept(); 322 QDialog::accept();
323 emit configDlgClosed(); 323 emit configDlgClosed();
324} 324}
325 325
326void ConfigDlg::moveSelectedUp() 326void ConfigDlg::moveSelectedUp()
327{ 327{
328 int i = keymaps->currentItem(); 328 int i = keymaps->currentItem();
329 /* Ignore Current Language */ 329 /* Ignore Current Language */
330 if (i > 1) { 330 if (i > 1) {
331 QString t = sw_maps[i-1]; 331 QString t = sw_maps[i-1];
332 sw_maps[i-1] = sw_maps[i-2]; 332 sw_maps[i-1] = sw_maps[i-2];
333 sw_maps[i-2] = t; 333 sw_maps[i-2] = t;
334 334
335 QString item = keymaps->currentText(); 335 QString item = keymaps->currentText();
336 keymaps->removeItem(i); 336 keymaps->removeItem(i);
337 keymaps->insertItem(item, i-1); 337 keymaps->insertItem(item, i-1);
338 keymaps->setCurrentItem(i-1); 338 keymaps->setCurrentItem(i-1);
339 } 339 }
340} 340}
341 341
342void ConfigDlg::moveSelectedDown() 342void ConfigDlg::moveSelectedDown()
343{ 343{
344 int i = keymaps->currentItem(); 344 int i = keymaps->currentItem();
345 /* Ignore Current Language */ 345 /* Ignore Current Language */
346 if (i > 0 && i < (int)keymaps->count() - 1) { 346 if (i > 0 && i < (int)keymaps->count() - 1) {
347 QString t = sw_maps[i-1]; 347 QString t = sw_maps[i-1];
348 sw_maps[i-1] = sw_maps[i]; 348 sw_maps[i-1] = sw_maps[i];
349 sw_maps[i] = t; 349 sw_maps[i] = t;
350 350
351 QString item = keymaps->currentText(); 351 QString item = keymaps->currentText();
352 keymaps->removeItem(i); 352 keymaps->removeItem(i);
353 keymaps->insertItem(item, i+1); 353 keymaps->insertItem(item, i+1);
354 keymaps->setCurrentItem(i+1); 354 keymaps->setCurrentItem(i+1);
355 } 355 }
356} 356}
357 357
358void ConfigDlg::closeEvent(QCloseEvent *) { 358void ConfigDlg::closeEvent(QCloseEvent *) {
359 359
360 // tell the parent it was closed, so delete me 360 // tell the parent it was closed, so delete me
361 emit configDlgClosed(); 361 emit configDlgClosed();
362} 362}
363 363
364void ConfigDlg::setMap(int index) { 364void ConfigDlg::setMap(int index) {
365 365
366 if (index == 0 || default_maps.find(sw_maps[index-1]) != default_maps.end()) { 366 if (index == 0 || default_maps.find(sw_maps[index-1]) != default_maps.end()) {
367 remove_button->setDisabled(true); 367 remove_button->setDisabled(true);
368 } else { 368 } else {
369 remove_button->setEnabled(true); 369 remove_button->setEnabled(true);
370 } 370 }
371} 371}
372 372
373// ConfigDlg::addMap() {{{1 373// ConfigDlg::addMap() {{{1
374void ConfigDlg::addMap() { 374void ConfigDlg::addMap() {
375 375
376 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); 376 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath());
377 377
378 if (map.isNull()) return; 378 if (map.isNull()) return;
379 379
380 Config config ("multikey"); 380 Config config ("multikey");
381 config.setGroup("keymaps"); 381 config.setGroup("keymaps");
382 QStringList maps = config.readListEntry("maps", QChar('|')); 382 QStringList maps = config.readListEntry("maps", QChar('|'));
383 maps.append(map); 383 maps.append(map);
384 custom_maps.append(map); 384 custom_maps.append(map);
385 if (sw_maps.find(map) == sw_maps.end()) 385 if (sw_maps.find(map) == sw_maps.end())
386 sw_maps.append(map); 386 sw_maps.append(map);
387 387
388 QFile map_file (map); 388 QFile map_file (map);
389 if (map_file.open(IO_ReadOnly)) { 389 if (map_file.open(IO_ReadOnly)) {
390 390
391 QString line; bool found = 0; 391 QString line; bool found = 0;
392 392
393 map_file.readLine(line, 1024); 393 map_file.readLine(line, 1024);
394 while (!map_file.atEnd()) { 394 while (!map_file.atEnd()) {
395 395
396 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) { 396 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) {
397 397
398 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); 398 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
399 found = 1; 399 found = 1;
400 break; 400 break;
401 } 401 }
402 map_file.readLine(line, 1024); 402 map_file.readLine(line, 1024);
403 } 403 }
404 if (!found) keymaps->insertItem(map); 404 if (!found) keymaps->insertItem(map);
405 405
406 map_file.close(); 406 map_file.close();
407 } 407 }
408 408
409 keymaps->setSelected(keymaps->count() - 1, true); 409 keymaps->setSelected(keymaps->count() - 1, true);
410} 410}
411 411
412// ConfigDlg::removeMap() {{{1 412// ConfigDlg::removeMap() {{{1
413void ConfigDlg::removeMap() { 413void ConfigDlg::removeMap() {
414 414
415 // move selection up one 415 // move selection up one
416 keymaps->setSelected(keymaps->currentItem() - 1, true); 416 keymaps->setSelected(keymaps->currentItem() - 1, true);
417 // delete the next selected item cus you just moved it up 417 // delete the next selected item cus you just moved it up
418 keymaps->removeItem(keymaps->currentItem() + 1); 418 keymaps->removeItem(keymaps->currentItem() + 1);
419 419
420 custom_maps.remove(sw_maps[keymaps->currentItem()]); 420 custom_maps.remove(sw_maps[keymaps->currentItem()]);
421 sw_maps.remove(sw_maps.at(keymaps->currentItem())); 421 sw_maps.remove(sw_maps.at(keymaps->currentItem()));
422} 422}
423 423
424/* ConfigDlg::slots for the color buttons {{{1 424/* ConfigDlg::slots for the color buttons {{{1
425 * 425 *
426 * these four slots are almost the same, except for the names. i was thinking 426 * these four slots are almost the same, except for the names. i was thinking
427 * of making a map with pointers to the buttons and names of the configEntry 427 * of making a map with pointers to the buttons and names of the configEntry
428 * so it could be one slot, but then there would be no way of telling which 428 * so it could be one slot, but then there would be no way of telling which
429 * of the buttons was clicked if they all connect to the same slot. 429 * of the buttons was clicked if they all connect to the same slot.
430 * 430 *
431 */ 431 */
432 432
433void ConfigDlg::keyColorClicked() { 433void ConfigDlg::keyColorClicked() {
434 434
435 Config config ("multikey"); 435 Config config ("multikey");
436 config.setGroup ("colors"); 436 config.setGroup ("colors");
437 437
438 QStringList color = config.readListEntry("keycolor", QChar(',')); 438 QStringList color = config.readListEntry("keycolor", QChar(','));
439 439
440 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 440 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
441 441
442 color[0].setNum(newcolor.red()); 442 color[0].setNum(newcolor.red());
443 color[1].setNum(newcolor.green()); 443 color[1].setNum(newcolor.green());
444 color[2].setNum(newcolor.blue()); 444 color[2].setNum(newcolor.blue());
445 445
446 config.writeEntry("keycolor", color, QChar(',')); 446 config.writeEntry("keycolor", color, QChar(','));
447 config.write(); 447 config.write();
448 448
449 keycolor_button->setPalette(QPalette(newcolor)); 449 keycolor_button->setPalette(QPalette(newcolor));
450 emit reloadKeyboard(); 450 emit reloadKeyboard();
451} 451}
452void ConfigDlg::keyColorPressedClicked() { 452void ConfigDlg::keyColorPressedClicked() {
453 453
454 Config config ("multikey"); 454 Config config ("multikey");
455 config.setGroup ("colors"); 455 config.setGroup ("colors");
456 456
457 QStringList color = config.readListEntry("keycolor_pressed", QChar(',')); 457 QStringList color = config.readListEntry("keycolor_pressed", QChar(','));
458 458
459 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 459 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
460 460
461 color[0].setNum(newcolor.red()); 461 color[0].setNum(newcolor.red());
462 color[1].setNum(newcolor.green()); 462 color[1].setNum(newcolor.green());
463 color[2].setNum(newcolor.blue()); 463 color[2].setNum(newcolor.blue());
464 464
465 config.writeEntry("keycolor_pressed", color, QChar(',')); 465 config.writeEntry("keycolor_pressed", color, QChar(','));
466 config.write(); 466 config.write();
467 467
468 keycolor_pressed_button->setPalette(QPalette(newcolor)); 468 keycolor_pressed_button->setPalette(QPalette(newcolor));
469 emit reloadKeyboard(); 469 emit reloadKeyboard();
470} 470}
471void ConfigDlg::keyColorLinesClicked() { 471void ConfigDlg::keyColorLinesClicked() {
472 472
473 Config config ("multikey"); 473 Config config ("multikey");
474 config.setGroup ("colors"); 474 config.setGroup ("colors");
475 475
476 QStringList color = config.readListEntry("keycolor_lines", QChar(',')); 476 QStringList color = config.readListEntry("keycolor_lines", QChar(','));
477 477
478 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 478 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
479 479
480 color[0].setNum(newcolor.red()); 480 color[0].setNum(newcolor.red());
481 color[1].setNum(newcolor.green()); 481 color[1].setNum(newcolor.green());
482 color[2].setNum(newcolor.blue()); 482 color[2].setNum(newcolor.blue());
483 483
484 config.writeEntry("keycolor_lines", color, QChar(',')); 484 config.writeEntry("keycolor_lines", color, QChar(','));
485 config.write(); 485 config.write();
486 486
487 keycolor_lines_button->setPalette(QPalette(newcolor)); 487 keycolor_lines_button->setPalette(QPalette(newcolor));
488 emit reloadKeyboard(); 488 emit reloadKeyboard();
489} 489}
490void ConfigDlg::textColorClicked() { 490void ConfigDlg::textColorClicked() {
491 491
492 Config config ("multikey"); 492 Config config ("multikey");
493 config.setGroup ("colors"); 493 config.setGroup ("colors");
494 494
495 QStringList color = config.readListEntry("textcolor", QChar(',')); 495 QStringList color = config.readListEntry("textcolor", QChar(','));
496 496
497 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 497 QColor newcolor = QColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
498 498
499 color[0].setNum(newcolor.red()); 499 color[0].setNum(newcolor.red());
500 color[1].setNum(newcolor.green()); 500 color[1].setNum(newcolor.green());
501 color[2].setNum(newcolor.blue()); 501 color[2].setNum(newcolor.blue());
502 502
503 config.writeEntry("textcolor", color, QChar(',')); 503 config.writeEntry("textcolor", color, QChar(','));
504 config.write(); 504 config.write();
505 505
506 textcolor_button->setPalette(QPalette(newcolor)); 506 textcolor_button->setPalette(QPalette(newcolor));
507 emit reloadKeyboard(); 507 emit reloadKeyboard();
508} 508}
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index 7ddfd3e..f8cafd5 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -1,1710 +1,1710 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "keyboard.h" 21#include "keyboard.h"
22#include "configdlg.h" 22#include "configdlg.h"
23 23
24#include <qpe/global.h> 24#include <qpe/global.h>
25#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
26 26
27#include <qwindowsystem_qws.h> 27#include <qwindowsystem_qws.h>
28#include <qpainter.h> 28#include <qpainter.h>
29#include <qfontmetrics.h> 29#include <qfontmetrics.h>
30#include <qtimer.h> 30#include <qtimer.h>
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#include <qpe/config.h> 32#include <qpe/config.h>
33#include <ctype.h> 33#include <ctype.h>
34#include <qdir.h> 34#include <qdir.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qstringlist.h> 36#include <qstringlist.h>
37 37
38#include <sys/utsname.h> 38#include <sys/utsname.h>
39 39
40using namespace MultiKey; 40using namespace MultiKey;
41 41
42static const char * const kb_config_xpm[] = { 42static const char * const kb_config_xpm[] = {
43"13 7 2 1", 43"13 7 2 1",
44" c None", 44" c None",
45". c #000000", 45". c #000000",
46" ", 46" ",
47" . ", 47" . ",
48" ... ", 48" ... ",
49" ..... ", 49" ..... ",
50" . ", 50" . ",
51" . ", 51" . ",
52" "}; 52" "};
53 53
54/* Keyboard::Keyboard {{{1 */ 54/* Keyboard::Keyboard {{{1 */
55Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : 55Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
56 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), 56 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0),
57 meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0), 57 meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0),
58 useLargeKeys(TRUE), usePicks(0), useRepeat(0), 58 useLargeKeys(TRUE), usePicks(0), useRepeat(0),
59 pressedKeyRow(-1), pressedKeyCol(-1), 59 pressedKeyRow(-1), pressedKeyCol(-1),
60 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), 60 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0),
61 configdlg(0) 61 configdlg(0)
62 62
63{ 63{
64 64
65 // get the default font 65 // get the default font
66 Config *config = new Config( "qpe" ); 66 Config *config = new Config( "qpe" );
67 config->setGroup( "Appearance" ); 67 config->setGroup( "Appearance" );
68 QString familyStr = config->readEntry( "FontFamily", "smallsmooth" ); 68 QString familyStr = config->readEntry( "FontFamily", "smallsmooth" );
69 delete config; 69 delete config;
70 70
71 config = new Config("multikey"); 71 config = new Config("multikey");
72 config->setGroup ("general"); 72 config->setGroup ("general");
73 usePicks = config->readBoolEntry ("usePickboard", 0); // default closed 73 usePicks = config->readBoolEntry ("usePickboard", 0); // default closed
74 useRepeat = config->readBoolEntry ("useRepeat", 1); 74 useRepeat = config->readBoolEntry ("useRepeat", 1);
75 delete config; 75 delete config;
76 76
77 77
78 setFont( QFont( familyStr, 10 ) ); 78 setFont( QFont( familyStr, 10 ) );
79 79
80 picks = new KeyboardPicks( this ); 80 picks = new KeyboardPicks( this );
81 picks->setFont( QFont( familyStr, 10 ) ); 81 picks->setFont( QFont( familyStr, 10 ) );
82 picks->initialise(); 82 picks->initialise();
83 if (usePicks) { 83 if (usePicks) {
84 84
85 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 85 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
86 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 86 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
87 87
88 } else picks->hide(); 88 } else picks->hide();
89 89
90 loadKeyboardColors(); 90 loadKeyboardColors();
91 91
92 keys = new Keys(); 92 keys = new Keys();
93 93
94 repeatTimer = new QTimer( this ); 94 repeatTimer = new QTimer( this );
95 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); 95 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
96 96
97 QCopChannel* kbdChannel = new QCopChannel("MultiKey/Keyboard", this); 97 QCopChannel* kbdChannel = new QCopChannel("MultiKey/Keyboard", this);
98 connect(kbdChannel, SIGNAL(received(const QCString&,const QByteArray&)), 98 connect(kbdChannel, SIGNAL(received(const QCString&,const QByteArray&)),
99 this, SLOT(receive(const QCString&,const QByteArray&))); 99 this, SLOT(receive(const QCString&,const QByteArray&)));
100} 100}
101 101
102Keyboard::~Keyboard() { 102Keyboard::~Keyboard() {
103 103
104 if ( configdlg ) { 104 if ( configdlg ) {
105 delete configdlg; 105 delete configdlg;
106 configdlg = 0; 106 configdlg = 0;
107 } 107 }
108 108
109} 109}
110 110
111/* Keyboard::resizeEvent {{{1 */ 111/* Keyboard::resizeEvent {{{1 */
112void Keyboard::resizeEvent(QResizeEvent*) 112void Keyboard::resizeEvent(QResizeEvent*)
113{ 113{
114 int ph = picks->sizeHint().height(); 114 int ph = picks->sizeHint().height();
115 picks->setGeometry( 0, 0, width(), ph ); 115 picks->setGeometry( 0, 0, width(), ph );
116 keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1); 116 keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1);
117 117
118 int nk; // number of keys? 118 int nk; // number of keys?
119 if ( useLargeKeys ) { 119 if ( useLargeKeys ) {
120 nk = 15; 120 nk = 15;
121 } else { 121 } else {
122 nk = 19; 122 nk = 19;
123 } 123 }
124 defaultKeyWidth = (width()/nk)/2; 124 defaultKeyWidth = (width()/nk)/2;
125 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? 125 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
126 126
127} 127}
128 128
129/* KeyboardPicks::initialize {{{1 */ 129/* KeyboardPicks::initialize {{{1 */
130void KeyboardPicks::initialise() 130void KeyboardPicks::initialise()
131{ 131{
132 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 132 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
133 mode = 0; 133 mode = 0;
134 dc = new KeyboardConfig(this); 134 dc = new KeyboardConfig(this);
135 configs.append(dc); 135 configs.append(dc);
136} 136}
137 137
138/* KeyboardPicks::sizeHint {{{1 */ 138/* KeyboardPicks::sizeHint {{{1 */
139QSize KeyboardPicks::sizeHint() const 139QSize KeyboardPicks::sizeHint() const
140{ 140{
141 return QSize(240,fontMetrics().lineSpacing()); 141 return QSize(240,fontMetrics().lineSpacing());
142} 142}
143 143
144 144
145/* KeyboardConfig::generateText {{{1 */ 145/* KeyboardConfig::generateText {{{1 */
146void KeyboardConfig::generateText(const QString &s) 146void KeyboardConfig::generateText(const QString &s)
147{ 147{
148#if defined(Q_WS_QWS) || defined(_WS_QWS_) 148#if defined(Q_WS_QWS) || defined(_WS_QWS_)
149 for (int i=0; i<(int)backspaces; i++) { 149 for (int i=0; i<(int)backspaces; i++) {
150 parent->emitKey( 0, ::Qt::Key_Backspace, 0, true, false ); 150 parent->emitKey( 0, ::Qt::Key_Backspace, 0, true, false );
151 parent->emitKey( 0, ::Qt::Key_Backspace, 0, false, false ); 151 parent->emitKey( 0, ::Qt::Key_Backspace, 0, false, false );
152 } 152 }
153 for (int i=0; i<(int)s.length(); i++) { 153 for (int i=0; i<(int)s.length(); i++) {
154 parent->emitKey( s[i].unicode(), 0, 0, true, false ); 154 parent->emitKey( s[i].unicode(), 0, 0, true, false );
155 parent->emitKey( s[i].unicode(), 0, 0, false, false ); 155 parent->emitKey( s[i].unicode(), 0, 0, false, false );
156 } 156 }
157 parent->emitKey( 0, ::Qt::Key_Space, 0, true, false ); 157 parent->emitKey( 0, ::Qt::Key_Space, 0, true, false );
158 parent->emitKey( 0, ::Qt::Key_Space, 0, false, false ); 158 parent->emitKey( 0, ::Qt::Key_Space, 0, false, false );
159 backspaces = 0; 159 backspaces = 0;
160#endif 160#endif
161} 161}
162 162
163 163
164 164
165 165
166/* Keyboard::paintEvent {{{1 */ 166/* Keyboard::paintEvent {{{1 */
167void Keyboard::paintEvent(QPaintEvent* e) 167void Keyboard::paintEvent(QPaintEvent* e)
168{ 168{
169 QPainter painter(this); 169 QPainter painter(this);
170 painter.setClipRect(e->rect()); 170 painter.setClipRect(e->rect());
171 drawKeyboard( painter ); 171 drawKeyboard( painter );
172 picks->dc->draw( &painter ); 172 picks->dc->draw( &painter );
173} 173}
174 174
175 175
176/* Keyboard::drawKeyboard {{{1 */ 176/* Keyboard::drawKeyboard {{{1 */
177 177
178void Keyboard::drawKeyboard(QPainter &p, int row, int col) 178void Keyboard::drawKeyboard(QPainter &p, int row, int col)
179{ 179{
180 180
181 181
182 if (row != -1 && col != -1) { //just redraw one key 182 if (row != -1 && col != -1) { //just redraw one key
183 183
184 int x = 0; 184 int x = 0;
185 for (int i = 0; i < col; i++) { 185 for (int i = 0; i < col; i++) {
186 186
187 x += keys->width(row, i) * defaultKeyWidth; 187 x += keys->width(row, i) * defaultKeyWidth;
188 } 188 }
189 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 189 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
190 190
191 int keyWidth = keys->width(row, col); 191 int keyWidth = keys->width(row, col);
192 192
193 p.fillRect(x + 1, y + 1, 193 p.fillRect(x + 1, y + 1,
194 keyWidth * defaultKeyWidth - 1, keyHeight - 1, 194 keyWidth * defaultKeyWidth - 1, keyHeight - 1,
195 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); 195 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor);
196 196
197 QImage *pix = keys->pix(row,col); 197 QImage *pix = keys->pix(row,col);
198 198
199 ushort c = keys->uni(row, col); 199 ushort c = keys->uni(row, col);
200 200
201 p.setPen(textcolor); 201 p.setPen(textcolor);
202 if (!pix) { 202 if (!pix) {
203 if ((shift || lock) && keys->shift(c)) 203 if ((shift || lock) && keys->shift(c))
204 204
205 if (circumflex && keys->circumflex(keys->shift(c))) 205 if (circumflex && keys->circumflex(keys->shift(c)))
206 c = keys->circumflex(keys->shift(c)); 206 c = keys->circumflex(keys->shift(c));
207 else if (diaeresis && keys->diaeresis(keys->shift(c))) 207 else if (diaeresis && keys->diaeresis(keys->shift(c)))
208 c = keys->diaeresis(keys->shift(c)); 208 c = keys->diaeresis(keys->shift(c));
209 else if (baccent && keys->baccent(keys->shift(c))) 209 else if (baccent && keys->baccent(keys->shift(c)))
210 c = keys->baccent(keys->shift(c)); 210 c = keys->baccent(keys->shift(c));
211 else if (accent && keys->accent(keys->shift(c))) 211 else if (accent && keys->accent(keys->shift(c)))
212 c = keys->accent(keys->shift(c)); 212 c = keys->accent(keys->shift(c));
213 else if (meta && keys->meta(keys->shift(c))) 213 else if (meta && keys->meta(keys->shift(c)))
214 c = keys->meta(keys->shift(c)); 214 c = keys->meta(keys->shift(c));
215 else 215 else
216 c = keys->shift(c); 216 c = keys->shift(c);
217 217
218 else if (meta && keys->meta(c)) 218 else if (meta && keys->meta(c))
219 c = keys->meta(c); 219 c = keys->meta(c);
220 else if (circumflex && keys->circumflex(c)) 220 else if (circumflex && keys->circumflex(c))
221 c = keys->circumflex(c); 221 c = keys->circumflex(c);
222 else if (baccent && keys->baccent(c)) 222 else if (baccent && keys->baccent(c))
223 c = keys->baccent(c); 223 c = keys->baccent(c);
224 else if (accent && keys->accent(c)) 224 else if (accent && keys->accent(c))
225 c = keys->accent(c); 225 c = keys->accent(c);
226 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { 226 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) {
227 227
228 // the diaeresis key itself has to be in the diaeresisMap, 228 // the diaeresis key itself has to be in the diaeresisMap,
229 // or just do this to make it display the diaeresis char. 229 // or just do this to make it display the diaeresis char.
230 230
231 if (c == 0x2c6) 231 if (c == 0x2c6)
232 c = 0xa8; 232 c = 0xa8;
233 else 233 else
234 c = keys->diaeresis(c); 234 c = keys->diaeresis(c);
235 } 235 }
236 236
237 p.drawText(x, y, 237 p.drawText(x, y,
238 defaultKeyWidth * keyWidth + 3, keyHeight, 238 defaultKeyWidth * keyWidth + 3, keyHeight,
239 AlignCenter, (QChar)c); 239 AlignCenter, (QChar)c);
240 } 240 }
241 else 241 else
242 // center the image in the middle of the key 242 // center the image in the middle of the key
243 p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1, 243 p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1,
244 y + (keyHeight - pix->height())/2 + 1, 244 y + (keyHeight - pix->height())/2 + 1,
245 *pix ); 245 *pix );
246 246
247 // this fixes the problem that the very right end of the board's vertical line 247 // this fixes the problem that the very right end of the board's vertical line
248 // gets painted over, because it's one pixel shorter than all other keys 248 // gets painted over, because it's one pixel shorter than all other keys
249 p.setPen(keycolor_lines); 249 p.setPen(keycolor_lines);
250 p.drawLine(width() - 1, 0, width() - 1, height()); 250 p.drawLine(width() - 1, 0, width() - 1, height());
251 251
252 } else { 252 } else {
253 253
254 254
255 p.fillRect(0, 0, width(), height(), keycolor); 255 p.fillRect(0, 0, width(), height(), keycolor);
256 256
257 for (row = 1; row <= keys->rows(); row++) { 257 for (row = 1; row <= keys->rows(); row++) {
258 258
259 int x = 0; 259 int x = 0;
260 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 260 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
261 261
262 p.setPen(keycolor_lines); 262 p.setPen(keycolor_lines);
263 p.drawLine(x, y, x + width(), y); 263 p.drawLine(x, y, x + width(), y);
264 264
265 for (int col = 0; col < keys->numKeys(row); col++) { 265 for (int col = 0; col < keys->numKeys(row); col++) {
266 266
267 QImage *pix = keys->pix(row, col); 267 QImage *pix = keys->pix(row, col);
268 int keyWidth = keys->width(row, col); 268 int keyWidth = keys->width(row, col);
269 269
270 270
271 int keyWidthPix = defaultKeyWidth * keyWidth; 271 int keyWidthPix = defaultKeyWidth * keyWidth;
272 272
273 if (keys->pressed(row, col)) 273 if (keys->pressed(row, col))
274 p.fillRect(x+1, y+1, keyWidthPix - 1, 274 p.fillRect(x+1, y+1, keyWidthPix - 1,
275 keyHeight - 1, keycolor_pressed); 275 keyHeight - 1, keycolor_pressed);
276 276
277 ushort c = keys->uni(row, col); 277 ushort c = keys->uni(row, col);
278 278
279 p.setPen(textcolor); 279 p.setPen(textcolor);
280 if (!pix) { 280 if (!pix) {
281 if ((shift || lock) && keys->shift(c)) 281 if ((shift || lock) && keys->shift(c))
282 282
283 if (circumflex && keys->circumflex(keys->shift(c))) 283 if (circumflex && keys->circumflex(keys->shift(c)))
284 c = keys->circumflex(keys->shift(c)); 284 c = keys->circumflex(keys->shift(c));
285 else if (diaeresis && keys->diaeresis(keys->shift(c))) 285 else if (diaeresis && keys->diaeresis(keys->shift(c)))
286 c = keys->diaeresis(keys->shift(c)); 286 c = keys->diaeresis(keys->shift(c));
287 else if (baccent && keys->baccent(keys->shift(c))) 287 else if (baccent && keys->baccent(keys->shift(c)))
288 c = keys->baccent(keys->shift(c)); 288 c = keys->baccent(keys->shift(c));
289 else if (accent && keys->accent(keys->shift(c))) 289 else if (accent && keys->accent(keys->shift(c)))
290 c = keys->accent(keys->shift(c)); 290 c = keys->accent(keys->shift(c));
291 else if (meta && keys->meta(keys->shift(c))) 291 else if (meta && keys->meta(keys->shift(c)))
292 c = keys->meta(keys->shift(c)); 292 c = keys->meta(keys->shift(c));
293 else 293 else
294 c = keys->shift(c); 294 c = keys->shift(c);
295 295
296 else if (meta && keys->meta(c)) 296 else if (meta && keys->meta(c))
297 c = keys->meta(c); 297 c = keys->meta(c);
298 else if (circumflex && keys->circumflex(c)) 298 else if (circumflex && keys->circumflex(c))
299 c = keys->circumflex(c); 299 c = keys->circumflex(c);
300 else if (baccent && keys->baccent(c)) 300 else if (baccent && keys->baccent(c))
301 c = keys->baccent(c); 301 c = keys->baccent(c);
302 else if (accent && keys->accent(c)) 302 else if (accent && keys->accent(c))
303 c = keys->accent(c); 303 c = keys->accent(c);
304 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { 304 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) {
305 305
306 if (c == 0x2c6) 306 if (c == 0x2c6)
307 c = 0xa8; 307 c = 0xa8;
308 else 308 else
309 c = keys->diaeresis(c); 309 c = keys->diaeresis(c);
310 } 310 }
311 311
312 p.drawText(x, y, 312 p.drawText(x, y,
313 keyWidthPix + 3, keyHeight, 313 keyWidthPix + 3, keyHeight,
314 AlignCenter, (QChar)c); 314 AlignCenter, (QChar)c);
315 } 315 }
316 else { 316 else {
317 // center the image in the middle of the key 317 // center the image in the middle of the key
318 pix->setColor(1, textcolor.rgb()); 318 pix->setColor(1, textcolor.rgb());
319 p.drawImage( x + (keyWidthPix - pix->width())/2 + 1, 319 p.drawImage( x + (keyWidthPix - pix->width())/2 + 1,
320 y + (keyHeight - pix->height())/2 + 1, 320 y + (keyHeight - pix->height())/2 + 1,
321 QImage(*pix) ); 321 QImage(*pix) );
322 } 322 }
323 323
324 p.setPen(keycolor_lines); 324 p.setPen(keycolor_lines);
325 p.drawLine(x, y, x, y + keyHeight); 325 p.drawLine(x, y, x, y + keyHeight);
326 326
327 x += keyWidthPix; 327 x += keyWidthPix;
328 } 328 }
329 329
330 330
331 } 331 }
332 p.setPen(keycolor_lines); 332 p.setPen(keycolor_lines);
333 p.drawLine(0, height() - 1, width(), height() - 1); 333 p.drawLine(0, height() - 1, width(), height() - 1);
334 p.drawLine(width() - 1, 0, width() - 1, height()); 334 p.drawLine(width() - 1, 0, width() - 1, height());
335 } 335 }
336 336
337} 337}
338 338
339 339
340/* Keyboard::mousePressEvent {{{1 */ 340/* Keyboard::mousePressEvent {{{1 */
341void Keyboard::mousePressEvent(QMouseEvent *e) 341void Keyboard::mousePressEvent(QMouseEvent *e)
342{ 342{
343 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; 343 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1;
344 if (row > 5) row = 5; 344 if (row > 5) row = 5;
345 345
346 // figure out the column 346 // figure out the column
347 int col = 0; 347 int col = 0;
348 for (int w = 0; e->x() >= w; col++) 348 for (int w = 0; e->x() >= w; col++)
349 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys 349 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys
350 w += keys->width(row,col) * defaultKeyWidth; 350 w += keys->width(row,col) * defaultKeyWidth;
351 else break; 351 else break;
352 352
353 if (col <= 0) return; 353 if (col <= 0) return;
354 354
355 col --; // rewind one... 355 col --; // rewind one...
356 356
357 qkeycode = keys->qcode(row, col); 357 qkeycode = keys->qcode(row, col);
358 unicode = keys->uni(row, col); 358 unicode = keys->uni(row, col);
359 359
360 // might need to repaint if two or more of the same keys. 360 // might need to repaint if two or more of the same keys.
361 // should be faster if just paint one key even though multiple keys exist. 361 // should be faster if just paint one key even though multiple keys exist.
362 bool need_repaint = FALSE; 362 bool need_repaint = FALSE;
363 363
364 // circumflex and diaeresis support 364 // circumflex and diaeresis support
365 // messy to have this here, but too hard to implement any other method 365 // messy to have this here, but too hard to implement any other method
366 if (unicode == 0x2c6) { 366 if (unicode == 0x2c6) {
367 367
368 unicode = 0; 368 unicode = 0;
369 if (shift || lock) { 369 if (shift || lock) {
370 370
371 // diaeresis 371 // diaeresis
372 qkeycode = 0x2001; 372 qkeycode = 0x2001;
373 } 373 }
374 else { 374 else {
375 375
376 // circumflex 376 // circumflex
377 qkeycode = 0x2000; 377 qkeycode = 0x2000;
378 } 378 }
379 } 379 }
380 380
381 // Back accent character support 381 // Back accent character support
382 382
383 // the keys from 2c6 ~ 2cf should be used instead of the ascii one 383 // the keys from 2c6 ~ 2cf should be used instead of the ascii one
384 if (unicode == 0x2cb) { 384 if (unicode == 0x2cb) {
385 385
386 unicode = 0; 386 unicode = 0;
387 if (shift || lock) { 387 if (shift || lock) {
388 388
389 // circumblex 389 // circumblex
390 qkeycode = 0x2000; 390 qkeycode = 0x2000;
391 } 391 }
392 else { 392 else {
393 393
394 // back accent 394 // back accent
395 qkeycode = 0x2002; 395 qkeycode = 0x2002;
396 } 396 }
397 } 397 }
398 398
399 // Accent character support 399 // Accent character support
400 400
401 if (unicode == 0x2ca) { 401 if (unicode == 0x2ca) {
402 402
403 unicode = 0; 403 unicode = 0;
404 if (shift || lock) { 404 if (shift || lock) {
405 405
406 // diaeresis 406 // diaeresis
407 qkeycode = 0x2001; 407 qkeycode = 0x2001;
408 } 408 }
409 else { 409 else {
410 410
411 // accent 411 // accent
412 qkeycode = 0x2003; 412 qkeycode = 0x2003;
413 } 413 }
414 } 414 }
415 415
416 416
417 if (unicode == 0) { // either Qt char, or nothing 417 if (unicode == 0) { // either Qt char, or nothing
418 418
419 if (qkeycode == Qt::Key_F1) { // toggle the pickboard 419 if (qkeycode == Qt::Key_F1) { // toggle the pickboard
420 420
421 if ( configdlg ) { 421 if ( configdlg ) {
422 422
423 delete configdlg; 423 delete configdlg;
424 configdlg = 0; 424 configdlg = 0;
425 } 425 }
426 else { 426 else {
427 configdlg = new ConfigDlg (); 427 configdlg = new ConfigDlg ();
428 connect(configdlg, SIGNAL(setMapToDefault()), 428 connect(configdlg, SIGNAL(setMapToDefault()),
429 this, SLOT(setMapToDefault())); 429 this, SLOT(setMapToDefault()));
430 connect(configdlg, SIGNAL(setMapToFile(QString)), 430 connect(configdlg, SIGNAL(setMapToFile(QString)),
431 this, SLOT(setMapToFile(QString))); 431 this, SLOT(setMapToFile(QString)));
432 connect(configdlg, SIGNAL(pickboardToggled(bool)), 432 connect(configdlg, SIGNAL(pickboardToggled(bool)),
433 this, SLOT(togglePickboard(bool))); 433 this, SLOT(togglePickboard(bool)));
434 connect(configdlg, SIGNAL(repeatToggled(bool)), 434 connect(configdlg, SIGNAL(repeatToggled(bool)),
435 this, SLOT(toggleRepeat(bool))); 435 this, SLOT(toggleRepeat(bool)));
436 connect(configdlg, SIGNAL(reloadKeyboard()), 436 connect(configdlg, SIGNAL(reloadKeyboard()),
437 this, SLOT(reloadKeyboard())); 437 this, SLOT(reloadKeyboard()));
438 connect(configdlg, SIGNAL(configDlgClosed()), 438 connect(configdlg, SIGNAL(configDlgClosed()),
439 this, SLOT(cleanupConfigDlg())); 439 this, SLOT(cleanupConfigDlg()));
440 connect(configdlg, SIGNAL(reloadSw()), 440 connect(configdlg, SIGNAL(reloadSw()),
441 this, SLOT(reloadSw())); 441 this, SLOT(reloadSw()));
442 configdlg->showMaximized(); 442 configdlg->showMaximized();
443 configdlg->show(); 443 configdlg->show();
444 configdlg->raise(); 444 configdlg->raise();
445 } 445 }
446 446
447 } else if (qkeycode == Qt::Key_Control) { 447 } else if (qkeycode == Qt::Key_Control) {
448 need_repaint = TRUE; 448 need_repaint = TRUE;
449 449
450 if (ctrl) { 450 if (ctrl) {
451 451
452 *ctrl = 0; 452 *ctrl = 0;
453 ctrl = 0; 453 ctrl = 0;
454 454
455 } else { 455 } else {
456 456
457 ctrl = keys->pressedPtr(row, col); 457 ctrl = keys->pressedPtr(row, col);
458 need_repaint = TRUE; 458 need_repaint = TRUE;
459 *ctrl = !keys->pressed(row, col); 459 *ctrl = !keys->pressed(row, col);
460 460
461 } 461 }
462 462
463 } else if (qkeycode == Qt::Key_Alt) { 463 } else if (qkeycode == Qt::Key_Alt) {
464 need_repaint = TRUE; 464 need_repaint = TRUE;
465 465
466 if (alt) { 466 if (alt) {
467 *alt = 0; 467 *alt = 0;
468 alt = 0; 468 alt = 0;
469 469
470 } else { 470 } else {
471 471
472 alt = keys->pressedPtr(row, col); 472 alt = keys->pressedPtr(row, col);
473 need_repaint = TRUE; 473 need_repaint = TRUE;
474 *alt = !keys->pressed(row, col); 474 *alt = !keys->pressed(row, col);
475 } 475 }
476 476
477 } else if (qkeycode == Qt::Key_Shift) { 477 } else if (qkeycode == Qt::Key_Shift) {
478 need_repaint = TRUE; 478 need_repaint = TRUE;
479 479
480 if (shift) { 480 if (shift) {
481 *shift = 0; 481 *shift = 0;
482 shift = 0; 482 shift = 0;
483 } 483 }
484 else { 484 else {
485 shift = keys->pressedPtr(row, col); 485 shift = keys->pressedPtr(row, col);
486 *shift = 1; 486 *shift = 1;
487 if (lock) { 487 if (lock) {
488 *lock = 0; 488 *lock = 0;
489 lock = 0; 489 lock = 0;
490 } 490 }
491 } 491 }
492 492
493 493
494 /* 494 /*
495 * want to be able to hit circumflex/diaeresis -> shift 495 * want to be able to hit circumflex/diaeresis -> shift
496 * to type in shifted circumflex/diaeresis chars. 496 * to type in shifted circumflex/diaeresis chars.
497 * same thing with meta 497 * same thing with meta
498 498
499 if (meta) { *meta = 0; meta = 0; } 499 if (meta) { *meta = 0; meta = 0; }
500 if (circumflex) { *circumflex = 0; circumflex = 0; } 500 if (circumflex) { *circumflex = 0; circumflex = 0; }
501 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 501 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
502 502
503 */ 503 */
504 504
505 } else if (qkeycode == Qt::Key_CapsLock) { 505 } else if (qkeycode == Qt::Key_CapsLock) {
506 need_repaint = TRUE; 506 need_repaint = TRUE;
507 507
508 if (lock) { 508 if (lock) {
509 *lock = 0; 509 *lock = 0;
510 lock = 0; 510 lock = 0;
511 } 511 }
512 else { 512 else {
513 lock = keys->pressedPtr(row, col);; 513 lock = keys->pressedPtr(row, col);;
514 *lock = true;; 514 *lock = true;;
515 if (shift) { 515 if (shift) {
516 *shift = 0; 516 *shift = 0;
517 shift = 0; 517 shift = 0;
518 } 518 }
519 } 519 }
520 520
521 /* 521 /*
522 if (meta) { *meta = 0; meta = 0; } 522 if (meta) { *meta = 0; meta = 0; }
523 if (circumflex) { *circumflex = 0; circumflex = 0; } 523 if (circumflex) { *circumflex = 0; circumflex = 0; }
524 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 524 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
525 */ 525 */
526 526
527 } else if (qkeycode == Qt::Key_Meta) { 527 } else if (qkeycode == Qt::Key_Meta) {
528 need_repaint = TRUE; 528 need_repaint = TRUE;
529 529
530 if (meta) { 530 if (meta) {
531 *meta = 0; 531 *meta = 0;
532 meta = 0; 532 meta = 0;
533 533
534 } else { 534 } else {
535 535
536 meta = keys->pressedPtr(row, col); 536 meta = keys->pressedPtr(row, col);
537 *meta = true; 537 *meta = true;
538 } 538 }
539 539
540 // reset all the other keys 540 // reset all the other keys
541 if (shift) { *shift = 0; shift = 0; } 541 if (shift) { *shift = 0; shift = 0; }
542 if (lock) { *lock = 0; lock = 0; } 542 if (lock) { *lock = 0; lock = 0; }
543 if (circumflex) { *circumflex = 0; circumflex = 0; } 543 if (circumflex) { *circumflex = 0; circumflex = 0; }
544 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 544 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
545 if (baccent) { *baccent = 0; baccent = 0; } 545 if (baccent) { *baccent = 0; baccent = 0; }
546 if (accent) { *accent = 0; accent = 0; } 546 if (accent) { *accent = 0; accent = 0; }
547 547
548 // dont need to emit this key... acts same as alt 548 // dont need to emit this key... acts same as alt
549 qkeycode = 0; 549 qkeycode = 0;
550 550
551 // circumflex 551 // circumflex
552 } else if (qkeycode == 0x2000) { 552 } else if (qkeycode == 0x2000) {
553 need_repaint = TRUE; 553 need_repaint = TRUE;
554 554
555 if (circumflex) { 555 if (circumflex) {
556 556
557 *circumflex = 0; 557 *circumflex = 0;
558 circumflex = 0; 558 circumflex = 0;
559 559
560 } else { 560 } else {
561 561
562 circumflex = keys->pressedPtr(row, col); 562 circumflex = keys->pressedPtr(row, col);
563 *circumflex = true; 563 *circumflex = true;
564 } 564 }
565 565
566 /* no need to turn off shift or lock if circumflex 566 /* no need to turn off shift or lock if circumflex
567 * keys are pressed 567 * keys are pressed
568 568
569 if (shift) { *shift = 0; shift = 0; } 569 if (shift) { *shift = 0; shift = 0; }
570 if (lock) { *lock = 0; lock = 0; } 570 if (lock) { *lock = 0; lock = 0; }
571 571
572 */ 572 */
573 573
574 // have to reset all the other keys 574 // have to reset all the other keys
575 if (meta) { *meta = 0; meta = 0; } 575 if (meta) { *meta = 0; meta = 0; }
576 if (diaeresis) { 576 if (diaeresis) {
577 577
578 // *diaeresis and *circumflex point to the same thing 578 // *diaeresis and *circumflex point to the same thing
579 // when diaeresis is enabled and you hit the circumflex 579 // when diaeresis is enabled and you hit the circumflex
580 // since they are the same key, it should turn off the 580 // since they are the same key, it should turn off the
581 // key 581 // key
582 582
583 *diaeresis = 0; 583 *diaeresis = 0;
584 diaeresis = 0; 584 diaeresis = 0;
585 circumflex = 0; 585 circumflex = 0;
586 } 586 }
587 587
588 qkeycode = 0; 588 qkeycode = 0;
589 589
590 // diaeresis 590 // diaeresis
591 } else if (qkeycode == 0x2001) { 591 } else if (qkeycode == 0x2001) {
592 need_repaint = TRUE; 592 need_repaint = TRUE;
593 593
594 if (diaeresis) { 594 if (diaeresis) {
595 595
596 *diaeresis = 0; 596 *diaeresis = 0;
597 diaeresis = 0; 597 diaeresis = 0;
598 598
599 } else { 599 } else {
600 600
601 diaeresis = keys->pressedPtr(row, col); 601 diaeresis = keys->pressedPtr(row, col);
602 *diaeresis = true; 602 *diaeresis = true;
603 } 603 }
604 604
605 605
606 if (shift) { *shift = 0; shift = 0; } 606 if (shift) { *shift = 0; shift = 0; }
607 607
608 /* 608 /*
609 * 609 *
610 if (lock) { *lock = 0; lock = 0; } 610 if (lock) { *lock = 0; lock = 0; }
611 * 611 *
612 */ 612 */
613 613
614 if (meta) { *meta = 0; meta = 0; } 614 if (meta) { *meta = 0; meta = 0; }
615 if (circumflex) { 615 if (circumflex) {
616 616
617 // *circumflex = 0; 617 // *circumflex = 0;
618 // 618 //
619 // same thing the diaeresis pointer points too 619 // same thing the diaeresis pointer points too
620 620
621 circumflex = 0; 621 circumflex = 0;
622 } 622 }
623 623
624 624
625 qkeycode = 0; 625 qkeycode = 0;
626 626
627 // Back accent 627 // Back accent
628 } else if (qkeycode == 0x2002) { 628 } else if (qkeycode == 0x2002) {
629 need_repaint = TRUE; 629 need_repaint = TRUE;
630 630
631 if (baccent) { 631 if (baccent) {
632 632
633 *baccent = 0; 633 *baccent = 0;
634 baccent = 0; 634 baccent = 0;
635 635
636 } else { 636 } else {
637 637
638 baccent = keys->pressedPtr(row, col); 638 baccent = keys->pressedPtr(row, col);
639 *baccent = true; 639 *baccent = true;
640 } 640 }
641 641
642 642
643 if (shift) { *shift = 0; shift = 0; } 643 if (shift) { *shift = 0; shift = 0; }
644 if (meta) { *meta = 0; meta = 0; } 644 if (meta) { *meta = 0; meta = 0; }
645 if (accent) { *accent = 0; accent = 0; } 645 if (accent) { *accent = 0; accent = 0; }
646 646
647 qkeycode = 0; 647 qkeycode = 0;
648 648
649 // Accent 649 // Accent
650 } else if (qkeycode == 0x2003) { 650 } else if (qkeycode == 0x2003) {
651 need_repaint = TRUE; 651 need_repaint = TRUE;
652 652
653 if (accent) { 653 if (accent) {
654 654
655 *accent = 0; 655 *accent = 0;
656 accent = 0; 656 accent = 0;
657 657
658 } else { 658 } else {
659 659
660 accent = keys->pressedPtr(row, col); 660 accent = keys->pressedPtr(row, col);
661 *accent = true; 661 *accent = true;
662 } 662 }
663 663
664 664
665 if (shift) { *shift = 0; shift = 0; } 665 if (shift) { *shift = 0; shift = 0; }
666 if (meta) { *meta = 0; meta = 0; } 666 if (meta) { *meta = 0; meta = 0; }
667 if (baccent) { *baccent = 0; } 667 if (baccent) { *baccent = 0; }
668 668
669 qkeycode = 0; 669 qkeycode = 0;
670 } 670 }
671 671
672 } 672 }
673 else { // normal char 673 else { // normal char
674 if ((shift || lock) && keys->shift(unicode)) { 674 if ((shift || lock) && keys->shift(unicode)) {
675 675
676 // make diaeresis/circumflex -> shift input shifted 676 // make diaeresis/circumflex -> shift input shifted
677 // diaeresis/circumflex chars 677 // diaeresis/circumflex chars
678 678
679 if (circumflex && keys->circumflex(keys->shift(unicode))) 679 if (circumflex && keys->circumflex(keys->shift(unicode)))
680 unicode = keys->circumflex(keys->shift(unicode)); 680 unicode = keys->circumflex(keys->shift(unicode));
681 else if (diaeresis && keys->diaeresis(keys->shift(unicode))) 681 else if (diaeresis && keys->diaeresis(keys->shift(unicode)))
682 unicode = keys->diaeresis(keys->shift(unicode)); 682 unicode = keys->diaeresis(keys->shift(unicode));
683 else if (baccent && keys->baccent(keys->shift(unicode))) 683 else if (baccent && keys->baccent(keys->shift(unicode)))
684 unicode = keys->baccent(keys->shift(unicode)); 684 unicode = keys->baccent(keys->shift(unicode));
685 else if (accent && keys->accent(keys->shift(unicode))) 685 else if (accent && keys->accent(keys->shift(unicode)))
686 unicode = keys->accent(keys->shift(unicode)); 686 unicode = keys->accent(keys->shift(unicode));
687 else if (meta && keys->meta(keys->shift(unicode))) 687 else if (meta && keys->meta(keys->shift(unicode)))
688 unicode = keys->meta(keys->shift(unicode)); 688 unicode = keys->meta(keys->shift(unicode));
689 else 689 else
690 unicode = keys->shift(unicode); 690 unicode = keys->shift(unicode);
691 } 691 }
692 else if (meta && keys->meta(unicode)) { 692 else if (meta && keys->meta(unicode)) {
693 unicode = keys->meta(unicode); 693 unicode = keys->meta(unicode);
694 } 694 }
695 else if (circumflex && keys->circumflex(unicode)) { 695 else if (circumflex && keys->circumflex(unicode)) {
696 unicode = keys->circumflex(unicode); 696 unicode = keys->circumflex(unicode);
697 } 697 }
698 else if (diaeresis && keys->diaeresis(unicode)) { 698 else if (diaeresis && keys->diaeresis(unicode)) {
699 699
700 unicode = keys->diaeresis(unicode); 700 unicode = keys->diaeresis(unicode);
701 } 701 }
702 else if (baccent && keys->baccent(unicode)) { 702 else if (baccent && keys->baccent(unicode)) {
703 unicode = keys->baccent(unicode); 703 unicode = keys->baccent(unicode);
704 } 704 }
705 else if (accent && keys->accent(unicode)) { 705 else if (accent && keys->accent(unicode)) {
706 unicode = keys->accent(unicode); 706 unicode = keys->accent(unicode);
707 } 707 }
708 } 708 }
709 709
710 // korean parsing 710 // korean parsing
711 if (keys->lang == "ko") { 711 if (keys->lang == "ko") {
712 712
713 unicode = parseKoreanInput(unicode); 713 unicode = parseKoreanInput(unicode);
714 } 714 }
715 715
716 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); 716 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
717 717
718 if ('A' <= unicode && unicode <= 'z' && modifiers) { 718 if ('A' <= unicode && unicode <= 'z' && modifiers) {
719 719
720 qkeycode = QChar(unicode).upper(); 720 qkeycode = QChar(unicode).upper();
721 unicode = qkeycode - '@'; 721 unicode = qkeycode - '@';
722 } 722 }
723 723
724 QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); 724 QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false);
725 725
726 // pickboard stuff 726 // pickboard stuff
727 if (usePicks) { 727 if (usePicks) {
728 728
729 KeyboardConfig *dc = picks->dc; 729 KeyboardConfig *dc = picks->dc;
730 730
731 if (dc) { 731 if (dc) {
732 if (qkeycode == Qt::Key_Backspace) { 732 if (qkeycode == Qt::Key_Backspace) {
733 dc->input.remove(dc->input.last()); // remove last input 733 dc->input.remove(dc->input.last()); // remove last input
734 dc->decBackspaces(); 734 dc->decBackspaces();
735 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { 735 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) {
736 dc->input.clear(); 736 dc->input.clear();
737 dc->resetBackspaces(); 737 dc->resetBackspaces();
738 } else { 738 } else {
739 dc->add(QString(QChar(unicode))); 739 dc->add(QString(QChar(unicode)));
740 dc->incBackspaces(); 740 dc->incBackspaces();
741 } 741 }
742 } 742 }
743 picks->repaint(); 743 picks->repaint();
744 } 744 }
745 745
746 746
747 // painting 747 // painting
748 pressed = TRUE; 748 pressed = TRUE;
749 749
750 pressedKeyRow = row; 750 pressedKeyRow = row;
751 pressedKeyCol = col; 751 pressedKeyCol = col;
752 752
753 if (need_repaint) repaint(FALSE); 753 if (need_repaint) repaint(FALSE);
754 else { // just paint the one key pressed 754 else { // just paint the one key pressed
755 755
756 756
757 757
758 QPainter p(this); 758 QPainter p(this);
759 drawKeyboard(p, row, col); 759 drawKeyboard(p, row, col);
760 760
761 } 761 }
762 762
763 if (useRepeat) repeatTimer->start( 800 ); 763 if (useRepeat) repeatTimer->start( 800 );
764 //pressTid = startTimer(80); 764 //pressTid = startTimer(80);
765 765
766} 766}
767 767
768void Keyboard::receive(const QCString &msg, const QByteArray &data) 768void Keyboard::receive(const QCString &msg, const QByteArray &data)
769{ 769{
770 if (msg == "setmultikey(QString)") { 770 if (msg == "setmultikey(QString)") {
771 QDataStream stream(data, IO_ReadOnly); 771 QDataStream stream(data, IO_ReadOnly);
772 QString map; 772 QString map;
773 stream >> map; 773 stream >> map;
774 setMapToFile(map); 774 setMapToFile(map);
775 } else if (msg == "getmultikey()") { 775 } else if (msg == "getmultikey()") {
776 reloadSw(); 776 reloadSw();
777 } 777 }
778} 778}
779 779
780/* Keyboard::mouseReleaseEvent {{{1 */ 780/* Keyboard::mouseReleaseEvent {{{1 */
781void Keyboard::mouseReleaseEvent(QMouseEvent*) 781void Keyboard::mouseReleaseEvent(QMouseEvent*)
782{ 782{
783 pressed = FALSE; 783 pressed = FALSE;
784 //if ( pressTid == 0 ) 784 //if ( pressTid == 0 )
785#if defined(Q_WS_QWS) || defined(_WS_QWS_) 785#if defined(Q_WS_QWS) || defined(_WS_QWS_)
786 if ( unicode != -1 ) { 786 if ( unicode != -1 ) {
787 emit key( unicode, qkeycode, modifiers, false, false ); 787 emit key( unicode, qkeycode, modifiers, false, false );
788 repeatTimer->stop(); 788 repeatTimer->stop();
789 } 789 }
790#endif 790#endif
791 if (shift && unicode != 0) { 791 if (shift && unicode != 0) {
792 792
793 793
794 *shift = 0; // unpress shift key 794 *shift = 0; // unpress shift key
795 shift = 0; // reset the shift pointer 795 shift = 0; // reset the shift pointer
796 repaint(FALSE); 796 repaint(FALSE);
797 797
798 } 798 }
799 if (ctrl && unicode != 0) { 799 if (ctrl && unicode != 0) {
800 800
801 *ctrl = 0; 801 *ctrl = 0;
802 ctrl = 0; 802 ctrl = 0;
803 repaint(FALSE); 803 repaint(FALSE);
804 804
805 } 805 }
806 if (alt && alt != 0) { 806 if (alt && alt != 0) {
807 807
808 *alt = 0; 808 *alt = 0;
809 alt = 0; 809 alt = 0;
810 repaint(FALSE); 810 repaint(FALSE);
811 811
812 } 812 }
813 813
814 /* 814 /*
815 * do not make the meta key release after being pressed 815 * do not make the meta key release after being pressed
816 * 816 *
817 817
818 else if (meta && unicode != 0) { 818 else if (meta && unicode != 0) {
819 819
820 *meta = 0; 820 *meta = 0;
821 meta = 0; 821 meta = 0;
822 repaint(FALSE); 822 repaint(FALSE);
823 } 823 }
824 824
825 */ 825 */
826 826
827 else clearHighlight(); 827 else clearHighlight();
828} 828}
829 829
830/* Keyboard::timerEvent {{{1 */ 830/* Keyboard::timerEvent {{{1 */
831 831
832/* dont know what this does, but i think it is here so that if your screen 832/* dont know what this does, but i think it is here so that if your screen
833 * sticks (like on an ipaq) then it will stop repeating if you click another 833 * sticks (like on an ipaq) then it will stop repeating if you click another
834 * key... but who knows what anything does in this thing anyway? 834 * key... but who knows what anything does in this thing anyway?
835 835
836 void Keyboard::timerEvent(QTimerEvent* e) 836 void Keyboard::timerEvent(QTimerEvent* e)
837{ 837{
838 if ( e->timerId() == pressTid ) { 838 if ( e->timerId() == pressTid ) {
839 killTimer(pressTid); 839 killTimer(pressTid);
840 pressTid = 0; 840 pressTid = 0;
841 if ( !pressed ) 841 if ( !pressed )
842 cout << "calling clearHighlight from timerEvent\n"; 842 cout << "calling clearHighlight from timerEvent\n";
843 //clearHighlight(); 843 //clearHighlight();
844 } 844 }
845} 845}
846*/ 846*/
847 847
848void Keyboard::repeat() 848void Keyboard::repeat()
849{ 849{
850 850
851 repeatTimer->start( 200 ); 851 repeatTimer->start( 200 );
852 emit key( unicode, qkeycode, modifiers, true, true ); 852 emit key( unicode, qkeycode, modifiers, true, true );
853} 853}
854 854
855void Keyboard::clearHighlight() 855void Keyboard::clearHighlight()
856{ 856{
857 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { 857 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) {
858 int tmpRow = pressedKeyRow; 858 int tmpRow = pressedKeyRow;
859 int tmpCol = pressedKeyCol; 859 int tmpCol = pressedKeyCol;
860 860
861 pressedKeyRow = -1; 861 pressedKeyRow = -1;
862 pressedKeyCol = -1; 862 pressedKeyCol = -1;
863 863
864 QPainter p(this); 864 QPainter p(this);
865 drawKeyboard(p, tmpRow, tmpCol); 865 drawKeyboard(p, tmpRow, tmpCol);
866 } 866 }
867} 867}
868 868
869 869
870/* Keyboard::sizeHint {{{1 */ 870/* Keyboard::sizeHint {{{1 */
871QSize Keyboard::sizeHint() const 871QSize Keyboard::sizeHint() const
872{ 872{
873 QFontMetrics fm=fontMetrics(); 873 QFontMetrics fm=fontMetrics();
874 int keyHeight = fm.lineSpacing() + 2; 874 int keyHeight = fm.lineSpacing() + 2;
875 875
876 return QSize( 240, keyHeight * keys->rows() + (usePicks ? picks->sizeHint().height() : 0) + 1); 876 return QSize( 240, keyHeight * keys->rows() + (usePicks ? picks->sizeHint().height() : 0) + 1);
877} 877}
878 878
879 879
880void Keyboard::resetState() 880void Keyboard::resetState()
881{ 881{
882 if (shift) { *shift = 0; shift = 0; } 882 if (shift) { *shift = 0; shift = 0; }
883 if (lock) {*lock = 0; lock = 0; } 883 if (lock) {*lock = 0; lock = 0; }
884 if (meta) { *meta = 0; meta = 0; } 884 if (meta) { *meta = 0; meta = 0; }
885 if (circumflex) { *circumflex = 0; circumflex = 0; } 885 if (circumflex) { *circumflex = 0; circumflex = 0; }
886 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 886 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
887 if (baccent) { *baccent = 0; baccent = 0; } 887 if (baccent) { *baccent = 0; baccent = 0; }
888 if (accent) { *accent = 0; accent = 0; } 888 if (accent) { *accent = 0; accent = 0; }
889 889
890 schar = mchar = echar = 0; 890 schar = mchar = echar = 0;
891 picks->resetState(); 891 picks->resetState();
892} 892}
893 893
894/* Keyboard::togglePickboard {{{1 */ 894/* Keyboard::togglePickboard {{{1 */
895void Keyboard::togglePickboard(bool on_off) 895void Keyboard::togglePickboard(bool on_off)
896{ 896{
897 usePicks = on_off; 897 usePicks = on_off;
898 if (usePicks) { 898 if (usePicks) {
899 picks->show(); 899 picks->show();
900 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send 900 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send
901 //adjustSize(); 901 //adjustSize();
902 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 902 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
903 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 903 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
904 } else { 904 } else {
905 905
906 picks->hide(); 906 picks->hide();
907 picks->resetState(); 907 picks->resetState();
908 //move(x(), y() + picks->height()); 908 //move(x(), y() + picks->height());
909 //adjustSize(); 909 //adjustSize();
910 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 910 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
911 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 911 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
912 912
913 } 913 }
914 /* 914 /*
915 * this closes && opens the input method 915 * this closes && opens the input method
916 */ 916 */
917 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 917 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
918 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 918 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
919} 919}
920 920
921void Keyboard::toggleRepeat(bool on) { 921void Keyboard::toggleRepeat(bool on) {
922 922
923 useRepeat = on; 923 useRepeat = on;
924 //cout << "setting useRepeat to: " << useRepeat << "\n"; 924 //cout << "setting useRepeat to: " << useRepeat << "\n";
925} 925}
926 926
927void Keyboard::cleanupConfigDlg() { 927void Keyboard::cleanupConfigDlg() {
928 928
929 if ( configdlg ) { 929 if ( configdlg ) {
930 delete configdlg; 930 delete configdlg;
931 configdlg = 0; 931 configdlg = 0;
932 } 932 }
933} 933}
934 934
935void Keyboard::reloadSw() { 935void Keyboard::reloadSw() {
936 QCopEnvelope e("MultiKey/Switcher", "setsw(QString,QString)"); 936 QCopEnvelope e("MultiKey/Switcher", "setsw(QString,QString)");
937 937
938 Config* config = new Config("multikey"); 938 Config* config = new Config("multikey");
939 config->setGroup("keymaps"); 939 config->setGroup("keymaps");
940 QString current_map = config->readEntry("current", "en.keymap"); 940 QString current_map = config->readEntry("current", "en.keymap");
941 delete config; 941 delete config;
942 942
943 e << ConfigDlg::loadSw().join("|") << current_map; 943 e << ConfigDlg::loadSw().join("|") << current_map;
944} 944}
945 945
946/* Keyboard::setMapTo ... {{{1 */ 946/* Keyboard::setMapTo ... {{{1 */
947void Keyboard::setMapToDefault() { 947void Keyboard::setMapToDefault() {
948 948
949 949
950 /* load current locale language map */ 950 /* load current locale language map */
951 Config *config = new Config("locale"); 951 Config *config = new Config("locale");
952 config->setGroup( "Language" ); 952 config->setGroup( "Language" );
953 QString l = config->readEntry( "Language" , "en" ); 953 QString l = config->readEntry( "Language" , "en" );
954 delete config; 954 delete config;
955 955
956 /* if Language represents as en_US, ru_RU, etc... */ 956 /* if Language represents as en_US, ru_RU, etc... */
957 int d = l.find('_'); 957 int d = l.find('_');
958 if (d != -1) { 958 if (d != -1) {
959 l.remove(d, l.length()-d); 959 l.remove(d, l.length()-d);
960 } 960 }
961 QString key_map = QPEApplication::qpeDir() + "share/multikey/" 961 QString key_map = QPEApplication::qpeDir() + "share/multikey/"
962 + l + ".keymap"; 962 + l + ".keymap";
963 963
964 /* save change to multikey config file */ 964 /* save change to multikey config file */
965 config = new Config("multikey"); 965 config = new Config("multikey");
966 config->setGroup ("keymaps"); 966 config->setGroup ("keymaps");
967 config->writeEntry ("current", key_map); // default closed 967 config->writeEntry ("current", key_map); // default closed
968 delete config; 968 delete config;
969 969
970 int prevRows = keys->rows(); 970 int prevRows = keys->rows();
971 971
972 delete keys; 972 delete keys;
973 keys = new Keys(key_map); 973 keys = new Keys(key_map);
974 974
975 // have to repaint the keyboard 975 // have to repaint the keyboard
976 if (prevRows != keys->rows()) { 976 if (prevRows != keys->rows()) {
977 977
978 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 978 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
979 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 979 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
980 980
981 } else repaint(FALSE); 981 } else repaint(FALSE);
982 982
983 resetState(); 983 resetState();
984} 984}
985 985
986void Keyboard::setMapToFile(QString map) { 986void Keyboard::setMapToFile(QString map) {
987 987
988 /* save change to multikey config file */ 988 /* save change to multikey config file */
989 Config *config = new Config("multikey"); 989 Config *config = new Config("multikey");
990 config->setGroup ("keymaps"); 990 config->setGroup ("keymaps");
991 config->writeEntry ("current", map); // default closed 991 config->writeEntry ("current", map); // default closed
992 992
993 delete config; 993 delete config;
994 994
995 int prevRows = keys->rows(); 995 int prevRows = keys->rows();
996 996
997 delete keys; 997 delete keys;
998 if (QFile(map).exists()) 998 if (QFile(map).exists())
999 keys = new Keys(map); 999 keys = new Keys(map);
1000 else 1000 else
1001 keys = new Keys(); 1001 keys = new Keys();
1002 1002
1003 if (keys->rows() != prevRows) { 1003 if (keys->rows() != prevRows) {
1004 1004
1005 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 1005 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
1006 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 1006 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
1007 } 1007 }
1008 else repaint(FALSE); 1008 else repaint(FALSE);
1009 1009
1010 resetState(); 1010 resetState();
1011} 1011}
1012 1012
1013/* Keybaord::reloadKeyboard {{{1 */ 1013/* Keybaord::reloadKeyboard {{{1 */
1014void Keyboard::reloadKeyboard() { 1014void Keyboard::reloadKeyboard() {
1015 1015
1016 // reload colors and redraw 1016 // reload colors and redraw
1017 loadKeyboardColors(); 1017 loadKeyboardColors();
1018 repaint(); 1018 repaint();
1019 1019
1020} 1020}
1021 1021
1022void Keyboard::loadKeyboardColors() { 1022void Keyboard::loadKeyboardColors() {
1023 1023
1024 Config config ("multikey"); 1024 Config config ("multikey");
1025 config.setGroup("colors"); 1025 config.setGroup("colors");
1026 1026
1027 QStringList color; 1027 QStringList color;
1028 color = config.readListEntry("keycolor", QChar(',')); 1028 color = config.readListEntry("keycolor", QChar(','));
1029 if (color.isEmpty()) { 1029 if (color.isEmpty()) {
1030 color = QStringList::split(",", "240,240,240"); 1030 color = QStringList::split(",", "240,240,240");
1031 config.writeEntry("keycolor", color.join(",")); 1031 config.writeEntry("keycolor", color.join(","));
1032 1032
1033 } 1033 }
1034 keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 1034 keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
1035 1035
1036 color = config.readListEntry("keycolor_pressed", QChar(',')); 1036 color = config.readListEntry("keycolor_pressed", QChar(','));
1037 if (color.isEmpty()) { 1037 if (color.isEmpty()) {
1038 color = QStringList::split(",", "171,183,198"); 1038 color = QStringList::split(",", "171,183,198");
1039 config.writeEntry("keycolor_pressed", color.join(",")); 1039 config.writeEntry("keycolor_pressed", color.join(","));
1040 1040
1041 } 1041 }
1042 keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 1042 keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
1043 1043
1044 color = config.readListEntry("keycolor_lines", QChar(',')); 1044 color = config.readListEntry("keycolor_lines", QChar(','));
1045 if (color.isEmpty()) { 1045 if (color.isEmpty()) {
1046 color = QStringList::split(",", "138,148,160"); 1046 color = QStringList::split(",", "138,148,160");
1047 config.writeEntry("keycolor_lines", color.join(",")); 1047 config.writeEntry("keycolor_lines", color.join(","));
1048 1048
1049 } 1049 }
1050 keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 1050 keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
1051 1051
1052 color = config.readListEntry("textcolor", QChar(',')); 1052 color = config.readListEntry("textcolor", QChar(','));
1053 if (color.isEmpty()) { 1053 if (color.isEmpty()) {
1054 color = QStringList::split(",", "43,54,68"); 1054 color = QStringList::split(",", "43,54,68");
1055 config.writeEntry("textcolor", color.join(",")); 1055 config.writeEntry("textcolor", color.join(","));
1056 1056
1057 } 1057 }
1058 textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 1058 textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
1059 1059
1060} 1060}
1061 1061
1062/* korean input functions {{{1 1062/* korean input functions {{{1
1063 * 1063 *
1064 * TODO 1064 * TODO
1065 * one major problem with this implementation is that you can't move the 1065 * one major problem with this implementation is that you can't move the
1066 * cursor after inputing korean chars, otherwise it will eat up and replace 1066 * cursor after inputing korean chars, otherwise it will eat up and replace
1067 * the char before the cursor you move to. fix that 1067 * the char before the cursor you move to. fix that
1068 * 1068 *
1069 * make backspace delete one single char, not the whole thing if still 1069 * make backspace delete one single char, not the whole thing if still
1070 * editing. 1070 * editing.
1071 * 1071 *
1072 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 1072 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1073 * 1073 *
1074 * how korean input works 1074 * how korean input works
1075 * 1075 *
1076 * all following chars means unicode char value and are in hex 1076 * all following chars means unicode char value and are in hex
1077 * 1077 *
1078 * 초음 = schar (start char) 1078 * 초음 = schar (start char)
1079 * 중음 = mchar (middle char) 1079 * 중음 = mchar (middle char)
1080 * 끝음 = echar (end char) 1080 * 끝음 = echar (end char)
1081 * 1081 *
1082 * there are 19 schars. unicode position is at 1100 - 1112 1082 * there are 19 schars. unicode position is at 1100 - 1112
1083 * there are 21 mchars. unicode position is at 1161 - 1175 1083 * there are 21 mchars. unicode position is at 1161 - 1175
1084 * there are 27 echars. unicode position is at 11a8 - 11c2 1084 * there are 27 echars. unicode position is at 11a8 - 11c2
1085 * 1085 *
1086 * the map with everything combined is at ac00 - d7a3 1086 * the map with everything combined is at ac00 - d7a3
1087 * 1087 *
1088 */ 1088 */
1089 1089
1090ushort Keyboard::parseKoreanInput (ushort c) { 1090ushort Keyboard::parseKoreanInput (ushort c) {
1091 1091
1092 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) 1092 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c))
1093 || 1093 ||
1094 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode 1094 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode
1095 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { 1095 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) {
1096 1096
1097 schar = 0, mchar = 0, echar = 0; 1097 schar = 0, mchar = 0, echar = 0;
1098 return c; 1098 return c;
1099 } 1099 }
1100 1100
1101 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input 1101 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input
1102 1102
1103 if (schar == 0 || (schar != 0 && mchar == 0)) { 1103 if (schar == 0 || (schar != 0 && mchar == 0)) {
1104 schar = c; mchar = 0; echar = 0; 1104 schar = c; mchar = 0; echar = 0;
1105 return c; 1105 return c;
1106 } 1106 }
1107 else if (mchar != 0) { 1107 else if (mchar != 0) {
1108 1108
1109 if (echar == 0) { 1109 if (echar == 0) {
1110 1110
1111 if (!(echar = constoe(c))) { 1111 if (!(echar = constoe(c))) {
1112 1112
1113 schar = c; mchar = 0; echar = 0; 1113 schar = c; mchar = 0; echar = 0;
1114 return c; 1114 return c;
1115 } 1115 }
1116 1116
1117 } 1117 }
1118 else { // must figure out what the echar is 1118 else { // must figure out what the echar is
1119 1119
1120 if (echar == 0x11a8) { // ㄱ 1120 if (echar == 0x11a8) { // ㄱ
1121 1121
1122 if (c == 0x1100) echar = 0x11a9; // ㄱ + ㄱ 1122 if (c == 0x1100) echar = 0x11a9; // ㄱ + ㄱ
1123 else if (c == 0x1109) echar = 0x11aa; // ㄱ + ㅅ 1123 else if (c == 0x1109) echar = 0x11aa; // ㄱ + ㅅ
1124 else { 1124 else {
1125 schar = c; mchar = 0; echar = 0; 1125 schar = c; mchar = 0; echar = 0;
1126 return c; 1126 return c;
1127 } 1127 }
1128 1128
1129 } else if (echar == 0x11ab) { // ㄴ 1129 } else if (echar == 0x11ab) { // ㄴ
1130 1130
1131 if (c == 0x110c) echar = 0x11ac; // ㄴ + ㅈ 1131 if (c == 0x110c) echar = 0x11ac; // ㄴ + ㅈ
1132 else if (c == 0x1112) echar = 0x11ad; // ㄴ + ㅎ 1132 else if (c == 0x1112) echar = 0x11ad; // ㄴ + ㅎ
1133 else { 1133 else {
1134 schar = c; mchar = 0; echar = 0; 1134 schar = c; mchar = 0; echar = 0;
1135 return c; 1135 return c;
1136 } 1136 }
1137 1137
1138 } else if (echar == 0x11af) { // ㄹ 1138 } else if (echar == 0x11af) { // ㄹ
1139 1139
1140 if (c == 0x1100) echar = 0x11b0; // ㄹ + ㄱ 1140 if (c == 0x1100) echar = 0x11b0; // ㄹ + ㄱ
1141 else if (c == 0x1106) echar = 0x11b1; // ㄹ + ㅁ 1141 else if (c == 0x1106) echar = 0x11b1; // ㄹ + ㅁ
1142 else if (c == 0x1107) echar = 0x11b2; // ㄹ + ㅂ 1142 else if (c == 0x1107) echar = 0x11b2; // ㄹ + ㅂ
1143 else if (c == 0x1109) echar = 0x11b3; // ㄹ + ㅅ 1143 else if (c == 0x1109) echar = 0x11b3; // ㄹ + ㅅ
1144 else if (c == 0x1110) echar = 0x11b4; // ㄹ + ㅌ 1144 else if (c == 0x1110) echar = 0x11b4; // ㄹ + ㅌ
1145 else if (c == 0x1111) echar = 0x11b5; // ㄹ + ㅍ 1145 else if (c == 0x1111) echar = 0x11b5; // ㄹ + ㅍ
1146 else if (c == 0x1112) echar = 0x11b6; // ㄹ + ㅎ 1146 else if (c == 0x1112) echar = 0x11b6; // ㄹ + ㅎ
1147 else { 1147 else {
1148 schar = c; mchar = 0; echar = 0; 1148 schar = c; mchar = 0; echar = 0;
1149 return c; 1149 return c;
1150 } 1150 }
1151 1151
1152 } else if (echar == 0x11b8) { // ㅂ 1152 } else if (echar == 0x11b8) { // ㅂ
1153 1153
1154 if (c == 0x1109) echar = 0x11b9; // ㅂ + ㅅ 1154 if (c == 0x1109) echar = 0x11b9; // ㅂ + ㅅ
1155 else { 1155 else {
1156 schar = c; mchar = 0; echar = 0; 1156 schar = c; mchar = 0; echar = 0;
1157 return c; 1157 return c;
1158 } 1158 }
1159 1159
1160 } else if (echar == 0x11ba) { // ㅅ 1160 } else if (echar == 0x11ba) { // ㅅ
1161 1161
1162 if (c == 0x1109) echar = 0x11bb; // ㅅ + ㅅ 1162 if (c == 0x1109) echar = 0x11bb; // ㅅ + ㅅ
1163 else { 1163 else {
1164 schar = c; mchar = 0; echar = 0; 1164 schar = c; mchar = 0; echar = 0;
1165 return c; 1165 return c;
1166 } 1166 }
1167 1167
1168 } else { // if any other char, cannot combine chars 1168 } else { // if any other char, cannot combine chars
1169 1169
1170 schar = c; mchar = 0; echar = 0; 1170 schar = c; mchar = 0; echar = 0;
1171 return c; 1171 return c;
1172 } 1172 }
1173 1173
1174 unicode = echar; 1174 unicode = echar;
1175 } 1175 }
1176 } 1176 }
1177 1177
1178 } 1178 }
1179 else if (0x1161 <= c && c <= 0x1175) { // mchar was input 1179 else if (0x1161 <= c && c <= 0x1175) { // mchar was input
1180 1180
1181 if (schar != 0 && mchar == 0) { mchar = c; } 1181 if (schar != 0 && mchar == 0) { mchar = c; }
1182 1182
1183 else if (schar != 0 && mchar != 0 && echar == 0) { 1183 else if (schar != 0 && mchar != 0 && echar == 0) {
1184 1184
1185 switch (mchar) { 1185 switch (mchar) {
1186 case 0x1169: 1186 case 0x1169:
1187 if (c == 0x1161) mchar = 0x116a; 1187 if (c == 0x1161) mchar = 0x116a;
1188 else if (c == 0x1162) mchar = 0x116b; 1188 else if (c == 0x1162) mchar = 0x116b;
1189 else if (c == 0x1175) mchar = 0x116c; 1189 else if (c == 0x1175) mchar = 0x116c;
1190 else { 1190 else {
1191 schar = 0; mchar = 0; echar = 0; 1191 schar = 0; mchar = 0; echar = 0;
1192 return c; 1192 return c;
1193 } 1193 }
1194 break; 1194 break;
1195 case 0x116e: 1195 case 0x116e:
1196 if (c == 0x1165) mchar = 0x116f; 1196 if (c == 0x1165) mchar = 0x116f;
1197 else if (c == 0x1166) mchar = 0x1170; 1197 else if (c == 0x1166) mchar = 0x1170;
1198 else if (c == 0x1175) mchar = 0x1171; 1198 else if (c == 0x1175) mchar = 0x1171;
1199 else { 1199 else {
1200 schar = 0; mchar = 0; echar = 0; 1200 schar = 0; mchar = 0; echar = 0;
1201 return c; 1201 return c;
1202 } 1202 }
1203 break; 1203 break;
1204 case 0x1173: 1204 case 0x1173:
1205 if (c == 0x1175) mchar = 0x1174; 1205 if (c == 0x1175) mchar = 0x1174;
1206 else { 1206 else {
1207 schar = 0; mchar = 0; echar = 0; 1207 schar = 0; mchar = 0; echar = 0;
1208 return c; 1208 return c;
1209 } 1209 }
1210 break; 1210 break;
1211 default: 1211 default:
1212 schar = 0; mchar = 0; echar = 0; 1212 schar = 0; mchar = 0; echar = 0;
1213 return c; 1213 return c;
1214 } 1214 }
1215 } 1215 }
1216 else if (schar != 0 && mchar != 0 && echar != 0) { 1216 else if (schar != 0 && mchar != 0 && echar != 0) {
1217 1217
1218 emit key( 8, Qt::Key_Backspace, 0, true, false ); 1218 emit key( 8, Qt::Key_Backspace, 0, true, false );
1219 1219
1220 ushort prev = 0; 1220 ushort prev = 0;
1221 switch (echar) { 1221 switch (echar) {
1222 /* 1222 /*
1223 case 0x11a9: 1223 case 0x11a9:
1224 prev = combineKoreanChars(schar, mchar, 0x11a8); 1224 prev = combineKoreanChars(schar, mchar, 0x11a8);
1225 schar = 0x1100; 1225 schar = 0x1100;
1226 break; 1226 break;
1227 */ 1227 */
1228 case 0x11aa: 1228 case 0x11aa:
1229 prev = combineKoreanChars(schar, mchar, 0x11a8); 1229 prev = combineKoreanChars(schar, mchar, 0x11a8);
1230 schar = 0x1109; 1230 schar = 0x1109;
1231 break; 1231 break;
1232 case 0x11ac: 1232 case 0x11ac:
1233 prev = combineKoreanChars(schar, mchar, 0x11ab); 1233 prev = combineKoreanChars(schar, mchar, 0x11ab);
1234 schar = 0x110c; 1234 schar = 0x110c;
1235 break; 1235 break;
1236 case 0x11ad: 1236 case 0x11ad:
1237 prev = combineKoreanChars(schar, mchar, 0x11ab); 1237 prev = combineKoreanChars(schar, mchar, 0x11ab);
1238 schar = 0x1112; 1238 schar = 0x1112;
1239 break; 1239 break;
1240 case 0x11b0: 1240 case 0x11b0:
1241 prev = combineKoreanChars(schar, mchar, 0x11af); 1241 prev = combineKoreanChars(schar, mchar, 0x11af);
1242 schar = 0x1100; 1242 schar = 0x1100;
1243 break; 1243 break;
1244 case 0x11b1: 1244 case 0x11b1:
1245 prev = combineKoreanChars(schar, mchar, 0x11af); 1245 prev = combineKoreanChars(schar, mchar, 0x11af);
1246 schar = 0x1106; 1246 schar = 0x1106;
1247 break; 1247 break;
1248 case 0x11b2: 1248 case 0x11b2:
1249 prev = combineKoreanChars(schar, mchar, 0x11af); 1249 prev = combineKoreanChars(schar, mchar, 0x11af);
1250 schar = 0x1107; 1250 schar = 0x1107;
1251 break; 1251 break;
1252 case 0x11b3: 1252 case 0x11b3:
1253 prev = combineKoreanChars(schar, mchar, 0x11af); 1253 prev = combineKoreanChars(schar, mchar, 0x11af);
1254 schar = 0x1109; 1254 schar = 0x1109;
1255 break; 1255 break;
1256 case 0x11b4: 1256 case 0x11b4:
1257 prev = combineKoreanChars(schar, mchar, 0x11af); 1257 prev = combineKoreanChars(schar, mchar, 0x11af);
1258 schar = 0x1110; 1258 schar = 0x1110;
1259 break; 1259 break;
1260 case 0x11b9: 1260 case 0x11b9:
1261 prev = combineKoreanChars(schar, mchar, 0x11b8); 1261 prev = combineKoreanChars(schar, mchar, 0x11b8);
1262 schar = 0x1109; 1262 schar = 0x1109;
1263 break; 1263 break;
1264 /* 1264 /*
1265 case 0x11bb: 1265 case 0x11bb:
1266 prev = combineKoreanChars(schar, mchar, 0x11ba); 1266 prev = combineKoreanChars(schar, mchar, 0x11ba);
1267 schar = 0x1109; 1267 schar = 0x1109;
1268 break; 1268 break;
1269 */ 1269 */
1270 default: 1270 default:
1271 1271
1272 if (constoe(echar)) { 1272 if (constoe(echar)) {
1273 1273
1274 prev = combineKoreanChars(schar, mchar, 0); 1274 prev = combineKoreanChars(schar, mchar, 0);
1275 schar = constoe(echar); 1275 schar = constoe(echar);
1276 } 1276 }
1277 break; 1277 break;
1278 } 1278 }
1279 1279
1280 emit key( prev, prev, 0, true, false ); 1280 emit key( prev, prev, 0, true, false );
1281 1281
1282 mchar = c; echar = 0; 1282 mchar = c; echar = 0;
1283 1283
1284 return combineKoreanChars(schar, mchar, 0); 1284 return combineKoreanChars(schar, mchar, 0);
1285 1285
1286 } 1286 }
1287 else { 1287 else {
1288 schar = 0; mchar = 0; echar = 0; 1288 schar = 0; mchar = 0; echar = 0;
1289 return c; 1289 return c;
1290 } 1290 }
1291 1291
1292 } 1292 }
1293 else /*if (c == ' ')*/ return c; 1293 else /*if (c == ' ')*/ return c;
1294 1294
1295 1295
1296 // and now... finally delete previous char, and return new char 1296 // and now... finally delete previous char, and return new char
1297 emit key( 8, Qt::Key_Backspace, 0, true, false ); 1297 emit key( 8, Qt::Key_Backspace, 0, true, false );
1298 1298
1299 1299
1300 return combineKoreanChars( schar, mchar, echar); 1300 return combineKoreanChars( schar, mchar, echar);
1301 1301
1302} 1302}
1303 1303
1304ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { 1304ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) {
1305 1305
1306 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; 1306 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00;
1307 1307
1308} 1308}
1309 1309
1310ushort Keyboard::constoe(const ushort c) { 1310ushort Keyboard::constoe(const ushort c) {
1311 1311
1312 // converts schars to echars if possible 1312 // converts schars to echars if possible
1313 1313
1314 if (0x1100 <= c && c <= 0x1112) { // schar to echar 1314 if (0x1100 <= c && c <= 0x1112) { // schar to echar
1315 1315
1316 switch (c) { 1316 switch (c) {
1317 case 0x1100: return 0x11a8; 1317 case 0x1100: return 0x11a8;
1318 case 0x1101: return 0x11a9; 1318 case 0x1101: return 0x11a9;
1319 case 0x1102: return 0x11ab; 1319 case 0x1102: return 0x11ab;
1320 case 0x1103: return 0x11ae; 1320 case 0x1103: return 0x11ae;
1321 case 0x1105: return 0x11af; 1321 case 0x1105: return 0x11af;
1322 case 0x1106: return 0x11b7; 1322 case 0x1106: return 0x11b7;
1323 case 0x1107: return 0x11b8; 1323 case 0x1107: return 0x11b8;
1324 case 0x1109: return 0x11ba; 1324 case 0x1109: return 0x11ba;
1325 case 0x110a: return 0x11bb; 1325 case 0x110a: return 0x11bb;
1326 case 0x110b: return 0x11bc; 1326 case 0x110b: return 0x11bc;
1327 case 0x110c: return 0x11bd; 1327 case 0x110c: return 0x11bd;
1328 case 0x110e: return 0x11be; 1328 case 0x110e: return 0x11be;
1329 case 0x110f: return 0x11bf; 1329 case 0x110f: return 0x11bf;
1330 case 0x1110: return 0x11c0; 1330 case 0x1110: return 0x11c0;
1331 case 0x1111: return 0x11c1; 1331 case 0x1111: return 0x11c1;
1332 case 0x1112: return 0x11c2; 1332 case 0x1112: return 0x11c2;
1333 default: return 0; 1333 default: return 0;
1334 1334
1335 } 1335 }
1336 1336
1337 } else { //echar to schar 1337 } else { //echar to schar
1338 1338
1339 switch (c) { 1339 switch (c) {
1340 case 0x11a8: return 0x1100; 1340 case 0x11a8: return 0x1100;
1341 case 0x11a9: return 0x1101; 1341 case 0x11a9: return 0x1101;
1342 case 0x11ab: return 0x1102; 1342 case 0x11ab: return 0x1102;
1343 case 0x11ae: return 0x1103; 1343 case 0x11ae: return 0x1103;
1344 case 0x11af: return 0x1105; 1344 case 0x11af: return 0x1105;
1345 case 0x11b7: return 0x1106; 1345 case 0x11b7: return 0x1106;
1346 case 0x11b8: return 0x1107; 1346 case 0x11b8: return 0x1107;
1347 case 0x11ba: return 0x1109; 1347 case 0x11ba: return 0x1109;
1348 case 0x11bb: return 0x110a; 1348 case 0x11bb: return 0x110a;
1349 case 0x11bc: return 0x110b; 1349 case 0x11bc: return 0x110b;
1350 case 0x11bd: return 0x110c; 1350 case 0x11bd: return 0x110c;
1351 case 0x11be: return 0x110e; 1351 case 0x11be: return 0x110e;
1352 case 0x11bf: return 0x110f; 1352 case 0x11bf: return 0x110f;
1353 case 0x11c0: return 0x1110; 1353 case 0x11c0: return 0x1110;
1354 case 0x11c1: return 0x1111; 1354 case 0x11c1: return 0x1111;
1355 case 0x11c2: return 0x1112; 1355 case 0x11c2: return 0x1112;
1356 default: return 0; 1356 default: return 0;
1357 1357
1358 } 1358 }
1359 1359
1360 } 1360 }
1361} 1361}
1362 1362
1363 1363
1364// Keys::Keys {{{1 1364// Keys::Keys {{{1
1365 1365
1366Keys::Keys() { 1366Keys::Keys() {
1367 1367
1368 Config *config = new Config ("multikey"); 1368 Config *config = new Config ("multikey");
1369 config->setGroup( "keymaps" ); 1369 config->setGroup( "keymaps" );
1370 QString map = config->readEntry( "current" ); 1370 QString map = config->readEntry( "current" );
1371 delete config; 1371 delete config;
1372 1372
1373 if (map.isNull() || !(QFile(map).exists())) { 1373 if (map.isNull() || !(QFile(map).exists())) {
1374 1374
1375 Config *config = new Config("locale"); 1375 Config *config = new Config("locale");
1376 config->setGroup( "Language" ); 1376 config->setGroup( "Language" );
1377 QString l = config->readEntry( "Language" , "en" ); 1377 QString l = config->readEntry( "Language" , "en" );
1378 delete config; 1378 delete config;
1379 1379
1380 map = QPEApplication::qpeDir() + "/share/multikey/" 1380 map = QPEApplication::qpeDir() + "share/multikey/"
1381 + l + ".keymap"; 1381 + l + ".keymap";
1382 1382
1383 } 1383 }
1384 if (map.isNull() || !(QFile(map).exists())) { 1384 if (map.isNull() || !(QFile(map).exists())) {
1385 map = QPEApplication::qpeDir() + "/share/multikey/en.keymap"; 1385 map = QPEApplication::qpeDir() + "share/multikey/en.keymap";
1386 } 1386 }
1387 1387
1388 setKeysFromFile(map); 1388 setKeysFromFile(map);
1389} 1389}
1390 1390
1391Keys::Keys(const char * filename) { 1391Keys::Keys(const char * filename) {
1392 1392
1393 setKeysFromFile(filename); 1393 setKeysFromFile(filename);
1394} 1394}
1395 1395
1396// Keys::setKeysFromFile {{{2 1396// Keys::setKeysFromFile {{{2
1397void Keys::setKeysFromFile(const char * filename) { 1397void Keys::setKeysFromFile(const char * filename) {
1398 1398
1399 QFile f(filename); 1399 QFile f(filename);
1400 1400
1401 if (f.open(IO_ReadOnly)) { 1401 if (f.open(IO_ReadOnly)) {
1402 1402
1403 QTextStream t(&f); 1403 QTextStream t(&f);
1404 int row; 1404 int row;
1405 int qcode; 1405 int qcode;
1406 ushort unicode; 1406 ushort unicode;
1407 int width; 1407 int width;
1408 QString buf; 1408 QString buf;
1409 QString comment; 1409 QString comment;
1410 char * xpm[256]; //couldnt be larger than that... could it? 1410 char * xpm[256]; //couldnt be larger than that... could it?
1411 QImage *xpm2pix = 0; 1411 QImage *xpm2pix = 0;
1412 1412
1413 buf = t.readLine(); 1413 buf = t.readLine();
1414 while (buf) { 1414 while (buf) {
1415 1415
1416 // get rid of comments 1416 // get rid of comments
1417 buf.replace(QRegExp("#.*$", FALSE, FALSE), ""); 1417 buf.replace(QRegExp("#.*$", FALSE, FALSE), "");
1418 1418
1419 // key definition 1419 // key definition
1420 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { 1420 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) {
1421 // no $1 type referencing!!! this implementation of regexp sucks 1421 // no $1 type referencing!!! this implementation of regexp sucks
1422 1422
1423 // dont know of any sscanf() type funcs in Qt lib 1423 // dont know of any sscanf() type funcs in Qt lib
1424 QTextStream tmp (buf, IO_ReadOnly); 1424 QTextStream tmp (buf, IO_ReadOnly);
1425 tmp >> row >> qcode >> unicode >> width >> comment; 1425 tmp >> row >> qcode >> unicode >> width >> comment;
1426 1426
1427 buf = t.readLine(); 1427 buf = t.readLine();
1428 int xpmLineCount = 0; 1428 int xpmLineCount = 0;
1429 xpm2pix = 0; 1429 xpm2pix = 0;
1430 1430
1431 // erase blank space 1431 // erase blank space
1432 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); 1432 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
1433 1433
1434 while (buf.contains(QRegExp("^\\s*\".*\""))) { 1434 while (buf.contains(QRegExp("^\\s*\".*\""))) {
1435 1435
1436 QString xpmBuf = buf.stripWhiteSpace(); 1436 QString xpmBuf = buf.stripWhiteSpace();
1437 1437
1438 xpm[xpmLineCount] = new char [xpmBuf.length()]; 1438 xpm[xpmLineCount] = new char [xpmBuf.length()];
1439 1439
1440 int j = 0; 1440 int j = 0;
1441 for (ushort i = 0; i < xpmBuf.length(); i++) { 1441 for (ushort i = 0; i < xpmBuf.length(); i++) {
1442 if (xpmBuf[i].latin1() != '"') { 1442 if (xpmBuf[i].latin1() != '"') {
1443 1443
1444 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); 1444 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1();
1445 j++; 1445 j++;
1446 } 1446 }
1447 1447
1448 } 1448 }
1449 // have to close that facker up 1449 // have to close that facker up
1450 ((char *)xpm[xpmLineCount])[j] = '\0'; 1450 ((char *)xpm[xpmLineCount])[j] = '\0';
1451 1451
1452 xpmLineCount++; 1452 xpmLineCount++;
1453 buf = t.readLine(); 1453 buf = t.readLine();
1454 } 1454 }
1455 if (xpmLineCount) { 1455 if (xpmLineCount) {
1456 1456
1457 xpm2pix = new QImage((const char **)xpm); 1457 xpm2pix = new QImage((const char **)xpm);
1458 for (int i = 0; i < xpmLineCount; i++) 1458 for (int i = 0; i < xpmLineCount; i++)
1459 1459
1460 delete [] (xpm[i]); 1460 delete [] (xpm[i]);
1461 1461
1462 } 1462 }
1463 setKey(row, qcode, unicode, width, xpm2pix); 1463 setKey(row, qcode, unicode, width, xpm2pix);
1464 } 1464 }
1465 1465
1466 // shift map 1466 // shift map
1467 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1467 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1468 1468
1469 QTextStream tmp (buf, IO_ReadOnly); 1469 QTextStream tmp (buf, IO_ReadOnly);
1470 ushort lower, shift; 1470 ushort lower, shift;
1471 tmp >> lower >> shift; 1471 tmp >> lower >> shift;
1472 1472
1473 shiftMap.insert(lower, shift); 1473 shiftMap.insert(lower, shift);
1474 1474
1475 buf = t.readLine(); 1475 buf = t.readLine();
1476 } 1476 }
1477 1477
1478 // meta key map 1478 // meta key map
1479 else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1479 else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1480 1480
1481 QTextStream tmp (buf, IO_ReadOnly); 1481 QTextStream tmp (buf, IO_ReadOnly);
1482 ushort lower, shift; 1482 ushort lower, shift;
1483 QChar m; 1483 QChar m;
1484 tmp >> m >> lower >> shift; 1484 tmp >> m >> lower >> shift;
1485 1485
1486 metaMap.insert(lower, shift); 1486 metaMap.insert(lower, shift);
1487 1487
1488 buf = t.readLine(); 1488 buf = t.readLine();
1489 } 1489 }
1490 1490
1491 // circumflex 1491 // circumflex
1492 else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1492 else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1493 1493
1494 QTextStream tmp (buf, IO_ReadOnly); 1494 QTextStream tmp (buf, IO_ReadOnly);
1495 ushort lower, shift; 1495 ushort lower, shift;
1496 QChar c; 1496 QChar c;
1497 tmp >> c >> lower >> shift; 1497 tmp >> c >> lower >> shift;
1498 1498
1499 circumflexMap.insert(lower, shift); 1499 circumflexMap.insert(lower, shift);
1500 1500
1501 buf = t.readLine(); 1501 buf = t.readLine();
1502 } 1502 }
1503 // diaeresis 1503 // diaeresis
1504 else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1504 else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1505 1505
1506 QTextStream tmp (buf, IO_ReadOnly); 1506 QTextStream tmp (buf, IO_ReadOnly);
1507 ushort lower, shift; 1507 ushort lower, shift;
1508 QChar d; 1508 QChar d;
1509 tmp >> d >> lower >> shift; 1509 tmp >> d >> lower >> shift;
1510 1510
1511 diaeresisMap.insert(lower, shift); 1511 diaeresisMap.insert(lower, shift);
1512 1512
1513 buf = t.readLine(); 1513 buf = t.readLine();
1514 } 1514 }
1515 // back accent 1515 // back accent
1516 else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1516 else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1517 1517
1518 QTextStream tmp (buf, IO_ReadOnly); 1518 QTextStream tmp (buf, IO_ReadOnly);
1519 ushort lower, shift; 1519 ushort lower, shift;
1520 QChar d; 1520 QChar d;
1521 tmp >> d >> lower >> shift; 1521 tmp >> d >> lower >> shift;
1522 1522
1523 baccentMap.insert(lower, shift); 1523 baccentMap.insert(lower, shift);
1524 1524
1525 qDebug ("Estoy aadiendo %i con %i", lower, shift); 1525 qDebug ("Estoy aadiendo %i con %i", lower, shift);
1526 buf = t.readLine(); 1526 buf = t.readLine();
1527 } 1527 }
1528 // accent 1528 // accent
1529 else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1529 else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1530 1530
1531 QTextStream tmp (buf, IO_ReadOnly); 1531 QTextStream tmp (buf, IO_ReadOnly);
1532 ushort lower, shift; 1532 ushort lower, shift;
1533 QChar d; 1533 QChar d;
1534 tmp >> d >> lower >> shift; 1534 tmp >> d >> lower >> shift;
1535 1535
1536 accentMap.insert(lower, shift); 1536 accentMap.insert(lower, shift);
1537 1537
1538 buf = t.readLine(); 1538 buf = t.readLine();
1539 } 1539 }
1540 1540
1541 // other variables like lang & title & sw 1541 // other variables like lang & title & sw
1542 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { 1542 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) {
1543 1543
1544 QTextStream tmp (buf, IO_ReadOnly); 1544 QTextStream tmp (buf, IO_ReadOnly);
1545 QString name, equals, value; 1545 QString name, equals, value;
1546 1546
1547 tmp >> name >> equals >> value; 1547 tmp >> name >> equals >> value;
1548 1548
1549 if (name == "lang") { 1549 if (name == "lang") {
1550 1550
1551 lang = value; 1551 lang = value;
1552 1552
1553 } 1553 }
1554 1554
1555 buf = t.readLine(); 1555 buf = t.readLine();
1556 } 1556 }
1557 // comments 1557 // comments
1558 else if (buf.contains(QRegExp("^\\s*#"))) { 1558 else if (buf.contains(QRegExp("^\\s*#"))) {
1559 1559
1560 buf = t.readLine(); 1560 buf = t.readLine();
1561 1561
1562 } else { // blank line, or garbage 1562 } else { // blank line, or garbage
1563 1563
1564 buf = t.readLine(); 1564 buf = t.readLine();
1565 1565
1566 } 1566 }
1567 1567
1568 } 1568 }
1569 1569
1570 f.close(); 1570 f.close();
1571 } else { 1571 } else {
1572 // We couldnt find the selected keymap, give them a configure button 1572 // We couldnt find the selected keymap, give them a configure button
1573 QImage * btn = new QImage((const char ** )kb_config_xpm); 1573 QImage * btn = new QImage((const char ** )kb_config_xpm);
1574 setKey(1, 0x1030, 0, 2, btn); 1574 setKey(1, 0x1030, 0, 2, btn);
1575 } 1575 }
1576 1576
1577} 1577}
1578 1578
1579 1579
1580// Keys::setKey {{{2 1580// Keys::setKey {{{2
1581void Keys::setKey(const int row, const int qcode, const ushort unicode, 1581void Keys::setKey(const int row, const int qcode, const ushort unicode,
1582 const int width, QImage *pix) { 1582 const int width, QImage *pix) {
1583 1583
1584 Key * key; 1584 Key * key;
1585 key = new Key; 1585 key = new Key;
1586 key->qcode = qcode; 1586 key->qcode = qcode;
1587 key->unicode = unicode; 1587 key->unicode = unicode;
1588 key->width = width; 1588 key->width = width;
1589 1589
1590 // share key->pressed between same keys 1590 // share key->pressed between same keys
1591 bool found = 0; 1591 bool found = 0;
1592 for (int i = 1; i <= 5; i++) { 1592 for (int i = 1; i <= 5; i++) {
1593 for (unsigned int j = 0; j < keys[i].count(); j++) 1593 for (unsigned int j = 0; j < keys[i].count(); j++)
1594 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { 1594 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) {
1595 1595
1596 key->pressed = keys[i].at(j)->pressed; 1596 key->pressed = keys[i].at(j)->pressed;
1597 found = 1; 1597 found = 1;
1598 } 1598 }
1599 1599
1600 } 1600 }
1601 if (!found) { 1601 if (!found) {
1602 1602
1603 key->pressed = new bool; 1603 key->pressed = new bool;
1604 *(key->pressed) = 0; 1604 *(key->pressed) = 0;
1605 } 1605 }
1606 1606
1607 key->pix = pix; 1607 key->pix = pix;
1608 1608
1609 1609
1610 keys[row].append(key); 1610 keys[row].append(key);
1611} 1611}
1612 1612
1613// Keys::~Keys {{{2 1613// Keys::~Keys {{{2
1614Keys::~Keys() { 1614Keys::~Keys() {
1615 1615
1616 for (int i = 1; i <= 5; i++) 1616 for (int i = 1; i <= 5; i++)
1617 for (unsigned int j = 0; j < keys[i].count(); j++) 1617 for (unsigned int j = 0; j < keys[i].count(); j++)
1618 delete keys[i].at(j); 1618 delete keys[i].at(j);
1619 1619
1620} 1620}
1621 1621
1622// Keys:: other functions {{{2 1622// Keys:: other functions {{{2
1623int Keys::width(const int row, const int col) { 1623int Keys::width(const int row, const int col) {
1624 1624
1625 return keys[row].at(col)->width; 1625 return keys[row].at(col)->width;
1626 1626
1627} 1627}
1628 1628
1629int Keys::rows() { 1629int Keys::rows() {
1630 1630
1631 for (int i = 1; i <= 5; i++) { 1631 for (int i = 1; i <= 5; i++) {
1632 1632
1633 if (keys[i].count() == 0) 1633 if (keys[i].count() == 0)
1634 return i - 1; 1634 return i - 1;
1635 1635
1636 } 1636 }
1637 return 5; 1637 return 5;
1638} 1638}
1639 1639
1640ushort Keys::uni(const int row, const int col) { 1640ushort Keys::uni(const int row, const int col) {
1641 1641
1642 return keys[row].at(col)->unicode; 1642 return keys[row].at(col)->unicode;
1643 1643
1644} 1644}
1645 1645
1646int Keys::qcode(const int row, const int col) { 1646int Keys::qcode(const int row, const int col) {
1647 1647
1648 return keys[row].at(col)->qcode; 1648 return keys[row].at(col)->qcode;
1649} 1649}
1650 1650
1651QImage *Keys::pix(const int row, const int col) { 1651QImage *Keys::pix(const int row, const int col) {
1652 1652
1653 return keys[row].at(col)->pix; 1653 return keys[row].at(col)->pix;
1654 1654
1655} 1655}
1656bool Keys::pressed(const int row, const int col) { 1656bool Keys::pressed(const int row, const int col) {
1657 1657
1658 return *(keys[row].at(col)->pressed); 1658 return *(keys[row].at(col)->pressed);
1659} 1659}
1660 1660
1661int Keys::numKeys(const int row) { 1661int Keys::numKeys(const int row) {
1662 1662
1663 return keys[row].count(); 1663 return keys[row].count();
1664} 1664}
1665 1665
1666void Keys::setPressed(const int row, const int col, const bool pressed) { 1666void Keys::setPressed(const int row, const int col, const bool pressed) {
1667 1667
1668 *(keys[row].at(col)->pressed) = pressed; 1668 *(keys[row].at(col)->pressed) = pressed;
1669} 1669}
1670 1670
1671ushort Keys::shift(const ushort uni) { 1671ushort Keys::shift(const ushort uni) {
1672 1672
1673 if (shiftMap[uni]) return shiftMap[uni]; 1673 if (shiftMap[uni]) return shiftMap[uni];
1674 else return 0; 1674 else return 0;
1675} 1675}
1676 1676
1677ushort Keys::meta(const ushort uni) { 1677ushort Keys::meta(const ushort uni) {
1678 1678
1679 if (metaMap[uni]) return metaMap[uni]; 1679 if (metaMap[uni]) return metaMap[uni];
1680 else return 0; 1680 else return 0;
1681} 1681}
1682 1682
1683ushort Keys::circumflex(const ushort uni) { 1683ushort Keys::circumflex(const ushort uni) {
1684 1684
1685 if (circumflexMap[uni]) return circumflexMap[uni]; 1685 if (circumflexMap[uni]) return circumflexMap[uni];
1686 else return 0; 1686 else return 0;
1687} 1687}
1688 1688
1689ushort Keys::diaeresis(const ushort uni) { 1689ushort Keys::diaeresis(const ushort uni) {
1690 1690
1691 if(diaeresisMap[uni]) return diaeresisMap[uni]; 1691 if(diaeresisMap[uni]) return diaeresisMap[uni];
1692 else return 0; 1692 else return 0;
1693} 1693}
1694 1694
1695ushort Keys::baccent(const ushort uni) { 1695ushort Keys::baccent(const ushort uni) {
1696 1696
1697 if(baccentMap[uni]) return baccentMap[uni]; 1697 if(baccentMap[uni]) return baccentMap[uni];
1698 else return 0; 1698 else return 0;
1699} 1699}
1700 1700
1701ushort Keys::accent(const ushort uni) { 1701ushort Keys::accent(const ushort uni) {
1702 1702
1703 if(accentMap[uni]) return accentMap[uni]; 1703 if(accentMap[uni]) return accentMap[uni];
1704 else return 0; 1704 else return 0;
1705} 1705}
1706 1706
1707bool *Keys::pressedPtr(const int row, const int col) { 1707bool *Keys::pressedPtr(const int row, const int col) {
1708 1708
1709 return keys[row].at(col)->pressed; 1709 return keys[row].at(col)->pressed;
1710} 1710}
diff --git a/libopie2/opiecore/opluginloader.cpp b/libopie2/opiecore/opluginloader.cpp
index 2a6e369..d33eac6 100644
--- a/libopie2/opiecore/opluginloader.cpp
+++ b/libopie2/opiecore/opluginloader.cpp
@@ -1,905 +1,905 @@
1/* 1/*
2 * LGPLv2 or later 2 * LGPLv2 or later
3 * zecke@handhelds.org 3 * zecke@handhelds.org
4 */ 4 */
5 5
6#include "opluginloader.h" 6#include "opluginloader.h"
7#include "oconfig.h" 7#include "oconfig.h"
8#include "odebug.h" 8#include "odebug.h"
9 9
10#include <qpe/qpeapplication.h> 10#include <qpe/qpeapplication.h>
11 11
12#include <qdir.h> 12#include <qdir.h>
13#include <qdict.h> 13#include <qdict.h>
14#include <qtl.h> 14#include <qtl.h>
15#include <qfile.h> 15#include <qfile.h>
16 16
17#include <stdlib.h> 17#include <stdlib.h>
18 18
19 19
20 20
21namespace Opie { 21namespace Opie {
22namespace Core { 22namespace Core {
23namespace Internal { 23namespace Internal {
24struct OPluginLibraryHolder { 24struct OPluginLibraryHolder {
25 static OPluginLibraryHolder *self(); 25 static OPluginLibraryHolder *self();
26 QLibrary *ref( const QString& ); 26 QLibrary *ref( const QString& );
27 void deref( QLibrary* ); 27 void deref( QLibrary* );
28private: 28private:
29 29
30 OPluginLibraryHolder(); 30 OPluginLibraryHolder();
31 ~OPluginLibraryHolder(); 31 ~OPluginLibraryHolder();
32 QDict<QLibrary> m_libs; 32 QDict<QLibrary> m_libs;
33 static OPluginLibraryHolder* m_self; 33 static OPluginLibraryHolder* m_self;
34}; 34};
35 35
36 OPluginLibraryHolder* OPluginLibraryHolder::m_self = 0; 36 OPluginLibraryHolder* OPluginLibraryHolder::m_self = 0;
37 OPluginLibraryHolder* OPluginLibraryHolder::self() { 37 OPluginLibraryHolder* OPluginLibraryHolder::self() {
38 if ( !m_self ) 38 if ( !m_self )
39 m_self = new OPluginLibraryHolder; 39 m_self = new OPluginLibraryHolder;
40 40
41 return m_self; 41 return m_self;
42 } 42 }
43 43
44 OPluginLibraryHolder::OPluginLibraryHolder() {} 44 OPluginLibraryHolder::OPluginLibraryHolder() {}
45 OPluginLibraryHolder::~OPluginLibraryHolder() {} 45 OPluginLibraryHolder::~OPluginLibraryHolder() {}
46 46
47 /* 47 /*
48 * We do simple ref counting... We will add the QLibrary again 48 * We do simple ref counting... We will add the QLibrary again
49 * and again to the dictionary and on deref we will pop and pop it 49 * and again to the dictionary and on deref we will pop and pop it
50 * until there are no more library and we will unload and delete the library 50 * until there are no more library and we will unload and delete the library
51 * luckily dlopen does some ref counting as well so we don't need 51 * luckily dlopen does some ref counting as well so we don't need
52 * to hack QPEApplication 52 * to hack QPEApplication
53 */ 53 */
54 QLibrary* OPluginLibraryHolder::ref(const QString& str) { 54 QLibrary* OPluginLibraryHolder::ref(const QString& str) {
55 QLibrary *lib = m_libs[str]; 55 QLibrary *lib = m_libs[str];
56 56
57 /* if not in the dict try to load it */ 57 /* if not in the dict try to load it */
58 if ( !lib ) { 58 if ( !lib ) {
59 lib = new QLibrary( str, QLibrary::Immediately ); 59 lib = new QLibrary( str, QLibrary::Immediately );
60 if ( !lib->isLoaded() ) { 60 if ( !lib->isLoaded() ) {
61 delete lib; 61 delete lib;
62 return 0l; 62 return 0l;
63 } 63 }
64 } 64 }
65 65
66 /* now refcount one up */ 66 /* now refcount one up */
67 m_libs.insert( str, lib ); 67 m_libs.insert( str, lib );
68 return lib; 68 return lib;
69 } 69 }
70 70
71 /* 71 /*
72 * 'unshadow' the items until we're the last then unload and delete 72 * 'unshadow' the items until we're the last then unload and delete
73 */ 73 */
74 void OPluginLibraryHolder::deref( QLibrary* lib ) { 74 void OPluginLibraryHolder::deref( QLibrary* lib ) {
75 if ( !lib ) 75 if ( !lib )
76 return; 76 return;
77 77
78 QString str = lib->library(); 78 QString str = lib->library();
79 /* no need to check if the lib was inserted or such */ 79 /* no need to check if the lib was inserted or such */
80 (void) m_libs.take( str ); 80 (void) m_libs.take( str );
81 if ( !m_libs[str] ) { 81 if ( !m_libs[str] ) {
82 lib->unload(); 82 lib->unload();
83 delete lib; 83 delete lib;
84 } 84 }
85 } 85 }
86} 86}
87 87
88/** 88/**
89 * We want values with 30,29,28 at the beginning of the list 89 * We want values with 30,29,28 at the beginning of the list
90 */ 90 */
91 91
92bool operator<( const OPluginItem& l, const OPluginItem& r ) { 92bool operator<( const OPluginItem& l, const OPluginItem& r ) {
93 return l.position() > r.position(); 93 return l.position() > r.position();
94} 94}
95 95
96bool operator>( const OPluginItem& l, const OPluginItem& r ) { 96bool operator>( const OPluginItem& l, const OPluginItem& r ) {
97 return l.position() < r.position(); 97 return l.position() < r.position();
98} 98}
99 99
100bool operator<=( const OPluginItem& l, const OPluginItem& r ) { 100bool operator<=( const OPluginItem& l, const OPluginItem& r ) {
101 return l.position() >= r.position(); 101 return l.position() >= r.position();
102} 102}
103 103
104/** 104/**
105 * \brief Creates an Empty OPluginItem 105 * \brief Creates an Empty OPluginItem
106 * 106 *
107 * create an empty pluginitem. Position is set to -1 and the 107 * create an empty pluginitem. Position is set to -1 and the
108 * other things are used with the default ctors 108 * other things are used with the default ctors
109 */ 109 */
110OPluginItem::OPluginItem() 110OPluginItem::OPluginItem()
111 : m_pos( -1 ) { 111 : m_pos( -1 ) {
112} 112}
113 113
114/** 114/**
115 * @todo Create Internal name so we can have the plugin names translated. Or only for the gui? I'm not yet sure 115 * @todo Create Internal name so we can have the plugin names translated. Or only for the gui? I'm not yet sure
116 * \brief Create an OPluginItem 116 * \brief Create an OPluginItem
117 * 117 *
118 * Create a Plugin Item with all information. If you for some reasons 118 * Create a Plugin Item with all information. If you for some reasons
119 * need to create your own OPluginItems make sure that 'name' is always the same 119 * need to create your own OPluginItems make sure that 'name' is always the same
120 * as it if used for positions and exclude list. 120 * as it if used for positions and exclude list.
121 * 121 *
122 * @param name The if available translated Name 122 * @param name The if available translated Name
123 * @param path The path to the plugin must be absolute. 123 * @param path The path to the plugin must be absolute.
124 * @param b If the OPluginItem is enabled or not 124 * @param b If the OPluginItem is enabled or not
125 * @param pos The position of the plugin if used for sorting 125 * @param pos The position of the plugin if used for sorting
126 * 126 *
127 */ 127 */
128OPluginItem::OPluginItem( const QString& name, const QString& path, bool b, int pos ) 128OPluginItem::OPluginItem( const QString& name, const QString& path, bool b, int pos )
129 : m_name( name ), m_path( path ), m_enabled( b ), m_pos( pos ) 129 : m_name( name ), m_path( path ), m_enabled( b ), m_pos( pos )
130{} 130{}
131 131
132/** 132/**
133 * \brief simple d'tor 133 * \brief simple d'tor
134 */ 134 */
135OPluginItem::~OPluginItem() { 135OPluginItem::~OPluginItem() {
136} 136}
137 137
138/** 138/**
139 * \brief Test if this Item is Empty and does not represent a loadable plugin 139 * \brief Test if this Item is Empty and does not represent a loadable plugin
140 * Test if a OPluginItem is empty. A OPluginItem is empty if name and path are empty 140 * Test if a OPluginItem is empty. A OPluginItem is empty if name and path are empty
141 * ,pos equals -1 and the item is disabled 141 * ,pos equals -1 and the item is disabled
142 * 142 *
143 * @see QString::isEmpty() 143 * @see QString::isEmpty()
144 * 144 *
145 */ 145 */
146bool OPluginItem::isEmpty()const { 146bool OPluginItem::isEmpty()const {
147 if ( m_pos != -1 ) return false; 147 if ( m_pos != -1 ) return false;
148 if ( m_enabled ) return false; 148 if ( m_enabled ) return false;
149 if ( !m_name.isEmpty() ) return false; 149 if ( !m_name.isEmpty() ) return false;
150 if ( !m_path.isEmpty() ) return false; 150 if ( !m_path.isEmpty() ) return false;
151 151
152 return true; 152 return true;
153} 153}
154 154
155/** 155/**
156 * \brief test equality 156 * \brief test equality
157 * operator to test equalness of two OPluginItem 157 * operator to test equalness of two OPluginItem
158 */ 158 */
159bool OPluginItem::operator==( const OPluginItem& r )const{ 159bool OPluginItem::operator==( const OPluginItem& r )const{
160 if ( m_pos != r.m_pos ) return false; 160 if ( m_pos != r.m_pos ) return false;
161 if ( m_enabled != r.m_enabled) return false; 161 if ( m_enabled != r.m_enabled) return false;
162 if ( m_name != r.m_name ) return false; 162 if ( m_name != r.m_name ) return false;
163 if ( m_path != r.m_path ) return false; 163 if ( m_path != r.m_path ) return false;
164 return true; 164 return true;
165} 165}
166 166
167/** 167/**
168 * \brief test non equality 168 * \brief test non equality
169 * operator to test non-equalness of two OPluginItem 169 * operator to test non-equalness of two OPluginItem
170 */ 170 */
171bool OPluginItem::operator!=( const OPluginItem& r )const{ 171bool OPluginItem::operator!=( const OPluginItem& r )const{
172 return !( *this == r ); 172 return !( *this == r );
173} 173}
174 174
175/** 175/**
176 * \brief returns the name of the plugin 176 * \brief returns the name of the plugin
177 * return the name of this Plugin 177 * return the name of this Plugin
178 */ 178 */
179QString OPluginItem::name()const { 179QString OPluginItem::name()const {
180 return m_name; 180 return m_name;
181} 181}
182 182
183/** 183/**
184 * \brief return the path of the plugin 184 * \brief return the path of the plugin
185 */ 185 */
186QString OPluginItem::path()const { 186QString OPluginItem::path()const {
187 return m_path; 187 return m_path;
188} 188}
189 189
190/** 190/**
191 * \brief Return if this item is enabled. 191 * \brief Return if this item is enabled.
192 */ 192 */
193bool OPluginItem::isEnabled()const { 193bool OPluginItem::isEnabled()const {
194 return m_enabled; 194 return m_enabled;
195} 195}
196 196
197/** 197/**
198 * \brief return the position of a plugin. 198 * \brief return the position of a plugin.
199 * return the position of the item 199 * return the position of the item
200 * -1 is the default value and means normally that the whole items are unsorted. 200 * -1 is the default value and means normally that the whole items are unsorted.
201 * Higher numbers belong to an upper position. With plugins with the postions 20,19,5,3 201 * Higher numbers belong to an upper position. With plugins with the postions 20,19,5,3
202 * the item with pos 20 would be the first in the list returned by the OGenericPluginLoader 202 * the item with pos 20 would be the first in the list returned by the OGenericPluginLoader
203 * 203 *
204 * @see OGenericPluginLoader::allAvailable 204 * @see OGenericPluginLoader::allAvailable
205 * @see OGenericPluginLoader::filtered 205 * @see OGenericPluginLoader::filtered
206 */ 206 */
207int OPluginItem::position()const{ 207int OPluginItem::position()const{
208 return m_pos; 208 return m_pos;
209} 209}
210 210
211/** 211/**
212 * \brief set the name of a plugin 212 * \brief set the name of a plugin
213 * Set the name of the Plugin Item 213 * Set the name of the Plugin Item
214 * @param name 214 * @param name
215 */ 215 */
216void OPluginItem::setName( const QString& name ) { 216void OPluginItem::setName( const QString& name ) {
217 m_name = name; 217 m_name = name;
218} 218}
219 219
220/** 220/**
221 * \brief set the path of a plugin 221 * \brief set the path of a plugin
222 * Set the path of Plugin Item. The path must be absolute. 222 * Set the path of Plugin Item. The path must be absolute.
223 * @param name The path of the plugin 223 * @param name The path of the plugin
224 */ 224 */
225void OPluginItem::setPath( const QString& name ) { 225void OPluginItem::setPath( const QString& name ) {
226 m_path = name; 226 m_path = name;
227} 227}
228 228
229/** 229/**
230 * \brief enable or disable the to load attribute 230 * \brief enable or disable the to load attribute
231 * Set the Enabled attribute. Such changes won't be saved. If you want to save it 231 * Set the Enabled attribute. Such changes won't be saved. If you want to save it
232 * use a OPluginManager to configure your plugins manually or Opie::Ui::OPluginConfig 232 * use a OPluginManager to configure your plugins manually or Opie::Ui::OPluginConfig
233 * for a graphical frontend. 233 * for a graphical frontend.
234 * 234 *
235 * @param enabled Enable or Disable the Enabled Attribute 235 * @param enabled Enable or Disable the Enabled Attribute
236 */ 236 */
237void OPluginItem::setEnabled( bool enabled ) { 237void OPluginItem::setEnabled( bool enabled ) {
238 m_enabled = enabled; 238 m_enabled = enabled;
239} 239}
240 240
241/** 241/**
242 * \brief Set the position. 242 * \brief Set the position.
243 * Set the position 243 * Set the position
244 * @param pos The position 244 * @param pos The position
245 * 245 *
246 * @see position() 246 * @see position()
247 */ 247 */
248void OPluginItem::setPosition( int pos ) { 248void OPluginItem::setPosition( int pos ) {
249 m_pos = pos; 249 m_pos = pos;
250} 250}
251 251
252 252
253 253
254/** 254/**
255 * \brief create a PluginLoader 255 * \brief create a PluginLoader
256 * 256 *
257 * Create a PluginLoader autoDelete is set to false 257 * Create a PluginLoader autoDelete is set to false
258 * 258 *
259 * \code 259 * \code
260 * Opie::Core::OGenericPluginLoader loader("myapp-plugin"); 260 * Opie::Core::OGenericPluginLoader loader("myapp-plugin");
261 * Opie::Core::OPluginItem::List lst = loader.filtered(); 261 * Opie::Core::OPluginItem::List lst = loader.filtered();
262 * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){ 262 * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){
263 * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface)); 263 * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface));
264 * } 264 * }
265 * \endcode 265 * \endcode
266 * 266 *
267 * \code 267 * \code
268 * Opie::Core::OGenericPluginLoader loader("myapp-plugin"); 268 * Opie::Core::OGenericPluginLoader loader("myapp-plugin");
269 * Opie::Core::OPluginItem::List lst = loader.filtered(); 269 * Opie::Core::OPluginItem::List lst = loader.filtered();
270 * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){ 270 * for(Opie::Core::OPluginItem::List::Iterator it = lst.begin(); it!=lst.end();++it){
271 * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface)); 271 * MyIface* iface = static_cast<MyIface*>(loader.load(*it,IID_MyIface));
272 * } 272 * }
273 * ... 273 * ...
274 * loader.clear(); 274 * loader.clear();
275 * 275 *
276 * \endcode 276 * \endcode
277 * 277 *
278 * @param name The name of the plugin directory. 278 * @param name The name of the plugin directory.
279 * @param isSorted Tell the PluginLoader if your Plugins are sorted 279 * @param isSorted Tell the PluginLoader if your Plugins are sorted
280 */ 280 */
281OGenericPluginLoader::OGenericPluginLoader( const QString& name, bool isSorted) 281OGenericPluginLoader::OGenericPluginLoader( const QString& name, bool isSorted)
282 : m_dir( name ), m_autoDelete( false ), m_isSafeMode( false ), 282 : m_dir( name ), m_autoDelete( false ), m_isSafeMode( false ),
283 m_isSorted( isSorted ) 283 m_isSorted( isSorted )
284{ 284{
285 setPluginDir( QPEApplication::qpeDir() + "plugins/"+name ); 285 setPluginDir( QPEApplication::qpeDir() + "plugins/"+name );
286 readConfig(); 286 readConfig();
287} 287}
288 288
289 289
290/** 290/**
291 * \brief simple d'tor that cleans up depending on autoDelete 291 * \brief simple d'tor that cleans up depending on autoDelete
292 * 292 *
293 * calls clear if autoDelete is true. This will release all interfaces 293 * calls clear if autoDelete is true. This will release all interfaces
294 * and remove the library from this process if the refcount falls to zero 294 * and remove the library from this process if the refcount falls to zero
295 */ 295 */
296OGenericPluginLoader::~OGenericPluginLoader() { 296OGenericPluginLoader::~OGenericPluginLoader() {
297 if ( m_autoDelete ) 297 if ( m_autoDelete )
298 clear(); 298 clear();
299} 299}
300 300
301/** 301/**
302 * \brief Enable or disable autoDelete on destruction 302 * \brief Enable or disable autoDelete on destruction
303 * 303 *
304 * enable autoDelete. This will call clear on the d'tor 304 * enable autoDelete. This will call clear on the d'tor
305 * 305 *
306 * @see ~OGenericPluginLoader 306 * @see ~OGenericPluginLoader
307 * @see clear() 307 * @see clear()
308 */ 308 */
309void OGenericPluginLoader::setAutoDelete( bool t ) { 309void OGenericPluginLoader::setAutoDelete( bool t ) {
310 m_autoDelete = t; 310 m_autoDelete = t;
311} 311}
312 312
313/** 313/**
314 * \brief See if autoDelete is enabled. 314 * \brief See if autoDelete is enabled.
315 */ 315 */
316bool OGenericPluginLoader::autoDelete()const{ 316bool OGenericPluginLoader::autoDelete()const{
317 return m_autoDelete; 317 return m_autoDelete;
318} 318}
319 319
320/** 320/**
321 * \brief unload all loaded Plugins 321 * \brief unload all loaded Plugins
322 * 322 *
323 * This will unload all returned QUnknownInterfaces by load. Unload 323 * This will unload all returned QUnknownInterfaces by load. Unload
324 * will be called. 324 * will be called.
325 */ 325 */
326void OGenericPluginLoader::clear() { 326void OGenericPluginLoader::clear() {
327 QPtrDictIterator<QLibrary> it( m_library ); 327 QPtrDictIterator<QLibrary> it( m_library );
328 for ( ;it.current(); ) 328 for ( ;it.current(); )
329 unload( static_cast<QUnknownInterface*>( it.currentKey() ) ); 329 unload( static_cast<QUnknownInterface*>( it.currentKey() ) );
330} 330}
331 331
332/** 332/**
333 * \brief unload the Plugin and the accompanied Resources. 333 * \brief unload the Plugin and the accompanied Resources.
334 * 334 *
335 * This will take the iface from the internal QPtrDict, Release it, 335 * This will take the iface from the internal QPtrDict, Release it,
336 * and deref the libray used. 336 * and deref the libray used.
337 * The visibility depends on the QPtrDict. 337 * The visibility depends on the QPtrDict.
338 * @see QPtrDict::insert 338 * @see QPtrDict::insert
339 */ 339 */
340void OGenericPluginLoader::unload( QUnknownInterface* iface ) { 340void OGenericPluginLoader::unload( QUnknownInterface* iface ) {
341 if ( !iface ) 341 if ( !iface )
342 return; 342 return;
343 343
344 iface->release(); 344 iface->release();
345 Internal::OPluginLibraryHolder::self()->deref( m_library.take( iface ) ); 345 Internal::OPluginLibraryHolder::self()->deref( m_library.take( iface ) );
346} 346}
347 347
348/** 348/**
349 * \brief The name of the plugins. 349 * \brief The name of the plugins.
350 * 350 *
351 * Return the name/type you specified in the constructor. 351 * Return the name/type you specified in the constructor.
352 * This is at least used by the OPluginManager to find the right config 352 * This is at least used by the OPluginManager to find the right config
353 */ 353 */
354QString OGenericPluginLoader::name()const { 354QString OGenericPluginLoader::name()const {
355 return m_dir; 355 return m_dir;
356} 356}
357 357
358 358
359/** 359/**
360 * \brief See if loading of a plugin segfaulted 360 * \brief See if loading of a plugin segfaulted
361 * This tells you 361 * This tells you
362 * if by previous tries to load, loading crashed your application. 362 * if by previous tries to load, loading crashed your application.
363 * If isInSafeMode you can use the GUI to configure the plugins prior to loading 363 * If isInSafeMode you can use the GUI to configure the plugins prior to loading
364 * 364 *
365 * @return true if prior loading failed 365 * @return true if prior loading failed
366 */ 366 */
367bool OGenericPluginLoader::isInSafeMode()const { 367bool OGenericPluginLoader::isInSafeMode()const {
368 return m_isSafeMode; 368 return m_isSafeMode;
369} 369}
370 370
371 371
372/** 372/**
373 * \brief Return all Plugins found in the plugins dirs. 373 * \brief Return all Plugins found in the plugins dirs.
374 * Return the list of all available plugins. This will go through all plugin 374 * Return the list of all available plugins. This will go through all plugin
375 * directories and search for your type of plugins ( by subdir ) 375 * directories and search for your type of plugins ( by subdir )
376 * 376 *
377 * @param sorted Tell if you want to have the positions sorted. This only makes sense if you 377 * @param sorted Tell if you want to have the positions sorted. This only makes sense if you
378 */ 378 */
379OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const { 379OPluginItem::List OGenericPluginLoader::allAvailable( bool sorted )const {
380 OPluginItem::List lst; 380 OPluginItem::List lst;
381 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) 381 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it )
382 lst += plugins( *it, sorted, false ); 382 lst += plugins( *it, sorted, false );
383 383
384 if ( sorted ) 384 if ( sorted )
385 qHeapSort( lst ); 385 qHeapSort( lst );
386 return lst; 386 return lst;
387} 387}
388 388
389/** 389/**
390 * \brief Return only the enabled plugins 390 * \brief Return only the enabled plugins
391 * Return only activated plugins. 391 * Return only activated plugins.
392 * 392 *
393 * @param sorted If the list should be sorted 393 * @param sorted If the list should be sorted
394 */ 394 */
395OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const { 395OPluginItem::List OGenericPluginLoader::filtered( bool sorted )const {
396 OPluginItem::List lst; 396 OPluginItem::List lst;
397 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it ) 397 for ( QStringList::ConstIterator it = m_plugDirs.begin(); it != m_plugDirs.end(); ++it )
398 lst += plugins( *it, sorted, true ); 398 lst += plugins( *it, sorted, true );
399 399
400 if ( sorted ) 400 if ( sorted )
401 qHeapSort( lst ); 401 qHeapSort( lst );
402 return lst; 402 return lst;
403} 403}
404 404
405 405
406/** 406/**
407 * \brief Load a OPluginItem for the specified interface 407 * \brief Load a OPluginItem for the specified interface
408 * This will open the resource of the OPluginItem::path() and then will query 408 * This will open the resource of the OPluginItem::path() and then will query
409 * if the Interface specified in the uuid is available and then will manage the 409 * if the Interface specified in the uuid is available and then will manage the
410 * resource and Interface. 410 * resource and Interface.
411 * 411 *
412 * @param item The OPluginItem that should be loaded 412 * @param item The OPluginItem that should be loaded
413 * @param uuid The Interface to query for 413 * @param uuid The Interface to query for
414 * 414 *
415 * @return Either 0 in case of failure or the Plugin as QUnknownInterface* 415 * @return Either 0 in case of failure or the Plugin as QUnknownInterface*
416 */ 416 */
417QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) { 417QUnknownInterface* OGenericPluginLoader::load( const OPluginItem& item, const QUuid& uuid) {
418 /* 418 /*
419 * Check if there could be a library 419 * Check if there could be a library
420 */ 420 */
421 QString pa = item.path(); 421 QString pa = item.path();
422 if ( pa.isEmpty() ) 422 if ( pa.isEmpty() )
423 return 0l; 423 return 0l;
424 424
425 /* 425 /*
426 * See if we get a library 426 * See if we get a library
427 * return if we've none 427 * return if we've none
428 */ 428 */
429 setSafeMode( pa, true ); 429 setSafeMode( pa, true );
430 QLibrary *lib = Internal::OPluginLibraryHolder::self()->ref( pa ); 430 QLibrary *lib = Internal::OPluginLibraryHolder::self()->ref( pa );
431 if ( !lib ) { 431 if ( !lib ) {
432 setSafeMode(); 432 setSafeMode();
433 return 0l; 433 return 0l;
434 } 434 }
435 435
436 /** 436 /**
437 * try to load the plugin and just in case initialize the pointer to a pointer again 437 * try to load the plugin and just in case initialize the pointer to a pointer again
438 */ 438 */
439 QUnknownInterface* iface=0; 439 QUnknownInterface* iface=0;
440 if ( lib->queryInterface( uuid, &iface ) == QS_OK ) { 440 if ( lib->queryInterface( uuid, &iface ) == QS_OK ) {
441 installTranslators( item.name() ); 441 installTranslators( item.name() );
442 m_library.insert( iface, lib ); 442 m_library.insert( iface, lib );
443 }else 443 }else
444 iface = 0; 444 iface = 0;
445 445
446 setSafeMode(); 446 setSafeMode();
447 447
448 return iface; 448 return iface;
449} 449}
450 450
451/** 451/**
452 * @internal and reads in the safe mode 452 * @internal and reads in the safe mode
453 */ 453 */
454void OGenericPluginLoader::readConfig() { 454void OGenericPluginLoader::readConfig() {
455 455
456 456
457/* read the config for SafeMode */ 457/* read the config for SafeMode */
458 OConfig conf( m_dir + "-odpplugins" ); 458 OConfig conf( m_dir + "-odpplugins" );
459 conf.setGroup( "General" ); 459 conf.setGroup( "General" );
460 m_isSafeMode = conf.readBoolEntry( "SafeMode", false ); 460 m_isSafeMode = conf.readBoolEntry( "SafeMode", false );
461} 461}
462 462
463/** 463/**
464 * @internal Enter or leave SafeMode 464 * @internal Enter or leave SafeMode
465 */ 465 */
466void OGenericPluginLoader::setSafeMode(const QString& str, bool b) { 466void OGenericPluginLoader::setSafeMode(const QString& str, bool b) {
467 OConfig conf( m_dir + "-odpplugins" ); 467 OConfig conf( m_dir + "-odpplugins" );
468 conf.setGroup( "General" ); 468 conf.setGroup( "General" );
469 conf.writeEntry( "SafeMode", b ); 469 conf.writeEntry( "SafeMode", b );
470 conf.writeEntry( "CrashedPlugin", str ); 470 conf.writeEntry( "CrashedPlugin", str );
471} 471}
472 472
473/** 473/**
474 * @internal 474 * @internal
475 * 475 *
476 * Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"/plugins/"+mytype 476 * Set the List of Plugin Dirs to lst. Currently only QPEApplication::qpeDir()+"plugins/"+mytype
477 * is used as plugin dir 477 * is used as plugin dir
478 */ 478 */
479void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) { 479void OGenericPluginLoader::setPluginDirs( const QStringList& lst ) {
480 m_plugDirs = lst; 480 m_plugDirs = lst;
481} 481}
482 482
483/** 483/**
484 * 484 *
485 * @internal 485 * @internal
486 * Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs 486 * Set the Plugin Dir to str. Str will be the only element in the list of plugin dirs
487 */ 487 */
488void OGenericPluginLoader::setPluginDir( const QString& str) { 488void OGenericPluginLoader::setPluginDir( const QString& str) {
489 m_plugDirs.clear(); 489 m_plugDirs.clear();
490 m_plugDirs.append( str ); 490 m_plugDirs.append( str );
491} 491}
492 492
493 493
494/** 494/**
495 * @internal 495 * @internal
496 */ 496 */
497bool OGenericPluginLoader::isSorted()const{ 497bool OGenericPluginLoader::isSorted()const{
498 return m_isSorted; 498 return m_isSorted;
499} 499}
500 500
501/* 501/*
502 * make libfoo.so.1.0.0 -> foo on UNIX 502 * make libfoo.so.1.0.0 -> foo on UNIX
503 * make libfoo.dylib -> foo on MAC OS X Unix 503 * make libfoo.dylib -> foo on MAC OS X Unix
504 * windows is obviously missing 504 * windows is obviously missing
505 */ 505 */
506/** 506/**
507 * @internal 507 * @internal
508 */ 508 */
509QString OGenericPluginLoader::unlibify( const QString& str ) { 509QString OGenericPluginLoader::unlibify( const QString& str ) {
510 QString st = str.mid( str.find( "lib" )+3 ); 510 QString st = str.mid( str.find( "lib" )+3 );
511#ifdef Q_OS_MACX 511#ifdef Q_OS_MACX
512 return st.left( st.findRev( ".dylib" ) ); 512 return st.left( st.findRev( ".dylib" ) );
513#else 513#else
514 return st.left( st.findRev( ".so" ) ); 514 return st.left( st.findRev( ".so" ) );
515#endif 515#endif
516} 516}
517 517
518/** 518/**
519 * @internal 519 * @internal
520 * 520 *
521 * \brief method to return available plugins. Internal and for reeimplementations 521 * \brief method to return available plugins. Internal and for reeimplementations
522 * 522 *
523 *Return a List of Plugins for a dir and add positions and remove disabled. 523 *Return a List of Plugins for a dir and add positions and remove disabled.
524 * If a plugin is on the excluded list assign position -2 524 * If a plugin is on the excluded list assign position -2
525 * 525 *
526 * @param _dir The dir to look in 526 * @param _dir The dir to look in
527 * @param sorted Should positions be read? 527 * @param sorted Should positions be read?
528 * @param disabled Remove excluded from the list 528 * @param disabled Remove excluded from the list
529 */ 529 */
530OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const { 530OPluginItem::List OGenericPluginLoader::plugins( const QString& _dir, bool sorted, bool disabled )const {
531#ifdef Q_OS_MACX 531#ifdef Q_OS_MACX
532 QDir dir( _dir, "lib*.dylib" ); 532 QDir dir( _dir, "lib*.dylib" );
533#else 533#else
534 QDir dir( _dir, "lib*.so" ); 534 QDir dir( _dir, "lib*.so" );
535#endif 535#endif
536 536
537 537
538 OPluginItem::List lst; 538 OPluginItem::List lst;
539 539
540 /* 540 /*
541 * get excluded list and then iterate over them 541 * get excluded list and then iterate over them
542 * Excluded list contains the name 542 * Excluded list contains the name
543 * Position is a list with 'name.pos.name.pos.name.pos' 543 * Position is a list with 'name.pos.name.pos.name.pos'
544 * 544 *
545 * For the look up we will create two QMap<QString,pos> 545 * For the look up we will create two QMap<QString,pos>
546 */ 546 */
547 QMap<QString, int> positionMap; 547 QMap<QString, int> positionMap;
548 QMap<QString, int> excludedMap; 548 QMap<QString, int> excludedMap;
549 549
550 550
551 OConfig cfg( m_dir+"-odpplugins" ); 551 OConfig cfg( m_dir+"-odpplugins" );
552 cfg.setGroup( _dir ); 552 cfg.setGroup( _dir );
553 553
554 554
555 QStringList excludes = cfg.readListEntry( "Excluded", ',' ); 555 QStringList excludes = cfg.readListEntry( "Excluded", ',' );
556 for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it ) 556 for ( QStringList::Iterator it = excludes.begin(); it != excludes.end(); ++it )
557 excludedMap.insert( *it, -2 ); 557 excludedMap.insert( *it, -2 );
558 558
559 if ( sorted ) { 559 if ( sorted ) {
560 QStringList pos = cfg.readListEntry( "Positions", '.' ); 560 QStringList pos = cfg.readListEntry( "Positions", '.' );
561 QStringList::Iterator it = pos.begin(); 561 QStringList::Iterator it = pos.begin();
562 QString tmp; int i; 562 QString tmp; int i;
563 while ( it != pos.end() ) { 563 while ( it != pos.end() ) {
564 tmp = *it++; i = (*it++).toInt(); 564 tmp = *it++; i = (*it++).toInt();
565 positionMap.insert( tmp, i ); 565 positionMap.insert( tmp, i );
566 } 566 }
567 567
568 } 568 }
569 569
570 570
571 571
572 572
573 QStringList list = dir.entryList(); 573 QStringList list = dir.entryList();
574 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { 574 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
575 QString str = unlibify( *it ); 575 QString str = unlibify( *it );
576 OPluginItem item( str, _dir + "/" + *it ); 576 OPluginItem item( str, _dir + "/" + *it );
577 577
578 bool ex = excludedMap.contains( str ); 578 bool ex = excludedMap.contains( str );
579 /* 579 /*
580 * if disabled but we should show all mark it as disabled 580 * if disabled but we should show all mark it as disabled
581 * else continue because we don't want to add the item 581 * else continue because we don't want to add the item
582 * else if sorted we assign the right position 582 * else if sorted we assign the right position
583 */ 583 */
584 if ( ex && !disabled) 584 if ( ex && !disabled)
585 item.setEnabled( false ); 585 item.setEnabled( false );
586 else if ( ex && disabled ) 586 else if ( ex && disabled )
587 continue; 587 continue;
588 else if ( sorted ) 588 else if ( sorted )
589 item.setPosition( positionMap[str] ); 589 item.setPosition( positionMap[str] );
590 590
591 591
592 lst.append( item ); 592 lst.append( item );
593 } 593 }
594 594
595 return lst; 595 return lst;
596} 596}
597 597
598/** 598/**
599 * @internal generate a list of languages from $LANG 599 * @internal generate a list of languages from $LANG
600 */ 600 */
601QStringList OGenericPluginLoader::languageList() { 601QStringList OGenericPluginLoader::languageList() {
602 if ( m_languages.isEmpty() ) { 602 if ( m_languages.isEmpty() ) {
603 /* 603 /*
604 * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be 604 * be_BY.CP1251 We will add, be_BY.CP1251,be_BY,be
605 * to our list of languages. 605 * to our list of languages.
606 * Also for de_DE@euro we will add de_DE@eurp, de_DE, de 606 * Also for de_DE@euro we will add de_DE@eurp, de_DE, de
607 * to our list of languages 607 * to our list of languages
608 */ 608 */
609 QString str = ::getenv( "LANG" ); 609 QString str = ::getenv( "LANG" );
610 m_languages += str; 610 m_languages += str;
611 int pos = str.find( '@' ); 611 int pos = str.find( '@' );
612 if( pos > 0 ) 612 if( pos > 0 )
613 m_languages += str.left( pos ); 613 m_languages += str.left( pos );
614 614
615 615
616 pos = str.find( '.' ); 616 pos = str.find( '.' );
617 if ( pos > 0 ) 617 if ( pos > 0 )
618 m_languages += str.left( pos ); 618 m_languages += str.left( pos );
619 619
620 int n_pos = str.find( '_' ); 620 int n_pos = str.find( '_' );
621 if ( n_pos > 0 ) 621 if ( n_pos > 0 )
622 m_languages += str.left( n_pos ); 622 m_languages += str.left( n_pos );
623 623
624 } 624 }
625 return m_languages; 625 return m_languages;
626} 626}
627 627
628/** 628/**
629 * @internal 629 * @internal
630 * Tries to install languages using the languageList for the type 630 * Tries to install languages using the languageList for the type
631 */ 631 */
632void OGenericPluginLoader::installTranslators(const QString& type) { 632void OGenericPluginLoader::installTranslators(const QString& type) {
633 QStringList lst = languageList(); 633 QStringList lst = languageList();
634 634
635 /* 635 /*
636 * for each language and maybe later for each language dir... 636 * for each language and maybe later for each language dir...
637 * try to load a Translator 637 * try to load a Translator
638 */ 638 */
639 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { 639 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
640 QTranslator* trans = new QTranslator( qApp ); 640 QTranslator* trans = new QTranslator( qApp );
641 QString tfn = QPEApplication::qpeDir()+"/i18n/" + *it + "/lib" + type + ".qm" ; 641 QString tfn = QPEApplication::qpeDir()+"i18n/" + *it + "/lib" + type + ".qm" ;
642 642
643 /* 643 /*
644 * If loaded then install else clean up and don't leak 644 * If loaded then install else clean up and don't leak
645 */ 645 */
646 if ( trans->load( tfn ) ) 646 if ( trans->load( tfn ) )
647 qApp->installTranslator( trans ); 647 qApp->installTranslator( trans );
648 else 648 else
649 delete trans; 649 delete trans;
650 } 650 }
651} 651}
652 652
653/** 653/**
654 * \brief Simple c'tor. 654 * \brief Simple c'tor.
655 * 655 *
656 * Simple C'tor same as the one of the base class. Additional this 656 * Simple C'tor same as the one of the base class. Additional this
657 * class can cast for you if you nee it. 657 * class can cast for you if you nee it.
658 * 658 *
659 * 659 *
660 * @param name The name of your plugin class 660 * @param name The name of your plugin class
661 * @param sorted If plugins are sorted 661 * @param sorted If plugins are sorted
662 * 662 *
663 * @see OGenericPluginLoader 663 * @see OGenericPluginLoader
664 */ 664 */
665OPluginLoader::OPluginLoader( const QString& name, bool sorted ) 665OPluginLoader::OPluginLoader( const QString& name, bool sorted )
666 : OGenericPluginLoader( name, sorted ) 666 : OGenericPluginLoader( name, sorted )
667{ 667{
668} 668}
669 669
670/** 670/**
671 * d'tor 671 * d'tor
672 * @see OGenericPluginLoader::~OGenericPluginLoader 672 * @see OGenericPluginLoader::~OGenericPluginLoader
673 */ 673 */
674OPluginLoader::~OPluginLoader() { 674OPluginLoader::~OPluginLoader() {
675} 675}
676 676
677/** 677/**
678 * \brief C'Tor using a OGenericPluginLoader 678 * \brief C'Tor using a OGenericPluginLoader
679 * The C'tor. Pass your OGenericPluginLoader to manage 679 * The C'tor. Pass your OGenericPluginLoader to manage
680 * OGenericPluginLoader::allAvailable plugins. 680 * OGenericPluginLoader::allAvailable plugins.
681 * 681 *
682 * 682 *
683 * @param loader A Pointer to your OGenericPluginLoader 683 * @param loader A Pointer to your OGenericPluginLoader
684 */ 684 */
685OPluginManager::OPluginManager( OGenericPluginLoader* loader) 685OPluginManager::OPluginManager( OGenericPluginLoader* loader)
686 : m_loader( loader ), m_isSorted( false ) 686 : m_loader( loader ), m_isSorted( false )
687{ 687{
688} 688}
689 689
690/** 690/**
691 * \brief Overloaded c'tor using a List of Plugins and a type name 691 * \brief Overloaded c'tor using a List of Plugins and a type name
692 * Overloaded Constructor to work with a 'Type' of plugins 692 * Overloaded Constructor to work with a 'Type' of plugins
693 * and a correspending list of those. In this case calling load 693 * and a correspending list of those. In this case calling load
694 * is a no operation. 694 * is a no operation.
695 * 695 *
696 * @param name The name of your plugin ('today','inputmethods','applets') 696 * @param name The name of your plugin ('today','inputmethods','applets')
697 * @param lst A List with plugins of your type to manage 697 * @param lst A List with plugins of your type to manage
698 * @param isSorted If the List should be treated sorted 698 * @param isSorted If the List should be treated sorted
699 */ 699 */
700OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted) 700OPluginManager::OPluginManager( const QString& name, const OPluginItem::List& lst, bool isSorted)
701 : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted ) 701 : m_loader( 0l ), m_cfgName( name ), m_plugins( lst ), m_isSorted( isSorted )
702{ 702{
703} 703}
704 704
705/** 705/**
706 * \brief A simple d'tor 706 * \brief A simple d'tor
707 */ 707 */
708OPluginManager::~OPluginManager() { 708OPluginManager::~OPluginManager() {
709} 709}
710 710
711/** 711/**
712 * \brief Return the OPluginItem where loading is likely to have crashed on. 712 * \brief Return the OPluginItem where loading is likely to have crashed on.
713 713
714 * Return the Item that made the OGenericPluginLoader crash 714 * Return the Item that made the OGenericPluginLoader crash
715 * the returned OPluginItem could be empty if no crash occured 715 * the returned OPluginItem could be empty if no crash occured
716 * which should apply most of the time. It could also be empty if the crashed 716 * which should apply most of the time. It could also be empty if the crashed
717 * plugin is not in the current list of available/managed plugins 717 * plugin is not in the current list of available/managed plugins
718 * 718 *
719 * @see OPluginItem::isEmpty 719 * @see OPluginItem::isEmpty
720 * @return OPluginItem that crashed the loader 720 * @return OPluginItem that crashed the loader
721 */ 721 */
722OPluginItem OPluginManager::crashedPlugin()const { 722OPluginItem OPluginManager::crashedPlugin()const {
723 return m_crashed; 723 return m_crashed;
724} 724}
725 725
726/** 726/**
727 * \brief Return a list of plugins that are managed by this OPluginManager 727 * \brief Return a list of plugins that are managed by this OPluginManager
728 * 728 *
729 * Return the list of managed plugins. This could either result 729 * Return the list of managed plugins. This could either result
730 * from passing a OGenericPluginLoader and calling load or by 730 * from passing a OGenericPluginLoader and calling load or by
731 * giving name and a list of plugins. 731 * giving name and a list of plugins.
732 */ 732 */
733OPluginItem::List OPluginManager::managedPlugins()const { 733OPluginItem::List OPluginManager::managedPlugins()const {
734 return m_plugins; 734 return m_plugins;
735} 735}
736 736
737/** 737/**
738 * \brief Set the position of the items 738 * \brief Set the position of the items
739 * 739 *
740 * Replace the OPluginItem with the name and path and this way 740 * Replace the OPluginItem with the name and path and this way
741 * apply the new position. The search is linear and this way O(n/2) 741 * apply the new position. The search is linear and this way O(n/2)
742 * You still need to call save() to make your changes effective. After saving 742 * You still need to call save() to make your changes effective. After saving
743 * a call to OGenericPluginLoader::filtered() returns the newly configured order and items 743 * a call to OGenericPluginLoader::filtered() returns the newly configured order and items
744 * 744 *
745 * @param item The OPluginItem to be replaced internall 745 * @param item The OPluginItem to be replaced internall
746 * 746 *
747 */ 747 */
748void OPluginManager::setPosition( const OPluginItem& item) { 748void OPluginManager::setPosition( const OPluginItem& item) {
749 replace( item ); 749 replace( item );
750} 750}
751 751
752/** 752/**
753 * \brief Enable the item specified as argument 753 * \brief Enable the item specified as argument
754 * 754 *
755 * This will make sure that OPluginItem::setEnabled is called and then will replace 755 * This will make sure that OPluginItem::setEnabled is called and then will replace
756 * the item with one that matches name and path internally. 756 * the item with one that matches name and path internally.
757 * @see setPosition 757 * @see setPosition
758 * 758 *
759 * @param item the Item to enable 759 * @param item the Item to enable
760 */ 760 */
761void OPluginManager::enable( const OPluginItem& item ) { 761void OPluginManager::enable( const OPluginItem& item ) {
762 setEnabled( item, true ); 762 setEnabled( item, true );
763} 763}
764 764
765/** 765/**
766 * \brief disable the Item. 766 * \brief disable the Item.
767 * 767 *
768 * Disable the OPluginItem. Same applies as in 768 * Disable the OPluginItem. Same applies as in
769 * @see setPosition and @see enable 769 * @see setPosition and @see enable
770 * 770 *
771 * @param item Item to disable 771 * @param item Item to disable
772 */ 772 */
773void OPluginManager::disable( const OPluginItem& item) { 773void OPluginManager::disable( const OPluginItem& item) {
774 setEnabled( item, false ); 774 setEnabled( item, false );
775} 775}
776 776
777/** 777/**
778 * \brief Enable or disable the OPluginItem. 778 * \brief Enable or disable the OPluginItem.
779 * Depending on the value of the parameter this will either disable 779 * Depending on the value of the parameter this will either disable
780 * or enable the pluginitem. 780 * or enable the pluginitem.
781 * Beside that same as in @see disable, @see enable, @see setPosition 781 * Beside that same as in @see disable, @see enable, @see setPosition
782 * applies. 782 * applies.
783 * 783 *
784 * @param _item The OPluginItem to enable or to disable. 784 * @param _item The OPluginItem to enable or to disable.
785 * @param b Enable or disable the plugin. 785 * @param b Enable or disable the plugin.
786 * 786 *
787 */ 787 */
788void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) { 788void OPluginManager::setEnabled( const OPluginItem& _item, bool b ) {
789 OPluginItem item = _item; 789 OPluginItem item = _item;
790 item.setEnabled( b ); 790 item.setEnabled( b );
791 replace( item ); 791 replace( item );
792} 792}
793 793
794/** 794/**
795 * \brief Load necessary information after constructing the object 795 * \brief Load necessary information after constructing the object
796 * If you speified a OGenericPluginLoader you need to call this method 796 * If you speified a OGenericPluginLoader you need to call this method
797 * so that this manager knows what to manage and have a right value for \sa crashedPlugin 797 * so that this manager knows what to manage and have a right value for \sa crashedPlugin
798 * For the name and the list of plugins this does only try to find out the crashed plugin 798 * For the name and the list of plugins this does only try to find out the crashed plugin
799 */ 799 */
800void OPluginManager::load() { 800void OPluginManager::load() {
801 OConfig cfg( configName() ); 801 OConfig cfg( configName() );
802 cfg.setGroup( "General" ); 802 cfg.setGroup( "General" );
803 QString crashedPath = cfg.readEntry( "CrashedPlugin" ); 803 QString crashedPath = cfg.readEntry( "CrashedPlugin" );
804 804
805 /* if we've a loader this applies if we were called from the first part */ 805 /* if we've a loader this applies if we were called from the first part */
806 if ( m_loader ) 806 if ( m_loader )
807 m_plugins = m_loader->allAvailable( m_loader->isSorted() ); 807 m_plugins = m_loader->allAvailable( m_loader->isSorted() );
808 808
809 /* fast and normal route if we did not crash... */ 809 /* fast and normal route if we did not crash... */
810 if ( crashedPath.isEmpty() ) 810 if ( crashedPath.isEmpty() )
811 return; 811 return;
812 812
813 /* lets try to find the plugin path and this way the associated item */ 813 /* lets try to find the plugin path and this way the associated item */
814 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) 814 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it )
815 if ( (*it).path() == crashedPath ) { 815 if ( (*it).path() == crashedPath ) {
816 m_crashed = *it; 816 m_crashed = *it;
817 break; 817 break;
818 } 818 }
819} 819}
820 820
821 821
822/** 822/**
823 * \brief Save the values and this way make it available. 823 * \brief Save the values and this way make it available.
824 * 824 *
825 * Save the current set of data. A call to @see OGenericPluginLoader::filtered 825 * Save the current set of data. A call to @see OGenericPluginLoader::filtered
826 * now would return your saved changes. 826 * now would return your saved changes.
827 */ 827 */
828void OPluginManager::save() { 828void OPluginManager::save() {
829 QMap<QString, QStringList> excluded; // map for path to excluded name 829 QMap<QString, QStringList> excluded; // map for path to excluded name
830 QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs 830 QMap<QString, QStringList> positions; // if positions matter contains splitted up by dirs
831 bool sorted = m_loader ? m_loader->isSorted() : m_isSorted; 831 bool sorted = m_loader ? m_loader->isSorted() : m_isSorted;
832 832
833 /* 833 /*
834 * We will create some maps for the groups to include positions a 834 * We will create some maps for the groups to include positions a
835 */ 835 */
836 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) { 836 for ( OPluginItem::List::Iterator it = m_plugins.begin(); it != m_plugins.end(); ++it ) {
837 OPluginItem item = *it; 837 OPluginItem item = *it;
838 QString path = QFileInfo( item.path() ).dirPath(true); 838 QString path = QFileInfo( item.path() ).dirPath(true);
839 if ( sorted ) { 839 if ( sorted ) {
840 positions[path].append( item.name() ); 840 positions[path].append( item.name() );
841 positions[path].append( QString::number( item.position() ) ); 841 positions[path].append( QString::number( item.position() ) );
842 } 842 }
843 843
844 if ( !item.isEnabled() ) 844 if ( !item.isEnabled() )
845 excluded[path].append( item.name() ); 845 excluded[path].append( item.name() );
846 if ( !excluded.contains( path ) ) 846 if ( !excluded.contains( path ) )
847 excluded[path] = QString::null; 847 excluded[path] = QString::null;
848 848
849 } 849 }
850 850
851/* 851/*
852 * The code below wouldn't work because we can't delete groups/keys from the config 852 * The code below wouldn't work because we can't delete groups/keys from the config
853 * ### for ODP make Config right! 853 * ### for ODP make Config right!
854 */ 854 */
855// if ( excluded.isEmpty() && positions.isEmpty() ) return; 855// if ( excluded.isEmpty() && positions.isEmpty() ) return;
856 /* 856 /*
857 * Now safe for each path 857 * Now safe for each path
858 */ 858 */
859 OConfig cfg( configName() ); 859 OConfig cfg( configName() );
860 860
861 /* safe excluded items */ 861 /* safe excluded items */
862 for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) { 862 for ( QMap<QString, QStringList>::Iterator it = excluded.begin(); it != excluded.end(); ++it ) {
863 OConfigGroupSaver saver( &cfg, it.key() ); 863 OConfigGroupSaver saver( &cfg, it.key() );
864 cfg.writeEntry("Excluded", it.data(), ',' ); 864 cfg.writeEntry("Excluded", it.data(), ',' );
865 } 865 }
866 866
867 /* safe positions we could also see if positions.contains(path) and remove/write in the above loop 867 /* safe positions we could also see if positions.contains(path) and remove/write in the above loop
868 * ### Write a Test Suite that can profile these runs... 868 * ### Write a Test Suite that can profile these runs...
869 */ 869 */
870 for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) { 870 for ( QMap<QString, QStringList>::Iterator it = positions.begin(); it != positions.end(); ++it ) {
871 OConfigGroupSaver saver( &cfg, it.key() ); 871 OConfigGroupSaver saver( &cfg, it.key() );
872 cfg.writeEntry("Positions", it.data(), '.' ); 872 cfg.writeEntry("Positions", it.data(), '.' );
873 } 873 }
874} 874}
875 875
876/** 876/**
877 * @internal 877 * @internal
878 */ 878 */
879QString OPluginManager::configName()const { 879QString OPluginManager::configName()const {
880 QString str = m_loader ? m_loader->name() : m_cfgName; 880 QString str = m_loader ? m_loader->name() : m_cfgName;
881 return str + "-odpplugins"; 881 return str + "-odpplugins";
882} 882}
883 883
884/** 884/**
885 * @internal.. replace in m_plugins by path... this is linear search O(n/2) 885 * @internal.. replace in m_plugins by path... this is linear search O(n/2)
886 */ 886 */
887void OPluginManager::replace( const OPluginItem& item ) { 887void OPluginManager::replace( const OPluginItem& item ) {
888 OPluginItem _item; 888 OPluginItem _item;
889 889
890 /* for all plugins */ 890 /* for all plugins */
891 for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) { 891 for ( OPluginItem::List::Iterator it=m_plugins.begin();it != m_plugins.end(); ++it ) {
892 _item = *it; 892 _item = *it;
893 /* if path and name are the same we will remove, readd and return */ 893 /* if path and name are the same we will remove, readd and return */
894 if ( _item.path() == item.path() && 894 if ( _item.path() == item.path() &&
895 _item.name() == item.name() ) { 895 _item.name() == item.name() ) {
896 it = m_plugins.remove( it ); 896 it = m_plugins.remove( it );
897 m_plugins.append( item ); 897 m_plugins.append( item );
898 return; 898 return;
899 } 899 }
900 900
901 } 901 }
902} 902}
903 903
904} 904}
905} 905}
diff --git a/libopie2/opienet/omanufacturerdb.cpp b/libopie2/opienet/omanufacturerdb.cpp
index 32bae0a..7e185a2 100644
--- a/libopie2/opienet/omanufacturerdb.cpp
+++ b/libopie2/opienet/omanufacturerdb.cpp
@@ -1,143 +1,143 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. 4 .=l.
5 .>+-= 5 .>+-=
6_;:, .> :=|. This program is free software; you can 6_;:, .> :=|. This program is free software; you can
7.> <`_, > . <= redistribute it and/or modify it under 7.> <`_, > . <= redistribute it and/or modify it under
8:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 8:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
9.="- .-=="i, .._ License as published by the Free Software 9.="- .-=="i, .._ License as published by the Free Software
10- . .-<_> .<> Foundation; either version 2 of the License, 10- . .-<_> .<> Foundation; either version 2 of the License,
11 ._= =} : or (at your option) any later version. 11 ._= =} : or (at your option) any later version.
12 .%`+i> _;_. 12 .%`+i> _;_.
13 .i_,=:_. -<s. This program is distributed in the hope that 13 .i_,=:_. -<s. This program is distributed in the hope that
14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
15 : .. .:, . . . without even the implied warranty of 15 : .. .:, . . . without even the implied warranty of
16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.= = ; Library General Public License for more 18..}^=.= = ; Library General Public License for more
19++= -. .` .: details. 19++= -. .` .: details.
20: = ...= . :.=- 20: = ...= . :.=-
21-. .:....=;==+<; You should have received a copy of the GNU 21-. .:....=;==+<; You should have received a copy of the GNU
22 -_. . . )=. = Library General Public License along with 22 -_. . . )=. = Library General Public License along with
23 -- :-=` this library; see the file COPYING.LIB. 23 -- :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27*/ 27*/
28 28
29#include "omanufacturerdb.h" 29#include "omanufacturerdb.h"
30 30
31#define OPIE_IMPROVE_GUI_LATENCY 1 31#define OPIE_IMPROVE_GUI_LATENCY 1
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35#include <qpe/qpeapplication.h> 35#include <qpe/qpeapplication.h>
36#ifdef OPIE_IMPROVE_GUI_LATENCY 36#ifdef OPIE_IMPROVE_GUI_LATENCY
37#include <qpe/global.h> 37#include <qpe/global.h>
38#endif 38#endif
39 39
40 40
41 41
42/* QT */ 42/* QT */
43#include <qapplication.h> 43#include <qapplication.h>
44#include <qfile.h> 44#include <qfile.h>
45#include <qtextstream.h> 45#include <qtextstream.h>
46 46
47using namespace Opie::Core; 47using namespace Opie::Core;
48namespace Opie { 48namespace Opie {
49namespace Net { 49namespace Net {
50 50
51OManufacturerDB* OManufacturerDB::_instance = 0; 51OManufacturerDB* OManufacturerDB::_instance = 0;
52 52
53OManufacturerDB* OManufacturerDB::instance() 53OManufacturerDB* OManufacturerDB::instance()
54{ 54{
55 if ( !OManufacturerDB::_instance ) 55 if ( !OManufacturerDB::_instance )
56 { 56 {
57 odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl; 57 odebug << "OManufacturerDB::instance(): creating OManufacturerDB..." << oendl;
58 _instance = new OManufacturerDB(); 58 _instance = new OManufacturerDB();
59 } 59 }
60 return _instance; 60 return _instance;
61} 61}
62 62
63 63
64OManufacturerDB::OManufacturerDB() 64OManufacturerDB::OManufacturerDB()
65{ 65{
66 #ifdef OPIE_IMPROVE_GUI_LATENCY 66 #ifdef OPIE_IMPROVE_GUI_LATENCY
67 Global::statusMessage( "Reading Manufacturers..." ); 67 Global::statusMessage( "Reading Manufacturers..." );
68 #endif 68 #endif
69 QString filename( "/etc/manufacturers" ); 69 QString filename( "/etc/manufacturers" );
70 odebug << "OManufacturerDB: trying to read " << filename << oendl; 70 odebug << "OManufacturerDB: trying to read " << filename << oendl;
71 if ( !QFile::exists( filename ) ) 71 if ( !QFile::exists( filename ) )
72 { 72 {
73 filename = QPEApplication::qpeDir()+"/etc/manufacturers"; 73 filename = QPEApplication::qpeDir()+"etc/manufacturers";
74 odebug << "OManufacturerDB: trying to read " << filename << oendl; 74 odebug << "OManufacturerDB: trying to read " << filename << oendl;
75 if ( !QFile::exists( filename ) ) 75 if ( !QFile::exists( filename ) )
76 { 76 {
77 filename = "/usr/share/wellenreiter/manufacturers"; 77 filename = "/usr/share/wellenreiter/manufacturers";
78 odebug << "OManufacturerDB: trying to read " << filename << oendl; 78 odebug << "OManufacturerDB: trying to read " << filename << oendl;
79 } 79 }
80 } 80 }
81 81
82 QFile file( filename ); 82 QFile file( filename );
83 bool hasFile = file.open( IO_ReadOnly ); 83 bool hasFile = file.open( IO_ReadOnly );
84 if (!hasFile) 84 if (!hasFile)
85 { 85 {
86 owarn << "OManufacturerDB: no valid manufacturer list found." << oendl; 86 owarn << "OManufacturerDB: no valid manufacturer list found." << oendl;
87 } 87 }
88 else 88 else
89 { 89 {
90 odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl; 90 odebug << "OManufacturerDB: found manufacturer list in " << filename << oendl;
91 QTextStream s( &file ); 91 QTextStream s( &file );
92 QString addr; 92 QString addr;
93 QString manu; 93 QString manu;
94 QString extManu; 94 QString extManu;
95 #ifdef OPIE_IMPROVE_GUI_LATENCY 95 #ifdef OPIE_IMPROVE_GUI_LATENCY
96 int counter = 0; 96 int counter = 0;
97 #endif 97 #endif
98 while (!s.atEnd()) 98 while (!s.atEnd())
99 { 99 {
100 s >> addr; 100 s >> addr;
101 s >> manu; 101 s >> manu;
102 s >> extManu; 102 s >> extManu;
103 103
104 manufacturers.insert( addr, manu ); 104 manufacturers.insert( addr, manu );
105 manufacturersExt.insert( addr, extManu ); 105 manufacturersExt.insert( addr, extManu );
106 // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl; 106 // odebug << "OmanufacturerDB: parse '" << addr << "' as '" << manu << "' (" << extManu << ")" << oendl;
107 #ifdef OPIE_IMPROVE_GUI_LATENCY 107 #ifdef OPIE_IMPROVE_GUI_LATENCY
108 counter++; 108 counter++;
109 if ( counter == 50 ) 109 if ( counter == 50 )
110 { 110 {
111 qApp->processEvents(); 111 qApp->processEvents();
112 counter = 0; 112 counter = 0;
113 } 113 }
114 #endif 114 #endif
115 } 115 }
116 odebug << "OManufacturerDB: manufacturer list completed." << oendl; 116 odebug << "OManufacturerDB: manufacturer list completed." << oendl;
117 #ifdef OPIE_IMPROVE_GUI_LATENCY 117 #ifdef OPIE_IMPROVE_GUI_LATENCY
118 Global::statusMessage( "Manufacturers Complete..." ); 118 Global::statusMessage( "Manufacturers Complete..." );
119 #endif 119 #endif
120 } 120 }
121} 121}
122 122
123 123
124OManufacturerDB::~OManufacturerDB() 124OManufacturerDB::~OManufacturerDB()
125{ 125{
126} 126}
127 127
128 128
129const QString& OManufacturerDB::lookup( const QString& macaddr ) const 129const QString& OManufacturerDB::lookup( const QString& macaddr ) const
130{ 130{
131 return manufacturers[macaddr.upper().left(8)]; 131 return manufacturers[macaddr.upper().left(8)];
132} 132}
133 133
134 134
135const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const 135const QString& OManufacturerDB::lookupExt( const QString& macaddr ) const
136{ 136{
137 QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) ); 137 QMap<QString,QString>::ConstIterator it = manufacturersExt.find( macaddr.upper().left(8) );
138 return it == manufacturersExt.end() ? lookup( macaddr ) : *it; 138 return it == manufacturersExt.end() ? lookup( macaddr ) : *it;
139} 139}
140 140
141} 141}
142} 142}
143 143
diff --git a/libopie2/opiesecurity/multiauthcommon.cpp b/libopie2/opiesecurity/multiauthcommon.cpp
index 9de62d2..e563193 100644
--- a/libopie2/opiesecurity/multiauthcommon.cpp
+++ b/libopie2/opiesecurity/multiauthcommon.cpp
@@ -1,195 +1,195 @@
1#include "multiauthplugininterface.h" 1#include "multiauthplugininterface.h"
2#include "multiauthcommon.h" 2#include "multiauthcommon.h"
3 3
4/* Opie */ 4/* Opie */
5#include <opie2/odebug.h> 5#include <opie2/odebug.h>
6#include <opie2/oapplication.h> 6#include <opie2/oapplication.h>
7 7
8/* Qt */ 8/* Qt */
9#include <qpe/qpeapplication.h> 9#include <qpe/qpeapplication.h>
10#include <qpe/qlibrary.h> 10#include <qpe/qlibrary.h>
11#include <qpe/qcom.h> 11#include <qpe/qcom.h>
12#include <qtextview.h> 12#include <qtextview.h>
13#include <qdir.h> 13#include <qdir.h>
14 14
15/* UNIX */ 15/* UNIX */
16#include <unistd.h> 16#include <unistd.h>
17#include <qpe/config.h> 17#include <qpe/config.h>
18 18
19namespace Opie { 19namespace Opie {
20namespace Security { 20namespace Security {
21 21
22SecOwnerDlg::SecOwnerDlg( QWidget *parent, const char * name, Contact c, 22SecOwnerDlg::SecOwnerDlg( QWidget *parent, const char * name, Contact c,
23 bool modal, bool fullscreen = FALSE ) 23 bool modal, bool fullscreen = FALSE )
24: QDialog( parent, name, modal, 24: QDialog( parent, name, modal,
25 fullscreen ? 25 fullscreen ?
26 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 ) 26 WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop : 0 )
27{ 27{
28 if ( fullscreen ) { 28 if ( fullscreen ) {
29 QRect desk = qApp->desktop()->geometry(); 29 QRect desk = qApp->desktop()->geometry();
30 setGeometry( 0, 0, desk.width(), desk.height() ); 30 setGeometry( 0, 0, desk.width(), desk.height() );
31 } 31 }
32 // set up contents. 32 // set up contents.
33 QString text("<H3>" + tr("Please contact the owner (directions follow), or try again clicking of this screen (and waiting for the penalty time) if you are the legitimate owner") + "</H3>"); 33 QString text("<H3>" + tr("Please contact the owner (directions follow), or try again clicking of this screen (and waiting for the penalty time) if you are the legitimate owner") + "</H3>");
34 text += c.toRichText(); 34 text += c.toRichText();
35 tv = new QTextView(this); 35 tv = new QTextView(this);
36 tv->setText(text); 36 tv->setText(text);
37 37
38 tv->viewport()->installEventFilter(this); 38 tv->viewport()->installEventFilter(this);
39} 39}
40 40
41void SecOwnerDlg::resizeEvent( QResizeEvent * ) 41void SecOwnerDlg::resizeEvent( QResizeEvent * )
42{ 42{
43 tv->resize( size() ); 43 tv->resize( size() );
44} 44}
45 45
46bool SecOwnerDlg::eventFilter(QObject *o, QEvent *e) 46bool SecOwnerDlg::eventFilter(QObject *o, QEvent *e)
47{ 47{
48 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) { 48 if (e->type() == QEvent::KeyPress || e->type() == QEvent::MouseButtonPress ) {
49 accept(); 49 accept();
50 return TRUE; 50 return TRUE;
51 } 51 }
52 return QWidget::eventFilter(o, e); 52 return QWidget::eventFilter(o, e);
53} 53}
54 54
55void SecOwnerDlg::mousePressEvent( QMouseEvent * ) { accept(); } 55void SecOwnerDlg::mousePressEvent( QMouseEvent * ) { accept(); }
56 56
57 57
58namespace Internal { 58namespace Internal {
59/// run plugins until we reach nbSuccessMin successes 59/// run plugins until we reach nbSuccessMin successes
60int runPlugins() { 60int runPlugins() {
61 61
62 SecOwnerDlg *oi = 0; 62 SecOwnerDlg *oi = 0;
63 // see if there is contact information. 63 // see if there is contact information.
64 QString vfilename = Global::applicationFileName("addressbook", 64 QString vfilename = Global::applicationFileName("addressbook",
65 "businesscard.vcf"); 65 "businesscard.vcf");
66 if (QFile::exists(vfilename)) { 66 if (QFile::exists(vfilename)) {
67 Contact c; 67 Contact c;
68 c = Contact::readVCard( vfilename )[0]; 68 c = Contact::readVCard( vfilename )[0];
69 69
70 oi = new SecOwnerDlg(0, 0, c, TRUE, TRUE); 70 oi = new SecOwnerDlg(0, 0, c, TRUE, TRUE);
71 } 71 }
72 72
73 Config config("Security"); 73 Config config("Security");
74 config.setGroup("Plugins"); 74 config.setGroup("Plugins");
75 QStringList plugins = config.readListEntry("IncludePlugins", ','); 75 QStringList plugins = config.readListEntry("IncludePlugins", ',');
76 /* if there are no configured plugins, we simply return 0 to 76 /* if there are no configured plugins, we simply return 0 to
77 * let the user in: 77 * let the user in:
78 */ 78 */
79 if (plugins.isEmpty() == true) { 79 if (plugins.isEmpty() == true) {
80 owarn << "No authentication plugin has been configured yet!" << oendl; 80 owarn << "No authentication plugin has been configured yet!" << oendl;
81 odebug << "Letting the user in..." << oendl; 81 odebug << "Letting the user in..." << oendl;
82 if(oi) delete oi; 82 if(oi) delete oi;
83 return 0; 83 return 0;
84 } 84 }
85 config.setGroup("Misc"); 85 config.setGroup("Misc");
86 int nbSuccessMin = config.readNumEntry("nbSuccessMin", 1); 86 int nbSuccessMin = config.readNumEntry("nbSuccessMin", 1);
87 int nbSuccess = 0; 87 int nbSuccess = 0;
88 88
89 /* tries to launch successively each plugin in $OPIEDIR/plugins/security 89 /* tries to launch successively each plugin in $OPIEDIR/plugins/security
90 * directory which file name is in Security.conf / [Misc] / IncludePlugins 90 * directory which file name is in Security.conf / [Misc] / IncludePlugins
91 */ 91 */
92 QString path = QPEApplication::qpeDir() + "/plugins/security"; 92 QString path = QPEApplication::qpeDir() + "plugins/security";
93 QStringList::Iterator libIt; 93 QStringList::Iterator libIt;
94 94
95 for ( libIt = plugins.begin(); libIt != plugins.end(); ++libIt ) { 95 for ( libIt = plugins.begin(); libIt != plugins.end(); ++libIt ) {
96 QInterfacePtr<MultiauthPluginInterface> iface; 96 QInterfacePtr<MultiauthPluginInterface> iface;
97 QLibrary *lib = new QLibrary( path + "/" + *libIt ); 97 QLibrary *lib = new QLibrary( path + "/" + *libIt );
98 98
99 if ( lib->queryInterface( 99 if ( lib->queryInterface(
100 IID_MultiauthPluginInterface, 100 IID_MultiauthPluginInterface,
101 (QUnknownInterface**)&iface ) == QS_OK ) 101 (QUnknownInterface**)&iface ) == QS_OK )
102 { 102 {
103 // the plugin is a true Multiauth plugin 103 // the plugin is a true Multiauth plugin
104 odebug << "Accepted plugin: " << QString( path + "/" + *libIt ) << oendl; 104 odebug << "Accepted plugin: " << QString( path + "/" + *libIt ) << oendl;
105 odebug << "Plugin name: " << iface->plugin()->pluginName() << oendl; 105 odebug << "Plugin name: " << iface->plugin()->pluginName() << oendl;
106 106
107 int resultCode; 107 int resultCode;
108 int tries = 0; 108 int tries = 0;
109 109
110 // perform authentication 110 // perform authentication
111 resultCode = iface->plugin()->authenticate(); 111 resultCode = iface->plugin()->authenticate();
112 112
113 // display the result in command line 113 // display the result in command line
114 QString resultMessage; 114 QString resultMessage;
115 switch (resultCode) 115 switch (resultCode)
116 { 116 {
117 case MultiauthPluginObject::Success: 117 case MultiauthPluginObject::Success:
118 resultMessage = "Success!"; 118 resultMessage = "Success!";
119 nbSuccess++; 119 nbSuccess++;
120 break; 120 break;
121 case MultiauthPluginObject::Failure: 121 case MultiauthPluginObject::Failure:
122 resultMessage = "Failure..."; 122 resultMessage = "Failure...";
123 break; 123 break;
124 case MultiauthPluginObject::Skip: 124 case MultiauthPluginObject::Skip:
125 resultMessage = "Skip"; 125 resultMessage = "Skip";
126 break; 126 break;
127 } 127 }
128 odebug << "Plugin result: " << resultMessage << oendl; 128 odebug << "Plugin result: " << resultMessage << oendl;
129 129
130 // if failure, wait, reperform, wait, reperform... until right 130 // if failure, wait, reperform, wait, reperform... until right
131 while (resultCode == MultiauthPluginObject::Failure) 131 while (resultCode == MultiauthPluginObject::Failure)
132 { 132 {
133 tries++; 133 tries++;
134 owarn << "This plugin has failed " << tries << " times already" << oendl; 134 owarn << "This plugin has failed " << tries << " times already" << oendl;
135 135
136 // displays owner information, if any 136 // displays owner information, if any
137 if (oi) 137 if (oi)
138 { 138 {
139 oi->exec(); 139 oi->exec();
140 odebug << "Contact information displayed" << oendl; 140 odebug << "Contact information displayed" << oendl;
141 } 141 }
142 142
143 /// \todo parametrize the time penalty according to \em mode (exponential, 143 /// \todo parametrize the time penalty according to \em mode (exponential,
144 /// linear or fixed) and \em basetime (time penalty for the first failure) 144 /// linear or fixed) and \em basetime (time penalty for the first failure)
145 sleep(2 * tries); 145 sleep(2 * tries);
146 146
147 if (oi) 147 if (oi)
148 { 148 {
149 oi->hide(); 149 oi->hide();
150 /** \todo fix the focus here: should go back to the current plugin widget 150 /** \todo fix the focus here: should go back to the current plugin widget
151 * but it doesn't, so we have to tap once on the widget before e.g. buttons 151 * but it doesn't, so we have to tap once on the widget before e.g. buttons
152 * are active again 152 * are active again
153 */ 153 */
154 odebug << "Contact information hidden" << oendl; 154 odebug << "Contact information hidden" << oendl;
155 } 155 }
156 156
157 // perform authentication 157 // perform authentication
158 resultCode = iface->plugin()->authenticate(); 158 resultCode = iface->plugin()->authenticate();
159 159
160 // display the result in command line 160 // display the result in command line
161 switch (resultCode) 161 switch (resultCode)
162 { 162 {
163 case MultiauthPluginObject::Success: 163 case MultiauthPluginObject::Success:
164 resultMessage = "Success!"; 164 resultMessage = "Success!";
165 nbSuccess++; 165 nbSuccess++;
166 break; 166 break;
167 case MultiauthPluginObject::Failure: 167 case MultiauthPluginObject::Failure:
168 resultMessage = "Failure..."; 168 resultMessage = "Failure...";
169 break; 169 break;
170 case MultiauthPluginObject::Skip: 170 case MultiauthPluginObject::Skip:
171 resultMessage = "Skip"; 171 resultMessage = "Skip";
172 break; 172 break;
173 } 173 }
174 odebug << "Plugin result: " << resultMessage << oendl; 174 odebug << "Plugin result: " << resultMessage << oendl;
175 } 175 }
176 delete lib; 176 delete lib;
177 177
178 if (resultCode == MultiauthPluginObject::Success && nbSuccess == nbSuccessMin) 178 if (resultCode == MultiauthPluginObject::Success && nbSuccess == nbSuccessMin)
179 { 179 {
180 if(oi) delete oi; 180 if(oi) delete oi;
181 // we have reached the required number of successes, we can exit the plugin loop 181 // we have reached the required number of successes, we can exit the plugin loop
182 return 0; 182 return 0;
183 } 183 }
184 } else { 184 } else {
185 owarn << "Could not recognize plugin " << QString( path + "/" + *libIt ) << oendl; 185 owarn << "Could not recognize plugin " << QString( path + "/" + *libIt ) << oendl;
186 delete lib; 186 delete lib;
187 } // end if plugin recognized 187 } // end if plugin recognized
188 } //end for 188 } //end for
189 if(oi) delete oi; 189 if(oi) delete oi;
190 return 1; 190 return 1;
191} 191}
192 192
193} 193}
194} 194}
195} 195}
diff --git a/library/fontdatabase.cpp b/library/fontdatabase.cpp
index d94e338..7934a09 100644
--- a/library/fontdatabase.cpp
+++ b/library/fontdatabase.cpp
@@ -1,251 +1,251 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22#include "fontdatabase.h" 22#include "fontdatabase.h"
23 23
24#include <qpe/qlibrary.h> 24#include <qpe/qlibrary.h>
25 25
26#include <qfontmanager_qws.h> 26#include <qfontmanager_qws.h>
27#include <qdir.h> 27#include <qdir.h>
28#include <stdio.h> 28#include <stdio.h>
29#include <stdlib.h> 29#include <stdlib.h>
30 30
31static QString fontDir() 31static QString fontDir()
32{ 32{
33 QString qtdir = getenv("QTDIR"); 33 QString qtdir = getenv("QTDIR");
34 if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded"; 34 if ( qtdir.isEmpty() ) qtdir = "/usr/local/qt-embedded";
35 return qtdir+"/lib/fonts/"; 35 return qtdir+"/lib/fonts/";
36} 36}
37 37
38#ifdef QT_NO_FONTDATABASE 38#ifdef QT_NO_FONTDATABASE
39static QString fontFamily( const QString& key ) 39static QString fontFamily( const QString& key )
40{ 40{
41 int u0 = key.find('_'); 41 int u0 = key.find('_');
42 int u1 = key.find('_',u0+1); 42 int u1 = key.find('_',u0+1);
43 int u2 = key.find('_',u1+1); 43 int u2 = key.find('_',u1+1);
44 QString family = key.left(u0); 44 QString family = key.left(u0);
45 //int pointSize = key.mid(u0+1,u1-u0-1).toInt(); 45 //int pointSize = key.mid(u0+1,u1-u0-1).toInt();
46 //int weight = key.mid(u1+1,u2-u1-1).toInt(); 46 //int weight = key.mid(u1+1,u2-u1-1).toInt();
47 //bool italic = key.mid(u2-1,1) == "i"; 47 //bool italic = key.mid(u2-1,1) == "i";
48 // #### ignores _t and _I fields 48 // #### ignores _t and _I fields
49 return family; 49 return family;
50} 50}
51#endif 51#endif
52 52
53 53
54QValueList<FontFactory> *FontDatabase::factoryList = 0; 54QValueList<FontFactory> *FontDatabase::factoryList = 0;
55/*! 55/*!
56 \class FontDatabase fontdatabase.h 56 \class FontDatabase fontdatabase.h
57 \brief The FontDatabase class provides information about available fonts. 57 \brief The FontDatabase class provides information about available fonts.
58 58
59 Most often you will simply want to query the database for the 59 Most often you will simply want to query the database for the
60 available font families(). 60 available font families().
61 61
62 Use FontDatabase rather than QFontDatabase when you may need access 62 Use FontDatabase rather than QFontDatabase when you may need access
63 to fonts that are not normally available. For example, if the 63 to fonts that are not normally available. For example, if the
64 freetype library and the Qtopia freetype plugin are installed, 64 freetype library and the Qtopia freetype plugin are installed,
65 TrueType fonts will be available to your application. Font renderer 65 TrueType fonts will be available to your application. Font renderer
66 plugins have greater resource requirements than system fonts so they 66 plugins have greater resource requirements than system fonts so they
67 should be used only when necessary. You can force the loading of 67 should be used only when necessary. You can force the loading of
68 font renderer plugins with loadRenderers(). 68 font renderer plugins with loadRenderers().
69 69
70 \ingroup qtopiaemb 70 \ingroup qtopiaemb
71*/ 71*/
72 72
73/*! 73/*!
74 Constructs a FontDatabase object. 74 Constructs a FontDatabase object.
75*/ 75*/
76FontDatabase::FontDatabase() 76FontDatabase::FontDatabase()
77#ifndef QT_NO_FONTDATABASE 77#ifndef QT_NO_FONTDATABASE
78 : QFontDatabase() 78 : QFontDatabase()
79#endif 79#endif
80{ 80{
81 if ( !factoryList ) 81 if ( !factoryList )
82 loadRenderers(); 82 loadRenderers();
83} 83}
84 84
85/*! 85/*!
86 Returns a list of names of all the available font families. 86 Returns a list of names of all the available font families.
87*/ 87*/
88QStringList FontDatabase::families() const 88QStringList FontDatabase::families() const
89{ 89{
90#ifndef QT_NO_FONTDATABASE 90#ifndef QT_NO_FONTDATABASE
91 return QFontDatabase::families(); 91 return QFontDatabase::families();
92#else 92#else
93 93
94#ifndef QWS 94#ifndef QWS
95 QStringList list; 95 QStringList list;
96 return list; 96 return list;
97#else 97#else
98 QStringList list; 98 QStringList list;
99 QDict<void> familyDict; 99 QDict<void> familyDict;
100 QDiskFont *qdf; 100 QDiskFont *qdf;
101 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0; 101 for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0;
102 qdf=qt_fontmanager->diskfonts.next()) { 102 qdf=qt_fontmanager->diskfonts.next()) {
103 QString familyname = qdf->name; 103 QString familyname = qdf->name;
104 if ( !familyDict.find( familyname ) ) { 104 if ( !familyDict.find( familyname ) ) {
105 familyDict.insert( familyname, (void *)1 ); 105 familyDict.insert( familyname, (void *)1 );
106 list.append( familyname ); 106 list.append( familyname );
107 } 107 }
108 } 108 }
109 109
110 QDir dir(fontDir(),"*.qpf"); 110 QDir dir(fontDir(),"*.qpf");
111 for (int i=0; i<(int)dir.count(); i++) { 111 for (int i=0; i<(int)dir.count(); i++) {
112 QString familyname = fontFamily(dir[i]); 112 QString familyname = fontFamily(dir[i]);
113 if ( !familyDict.find( familyname ) ) { 113 if ( !familyDict.find( familyname ) ) {
114 familyDict.insert( familyname, (void *)1 ); 114 familyDict.insert( familyname, (void *)1 );
115 list.append( familyname ); 115 list.append( familyname );
116 } 116 }
117 } 117 }
118 118
119 return list; 119 return list;
120#endif 120#endif
121#endif 121#endif
122} 122}
123 123
124#ifdef QT_NO_FONTDATABASE 124#ifdef QT_NO_FONTDATABASE
125/*! 125/*!
126 Returns a list of standard fontsizes. 126 Returns a list of standard fontsizes.
127*/ 127*/
128QValueList<int> FontDatabase::standardSizes() 128QValueList<int> FontDatabase::standardSizes()
129{ 129{
130 static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 130 static int s[]={ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28,
131 36, 48, 72, 0 }; 131 36, 48, 72, 0 };
132 static bool first = TRUE; 132 static bool first = TRUE;
133 static QValueList<int> sList; 133 static QValueList<int> sList;
134 if ( first ) { 134 if ( first ) {
135 first = FALSE; 135 first = FALSE;
136 int i = 0; 136 int i = 0;
137 while( s[i] ) 137 while( s[i] )
138 sList.append( s[i++] ); 138 sList.append( s[i++] );
139 } 139 }
140 return sList; 140 return sList;
141} 141}
142 142
143#endif 143#endif
144 144
145/*! 145/*!
146 Load any font renderer plugins that are available and make the fonts 146 Load any font renderer plugins that are available and make the fonts
147 that the plugins can read available. 147 that the plugins can read available.
148*/ 148*/
149void FontDatabase::loadRenderers() 149void FontDatabase::loadRenderers()
150{ 150{
151#ifndef QWS 151#ifndef QWS
152 return; 152 return;
153#else 153#else
154 154
155#ifndef QT_NO_COMPONENT 155#ifndef QT_NO_COMPONENT
156 if ( !factoryList ) 156 if ( !factoryList )
157 factoryList = new QValueList<FontFactory>; 157 factoryList = new QValueList<FontFactory>;
158 158
159 QValueList<FontFactory>::Iterator mit; 159 QValueList<FontFactory>::Iterator mit;
160 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) { 160 for ( mit = factoryList->begin(); mit != factoryList->end(); ++mit ) {
161 qt_fontmanager->factories.setAutoDelete( false ); 161 qt_fontmanager->factories.setAutoDelete( false );
162 qt_fontmanager->factories.removeRef( (*mit).factory ); 162 qt_fontmanager->factories.removeRef( (*mit).factory );
163 qt_fontmanager->factories.setAutoDelete( true ); 163 qt_fontmanager->factories.setAutoDelete( true );
164 (*mit).interface->release(); 164 (*mit).interface->release();
165 (*mit).library->unload(); 165 (*mit).library->unload();
166 delete (*mit).library; 166 delete (*mit).library;
167 } 167 }
168 factoryList->clear(); 168 factoryList->clear();
169 169
170 QString path = QPEApplication::qpeDir() + "/plugins/fontfactories"; 170 QString path = QPEApplication::qpeDir() + "plugins/fontfactories";
171#ifdef Q_OS_MACX 171#ifdef Q_OS_MACX
172 QDir dir( path, "lib*.dylib" ); 172 QDir dir( path, "lib*.dylib" );
173#else 173#else
174 QDir dir( path, "lib*.so" ); 174 QDir dir( path, "lib*.so" );
175#endif 175#endif
176 176
177 if ( !dir.exists()) 177 if ( !dir.exists())
178 return; 178 return;
179 179
180 QStringList list = dir.entryList(); 180 QStringList list = dir.entryList();
181 QStringList::Iterator it; 181 QStringList::Iterator it;
182 for ( it = list.begin(); it != list.end(); ++it ) { 182 for ( it = list.begin(); it != list.end(); ++it ) {
183 FontFactoryInterface *iface = 0; 183 FontFactoryInterface *iface = 0;
184 QLibrary *lib = new QLibrary( path + "/" + *it ); 184 QLibrary *lib = new QLibrary( path + "/" + *it );
185 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) { 185 if ( lib->queryInterface( IID_FontFactory, (QUnknownInterface**)&iface ) == QS_OK ) {
186 FontFactory factory; 186 FontFactory factory;
187 factory.library = lib; 187 factory.library = lib;
188 factory.interface = iface; 188 factory.interface = iface;
189 factory.factory = factory.interface->fontFactory(); 189 factory.factory = factory.interface->fontFactory();
190 factoryList->append( factory ); 190 factoryList->append( factory );
191 qt_fontmanager->factories.append( factory.factory ); 191 qt_fontmanager->factories.append( factory.factory );
192 readFonts( factory.factory ); 192 readFonts( factory.factory );
193 } else { 193 } else {
194 delete lib; 194 delete lib;
195 } 195 }
196 } 196 }
197#endif 197#endif
198#endif 198#endif
199} 199}
200 200
201/*! 201/*!
202 \internal 202 \internal
203*/ 203*/
204void FontDatabase::readFonts( QFontFactory *factory ) 204void FontDatabase::readFonts( QFontFactory *factory )
205{ 205{
206#ifndef QWS 206#ifndef QWS
207return; 207return;
208#else 208#else
209 // Load in font definition file 209 // Load in font definition file
210 QString fn = fontDir() + "fontdir"; 210 QString fn = fontDir() + "fontdir";
211 FILE* fontdef=fopen(fn.local8Bit(),"r"); 211 FILE* fontdef=fopen(fn.local8Bit(),"r");
212 if(!fontdef) { 212 if(!fontdef) {
213 QCString temp=fn.local8Bit(); 213 QCString temp=fn.local8Bit();
214 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?", 214 qWarning("Cannot find font definition file %s - is $QTDIR set correctly?",
215 temp.data()); 215 temp.data());
216 return; 216 return;
217 } 217 }
218 char buf[200]=""; 218 char buf[200]="";
219 char name[200]=""; 219 char name[200]="";
220 char render[200]=""; 220 char render[200]="";
221 char file[200]=""; 221 char file[200]="";
222 char flags[200]=""; 222 char flags[200]="";
223 char isitalic[10]=""; 223 char isitalic[10]="";
224 fgets(buf,200,fontdef); 224 fgets(buf,200,fontdef);
225 while(!feof(fontdef)) { 225 while(!feof(fontdef)) {
226 if ( buf[0] != '#' ) { 226 if ( buf[0] != '#' ) {
227 int weight=50; 227 int weight=50;
228 int size=0; 228 int size=0;
229 flags[0]=0; 229 flags[0]=0;
230 sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags); 230 sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags);
231 QString filename; 231 QString filename;
232 if ( file[0] != '/' ) 232 if ( file[0] != '/' )
233 filename = fontDir(); 233 filename = fontDir();
234 filename += file; 234 filename += file;
235 if ( QFile::exists(filename) ) { 235 if ( QFile::exists(filename) ) {
236 if( factory->name() == render ) { 236 if( factory->name() == render ) {
237 QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y', 237 QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y',
238 weight,size,flags,filename); 238 weight,size,flags,filename);
239 qt_fontmanager->diskfonts.append(qdf); 239 qt_fontmanager->diskfonts.append(qdf);
240#if QT_VERSION >= 232 240#if QT_VERSION >= 232
241 QFontDatabase::qwsAddDiskFont( qdf ); 241 QFontDatabase::qwsAddDiskFont( qdf );
242#endif 242#endif
243 } 243 }
244 } 244 }
245 } 245 }
246 fgets(buf,200,fontdef); 246 fgets(buf,200,fontdef);
247 } 247 }
248 fclose(fontdef); 248 fclose(fontdef);
249#endif 249#endif
250} 250}
251 251
diff --git a/library/network.cpp b/library/network.cpp
index f2a673c..0bbbec1 100644
--- a/library/network.cpp
+++ b/library/network.cpp
@@ -1,448 +1,448 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22#include <qpe/network.h> 22#include <qpe/network.h>
23#include <qpe/networkinterface.h> 23#include <qpe/networkinterface.h>
24#include <qpe/global.h> 24#include <qpe/global.h>
25#include <qpe/config.h> 25#include <qpe/config.h>
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qpe/qcopenvelope_qws.h> 28#include <qpe/qcopenvelope_qws.h>
29#include <qpe/qlibrary.h> 29#include <qpe/qlibrary.h>
30 30
31#include <qlistbox.h> 31#include <qlistbox.h>
32#include <qdir.h> 32#include <qdir.h>
33#include <qlayout.h> 33#include <qlayout.h>
34#include <qdict.h> 34#include <qdict.h>
35#include <qtranslator.h> 35#include <qtranslator.h>
36 36
37#include <stdlib.h> 37#include <stdlib.h>
38 38
39#ifndef QT_NO_COP 39#ifndef QT_NO_COP
40class NetworkEmitter : public QCopChannel { 40class NetworkEmitter : public QCopChannel {
41 Q_OBJECT 41 Q_OBJECT
42public: 42public:
43 NetworkEmitter() : QCopChannel("QPE/Network",qApp) 43 NetworkEmitter() : QCopChannel("QPE/Network",qApp)
44 { 44 {
45 } 45 }
46 46
47 void receive(const QCString &msg, const QByteArray&) 47 void receive(const QCString &msg, const QByteArray&)
48 { 48 {
49 if ( msg == "choicesChanged()" ) 49 if ( msg == "choicesChanged()" )
50 emit changed(); 50 emit changed();
51 } 51 }
52 52
53signals: 53signals:
54 void changed(); 54 void changed();
55}; 55};
56 56
57/*! 57/*!
58 \internal 58 \internal
59 59
60 Requests that the service \a choice be started. The \a password is 60 Requests that the service \a choice be started. The \a password is
61 the password to use if required. 61 the password to use if required.
62*/ 62*/
63void Network::start(const QString& choice, const QString& password) 63void Network::start(const QString& choice, const QString& password)
64{ 64{
65 QCopEnvelope e("QPE/Network", "start(QString,QString)"); 65 QCopEnvelope e("QPE/Network", "start(QString,QString)");
66 e << choice << password; 66 e << choice << password;
67} 67}
68 68
69/*! 69/*!
70 \class Network network.h 70 \class Network network.h
71 \brief The Network class provides network access functionality. 71 \brief The Network class provides network access functionality.
72 \internal 72 \internal
73*/ 73*/
74 74
75// copy the proxy settings of the active config over to the Proxies.conf file 75// copy the proxy settings of the active config over to the Proxies.conf file
76/*! 76/*!
77 \internal 77 \internal
78*/ 78*/
79void Network::writeProxySettings( Config &cfg ) 79void Network::writeProxySettings( Config &cfg )
80{ 80{
81 Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File ); 81 Config proxy( Network::settingsDir() + "/Proxies.conf", Config::File );
82 proxy.setGroup("Properties"); 82 proxy.setGroup("Properties");
83 cfg.setGroup("Proxy"); 83 cfg.setGroup("Proxy");
84 proxy.writeEntry("type", cfg.readEntry("type") ); 84 proxy.writeEntry("type", cfg.readEntry("type") );
85 proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") ); 85 proxy.writeEntry("autoconfig", cfg.readEntry("autoconfig") );
86 proxy.writeEntry("httphost", cfg.readEntry("httphost") ); 86 proxy.writeEntry("httphost", cfg.readEntry("httphost") );
87 proxy.writeEntry("httpport", cfg.readEntry("httpport") ); 87 proxy.writeEntry("httpport", cfg.readEntry("httpport") );
88 proxy.writeEntry("ftphost", cfg.readEntry("ftphost") ); 88 proxy.writeEntry("ftphost", cfg.readEntry("ftphost") );
89 proxy.writeEntry("ftpport", cfg.readEntry("ftpport") ); 89 proxy.writeEntry("ftpport", cfg.readEntry("ftpport") );
90 proxy.writeEntry("noproxies", cfg.readEntry("noproxies") ); 90 proxy.writeEntry("noproxies", cfg.readEntry("noproxies") );
91 cfg.setGroup("Properties"); 91 cfg.setGroup("Properties");
92} 92}
93 93
94 94
95 95
96/*! 96/*!
97 \internal 97 \internal
98 98
99 Stops the current network service. 99 Stops the current network service.
100*/ 100*/
101void Network::stop() 101void Network::stop()
102{ 102{
103 QCopEnvelope e("QPE/Network", "stop()"); 103 QCopEnvelope e("QPE/Network", "stop()");
104} 104}
105 105
106static NetworkEmitter *emitter = 0; 106static NetworkEmitter *emitter = 0;
107 107
108/*! 108/*!
109 \internal 109 \internal
110*/ 110*/
111void Network::connectChoiceChange(QObject* receiver, const char* slot) 111void Network::connectChoiceChange(QObject* receiver, const char* slot)
112{ 112{
113 if ( !emitter ) 113 if ( !emitter )
114 emitter = new NetworkEmitter; 114 emitter = new NetworkEmitter;
115 QObject::connect(emitter,SIGNAL(changed()),receiver,slot); 115 QObject::connect(emitter,SIGNAL(changed()),receiver,slot);
116} 116}
117 117
118 #endif// QT_NO_COP 118 #endif// QT_NO_COP
119/*! 119/*!
120 \internal 120 \internal
121*/ 121*/
122QString Network::settingsDir() 122QString Network::settingsDir()
123{ 123{
124 return Global::applicationFileName("Network", "modules"); 124 return Global::applicationFileName("Network", "modules");
125} 125}
126 126
127#ifndef QT_NO_COP 127#ifndef QT_NO_COP
128/*! 128/*!
129 \internal 129 \internal
130*/ 130*/
131QStringList Network::choices(QListBox* lb, const QString& dir) 131QStringList Network::choices(QListBox* lb, const QString& dir)
132{ 132{
133 QStringList list; 133 QStringList list;
134 134
135 if ( lb ) 135 if ( lb )
136 lb->clear(); 136 lb->clear();
137 137
138 QString adir = dir.isEmpty() ? settingsDir() : dir; 138 QString adir = dir.isEmpty() ? settingsDir() : dir;
139 QDir settingsdir(adir); 139 QDir settingsdir(adir);
140 settingsdir.mkdir(adir); 140 settingsdir.mkdir(adir);
141 141
142 QStringList files = settingsdir.entryList("*.conf"); 142 QStringList files = settingsdir.entryList("*.conf");
143 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) { 143 for (QStringList::ConstIterator it=files.begin(); it!=files.end(); ++it ) {
144 QString filename = settingsdir.filePath(*it); 144 QString filename = settingsdir.filePath(*it);
145 Config cfg(filename, Config::File); 145 Config cfg(filename, Config::File);
146 cfg.setGroup("Info"); 146 cfg.setGroup("Info");
147 if ( lb ) 147 if ( lb )
148 lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")), 148 lb->insertItem(Resource::loadPixmap("Network/" + cfg.readEntry("Type")),
149 cfg.readEntry("Name")); 149 cfg.readEntry("Name"));
150 list.append(filename); 150 list.append(filename);
151 } 151 }
152 152
153 return list; 153 return list;
154} 154}
155 155
156class NetworkServer : public QCopChannel { 156class NetworkServer : public QCopChannel {
157 Q_OBJECT 157 Q_OBJECT
158public: 158public:
159 NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0) 159 NetworkServer(QObject* parent) : QCopChannel("QPE/Network",parent), wait(0)
160 { 160 {
161 up = FALSE; 161 up = FALSE;
162 examineNetworks( TRUE ); 162 examineNetworks( TRUE );
163 QCopChannel* card = new QCopChannel("QPE/Card",parent); 163 QCopChannel* card = new QCopChannel("QPE/Card",parent);
164 connect(card,SIGNAL(received(const QCString&,const QByteArray&)), 164 connect(card,SIGNAL(received(const QCString&,const QByteArray&)),
165 this,SLOT(cardMessage(const QCString&,const QByteArray&))); 165 this,SLOT(cardMessage(const QCString&,const QByteArray&)));
166 } 166 }
167 167
168 ~NetworkServer() 168 ~NetworkServer()
169 { 169 {
170 stop(); 170 stop();
171 } 171 }
172 172
173 bool networkOnline() const 173 bool networkOnline() const
174 { 174 {
175 return up; 175 return up;
176 } 176 }
177 177
178private: 178private:
179 void receive(const QCString &msg, const QByteArray& data) 179 void receive(const QCString &msg, const QByteArray& data)
180 { 180 {
181 if ( msg == "start(QString,QString)" ) { 181 if ( msg == "start(QString,QString)" ) {
182 QDataStream stream(data,IO_ReadOnly); 182 QDataStream stream(data,IO_ReadOnly);
183 QString file,password; 183 QString file,password;
184 stream >> file >> password; 184 stream >> file >> password;
185 if ( file.isEmpty() ) { 185 if ( file.isEmpty() ) {
186 QStringList l = Network::choices(); 186 QStringList l = Network::choices();
187 for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) { 187 for (QStringList::ConstIterator i=l.begin(); i!=l.end(); ++i) {
188 Config cfg(*i,Config::File); 188 Config cfg(*i,Config::File);
189 cfg.setGroup("Info"); 189 cfg.setGroup("Info");
190 QString type = cfg.readEntry("Type"); 190 QString type = cfg.readEntry("Type");
191 NetworkInterface* plugin = Network::loadPlugin(type); 191 NetworkInterface* plugin = Network::loadPlugin(type);
192 cfg.setGroup("Properties"); 192 cfg.setGroup("Properties");
193 if ( plugin && plugin->isAvailable(cfg) ) { 193 if ( plugin && plugin->isAvailable(cfg) ) {
194 file = *i; 194 file = *i;
195 break; 195 break;
196 } 196 }
197 } 197 }
198 if ( file.isEmpty() ) { 198 if ( file.isEmpty() ) {
199 QCopEnvelope("QPE/Network", "failed()"); 199 QCopEnvelope("QPE/Network", "failed()");
200 return; 200 return;
201 } 201 }
202 } 202 }
203 start(file,password); 203 start(file,password);
204 } else if ( msg == "stop()" ) { 204 } else if ( msg == "stop()" ) {
205 stop(); 205 stop();
206 } else if ( msg == "choicesChanged()" ) { 206 } else if ( msg == "choicesChanged()" ) {
207 examineNetworks(); 207 examineNetworks();
208 } 208 }
209 } 209 }
210 210
211private slots: 211private slots:
212 void cardMessage(const QCString &msg, const QByteArray&) 212 void cardMessage(const QCString &msg, const QByteArray&)
213 { 213 {
214 if ( msg == "stabChanged()" ) 214 if ( msg == "stabChanged()" )
215 examineNetworks(); 215 examineNetworks();
216 } 216 }
217 217
218private: 218private:
219 void examineNetworks( bool firstStart = FALSE ) 219 void examineNetworks( bool firstStart = FALSE )
220 { 220 {
221 QStringList l = Network::choices(); 221 QStringList l = Network::choices();
222 bool wasup = up; up=FALSE; 222 bool wasup = up; up=FALSE;
223 QStringList pavailable = available; 223 QStringList pavailable = available;
224 available.clear(); 224 available.clear();
225 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { 225 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
226 Config cfg(*it,Config::File); 226 Config cfg(*it,Config::File);
227 cfg.setGroup("Info"); 227 cfg.setGroup("Info");
228 QString type = cfg.readEntry("Type"); 228 QString type = cfg.readEntry("Type");
229 NetworkInterface* plugin = Network::loadPlugin(type); 229 NetworkInterface* plugin = Network::loadPlugin(type);
230 cfg.setGroup("Properties"); 230 cfg.setGroup("Properties");
231 if ( plugin ) { 231 if ( plugin ) {
232 if ( plugin->isActive(cfg) ) { 232 if ( plugin->isActive(cfg) ) {
233 up = TRUE; 233 up = TRUE;
234 if ( firstStart ) 234 if ( firstStart )
235 plugin->start( cfg ); 235 plugin->start( cfg );
236 } 236 }
237 if ( plugin->isAvailable(cfg) ) 237 if ( plugin->isAvailable(cfg) )
238 available.append(*it); 238 available.append(*it);
239 } 239 }
240 } 240 }
241 241
242 // Try to work around unreproducible bug whereby 242 // Try to work around unreproducible bug whereby
243 // the netmon applet shows wrong state. 243 // the netmon applet shows wrong state.
244 bool reannounce = wait<0; 244 bool reannounce = wait<0;
245 245
246 if ( available != pavailable || reannounce ) { 246 if ( available != pavailable || reannounce ) {
247 QCopEnvelope e("QPE/Network", "available(QStringList)"); 247 QCopEnvelope e("QPE/Network", "available(QStringList)");
248 e << available; 248 e << available;
249 } 249 }
250 if ( up != wasup || reannounce ) { 250 if ( up != wasup || reannounce ) {
251 QCopEnvelope("QPE/Network", up ? "up()" : "down()"); 251 QCopEnvelope("QPE/Network", up ? "up()" : "down()");
252 } 252 }
253 } 253 }
254 254
255 void start( const QString& file, const QString& password ) 255 void start( const QString& file, const QString& password )
256 { 256 {
257 if ( !current.isEmpty() ) 257 if ( !current.isEmpty() )
258 stop(); 258 stop();
259 current = QString::null; 259 current = QString::null;
260 Config cfg(file, Config::File); 260 Config cfg(file, Config::File);
261 cfg.setGroup("Info"); 261 cfg.setGroup("Info");
262 QString type = cfg.readEntry("Type"); 262 QString type = cfg.readEntry("Type");
263 NetworkInterface* plugin = Network::loadPlugin(type); 263 NetworkInterface* plugin = Network::loadPlugin(type);
264 bool started = FALSE; 264 bool started = FALSE;
265 if ( plugin ) { 265 if ( plugin ) {
266 cfg.setGroup("Properties"); 266 cfg.setGroup("Properties");
267 if ( plugin->start(cfg,password) ) { 267 if ( plugin->start(cfg,password) ) {
268 Network::writeProxySettings( cfg ); 268 Network::writeProxySettings( cfg );
269 current = file; 269 current = file;
270 wait=0; 270 wait=0;
271 startTimer(400); 271 startTimer(400);
272 started = TRUE; 272 started = TRUE;
273 } 273 }
274 } 274 }
275 if ( !started ) { 275 if ( !started ) {
276 QCopEnvelope("QPE/Network", "failed()"); 276 QCopEnvelope("QPE/Network", "failed()");
277 } 277 }
278 } 278 }
279 279
280 void stop() 280 void stop()
281 { 281 {
282 bool stopped = FALSE; 282 bool stopped = FALSE;
283 if ( !current.isEmpty() ) { 283 if ( !current.isEmpty() ) {
284 Config cfg(current, Config::File); 284 Config cfg(current, Config::File);
285 cfg.setGroup("Info"); 285 cfg.setGroup("Info");
286 QString type = cfg.readEntry("Type"); 286 QString type = cfg.readEntry("Type");
287 NetworkInterface* plugin = Network::loadPlugin(type); 287 NetworkInterface* plugin = Network::loadPlugin(type);
288 if ( plugin ) { 288 if ( plugin ) {
289 cfg.setGroup("Properties"); 289 cfg.setGroup("Properties");
290 if ( plugin->stop(cfg) ) { 290 if ( plugin->stop(cfg) ) {
291 current = QString::null; 291 current = QString::null;
292 wait=0; 292 wait=0;
293 startTimer(400); 293 startTimer(400);
294 stopped = TRUE; 294 stopped = TRUE;
295 } 295 }
296 } 296 }
297 } 297 }
298 if ( !stopped ) { 298 if ( !stopped ) {
299 QCopEnvelope("QPE/Network", "failed()"); 299 QCopEnvelope("QPE/Network", "failed()");
300 } 300 }
301 } 301 }
302 302
303 void timerEvent(QTimerEvent*) 303 void timerEvent(QTimerEvent*)
304 { 304 {
305 examineNetworks(); 305 examineNetworks();
306 if ( wait >= 0 ) { 306 if ( wait >= 0 ) {
307 if ( up == !current.isNull() ) { 307 if ( up == !current.isNull() ) {
308 // done 308 // done
309 killTimers(); 309 killTimers();
310 if ( up ) { 310 if ( up ) {
311 startTimer(3000); // monitor link 311 startTimer(3000); // monitor link
312 wait = -1; 312 wait = -1;
313 } 313 }
314 } else { 314 } else {
315 wait++; 315 wait++;
316 if ( wait == 600 ) { 316 if ( wait == 600 ) {
317 killTimers(); // forget about it after 240 s 317 killTimers(); // forget about it after 240 s
318 QCopEnvelope("QPE/Network", "failed()"); 318 QCopEnvelope("QPE/Network", "failed()");
319 up = !current.isNull(); 319 up = !current.isNull();
320 } 320 }
321 } 321 }
322 } else if ( !up ) { 322 } else if ( !up ) {
323 killTimers(); 323 killTimers();
324 } 324 }
325 } 325 }
326 326
327private: 327private:
328 QStringList available; 328 QStringList available;
329 QString current; 329 QString current;
330 bool up; 330 bool up;
331 int wait; 331 int wait;
332}; 332};
333 333
334static NetworkServer* ns=0; 334static NetworkServer* ns=0;
335 335
336/*! 336/*!
337 \internal 337 \internal
338*/ 338*/
339QString Network::serviceName(const QString& service) 339QString Network::serviceName(const QString& service)
340{ 340{
341 Config cfg(service, Config::File); 341 Config cfg(service, Config::File);
342 cfg.setGroup("Info"); 342 cfg.setGroup("Info");
343 return cfg.readEntry("Name"); 343 return cfg.readEntry("Name");
344} 344}
345 345
346/*! 346/*!
347 \internal 347 \internal
348*/ 348*/
349QString Network::serviceType(const QString& service) 349QString Network::serviceType(const QString& service)
350{ 350{
351 Config cfg(service, Config::File); 351 Config cfg(service, Config::File);
352 cfg.setGroup("Info"); 352 cfg.setGroup("Info");
353 return cfg.readEntry("Type"); 353 return cfg.readEntry("Type");
354} 354}
355 355
356/*! 356/*!
357 \internal 357 \internal
358*/ 358*/
359bool Network::serviceNeedsPassword(const QString& service) 359bool Network::serviceNeedsPassword(const QString& service)
360{ 360{
361 Config cfg(service,Config::File); 361 Config cfg(service,Config::File);
362 cfg.setGroup("Info"); 362 cfg.setGroup("Info");
363 QString type = cfg.readEntry("Type"); 363 QString type = cfg.readEntry("Type");
364 NetworkInterface* plugin = Network::loadPlugin(type); 364 NetworkInterface* plugin = Network::loadPlugin(type);
365 cfg.setGroup("Properties"); 365 cfg.setGroup("Properties");
366 return plugin ? plugin->needPassword(cfg) : FALSE; 366 return plugin ? plugin->needPassword(cfg) : FALSE;
367} 367}
368 368
369/*! 369/*!
370 \internal 370 \internal
371*/ 371*/
372bool Network::networkOnline() 372bool Network::networkOnline()
373{ 373{
374 return ns && ns->networkOnline(); 374 return ns && ns->networkOnline();
375} 375}
376 376
377/*! 377/*!
378 \internal 378 \internal
379*/ 379*/
380void Network::createServer(QObject* parent) 380void Network::createServer(QObject* parent)
381{ 381{
382 ns = new NetworkServer(parent); 382 ns = new NetworkServer(parent);
383} 383}
384 384
385/*! 385/*!
386 \internal 386 \internal
387*/ 387*/
388int Network::addStateWidgets(QWidget* parent) 388int Network::addStateWidgets(QWidget* parent)
389{ 389{
390 int n=0; 390 int n=0;
391 QStringList l = Network::choices(); 391 QStringList l = Network::choices();
392 QVBoxLayout* vb = new QVBoxLayout(parent); 392 QVBoxLayout* vb = new QVBoxLayout(parent);
393 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { 393 for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) {
394 Config cfg(*it,Config::File); 394 Config cfg(*it,Config::File);
395 cfg.setGroup("Info"); 395 cfg.setGroup("Info");
396 QString type = cfg.readEntry("Type"); 396 QString type = cfg.readEntry("Type");
397 NetworkInterface* plugin = Network::loadPlugin(type); 397 NetworkInterface* plugin = Network::loadPlugin(type);
398 cfg.setGroup("Properties"); 398 cfg.setGroup("Properties");
399 if ( plugin ) { 399 if ( plugin ) {
400 QWidget* w; 400 QWidget* w;
401 if ( (w=plugin->addStateWidget(parent,cfg)) ) { 401 if ( (w=plugin->addStateWidget(parent,cfg)) ) {
402 n++; 402 n++;
403 vb->addWidget(w); 403 vb->addWidget(w);
404 } 404 }
405 } 405 }
406 } 406 }
407 return n; 407 return n;
408} 408}
409 409
410static QDict<NetworkInterface> *ifaces; 410static QDict<NetworkInterface> *ifaces;
411 411
412/*! 412/*!
413 \internal 413 \internal
414*/ 414*/
415NetworkInterface* Network::loadPlugin(const QString& type) 415NetworkInterface* Network::loadPlugin(const QString& type)
416{ 416{
417#ifndef QT_NO_COMPONENT 417#ifndef QT_NO_COMPONENT
418 if ( !ifaces ) ifaces = new QDict<NetworkInterface>; 418 if ( !ifaces ) ifaces = new QDict<NetworkInterface>;
419 NetworkInterface *iface = ifaces->find(type); 419 NetworkInterface *iface = ifaces->find(type);
420 if ( !iface ) { 420 if ( !iface ) {
421#ifdef Q_OS_MACX 421#ifdef Q_OS_MACX
422 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".dylib"; 422 QString libfile = QPEApplication::qpeDir() + "plugins/network/lib" + type + ".dylib";
423#else 423#else
424 QString libfile = QPEApplication::qpeDir() + "/plugins/network/lib" + type + ".so"; 424 QString libfile = QPEApplication::qpeDir() + "plugins/network/lib" + type + ".so";
425#endif 425#endif
426 QLibrary lib(libfile); 426 QLibrary lib(libfile);
427 if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK ) 427 if ( !lib.queryInterface( IID_Network, (QUnknownInterface**)&iface ) == QS_OK )
428 return 0; 428 return 0;
429 ifaces->insert(type,iface); 429 ifaces->insert(type,iface);
430 QStringList langs = Global::languageList(); 430 QStringList langs = Global::languageList();
431 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) { 431 for (QStringList::ConstIterator it = langs.begin(); it!=langs.end(); ++it) {
432 QString lang = *it; 432 QString lang = *it;
433 QTranslator * trans = new QTranslator(qApp); 433 QTranslator * trans = new QTranslator(qApp);
434 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/lib"+type+".qm"; 434 QString tfn = QPEApplication::qpeDir()+"i18n/"+lang+"/lib"+type+".qm";
435 if ( trans->load( tfn )) 435 if ( trans->load( tfn ))
436 qApp->installTranslator( trans ); 436 qApp->installTranslator( trans );
437 else 437 else
438 delete trans; 438 delete trans;
439 } 439 }
440 } 440 }
441 return iface; 441 return iface;
442#else 442#else
443 return 0; 443 return 0;
444#endif 444#endif
445} 445}
446 446
447#include "network.moc" 447#include "network.moc"
448 #endif// QT_NO_COP 448 #endif// QT_NO_COP
diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp
index 7842ebd..8b02de6 100644
--- a/library/qpedecoration_qws.cpp
+++ b/library/qpedecoration_qws.cpp
@@ -1,967 +1,967 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifdef QWS 20#ifdef QWS
21#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qstyle.h> 23#include <qstyle.h>
24#include <qwidget.h> 24#include <qwidget.h>
25#include <qpainter.h> 25#include <qpainter.h>
26#include <qtimer.h> 26#include <qtimer.h>
27#include <qwhatsthis.h> 27#include <qwhatsthis.h>
28#include <qpopupmenu.h> 28#include <qpopupmenu.h>
29#include "qcopenvelope_qws.h" 29#include "qcopenvelope_qws.h"
30#include "qpedecoration_qws.h" 30#include "qpedecoration_qws.h"
31#include <qdialog.h> 31#include <qdialog.h>
32#include <qdrawutil.h> 32#include <qdrawutil.h>
33#include <qgfx_qws.h> 33#include <qgfx_qws.h>
34#include "qpeapplication.h" 34#include "qpeapplication.h"
35#include "resource.h" 35#include "resource.h"
36#include "global.h" 36#include "global.h"
37#include "qlibrary.h" 37#include "qlibrary.h"
38#include "windowdecorationinterface.h" 38#include "windowdecorationinterface.h"
39#include <qpe/qlibrary.h> 39#include <qpe/qlibrary.h>
40#include <qfile.h> 40#include <qfile.h>
41#include <qsignal.h> 41#include <qsignal.h>
42 42
43#include <stdlib.h> 43#include <stdlib.h>
44 44
45extern Q_EXPORT QRect qt_maxWindowRect; 45extern Q_EXPORT QRect qt_maxWindowRect;
46 46
47#define WHATSTHIS_MODE 47#define WHATSTHIS_MODE
48 48
49#ifndef QT_NO_QWS_QPE_WM_STYLE 49#ifndef QT_NO_QWS_QPE_WM_STYLE
50 50
51#ifndef QT_NO_IMAGEIO_XPM 51#ifndef QT_NO_IMAGEIO_XPM
52 52
53/* XPM */ 53/* XPM */
54static const char * const qpe_close_xpm[] = { 54static const char * const qpe_close_xpm[] = {
55"16 16 3 1", 55"16 16 3 1",
56" c None", 56" c None",
57". c #FFFFFF", 57". c #FFFFFF",
58"+ c #000000", 58"+ c #000000",
59" ", 59" ",
60" ", 60" ",
61" ..... ", 61" ..... ",
62" ..+++++.. ", 62" ..+++++.. ",
63" .+++++++++. ", 63" .+++++++++. ",
64" .+..+++..+. ", 64" .+..+++..+. ",
65" .++...+...++. ", 65" .++...+...++. ",
66" .+++.....+++. ", 66" .+++.....+++. ",
67" .++++...++++. ", 67" .++++...++++. ",
68" .+++.....+++. ", 68" .+++.....+++. ",
69" .++...+...++. ", 69" .++...+...++. ",
70" .+..+++..+. ", 70" .+..+++..+. ",
71" .+++++++++. ", 71" .+++++++++. ",
72" ..+++++.. ", 72" ..+++++.. ",
73" ..... ", 73" ..... ",
74" "}; 74" "};
75 75
76/* XPM */ 76/* XPM */
77static const char * const qpe_accept_xpm[] = { 77static const char * const qpe_accept_xpm[] = {
78"16 16 3 1", 78"16 16 3 1",
79" c None", 79" c None",
80". c #FFFFFF", 80". c #FFFFFF",
81"+ c #000000", 81"+ c #000000",
82" ", 82" ",
83" ", 83" ",
84" ..... ", 84" ..... ",
85" ..+++++.. ", 85" ..+++++.. ",
86" .+++++++++. ", 86" .+++++++++. ",
87" .+++++++++. ", 87" .+++++++++. ",
88" .+++++++..++. ", 88" .+++++++..++. ",
89" .++.+++...++. ", 89" .++.+++...++. ",
90" .+...+...+++. ", 90" .+...+...+++. ",
91" .+......++++. ", 91" .+......++++. ",
92" .++....+++++. ", 92" .++....+++++. ",
93" .++..+++++. ", 93" .++..+++++. ",
94" .+++++++++. ", 94" .+++++++++. ",
95" ..+++++.. ", 95" ..+++++.. ",
96" ..... ", 96" ..... ",
97" "}; 97" "};
98 98
99#endif // QT_NO_IMAGEIO_XPM 99#endif // QT_NO_IMAGEIO_XPM
100 100
101class DecorHackWidget : public QWidget 101class DecorHackWidget : public QWidget
102{ 102{
103public: 103public:
104 bool needsOk() { 104 bool needsOk() {
105 return (getWState() & WState_Reserved1 ) || 105 return (getWState() & WState_Reserved1 ) ||
106 (inherits("QDialog") && !inherits("QMessageBox") 106 (inherits("QDialog") && !inherits("QMessageBox")
107 && !inherits("QWizard") ); 107 && !inherits("QWizard") );
108 } 108 }
109}; 109};
110 110
111static QImage scaleButton( const QImage &img, int height ) 111static QImage scaleButton( const QImage &img, int height )
112{ 112{
113 if ( img.height() != 0 && img.height() != height ) { 113 if ( img.height() != 0 && img.height() != height ) {
114 return img.smoothScale( img.width()*height/img.height(), height ); 114 return img.smoothScale( img.width()*height/img.height(), height );
115 } else { 115 } else {
116 return img; 116 return img;
117 } 117 }
118} 118}
119 119
120class TLWidget : public QWidget 120class TLWidget : public QWidget
121{ 121{
122public: 122public:
123 QWSManager *manager() 123 QWSManager *manager()
124 { 124 {
125 return topData()->qwsManager; 125 return topData()->qwsManager;
126 } 126 }
127 127
128 QTLWExtra *topExtra() 128 QTLWExtra *topExtra()
129 { 129 {
130 return topData(); 130 return topData();
131 } 131 }
132 132
133 void setWState( uint s ) { QWidget::setWState( s ); } 133 void setWState( uint s ) { QWidget::setWState( s ); }
134 void clearWState( uint s ) { QWidget::clearWState( s ); } 134 void clearWState( uint s ) { QWidget::clearWState( s ); }
135}; 135};
136 136
137 137
138QPEManager::QPEManager( QPEDecoration *d, QObject *parent ) 138QPEManager::QPEManager( QPEDecoration *d, QObject *parent )
139 : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE) 139 : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE)
140{ 140{
141 wtTimer = new QTimer( this ); 141 wtTimer = new QTimer( this );
142 connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) ); 142 connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) );
143} 143}
144 144
145 145
146void QPEManager::updateActive() 146void QPEManager::updateActive()
147{ 147{
148 QWidget *newActive = qApp->activeWindow(); 148 QWidget *newActive = qApp->activeWindow();
149 if ( newActive && (QWidget*)active == newActive ) 149 if ( newActive && (QWidget*)active == newActive )
150 return; 150 return;
151 151
152 if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) { 152 if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) {
153 ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this ); 153 ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this );
154 } 154 }
155 155
156 if ( newActive && ((TLWidget *)newActive)->manager() ) { 156 if ( newActive && ((TLWidget *)newActive)->manager() ) {
157 active = newActive; 157 active = newActive;
158 ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this ); 158 ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this );
159 } else if ( !newActive ) { 159 } else if ( !newActive ) {
160 active = 0; 160 active = 0;
161 } 161 }
162} 162}
163 163
164int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p ) 164int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p )
165{ 165{
166 QRect rect(w->geometry()); 166 QRect rect(w->geometry());
167 167
168 if ( decoration->region( w, rect, 168 if ( decoration->region( w, rect,
169 (QWSDecoration::Region)QPEDecoration::Help ).contains(p) ) 169 (QWSDecoration::Region)QPEDecoration::Help ).contains(p) )
170 return QPEDecoration::Help; 170 return QPEDecoration::Help;
171 171
172 for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) { 172 for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) {
173 if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p)) 173 if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p))
174 return (QWSDecoration::Region)i; 174 return (QWSDecoration::Region)i;
175 } 175 }
176 176
177 return QWSDecoration::None; 177 return QWSDecoration::None;
178} 178}
179 179
180bool QPEManager::eventFilter( QObject *o, QEvent *e ) 180bool QPEManager::eventFilter( QObject *o, QEvent *e )
181{ 181{
182 QWSManager *mgr = (QWSManager *)o; 182 QWSManager *mgr = (QWSManager *)o;
183 QWidget *w = mgr->widget(); 183 QWidget *w = mgr->widget();
184 switch ( e->type() ) { 184 switch ( e->type() ) {
185 case QEvent::MouseButtonPress: 185 case QEvent::MouseButtonPress:
186 { 186 {
187 pressTime = QTime::currentTime(); 187 pressTime = QTime::currentTime();
188 QPoint p = ((QMouseEvent*)e)->globalPos(); 188 QPoint p = ((QMouseEvent*)e)->globalPos();
189 int inRegion = pointInQpeRegion( w, p ); 189 int inRegion = pointInQpeRegion( w, p );
190#ifdef WHATSTHIS_MODE 190#ifdef WHATSTHIS_MODE
191 if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) { 191 if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) {
192 QString text; 192 QString text;
193 switch ( inRegion ) { 193 switch ( inRegion ) {
194 case QWSDecoration::Close: 194 case QWSDecoration::Close:
195 if ( ((DecorHackWidget*)w)->needsOk() ) 195 if ( ((DecorHackWidget*)w)->needsOk() )
196 text = tr("Click to close this window, discarding changes."); 196 text = tr("Click to close this window, discarding changes.");
197 else 197 else
198 text = tr("Click to close this window."); 198 text = tr("Click to close this window.");
199 break; 199 break;
200 case QWSDecoration::Minimize: 200 case QWSDecoration::Minimize:
201 text = tr("Click to close this window and apply changes."); 201 text = tr("Click to close this window and apply changes.");
202 break; 202 break;
203 case QWSDecoration::Maximize: 203 case QWSDecoration::Maximize:
204 if ( w->isMaximized() ) 204 if ( w->isMaximized() )
205 text = tr("Click to make this window movable."); 205 text = tr("Click to make this window movable.");
206 else 206 else
207 text = tr("Click to make this window use all available screen area."); 207 text = tr("Click to make this window use all available screen area.");
208 break; 208 break;
209 default: 209 default:
210 break; 210 break;
211 } 211 }
212 QWhatsThis::leaveWhatsThisMode( text ); 212 QWhatsThis::leaveWhatsThisMode( text );
213 whatsThisTimeout(); 213 whatsThisTimeout();
214 helpState = 0; 214 helpState = 0;
215 return true; 215 return true;
216 } 216 }
217#endif 217#endif
218 if ( inRegion == QPEDecoration::Help ) { 218 if ( inRegion == QPEDecoration::Help ) {
219#ifdef WHATSTHIS_MODE 219#ifdef WHATSTHIS_MODE
220 wtTimer->start( 400, TRUE ); 220 wtTimer->start( 400, TRUE );
221#endif 221#endif
222 helpState = QWSButton::Clicked|QWSButton::MouseOver; 222 helpState = QWSButton::Clicked|QWSButton::MouseOver;
223 drawButton( w, QPEDecoration::Help, helpState ); 223 drawButton( w, QPEDecoration::Help, helpState );
224 return true; 224 return true;
225 } 225 }
226 } 226 }
227 break; 227 break;
228 case QEvent::MouseButtonRelease: 228 case QEvent::MouseButtonRelease:
229 if ( helpState & QWSButton::Clicked ) { 229 if ( helpState & QWSButton::Clicked ) {
230 wtTimer->stop(); 230 wtTimer->stop();
231 helpState = 0; 231 helpState = 0;
232 drawButton( w, QPEDecoration::Help, helpState ); 232 drawButton( w, QPEDecoration::Help, helpState );
233 QPoint p = ((QMouseEvent*)e)->globalPos(); 233 QPoint p = ((QMouseEvent*)e)->globalPos();
234 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { 234 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
235 decoration->help( w ); 235 decoration->help( w );
236 } 236 }
237 return true; 237 return true;
238 } 238 }
239 break; 239 break;
240 case QEvent::MouseMove: 240 case QEvent::MouseMove:
241 if ( helpState & QWSButton::Clicked ) { 241 if ( helpState & QWSButton::Clicked ) {
242 int oldState = helpState; 242 int oldState = helpState;
243 QPoint p = ((QMouseEvent*)e)->globalPos(); 243 QPoint p = ((QMouseEvent*)e)->globalPos();
244 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { 244 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
245 helpState = QWSButton::Clicked|QWSButton::MouseOver; 245 helpState = QWSButton::Clicked|QWSButton::MouseOver;
246 } else { 246 } else {
247 helpState = 0; 247 helpState = 0;
248 } 248 }
249 if ( helpState != oldState ) 249 if ( helpState != oldState )
250 drawButton( w, QPEDecoration::Help, helpState ); 250 drawButton( w, QPEDecoration::Help, helpState );
251 } 251 }
252 break; 252 break;
253 default: 253 default:
254 break; 254 break;
255 } 255 }
256 return QObject::eventFilter( o, e ); 256 return QObject::eventFilter( o, e );
257} 257}
258 258
259void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state ) 259void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state )
260{ 260{
261 QPainter painter(w); 261 QPainter painter(w);
262 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; 262 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
263 painter.internalGfx()->setWidgetDeviceRegion( rgn ); 263 painter.internalGfx()->setWidgetDeviceRegion( rgn );
264 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); 264 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
265 decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state ); 265 decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state );
266} 266}
267 267
268void QPEManager::drawTitle( QWidget *w ) 268void QPEManager::drawTitle( QWidget *w )
269{ 269{
270 QPainter painter(w); 270 QPainter painter(w);
271 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; 271 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
272 painter.internalGfx()->setWidgetDeviceRegion( rgn ); 272 painter.internalGfx()->setWidgetDeviceRegion( rgn );
273 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); 273 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
274 decoration->paint( &painter, w ); 274 decoration->paint( &painter, w );
275 decoration->paintButton(&painter, w, QWSDecoration::Menu, 0); 275 decoration->paintButton(&painter, w, QWSDecoration::Menu, 0);
276 decoration->paintButton(&painter, w, QWSDecoration::Close, 0); 276 decoration->paintButton(&painter, w, QWSDecoration::Close, 0);
277 decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0); 277 decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0);
278 decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0); 278 decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0);
279} 279}
280 280
281void QPEManager::whatsThisTimeout() 281void QPEManager::whatsThisTimeout()
282{ 282{
283 if ( !QWhatsThis::inWhatsThisMode() ) { 283 if ( !QWhatsThis::inWhatsThisMode() ) {
284 if ( inWhatsThis ) { 284 if ( inWhatsThis ) {
285 if ( whatsThis ) { 285 if ( whatsThis ) {
286 QWidget *w = whatsThis; 286 QWidget *w = whatsThis;
287 whatsThis = 0; 287 whatsThis = 0;
288 drawTitle( w ); 288 drawTitle( w );
289 } 289 }
290 wtTimer->stop(); 290 wtTimer->stop();
291 } else { 291 } else {
292 QWhatsThis::enterWhatsThisMode(); 292 QWhatsThis::enterWhatsThisMode();
293 helpState = 0; 293 helpState = 0;
294 updateActive(); 294 updateActive();
295 if ( active ) { 295 if ( active ) {
296 whatsThis = active; 296 whatsThis = active;
297 drawTitle( active ); 297 drawTitle( active );
298 // check periodically to see if we've left whats this mode 298 // check periodically to see if we've left whats this mode
299 wtTimer->start( 250 ); 299 wtTimer->start( 250 );
300 } 300 }
301 } 301 }
302 inWhatsThis = !inWhatsThis; 302 inWhatsThis = !inWhatsThis;
303 } 303 }
304} 304}
305 305
306//=========================================================================== 306//===========================================================================
307 307
308static QImage *okImage( int th ) 308static QImage *okImage( int th )
309{ 309{
310 static QImage *i = 0; 310 static QImage *i = 0;
311 if ( !i || i->height() != th ) { 311 if ( !i || i->height() != th ) {
312 delete i; 312 delete i;
313 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th)); 313 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th));
314 } 314 }
315 return i; 315 return i;
316} 316}
317 317
318static QImage *closeImage( int th ) 318static QImage *closeImage( int th )
319{ 319{
320 static QImage *i = 0; 320 static QImage *i = 0;
321 if ( !i || i->height() != th ) { 321 if ( !i || i->height() != th ) {
322 delete i; 322 delete i;
323 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th)); 323 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th));
324 } 324 }
325 return i; 325 return i;
326} 326}
327 327
328static QImage *helpImage( int th ) 328static QImage *helpImage( int th )
329{ 329{
330 static QImage *i = 0; 330 static QImage *i = 0;
331 if ( !i || i->height() != th ) { 331 if ( !i || i->height() != th ) {
332 delete i; 332 delete i;
333 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th)); 333 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th));
334 } 334 }
335 return i; 335 return i;
336} 336}
337 337
338static QImage *maximizeImage( int th ) 338static QImage *maximizeImage( int th )
339{ 339{
340 static QImage *i = 0; 340 static QImage *i = 0;
341 if ( !i || i->height() != th ) { 341 if ( !i || i->height() != th ) {
342 delete i; 342 delete i;
343 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th)); 343 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th));
344 } 344 }
345 return i; 345 return i;
346} 346}
347 347
348int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const 348int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const
349{ 349{
350 switch ( m ) { 350 switch ( m ) {
351 case TitleHeight: 351 case TitleHeight:
352 if ( QApplication::desktop()->height() > 320 ) 352 if ( QApplication::desktop()->height() > 320 )
353 return 19; 353 return 19;
354 else 354 else
355 return 15; 355 return 15;
356 case LeftBorder: 356 case LeftBorder:
357 case RightBorder: 357 case RightBorder:
358 case TopBorder: 358 case TopBorder:
359 case BottomBorder: 359 case BottomBorder:
360 return 4; 360 return 4;
361 case OKWidth: 361 case OKWidth:
362 return okImage(metric(TitleHeight,wd))->width(); 362 return okImage(metric(TitleHeight,wd))->width();
363 case CloseWidth: 363 case CloseWidth:
364 return closeImage(metric(TitleHeight,wd))->width(); 364 return closeImage(metric(TitleHeight,wd))->width();
365 case HelpWidth: 365 case HelpWidth:
366 return helpImage(metric(TitleHeight,wd))->width(); 366 return helpImage(metric(TitleHeight,wd))->width();
367 case MaximizeWidth: 367 case MaximizeWidth:
368 return maximizeImage(metric(TitleHeight,wd))->width(); 368 return maximizeImage(metric(TitleHeight,wd))->width();
369 case CornerGrabSize: 369 case CornerGrabSize:
370 return 16; 370 return 16;
371 } 371 }
372 372
373 return 0; 373 return 0;
374} 374}
375 375
376void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const 376void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const
377{ 377{
378 int th = metric( TitleHeight, wd ); 378 int th = metric( TitleHeight, wd );
379 QRect r = wd->rect; 379 QRect r = wd->rect;
380 380
381 switch ( a ) { 381 switch ( a ) {
382 case Border: 382 case Border:
383 { 383 {
384 const QColorGroup &cg = wd->palette.active(); 384 const QColorGroup &cg = wd->palette.active();
385 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd), 385 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd),
386 r.y()-th-metric(TopBorder,wd), 386 r.y()-th-metric(TopBorder,wd),
387 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd), 387 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd),
388 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd), 388 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd),
389 cg, FALSE, &cg.brush(QColorGroup::Background)); 389 cg, FALSE, &cg.brush(QColorGroup::Background));
390 } 390 }
391 break; 391 break;
392 case Title: 392 case Title:
393 { 393 {
394 const QColorGroup &cg = wd->palette.active(); 394 const QColorGroup &cg = wd->palette.active();
395 QBrush titleBrush; 395 QBrush titleBrush;
396 QPen titleLines; 396 QPen titleLines;
397 397
398 if ( wd->flags & WindowData::Active ) { 398 if ( wd->flags & WindowData::Active ) {
399 titleBrush = cg.brush(QColorGroup::Highlight); 399 titleBrush = cg.brush(QColorGroup::Highlight);
400 titleLines = titleBrush.color().dark(); 400 titleLines = titleBrush.color().dark();
401 } else { 401 } else {
402 titleBrush = cg.brush(QColorGroup::Background); 402 titleBrush = cg.brush(QColorGroup::Background);
403 titleLines = titleBrush.color(); 403 titleLines = titleBrush.color();
404 } 404 }
405 405
406 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush); 406 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush);
407 407
408 p->setPen( titleLines ); 408 p->setPen( titleLines );
409 for ( int i = r.y()-th; i < r.y(); i += 2 ) 409 for ( int i = r.y()-th; i < r.y(); i += 2 )
410 p->drawLine( r.left(), i, r.right(), i ); 410 p->drawLine( r.left(), i, r.right(), i );
411 } 411 }
412 break; 412 break;
413 case TitleText: 413 case TitleText:
414 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th, 414 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th,
415 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd), 415 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd),
416 th, QPainter::AlignVCenter, wd->caption); 416 th, QPainter::AlignVCenter, wd->caption);
417 break; 417 break;
418 } 418 }
419} 419}
420 420
421void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const 421void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const
422{ 422{
423 QImage *img = 0; 423 QImage *img = 0;
424 switch ( b ) { 424 switch ( b ) {
425 case OK: 425 case OK:
426 img = okImage(metric(TitleHeight,wd)); 426 img = okImage(metric(TitleHeight,wd));
427 break; 427 break;
428 case Close: 428 case Close:
429 img = closeImage(metric(TitleHeight,wd)); 429 img = closeImage(metric(TitleHeight,wd));
430 break; 430 break;
431 case Help: 431 case Help:
432 img = helpImage(metric(TitleHeight,wd)); 432 img = helpImage(metric(TitleHeight,wd));
433 break; 433 break;
434 case Maximize: 434 case Maximize:
435 img = maximizeImage(metric(TitleHeight,wd)); 435 img = maximizeImage(metric(TitleHeight,wd));
436 break; 436 break;
437 } 437 }
438 438
439 if ( img ) { 439 if ( img ) {
440 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked)) 440 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked))
441 p->drawImage(x+2, y+2, *img); 441 p->drawImage(x+2, y+2, *img);
442 else 442 else
443 p->drawImage(x+1, y+1, *img); 443 p->drawImage(x+1, y+1, *img);
444 } 444 }
445} 445}
446 446
447QRegion WindowDecorationInterface::mask( const WindowData *wd ) const 447QRegion WindowDecorationInterface::mask( const WindowData *wd ) const
448{ 448{
449 int th = metric(TitleHeight,wd); 449 int th = metric(TitleHeight,wd);
450 QRect rect( wd->rect ); 450 QRect rect( wd->rect );
451 QRect r(rect.left() - metric(LeftBorder,wd), 451 QRect r(rect.left() - metric(LeftBorder,wd),
452 rect.top() - th - metric(TopBorder,wd), 452 rect.top() - th - metric(TopBorder,wd),
453 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd), 453 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd),
454 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd)); 454 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd));
455 return QRegion(r) - rect; 455 return QRegion(r) - rect;
456} 456}
457 457
458class DefaultWindowDecoration : public WindowDecorationInterface 458class DefaultWindowDecoration : public WindowDecorationInterface
459{ 459{
460public: 460public:
461 DefaultWindowDecoration(){} 461 DefaultWindowDecoration(){}
462 QString name() const { 462 QString name() const {
463 return qApp->translate("WindowDecoration", "Default", 463 return qApp->translate("WindowDecoration", "Default",
464 "List box text for default window decoration"); 464 "List box text for default window decoration");
465 } 465 }
466 QPixmap icon() const { 466 QPixmap icon() const {
467 return QPixmap(); 467 return QPixmap();
468 } 468 }
469 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { 469 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
470 *iface = 0; 470 *iface = 0;
471 if ( uuid == IID_QUnknown ) 471 if ( uuid == IID_QUnknown )
472 *iface = this; 472 *iface = this;
473 else if ( uuid == IID_WindowDecoration ) 473 else if ( uuid == IID_WindowDecoration )
474 *iface = this; 474 *iface = this;
475 else 475 else
476 return QS_FALSE; 476 return QS_FALSE;
477 477
478 if ( *iface ) 478 if ( *iface )
479 (*iface)->addRef(); 479 (*iface)->addRef();
480 return QS_OK; 480 return QS_OK;
481 } 481 }
482 Q_REFCOUNT 482 Q_REFCOUNT
483 483
484}; 484};
485 485
486static WindowDecorationInterface *wdiface = 0; 486static WindowDecorationInterface *wdiface = 0;
487static QLibrary* wdlib = 0; 487static QLibrary* wdlib = 0;
488static QString libname; 488static QString libname;
489 489
490//=========================================================================== 490//===========================================================================
491bool QPEDecoration::helpExists() const 491bool QPEDecoration::helpExists() const
492{ 492{
493 if ( helpFile.isNull() ) { 493 if ( helpFile.isNull() ) {
494 QStringList helpPath = Global::helpPath(); 494 QStringList helpPath = Global::helpPath();
495 QString hf = QString(qApp->argv()[0]) + ".html"; 495 QString hf = QString(qApp->argv()[0]) + ".html";
496 bool he = FALSE; 496 bool he = FALSE;
497 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !he; ++it) 497 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !he; ++it)
498 he = QFile::exists( *it + "/" + hf ); 498 he = QFile::exists( *it + "/" + hf );
499 ((QPEDecoration*)this)->helpFile = hf; 499 ((QPEDecoration*)this)->helpFile = hf;
500 ((QPEDecoration*)this)->helpexists = he; 500 ((QPEDecoration*)this)->helpexists = he;
501 return he; 501 return he;
502 } 502 }
503 return helpexists; 503 return helpexists;
504} 504}
505 505
506QPEDecoration::QPEDecoration() 506QPEDecoration::QPEDecoration()
507 : QWSDefaultDecoration() 507 : QWSDefaultDecoration()
508{ 508{
509 if ( wdlib ) { 509 if ( wdlib ) {
510 delete wdlib; 510 delete wdlib;
511 wdlib = 0; 511 wdlib = 0;
512 } else { 512 } else {
513 delete wdiface; 513 delete wdiface;
514 } 514 }
515 wdiface = new DefaultWindowDecoration; 515 wdiface = new DefaultWindowDecoration;
516 516
517 helpexists = FALSE; // We don't know (flagged by helpFile being null) 517 helpexists = FALSE; // We don't know (flagged by helpFile being null)
518 qpeManager = new QPEManager( this ); 518 qpeManager = new QPEManager( this );
519 imageOk = Resource::loadImage( "OKButton" ); 519 imageOk = Resource::loadImage( "OKButton" );
520 imageClose = Resource::loadImage( "CloseButton" ); 520 imageClose = Resource::loadImage( "CloseButton" );
521 imageHelp = Resource::loadImage( "HelpButton" ); 521 imageHelp = Resource::loadImage( "HelpButton" );
522} 522}
523 523
524QPEDecoration::QPEDecoration( const QString &plugin ) 524QPEDecoration::QPEDecoration( const QString &plugin )
525 : QWSDefaultDecoration() 525 : QWSDefaultDecoration()
526{ 526{
527 libname = plugin; 527 libname = plugin;
528 528
529 if ( wdlib ) { 529 if ( wdlib ) {
530 wdiface->release(); 530 wdiface->release();
531 wdlib->unload(); 531 wdlib->unload();
532 delete wdlib; 532 delete wdlib;
533 wdlib = 0; 533 wdlib = 0;
534 } else { 534 } else {
535 delete wdiface; 535 delete wdiface;
536 } 536 }
537 537
538 WindowDecorationInterface *iface = 0; 538 WindowDecorationInterface *iface = 0;
539 QString path = QPEApplication::qpeDir() + "/plugins/decorations/"; 539 QString path = QPEApplication::qpeDir() + "plugins/decorations/";
540 540
541#ifdef Q_OS_MACX 541#ifdef Q_OS_MACX
542 if ( plugin.find( ".dylib" ) > 0 ) { 542 if ( plugin.find( ".dylib" ) > 0 ) {
543#else 543#else
544 if ( plugin.find( ".so" ) > 0 ) { 544 if ( plugin.find( ".so" ) > 0 ) {
545#endif 545#endif
546 // full library name supplied 546 // full library name supplied
547 path += plugin; 547 path += plugin;
548 } else { 548 } else {
549#ifdef Q_OS_MACX 549#ifdef Q_OS_MACX
550 path += "lib" + plugin.lower() + ".dylib"; // compatibility 550 path += "lib" + plugin.lower() + ".dylib"; // compatibility
551#else 551#else
552 path += "lib" + plugin.lower() + ".so"; // compatibility 552 path += "lib" + plugin.lower() + ".so"; // compatibility
553#endif 553#endif
554 } 554 }
555 555
556 QLibrary *lib = new QLibrary( path ); 556 QLibrary *lib = new QLibrary( path );
557 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 557 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
558 wdiface = iface; 558 wdiface = iface;
559 wdlib = lib; 559 wdlib = lib;
560 } else { 560 } else {
561 delete lib; 561 delete lib;
562 wdiface = new DefaultWindowDecoration; 562 wdiface = new DefaultWindowDecoration;
563 } 563 }
564 564
565 565
566 566
567 helpexists = FALSE; // We don't know (flagged by helpFile being null) 567 helpexists = FALSE; // We don't know (flagged by helpFile being null)
568 qpeManager = new QPEManager( this ); 568 qpeManager = new QPEManager( this );
569} 569}
570 570
571QPEDecoration::~QPEDecoration() 571QPEDecoration::~QPEDecoration()
572{ 572{
573 delete qpeManager; 573 delete qpeManager;
574} 574}
575 575
576const char **QPEDecoration::menuPixmap() 576const char **QPEDecoration::menuPixmap()
577{ 577{
578 return (const char **)0; 578 return (const char **)0;
579} 579}
580 580
581const char **QPEDecoration::closePixmap() 581const char **QPEDecoration::closePixmap()
582{ 582{
583 return (const char **)qpe_close_xpm; 583 return (const char **)qpe_close_xpm;
584} 584}
585 585
586const char **QPEDecoration::minimizePixmap() 586const char **QPEDecoration::minimizePixmap()
587{ 587{
588 return (const char **)qpe_accept_xpm; 588 return (const char **)qpe_accept_xpm;
589} 589}
590 590
591const char **QPEDecoration::maximizePixmap() 591const char **QPEDecoration::maximizePixmap()
592{ 592{
593 return (const char **)0; 593 return (const char **)0;
594} 594}
595 595
596const char **QPEDecoration::normalizePixmap() 596const char **QPEDecoration::normalizePixmap()
597{ 597{
598 return (const char **)0; 598 return (const char **)0;
599} 599}
600 600
601int QPEDecoration::getTitleHeight( const QWidget *w ) 601int QPEDecoration::getTitleHeight( const QWidget *w )
602{ 602{
603 WindowDecorationInterface::WindowData wd; 603 WindowDecorationInterface::WindowData wd;
604 windowData( w, wd ); 604 windowData( w, wd );
605 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 605 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
606} 606}
607 607
608/* 608/*
609 If rect is empty, no frame is added. (a hack, really) 609 If rect is empty, no frame is added. (a hack, really)
610*/ 610*/
611QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type) 611QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type)
612{ 612{
613 qpeManager->updateActive(); 613 qpeManager->updateActive();
614 614
615 WindowDecorationInterface::WindowData wd; 615 WindowDecorationInterface::WindowData wd;
616 windowData( widget, wd ); 616 windowData( widget, wd );
617 wd.rect = rect; 617 wd.rect = rect;
618 618
619 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 619 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
620 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd); 620 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd);
621 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd); 621 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd);
622 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd); 622 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd);
623 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd); 623 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd);
624 624
625 QRegion region; 625 QRegion region;
626 626
627 switch ((int)type) { 627 switch ((int)type) {
628 case Menu: 628 case Menu:
629 break; 629 break;
630 case Maximize: 630 case Maximize:
631 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) { 631 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) {
632 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd); 632 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd);
633 int left = rect.right() - maximizeWidth - closeWidth; 633 int left = rect.right() - maximizeWidth - closeWidth;
634 if ( ((DecorHackWidget *)widget)->needsOk() ) 634 if ( ((DecorHackWidget *)widget)->needsOk() )
635 left -= okWidth; 635 left -= okWidth;
636 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 636 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
637 region = r; 637 region = r;
638 } 638 }
639 break; 639 break;
640 case Minimize: 640 case Minimize:
641 if ( ((DecorHackWidget *)widget)->needsOk() ) { 641 if ( ((DecorHackWidget *)widget)->needsOk() ) {
642 QRect r(rect.right() - okWidth, 642 QRect r(rect.right() - okWidth,
643 rect.top() - titleHeight, okWidth, titleHeight); 643 rect.top() - titleHeight, okWidth, titleHeight);
644 if (r.left() > rect.left() + titleHeight) 644 if (r.left() > rect.left() + titleHeight)
645 region = r; 645 region = r;
646 } 646 }
647 break; 647 break;
648 case Close: 648 case Close:
649 { 649 {
650 int left = rect.right() - closeWidth; 650 int left = rect.right() - closeWidth;
651 if ( ((DecorHackWidget *)widget)->needsOk() ) 651 if ( ((DecorHackWidget *)widget)->needsOk() )
652 left -= okWidth; 652 left -= okWidth;
653 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 653 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
654 region = r; 654 region = r;
655 } 655 }
656 break; 656 break;
657 case Title: 657 case Title:
658 if ( !widget->isMaximized() ) { 658 if ( !widget->isMaximized() ) {
659 int width = rect.width() - helpWidth - closeWidth; 659 int width = rect.width() - helpWidth - closeWidth;
660 if ( ((DecorHackWidget *)widget)->needsOk() ) 660 if ( ((DecorHackWidget *)widget)->needsOk() )
661 width -= okWidth; 661 width -= okWidth;
662 QRect r(rect.left()+helpWidth, rect.top() - titleHeight, 662 QRect r(rect.left()+helpWidth, rect.top() - titleHeight,
663 width, titleHeight); 663 width, titleHeight);
664 if (r.width() > 0) 664 if (r.width() > 0)
665 region = r; 665 region = r;
666 } 666 }
667 break; 667 break;
668 case Help: 668 case Help:
669 if ( helpExists() || widget->testWFlags(Qt::WStyle_ContextHelp) ) { 669 if ( helpExists() || widget->testWFlags(Qt::WStyle_ContextHelp) ) {
670 QRect r(rect.left(), rect.top() - titleHeight, 670 QRect r(rect.left(), rect.top() - titleHeight,
671 helpWidth, titleHeight); 671 helpWidth, titleHeight);
672 region = r; 672 region = r;
673 } 673 }
674 break; 674 break;
675 case Top: 675 case Top:
676 if ( !widget->isMaximized() ) { 676 if ( !widget->isMaximized() ) {
677 QRegion m = wdiface->mask(&wd); 677 QRegion m = wdiface->mask(&wd);
678 QRect br = m.boundingRect(); 678 QRect br = m.boundingRect();
679 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 679 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
680 region = m & QRect( br.left()+grab, br.top(), 680 region = m & QRect( br.left()+grab, br.top(),
681 br.width()-2*grab, b ); 681 br.width()-2*grab, b );
682 } 682 }
683 break; 683 break;
684 case Left: 684 case Left:
685 if ( !widget->isMaximized() ) { 685 if ( !widget->isMaximized() ) {
686 QRegion m = wdiface->mask(&wd); 686 QRegion m = wdiface->mask(&wd);
687 QRect br = m.boundingRect(); 687 QRect br = m.boundingRect();
688 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 688 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
689 region = m & QRect( br.left(), br.top()+grab, 689 region = m & QRect( br.left(), br.top()+grab,
690 b, br.height()-2*grab ); 690 b, br.height()-2*grab );
691 } 691 }
692 break; 692 break;
693 case Right: 693 case Right:
694 if ( !widget->isMaximized() ) { 694 if ( !widget->isMaximized() ) {
695 QRegion m = wdiface->mask(&wd); 695 QRegion m = wdiface->mask(&wd);
696 QRect br = m.boundingRect(); 696 QRect br = m.boundingRect();
697 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 697 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
698 region = m & QRect( rect.right(), br.top()+grab, 698 region = m & QRect( rect.right(), br.top()+grab,
699 b, br.height()-2*grab ); 699 b, br.height()-2*grab );
700 } 700 }
701 break; 701 break;
702 case Bottom: 702 case Bottom:
703 if ( !widget->isMaximized() ) { 703 if ( !widget->isMaximized() ) {
704 QRegion m = wdiface->mask(&wd); 704 QRegion m = wdiface->mask(&wd);
705 QRect br = m.boundingRect(); 705 QRect br = m.boundingRect();
706 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd); 706 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd);
707 region = m & QRect( br.left()+grab, rect.bottom(), 707 region = m & QRect( br.left()+grab, rect.bottom(),
708 br.width()-2*grab, b ); 708 br.width()-2*grab, b );
709 } 709 }
710 break; 710 break;
711 case TopLeft: 711 case TopLeft:
712 if ( !widget->isMaximized() ) { 712 if ( !widget->isMaximized() ) {
713 QRegion m = wdiface->mask(&wd); 713 QRegion m = wdiface->mask(&wd);
714 QRect br = m.boundingRect(); 714 QRect br = m.boundingRect();
715 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 715 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
716 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 716 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
717 QRegion crgn( br.left(), br.top(), grab, tb ); 717 QRegion crgn( br.left(), br.top(), grab, tb );
718 crgn |= QRect( br.left(), br.top(), lb, grab ); 718 crgn |= QRect( br.left(), br.top(), lb, grab );
719 region = m & crgn; 719 region = m & crgn;
720 } 720 }
721 break; 721 break;
722 case TopRight: 722 case TopRight:
723 if ( !widget->isMaximized() ) { 723 if ( !widget->isMaximized() ) {
724 QRegion m = wdiface->mask(&wd); 724 QRegion m = wdiface->mask(&wd);
725 QRect br = m.boundingRect(); 725 QRect br = m.boundingRect();
726 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 726 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
727 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 727 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
728 QRegion crgn( br.right()-grab, br.top(), grab, tb ); 728 QRegion crgn( br.right()-grab, br.top(), grab, tb );
729 crgn |= QRect( br.right()-rb, br.top(), rb, grab ); 729 crgn |= QRect( br.right()-rb, br.top(), rb, grab );
730 region = m & crgn; 730 region = m & crgn;
731 } 731 }
732 break; 732 break;
733 case BottomLeft: 733 case BottomLeft:
734 if ( !widget->isMaximized() ) { 734 if ( !widget->isMaximized() ) {
735 QRegion m = wdiface->mask(&wd); 735 QRegion m = wdiface->mask(&wd);
736 QRect br = m.boundingRect(); 736 QRect br = m.boundingRect();
737 region = m & QRect( br.left(), br.bottom()-grab, grab, grab ); 737 region = m & QRect( br.left(), br.bottom()-grab, grab, grab );
738 } 738 }
739 break; 739 break;
740 case BottomRight: 740 case BottomRight:
741 if ( !widget->isMaximized() ) { 741 if ( !widget->isMaximized() ) {
742 QRegion m = wdiface->mask(&wd); 742 QRegion m = wdiface->mask(&wd);
743 QRect br = m.boundingRect(); 743 QRect br = m.boundingRect();
744 region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab ); 744 region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab );
745 } 745 }
746 break; 746 break;
747 case All: 747 case All:
748 if ( widget->isMaximized() ) 748 if ( widget->isMaximized() )
749 region = QWSDefaultDecoration::region(widget, rect, type); 749 region = QWSDefaultDecoration::region(widget, rect, type);
750 else 750 else
751 region = wdiface->mask(&wd) - rect; 751 region = wdiface->mask(&wd) - rect;
752 break; 752 break;
753 default: 753 default:
754 region = QWSDefaultDecoration::region(widget, rect, type); 754 region = QWSDefaultDecoration::region(widget, rect, type);
755 break; 755 break;
756 } 756 }
757 757
758 return region; 758 return region;
759} 759}
760 760
761void QPEDecoration::paint(QPainter *painter, const QWidget *widget) 761void QPEDecoration::paint(QPainter *painter, const QWidget *widget)
762{ 762{
763 WindowDecorationInterface::WindowData wd; 763 WindowDecorationInterface::WindowData wd;
764 windowData( widget, wd ); 764 windowData( widget, wd );
765 765
766 int titleWidth = getTitleWidth(widget); 766 int titleWidth = getTitleWidth(widget);
767 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 767 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
768 768
769 QRect rect(widget->rect()); 769 QRect rect(widget->rect());
770 770
771 // title bar rect 771 // title bar rect
772 QRect tbr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); 772 QRect tbr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
773 773
774#ifndef QT_NO_PALETTE 774#ifndef QT_NO_PALETTE
775 QRegion oldClip = painter->clipRegion(); 775 QRegion oldClip = painter->clipRegion();
776 painter->setClipRegion( oldClip - QRegion( tbr ) );// reduce flicker 776 painter->setClipRegion( oldClip - QRegion( tbr ) );// reduce flicker
777 wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd ); 777 wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd );
778 painter->setClipRegion( oldClip ); 778 painter->setClipRegion( oldClip );
779 779
780 if (titleWidth > 0) { 780 if (titleWidth > 0) {
781 const QColorGroup &cg = widget->palette().active(); 781 const QColorGroup &cg = widget->palette().active();
782 QBrush titleBrush; 782 QBrush titleBrush;
783 QPen titlePen; 783 QPen titlePen;
784 784
785 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) { 785 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) {
786 titleBrush = cg.brush(QColorGroup::Highlight); 786 titleBrush = cg.brush(QColorGroup::Highlight);
787 titlePen = cg.color(QColorGroup::HighlightedText); 787 titlePen = cg.color(QColorGroup::HighlightedText);
788 } else { 788 } else {
789 titleBrush = cg.brush(QColorGroup::Background); 789 titleBrush = cg.brush(QColorGroup::Background);
790 titlePen = cg.color(QColorGroup::Text); 790 titlePen = cg.color(QColorGroup::Text);
791 } 791 }
792 792
793 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); 793 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
794 794
795 // Draw caption 795 // Draw caption
796 painter->setPen(titlePen); 796 painter->setPen(titlePen);
797 QFont f( QApplication::font() ); 797 QFont f( QApplication::font() );
798 f.setWeight( QFont::Bold ); 798 f.setWeight( QFont::Bold );
799 painter->setFont(f); 799 painter->setFont(f);
800 wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd ); 800 wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd );
801 } 801 }
802#endif //QT_NO_PALETTE 802#endif //QT_NO_PALETTE
803 803
804 paintButton( painter, widget, (QWSDecoration::Region)Help, 0 ); 804 paintButton( painter, widget, (QWSDecoration::Region)Help, 0 );
805} 805}
806 806
807void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, 807void QPEDecoration::paintButton(QPainter *painter, const QWidget *w,
808 QWSDecoration::Region type, int state) 808 QWSDecoration::Region type, int state)
809{ 809{
810 WindowDecorationInterface::Button b; 810 WindowDecorationInterface::Button b;
811 switch ((int)type) { 811 switch ((int)type) {
812 case Close: 812 case Close:
813 b = WindowDecorationInterface::Close; 813 b = WindowDecorationInterface::Close;
814 break; 814 break;
815 case Minimize: 815 case Minimize:
816 if ( ((DecorHackWidget *)w)->needsOk() ) 816 if ( ((DecorHackWidget *)w)->needsOk() )
817 b = WindowDecorationInterface::OK; 817 b = WindowDecorationInterface::OK;
818 else if ( helpExists() ) 818 else if ( helpExists() )
819 b = WindowDecorationInterface::Help; 819 b = WindowDecorationInterface::Help;
820 else 820 else
821 return; 821 return;
822 break; 822 break;
823 case Help: 823 case Help:
824 b = WindowDecorationInterface::Help; 824 b = WindowDecorationInterface::Help;
825 break; 825 break;
826 case Maximize: 826 case Maximize:
827 b = WindowDecorationInterface::Maximize; 827 b = WindowDecorationInterface::Maximize;
828 break; 828 break;
829 default: 829 default:
830 return; 830 return;
831 } 831 }
832 832
833 WindowDecorationInterface::WindowData wd; 833 WindowDecorationInterface::WindowData wd;
834 windowData( w, wd ); 834 windowData( w, wd );
835 835
836 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 836 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
837 QRect rect(w->rect()); 837 QRect rect(w->rect());
838 QRect tbr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); 838 QRect tbr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
839 QRect brect(region(w, w->rect(), type).boundingRect()); 839 QRect brect(region(w, w->rect(), type).boundingRect());
840 840
841 const QColorGroup &cg = w->palette().active(); 841 const QColorGroup &cg = w->palette().active();
842 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) 842 if ( wd.flags & WindowDecorationInterface::WindowData::Active )
843 painter->setPen( cg.color(QColorGroup::HighlightedText) ); 843 painter->setPen( cg.color(QColorGroup::HighlightedText) );
844 else 844 else
845 painter->setPen( cg.color(QColorGroup::Text) ); 845 painter->setPen( cg.color(QColorGroup::Text) );
846 846
847 QRegion oldClip = painter->clipRegion(); 847 QRegion oldClip = painter->clipRegion();
848 painter->setClipRegion( QRect(brect.x(), tbr.y(), brect.width(), tbr.height()) ); // reduce flicker 848 painter->setClipRegion( QRect(brect.x(), tbr.y(), brect.width(), tbr.height()) ); // reduce flicker
849 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); 849 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
850 wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state ); 850 wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state );
851 painter->setClipRegion( oldClip ); 851 painter->setClipRegion( oldClip );
852} 852}
853 853
854//#define QPE_DONT_SHOW_TITLEBAR 854//#define QPE_DONT_SHOW_TITLEBAR
855 855
856void QPEDecoration::maximize( QWidget *widget ) 856void QPEDecoration::maximize( QWidget *widget )
857{ 857{
858#ifdef QPE_DONT_SHOW_TITLEBAR 858#ifdef QPE_DONT_SHOW_TITLEBAR
859 if ( !widget->inherits( "QDialog" ) ) { 859 if ( !widget->inherits( "QDialog" ) ) {
860 widget->setGeometry( qt_maxWindowRect ); 860 widget->setGeometry( qt_maxWindowRect );
861 } else 861 } else
862#endif 862#endif
863 { 863 {
864 QWSDecoration::maximize( widget ); 864 QWSDecoration::maximize( widget );
865 } 865 }
866} 866}
867 867
868QPopupMenu *QPEDecoration::menu( const QWidget *, const QPoint & ) 868QPopupMenu *QPEDecoration::menu( const QWidget *, const QPoint & )
869{ 869{
870 QPopupMenu *m = new QPopupMenu(); 870 QPopupMenu *m = new QPopupMenu();
871 871
872 m->insertItem(QPEManager::tr("Restore"), (int)Normalize); 872 m->insertItem(QPEManager::tr("Restore"), (int)Normalize);
873 m->insertItem(QPEManager::tr("Move"), (int)Title); 873 m->insertItem(QPEManager::tr("Move"), (int)Title);
874 m->insertItem(QPEManager::tr("Size"), (int)BottomRight); 874 m->insertItem(QPEManager::tr("Size"), (int)BottomRight);
875 m->insertItem(QPEManager::tr("Maximize"), (int)Maximize); 875 m->insertItem(QPEManager::tr("Maximize"), (int)Maximize);
876 m->insertSeparator(); 876 m->insertSeparator();
877 m->insertItem(QPEManager::tr("Close"), (int)Close); 877 m->insertItem(QPEManager::tr("Close"), (int)Close);
878 878
879 return m; 879 return m;
880} 880}
881 881
882#ifndef QT_NO_DIALOG 882#ifndef QT_NO_DIALOG
883class HackDialog : public QDialog 883class HackDialog : public QDialog
884{ 884{
885public: 885public:
886 void acceptIt() { 886 void acceptIt() {
887 if ( isA( "QMessageBox" ) ) 887 if ( isA( "QMessageBox" ) )
888 qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) ); 888 qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) );
889 else 889 else
890 accept(); 890 accept();
891 } 891 }
892}; 892};
893#endif 893#endif
894 894
895 895
896void QPEDecoration::minimize( QWidget *widget ) 896void QPEDecoration::minimize( QWidget *widget )
897{ 897{
898#ifndef QT_NO_DIALOG 898#ifndef QT_NO_DIALOG
899 // We use the minimize button as an "accept" button. 899 // We use the minimize button as an "accept" button.
900 if ( widget->inherits( "QDialog" ) ) { 900 if ( widget->inherits( "QDialog" ) ) {
901 HackDialog *d = (HackDialog *)widget; 901 HackDialog *d = (HackDialog *)widget;
902 d->acceptIt(); 902 d->acceptIt();
903 } 903 }
904#endif 904#endif
905 else if ( ((DecorHackWidget *)widget)->needsOk() ) { 905 else if ( ((DecorHackWidget *)widget)->needsOk() ) {
906 QSignal s; 906 QSignal s;
907 s.connect( widget, SLOT( accept() ) ); 907 s.connect( widget, SLOT( accept() ) );
908 s.activate(); 908 s.activate();
909 } else { 909 } else {
910 help( widget ); 910 help( widget );
911 } 911 }
912} 912}
913 913
914void QPEDecoration::help( QWidget *w ) 914void QPEDecoration::help( QWidget *w )
915{ 915{
916 if ( helpExists() ) { 916 if ( helpExists() ) {
917 QString hf = helpFile; 917 QString hf = helpFile;
918 QString localHelpFile = QString(qApp->argv()[0]) + "-" + w->name() + ".html"; 918 QString localHelpFile = QString(qApp->argv()[0]) + "-" + w->name() + ".html";
919 QStringList helpPath = Global::helpPath(); 919 QStringList helpPath = Global::helpPath();
920 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end(); ++it) { 920 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end(); ++it) {
921 if ( QFile::exists( *it + "/" + localHelpFile ) ) { 921 if ( QFile::exists( *it + "/" + localHelpFile ) ) {
922 hf = localHelpFile; 922 hf = localHelpFile;
923 break; 923 break;
924 } 924 }
925 } 925 }
926 Global::execute( "helpbrowser", hf ); 926 Global::execute( "helpbrowser", hf );
927 } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) { 927 } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) {
928 QWhatsThis::enterWhatsThisMode(); 928 QWhatsThis::enterWhatsThisMode();
929 QWhatsThis::leaveWhatsThisMode( QObject::tr( 929 QWhatsThis::leaveWhatsThisMode( QObject::tr(
930 "<Qt>Comprehensive help is not available for this application, " 930 "<Qt>Comprehensive help is not available for this application, "
931 "however there is context-sensitive help.<p>To use context-sensitive help:<p>" 931 "however there is context-sensitive help.<p>To use context-sensitive help:<p>"
932 "<ol><li>click and hold the help button." 932 "<ol><li>click and hold the help button."
933 "<li>when the title bar shows <b>What's this...</b>, " 933 "<li>when the title bar shows <b>What's this...</b>, "
934 "click on any control.</ol></Qt>" ) ); 934 "click on any control.</ol></Qt>" ) );
935 } 935 }
936} 936}
937 937
938void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const 938void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const
939{ 939{
940 wd.rect = w->rect(); 940 wd.rect = w->rect();
941 if ( qpeManager->whatsThisWidget() == w ) 941 if ( qpeManager->whatsThisWidget() == w )
942 wd.caption = QObject::tr( "What's this..." ); 942 wd.caption = QObject::tr( "What's this..." );
943 else 943 else
944 wd.caption = w->caption(); 944 wd.caption = w->caption();
945 wd.palette = qApp->palette(); 945 wd.palette = qApp->palette();
946 wd.flags = 0; 946 wd.flags = 0;
947 wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0; 947 wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0;
948 wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0; 948 wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0;
949 const QWidget *active = qpeManager->activeWidget(); 949 const QWidget *active = qpeManager->activeWidget();
950 wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0; 950 wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0;
951 wd.reserved = 1; 951 wd.reserved = 1;
952} 952}
953 953
954/* 954/*
955#ifndef QT_NO_POPUPMENU 955#ifndef QT_NO_POPUPMENU
956QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&) 956QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&)
957{ 957{
958 return 0; 958 return 0;
959} 959}
960#endif 960#endif
961*/ 961*/
962 962
963 963
964 964
965 965
966#endif // QT_NO_QWS_QPE_WM_STYLE 966#endif // QT_NO_QWS_QPE_WM_STYLE
967#endif 967#endif
diff --git a/libslcompat/slmisc.h b/libslcompat/slmisc.h
index 20ba988..442b098 100644
--- a/libslcompat/slmisc.h
+++ b/libslcompat/slmisc.h
@@ -1,135 +1,135 @@
1/* 1/*
2 * Copyright (C) 2002 SHARP CORPORATION All rights reserved. 2 * Copyright (C) 2002 SHARP CORPORATION All rights reserved.
3 */ 3 */
4#ifndef _SLMISC_H_INCLUDED 4#ifndef _SLMISC_H_INCLUDED
5#define _SLMISC_H_INCLUDED 5#define _SLMISC_H_INCLUDED
6 6
7#include <qpe/qpeapplication.h> 7#include <qpe/qpeapplication.h>
8#include <qfileinfo.h> 8#include <qfileinfo.h>
9#include <qpe/global.h> 9#include <qpe/global.h>
10#include <qmessagebox.h> 10#include <qmessagebox.h>
11 11
12 12
13#define _SLPOWER 13#define _SLPOWER
14 14
15class QPopupMenu; 15class QPopupMenu;
16class QListView; 16class QListView;
17#if !defined(_SLPOWER) 17#if !defined(_SLPOWER)
18class PowerStatus; 18class PowerStatus;
19#else 19#else
20class SlPowerStatus; 20class SlPowerStatus;
21#endif 21#endif
22class Config; 22class Config;
23 23
24typedef ulong SlResolutionScale; 24typedef ulong SlResolutionScale;
25 25
26class SlMisc { 26class SlMisc {
27public: 27public:
28 static bool isExecutable(const QString &c) { 28 static bool isExecutable(const QString &c) {
29 QFileInfo exec(QPEApplication::qpeDir() + "/bin/" + c); 29 QFileInfo exec(QPEApplication::qpeDir() + "bin/" + c);
30 return exec.isExecutable(); 30 return exec.isExecutable();
31 }; 31 };
32 static ulong availableMemory(); 32 static ulong availableMemory();
33 static bool invalidFileName(QString &fName); 33 static bool invalidFileName(QString &fName);
34 static QString getValidFileName(const QString &baseName); 34 static QString getValidFileName(const QString &baseName);
35 static QString getCanonicalPath(const QString &fName); 35 static QString getCanonicalPath(const QString &fName);
36 static void enableAutoPowerOff(bool isOn); 36 static void enableAutoPowerOff(bool isOn);
37 static void enableAutoPowerOff(bool isOn,bool DimAlso,bool ScreenSaverAlso=FALSE); 37 static void enableAutoPowerOff(bool isOn,bool DimAlso,bool ScreenSaverAlso=FALSE);
38 static void enableLockApplication(bool); 38 static void enableLockApplication(bool);
39 static bool isTheSmbShareFileHasWriteEntry(const QString &shareFName); 39 static bool isTheSmbShareFileHasWriteEntry(const QString &shareFName);
40 static bool isTheSmbShareFileNowCopy(const QString &shareFName); 40 static bool isTheSmbShareFileNowCopy(const QString &shareFName);
41 static bool checkTheSmbShareFileMode(const QString &shareFName, 41 static bool checkTheSmbShareFileMode(const QString &shareFName,
42 char modeMask, char checkMode, bool equality); 42 char modeMask, char checkMode, bool equality);
43 static bool isTheFileLockedBySmbd(const QString &fName); 43 static bool isTheFileLockedBySmbd(const QString &fName);
44 static bool isSambaForked(); 44 static bool isSambaForked();
45 static void startSamba(); 45 static void startSamba();
46 static void stopSamba(); 46 static void stopSamba();
47 enum ListType { Pid, CmdLine, Both }; 47 enum ListType { Pid, CmdLine, Both };
48 static QStringList procList (const QRegExp& re, uint max = 0, enum ListType type = Pid); 48 static QStringList procList (const QRegExp& re, uint max = 0, enum ListType type = Pid);
49 static void dumpMemInfo(bool isShowHeap); 49 static void dumpMemInfo(bool isShowHeap);
50 static bool canCreateTheFile(const QString&); 50 static bool canCreateTheFile(const QString&);
51 static QString getLanguage(); 51 static QString getLanguage();
52 static QSize getMaximizedWidgetInfo(); 52 static QSize getMaximizedWidgetInfo();
53 static QSize SlMisc::getScrollbarMetrics(); 53 static QSize SlMisc::getScrollbarMetrics();
54 static int getDpi(); 54 static int getDpi();
55 static SlResolutionScale getResolutionScale(); 55 static SlResolutionScale getResolutionScale();
56 static int getMaximizedWidgetContentsWidth(); 56 static int getMaximizedWidgetContentsWidth();
57 static bool isLandscape(); 57 static bool isLandscape();
58 static void requestCloseFile(const QString&); 58 static void requestCloseFile(const QString&);
59 static void requestOpenFile(const QString&); 59 static void requestOpenFile(const QString&);
60 60
61 static void insertStandardFontMenu(QPopupMenu *pm); 61 static void insertStandardFontMenu(QPopupMenu *pm);
62 static void insertAllFontMenu(QPopupMenu *pm); 62 static void insertAllFontMenu(QPopupMenu *pm);
63 static int getLogicalSizeFromMenuId(int id); 63 static int getLogicalSizeFromMenuId(int id);
64 static void setFontSizeItemChecked(QPopupMenu *pm,int logicalSize); 64 static void setFontSizeItemChecked(QPopupMenu *pm,int logicalSize);
65 static int getFontPointSize(int logicalSize); 65 static int getFontPointSize(int logicalSize);
66 static void toggleFontSize(QPopupMenu *pm,int &logicalSize,bool isLarge=true); 66 static void toggleFontSize(QPopupMenu *pm,int &logicalSize,bool isLarge=true);
67 static void toggleAllFontSize(QPopupMenu *pm,int *fontSize,bool isLarge=true); 67 static void toggleAllFontSize(QPopupMenu *pm,int *fontSize,bool isLarge=true);
68 68
69 static void SlFontArrange (QWidget* widget); 69 static void SlFontArrange (QWidget* widget);
70 static void SlLayoutSpaceArrange (QObject* object); 70 static void SlLayoutSpaceArrange (QObject* object);
71 71
72 static bool checkBatteryError(const QString &module_name, bool force); 72 static bool checkBatteryError(const QString &module_name, bool force);
73 static bool checkBatteryErrorWithoutDialog(const QString &module_name, bool force); 73 static bool checkBatteryErrorWithoutDialog(const QString &module_name, bool force);
74 74
75 75
76 enum InputDeviceType { 76 enum InputDeviceType {
77 BuiltinKeyboard = 1, 77 BuiltinKeyboard = 1,
78 SoftwareKeyboard = 2 78 SoftwareKeyboard = 2
79 }; 79 };
80 static InputDeviceType defaultInputDevice(); 80 static InputDeviceType defaultInputDevice();
81 81
82 82
83 typedef struct SlListColumnInfo { 83 typedef struct SlListColumnInfo {
84 enum Type { 84 enum Type {
85 Fixed = 0, 85 Fixed = 0,
86 StringLen, 86 StringLen,
87 Scale, 87 Scale,
88 FixedDpiAware 88 FixedDpiAware
89 }; 89 };
90 Type type; 90 Type type;
91 QString str; 91 QString str;
92 int val; 92 int val;
93 }; 93 };
94 typedef QValueList<SlListColumnInfo> SlListColumnInfos; 94 typedef QValueList<SlListColumnInfo> SlListColumnInfos;
95 95
96 static void setListColumnsWidth(QWidget *w,SlListColumnInfos &infos, 96 static void setListColumnsWidth(QWidget *w,SlListColumnInfos &infos,
97 Config &config); 97 Config &config);
98 static void writeListColumnsWidth(QWidget *w,SlListColumnInfos &infos, 98 static void writeListColumnsWidth(QWidget *w,SlListColumnInfos &infos,
99 Config &config); 99 Config &config);
100 static void writeListColumnsWidth(QWidget *w,SlListColumnInfos &infos, 100 static void writeListColumnsWidth(QWidget *w,SlListColumnInfos &infos,
101 Config &config,bool isLandscape); 101 Config &config,bool isLandscape);
102 static void rotateListColumnsWidth(QWidget *w,SlListColumnInfos &infos, 102 static void rotateListColumnsWidth(QWidget *w,SlListColumnInfos &infos,
103 Config &config); 103 Config &config);
104 static void setListColumnsWidth(QWidget *w,SlListColumnInfos &infos, Config *config=NULL); 104 static void setListColumnsWidth(QWidget *w,SlListColumnInfos &infos, Config *config=NULL);
105 static void writeListColumnsWidth(QWidget *w,SlListColumnInfos &infos, Config *config=NULL); 105 static void writeListColumnsWidth(QWidget *w,SlListColumnInfos &infos, Config *config=NULL);
106 static void writeListColumnsWidth(QWidget *w,SlListColumnInfos &infos, bool isLandscape, Config *config=NULL); 106 static void writeListColumnsWidth(QWidget *w,SlListColumnInfos &infos, bool isLandscape, Config *config=NULL);
107 static void rotateListColumnsWidth(QWidget *w,SlListColumnInfos &infos, Config *config=NULL); 107 static void rotateListColumnsWidth(QWidget *w,SlListColumnInfos &infos, Config *config=NULL);
108 static void temporaryMessageBox(const QString &caption, const QString &text, int msec=10000, QMessageBox::Icon icon=QMessageBox::NoIcon, int button0=0, int button1=0, int button2=0, QWidget *parent=0, const char *name=0, QWidget::WFlags f=QWidget::WStyle_DialogBorder); 108 static void temporaryMessageBox(const QString &caption, const QString &text, int msec=10000, QMessageBox::Icon icon=QMessageBox::NoIcon, int button0=0, int button1=0, int button2=0, QWidget *parent=0, const char *name=0, QWidget::WFlags f=QWidget::WStyle_DialogBorder);
109 109
110 static QString defaultWallPaper(); 110 static QString defaultWallPaper();
111 typedef enum AppCommand { 111 typedef enum AppCommand {
112 NoneCommand = 0, 112 NoneCommand = 0,
113 NewCommand, 113 NewCommand,
114 ModifyCommand, 114 ModifyCommand,
115 DeleteCommand, 115 DeleteCommand,
116 ZoomInCommand, 116 ZoomInCommand,
117 ZoomOutCommand, 117 ZoomOutCommand,
118 CutCommand = 50, 118 CutCommand = 50,
119 CopyCommand, 119 CopyCommand,
120 PasteCommand 120 PasteCommand
121 }; 121 };
122 static AppCommand appCommandFromKey(const QKeyEvent &e); 122 static AppCommand appCommandFromKey(const QKeyEvent &e);
123 123
124 typedef enum RequiredSize { 124 typedef enum RequiredSize {
125 SmallSize = 0, 125 SmallSize = 0,
126 LargeSize 126 LargeSize
127 }; 127 };
128 static const char* getTmpPath(RequiredSize); 128 static const char* getTmpPath(RequiredSize);
129 static const char* getTmpPath(ulong); 129 static const char* getTmpPath(ulong);
130 static QString getObexTmpPath(); 130 static QString getObexTmpPath();
131 static ulong availableInternalStorage(void); 131 static ulong availableInternalStorage(void);
132 static QString moduleNameFromPath(const QString &path); 132 static QString moduleNameFromPath(const QString &path);
133}; 133};
134 134
135#endif 135#endif
diff --git a/noncore/applets/zkbapplet/applet/zkbwidget.cpp b/noncore/applets/zkbapplet/applet/zkbwidget.cpp
index 8499500..13729ea 100644
--- a/noncore/applets/zkbapplet/applet/zkbwidget.cpp
+++ b/noncore/applets/zkbapplet/applet/zkbwidget.cpp
@@ -1,168 +1,168 @@
1#include <opie2/otaskbarapplet.h> 1#include <opie2/otaskbarapplet.h>
2#include <opie2/okeyfilter.h> 2#include <opie2/okeyfilter.h>
3#include <qpe/qcopenvelope_qws.h> 3#include <qpe/qcopenvelope_qws.h>
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5#include <qpe/qpeapplication.h> 5#include <qpe/qpeapplication.h>
6#include <qpe/resource.h> 6#include <qpe/resource.h>
7#include <stdio.h> 7#include <stdio.h>
8#include <unistd.h> 8#include <unistd.h>
9#include "zkbwidget.h" 9#include "zkbwidget.h"
10#include "zkbcfg.h" 10#include "zkbcfg.h"
11 11
12using namespace Opie::Ui; 12using namespace Opie::Ui;
13 13
14ZkbWidget::ZkbWidget(QWidget* parent) 14ZkbWidget::ZkbWidget(QWidget* parent)
15 :QLabel(parent),keymap(0),disabled(Resource::loadPixmap("zkb-disabled")) { 15 :QLabel(parent),keymap(0),disabled(Resource::loadPixmap("zkb-disabled")) {
16 16
17 labels = new QPopupMenu(); 17 labels = new QPopupMenu();
18 connect(labels, SIGNAL(activated(int)), this, 18 connect(labels, SIGNAL(activated(int)), this,
19 SLOT(labelChanged(int))); 19 SLOT(labelChanged(int)));
20 20
21 loadKeymap(); 21 loadKeymap();
22 22
23 channel = new QCopChannel("QPE/zkb", this); 23 channel = new QCopChannel("QPE/zkb", this);
24 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), 24 connect(channel, SIGNAL(received(const QCString&,const QByteArray&)),
25 this, SLOT(signalReceived(const QCString&,const QByteArray&))); 25 this, SLOT(signalReceived(const QCString&,const QByteArray&)));
26 setFixedWidth ( AppLnk::smallIconSize() ); 26 setFixedWidth ( AppLnk::smallIconSize() );
27 setFixedHeight ( AppLnk::smallIconSize() ); 27 setFixedHeight ( AppLnk::smallIconSize() );
28} 28}
29 29
30ZkbWidget::~ZkbWidget() 30ZkbWidget::~ZkbWidget()
31{ 31{
32 if (keymap != 0) { 32 if (keymap != 0) {
33 delete keymap; 33 delete keymap;
34 keymap = 0; 34 keymap = 0;
35 } 35 }
36} 36}
37 37
38int ZkbWidget::position() 38int ZkbWidget::position()
39{ 39{
40 return 8; 40 return 8;
41} 41}
42 42
43bool ZkbWidget::loadKeymap() { 43bool ZkbWidget::loadKeymap() {
44 ZkbConfig c(QPEApplication::qpeDir()+"/share/zkb"); 44 ZkbConfig c(QPEApplication::qpeDir()+"share/zkb");
45 QFontMetrics fm(font()); 45 QFontMetrics fm(font());
46 46
47 if (keymap != 0) { 47 if (keymap != 0) {
48 delete keymap; 48 delete keymap;
49 keymap = 0; 49 keymap = 0;
50 } 50 }
51 51
52 Keymap* km = new Keymap(); 52 Keymap* km = new Keymap();
53 53
54 if (!c.load("zkb.xml", *km, "")) { 54 if (!c.load("zkb.xml", *km, "")) {
55 delete km; 55 delete km;
56 setPixmap(disabled); 56 setPixmap(disabled);
57 return false; 57 return false;
58 } 58 }
59 59
60 connect(km, SIGNAL(stateChanged(const QString&)), 60 connect(km, SIGNAL(stateChanged(const QString&)),
61 this, SLOT(stateChanged(const QString&))); 61 this, SLOT(stateChanged(const QString&)));
62 62
63 Opie::Core::OKeyFilter::inst()->addHandler(km); 63 Opie::Core::OKeyFilter::inst()->addHandler(km);
64 64
65 Keymap* oldkm = keymap; 65 Keymap* oldkm = keymap;
66 keymap = km; 66 keymap = km;
67 67
68 if (oldkm != 0) { 68 if (oldkm != 0) {
69 delete oldkm; 69 delete oldkm;
70 } 70 }
71 71
72 QString ltext = keymap->getCurrentLabel(); 72 QString ltext = keymap->getCurrentLabel();
73 if (ltext.length()==0) ltext = "??"; 73 if (ltext.length()==0) ltext = "??";
74 setText(ltext); 74 setText(ltext);
75 75
76 labels->clear(); 76 labels->clear();
77 QStringList l = keymap->listLabels(); 77 QStringList l = keymap->listLabels();
78 labels->insertItem(disabled, 0, 0); 78 labels->insertItem(disabled, 0, 0);
79 int n = 1; 79 int n = 1;
80 w = 0; 80 w = 0;
81 for(QStringList::Iterator it = l.begin(); it != l.end(); 81 for(QStringList::Iterator it = l.begin(); it != l.end();
82 ++it, n++) { 82 ++it, n++) {
83 83
84// printf("label: %s\n", (const char*) (*it).utf8()); 84// printf("label: %s\n", (const char*) (*it).utf8());
85 85
86 labels->insertItem(*it, n, n); 86 labels->insertItem(*it, n, n);
87 int lw = fm.width(*it); 87 int lw = fm.width(*it);
88 if (lw > w) { 88 if (lw > w) {
89 w = lw; 89 w = lw;
90 } 90 }
91 } 91 }
92 92
93 if (w == 0) { 93 if (w == 0) {
94 hide(); 94 hide();
95 } else { 95 } else {
96 show(); 96 show();
97 } 97 }
98 return true; 98 return true;
99} 99}
100 100
101QSize ZkbWidget::sizeHint() const { 101QSize ZkbWidget::sizeHint() const {
102 return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize()); 102 return QSize(AppLnk::smallIconSize(),AppLnk::smallIconSize());
103} 103}
104 104
105void ZkbWidget::stateChanged(const QString& s) { 105void ZkbWidget::stateChanged(const QString& s) {
106// odebug << "stateChanged: " << s.utf8() << "\n" << oendl; 106// odebug << "stateChanged: " << s.utf8() << "\n" << oendl;
107 setText(s); 107 setText(s);
108} 108}
109 109
110void ZkbWidget::labelChanged(int id) { 110void ZkbWidget::labelChanged(int id) {
111 if (id == 0) { 111 if (id == 0) {
112 keymap->disable(); 112 keymap->disable();
113 setPixmap(disabled); 113 setPixmap(disabled);
114 return; 114 return;
115 } 115 }
116 116
117 keymap->enable(); 117 keymap->enable();
118 118
119 QStringList l = keymap->listLabels(); 119 QStringList l = keymap->listLabels();
120 QString lbl = l[id-1]; 120 QString lbl = l[id-1];
121 121
122// printf("labelChanged: %s\n", (const char*) lbl.utf8()); 122// printf("labelChanged: %s\n", (const char*) lbl.utf8());
123 State* state = keymap->getStateByLabel(lbl); 123 State* state = keymap->getStateByLabel(lbl);
124 if (state != 0) { 124 if (state != 0) {
125 keymap->setCurrentState(state); 125 keymap->setCurrentState(state);
126 setText(lbl); 126 setText(lbl);
127 } 127 }
128} 128}
129 129
130void ZkbWidget::mouseReleaseEvent(QMouseEvent*) { 130void ZkbWidget::mouseReleaseEvent(QMouseEvent*) {
131 QSize sh = labels->sizeHint(); 131 QSize sh = labels->sizeHint();
132 QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height())); 132 QPoint p = mapToGlobal(QPoint((width()-sh.width())/2,-sh.height()));
133 labels->exec(p); 133 labels->exec(p);
134} 134}
135 135
136void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) { 136void ZkbWidget::signalReceived(const QCString& msg, const QByteArray& data) {
137 QDataStream stream(data, IO_ReadOnly); 137 QDataStream stream(data, IO_ReadOnly);
138 138
139 if (msg == "enable()") { 139 if (msg == "enable()") {
140 keymap->enable(); 140 keymap->enable();
141 } else if (msg == "disable()") { 141 } else if (msg == "disable()") {
142 keymap->disable(); 142 keymap->disable();
143 } else if (msg == "reload()") { 143 } else if (msg == "reload()") {
144 QCopEnvelope("QPE/System", "busy()"); 144 QCopEnvelope("QPE/System", "busy()");
145 QTimer::singleShot(0, this, SLOT(reload())); 145 QTimer::singleShot(0, this, SLOT(reload()));
146 } else if (msg == "switch(QString)") { 146 } else if (msg == "switch(QString)") {
147 QString lbl; 147 QString lbl;
148 stream >> lbl; 148 stream >> lbl;
149 149
150 if (keymap != 0) { 150 if (keymap != 0) {
151 State* state = keymap->getStateByLabel(lbl); 151 State* state = keymap->getStateByLabel(lbl);
152 if (state != 0) { 152 if (state != 0) {
153 keymap->setCurrentState(state); 153 keymap->setCurrentState(state);
154 setText(lbl); 154 setText(lbl);
155 } 155 }
156 } 156 }
157 } else if (msg == "debug(QString)") { 157 } else if (msg == "debug(QString)") {
158 QString flag; 158 QString flag;
159 stream >> flag; 159 stream >> flag;
160 } 160 }
161} 161}
162 162
163void ZkbWidget::reload() { 163void ZkbWidget::reload() {
164 loadKeymap(); 164 loadKeymap();
165 QCopEnvelope("QPE/System", "notBusy()"); 165 QCopEnvelope("QPE/System", "notBusy()");
166} 166}
167 167
168EXPORT_OPIE_APPLET_v1( ZkbWidget ) 168EXPORT_OPIE_APPLET_v1( ZkbWidget )
diff --git a/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp
index 8d868d4..4190a9e 100644
--- a/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp
+++ b/noncore/applets/zkbapplet/keyzcfg/cfgdlg.cpp
@@ -1,132 +1,132 @@
1 1
2#include <qdir.h> 2#include <qdir.h>
3#include <qpe/qpeapplication.h> 3#include <qpe/qpeapplication.h>
4#include <qpe/qcopenvelope_qws.h> 4#include <qpe/qcopenvelope_qws.h>
5#include <unistd.h> 5#include <unistd.h>
6#include "cfgdlg.h" 6#include "cfgdlg.h"
7 7
8CfgDlg::CfgDlg(QWidget* parent, CfgFile* cf, QApplication* app, bool mod): 8CfgDlg::CfgDlg(QWidget* parent, CfgFile* cf, QApplication* app, bool mod):
9 QDialog(parent, "CfgDlg", mod), cfile(cf), application(app) { 9 QDialog(parent, "CfgDlg", mod), cfile(cf), application(app) {
10 10
11 setCaption(tr("keyz configurator")); 11 setCaption(tr("keyz configurator"));
12 12
13 QGridLayout* gl = new QGridLayout(this, 7, 5, 5, 5); 13 QGridLayout* gl = new QGridLayout(this, 7, 5, 5, 5);
14 14
15 QLabel* flabel = new QLabel("Available Keymaps", this); 15 QLabel* flabel = new QLabel("Available Keymaps", this);
16 files = new QListBox(this); 16 files = new QListBox(this);
17 QPushButton* addButton = new QPushButton(">>", this); //add->setText("Add"); 17 QPushButton* addButton = new QPushButton(">>", this); //add->setText("Add");
18 connect(addButton, SIGNAL(clicked()), this, SLOT(add())); 18 connect(addButton, SIGNAL(clicked()), this, SLOT(add()));
19 QLabel* klabel = new QLabel("Selected Keymaps", this); 19 QLabel* klabel = new QLabel("Selected Keymaps", this);
20 keymaps = new QListBox(this); 20 keymaps = new QListBox(this);
21 connect(keymaps, SIGNAL(highlighted(const QString&)), this, SLOT(keymapHighlighted(const QString&))); 21 connect(keymaps, SIGNAL(highlighted(const QString&)), this, SLOT(keymapHighlighted(const QString&)));
22 QPushButton* delButton = new QPushButton("<<", this); //del->setText("Delete"); 22 QPushButton* delButton = new QPushButton("<<", this); //del->setText("Delete");
23 connect(delButton, SIGNAL(clicked()), this, SLOT(del())); 23 connect(delButton, SIGNAL(clicked()), this, SLOT(del()));
24 QPushButton* slabelButton = new QPushButton("Set Label", this); //apply->setText("Apply"); 24 QPushButton* slabelButton = new QPushButton("Set Label", this); //apply->setText("Apply");
25 connect(slabelButton, SIGNAL(clicked()), this, SLOT(setLabel())); 25 connect(slabelButton, SIGNAL(clicked()), this, SLOT(setLabel()));
26 QLabel* l = new QLabel("Label", this); 26 QLabel* l = new QLabel("Label", this);
27 label = new QLineEdit(this); 27 label = new QLineEdit(this);
28 QLabel* adlabel = new QLabel("Auto Repeat Delay (ms)", this); 28 QLabel* adlabel = new QLabel("Auto Repeat Delay (ms)", this);
29 QLabel* aplabel = new QLabel("Auto Repeat Period (ms)", this); 29 QLabel* aplabel = new QLabel("Auto Repeat Period (ms)", this);
30 ad = new QSpinBox(50, 5000, 5, this); 30 ad = new QSpinBox(50, 5000, 5, this);
31 ap = new QSpinBox(0, 5000, 5, this); 31 ap = new QSpinBox(0, 5000, 5, this);
32 32
33 //QLabel* adms = new QLabel("ms", this); 33 //QLabel* adms = new QLabel("ms", this);
34 //QLabel* apms = new QLabel("ms", this); 34 //QLabel* apms = new QLabel("ms", this);
35 35
36 //QCheckBox* enable = new QCheckBox("Enable", t); 36 //QCheckBox* enable = new QCheckBox("Enable", t);
37 37
38 gl->setColStretch(0, 1); 38 gl->setColStretch(0, 1);
39 gl->setColStretch(1, 1); 39 gl->setColStretch(1, 1);
40 gl->setColStretch(3, 1); 40 gl->setColStretch(3, 1);
41 gl->setColStretch(4, 1); 41 gl->setColStretch(4, 1);
42 gl->setRowStretch(3, 1); 42 gl->setRowStretch(3, 1);
43 gl->addMultiCellWidget(flabel, 0, 0, 0, 1); 43 gl->addMultiCellWidget(flabel, 0, 0, 0, 1);
44 gl->addMultiCellWidget(klabel, 0, 0, 3, 4); 44 gl->addMultiCellWidget(klabel, 0, 0, 3, 4);
45 gl->addMultiCellWidget(files, 1, 3, 0, 1); 45 gl->addMultiCellWidget(files, 1, 3, 0, 1);
46 gl->addMultiCellWidget(keymaps, 1, 3, 3, 4); 46 gl->addMultiCellWidget(keymaps, 1, 3, 3, 4);
47 gl->addWidget(addButton, 1, 2); 47 gl->addWidget(addButton, 1, 2);
48 gl->addWidget(delButton, 2, 2); 48 gl->addWidget(delButton, 2, 2);
49 49
50 gl->addWidget(l, 4, 0); 50 gl->addWidget(l, 4, 0);
51 gl->addWidget(label, 4, 1); 51 gl->addWidget(label, 4, 1);
52 gl->addMultiCellWidget(slabelButton, 4, 4, 3, 4); 52 gl->addMultiCellWidget(slabelButton, 4, 4, 3, 4);
53 53
54 gl->addMultiCellWidget(adlabel, 5, 5, 0, 2); 54 gl->addMultiCellWidget(adlabel, 5, 5, 0, 2);
55 gl->addMultiCellWidget(ad, 5, 5, 3, 4); 55 gl->addMultiCellWidget(ad, 5, 5, 3, 4);
56 //gl->addWidget(adms, 5, 3); 56 //gl->addWidget(adms, 5, 3);
57 57
58 gl->addMultiCellWidget(aplabel, 6, 6, 0, 2); 58 gl->addMultiCellWidget(aplabel, 6, 6, 0, 2);
59 gl->addMultiCellWidget(ap, 6, 6, 3, 4); 59 gl->addMultiCellWidget(ap, 6, 6, 3, 4);
60 60
61 //gl->addWidget(apms, 6, 3); 61 //gl->addWidget(apms, 6, 3);
62 62
63 QList<CfgEntry>& e = cfile->getEntries(); 63 QList<CfgEntry>& e = cfile->getEntries();
64 64
65 for(uint i = 0; i < e.count(); i++) { 65 for(uint i = 0; i < e.count(); i++) {
66 CfgEntry* entry = e.at(i); 66 CfgEntry* entry = e.at(i);
67 keymaps->insertItem(entry->getFile()); 67 keymaps->insertItem(entry->getFile());
68 m.insert(entry->getFile(), entry->getLabel()); 68 m.insert(entry->getFile(), entry->getLabel());
69 } 69 }
70 70
71 QDir dir(QPEApplication::qpeDir()+"/share/zkb", "*.xml"); 71 QDir dir(QPEApplication::qpeDir()+"share/zkb", "*.xml");
72 QStringList flist = dir.entryList(); 72 QStringList flist = dir.entryList();
73 QStringList::Iterator sit; 73 QStringList::Iterator sit;
74 for(sit = flist.begin(); sit != flist.end(); ++sit) { 74 for(sit = flist.begin(); sit != flist.end(); ++sit) {
75 if (*sit != "common.xml" && *sit != "zkb.xml" && m.find(*sit) == m.end()) { 75 if (*sit != "common.xml" && *sit != "zkb.xml" && m.find(*sit) == m.end()) {
76 files->insertItem(*sit); 76 files->insertItem(*sit);
77 } 77 }
78 } 78 }
79 79
80 ad->setValue(cfile->getAutorepeatDelay()); 80 ad->setValue(cfile->getAutorepeatDelay());
81 ap->setValue(cfile->getAutorepeatPeriod()); 81 ap->setValue(cfile->getAutorepeatPeriod());
82 82
83 //gl->addMultiCellWidget(enable, 7, 7, 0, 4); 83 //gl->addMultiCellWidget(enable, 7, 7, 0, 4);
84} 84}
85 85
86CfgDlg::~CfgDlg() { 86CfgDlg::~CfgDlg() {
87} 87}
88 88
89void CfgDlg::add() { 89void CfgDlg::add() {
90 if (!files->currentText().isEmpty()) { 90 if (!files->currentText().isEmpty()) {
91 QString t = files->currentText(); 91 QString t = files->currentText();
92 files->removeItem(files->currentItem()); 92 files->removeItem(files->currentItem());
93 keymaps->insertItem(t); 93 keymaps->insertItem(t);
94 cfile->replaceEntry(t, ""); 94 cfile->replaceEntry(t, "");
95 m.replace(t, ""); 95 m.replace(t, "");
96 } 96 }
97} 97}
98 98
99void CfgDlg::del() { 99void CfgDlg::del() {
100 if (!keymaps->currentText().isEmpty()) { 100 if (!keymaps->currentText().isEmpty()) {
101 QString t = keymaps->currentText(); 101 QString t = keymaps->currentText();
102 keymaps->removeItem(keymaps->currentItem()); 102 keymaps->removeItem(keymaps->currentItem());
103 cfile->deleteEntry(t); 103 cfile->deleteEntry(t);
104 files->insertItem(t); 104 files->insertItem(t);
105 m.remove(files->currentText()); 105 m.remove(files->currentText());
106 } 106 }
107} 107}
108 108
109void CfgDlg::setLabel() { 109void CfgDlg::setLabel() {
110 if (!keymaps->currentText().isEmpty()) { 110 if (!keymaps->currentText().isEmpty()) {
111 cfile->replaceEntry(keymaps->currentText(), 111 cfile->replaceEntry(keymaps->currentText(),
112 label->text()); 112 label->text());
113 m.replace(keymaps->currentText(), label->text()); 113 m.replace(keymaps->currentText(), label->text());
114 } 114 }
115} 115}
116 116
117void CfgDlg::keymapHighlighted(const QString&text) { 117void CfgDlg::keymapHighlighted(const QString&text) {
118 label->setText(*m.find(text)); 118 label->setText(*m.find(text));
119} 119}
120 120
121 121
122void CfgDlg::accept() { 122void CfgDlg::accept() {
123 cfile->setAutorepeatDelay(ad->value()); 123 cfile->setAutorepeatDelay(ad->value());
124 cfile->setAutorepeatPeriod(ap->value()); 124 cfile->setAutorepeatPeriod(ap->value());
125 125
126 CfgParser p; 126 CfgParser p;
127 p.save(QPEApplication::qpeDir()+"/share/zkb/zkb.xml", *cfile); 127 p.save(QPEApplication::qpeDir()+"share/zkb/zkb.xml", *cfile);
128 QCopEnvelope("QPE/zkb", "reload()"); 128 QCopEnvelope("QPE/zkb", "reload()");
129 129
130 QDialog::accept(); 130 QDialog::accept();
131} 131}
132 132
diff --git a/noncore/applets/zkbapplet/keyzcfg/main.cpp b/noncore/applets/zkbapplet/keyzcfg/main.cpp
index 4615562..afd0f6a 100644
--- a/noncore/applets/zkbapplet/keyzcfg/main.cpp
+++ b/noncore/applets/zkbapplet/keyzcfg/main.cpp
@@ -1,22 +1,22 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <qpe/qpeapplication.h> 2#include <qpe/qpeapplication.h>
3#include <qlayout.h> 3#include <qlayout.h>
4#include <qmainwindow.h> 4#include <qmainwindow.h>
5 5
6#include "cfgdlg.h" 6#include "cfgdlg.h"
7 7
8int main( int argc, char **argv ) { 8int main( int argc, char **argv ) {
9 QPEApplication app(argc, argv); 9 QPEApplication app(argc, argv);
10 CfgFile cfile; 10 CfgFile cfile;
11 CfgParser cp; 11 CfgParser cp;
12 cp.load(QPEApplication::qpeDir()+"/share/zkb/zkb.xml", cfile); 12 cp.load(QPEApplication::qpeDir()+"share/zkb/zkb.xml", cfile);
13 13
14 14
15 CfgDlg c(0, &cfile, &app, true); 15 CfgDlg c(0, &cfile, &app, true);
16 16
17 17
18 app.showMainWidget(&c); 18 app.showMainWidget(&c);
19 int ret = QPEApplication::execDialog(&c); 19 int ret = QPEApplication::execDialog(&c);
20 20
21 return ret; 21 return ret;
22} 22}
diff --git a/noncore/apps/opie-bartender/bartender.cpp b/noncore/apps/opie-bartender/bartender.cpp
index 59fc242..b4958b3 100644
--- a/noncore/apps/opie-bartender/bartender.cpp
+++ b/noncore/apps/opie-bartender/bartender.cpp
@@ -1,435 +1,435 @@
1/**************************************************************************** 1/****************************************************************************
2** 2**
3** Created: Sat Jul 20 08:10:53 2002 3** Created: Sat Jul 20 08:10:53 2002
4** by: L.J. Potter <ljp@llornkcor.com> 4** by: L.J. Potter <ljp@llornkcor.com>
5** copyright : (C) 2002 by ljp 5** copyright : (C) 2002 by ljp
6 email : ljp@llornkcor.com 6 email : ljp@llornkcor.com
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 ***************************************************************************/ 11 ***************************************************************************/
12 12
13#include "bartender.h" 13#include "bartender.h"
14#include "showdrinks.h" 14#include "showdrinks.h"
15#include "inputDialog.h" 15#include "inputDialog.h"
16#include "searchresults.h" 16#include "searchresults.h"
17#include "bac.h" 17#include "bac.h"
18 18
19/* OPIE */ 19/* OPIE */
20#include <opie2/odebug.h> 20#include <opie2/odebug.h>
21#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23using namespace Opie::Core; 23using namespace Opie::Core;
24 24
25/* QT */ 25/* QT */
26#include <qlineedit.h> 26#include <qlineedit.h>
27#include <qdir.h> 27#include <qdir.h>
28#include <qpushbutton.h> 28#include <qpushbutton.h>
29#include <qlistbox.h> 29#include <qlistbox.h>
30#include <qmultilineedit.h> 30#include <qmultilineedit.h>
31#include <qmessagebox.h> 31#include <qmessagebox.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qaction.h> 33#include <qaction.h>
34#include <qheader.h> 34#include <qheader.h>
35#include <qlistview.h> 35#include <qlistview.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qtoolbar.h> 37#include <qtoolbar.h>
38#include <qmenubar.h> 38#include <qmenubar.h>
39 39
40/* STD */ 40/* STD */
41#include <fcntl.h> 41#include <fcntl.h>
42#include <unistd.h> 42#include <unistd.h>
43#include <stdlib.h> 43#include <stdlib.h>
44#include <stdio.h> 44#include <stdio.h>
45#include <errno.h> 45#include <errno.h>
46 46
47Bartender::Bartender( QWidget* parent, const char* name, WFlags fl ) 47Bartender::Bartender( QWidget* parent, const char* name, WFlags fl )
48 : QMainWindow( parent, name, fl ) { 48 : QMainWindow( parent, name, fl ) {
49 if ( !name ) 49 if ( !name )
50 setName( "Bartender" ); 50 setName( "Bartender" );
51 QGridLayout *layout = new QGridLayout( this ); 51 QGridLayout *layout = new QGridLayout( this );
52 layout->setSpacing( 2); 52 layout->setSpacing( 2);
53 layout->setMargin( 2); 53 layout->setMargin( 2);
54 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 54 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
55 55
56 setCaption( tr( "Bartender" ) ); 56 setCaption( tr( "Bartender" ) );
57 57
58 ToolBar1 = new QToolBar( this, "ToolBar1" ); 58 ToolBar1 = new QToolBar( this, "ToolBar1" );
59 ToolBar1->setFixedHeight(22); 59 ToolBar1->setFixedHeight(22);
60 layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 ); 60 layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 );
61 61
62 QMenuBar *menuBar = new QMenuBar( ToolBar1 ); 62 QMenuBar *menuBar = new QMenuBar( ToolBar1 );
63 QPopupMenu *fileMenu; 63 QPopupMenu *fileMenu;
64 fileMenu = new QPopupMenu( this); 64 fileMenu = new QPopupMenu( this);
65 menuBar->insertItem( tr("File"), fileMenu ); 65 menuBar->insertItem( tr("File"), fileMenu );
66 66
67 fileMenu->insertItem(tr("New Drink")); 67 fileMenu->insertItem(tr("New Drink"));
68 fileMenu->insertItem(tr("Open Drink")); 68 fileMenu->insertItem(tr("Open Drink"));
69 fileMenu->insertItem(tr("Find by Drink Name")); 69 fileMenu->insertItem(tr("Find by Drink Name"));
70 fileMenu->insertItem(tr("Find by Alcohol")); 70 fileMenu->insertItem(tr("Find by Alcohol"));
71 71
72 QPopupMenu *editMenu; 72 QPopupMenu *editMenu;
73 editMenu = new QPopupMenu( this); 73 editMenu = new QPopupMenu( this);
74 menuBar->insertItem( tr("Edit"), editMenu ); 74 menuBar->insertItem( tr("Edit"), editMenu );
75 editMenu->insertItem(tr("edit")); 75 editMenu->insertItem(tr("edit"));
76 76
77 connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) )); 77 connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) ));
78 connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) )); 78 connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) ));
79 79
80 80
81 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 ); 81 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 );
82 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 82 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
83 a->addTo( ToolBar1 ); 83 a->addTo( ToolBar1 );
84 84
85 a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 ); 85 a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 );
86 connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) ); 86 connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) );
87 a->addTo( ToolBar1 ); 87 a->addTo( ToolBar1 );
88 88
89 a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 ); 89 a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 );
90 connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) ); 90 connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) );
91 a->addTo( ToolBar1 ); 91 a->addTo( ToolBar1 );
92 92
93 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ),"Edit", 0, this, 0 ); 93 a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ),"Edit", 0, this, 0 );
94 connect( a, SIGNAL( activated() ), this, SLOT( doEdit() ) ); 94 connect( a, SIGNAL( activated() ), this, SLOT( doEdit() ) );
95 a->addTo( ToolBar1 ); 95 a->addTo( ToolBar1 );
96 96
97 QPushButton *t; 97 QPushButton *t;
98 t= new QPushButton( "BAC", ToolBar1, "bacButtin"); 98 t= new QPushButton( "BAC", ToolBar1, "bacButtin");
99 connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) ); 99 connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) );
100 100
101 DrinkView = new QListView( this, "DrinkView" ); 101 DrinkView = new QListView( this, "DrinkView" );
102 DrinkView->addColumn( tr( "Name of Drink" ) ); 102 DrinkView->addColumn( tr( "Name of Drink" ) );
103// DrinkView->setRootIsDecorated( TRUE ); 103// DrinkView->setRootIsDecorated( TRUE );
104 DrinkView->header()->hide(); 104 DrinkView->header()->hide();
105 105
106 QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold); 106 QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold);
107 107
108 connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink(QListViewItem*))); 108 connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink(QListViewItem*)));
109 connect(DrinkView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)), 109 connect(DrinkView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)),
110 this,SLOT( showDrink(int,QListViewItem*,const QPoint&,int))); 110 this,SLOT( showDrink(int,QListViewItem*,const QPoint&,int)));
111 111
112 layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 ); 112 layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 );
113 if(QDir("db").exists()) { 113 if(QDir("db").exists()) {
114 dbFile.setName( "db/drinkdb.txt"); 114 dbFile.setName( "db/drinkdb.txt");
115 } else 115 } else
116 dbFile.setName( QPEApplication::qpeDir()+"/etc/bartender/drinkdb.txt"); 116 dbFile.setName( QPEApplication::qpeDir()+"etc/bartender/drinkdb.txt");
117 initDrinkDb(); 117 initDrinkDb();
118} 118}
119 119
120Bartender::~Bartender() { 120Bartender::~Bartender() {
121} 121}
122 122
123/* 123/*
124this happens right before exit */ 124this happens right before exit */
125void Bartender::cleanUp() { 125void Bartender::cleanUp() {
126 dbFile.close(); 126 dbFile.close();
127 127
128} 128}
129 129
130void Bartender::initDrinkDb() { 130void Bartender::initDrinkDb() {
131 131
132 if(!dbFile.isOpen()) 132 if(!dbFile.isOpen())
133 if ( !dbFile.open( IO_ReadOnly)) { 133 if ( !dbFile.open( IO_ReadOnly)) {
134 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); 134 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) );
135 return; 135 return;
136 } 136 }
137 fillList(); 137 fillList();
138} 138}
139 139
140void Bartender::fillList() { 140void Bartender::fillList() {
141 dbFile.at(1); 141 dbFile.at(1);
142 DrinkView->clear(); 142 DrinkView->clear();
143 int i=0; 143 int i=0;
144 QListViewItem * item ; 144 QListViewItem * item ;
145 QTextStream t( &dbFile); 145 QTextStream t( &dbFile);
146 QString s; 146 QString s;
147 while ( !t.eof()) { 147 while ( !t.eof()) {
148 s = t.readLine(); 148 s = t.readLine();
149 if(s.find("#",0,TRUE) != -1) { 149 if(s.find("#",0,TRUE) != -1) {
150// odebug << s.right(s.length()-2) << oendl; 150// odebug << s.right(s.length()-2) << oendl;
151 item= new QListViewItem( DrinkView, 0 ); 151 item= new QListViewItem( DrinkView, 0 );
152 item->setText( 0, s.right(s.length()-2)); 152 item->setText( 0, s.right(s.length()-2));
153 i++; 153 i++;
154 } 154 }
155 } 155 }
156 odebug << "there are currently " << i << " of drinks" << oendl; 156 odebug << "there are currently " << i << " of drinks" << oendl;
157} 157}
158 158
159void Bartender::fileNew() { 159void Bartender::fileNew() {
160 160
161 New_Drink *newDrinks; 161 New_Drink *newDrinks;
162 newDrinks = new New_Drink(this,"New Drink....", TRUE); 162 newDrinks = new New_Drink(this,"New Drink....", TRUE);
163 QString newName, newIng; 163 QString newName, newIng;
164 QPEApplication::execDialog( newDrinks ); 164 QPEApplication::execDialog( newDrinks );
165 newName = newDrinks->LineEdit1->text(); 165 newName = newDrinks->LineEdit1->text();
166 newIng= newDrinks->MultiLineEdit1->text(); 166 newIng= newDrinks->MultiLineEdit1->text();
167 167
168 if(dbFile.isOpen()) 168 if(dbFile.isOpen())
169 dbFile.close(); 169 dbFile.close();
170 if ( !dbFile.open( IO_WriteOnly| IO_Append)) { 170 if ( !dbFile.open( IO_WriteOnly| IO_Append)) {
171 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); 171 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) );
172 return; 172 return;
173 } 173 }
174 if(newDrinks ->result() == 1 ) { 174 if(newDrinks ->result() == 1 ) {
175 QString newDrink="\n# "+newName+"\n"; 175 QString newDrink="\n# "+newName+"\n";
176 newDrink.append(newIng+"\n"); 176 newDrink.append(newIng+"\n");
177 odebug << "writing "+newDrink << oendl; 177 odebug << "writing "+newDrink << oendl;
178 dbFile.writeBlock( newDrink.latin1(), newDrink.length()); 178 dbFile.writeBlock( newDrink.latin1(), newDrink.length());
179 clearList(); 179 clearList();
180 dbFile.close(); 180 dbFile.close();
181 181
182 initDrinkDb(); 182 initDrinkDb();
183 } 183 }
184 delete newDrinks; 184 delete newDrinks;
185} 185}
186 186
187void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) { 187void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) {
188 switch (mouse) { 188 switch (mouse) {
189 case 1: 189 case 1:
190// showDrink(item); 190// showDrink(item);
191 break; 191 break;
192 case 2: 192 case 2:
193 showDrink(item); 193 showDrink(item);
194 break; 194 break;
195 } 195 }
196} 196}
197 197
198void Bartender::showDrink( QListViewItem *item) { 198void Bartender::showDrink( QListViewItem *item) {
199 if(item==NULL) return; 199 if(item==NULL) return;
200 dbFile.at(0); 200 dbFile.at(0);
201 Show_Drink *showDrinks; 201 Show_Drink *showDrinks;
202 QString myDrink=item->text(0); 202 QString myDrink=item->text(0);
203 showDrinks = new Show_Drink(this, myDrink, TRUE); 203 showDrinks = new Show_Drink(this, myDrink, TRUE);
204 QTextStream t( &dbFile); 204 QTextStream t( &dbFile);
205 205
206 QString s, s2; 206 QString s, s2;
207 while ( !t.eof()) { 207 while ( !t.eof()) {
208 s = t.readLine(); 208 s = t.readLine();
209 if(s.find( myDrink, 0, TRUE) != -1) { 209 if(s.find( myDrink, 0, TRUE) != -1) {
210 for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { 210 for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) {
211 s2 = t.readLine(); 211 s2 = t.readLine();
212 if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { 212 if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) {
213// odebug << s2 << oendl; 213// odebug << s2 << oendl;
214 showDrinks->MultiLineEdit1->append(s2); 214 showDrinks->MultiLineEdit1->append(s2);
215 } 215 }
216 if( dbFile.atEnd() ) break; 216 if( dbFile.atEnd() ) break;
217 } 217 }
218 } 218 }
219 } 219 }
220 QPEApplication::execDialog( showDrinks ); 220 QPEApplication::execDialog( showDrinks );
221 221
222 if(showDrinks ->result() ==0) { 222 if(showDrinks ->result() ==0) {
223 doEdit(); 223 doEdit();
224 } 224 }
225 delete showDrinks; 225 delete showDrinks;
226} 226}
227 227
228void Bartender::askSearch() { 228void Bartender::askSearch() {
229 switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+ 229 switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+
230 "\nor alcohol ?" 230 "\nor alcohol ?"
231 ,tr("Drink Name"),tr("Alcohol"),0,0,1) ) { 231 ,tr("Drink Name"),tr("Alcohol"),0,0,1) ) {
232 case 0: 232 case 0:
233 doSearchByName(); 233 doSearchByName();
234 break; 234 break;
235 case 1: 235 case 1:
236 doSearchByDrink(); 236 doSearchByDrink();
237 break; 237 break;
238 }; 238 };
239} 239}
240 240
241/* search by name */ 241/* search by name */
242void Bartender::doSearchByName() { 242void Bartender::doSearchByName() {
243// if( DrinkView->currentItem() == NULL) return; 243// if( DrinkView->currentItem() == NULL) return;
244 QStringList searchList; 244 QStringList searchList;
245 QString searchForDrinkName; 245 QString searchForDrinkName;
246 InputDialog *fileDlg; 246 InputDialog *fileDlg;
247 fileDlg = new InputDialog(this,tr("Find by Drink Name"),TRUE, 0); 247 fileDlg = new InputDialog(this,tr("Find by Drink Name"),TRUE, 0);
248 fileDlg->exec(); 248 fileDlg->exec();
249 if( fileDlg->result() == 1 ) { 249 if( fileDlg->result() == 1 ) {
250 searchForDrinkName = fileDlg->LineEdit1->text(); 250 searchForDrinkName = fileDlg->LineEdit1->text();
251 QListViewItemIterator it( DrinkView ); 251 QListViewItemIterator it( DrinkView );
252 for ( ; it.current(); ++it ) { 252 for ( ; it.current(); ++it ) {
253 if ( it.current()->text(0).find( searchForDrinkName, 0, TRUE) != -1 ) { 253 if ( it.current()->text(0).find( searchForDrinkName, 0, TRUE) != -1 ) {
254// odebug << it.current()->text(0) << oendl; 254// odebug << it.current()->text(0) << oendl;
255 searchList.append(it.current()->text(0)); 255 searchList.append(it.current()->text(0));
256 } 256 }
257 } 257 }
258 if(searchList.count() >0) 258 if(searchList.count() >0)
259 showSearchResult(searchList); 259 showSearchResult(searchList);
260 else 260 else
261 QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+searchForDrinkName); 261 QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+searchForDrinkName);
262 }//end Inputdialog 262 }//end Inputdialog
263 delete fileDlg; 263 delete fileDlg;
264} 264}
265 265
266void Bartender::doSearchByDrink() { 266void Bartender::doSearchByDrink() {
267// if( DrinkView->currentItem() == NULL) return; 267// if( DrinkView->currentItem() == NULL) return;
268 QStringList searchList; 268 QStringList searchList;
269 QString searchForDrinkName, lastDrinkName, tempName; 269 QString searchForDrinkName, lastDrinkName, tempName;
270 270
271 InputDialog *fileDlg; 271 InputDialog *fileDlg;
272 fileDlg = new InputDialog(this,tr("Find by Alcohol"),TRUE, 0); 272 fileDlg = new InputDialog(this,tr("Find by Alcohol"),TRUE, 0);
273 fileDlg->exec(); 273 fileDlg->exec();
274 if( fileDlg->result() == 1 ) { 274 if( fileDlg->result() == 1 ) {
275 searchForDrinkName = fileDlg->LineEdit1->text(); 275 searchForDrinkName = fileDlg->LineEdit1->text();
276 276
277 dbFile.at(0); 277 dbFile.at(0);
278 QTextStream t( &dbFile); 278 QTextStream t( &dbFile);
279 279
280 QString s, s2; 280 QString s, s2;
281 while ( !t.eof()) { 281 while ( !t.eof()) {
282 s = t.readLine(); 282 s = t.readLine();
283 if(s.find("#",0,TRUE) != -1) { 283 if(s.find("#",0,TRUE) != -1) {
284 lastDrinkName=s.right(s.length()-2); 284 lastDrinkName=s.right(s.length()-2);
285// odebug << "last drink name "+lastDrinkName << oendl; 285// odebug << "last drink name "+lastDrinkName << oendl;
286 } 286 }
287 else if( s.find( searchForDrinkName ,0, FALSE) != -1 && lastDrinkName != tempName ) { 287 else if( s.find( searchForDrinkName ,0, FALSE) != -1 && lastDrinkName != tempName ) {
288// odebug << "appending "+lastDrinkName << oendl; 288// odebug << "appending "+lastDrinkName << oendl;
289 searchList.append( lastDrinkName); 289 searchList.append( lastDrinkName);
290 tempName=lastDrinkName; 290 tempName=lastDrinkName;
291 } 291 }
292// if( dbFile.atEnd() ) break; 292// if( dbFile.atEnd() ) break;
293 293
294 } //oef 294 } //oef
295 if(searchList.count() >0) 295 if(searchList.count() >0)
296 showSearchResult(searchList); 296 showSearchResult(searchList);
297 else 297 else
298 QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForDrinkName); 298 QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForDrinkName);
299 } 299 }
300 delete fileDlg; 300 delete fileDlg;
301} 301}
302 302
303void Bartender::showSearchResult(QStringList &searchList) { 303void Bartender::showSearchResult(QStringList &searchList) {
304 QString result; 304 QString result;
305 Search_Results *searchDlg; 305 Search_Results *searchDlg;
306 306
307 searchList.sort(); 307 searchList.sort();
308 308
309 searchDlg = new Search_Results(this, "Search Results", TRUE); 309 searchDlg = new Search_Results(this, "Search Results", TRUE);
310 searchDlg->ListBox1->insertStringList( searchList,-1); 310 searchDlg->ListBox1->insertStringList( searchList,-1);
311 QPEApplication::execDialog( searchDlg ); 311 QPEApplication::execDialog( searchDlg );
312 312
313 if( searchDlg->result() == 1 ) { 313 if( searchDlg->result() == 1 ) {
314 result= searchDlg->ListBox1->currentText(); 314 result= searchDlg->ListBox1->currentText();
315 } 315 }
316 QListViewItemIterator it2( DrinkView ); 316 QListViewItemIterator it2( DrinkView );
317 for ( ; it2.current(); ++it2 ) { 317 for ( ; it2.current(); ++it2 ) {
318 if ( it2.current()->text(0)== result ) { 318 if ( it2.current()->text(0)== result ) {
319// odebug << it2.current()->text(0) << oendl; 319// odebug << it2.current()->text(0) << oendl;
320 showDrink(it2.current()); 320 showDrink(it2.current());
321 } 321 }
322 } 322 }
323delete searchDlg; 323delete searchDlg;
324} 324}
325 325
326void Bartender::doEdit() { 326void Bartender::doEdit() {
327 if(DrinkView->currentItem() == NULL) { 327 if(DrinkView->currentItem() == NULL) {
328 fileNew(); 328 fileNew();
329 } 329 }
330 330
331 QString myDrink; 331 QString myDrink;
332 myDrink= DrinkView->currentItem()->text(0); 332 myDrink= DrinkView->currentItem()->text(0);
333 dbFile.at(0); 333 dbFile.at(0);
334 int foundAt=0; 334 int foundAt=0;
335 New_Drink *newDrinks; 335 New_Drink *newDrinks;
336 newDrinks = new New_Drink(this,"Edit Drink....", TRUE); 336 newDrinks = new New_Drink(this,"Edit Drink....", TRUE);
337 QString newName, newIng; 337 QString newName, newIng;
338 QPEApplication::showDialog( newDrinks ); 338 QPEApplication::showDialog( newDrinks );
339 QTextStream t( &dbFile); 339 QTextStream t( &dbFile);
340 340
341 QString s, s2; 341 QString s, s2;
342 while ( !t.eof()) { 342 while ( !t.eof()) {
343 s = t.readLine(); 343 s = t.readLine();
344 if(s.find( myDrink, 0, TRUE) != -1) { 344 if(s.find( myDrink, 0, TRUE) != -1) {
345 foundAt = dbFile.at() - (s.length()+1); 345 foundAt = dbFile.at() - (s.length()+1);
346 for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { 346 for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) {
347 s2 = t.readLine(); 347 s2 = t.readLine();
348 if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { 348 if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) {
349// odebug << s2 << oendl; 349// odebug << s2 << oendl;
350 newDrinks->MultiLineEdit1->append(s2); 350 newDrinks->MultiLineEdit1->append(s2);
351 newDrinks->LineEdit1->setText(myDrink); 351 newDrinks->LineEdit1->setText(myDrink);
352 } 352 }
353 if( dbFile.atEnd() ) break; 353 if( dbFile.atEnd() ) break;
354 } 354 }
355 } 355 }
356 } 356 }
357 newDrinks->exec(); 357 newDrinks->exec();
358 newName = newDrinks->LineEdit1->text(); 358 newName = newDrinks->LineEdit1->text();
359 newIng= newDrinks->MultiLineEdit1->text(); 359 newIng= newDrinks->MultiLineEdit1->text();
360 360
361 if( newDrinks ->result() == 1 ) { 361 if( newDrinks ->result() == 1 ) {
362 if(dbFile.isOpen()) 362 if(dbFile.isOpen())
363 dbFile.close(); 363 dbFile.close();
364 if ( !dbFile.open( IO_ReadWrite )) { 364 if ( !dbFile.open( IO_ReadWrite )) {
365 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); 365 QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) );
366 return; 366 return;
367 } 367 }
368 int fd = dbFile.handle(); 368 int fd = dbFile.handle();
369 lseek( fd, foundAt, SEEK_SET); 369 lseek( fd, foundAt, SEEK_SET);
370 370
371// dbFile.at( foundAt); 371// dbFile.at( foundAt);
372#warning FIXME problems with editing drinks db 372#warning FIXME problems with editing drinks db
373 ////////// FIXME write to user file 373 ////////// FIXME write to user file
374 QString newDrink="# "+newName+"\n"; 374 QString newDrink="# "+newName+"\n";
375 newDrink.append(newIng+"\n"); 375 newDrink.append(newIng+"\n");
376 odebug << "writing "+newDrink << oendl; 376 odebug << "writing "+newDrink << oendl;
377 dbFile.writeBlock( newDrink.latin1(), newDrink.length()); 377 dbFile.writeBlock( newDrink.latin1(), newDrink.length());
378 clearList(); 378 clearList();
379 379
380 dbFile.flush(); 380 dbFile.flush();
381 381
382 initDrinkDb(); 382 initDrinkDb();
383 } 383 }
384} 384}
385 385
386void Bartender::clearList() { 386void Bartender::clearList() {
387 DrinkView->clear(); 387 DrinkView->clear();
388} 388}
389 389
390void Bartender::doBac() { 390void Bartender::doBac() {
391 BacDialog *bacDlg; 391 BacDialog *bacDlg;
392 bacDlg = new BacDialog(this,"BAC",TRUE); 392 bacDlg = new BacDialog(this,"BAC",TRUE);
393 QPEApplication::execDialog( bacDlg ); 393 QPEApplication::execDialog( bacDlg );
394 delete bacDlg; 394 delete bacDlg;
395} 395}
396 396
397void Bartender::openCurrentDrink() { 397void Bartender::openCurrentDrink() {
398 if(DrinkView->currentItem() == NULL) return; 398 if(DrinkView->currentItem() == NULL) return;
399 showDrink(DrinkView->currentItem()); 399 showDrink(DrinkView->currentItem());
400} 400}
401 401
402void Bartender::fileMenuActivated( int item) { 402void Bartender::fileMenuActivated( int item) {
403 odebug << "Item " << item << "" << oendl; 403 odebug << "Item " << item << "" << oendl;
404 switch(item) { 404 switch(item) {
405 case -3: // new -3 405 case -3: // new -3
406 fileNew(); 406 fileNew();
407 break; 407 break;
408 case -4:// open -4 408 case -4:// open -4
409 openCurrentDrink(); 409 openCurrentDrink();
410 break; 410 break;
411 case -5:// drink -5 411 case -5:// drink -5
412 doSearchByName(); 412 doSearchByName();
413 413
414 break; 414 break;
415 case -6:// alcohol -6 415 case -6:// alcohol -6
416 doSearchByDrink(); 416 doSearchByDrink();
417 417
418 break; 418 break;
419 419
420 } 420 }
421} 421}
422 422
423void Bartender::editMenuActivated(int item) { 423void Bartender::editMenuActivated(int item) {
424 odebug << "Item " << item << "" << oendl; 424 odebug << "Item " << item << "" << oendl;
425 /* 425 /*
426 edit -8 426 edit -8
427 */ 427 */
428 switch(item) { 428 switch(item) {
429 case -8: 429 case -8:
430 doEdit() ; 430 doEdit() ;
431 break; 431 break;
432 432
433 } 433 }
434} 434}
435 435
diff --git a/noncore/apps/opie-console/fixit.cpp b/noncore/apps/opie-console/fixit.cpp
index 3b0044a..f170074 100644
--- a/noncore/apps/opie-console/fixit.cpp
+++ b/noncore/apps/opie-console/fixit.cpp
@@ -1,94 +1,94 @@
1 1
2#include "fixit.h" 2#include "fixit.h"
3 3
4using namespace Opie::Core; 4using namespace Opie::Core;
5 5
6#ifdef FSCKED_DISTRI 6#ifdef FSCKED_DISTRI
7FixIt::FixIt() { 7FixIt::FixIt() {
8 /* the new inittab */ 8 /* the new inittab */
9 m_file = "#\n# /etc/inittab" 9 m_file = "#\n# /etc/inittab"
10"#" 10"#"
11"" 11""
12"# 0 - halt (Do NOT set initdefault to this)" 12"# 0 - halt (Do NOT set initdefault to this)"
13"# 1 - Single user mode" 13"# 1 - Single user mode"
14"# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)" 14"# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)"
15"# 3 - Full multiuser mode" 15"# 3 - Full multiuser mode"
16"# 4 - JavaVM(Intent) developer mode" 16"# 4 - JavaVM(Intent) developer mode"
17"# 5 - JavaVM(Intent)" 17"# 5 - JavaVM(Intent)"
18"# 6 - reboot (Do NOT set initdefault to this)" 18"# 6 - reboot (Do NOT set initdefault to this)"
19"#" 19"#"
20"id:5:initdefault:" 20"id:5:initdefault:"
21"" 21""
22"# Specify things to do when starting" 22"# Specify things to do when starting"
23"si::sysinit:/etc/rc.d/rc.sysinit" 23"si::sysinit:/etc/rc.d/rc.sysinit"
24"" 24""
25"l0:0:wait:/root/etc/rc.d/rc 0" 25"l0:0:wait:/root/etc/rc.d/rc 0"
26"l1:1:wait:/etc/rc.d/rc 1" 26"l1:1:wait:/etc/rc.d/rc 1"
27"l2:2:wait:/etc/rc.d/rc 2" 27"l2:2:wait:/etc/rc.d/rc 2"
28"l3:3:wait:/etc/rc.d/rc 3" 28"l3:3:wait:/etc/rc.d/rc 3"
29"l4:4:wait:/etc/rc.d/rc 4" 29"l4:4:wait:/etc/rc.d/rc 4"
30"l5:5:wait:/etc/rc.d/rc 5" 30"l5:5:wait:/etc/rc.d/rc 5"
31"l6:6:wait:/root/etc/rc.d/rc 6" 31"l6:6:wait:/root/etc/rc.d/rc 6"
32"" 32""
33"# Specify things to do before rebooting" 33"# Specify things to do before rebooting"
34"um::ctrlaltdel:/bin/umount -a -r > /dev/null 2>&1" 34"um::ctrlaltdel:/bin/umount -a -r > /dev/null 2>&1"
35"sw::ctrlaltdel:/sbin/swapoff -a > /dev/null 2>&1" 35"sw::ctrlaltdel:/sbin/swapoff -a > /dev/null 2>&1"
36"" 36""
37"# Specify program to run on ttyS0" 37"# Specify program to run on ttyS0"
38"s0:24:respawn:/sbin/getty 9600 ttyS0" 38"s0:24:respawn:/sbin/getty 9600 ttyS0"
39"#pd:5:respawn:/etc/sync/serialctl" 39"#pd:5:respawn:/etc/sync/serialctl"
40"" 40""
41"# Specify program to run on tty1" 41"# Specify program to run on tty1"
42"1:2:respawn:/sbin/getty 9600 tty1" 42"1:2:respawn:/sbin/getty 9600 tty1"
43"ln:345:respawn:survive -l 6 /sbin/launch" 43"ln:345:respawn:survive -l 6 /sbin/launch"
44"#qt:5:respawn:/sbin/qt" 44"#qt:5:respawn:/sbin/qt"
45"" 45""
46"# collie sp." 46"# collie sp."
47"sy::respawn:/sbin/shsync\n"; 47"sy::respawn:/sbin/shsync\n";
48} 48}
49 49
50/* 50/*
51 * the retail Zaurus is broken in many ways 51 * the retail Zaurus is broken in many ways
52 * one is that pppd is listening on our port... 52 * one is that pppd is listening on our port...
53 * we've to stop it from that and then do kill(SIGHUP,1); 53 * we've to stop it from that and then do kill(SIGHUP,1);
54 */ 54 */
55void FixIt::fixIt() { 55void FixIt::fixIt() {
56 #ifndef EAST 56 #ifndef EAST
57 ::rename("/etc/inittab", QPEApplication::qpeDir() + "/etc/inittab" ); 57 ::rename("/etc/inittab", QPEApplication::qpeDir() + "etc/inittab" );
58 QFile file( "/etc/inittab" ); 58 QFile file( "/etc/inittab" );
59 if ( file.open(IO_WriteOnly | IO_Raw ) ) { 59 if ( file.open(IO_WriteOnly | IO_Raw ) ) {
60 file.writeBlock(m_file,strlen(m_file) ); 60 file.writeBlock(m_file,strlen(m_file) );
61 } 61 }
62 file.close(); 62 file.close();
63 ::kill( SIGHUP, 1 ); 63 ::kill( SIGHUP, 1 );
64 64
65 #else 65 #else
66 66
67 OProcess m_kill; 67 OProcess m_kill;
68 m_kill << QPEApplication::qpeDir() + "/share/opie-console/sl6000_embedix_kill_0_1.sh"; 68 m_kill << QPEApplication::qpeDir() + "share/opie-console/sl6000_embedix_kill_0_1.sh";
69 69
70 70
71 if ( !m_kill.start(OProcess::DontCare,OProcess::NoCommunication) ) { 71 if ( !m_kill.start(OProcess::DontCare,OProcess::NoCommunication) ) {
72 owarn << "could not execute kill script" << oendl; 72 owarn << "could not execute kill script" << oendl;
73 } else { 73 } else {
74 Global::statusMessage( QObject::tr("Fixing up Embedix")); 74 Global::statusMessage( QObject::tr("Fixing up Embedix"));
75 } 75 }
76 76
77 #endif 77 #endif
78} 78}
79 79
80void FixIt::breakIt() { 80void FixIt::breakIt() {
81 #ifdef EAST 81 #ifdef EAST
82 OProcess m_restart; 82 OProcess m_restart;
83 m_restart << QPEApplication::qpeDir() + "/share/opie-console/sl6000_embedix_restart_0_1.sh"; 83 m_restart << QPEApplication::qpeDir() + "share/opie-console/sl6000_embedix_restart_0_1.sh";
84 84
85 85
86 if ( !m_restart.start(OProcess::DontCare,OProcess::NoCommunication) ) { 86 if ( !m_restart.start(OProcess::DontCare,OProcess::NoCommunication) ) {
87 owarn << "could not execute restart script" << oendl; 87 owarn << "could not execute restart script" << oendl;
88 } 88 }
89 89
90 #endif 90 #endif
91} 91}
92 92
93 93
94#endif 94#endif
diff --git a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
index 020a116..3c096ed 100644
--- a/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
+++ b/noncore/apps/opie-gutenbrowser/LibraryDialog.cpp
@@ -1,1073 +1,1073 @@
1/*************************************************************************** 1/***************************************************************************
2// LibraryDialog.cpp - description 2// LibraryDialog.cpp - description
3// ------------------- 3// -------------------
4// begin : Sat Aug 19 2000 4// begin : Sat Aug 19 2000
5// copyright : (C) 2000 - 2004 by llornkcor 5// copyright : (C) 2000 - 2004 by llornkcor
6// email : ljp@llornkcor.com 6// email : ljp@llornkcor.com
7// ***************************************************/ 7// ***************************************************/
8// /*************************************************************************** 8// /***************************************************************************
9// * This program is free software; you can redistribute it and/or modify * 9// * This program is free software; you can redistribute it and/or modify *
10// * it under the terms of the GNU General Public License as published by * 10// * it under the terms of the GNU General Public License as published by *
11// * the Free Software Foundation; either version 2 of the License, or * 11// * the Free Software Foundation; either version 2 of the License, or *
12// * (at your option) any later version. * 12// * (at your option) any later version. *
13// ***************************************************************************/ 13// ***************************************************************************/
14//ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL 14//ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL
15 15
16#include "LibraryDialog.h" 16#include "LibraryDialog.h"
17#include "output.h" 17#include "output.h"
18 18
19/* OPIE */ 19/* OPIE */
20#include <qpe/applnk.h> 20#include <qpe/applnk.h>
21#include <qpe/qpeapplication.h> 21#include <qpe/qpeapplication.h>
22#include <qpe/qpedialog.h> 22#include <qpe/qpedialog.h>
23#include <opie2/odebug.h> 23#include <opie2/odebug.h>
24 24
25/* QT */ 25/* QT */
26#include <qpushbutton.h> 26#include <qpushbutton.h>
27#include <qmultilineedit.h> 27#include <qmultilineedit.h>
28//#include <qlayout.h> 28//#include <qlayout.h>
29 29
30/* STD */ 30/* STD */
31#include <unistd.h> 31#include <unistd.h>
32#include <stdio.h> 32#include <stdio.h>
33#include <stdlib.h> 33#include <stdlib.h>
34 34
35/* 35/*
36 * The dialog will by default be modeless, unless you set 'modal' to 36 * The dialog will by default be modeless, unless you set 'modal' to
37 * TRUE to construct a modal dialog. */ 37 * TRUE to construct a modal dialog. */
38LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl ) 38LibraryDialog::LibraryDialog( QWidget* parent, const char* name , bool /*modal*/, WFlags fl )
39 : QDialog( parent, name, true/* modal*/, fl ) 39 : QDialog( parent, name, true/* modal*/, fl )
40{ 40{
41 if ( !name ) 41 if ( !name )
42 setName( "LibraryDialog" ); 42 setName( "LibraryDialog" );
43 indexLoaded=false; 43 indexLoaded=false;
44 initDialog(); 44 initDialog();
45 45
46 // this->setMaximumWidth(240); 46 // this->setMaximumWidth(240);
47 47
48 index = "GUTINDEX.ALL"; 48 index = "GUTINDEX.ALL";
49 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; 49 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
50 local_index = local_library + index; 50 local_index = local_library + index;
51 51
52 QString iniFile ; 52 QString iniFile ;
53 iniFile = QPEApplication::qpeDir()+"/etc/gutenbrowser/gutenbrowserrc"; 53 iniFile = QPEApplication::qpeDir()+"etc/gutenbrowser/gutenbrowserrc";
54 54
55 new_index =QPEApplication::qpeDir()+"/etc/gutenbrowser/PGWHOLE.TXT"; 55 new_index =QPEApplication::qpeDir()+"etc/gutenbrowser/PGWHOLE.TXT";
56 56
57 old_index = QPEApplication::qpeDir()+"/etc/gutenbrowser/GUTINDEX.ALL"; 57 old_index = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL";
58 // old_index = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; 58 // old_index = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL";
59 59
60 // iniFile = local_library+"gutenbrowserrc"; 60 // iniFile = local_library+"gutenbrowserrc";
61 // new_index = local_library + "PGWHOLE.TXT"; 61 // new_index = local_library + "PGWHOLE.TXT";
62 // old_index = local_library + "GUTINDEX.ALL"; 62 // old_index = local_library + "GUTINDEX.ALL";
63 63
64 Config config("Gutenbrowser"); 64 Config config("Gutenbrowser");
65 65
66 config.setGroup( "HttpServer" ); 66 config.setGroup( "HttpServer" );
67 proxy_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); 67 proxy_http = config.readEntry("Preferred", "http://sailor.gutenbook.org");
68 68
69 config.setGroup( "FTPsite" ); 69 config.setGroup( "FTPsite" );
70 ftp_host=config.readEntry("SiteName", "sailor.gutenberg.org"); 70 ftp_host=config.readEntry("SiteName", "sailor.gutenberg.org");
71 odebug << "Library Dialog: ftp_host is "+ftp_host << oendl; 71 odebug << "Library Dialog: ftp_host is "+ftp_host << oendl;
72 // ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,TRUE)+1) ); 72 // ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,TRUE)+1) );
73 // ftp_host=ftp_host.stripWhiteSpace(); 73 // ftp_host=ftp_host.stripWhiteSpace();
74 ftp_base_dir= config.readEntry("base", "/pub/gutenberg"); 74 ftp_base_dir= config.readEntry("base", "/pub/gutenberg");
75 75
76 i_binary = 0; 76 i_binary = 0;
77 77
78 config.setGroup("SortAuth"); 78 config.setGroup("SortAuth");
79 if( config.readEntry("authSort", "FALSE") == "TRUE") 79 if( config.readEntry("authSort", "FALSE") == "TRUE")
80 authBox->setChecked(TRUE); 80 authBox->setChecked(TRUE);
81 81
82 config.setGroup("General"); 82 config.setGroup("General");
83 downDir =config.readEntry( "DownloadDirectory",local_library); 83 downDir =config.readEntry( "DownloadDirectory",local_library);
84 odebug << "downDir is "+downDir << oendl; 84 odebug << "downDir is "+downDir << oendl;
85 newindexLib.setName( old_index); 85 newindexLib.setName( old_index);
86 indexLib.setName( old_index); 86 indexLib.setName( old_index);
87 87
88 new QPEDialogListener(this); 88 new QPEDialogListener(this);
89 QTimer::singleShot( 1000, this, SLOT( FindLibrary()) ); 89 QTimer::singleShot( 1000, this, SLOT( FindLibrary()) );
90 90
91} 91}
92 92
93LibraryDialog::~LibraryDialog() 93LibraryDialog::~LibraryDialog()
94{ 94{
95// delete QList_Item2; 95// delete QList_Item2;
96// delete QList_Item1; 96// delete QList_Item1;
97// delete QList_Item3; 97// delete QList_Item3;
98// delete QList_Item4; 98// delete QList_Item4;
99// delete QList_Item5; 99// delete QList_Item5;
100 100
101 // saveConfig(); 101 // saveConfig();
102} 102}
103 103
104 /*This groks using PGWHOLE.TXT */ 104 /*This groks using PGWHOLE.TXT */
105void LibraryDialog::Newlibrary() 105void LibraryDialog::Newlibrary()
106{ 106{
107#ifndef Q_WS_QWS //sorry embedded gutenbrowser cant use zip files 107#ifndef Q_WS_QWS //sorry embedded gutenbrowser cant use zip files
108 //odebug << "Opening new library index " << newindexLib << "" << oendl; 108 //odebug << "Opening new library index " << newindexLib << "" << oendl;
109 if ( newindexLib.open( IO_ReadOnly) ) { 109 if ( newindexLib.open( IO_ReadOnly) ) {
110 setCaption( tr( "Library Index - using master pg index." ) );// file opened successfully 110 setCaption( tr( "Library Index - using master pg index." ) );// file opened successfully
111 QTextStream indexStream( &newindexLib ); 111 QTextStream indexStream( &newindexLib );
112 QString indexLine; 112 QString indexLine;
113 while ( !indexStream.atEnd() ) { // until end of file.. 113 while ( !indexStream.atEnd() ) { // until end of file..
114 indexLine = indexStream.readLine(); 114 indexLine = indexStream.readLine();
115 if ( ( indexLine.mid(4,4)).toInt() && !( indexLine.left(3)).toInt()) { 115 if ( ( indexLine.mid(4,4)).toInt() && !( indexLine.left(3)).toInt()) {
116 year = indexLine.mid(4,4); 116 year = indexLine.mid(4,4);
117 year = year.stripWhiteSpace(); 117 year = year.stripWhiteSpace();
118 file = indexLine.mid( indexLine.find( "[", 0, TRUE )+1, 12 ); 118 file = indexLine.mid( indexLine.find( "[", 0, TRUE )+1, 12 );
119 file = file.stripWhiteSpace(); 119 file = file.stripWhiteSpace();
120 number = indexLine.mid( indexLine.find( "]", 0, TRUE ) +1, indexLine.find( " ", 0, TRUE )+1 ); 120 number = indexLine.mid( indexLine.find( "]", 0, TRUE ) +1, indexLine.find( " ", 0, TRUE )+1 );
121 if( year.toInt() < 1984) 121 if( year.toInt() < 1984)
122 number = number.left( number.length() -1 ); 122 number = number.left( number.length() -1 );
123 number = number.stripWhiteSpace(); 123 number = number.stripWhiteSpace();
124 title = indexLine.mid( indexLine.find(" ", 26, TRUE), indexLine.length() ); 124 title = indexLine.mid( indexLine.find(" ", 26, TRUE), indexLine.length() );
125 title = title.stripWhiteSpace(); 125 title = title.stripWhiteSpace();
126 126
127 getAuthor(); // groks author 127 getAuthor(); // groks author
128 author = author.stripWhiteSpace(); 128 author = author.stripWhiteSpace();
129 if (authBox->isChecked()) { // this reverses the first name and last name of the author 129 if (authBox->isChecked()) { // this reverses the first name and last name of the author
130 // odebug << "Sorting last name first" << oendl; 130 // odebug << "Sorting last name first" << oendl;
131 QString lastName, firstName=""; 131 QString lastName, firstName="";
132 int finder=author.findRev( ' ', -1, TRUE); 132 int finder=author.findRev( ' ', -1, TRUE);
133 lastName=author.right( author.length()-finder); 133 lastName=author.right( author.length()-finder);
134 firstName=author.left(finder); 134 firstName=author.left(finder);
135 lastName=lastName.stripWhiteSpace(); 135 lastName=lastName.stripWhiteSpace();
136 firstName=firstName.stripWhiteSpace(); 136 firstName=firstName.stripWhiteSpace();
137 137
138 if( lastName.find( firstName, 0, true) == -1) // this avoids dup names 138 if( lastName.find( firstName, 0, true) == -1) // this avoids dup names
139 author=lastName+", "+firstName; 139 author=lastName+", "+firstName;
140 } 140 }
141 141
142 if( !number.isEmpty() && (title.find( "reserved",0, FALSE) == -1) && (file.find( "]",0, TRUE) == -1) ) { 142 if( !number.isEmpty() && (title.find( "reserved",0, FALSE) == -1) && (file.find( "]",0, TRUE) == -1) ) {
143 143
144 // fill string list or something to be able to resort the whole library 144 // fill string list or something to be able to resort the whole library
145 if( author.isEmpty() ) 145 if( author.isEmpty() )
146 QList_Item5 = new QListViewItem( ListView5, /* number,*/ title, author, year, file ); 146 QList_Item5 = new QListViewItem( ListView5, /* number,*/ title, author, year, file );
147 else { 147 else {
148 148
149 if( (author.left(1) >= QString("A") && author.left(1) <= QString("F")) || 149 if( (author.left(1) >= QString("A") && author.left(1) <= QString("F")) ||
150 (author.left(1) >= QString("a") && author.left(1) <= QString("f")) ) 150 (author.left(1) >= QString("a") && author.left(1) <= QString("f")) )
151 QList_Item1 = new QListViewItem( ListView1,/* number,*/ title, author, year, file ); 151 QList_Item1 = new QListViewItem( ListView1,/* number,*/ title, author, year, file );
152 152
153 else if( (author.left(1) >= QString("G") && author.left(1) <= QString("M")) || 153 else if( (author.left(1) >= QString("G") && author.left(1) <= QString("M")) ||
154 (author.left(1) >= QString("g") && author.left(1) <= QString("m")) ) 154 (author.left(1) >= QString("g") && author.left(1) <= QString("m")) )
155 QList_Item2 = new QListViewItem( ListView2, /*number, */title, author, year, file ); 155 QList_Item2 = new QListViewItem( ListView2, /*number, */title, author, year, file );
156 156
157 else if( (author.left(1) >= QString("N") && author.left(1) <= QString("R")) || 157 else if( (author.left(1) >= QString("N") && author.left(1) <= QString("R")) ||
158 (author.left(1) >= QString("n") && author.left(1) <= QString("r")) ) 158 (author.left(1) >= QString("n") && author.left(1) <= QString("r")) )
159 QList_Item3 = new QListViewItem( ListView3, /*number,*/ title, author, year, file ); 159 QList_Item3 = new QListViewItem( ListView3, /*number,*/ title, author, year, file );
160 160
161 else if( (author.left(1) >= QString("S") && author.left(1) <= QString("Z")) || 161 else if( (author.left(1) >= QString("S") && author.left(1) <= QString("Z")) ||
162 (author.left(1) >= QString("s") && author.left(1) <= QString("z")) ) 162 (author.left(1) >= QString("s") && author.left(1) <= QString("z")) )
163 QList_Item4 = new QListViewItem( ListView4, /* number,*/ title, author, year, file ); 163 QList_Item4 = new QListViewItem( ListView4, /* number,*/ title, author, year, file );
164 164
165 else 165 else
166 QList_Item5 = new QListViewItem( ListView5, /* number,*/ title, author, year, file ); 166 QList_Item5 = new QListViewItem( ListView5, /* number,*/ title, author, year, file );
167 } 167 }
168 } 168 }
169 }// end if 169 }// end if
170 }// end while 170 }// end while
171 newindexLib.close(); 171 newindexLib.close();
172 } 172 }
173#ifndef Q_WS_QWS 173#ifndef Q_WS_QWS
174 setCursor( arrowCursor); 174 setCursor( arrowCursor);
175#endif 175#endif
176#endif 176#endif
177} // end Newlibrary() 177} // end Newlibrary()
178 178
179 179
180void LibraryDialog::Library() 180void LibraryDialog::Library()
181{// old library groking method 181{// old library groking method
182 182
183 ListView1->clear(); 183 ListView1->clear();
184 ListView2->clear(); 184 ListView2->clear();
185 ListView3->clear(); 185 ListView3->clear();
186 ListView4->clear(); 186 ListView4->clear();
187 ListView5->clear(); 187 ListView5->clear();
188 188
189 odebug << "opening GUTINDEX.ALL file" << oendl; 189 odebug << "opening GUTINDEX.ALL file" << oendl;
190 IDontKnowWhy = ""; 190 IDontKnowWhy = "";
191 if ( indexLib.open( IO_ReadOnly) ) { // file opened successfully 191 if ( indexLib.open( IO_ReadOnly) ) { // file opened successfully
192 QTextStream indexStream( &indexLib ); 192 QTextStream indexStream( &indexLib );
193 QString indexLine; 193 QString indexLine;
194 qApp->processEvents(); 194 qApp->processEvents();
195 // int jig; 195 // int jig;
196 while ( !indexStream.eof() ) { 196 while ( !indexStream.eof() ) {
197 197
198 indexLine = indexStream.readLine(); 198 indexLine = indexStream.readLine();
199 if ( indexLine != "") { 199 if ( indexLine != "") {
200 if( (indexLine.mid(4,4)).toInt() /* && !( indexLine.left(3)).toInt()*/ ) { 200 if( (indexLine.mid(4,4)).toInt() /* && !( indexLine.left(3)).toInt()*/ ) {
201 // month = indexLine.left( 3); 201 // month = indexLine.left( 3);
202 year = indexLine.mid(4,4); 202 year = indexLine.mid(4,4);
203 // title = indexLine.mid( 9, 50); 203 // title = indexLine.mid( 9, 50);
204 file = indexLine.mid(60,12); 204 file = indexLine.mid(60,12);
205 if(file.left(1).find("[",0,TRUE) != -1) 205 if(file.left(1).find("[",0,TRUE) != -1)
206 file.remove(1,1); 206 file.remove(1,1);
207 if( file.find("]",0,TRUE) != -1) 207 if( file.find("]",0,TRUE) != -1)
208 file = file.left( file.find("]",0,TRUE)); 208 file = file.left( file.find("]",0,TRUE));
209 //odebug << "file is "+file << oendl; 209 //odebug << "file is "+file << oendl;
210 /// number = indexLine.mid( indexLine.find( "]", 0, TRUE ) +1, indexLine.find( " ", 0, TRUE )+1 ); 210 /// number = indexLine.mid( indexLine.find( "]", 0, TRUE ) +1, indexLine.find( " ", 0, TRUE )+1 );
211 number = indexLine.mid(55,5); 211 number = indexLine.mid(55,5);
212 number = number.stripWhiteSpace(); 212 number = number.stripWhiteSpace();
213 // title = indexLine.mid( indexLine.find(" ", 26, TRUE), indexLine.length() ); 213 // title = indexLine.mid( indexLine.find(" ", 26, TRUE), indexLine.length() );
214 title = indexLine.mid( 9, 50 ); 214 title = indexLine.mid( 9, 50 );
215 title = title.stripWhiteSpace(); 215 title = title.stripWhiteSpace();
216 //odebug << "title is "+title << oendl; 216 //odebug << "title is "+title << oendl;
217 getAuthor(); // grok author 217 getAuthor(); // grok author
218 author = author.stripWhiteSpace(); 218 author = author.stripWhiteSpace();
219 //odebug << "author is "+author << oendl; 219 //odebug << "author is "+author << oendl;
220 if (authBox->isChecked() == TRUE) { // this reverses the first name and last name of the author 220 if (authBox->isChecked() == TRUE) { // this reverses the first name and last name of the author
221 QString lastName, firstName=""; 221 QString lastName, firstName="";
222 int finder=author.findRev( ' ', -1, TRUE); 222 int finder=author.findRev( ' ', -1, TRUE);
223 lastName=author.right( author.length()-finder); 223 lastName=author.right( author.length()-finder);
224 firstName=author.left(finder); 224 firstName=author.left(finder);
225 lastName=lastName.stripWhiteSpace(); 225 lastName=lastName.stripWhiteSpace();
226 firstName=firstName.stripWhiteSpace(); 226 firstName=firstName.stripWhiteSpace();
227 227
228 if( lastName.find( firstName, 0, true) == -1) // this avoids dup names 228 if( lastName.find( firstName, 0, true) == -1) // this avoids dup names
229 author=lastName+", "+firstName; 229 author=lastName+", "+firstName;
230 } 230 }
231 231
232 if( !number.isEmpty() && (title.find( "reserved",0, FALSE) == -1) /*&& (file.find( "]",0, TRUE))*/ ) { 232 if( !number.isEmpty() && (title.find( "reserved",0, FALSE) == -1) /*&& (file.find( "]",0, TRUE))*/ ) {
233 // fill string list or something to be able to sort by Author 233 // fill string list or something to be able to sort by Author
234 if( author.isEmpty() ) 234 if( author.isEmpty() )
235 QList_Item5 = new QListViewItem( ListView5, /*number, */title, author, year, file ); 235 QList_Item5 = new QListViewItem( ListView5, /*number, */title, author, year, file );
236 else { 236 else {
237 if( (author.left(1) >= QString("A") && author.left(1) <= QString("F")) || 237 if( (author.left(1) >= QString("A") && author.left(1) <= QString("F")) ||
238 (author.left(1) >= QString("a") && author.left(1) <= QString("f")) ) 238 (author.left(1) >= QString("a") && author.left(1) <= QString("f")) )
239 QList_Item1 = new QListViewItem( ListView1, /* number,*/ title, author, year, file ); 239 QList_Item1 = new QListViewItem( ListView1, /* number,*/ title, author, year, file );
240 240
241 else if( (author.left(1) >= QString("G") && author.left(1) <= QString("M")) || 241 else if( (author.left(1) >= QString("G") && author.left(1) <= QString("M")) ||
242 (author.left(1) >= QString("g") && author.left(1) <= QString("m")) ) 242 (author.left(1) >= QString("g") && author.left(1) <= QString("m")) )
243 QList_Item2 = new QListViewItem( ListView2, /* number,*/ title, author, year, file ); 243 QList_Item2 = new QListViewItem( ListView2, /* number,*/ title, author, year, file );
244 244
245 else if( (author.left(1) >= QString("N") && author.left(1) <= QString("R")) || 245 else if( (author.left(1) >= QString("N") && author.left(1) <= QString("R")) ||
246 (author.left(1) >= QString("n") && author.left(1) <= QString("r")) ) 246 (author.left(1) >= QString("n") && author.left(1) <= QString("r")) )
247 QList_Item3 = new QListViewItem( ListView3, /* number,*/ title, author, year, file ); 247 QList_Item3 = new QListViewItem( ListView3, /* number,*/ title, author, year, file );
248 248
249 else if( (author.left(1) >= QString("S") && author.left(1) <= QString("Z")) || 249 else if( (author.left(1) >= QString("S") && author.left(1) <= QString("Z")) ||
250 (author.left(1) >= QString("s") && author.left(1) <= QString("z")) ) 250 (author.left(1) >= QString("s") && author.left(1) <= QString("z")) )
251 QList_Item4 = new QListViewItem( ListView4, /* number,*/ title, author, year, file ); 251 QList_Item4 = new QListViewItem( ListView4, /* number,*/ title, author, year, file );
252 } 252 }
253 } 253 }
254 } 254 }
255 } 255 }
256 } 256 }
257 indexLib.close(); 257 indexLib.close();
258 } else { 258 } else {
259 QString sMsg; 259 QString sMsg;
260 sMsg = ( tr("<p>Error opening local library index:</P> "))+local_index; 260 sMsg = ( tr("<p>Error opening local library index:</P> "))+local_index;
261 QMessageBox::message( "Error",sMsg); 261 QMessageBox::message( "Error",sMsg);
262 } 262 }
263 263
264} //end Library() 264} //end Library()
265 265
266 266
267 /* 267 /*
268 Groks the author out of the title */ 268 Groks the author out of the title */
269bool LibraryDialog::getAuthor() 269bool LibraryDialog::getAuthor()
270{ 270{
271 if( title.contains( ", by", TRUE)) { 271 if( title.contains( ", by", TRUE)) {
272 int auth; 272 int auth;
273 auth = title.find(", by", 0, TRUE); 273 auth = title.find(", by", 0, TRUE);
274 author = title.right(title.length() - (auth + 4) ); 274 author = title.right(title.length() - (auth + 4) );
275 if( int finder = author.find("[", 0, TRUE)) { 275 if( int finder = author.find("[", 0, TRUE)) {
276 author = author.left(finder); 276 author = author.left(finder);
277 } 277 }
278 } 278 }
279 else if ( title.contains( "by, ", TRUE) ) { 279 else if ( title.contains( "by, ", TRUE) ) {
280 int auth; 280 int auth;
281 auth = title.find("by, ", 0, TRUE); 281 auth = title.find("by, ", 0, TRUE);
282 author = title.right(title.length() - (auth + 4) ); 282 author = title.right(title.length() - (auth + 4) );
283 if( int finder = author.find("[", 0, TRUE)) { 283 if( int finder = author.find("[", 0, TRUE)) {
284 author = author.left( finder); 284 author = author.left( finder);
285 } 285 }
286 } 286 }
287 else if ( title.contains( " by", TRUE) ) { 287 else if ( title.contains( " by", TRUE) ) {
288 int auth; 288 int auth;
289 auth = title.find(" by", 0, TRUE); 289 auth = title.find(" by", 0, TRUE);
290 author = title.right(title.length() - (auth + 3) ); 290 author = title.right(title.length() - (auth + 3) );
291 if( int finder = author.find("[", 0, TRUE)) { 291 if( int finder = author.find("[", 0, TRUE)) {
292 author = author.left( finder); 292 author = author.left( finder);
293 } 293 }
294 } 294 }
295 else if ( title.contains( "by ", TRUE) ) { 295 else if ( title.contains( "by ", TRUE) ) {
296 int auth; 296 int auth;
297 auth = title.find("by ", 0, TRUE); 297 auth = title.find("by ", 0, TRUE);
298 author = title.right(title.length() - (auth + 3) ); 298 author = title.right(title.length() - (auth + 3) );
299 if( int finder = author.find("[", 0, TRUE)) { 299 if( int finder = author.find("[", 0, TRUE)) {
300 author = author.left( finder); 300 author = author.left( finder);
301 } 301 }
302 } 302 }
303 else if ( title.contains( ",", TRUE) ) { 303 else if ( title.contains( ",", TRUE) ) {
304 int auth; 304 int auth;
305 auth = title.find(",", 0, TRUE); 305 auth = title.find(",", 0, TRUE);
306 author = title.right( title.length() - (auth + 1) ); 306 author = title.right( title.length() - (auth + 1) );
307 if ( author.contains( ",", TRUE) ) { 307 if ( author.contains( ",", TRUE) ) {
308 int auth; 308 int auth;
309 auth = author.find(",", 0, TRUE); 309 auth = author.find(",", 0, TRUE);
310 author = author.right( author.length() - (auth + 1) ); 310 author = author.right( author.length() - (auth + 1) );
311 } 311 }
312 if( int finder = author.find("[", 0, TRUE)) { 312 if( int finder = author.find("[", 0, TRUE)) {
313 author = author.left( finder); 313 author = author.left( finder);
314 } 314 }
315 } 315 }
316 else if ( title.contains( "/", TRUE) ) { 316 else if ( title.contains( "/", TRUE) ) {
317 int auth; 317 int auth;
318 auth = title.find("/", 0, TRUE); 318 auth = title.find("/", 0, TRUE);
319 author = title.right(title.length() - (auth + 1) ); 319 author = title.right(title.length() - (auth + 1) );
320 if( int finder = author.find("[", 0, TRUE)) { 320 if( int finder = author.find("[", 0, TRUE)) {
321 author = author.left( finder); 321 author = author.left( finder);
322 } 322 }
323 } 323 }
324 else if ( title.contains( "of", TRUE) ) { 324 else if ( title.contains( "of", TRUE) ) {
325 int auth; 325 int auth;
326 auth = title.find("of", 0, TRUE); 326 auth = title.find("of", 0, TRUE);
327 author = title.right(title.length() - (auth + 2) ); 327 author = title.right(title.length() - (auth + 2) );
328 if( int finder = author.find("[", 0, TRUE)) 328 if( int finder = author.find("[", 0, TRUE))
329 { 329 {
330 author = author.left( finder); 330 author = author.left( finder);
331 } 331 }
332 } else { 332 } else {
333 author = ""; 333 author = "";
334 } 334 }
335 if ( author.contains("et. al")) { 335 if ( author.contains("et. al")) {
336 int auth; 336 int auth;
337 auth = author.find("et. al", 0, TRUE); 337 auth = author.find("et. al", 0, TRUE);
338 author = author.left( auth ); 338 author = author.left( auth );
339 } 339 }
340 if ( author.contains("#")) { 340 if ( author.contains("#")) {
341 int auth; 341 int auth;
342 auth = author.find("#", 0, TRUE); 342 auth = author.find("#", 0, TRUE);
343 author = author.left( auth); 343 author = author.left( auth);
344 } 344 }
345 if ( author.contains("(")) { 345 if ( author.contains("(")) {
346 int auth; 346 int auth;
347 auth = author.find("(", 0, TRUE); 347 auth = author.find("(", 0, TRUE);
348 author = author.left( auth); 348 author = author.left( auth);
349 } 349 }
350 if ( author.contains("et al")) { 350 if ( author.contains("et al")) {
351 int auth; 351 int auth;
352 auth = author.find("et al", 0, TRUE); 352 auth = author.find("et al", 0, TRUE);
353 author = author.left( auth ); 353 author = author.left( auth );
354 } 354 }
355 QRegExp r = QRegExp("[0-9]", TRUE, FALSE); 355 QRegExp r = QRegExp("[0-9]", TRUE, FALSE);
356 if ( author.left(2).find( r) != -1 ) { 356 if ( author.left(2).find( r) != -1 ) {
357 author = ""; 357 author = "";
358 } 358 }
359 // if( author.contains(" ", TRUE)) { 359 // if( author.contains(" ", TRUE)) {
360 // int suth = author.findRev(" ", -1, TRUE); 360 // int suth = author.findRev(" ", -1, TRUE);
361 // author = author.right( author.length() - suth); 361 // author = author.right( author.length() - suth);
362 // } 362 // }
363 363
364 // title 364 // title
365 // author 365 // author
366 return true; 366 return true;
367}////// end getAuthor() 367}////// end getAuthor()
368 368
369 /* 369 /*
370 selected one etext*/ 370 selected one etext*/
371void LibraryDialog::select_title( QListViewItem * item) 371void LibraryDialog::select_title( QListViewItem * item)
372{ 372{
373 if(item != NULL) { 373 if(item != NULL) {
374 i++; 374 i++;
375 int index = tabWidget->currentPageIndex(); 375 int index = tabWidget->currentPageIndex();
376 DlglistItemTitle = item->text(0); 376 DlglistItemTitle = item->text(0);
377 DlglistItemYear = item->text(2); 377 DlglistItemYear = item->text(2);
378 DlglistItemFile = item->text(3); 378 DlglistItemFile = item->text(3);
379 switch (index) { 379 switch (index) {
380 case 0: { 380 case 0: {
381 ListView1->clearSelection(); 381 ListView1->clearSelection();
382 } 382 }
383 break; 383 break;
384 case 1: { 384 case 1: {
385 ListView2->clearSelection(); 385 ListView2->clearSelection();
386 } 386 }
387 break; 387 break;
388 case 2: { 388 case 2: {
389 ListView3->clearSelection(); 389 ListView3->clearSelection();
390 } 390 }
391 break; 391 break;
392 case 3: { 392 case 3: {
393 ListView4->clearSelection(); 393 ListView4->clearSelection();
394 } 394 }
395 break; 395 break;
396 case 4: { 396 case 4: {
397 ListView5->clearSelection(); 397 ListView5->clearSelection();
398 } 398 }
399 break; 399 break;
400 }; 400 };
401 } 401 }
402 402
403 if(DlglistItemTitle.length()>2) { 403 if(DlglistItemTitle.length()>2) {
404 // DlglistItemNumber = item->text(0); 404 // DlglistItemNumber = item->text(0);
405 item = 0; 405 item = 0;
406 odebug << "string from librarydialog is:" << DlglistItemYear << " " << DlglistItemFile << " " << DlglistItemNumber << "" << oendl; 406 odebug << "string from librarydialog is:" << DlglistItemYear << " " << DlglistItemFile << " " << DlglistItemNumber << "" << oendl;
407 odebug << "Title is "+DlglistItemTitle << oendl; 407 odebug << "Title is "+DlglistItemTitle << oendl;
408 408
409 // check for connection here 409 // check for connection here
410 // if( get_extext()) 410 // if( get_extext())
411 411
412 if(download_Etext()) { 412 if(download_Etext()) {
413 // odebug << "get here 2" << oendl; 413 // odebug << "get here 2" << oendl;
414 if(i_binary == 1) { 414 if(i_binary == 1) {
415 415
416 } 416 }
417 if(checkBox->isChecked () ) { 417 if(checkBox->isChecked () ) {
418 accept(); 418 accept();
419 } 419 }
420 } 420 }
421 } 421 }
422} 422}
423 423
424bool LibraryDialog::download_Etext() 424bool LibraryDialog::download_Etext()
425{ // ftp method 425{ // ftp method
426 // might have to use old gpl'd ftp for embedded!! 426 // might have to use old gpl'd ftp for embedded!!
427 Config cfg("Gutenbrowser"); 427 Config cfg("Gutenbrowser");
428 cfg.setGroup("FTPsite"); 428 cfg.setGroup("FTPsite");
429 ftp_host=cfg.readEntry("SiteName", "sailor.gutenberg.org"); 429 ftp_host=cfg.readEntry("SiteName", "sailor.gutenberg.org");
430 ftp_base_dir= cfg.readEntry("base", "/pub/gutenberg"); 430 ftp_base_dir= cfg.readEntry("base", "/pub/gutenberg");
431 431
432 odebug << "about to network dialog" << oendl; 432 odebug << "about to network dialog" << oendl;
433 QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, networkUrl, outputFile; 433 QString NewlistItemNumber, NewlistItemYear, ls_result, result_line, s, dir, networkUrl, outputFile;
434 434
435 //////////////////// FIXME- if 'x' is part of real name.... 435 //////////////////// FIXME- if 'x' is part of real name....
436 NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, FALSE)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, FALSE)).find("x", 1, FALSE)); 436 NewlistItemFile = DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, FALSE)).left(DlglistItemFile.left(DlglistItemFile.find(".xxx", 1, FALSE)).find("x", 1, FALSE));
437 437
438 if( NewlistItemFile.find( DlglistItemFile.left(4) ,0,TRUE) ==-1 ) { 438 if( NewlistItemFile.find( DlglistItemFile.left(4) ,0,TRUE) ==-1 ) {
439 NewlistItemFile.replace( 0,4, DlglistItemFile.left(4)); 439 NewlistItemFile.replace( 0,4, DlglistItemFile.left(4));
440 odebug << "NewlistItemFile is now "+NewlistItemFile << oendl; 440 odebug << "NewlistItemFile is now "+NewlistItemFile << oendl;
441 } 441 }
442 NewlistItemYear = DlglistItemYear.right(2); 442 NewlistItemYear = DlglistItemYear.right(2);
443 int NewlistItemYear_Int = NewlistItemYear.toInt(0, 10); 443 int NewlistItemYear_Int = NewlistItemYear.toInt(0, 10);
444 odebug << NewlistItemYear << oendl; 444 odebug << NewlistItemYear << oendl;
445 if (NewlistItemYear_Int < 91 && NewlistItemYear_Int > 70) { 445 if (NewlistItemYear_Int < 91 && NewlistItemYear_Int > 70) {
446 NewlistItemYear = "90"; 446 NewlistItemYear = "90";
447 } 447 }
448 Edir ="etext" +NewlistItemYear; 448 Edir ="etext" +NewlistItemYear;
449 dir= ftp_base_dir + "/etext" +NewlistItemYear+"/"; 449 dir= ftp_base_dir + "/etext" +NewlistItemYear+"/";
450 if( ftp_base_dir.find("=",0,true) ) 450 if( ftp_base_dir.find("=",0,true) )
451 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1); 451 ftp_base_dir.remove( ftp_base_dir.find("=",0,true),1);
452 452
453 networkUrl= "ftp://"+ftp_host+dir; 453 networkUrl= "ftp://"+ftp_host+dir;
454 454
455 outputFile=local_library+".guten_temp"; 455 outputFile=local_library+".guten_temp";
456 //odebug << "Download file:" << NewlistItemFile << "" << oendl; 456 //odebug << "Download file:" << NewlistItemFile << "" << oendl;
457 odebug << "Checking: "+ftp_host+" "+dir+" "+outputFile+" "+NewlistItemFile << oendl; 457 odebug << "Checking: "+ftp_host+" "+dir+" "+outputFile+" "+NewlistItemFile << oendl;
458 QStringList networkList; 458 QStringList networkList;
459 networkList.append((const char *)ftp_host); 459 networkList.append((const char *)ftp_host);
460 networkList.append((const char *)dir); 460 networkList.append((const char *)dir);
461 networkList.append((const char *)outputFile); 461 networkList.append((const char *)outputFile);
462 networkList.append((const char *)NewlistItemFile); 462 networkList.append((const char *)NewlistItemFile);
463//<< (char *)ftp_host << (char *)dir << (char *)outputFile << (char *)NewlistItemFile; 463//<< (char *)ftp_host << (char *)dir << (char *)outputFile << (char *)NewlistItemFile;
464 464
465 NetworkDialog *NetworkDlg; 465 NetworkDialog *NetworkDlg;
466 NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkList); 466 NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkList);
467 467
468 468
469 if( NetworkDlg->exec() != 0 ) { // use new, improved, *INSTANT* network-dialog-file-getterer 469 if( NetworkDlg->exec() != 0 ) { // use new, improved, *INSTANT* network-dialog-file-getterer
470 File_Name= NetworkDlg->localFileName; 470 File_Name= NetworkDlg->localFileName;
471 odebug << "back to Library from Network Dialog" << oendl; 471 odebug << "back to Library from Network Dialog" << oendl;
472 odebug << "Just downloaded "+NetworkDlg->localFileName << oendl; 472 odebug << "Just downloaded "+NetworkDlg->localFileName << oendl;
473 473
474 // if (File_Name.find( local_library, 0, TRUE) != -1 ) { //could not be found 474 // if (File_Name.find( local_library, 0, TRUE) != -1 ) { //could not be found
475 // QString oldName=File_Name; 475 // QString oldName=File_Name;
476 // File_Name.replace(0,local_library.length(),downDir); 476 // File_Name.replace(0,local_library.length(),downDir);
477 // odebug << "File_Name now is "+File_Name << oendl; 477 // odebug << "File_Name now is "+File_Name << oendl;
478 478
479 // } 479 // }
480 // rename .txt to .etx 480 // rename .txt to .etx
481 if(NetworkDlg->successDownload) { 481 if(NetworkDlg->successDownload) {
482 odebug << "Filename is "+File_Name << oendl; 482 odebug << "Filename is "+File_Name << oendl;
483 if(File_Name.right(4)==".txt") { 483 if(File_Name.right(4)==".txt") {
484 QString s_fileName=File_Name; 484 QString s_fileName=File_Name;
485 s_fileName.replace( s_fileName.length()-3,3,"gtn"); 485 s_fileName.replace( s_fileName.length()-3,3,"gtn");
486 // s_fileName.replace( s_fileName.length()-3,3,"etx"); 486 // s_fileName.replace( s_fileName.length()-3,3,"etx");
487 rename(File_Name.latin1(),s_fileName.latin1()); 487 rename(File_Name.latin1(),s_fileName.latin1());
488 File_Name=s_fileName; 488 File_Name=s_fileName;
489 489
490 odebug << "Filename is now "+File_Name << oendl; 490 odebug << "Filename is now "+File_Name << oendl;
491 491
492 } 492 }
493 if(File_Name.length() > 5 ) { 493 if(File_Name.length() > 5 ) {
494 setTitle(); 494 setTitle();
495 QFileInfo fi(File_Name); 495 QFileInfo fi(File_Name);
496 QString name_file=fi.fileName(); 496 QString name_file=fi.fileName();
497 name_file=name_file.left(name_file.length()-4); 497 name_file=name_file.left(name_file.length()-4);
498 498
499 odebug << "Setting doclink" << oendl; 499 odebug << "Setting doclink" << oendl;
500 DocLnk lnk; 500 DocLnk lnk;
501 odebug << "name is "+name_file << oendl; 501 odebug << "name is "+name_file << oendl;
502 lnk.setName(name_file); //sets file name 502 lnk.setName(name_file); //sets file name
503 odebug << "Title is "+DlglistItemTitle << oendl; 503 odebug << "Title is "+DlglistItemTitle << oendl;
504 lnk.setComment(DlglistItemTitle); 504 lnk.setComment(DlglistItemTitle);
505 505
506 odebug << "Filename is "+File_Name << oendl; 506 odebug << "Filename is "+File_Name << oendl;
507 lnk.setFile(File_Name); //sets File property 507 lnk.setFile(File_Name); //sets File property
508 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D 508 lnk.setType("guten/plain");// hey is this a REGISTERED mime type?!?!? ;D
509 lnk.setExec(File_Name); 509 lnk.setExec(File_Name);
510 lnk.setIcon("gutenbrowser/Gutenbrowser"); 510 lnk.setIcon("gutenbrowser/Gutenbrowser");
511 if(!lnk.writeLink()) { 511 if(!lnk.writeLink()) {
512 odebug << "Writing doclink did not work" << oendl; 512 odebug << "Writing doclink did not work" << oendl;
513 } else { 513 } else {
514 } 514 }
515 } else 515 } else
516 QMessageBox::message("Note","<p>There was an error with the file</p>"); 516 QMessageBox::message("Note","<p>There was an error with the file</p>");
517 } 517 }
518 } 518 }
519 return true; 519 return true;
520} 520}
521 521
522bool LibraryDialog::httpDownload() 522bool LibraryDialog::httpDownload()
523{// httpDownload 523{// httpDownload
524#ifndef Q_WS_QWS 524#ifndef Q_WS_QWS
525 Config config("Gutenbrowser"); 525 Config config("Gutenbrowser");
526 config.setGroup( "Browser" ); 526 config.setGroup( "Browser" );
527 QString brow = config.readEntry("Preferred", ""); 527 QString brow = config.readEntry("Preferred", "");
528 QString file_name = "./.guten_temp"; 528 QString file_name = "./.guten_temp";
529 // config.setGroup( "HttpServer" ); 529 // config.setGroup( "HttpServer" );
530 // QString s_http = config.readEntry("Preferred", "http://sailor.gutenbook.org"); 530 // QString s_http = config.readEntry("Preferred", "http://sailor.gutenbook.org");
531 QString httpName = proxy_http + "/"+Edir; 531 QString httpName = proxy_http + "/"+Edir;
532 // progressBar->setProgress( i); 532 // progressBar->setProgress( i);
533 i++; 533 i++;
534 if ( brow != "Konq") { /////////// use lynx 534 if ( brow != "Konq") { /////////// use lynx
535 // QString cmd = "lynx -source " + httpName +" | cat >> " + file_name; 535 // QString cmd = "lynx -source " + httpName +" | cat >> " + file_name;
536 // system(cmd); 536 // system(cmd);
537 } else { //////////// use KFM 537 } else { //////////// use KFM
538 // KFM::download( httpName, file_name); 538 // KFM::download( httpName, file_name);
539 } 539 }
540 i++; 540 i++;
541 QFile tmp( file_name); 541 QFile tmp( file_name);
542 QString str; 542 QString str;
543 if (tmp.open(IO_ReadOnly)) { 543 if (tmp.open(IO_ReadOnly)) {
544 QTextStream t( &tmp ); // use a text stream 544 QTextStream t( &tmp ); // use a text stream
545 while ( !t.eof()) { 545 while ( !t.eof()) {
546 QString s = t.readLine(); 546 QString s = t.readLine();
547 if (s.contains( NewlistItemFile, FALSE) && (s.contains(".txt")) ) { 547 if (s.contains( NewlistItemFile, FALSE) && (s.contains(".txt")) ) {
548 str = s.mid( s.find( ".txt\">"+NewlistItemFile, 0, TRUE)+6, (s.find( ".txt</A>", 0, TRUE) + 4) - ( s.find( ".txt\">"+NewlistItemFile, 0, TRUE)+6 ) ); 548 str = s.mid( s.find( ".txt\">"+NewlistItemFile, 0, TRUE)+6, (s.find( ".txt</A>", 0, TRUE) + 4) - ( s.find( ".txt\">"+NewlistItemFile, 0, TRUE)+6 ) );
549 httpName += "/" + str; 549 httpName += "/" + str;
550 } 550 }
551 } //end of while loop 551 } //end of while loop
552 } 552 }
553 tmp.close(); 553 tmp.close();
554 m_getFilePath = local_library + str; 554 m_getFilePath = local_library + str;
555 i++; 555 i++;
556 if ( brow != "KFM"){ ///////// use lynx 556 if ( brow != "KFM"){ ///////// use lynx
557 QString cmd = "lynx -source " + httpName +" | cat >> " + m_getFilePath; 557 QString cmd = "lynx -source " + httpName +" | cat >> " + m_getFilePath;
558 // QMessageBox::message("Error", cmd); 558 // QMessageBox::message("Error", cmd);
559 system(cmd); 559 system(cmd);
560 } else { ////////// use KFM 560 } else { ////////// use KFM
561 // KFM::download( httpName, m_getFilePath); 561 // KFM::download( httpName, m_getFilePath);
562 } 562 }
563 i++; 563 i++;
564#endif 564#endif
565 return false; 565 return false;
566} 566}
567 567
568void LibraryDialog::cancelIt() 568void LibraryDialog::cancelIt()
569{ 569{
570 saveConfig(); 570 saveConfig();
571 571
572 DlglistItemNumber = ""; 572 DlglistItemNumber = "";
573 this->reject(); 573 this->reject();
574} 574}
575 575
576bool LibraryDialog::setTitle() 576bool LibraryDialog::setTitle()
577{ 577{
578 Config config("Gutenbrowser"); 578 Config config("Gutenbrowser");
579 odebug << "setting title" << oendl; 579 odebug << "setting title" << oendl;
580 odebug << DlglistItemTitle << oendl; 580 odebug << DlglistItemTitle << oendl;
581 581
582 if( DlglistItemTitle.find("[",0,TRUE) != -1) 582 if( DlglistItemTitle.find("[",0,TRUE) != -1)
583 DlglistItemTitle.replace(DlglistItemTitle.find("[",0,TRUE),1, "(" ); 583 DlglistItemTitle.replace(DlglistItemTitle.find("[",0,TRUE),1, "(" );
584 if( DlglistItemTitle.find("]",0,TRUE) !=-1) 584 if( DlglistItemTitle.find("]",0,TRUE) !=-1)
585 DlglistItemTitle.replace(DlglistItemTitle.find("]",0,TRUE),1, ")" ); 585 DlglistItemTitle.replace(DlglistItemTitle.find("]",0,TRUE),1, ")" );
586 odebug << "Title being set is "+DlglistItemTitle << oendl; 586 odebug << "Title being set is "+DlglistItemTitle << oendl;
587 int test = 0; 587 int test = 0;
588 QString ramble, temp; 588 QString ramble, temp;
589 config.setGroup("Files"); 589 config.setGroup("Files");
590 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); 590 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
591 int i_numofFiles = s_numofFiles.toInt(); 591 int i_numofFiles = s_numofFiles.toInt();
592 for ( int i = 0; i <= i_numofFiles; i++){ 592 for ( int i = 0; i <= i_numofFiles; i++){
593 temp.setNum( i); 593 temp.setNum( i);
594 ramble = config.readEntry( temp, "" ); 594 ramble = config.readEntry( temp, "" );
595 if( strcmp( ramble, File_Name) == 0){ 595 if( strcmp( ramble, File_Name) == 0){
596 test = 1; 596 test = 1;
597 } 597 }
598 } 598 }
599 config.setGroup("Files"); 599 config.setGroup("Files");
600 config.writeEntry( "NumberOfFiles", i_numofFiles +1 ); 600 config.writeEntry( "NumberOfFiles", i_numofFiles +1 );
601 QString interger; 601 QString interger;
602 interger.setNum( i_numofFiles +1); 602 interger.setNum( i_numofFiles +1);
603 config.writeEntry( interger, File_Name); 603 config.writeEntry( interger, File_Name);
604 config.setGroup( "Titles" ); 604 config.setGroup( "Titles" );
605 config.writeEntry( File_Name, DlglistItemTitle); 605 config.writeEntry( File_Name, DlglistItemTitle);
606 606
607 test = 0; 607 test = 0;
608 return true; 608 return true;
609} 609}
610 610
611 611
612void LibraryDialog::saveConfig() 612void LibraryDialog::saveConfig()
613{ 613{
614 Config config("Gutenbrowser"); 614 Config config("Gutenbrowser");
615 if( httpBox->isChecked() == TRUE) { 615 if( httpBox->isChecked() == TRUE) {
616 checked = 1; 616 checked = 1;
617 config.setGroup( "Proxy" ); 617 config.setGroup( "Proxy" );
618 config.writeEntry("IsChecked", "TRUE"); 618 config.writeEntry("IsChecked", "TRUE");
619 } else { 619 } else {
620 checked = 0; 620 checked = 0;
621 config.setGroup( "Proxy" ); 621 config.setGroup( "Proxy" );
622 config.writeEntry("IsChecked", "FALSE"); 622 config.writeEntry("IsChecked", "FALSE");
623 } 623 }
624 if (authBox->isChecked() == TRUE) { 624 if (authBox->isChecked() == TRUE) {
625 config.setGroup("SortAuth"); 625 config.setGroup("SortAuth");
626 config.writeEntry("authSort", "TRUE"); 626 config.writeEntry("authSort", "TRUE");
627 } else { 627 } else {
628 config.setGroup("SortAuth"); 628 config.setGroup("SortAuth");
629 config.writeEntry("authSort", "FALSE"); 629 config.writeEntry("authSort", "FALSE");
630 } 630 }
631 // config.write(); 631 // config.write();
632} 632}
633 633
634 /* 634 /*
635 searches library index for user word*/ 635 searches library index for user word*/
636void LibraryDialog::onButtonSearch() 636void LibraryDialog::onButtonSearch()
637{ 637{
638 ListView1->clearSelection(); 638 ListView1->clearSelection();
639 ListView2->clearSelection(); 639 ListView2->clearSelection();
640 ListView3->clearSelection(); 640 ListView3->clearSelection();
641 ListView4->clearSelection(); 641 ListView4->clearSelection();
642 ListView5->clearSelection(); 642 ListView5->clearSelection();
643 643
644 int curTab=tabWidget->currentPageIndex(); 644 int curTab=tabWidget->currentPageIndex();
645 SearchDialog* searchDlg; 645 SearchDialog* searchDlg;
646 646
647 // if( resultsList) 647 // if( resultsList)
648 searchDlg = new SearchDialog( this, "Library Search", TRUE); 648 searchDlg = new SearchDialog( this, "Library Search", TRUE);
649 searchDlg->setCaption( tr( "Library Search" ) ); 649 searchDlg->setCaption( tr( "Library Search" ) );
650 searchDlg->setLabel( "- author or title"); 650 searchDlg->setLabel( "- author or title");
651 QString resultString; 651 QString resultString;
652 int i_berger = 0; 652 int i_berger = 0;
653 if( searchDlg->exec() != 0 ) { 653 if( searchDlg->exec() != 0 ) {
654 QString searcherStr = searchDlg->get_text(); 654 QString searcherStr = searchDlg->get_text();
655 int fluff=0; 655 int fluff=0;
656 656
657 // int tabPage = tabWidget->currentPageIndex(); 657 // int tabPage = tabWidget->currentPageIndex();
658 // TODO ititerate here... struct<listViews>?? 658 // TODO ititerate here... struct<listViews>??
659 659
660 QListViewItemIterator it1( ListView1 ); 660 QListViewItemIterator it1( ListView1 );
661 QListViewItemIterator it2( ListView2 ); 661 QListViewItemIterator it2( ListView2 );
662 QListViewItemIterator it3( ListView3 ); 662 QListViewItemIterator it3( ListView3 );
663 QListViewItemIterator it4( ListView4 ); 663 QListViewItemIterator it4( ListView4 );
664 QListViewItemIterator it5( ListView5 ); 664 QListViewItemIterator it5( ListView5 );
665 665
666 //// this is really pitiful work, 666 //// this is really pitiful work,
667 /////// 667 ///////
668 bool cS; 668 bool cS;
669 if( searchDlg->caseSensitiveCheckBox->isChecked()) 669 if( searchDlg->caseSensitiveCheckBox->isChecked())
670 cS=true; //case sensitive 670 cS=true; //case sensitive
671 else 671 else
672 cS=false; 672 cS=false;
673 673
674 if(fluff==0) { 674 if(fluff==0) {
675 for ( ; it1.current(); ++it1 ) { 675 for ( ; it1.current(); ++it1 ) {
676 resultString = ( it1.current() )->text(0); 676 resultString = ( it1.current() )->text(0);
677 resultString += (" : "); 677 resultString += (" : ");
678 resultString += ( it1.current() )->text(2); 678 resultString += ( it1.current() )->text(2);
679 resultString += (" : "); 679 resultString += (" : ");
680 resultString += ( it1.current() )->text(3); 680 resultString += ( it1.current() )->text(3);
681 if( resultString.find( searcherStr, 0, cS) != -1) 681 if( resultString.find( searcherStr, 0, cS) != -1)
682 { 682 {
683 Searchlist.append( resultString); 683 Searchlist.append( resultString);
684 } 684 }
685 } 685 }
686 } 686 }
687 if(fluff==0) {// search routine here 687 if(fluff==0) {// search routine here
688 for ( ; it2.current(); ++it2 ) { 688 for ( ; it2.current(); ++it2 ) {
689 resultString = ( it2.current() )->text(0); 689 resultString = ( it2.current() )->text(0);
690 resultString += (" : "); 690 resultString += (" : ");
691 resultString += ( it2.current() )->text(2); 691 resultString += ( it2.current() )->text(2);
692 resultString += (" : "); 692 resultString += (" : ");
693 resultString += ( it2.current() )->text(3); 693 resultString += ( it2.current() )->text(3);
694 if( resultString.find( searcherStr, 0, cS) != -1) { 694 if( resultString.find( searcherStr, 0, cS) != -1) {
695 Searchlist.append( resultString); 695 Searchlist.append( resultString);
696 } 696 }
697 } 697 }
698 } 698 }
699 if(fluff==0) {// search routine here 699 if(fluff==0) {// search routine here
700 for ( ; it3.current(); ++it3 ) { 700 for ( ; it3.current(); ++it3 ) {
701 resultString = ( it3.current() )->text(0); 701 resultString = ( it3.current() )->text(0);
702 resultString += (" : "); 702 resultString += (" : ");
703 resultString += ( it3.current() )->text(2); 703 resultString += ( it3.current() )->text(2);
704 resultString += (" : "); 704 resultString += (" : ");
705 resultString += ( it3.current() )->text(3); 705 resultString += ( it3.current() )->text(3);
706 706
707 if( resultString.find( searcherStr, 0, cS) != -1) { 707 if( resultString.find( searcherStr, 0, cS) != -1) {
708 Searchlist.append( resultString); 708 Searchlist.append( resultString);
709 } 709 }
710 } 710 }
711 } 711 }
712 if(fluff==0) { 712 if(fluff==0) {
713 // search routine here 713 // search routine here
714 for ( ; it4.current(); ++it4 ) { 714 for ( ; it4.current(); ++it4 ) {
715 resultString = ( it4.current() )->text(0); 715 resultString = ( it4.current() )->text(0);
716 resultString += (" : "); 716 resultString += (" : ");
717 resultString += ( it4.current() )->text(2); 717 resultString += ( it4.current() )->text(2);
718 resultString += (" : "); 718 resultString += (" : ");
719 resultString += ( it4.current() )->text(3); 719 resultString += ( it4.current() )->text(3);
720 if( resultString.find( searcherStr, 0, cS) != -1) { 720 if( resultString.find( searcherStr, 0, cS) != -1) {
721 Searchlist.append( resultString); 721 Searchlist.append( resultString);
722 } 722 }
723 } 723 }
724 } 724 }
725 if(fluff==0) { // search routine here 725 if(fluff==0) { // search routine here
726 for ( ; it5.current(); ++it5 ) { 726 for ( ; it5.current(); ++it5 ) {
727 resultString = ( it5.current() )->text(0); 727 resultString = ( it5.current() )->text(0);
728 resultString += (" : "); 728 resultString += (" : ");
729 resultString += ( it5.current() )->text(2); 729 resultString += ( it5.current() )->text(2);
730 resultString += (" : "); 730 resultString += (" : ");
731 resultString += ( it5.current() )->text(3); 731 resultString += ( it5.current() )->text(3);
732 if( resultString.find( searcherStr, 0, cS) != -1) { 732 if( resultString.find( searcherStr, 0, cS) != -1) {
733 Searchlist.append( resultString); 733 Searchlist.append( resultString);
734 } 734 }
735 } 735 }
736 } 736 }
737 737
738 tabWidget->setCurrentPage( curTab); 738 tabWidget->setCurrentPage( curTab);
739 739
740 Searchlist.sort(); 740 Searchlist.sort();
741 SearchResultsDlg* SearchResultsDialog; 741 SearchResultsDlg* SearchResultsDialog;
742 SearchResultsDialog = new SearchResultsDlg( searchDlg, "Results Dialog", true, 0 , Searchlist); 742 SearchResultsDialog = new SearchResultsDlg( searchDlg, "Results Dialog", true, 0 , Searchlist);
743 743
744 SearchResultsDialog->showMaximized(); 744 SearchResultsDialog->showMaximized();
745 if( SearchResultsDialog->exec() != 0) { 745 if( SearchResultsDialog->exec() != 0) {
746 texter = SearchResultsDialog->selText; 746 texter = SearchResultsDialog->selText;
747 // odebug << texter << oendl; 747 // odebug << texter << oendl;
748 resultLs= SearchResultsDialog->resultsList; 748 resultLs= SearchResultsDialog->resultsList;
749 i_berger = 1; 749 i_berger = 1;
750 } 750 }
751 Searchlist.clear(); 751 Searchlist.clear();
752 752
753 // if(SearchResultsDialog) 753 // if(SearchResultsDialog)
754 // delete SearchResultsDialog; 754 // delete SearchResultsDialog;
755 QString tester; 755 QString tester;
756 for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) { 756 for ( QStringList::Iterator it = resultLs.begin(); it != resultLs.end(); ++it ) {
757 texter.sprintf("%s \n",(*it).latin1()); 757 texter.sprintf("%s \n",(*it).latin1());
758 // odebug << texter << oendl; 758 // odebug << texter << oendl;
759 if( tester!=texter) 759 if( tester!=texter)
760 parseSearchResults( texter); 760 parseSearchResults( texter);
761 tester = texter; 761 tester = texter;
762 } 762 }
763 if(searchDlg) 763 if(searchDlg)
764 delete searchDlg; 764 delete searchDlg;
765 } 765 }
766 if(checkBox->isChecked() ) { 766 if(checkBox->isChecked() ) {
767 accept(); 767 accept();
768 } else { 768 } else {
769 setActiveWindow(); 769 setActiveWindow();
770 } 770 }
771} 771}
772 772
773 /* 773 /*
774 splits the result string and calls download for the current search result*/ 774 splits the result string and calls download for the current search result*/
775void LibraryDialog::parseSearchResults( QString resultStr) 775void LibraryDialog::parseSearchResults( QString resultStr)
776{ 776{
777 777
778 int stringLeng=resultStr.length(); 778 int stringLeng=resultStr.length();
779 QString my; 779 QString my;
780 my.setNum( stringLeng, 10); 780 my.setNum( stringLeng, 10);
781 781
782 if( resultStr.length() > 2 && resultStr.length() < 130) { 782 if( resultStr.length() > 2 && resultStr.length() < 130) {
783 int titleInt = resultStr.find( " : ", 0, TRUE); 783 int titleInt = resultStr.find( " : ", 0, TRUE);
784 DlglistItemTitle = resultStr.left( titleInt); 784 DlglistItemTitle = resultStr.left( titleInt);
785 int yearInt = resultStr.find( " : ", titleInt+3, TRUE); 785 int yearInt = resultStr.find( " : ", titleInt+3, TRUE);
786 DlglistItemYear = resultStr.mid( titleInt+3, (yearInt - titleInt)-3); 786 DlglistItemYear = resultStr.mid( titleInt+3, (yearInt - titleInt)-3);
787 DlglistItemFile = resultStr.right( resultStr.length() - (yearInt + 3)); 787 DlglistItemFile = resultStr.right( resultStr.length() - (yearInt + 3));
788 download_Etext(); 788 download_Etext();
789 } 789 }
790 /* 790 /*
791 printf( DlglistItemTitle+"\n"); printf( DlglistItemYear+"\n"); printf( DlglistItemFile+"\n");*/ 791 printf( DlglistItemTitle+"\n"); printf( DlglistItemYear+"\n"); printf( DlglistItemFile+"\n");*/
792} 792}
793 793
794 // bool LibraryDialog::UnzipIt( QString zipFile) { 794 // bool LibraryDialog::UnzipIt( QString zipFile) {
795 // //////////TODO findsome other way of dealingwithzip files. 795 // //////////TODO findsome other way of dealingwithzip files.
796 // ///usr/bin/unzip"; 796 // ///usr/bin/unzip";
797 // if( QFile::exists( zipFile)) { 797 // if( QFile::exists( zipFile)) {
798 // // QString thatFile = local_library +"PGWHOLE.TXT"; 798 // // QString thatFile = local_library +"PGWHOLE.TXT";
799 // QString cmd; 799 // QString cmd;
800 // #if defined(_WS_X11_) 800 // #if defined(_WS_X11_)
801 // cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library; 801 // cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library;
802 // #endif 802 // #endif
803 // #if defined(_WS_WIN_) 803 // #if defined(_WS_WIN_)
804 // QString temp= QDir::convertSeparators(local_library); 804 // QString temp= QDir::convertSeparators(local_library);
805 // zipFile=QDir::convertSeparators( zipFile); 805 // zipFile=QDir::convertSeparators( zipFile);
806 // cmd = temp+"unzip.exe -o " +zipFile/*newestLibraryFile */+" -d " + temp; 806 // cmd = temp+"unzip.exe -o " +zipFile/*newestLibraryFile */+" -d " + temp;
807 // #endif 807 // #endif
808 // #ifndef Q_WS_QWS 808 // #ifndef Q_WS_QWS
809 // // QString cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library; 809 // // QString cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library;
810 // cmd = "unzip " + zipFile; 810 // cmd = "unzip " + zipFile;
811 // #endif 811 // #endif
812 812
813 // int exit=QMessageBox::information(this, "Unzip?", "Ok to unzip "+ zipFile+" ?", QMessageBox::Yes, QMessageBox::No); 813 // int exit=QMessageBox::information(this, "Unzip?", "Ok to unzip "+ zipFile+" ?", QMessageBox::Yes, QMessageBox::No);
814 // if (exit==QMessageBox::Yes) { 814 // if (exit==QMessageBox::Yes) {
815 // odebug << "Issuing the command "+cmd << oendl; 815 // odebug << "Issuing the command "+cmd << oendl;
816 // #if defined(_WS_WIN_) 816 // #if defined(_WS_WIN_)
817 // WinExec( cmd, SW_HIDE ); 817 // WinExec( cmd, SW_HIDE );
818 // #endif 818 // #endif
819 // #if defined(_WS_X11_) 819 // #if defined(_WS_X11_)
820 // system( cmd); 820 // system( cmd);
821 // #endif 821 // #endif
822 // #ifndef Q_WS_QWS 822 // #ifndef Q_WS_QWS
823 // system( cmd); 823 // system( cmd);
824 // #endif 824 // #endif
825 // // printf("unzip\n"); 825 // // printf("unzip\n");
826 // // remove( zipFile /*newestLibraryFile*/); 826 // // remove( zipFile /*newestLibraryFile*/);
827 // return true; 827 // return true;
828 // } 828 // }
829 // else if(exit==QMessageBox::No) { 829 // else if(exit==QMessageBox::No) {
830 // // printf("unzip\n"); 830 // // printf("unzip\n");
831 // return false; 831 // return false;
832 // } 832 // }
833 // } else { 833 // } else {
834 // // QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) ); 834 // // QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) );
835 // return false; 835 // return false;
836 // } 836 // }
837 // return true; 837 // return true;
838 // } 838 // }
839 839
840void LibraryDialog::sort() 840void LibraryDialog::sort()
841{ 841{
842 842
843} 843}
844 844
845 /* 845 /*
846 Downloads the current selected listitem*/ 846 Downloads the current selected listitem*/
847bool LibraryDialog::getItem(QListViewItem *it) 847bool LibraryDialog::getItem(QListViewItem *it)
848{ 848{
849 // odebug << "selected getItem" << oendl; 849 // odebug << "selected getItem" << oendl;
850 850
851 // DlglistItemNumber = it->text(0); 851 // DlglistItemNumber = it->text(0);
852 DlglistItemTitle = it->text(0); 852 DlglistItemTitle = it->text(0);
853 DlglistItemYear = it->text(2); 853 DlglistItemYear = it->text(2);
854 DlglistItemFile = it->text(3); 854 DlglistItemFile = it->text(3);
855 855
856 if(download_Etext()) { 856 if(download_Etext()) {
857 if(i_binary == 1) { 857 if(i_binary == 1) {
858 } 858 }
859 } 859 }
860 return true; 860 return true;
861} 861}
862 862
863 /* 863 /*
864 download button is pushed so we get the current items to download*/ 864 download button is pushed so we get the current items to download*/
865bool LibraryDialog::onButtonDownload() 865bool LibraryDialog::onButtonDownload()
866{ 866{
867 // odebug << "selected onButtonDownloadz" << oendl; 867 // odebug << "selected onButtonDownloadz" << oendl;
868 868
869 QListViewItemIterator it1( ListView1 ); 869 QListViewItemIterator it1( ListView1 );
870 QListViewItemIterator it2( ListView2 ); 870 QListViewItemIterator it2( ListView2 );
871 QListViewItemIterator it3( ListView3 ); 871 QListViewItemIterator it3( ListView3 );
872 QListViewItemIterator it4( ListView4 ); 872 QListViewItemIterator it4( ListView4 );
873 QListViewItemIterator it5( ListView5 ); 873 QListViewItemIterator it5( ListView5 );
874 874
875 // iterate through all items of the listview 875 // iterate through all items of the listview
876 for ( ; it1.current(); ++it1 ) { 876 for ( ; it1.current(); ++it1 ) {
877 if ( it1.current()->isSelected() ) 877 if ( it1.current()->isSelected() )
878 getItem(it1.current()); 878 getItem(it1.current());
879 it1.current()->setSelected(FALSE); 879 it1.current()->setSelected(FALSE);
880 } 880 }
881 for ( ; it2.current(); ++it2 ) { 881 for ( ; it2.current(); ++it2 ) {
882 if ( it2.current()->isSelected() ) 882 if ( it2.current()->isSelected() )
883 getItem(it2.current()); 883 getItem(it2.current());
884 it2.current()->setSelected(FALSE); 884 it2.current()->setSelected(FALSE);
885 } 885 }
886 for ( ; it3.current(); ++it3 ) { 886 for ( ; it3.current(); ++it3 ) {
887 if ( it3.current()->isSelected() ) 887 if ( it3.current()->isSelected() )
888 getItem(it3.current()); 888 getItem(it3.current());
889 it3.current()->setSelected(FALSE); 889 it3.current()->setSelected(FALSE);
890 } 890 }
891 for ( ; it4.current(); ++it4 ) { 891 for ( ; it4.current(); ++it4 ) {
892 if ( it4.current()->isSelected() ) 892 if ( it4.current()->isSelected() )
893 getItem(it4.current()); 893 getItem(it4.current());
894 it4.current()->setSelected(FALSE); 894 it4.current()->setSelected(FALSE);
895 } 895 }
896 for ( ; it5.current(); ++it5 ) { 896 for ( ; it5.current(); ++it5 ) {
897 if ( it5.current()->isSelected() ) 897 if ( it5.current()->isSelected() )
898 getItem(it5.current()); 898 getItem(it5.current());
899 it5.current()->setSelected(FALSE); 899 it5.current()->setSelected(FALSE);
900 } 900 }
901 return true; 901 return true;
902} 902}
903 903
904 904
905 /* 905 /*
906 handles the sorting combo box */ 906 handles the sorting combo box */
907void LibraryDialog::comboSelect(int index) 907void LibraryDialog::comboSelect(int index)
908{ 908{
909 // odebug << "we are sorting" << oendl; 909 // odebug << "we are sorting" << oendl;
910 ListView1->setSorting( index, TRUE); 910 ListView1->setSorting( index, TRUE);
911 ListView2->setSorting( index, TRUE); 911 ListView2->setSorting( index, TRUE);
912 ListView3->setSorting( index, TRUE); 912 ListView3->setSorting( index, TRUE);
913 ListView4->setSorting( index, TRUE); 913 ListView4->setSorting( index, TRUE);
914 ListView5->setSorting( index, TRUE); 914 ListView5->setSorting( index, TRUE);
915 915
916 ListView1->sort(); 916 ListView1->sort();
917 ListView2->sort(); 917 ListView2->sort();
918 ListView3->sort(); 918 ListView3->sort();
919 ListView4->sort(); 919 ListView4->sort();
920 ListView5->sort(); 920 ListView5->sort();
921 921
922 // ListView1->triggerUpdate(); 922 // ListView1->triggerUpdate();
923 // ListView2->triggerUpdate(); 923 // ListView2->triggerUpdate();
924 // ListView3->triggerUpdate(); 924 // ListView3->triggerUpdate();
925 // ListView4->triggerUpdate(); 925 // ListView4->triggerUpdate();
926 // ListView5->triggerUpdate(); 926 // ListView5->triggerUpdate();
927} 927}
928 928
929void LibraryDialog::newList() 929void LibraryDialog::newList()
930{ 930{
931 if(indexLoaded) { 931 if(indexLoaded) {
932 onButtonDownload(); 932 onButtonDownload();
933 } else { 933 } else {
934 Output *outDlg; 934 Output *outDlg;
935 buttonNewList->setDown(TRUE); 935 buttonNewList->setDown(TRUE);
936 QDir gutDir(QPEApplication::qpeDir()+"etc/gutenbrowser"); 936 QDir gutDir(QPEApplication::qpeDir()+"etc/gutenbrowser");
937 if(!gutDir.exists()) gutDir.mkdir(QPEApplication::qpeDir()+"etc/gutenbrowser",true); 937 if(!gutDir.exists()) gutDir.mkdir(QPEApplication::qpeDir()+"etc/gutenbrowser",true);
938 if( chdir(QPEApplication::qpeDir()+"etc/gutenbrowser") == 0) { 938 if( chdir(QPEApplication::qpeDir()+"etc/gutenbrowser") == 0) {
939 odebug << "changing dir "+QPEApplication::qpeDir()+"etc/gutenbrowser" << oendl; 939 odebug << "changing dir "+QPEApplication::qpeDir()+"etc/gutenbrowser" << oendl;
940 QString gutenindex1 = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; 940 QString gutenindex1 = QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL";
941 QString cmd="wget -O " + gutenindex1 + " http://sailor.gutenberg.org/GUTINDEX.ALL 2>&1"; 941 QString cmd="wget -O " + gutenindex1 + " http://sailor.gutenberg.org/GUTINDEX.ALL 2>&1";
942 942
943 int result = QMessageBox::warning( this,"Download" 943 int result = QMessageBox::warning( this,"Download"
944 ,"<p>Ok to use /'wget/' to download a new library list?</P>" 944 ,"<p>Ok to use /'wget/' to download a new library list?</P>"
945 ,"Yes","No",0,0,1); 945 ,"Yes","No",0,0,1);
946 qApp->processEvents(); 946 qApp->processEvents();
947 if(result == 0) { 947 if(result == 0) {
948 outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),TRUE); 948 outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),TRUE);
949 outDlg->showMaximized(); 949 outDlg->showMaximized();
950 outDlg->show(); 950 outDlg->show();
951 qApp->processEvents(); 951 qApp->processEvents();
952 FILE *fp; 952 FILE *fp;
953 char line[130]; 953 char line[130];
954 outDlg->OutputEdit->append( tr("Running wget") ); 954 outDlg->OutputEdit->append( tr("Running wget") );
955 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 955 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
956 sleep(1); 956 sleep(1);
957 fp = popen( (const char *) cmd, "r"); 957 fp = popen( (const char *) cmd, "r");
958 if ( !fp ) { 958 if ( !fp ) {
959 } else { 959 } else {
960 odebug << "Issuing the command\n"+cmd << oendl; 960 odebug << "Issuing the command\n"+cmd << oendl;
961 // system(cmd); 961 // system(cmd);
962 while ( fgets( line, sizeof line, fp)) { 962 while ( fgets( line, sizeof line, fp)) {
963 outDlg->OutputEdit->append(line); 963 outDlg->OutputEdit->append(line);
964 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 964 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
965 } 965 }
966 pclose(fp); 966 pclose(fp);
967 outDlg->OutputEdit->append("Finished downloading\n"); 967 outDlg->OutputEdit->append("Finished downloading\n");
968 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 968 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
969 qApp->processEvents(); 969 qApp->processEvents();
970 970
971 // if( QFile(gutenindex1).exists() ) { 971 // if( QFile(gutenindex1).exists() ) {
972 // QString gutenindex=QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL"; 972 // QString gutenindex=QPEApplication::qpeDir()+"etc/gutenbrowser/GUTINDEX.ALL";
973 // if( rename(gutenindex1.latin1(),gutenindex.latin1()) !=0) 973 // if( rename(gutenindex1.latin1(),gutenindex.latin1()) !=0)
974 // odebug << "renaming error" << oendl; 974 // odebug << "renaming error" << oendl;
975 // } 975 // }
976 976
977 } 977 }
978 // outDlg->close(); 978 // outDlg->close();
979 FindLibrary(); 979 FindLibrary();
980 if(outDlg) delete outDlg; 980 if(outDlg) delete outDlg;
981 } 981 }
982 buttonNewList->setDown(FALSE); 982 buttonNewList->setDown(FALSE);
983 } else { 983 } else {
984 QMessageBox::message("Note","Could not change directories"); 984 QMessageBox::message("Note","Could not change directories");
985 } 985 }
986 // if(outDlg) 986 // if(outDlg)
987 // delete outDlg; 987 // delete outDlg;
988 } 988 }
989} 989}
990 990
991bool LibraryDialog::moreInfo() 991bool LibraryDialog::moreInfo()
992{ 992{
993 993
994 QListViewItem * item; 994 QListViewItem * item;
995 item = 0; 995 item = 0;
996 QString titleString; 996 QString titleString;
997 item = ListView1->currentItem(); 997 item = ListView1->currentItem();
998 if( item != 0) { 998 if( item != 0) {
999 titleString = item->text(0); 999 titleString = item->text(0);
1000 ListView1->clearSelection(); 1000 ListView1->clearSelection();
1001 item = 0; 1001 item = 0;
1002 } 1002 }
1003 if( item == 0) 1003 if( item == 0)
1004 item = ListView2->currentItem(); 1004 item = ListView2->currentItem();
1005 if( item != 0) { 1005 if( item != 0) {
1006 titleString = item->text(0); 1006 titleString = item->text(0);
1007 ListView2->clearSelection(); 1007 ListView2->clearSelection();
1008 item = 0; 1008 item = 0;
1009 } 1009 }
1010 if( item == 0) 1010 if( item == 0)
1011 item = ListView3->currentItem(); 1011 item = ListView3->currentItem();
1012 if( item != 0) { 1012 if( item != 0) {
1013 titleString = item->text(0); 1013 titleString = item->text(0);
1014 ListView3->clearSelection(); 1014 ListView3->clearSelection();
1015 item = 0; 1015 item = 0;
1016 } 1016 }
1017 if( item == 0) 1017 if( item == 0)
1018 item = ListView4->currentItem(); 1018 item = ListView4->currentItem();
1019 if( item != 0) { 1019 if( item != 0) {
1020 titleString = item->text(0); 1020 titleString = item->text(0);
1021 ListView4->clearSelection(); 1021 ListView4->clearSelection();
1022 item = 0; 1022 item = 0;
1023 } 1023 }
1024 if( item == 0) 1024 if( item == 0)
1025 item = ListView5->currentItem(); 1025 item = ListView5->currentItem();
1026 if( item != 0) { 1026 if( item != 0) {
1027 titleString = item->text(0); 1027 titleString = item->text(0);
1028 ListView5->clearSelection(); 1028 ListView5->clearSelection();
1029 item = 0; 1029 item = 0;
1030 } 1030 }
1031 item=0; 1031 item=0;
1032 if(titleString.length()>2) { 1032 if(titleString.length()>2) {
1033 odebug << "Title is "+titleString << oendl; 1033 odebug << "Title is "+titleString << oendl;
1034 titleString.replace( QRegExp("\\s"), "%20"); 1034 titleString.replace( QRegExp("\\s"), "%20");
1035 titleString.replace( QRegExp("'"), "%20"); 1035 titleString.replace( QRegExp("'"), "%20");
1036 titleString.replace( QRegExp("\""), "%20"); 1036 titleString.replace( QRegExp("\""), "%20");
1037 titleString.replace( QRegExp("&"), "%20"); 1037 titleString.replace( QRegExp("&"), "%20");
1038 QString cmd= "http://google.com/search?q="+titleString+"&num=30&sa=Google+Search"; 1038 QString cmd= "http://google.com/search?q="+titleString+"&num=30&sa=Google+Search";
1039 cmd="opera "+cmd; 1039 cmd="opera "+cmd;
1040 system(cmd); 1040 system(cmd);
1041 } else 1041 } else
1042 QMessageBox::message( "Note","<p>If you select a title, this will search google.com for that title.</p>"); 1042 QMessageBox::message( "Note","<p>If you select a title, this will search google.com for that title.</p>");
1043 return true; 1043 return true;
1044 1044
1045} 1045}
1046 1046
1047 /* 1047 /*
1048 This loads the library Index*/ 1048 This loads the library Index*/
1049void LibraryDialog::FindLibrary() 1049void LibraryDialog::FindLibrary()
1050{ 1050{
1051 buttonLibrary->setDown(TRUE); 1051 buttonLibrary->setDown(TRUE);
1052 1052
1053 qApp->processEvents(); 1053 qApp->processEvents();
1054 if( QFile( new_index).exists() /* && this->isHidden() */) { 1054 if( QFile( new_index).exists() /* && this->isHidden() */) {
1055 newindexLib.setName( new_index); 1055 newindexLib.setName( new_index);
1056 indexLib.setName( new_index); 1056 indexLib.setName( new_index);
1057 odebug << "index file is "+ new_index << oendl; 1057 odebug << "index file is "+ new_index << oendl;
1058 Newlibrary(); 1058 Newlibrary();
1059 } else { 1059 } else {
1060 newindexLib.setName( old_index); 1060 newindexLib.setName( old_index);
1061 indexLib.setName( old_index); 1061 indexLib.setName( old_index);
1062 odebug << "new index nameis "+ old_index << oendl; 1062 odebug << "new index nameis "+ old_index << oendl;
1063 Library(); 1063 Library();
1064 } 1064 }
1065 indexLoaded=true; 1065 indexLoaded=true;
1066 buttonSearch->setEnabled(TRUE); 1066 buttonSearch->setEnabled(TRUE);
1067 moreInfoButton->setEnabled(TRUE); 1067 moreInfoButton->setEnabled(TRUE);
1068 1068
1069 buttonLibrary->setDown(FALSE); 1069 buttonLibrary->setDown(FALSE);
1070 buttonNewList->setText("Download"); 1070 buttonNewList->setText("Download");
1071 qApp->processEvents(); 1071 qApp->processEvents();
1072 1072
1073} 1073}
diff --git a/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp b/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp
index a9c7346..de9c72b 100644
--- a/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp
+++ b/noncore/apps/opie-gutenbrowser/ftpsitedlg.cpp
@@ -1,252 +1,252 @@
1/*************************************************************************** 1/***************************************************************************
2 ftpsitedlg.cpp - description 2 ftpsitedlg.cpp - description
3 ------------------- 3 -------------------
4 begin : Tue Jul 25 2000 4 begin : Tue Jul 25 2000
5 copyright : (C) 2000 -2004 by llornkcor 5 copyright : (C) 2000 -2004 by llornkcor
6 email : ljp@llornkcor.com 6 email : ljp@llornkcor.com
7 ***************************************************************************/ 7 ***************************************************************************/
8/*************************************************************************** 8/***************************************************************************
9 * This program is free software; you can redistribute it and/or modify * 9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by * 10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or * 11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. * 12 * (at your option) any later version. *
13 ***************************************************************************/ 13 ***************************************************************************/
14 14
15#include "optionsDialog.h" 15#include "optionsDialog.h"
16#include "gutenbrowser.h" 16#include "gutenbrowser.h"
17//#include "NetworkDialog.h" 17//#include "NetworkDialog.h"
18#include "output.h" 18#include "output.h"
19 19
20/* OPIE */ 20/* OPIE */
21#include <opie2/odebug.h> 21#include <opie2/odebug.h>
22#include <qpe/config.h> 22#include <qpe/config.h>
23 23
24/* QT */ 24/* QT */
25#include <qprogressbar.h> 25#include <qprogressbar.h>
26#include <qurloperator.h> 26#include <qurloperator.h>
27#include <qlistbox.h> 27#include <qlistbox.h>
28 28
29/* STD */ 29/* STD */
30#include <stdlib.h> 30#include <stdlib.h>
31#include <unistd.h> 31#include <unistd.h>
32#include <stdio.h> 32#include <stdio.h>
33 33
34// :)~ 34// :)~
35void optionsDialog::ftpSiteDlg( ) 35void optionsDialog::ftpSiteDlg( )
36{ 36{
37//printf( "ftpSiteDlg: ListFile is "+ ListFile +"\n" ); 37//printf( "ftpSiteDlg: ListFile is "+ ListFile +"\n" );
38// initDialog(); 38// initDialog();
39 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; 39 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
40// ListFile = local_library + "ftpList"; 40// ListFile = local_library + "ftpList";
41 ListFile = QPEApplication::qpeDir() + "/etc/gutenbrowser"; 41 ListFile = QPEApplication::qpeDir() + "etc/gutenbrowser";
42 QDir dir(ListFile); 42 QDir dir(ListFile);
43 if( !dir.exists()) 43 if( !dir.exists())
44 dir.mkdir(ListFile,true); 44 dir.mkdir(ListFile,true);
45 ListFile+="/ftpList"; 45 ListFile+="/ftpList";
46 odebug << "opening "+ListFile << oendl; 46 odebug << "opening "+ListFile << oendl;
47 if ( QFile(ListFile).exists() ) { 47 if ( QFile(ListFile).exists() ) {
48 openSiteList(); 48 openSiteList();
49 } else { 49 } else {
50 switch( QMessageBox::warning( this, "Gutenbrowser", 50 switch( QMessageBox::warning( this, "Gutenbrowser",
51 "Do you want to download \nan ftp site list?", 51 "Do you want to download \nan ftp site list?",
52 QMessageBox::Yes, QMessageBox::No)) { 52 QMessageBox::Yes, QMessageBox::No)) {
53 case QMessageBox::Yes: // yes 53 case QMessageBox::Yes: // yes
54 getSite(); 54 getSite();
55 break; 55 break;
56 case QMessageBox::No: // No 56 case QMessageBox::No: // No
57 // exit 57 // exit
58 break; 58 break;
59 } 59 }
60 60
61 } 61 }
62} 62}
63 63
64 64
65/* 65/*
66// get ftp list from web- parse it. */ 66// get ftp list from web- parse it. */
67void optionsDialog::getSite() 67void optionsDialog::getSite()
68{ 68{
69 QString file_name; 69 QString file_name;
70 QString ftp_listFileURL; 70 QString ftp_listFileURL;
71 QString outputFile; 71 QString outputFile;
72// outputFile = local_library+ "list.html"; 72// outputFile = local_library+ "list.html";
73 outputFile = ListFile + "list.html"; 73 outputFile = ListFile + "list.html";
74 QString networkUrl= "http://www.gutenberg.org/www/mirror.sites.html"; 74 QString networkUrl= "http://www.gutenberg.org/www/mirror.sites.html";
75//http://www.gutenberg.org/index.html"; 75//http://www.gutenberg.org/index.html";
76// QString networkUrl= "http://llornkcor.com/index.shtml"; 76// QString networkUrl= "http://llornkcor.com/index.shtml";
77// // "http://www.gutenberg.org/index.html" 77// // "http://www.gutenberg.org/index.html"
78// 78//
79//Qhttp stops working at times.... :( 79//Qhttp stops working at times.... :(
80// NetworkDialog *NetworkDlg; 80// NetworkDialog *NetworkDlg;
81// NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog",TRUE,0,networkUrl,outputFile); 81// NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog",TRUE,0,networkUrl,outputFile);
82// if( NetworkDlg->exec() != 0 ) 82// if( NetworkDlg->exec() != 0 )
83// { // use new, improved, *INSTANT* network-dialog-file-getterer 83// { // use new, improved, *INSTANT* network-dialog-file-getterer
84// odebug << "gitcha!" << oendl; 84// odebug << "gitcha!" << oendl;
85// } 85// }
86// delete NetworkDlg; 86// delete NetworkDlg;
87//#ifdef Q_WS_QWS 87//#ifdef Q_WS_QWS
88 88
89// TODO qprocess here 89// TODO qprocess here
90 90
91 QString cmd="wget -T 15 -O " +outputFile + " " + networkUrl + " 2>&1" ; 91 QString cmd="wget -T 15 -O " +outputFile + " " + networkUrl + " 2>&1" ;
92 odebug << "Issuing the command "+cmd << oendl; 92 odebug << "Issuing the command "+cmd << oendl;
93 Output *outDlg; 93 Output *outDlg;
94 outDlg = new Output( 0, tr("Downloading ftp sites...."),TRUE); 94 outDlg = new Output( 0, tr("Downloading ftp sites...."),TRUE);
95 outDlg->showMaximized(); 95 outDlg->showMaximized();
96 outDlg->show(); 96 outDlg->show();
97 qApp->processEvents(); 97 qApp->processEvents();
98 FILE *fp; 98 FILE *fp;
99 char line[130]; 99 char line[130];
100 outDlg->OutputEdit->append( tr("Running wget") ); 100 outDlg->OutputEdit->append( tr("Running wget") );
101 sleep(1); 101 sleep(1);
102 fp = popen( (const char *) cmd, "r"); 102 fp = popen( (const char *) cmd, "r");
103 while ( fgets( line, sizeof line, fp)) { 103 while ( fgets( line, sizeof line, fp)) {
104 outDlg->OutputEdit->append(line); 104 outDlg->OutputEdit->append(line);
105 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 105 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
106 } 106 }
107 pclose(fp); 107 pclose(fp);
108 outDlg->close(); 108 outDlg->close();
109 if(outDlg) 109 if(outDlg)
110 delete outDlg; 110 delete outDlg;
111 111
112// outputFile=ListFile; 112// outputFile=ListFile;
113 ftp_QListBox_1->clear(); 113 ftp_QListBox_1->clear();
114 parseFtpList( outputFile); // got the html list, now parse it so we can use it 114 parseFtpList( outputFile); // got the html list, now parse it so we can use it
115} 115}
116 116
117bool optionsDialog::parseFtpList( QString outputFile) 117bool optionsDialog::parseFtpList( QString outputFile)
118{ 118{
119// parse ftplist html and extract just the machine names/directories 119// parse ftplist html and extract just the machine names/directories
120// TODO: add locations!! 120// TODO: add locations!!
121 odebug << "parse ftplist "+outputFile << oendl; 121 odebug << "parse ftplist "+outputFile << oendl;
122 QString ftpList, s_location; 122 QString ftpList, s_location;
123 QFile f( outputFile ); 123 QFile f( outputFile );
124 124
125 if( f.open( IO_ReadWrite )) { 125 if( f.open( IO_ReadWrite )) {
126 QTextStream t( &f); 126 QTextStream t( &f);
127 QString countryName; 127 QString countryName;
128 bool b_gotchTest=false; 128 bool b_gotchTest=false;
129 129
130 while ( !t.eof() ) { 130 while ( !t.eof() ) {
131 QString s = t.readLine(); 131 QString s = t.readLine();
132 int start; 132 int start;
133 int end; 133 int end;
134 if( s.find( "FTP mirror sites for Project Gutenberg:", 0, TRUE) !=-1) { //lower end of this file 134 if( s.find( "FTP mirror sites for Project Gutenberg:", 0, TRUE) !=-1) { //lower end of this file
135 b_gotchTest = true; 135 b_gotchTest = true;
136 } 136 }
137 if( b_gotchTest) { 137 if( b_gotchTest) {
138 if(( start = s.find( "ftp://", 0, TRUE))!=-1 ) { 138 if(( start = s.find( "ftp://", 0, TRUE))!=-1 ) {
139 end = s.find( "/\"", 0, TRUE);// ==-1)) { 139 end = s.find( "/\"", 0, TRUE);// ==-1)) {
140 if( end == -1) { 140 if( end == -1) {
141 end = s.find( "\">"); 141 end = s.find( "\">");
142 } 142 }
143 ftpSite = s.mid( start, (end - start) ); 143 ftpSite = s.mid( start, (end - start) );
144 if(ftpSite.right(1) != "/") { 144 if(ftpSite.right(1) != "/") {
145 // ftpSite += "/"; 145 // ftpSite += "/";
146 } 146 }
147 ftpSite=ftpSite.right( ftpSite.length()-6); 147 ftpSite=ftpSite.right( ftpSite.length()-6);
148 if( ftpSite.find("\n", 0, TRUE) ) 148 if( ftpSite.find("\n", 0, TRUE) )
149 ftpSite.remove( ftpSite.find("\n", 0, TRUE), 1); 149 ftpSite.remove( ftpSite.find("\n", 0, TRUE), 1);
150 150
151 if( ftpSite.find("\"", 0, TRUE) ) 151 if( ftpSite.find("\"", 0, TRUE) )
152 ftpSite.remove( ftpSite.find("\"", 0, TRUE), 1); 152 ftpSite.remove( ftpSite.find("\"", 0, TRUE), 1);
153 if( ftpSite.find("a>", 0, TRUE) ) 153 if( ftpSite.find("a>", 0, TRUE) )
154 ftpSite.remove( ftpSite.find("a>", 0, TRUE) -2, 4); 154 ftpSite.remove( ftpSite.find("a>", 0, TRUE) -2, 4);
155 155
156 156
157 s = t.readLine(); 157 s = t.readLine();
158 s = t.readLine(); 158 s = t.readLine();
159 if(( start=s.find("<BR>(", 0, TRUE) ) != -1) { 159 if(( start=s.find("<BR>(", 0, TRUE) ) != -1) {
160// odebug << "" << s << "" << oendl; 160// odebug << "" << s << "" << oendl;
161 end = s.find( ")", 0, TRUE)+1; 161 end = s.find( ")", 0, TRUE)+1;
162 s_location= s.mid( start+4, (end - start) ); 162 s_location= s.mid( start+4, (end - start) );
163 163
164// odebug << "" << s_location << "" << oendl; 164// odebug << "" << s_location << "" << oendl;
165// ftpList += ftpSite + "\n"; 165// ftpList += ftpSite + "\n";
166// ftp_QListBox_1->sort( TRUE ); 166// ftp_QListBox_1->sort( TRUE );
167 ftpList += s_location+ " "+ftpSite+"\n"; 167 ftpList += s_location+ " "+ftpSite+"\n";
168 168
169 ftp_QListBox_1->sort( TRUE ); 169 ftp_QListBox_1->sort( TRUE );
170 QString winbug=" "; 170 QString winbug=" ";
171 ftp_QListBox_1->insertItem ( s_location.latin1() +winbug+ftpSite); 171 ftp_QListBox_1->insertItem ( s_location.latin1() +winbug+ftpSite);
172 // ftp_QListBox_1->insertItem ( ftpSite+" "+s_location.latin1()); 172 // ftp_QListBox_1->insertItem ( ftpSite+" "+s_location.latin1());
173 } 173 }
174 174
175 // ftp_QListBox_1->insertItem ( ftpSite); 175 // ftp_QListBox_1->insertItem ( ftpSite);
176 } 176 }
177 } // end find ftp:// 177 } // end find ftp://
178 178
179 } // end while loop 179 } // end while loop
180 QFile f2( ListFile); 180 QFile f2( ListFile);
181 if(!f2.open( IO_ReadWrite | IO_Truncate)) 181 if(!f2.open( IO_ReadWrite | IO_Truncate))
182 QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n"+ListFile )) ); 182 QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n"+ListFile )) );
183 f2.writeBlock( ftpList, ftpList.length() ); 183 f2.writeBlock( ftpList, ftpList.length() );
184 f.close(); 184 f.close();
185 f2.close(); 185 f2.close();
186 if( f.exists() ) 186 if( f.exists() )
187 f.remove(); 187 f.remove();
188 } else { 188 } else {
189 QMessageBox::message( (tr("ftpSiteDlg")), (tr("List File not opened sucessfully." )) ); 189 QMessageBox::message( (tr("ftpSiteDlg")), (tr("List File not opened sucessfully." )) );
190 return false; 190 return false;
191 } 191 }
192 setActiveWindow(); 192 setActiveWindow();
193 return true; 193 return true;
194} 194}
195 195
196void optionsDialog::openSiteList() { 196void optionsDialog::openSiteList() {
197 197
198 odebug << " just opens the ftp site list" << oendl; 198 odebug << " just opens the ftp site list" << oendl;
199// ListFile = ( QDir::homeDirPath ()) +"/.gutenbrowser/ftpList"; 199// ListFile = ( QDir::homeDirPath ()) +"/.gutenbrowser/ftpList";
200 QFile f( ListFile); 200 QFile f( ListFile);
201 if(!f.open( IO_ReadWrite )) { 201 if(!f.open( IO_ReadWrite )) {
202 QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully." )) ); 202 QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully." )) );
203 } else { 203 } else {
204 QTextStream t( &f); 204 QTextStream t( &f);
205 while ( !t.atEnd() ) { 205 while ( !t.atEnd() ) {
206 QString ftpSite = t.readLine(); 206 QString ftpSite = t.readLine();
207 ftp_QListBox_1->sort( TRUE ); 207 ftp_QListBox_1->sort( TRUE );
208 ftp_QListBox_1->insertItem ( ftpSite); 208 ftp_QListBox_1->insertItem ( ftpSite);
209 209
210 } // end while loop 210 } // end while loop
211 f.close(); 211 f.close();
212 } 212 }
213 213
214 QListBoxItem *itemSel=0; 214 QListBoxItem *itemSel=0;
215 if( (itemSel=ftp_QListBox_1->findItem( ftp_host)) ) 215 if( (itemSel=ftp_QListBox_1->findItem( ftp_host)) )
216 ftp_QListBox_1->setSelected( itemSel, true); 216 ftp_QListBox_1->setSelected( itemSel, true);
217} 217}
218 218
219/* 219/*
220List box clicked */ 220List box clicked */
221void optionsDialog::getSelection( QListBoxItem *item) 221void optionsDialog::getSelection( QListBoxItem *item)
222{ 222{
223 QString selctionStr; 223 QString selctionStr;
224 selctionStr = item->text(); 224 selctionStr = item->text();
225// selctionStr = ftp_QListBox_1->currentText(); 225// selctionStr = ftp_QListBox_1->currentText();
226// printf( selctionStr+"\n" ); 226// printf( selctionStr+"\n" );
227 select_site( selctionStr ); 227 select_site( selctionStr );
228} 228}
229 229
230void optionsDialog::select_site( const char *index ) 230void optionsDialog::select_site( const char *index )
231{ 231{
232// ftp://ftp.datacanyon.com/pub/gutenberg/ 232// ftp://ftp.datacanyon.com/pub/gutenberg/
233 233
234 s_site = index; 234 s_site = index;
235 QString s_site2; 235 QString s_site2;
236// if(s_site.find("(",0,TRUE)) 236// if(s_site.find("(",0,TRUE))
237 s_site2=s_site.right( s_site.length()-(s_site.find(" ",0,TRUE)+4) ); 237 s_site2=s_site.right( s_site.length()-(s_site.find(" ",0,TRUE)+4) );
238odebug << "Selected ftp site is "+ s_site2 << oendl; 238odebug << "Selected ftp site is "+ s_site2 << oendl;
239 int i_ftp = s_site2.find("/", 0, FALSE); 239 int i_ftp = s_site2.find("/", 0, FALSE);
240 ftp_host = s_site2.left(i_ftp ); 240 ftp_host = s_site2.left(i_ftp );
241 ftp_base_dir = s_site2.right( s_site2.length() - i_ftp); 241 ftp_base_dir = s_site2.right( s_site2.length() - i_ftp);
242 242
243// config->read(); 243// config->read();
244 Config config("Gutenbrowser"); 244 Config config("Gutenbrowser");
245 config.setGroup( "FTPsite" ); 245 config.setGroup( "FTPsite" );
246 config.writeEntry("SiteName",ftp_host); 246 config.writeEntry("SiteName",ftp_host);
247 config.writeEntry("base",ftp_base_dir); 247 config.writeEntry("base",ftp_base_dir);
248// config->write(); 248// config->write();
249 TextLabel3->setText( "Current ftp server:\n"+ftp_host /*+ ftp_base_dir*/ ); 249 TextLabel3->setText( "Current ftp server:\n"+ftp_host /*+ ftp_base_dir*/ );
250// optionsDialog::accept(); 250// optionsDialog::accept();
251} 251}
252 252
diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
index 644fae8..fac21da 100644
--- a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
+++ b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
@@ -1,1995 +1,1995 @@
1/*************************************************************************** 1/***************************************************************************
2 gutenbrowser.cpp - description 2 gutenbrowser.cpp - description
3 ------------------- 3 -------------------
4 begin : Mon Jul 24 22:33:12 MDT 2000 4 begin : Mon Jul 24 22:33:12 MDT 2000
5 copyright : (C) 2000 -2004 by llornkcor 5 copyright : (C) 2000 -2004 by llornkcor
6 email : ljp@llornkcor.com 6 email : ljp@llornkcor.com
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 ***************************************************************************/ 11 ***************************************************************************/
12// http search 12// http search
13// http://digital.library.upenn.edu/books/authors.html 13// http://digital.library.upenn.edu/books/authors.html
14// http://digital.library.upenn.edu/books/titles.html 14// http://digital.library.upenn.edu/books/titles.html
15// ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL 15// ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL
16// donate@gutenberg.net 16// donate@gutenberg.net
17 17
18 18
19#include "editTitle.h" 19#include "editTitle.h"
20#include "gutenbrowser.h" 20#include "gutenbrowser.h"
21#include "LibraryDialog.h" 21#include "LibraryDialog.h"
22 //#include "bookmarksdlg.h" 22 //#include "bookmarksdlg.h"
23#include "optionsDialog.h" 23#include "optionsDialog.h"
24#include "helpme.h" 24#include "helpme.h"
25#include "NetworkDialog.h" 25#include "NetworkDialog.h"
26 26
27#include "openetext.h" 27#include "openetext.h"
28#include "output.h" 28#include "output.h"
29 29
30/* OPIE */ 30/* OPIE */
31#include <opie2/odebug.h> 31#include <opie2/odebug.h>
32#include <qpe/qpeapplication.h> 32#include <qpe/qpeapplication.h>
33#include <qpe/fontdatabase.h> 33#include <qpe/fontdatabase.h>
34#include <qpe/config.h> 34#include <qpe/config.h>
35#include <qpe/qcopenvelope_qws.h> 35#include <qpe/qcopenvelope_qws.h>
36#include <qpe/mimetype.h> 36#include <qpe/mimetype.h>
37#include <qpe/resource.h> 37#include <qpe/resource.h>
38#include <qpe/applnk.h> 38#include <qpe/applnk.h>
39 39
40/* QT */ 40/* QT */
41#include <qregexp.h> 41#include <qregexp.h>
42#include <qregion.h> 42#include <qregion.h>
43#include <qpaintdevicemetrics.h> 43#include <qpaintdevicemetrics.h>
44#include <qvaluelist.h> 44#include <qvaluelist.h>
45#include <qlabel.h> 45#include <qlabel.h>
46#include <qclipboard.h> 46#include <qclipboard.h>
47#include <qpainter.h> 47#include <qpainter.h>
48#include <qpalette.h> 48#include <qpalette.h>
49#include <qobjectlist.h> 49#include <qobjectlist.h>
50#include <qfontdialog.h> 50#include <qfontdialog.h>
51#include <qtextview.h> 51#include <qtextview.h>
52#include <qbrush.h> 52#include <qbrush.h>
53#include <qfile.h> 53#include <qfile.h>
54#include <qfontinfo.h> 54#include <qfontinfo.h>
55#include <qscrollview.h> 55#include <qscrollview.h>
56#include <qpoint.h> 56#include <qpoint.h>
57 57
58/* STD */ 58/* STD */
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <unistd.h> 61#include <unistd.h>
62#include <sys/stat.h> 62#include <sys/stat.h>
63#include <fcntl.h> 63#include <fcntl.h>
64#include <errno.h> 64#include <errno.h>
65 65
66static const int nfontsizes = 9; 66static const int nfontsizes = 9;
67static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24}; 67static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24};
68 68
69#ifdef NOQUICKLAUNCH 69#ifdef NOQUICKLAUNCH
70Gutenbrowser::Gutenbrowser() 70Gutenbrowser::Gutenbrowser()
71 Gutenbrowser(); 71 Gutenbrowser();
72#else 72#else
73Gutenbrowser::Gutenbrowser(QWidget *,const char*, WFlags ) 73Gutenbrowser::Gutenbrowser(QWidget *,const char*, WFlags )
74#endif 74#endif
75 : QMainWindow() 75 : QMainWindow()
76{ 76{
77 // QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 77 // QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
78 // QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); 78 // QCopEnvelope e("QPE/System", "grabKeyboard(QString)" );
79 // e << ""; 79 // e << "";
80 // QPEApplication::grabKeyboard(); 80 // QPEApplication::grabKeyboard();
81 showMainList=TRUE; 81 showMainList=TRUE;
82 working=false; 82 working=false;
83 this->setUpdatesEnabled(TRUE); 83 this->setUpdatesEnabled(TRUE);
84 // #ifndef Q_WS_QWS 84 // #ifndef Q_WS_QWS
85 QString msg; 85 QString msg;
86 msg="You have now entered unto gutenbrowser,\n"; 86 msg="You have now entered unto gutenbrowser,\n";
87 msg+="make your self at home, sit back, relax and read something great.\n"; 87 msg+="make your self at home, sit back, relax and read something great.\n";
88 88
89 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; 89 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
90 setCaption("Gutenbrowser");// Embedded " VERSION); 90 setCaption("Gutenbrowser");// Embedded " VERSION);
91 this->setUpdatesEnabled(TRUE); 91 this->setUpdatesEnabled(TRUE);
92 92
93 // bool firstTime=FALSE; 93 // bool firstTime=FALSE;
94 topLayout = new QVBoxLayout( this, 0, 0, "topLayout"); 94 topLayout = new QVBoxLayout( this, 0, 0, "topLayout");
95 95
96 menu = new QHBoxLayout(-1,"menu"); 96 menu = new QHBoxLayout(-1,"menu");
97 buttons2 = new QHBoxLayout(-1,"buttons2"); 97 buttons2 = new QHBoxLayout(-1,"buttons2");
98 edits = new QHBoxLayout(-1,"edits"); 98 edits = new QHBoxLayout(-1,"edits");
99 99
100 useSplitter=TRUE; 100 useSplitter=TRUE;
101 101
102 initConfig(); 102 initConfig();
103 initMenuBar(); 103 initMenuBar();
104 initButtonBar(); 104 initButtonBar();
105 initStatusBar(); 105 initStatusBar();
106 initView(); 106 initView();
107 initSlots(); 107 initSlots();
108 qDebug("init finished"); 108 qDebug("init finished");
109 QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold); 109 QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold);
110 110
111 connect( mainList, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint &)), 111 connect( mainList, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint &)),
112 this, SLOT( mainListPressed(int, QListBoxItem *, const QPoint &)) ); 112 this, SLOT( mainListPressed(int, QListBoxItem *, const QPoint &)) );
113 if( useIcons) 113 if( useIcons)
114 toggleButtonIcons( TRUE); 114 toggleButtonIcons( TRUE);
115 else 115 else
116 toggleButtonIcons( FALSE); 116 toggleButtonIcons( FALSE);
117 117
118 enableButtons(false); 118 enableButtons(false);
119 119
120 Config config("Gutenbrowser"); // populate menubuttonlist 120 Config config("Gutenbrowser"); // populate menubuttonlist
121 config.setGroup("General"); 121 config.setGroup("General");
122 122
123 config.setGroup( "Files" ); 123 config.setGroup( "Files" );
124 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); 124 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
125 int i_numofFiles = s_numofFiles.toInt(); 125 int i_numofFiles = s_numofFiles.toInt();
126 126
127 QString tempFileName; 127 QString tempFileName;
128 128
129 for (int i = 0; i <= i_numofFiles; i++) { 129 for (int i = 0; i <= i_numofFiles; i++) {
130 // tempFileName.setNum(i); 130 // tempFileName.setNum(i);
131 config.setGroup( "Files" ); 131 config.setGroup( "Files" );
132 QString ramble = config.readEntry( QString::number(i), "" ); 132 QString ramble = config.readEntry( QString::number(i), "" );
133 133
134 config.setGroup( "Titles" ); 134 config.setGroup( "Titles" );
135 QString tempTitle = config.readEntry( ramble, ""); 135 QString tempTitle = config.readEntry( ramble, "");
136 config.setGroup( tempTitle); 136 config.setGroup( tempTitle);
137 int index = config.readNumEntry( "LineNumber", -1 ); 137 int index = config.readNumEntry( "LineNumber", -1 );
138 if( index != -1) { 138 if( index != -1) {
139 odebug << tempTitle << oendl; 139 odebug << tempTitle << oendl;
140 if(!tempTitle.isEmpty()) bookmarksMenu->insertItem( tempTitle); 140 if(!tempTitle.isEmpty()) bookmarksMenu->insertItem( tempTitle);
141 } 141 }
142 } 142 }
143 143
144 // QString gutenIndex= local_library + "GUTINDEX.ALL"; 144 // QString gutenIndex= local_library + "GUTINDEX.ALL";
145 QString gutenIndex = QPEApplication::qpeDir()+ "/etc/gutenbrowser/GUTINDEX.ALL"; 145 QString gutenIndex = QPEApplication::qpeDir()+ "etc/gutenbrowser/GUTINDEX.ALL";
146 qDebug("gutenindex "+gutenIndex ); 146 qDebug("gutenindex "+gutenIndex );
147 if( QFile( gutenIndex).exists() ) { 147 if( QFile( gutenIndex).exists() ) {
148 indexLib.setName( gutenIndex); 148 indexLib.setName( gutenIndex);
149 } else { 149 } else {
150 QString localLibIndexFile = QPEApplication::qpeDir()+ "/etc/gutenbrowser/PGWHOLE.TXT"; 150 QString localLibIndexFile = QPEApplication::qpeDir()+ "etc/gutenbrowser/PGWHOLE.TXT";
151 // QString localLibIndexFile= local_library + "PGWHOLE.TXT"; 151 // QString localLibIndexFile= local_library + "PGWHOLE.TXT";
152 newindexLib.setName( localLibIndexFile); 152 newindexLib.setName( localLibIndexFile);
153 } 153 }
154 qDebug("attempting new library"); 154 qDebug("attempting new library");
155 LibraryDlg = new LibraryDialog( this, "Library Index" /*, TRUE */); 155 LibraryDlg = new LibraryDialog( this, "Library Index" /*, TRUE */);
156 loadCheck = false; 156 loadCheck = false;
157 chdir(local_library); 157 chdir(local_library);
158 if(!showMainList) { 158 if(!showMainList) {
159 Lview->setFocus(); 159 Lview->setFocus();
160 // if(firstTime) 160 // if(firstTime)
161 // Bookmark(); 161 // Bookmark();
162 for (int i=1;i< qApp->argc();i++) { 162 for (int i=1;i< qApp->argc();i++) {
163 qDebug("Suppose we open somethin"); 163 qDebug("Suppose we open somethin");
164 if(!load(qApp->argv()[i])) return; 164 if(!load(qApp->argv()[i])) return;
165 } 165 }
166 } else { 166 } else {
167 fillWithTitles(); 167 fillWithTitles();
168 mainList->setFocus(); 168 mainList->setFocus();
169 // mainList->setCurrentItem(0); 169 // mainList->setCurrentItem(0);
170 170
171 } 171 }
172 writeConfig(); 172 writeConfig();
173 QTimer::singleShot( 250, this, SLOT(hideView()) ); 173 QTimer::singleShot( 250, this, SLOT(hideView()) );
174} //end init 174} //end init
175 175
176Gutenbrowser::~Gutenbrowser() { 176Gutenbrowser::~Gutenbrowser() {
177 // QPEApplication::grabKeyboard(); 177 // QPEApplication::grabKeyboard();
178 // QPEApplication::ungrabKeyboard(); 178 // QPEApplication::ungrabKeyboard();
179 odebug << "Exit" << oendl; 179 odebug << "Exit" << oendl;
180} 180}
181 181
182 /* 182 /*
183 Google.com search */ 183 Google.com search */
184void Gutenbrowser::InfoBarClick() { 184void Gutenbrowser::InfoBarClick() {
185 QString text; 185 QString text;
186 if( Lview->hasSelectedText()) { 186 if( Lview->hasSelectedText()) {
187 Lview->copy(); 187 Lview->copy();
188 QClipboard *cb = QApplication::clipboard(); 188 QClipboard *cb = QApplication::clipboard();
189 text = cb->text(); 189 text = cb->text();
190 } else { 190 } else {
191 // text=title; 191 // text=title;
192 text=this->caption(); 192 text=this->caption();
193 } 193 }
194 searchGoogle(text); 194 searchGoogle(text);
195} 195}
196 196
197 /* 197 /*
198 download http with wget or preferred browser */ 198 download http with wget or preferred browser */
199void Gutenbrowser::goGetit( const QString &url, bool showMsg) { 199void Gutenbrowser::goGetit( const QString &url, bool showMsg) {
200 // int eexit=0; 200 // int eexit=0;
201 QString cmd; 201 QString cmd;
202 // config.read(); 202 // config.read();
203 qApp->processEvents(); 203 qApp->processEvents();
204 QString filename = QPEApplication::qpeDir(); 204 QString filename = QPEApplication::qpeDir();
205 if(filename.right(1)!="/") 205 if(filename.right(1)!="/")
206 filename+="/etc/gutenbrowser/"; 206 filename+="/etc/gutenbrowser/";
207 else 207 else
208 filename+="etc/gutenbrowser/"; 208 filename+="etc/gutenbrowser/";
209 odebug << "filename "+filename << oendl; 209 odebug << "filename "+filename << oendl;
210 // QString filename = QDir::homeDirPath()+"/Applications/gutenbrowser/"; 210 // QString filename = QDir::homeDirPath()+"/Applications/gutenbrowser/";
211 211
212 filename += url.right( url.length() - url.findRev("/",-1,TRUE) -1); 212 filename += url.right( url.length() - url.findRev("/",-1,TRUE) -1);
213 213
214 Config config("Gutenbrowser"); 214 Config config("Gutenbrowser");
215 config.setGroup( "Browser" ); 215 config.setGroup( "Browser" );
216 QString brow = config.readEntry("Preferred", "Opera"); 216 QString brow = config.readEntry("Preferred", "Opera");
217 odebug << "Preferred browser is "+brow << oendl; 217 odebug << "Preferred browser is "+brow << oendl;
218 if(!showMsg) { //if we just get the gutenindex.all 218 if(!showMsg) { //if we just get the gutenindex.all
219 cmd="wget -O " + filename +" " + url+" 2>&1" ; 219 cmd="wget -O " + filename +" " + url+" 2>&1" ;
220 chdir(local_library); 220 chdir(local_library);
221 odebug << "Issuing the system command: " << cmd << "" << oendl; 221 odebug << "Issuing the system command: " << cmd << "" << oendl;
222 222
223 Output *outDlg; 223 Output *outDlg;
224 outDlg = new Output(this, tr("Gutenbrowser Output"),FALSE); 224 outDlg = new Output(this, tr("Gutenbrowser Output"),FALSE);
225 outDlg->showMaximized(); 225 outDlg->showMaximized();
226 outDlg->show(); 226 outDlg->show();
227 qApp->processEvents(); 227 qApp->processEvents();
228 FILE *fp; 228 FILE *fp;
229 char line[130]; 229 char line[130];
230 outDlg->OutputEdit->append( tr("Running wget") ); 230 outDlg->OutputEdit->append( tr("Running wget") );
231 sleep(1); 231 sleep(1);
232 fp = popen( (const char *) cmd, "r"); 232 fp = popen( (const char *) cmd, "r");
233 odebug << "Issuing the command\n"+cmd << oendl; 233 odebug << "Issuing the command\n"+cmd << oendl;
234 // system(cmd); 234 // system(cmd);
235 while ( fgets( line, sizeof line, fp)) { 235 while ( fgets( line, sizeof line, fp)) {
236 outDlg->OutputEdit->append(line); 236 outDlg->OutputEdit->append(line);
237// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 237// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
238 } 238 }
239 pclose(fp); 239 pclose(fp);
240 outDlg->close(); 240 outDlg->close();
241 if(outDlg) 241 if(outDlg)
242 delete outDlg; 242 delete outDlg;
243 } else { 243 } else {
244 if( brow == "Konq") { 244 if( brow == "Konq") {
245 cmd = "konqueror "+url+" &"; 245 cmd = "konqueror "+url+" &";
246 } 246 }
247 if( brow == "Opera") { //for desktop testing 247 if( brow == "Opera") { //for desktop testing
248 cmd = "opera "+url+" &"; 248 cmd = "opera "+url+" &";
249 } 249 }
250 // if( brow == "Opera") { // on Zaurus 250 // if( brow == "Opera") { // on Zaurus
251 // cmd = "operagui "+url+" &"; 251 // cmd = "operagui "+url+" &";
252 // } 252 // }
253 if( brow == "Mozilla") { 253 if( brow == "Mozilla") {
254 cmd = "mozilla "+url+" &"; 254 cmd = "mozilla "+url+" &";
255 } 255 }
256 if( brow == "Netscape") { 256 if( brow == "Netscape") {
257 cmd = "netscape "+url+" &"; 257 cmd = "netscape "+url+" &";
258 } 258 }
259 if(brow == "wget") { 259 if(brow == "wget") {
260 // cmd="wget -q "+url+" &"; 260 // cmd="wget -q "+url+" &";
261 QString tempHtml=local_library+"webster.html"; 261 QString tempHtml=local_library+"webster.html";
262 cmd="wget -O "+tempHtml+" -q "+url; 262 cmd="wget -O "+tempHtml+" -q "+url;
263 } 263 }
264 264
265 chdir(local_library); 265 chdir(local_library);
266 odebug << "Issuing the sys command: " << cmd << "" << oendl; 266 odebug << "Issuing the sys command: " << cmd << "" << oendl;
267 system(cmd); 267 system(cmd);
268 } 268 }
269} 269}
270 270
271void Gutenbrowser::toggleButtonIcons( bool useEm) { 271void Gutenbrowser::toggleButtonIcons( bool useEm) {
272 QString pixDir; 272 QString pixDir;
273 if(useEm) 273 if(useEm)
274 useEm=TRUE; 274 useEm=TRUE;
275 pixDir=QPEApplication::qpeDir()+"pics/gutenbrowser"; 275 pixDir=QPEApplication::qpeDir()+"pics/gutenbrowser";
276 odebug << "Docdir is "+QPEApplication::documentDir() << oendl; 276 odebug << "Docdir is "+QPEApplication::documentDir() << oendl;
277 277
278 if( useIcons && QDir( pixDir).exists() ) { 278 if( useIcons && QDir( pixDir).exists() ) {
279 LibraryButton->setPixmap( Resource::loadPixmap("home") ); //in inline 279 LibraryButton->setPixmap( Resource::loadPixmap("home") ); //in inline
280 OpenButton->setPixmap( Resource::loadPixmap("gutenbrowser/openbook")); 280 OpenButton->setPixmap( Resource::loadPixmap("gutenbrowser/openbook"));
281 ForwardButton->setPixmap( Resource::loadPixmap("forward"));//in inline 281 ForwardButton->setPixmap( Resource::loadPixmap("forward"));//in inline
282 BackButton->setPixmap( Resource::loadPixmap("back") );//in inline 282 BackButton->setPixmap( Resource::loadPixmap("back") );//in inline
283 SearchButton->setPixmap( Resource::loadPixmap("gutenbrowser/search") );//in inline 283 SearchButton->setPixmap( Resource::loadPixmap("gutenbrowser/search") );//in inline
284 lastBmkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark_folder")); 284 lastBmkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark_folder"));
285 setBookmarkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark") ); 285 setBookmarkButton->setPixmap( Resource::loadPixmap("gutenbrowser/bookmark") );
286 dictionaryButton->setPixmap( Resource::loadPixmap("gutenbrowser/spellcheck") ); 286 dictionaryButton->setPixmap( Resource::loadPixmap("gutenbrowser/spellcheck") );
287 InfoBar->setPixmap( Resource::loadPixmap("gutenbrowser/google")); 287 InfoBar->setPixmap( Resource::loadPixmap("gutenbrowser/google"));
288 } 288 }
289} 289}
290 290
291 291
292bool Gutenbrowser::queryExit() 292bool Gutenbrowser::queryExit()
293{ 293{
294 int exit=QMessageBox::information(this, "Quit...", "Do your really want to quit?", 294 int exit=QMessageBox::information(this, "Quit...", "Do your really want to quit?",
295 QMessageBox::Ok, QMessageBox::Cancel); 295 QMessageBox::Ok, QMessageBox::Cancel);
296 if (exit==1) { 296 if (exit==1) {
297 writeConfig(); 297 writeConfig();
298 qApp->quit(); 298 qApp->quit();
299 } else { 299 } else {
300 }; 300 };
301 return (exit==1); 301 return (exit==1);
302} 302}
303 303
304 // SLOT IMPLEMENTATION 304 // SLOT IMPLEMENTATION
305 305
306void Gutenbrowser::slotFilePrint() { 306void Gutenbrowser::slotFilePrint() {
307} 307}
308 308
309void Gutenbrowser::ByeBye() { 309void Gutenbrowser::ByeBye() {
310 if (b_queryExit) 310 if (b_queryExit)
311 queryExit(); 311 queryExit();
312 else { 312 else {
313 // writeConfig(); 313 // writeConfig();
314 qApp->quit(); 314 qApp->quit();
315 } 315 }
316} 316}
317 317
318void Gutenbrowser::HelpBtn() { 318void Gutenbrowser::HelpBtn() {
319 HelpMe* HelpDlg; 319 HelpMe* HelpDlg;
320 HelpDlg = new HelpMe( this, "Help Dialog"); 320 HelpDlg = new HelpMe( this, "Help Dialog");
321 HelpDlg->showMaximized(); 321 HelpDlg->showMaximized();
322} 322}
323 323
324void Gutenbrowser::DownloadIndex() { 324void Gutenbrowser::DownloadIndex() {
325#ifndef Q_WS_QWS 325#ifndef Q_WS_QWS
326 { 326 {
327 switch( QMessageBox::information( 0, (tr("Download Library Index, or FTP sites?")), 327 switch( QMessageBox::information( 0, (tr("Download Library Index, or FTP sites?")),
328 (tr("Do you want to download the newest\n" 328 (tr("Do you want to download the newest\n"
329 "Project Gutenberg Library Index?\n" 329 "Project Gutenberg Library Index?\n"
330 "or select an ftp site?\n")), 330 "or select an ftp site?\n")),
331 (tr("&Library Index")), (tr("&Ftp Site")), (tr("&Cancel")), 2, 2 ) ) 331 (tr("&Library Index")), (tr("&Ftp Site")), (tr("&Cancel")), 2, 2 ) )
332 { 332 {
333 case 0: // index clicked, 333 case 0: // index clicked,
334 downloadLibIndex(); 334 downloadLibIndex();
335 break; 335 break;
336 336
337 case 1: // ftp selected 337 case 1: // ftp selected
338 downloadFtpList(); 338 downloadFtpList();
339 break; 339 break;
340 340
341 case 2: // Cancel 341 case 2: // Cancel
342 break; 342 break;
343 }; 343 };
344 } 344 }
345#endif 345#endif
346} // end DownloadIndex 346} // end DownloadIndex
347 347
348 348
349void Gutenbrowser::downloadFtpList() { 349void Gutenbrowser::downloadFtpList() {
350 // QString cmd="wget http://www.promo.net/pg/list.html"); 350 // QString cmd="wget http://www.promo.net/pg/list.html");
351 //system(cmd); 351 //system(cmd);
352 qApp->processEvents(); 352 qApp->processEvents();
353 optionsDialog* optDlg; 353 optionsDialog* optDlg;
354 optDlg = new optionsDialog( this,"Options_Dlg", true); 354 optDlg = new optionsDialog( this,"Options_Dlg", true);
355 optDlg->getSite(); 355 optDlg->getSite();
356 if(optDlg) 356 if(optDlg)
357 delete optDlg; 357 delete optDlg;
358} 358}
359 359
360 360
361void Gutenbrowser::downloadLibIndex() { 361void Gutenbrowser::downloadLibIndex() {
362 // QString dwmloader = local_library + "pgwhole.zip"; 362 // QString dwmloader = local_library + "pgwhole.zip";
363 // QString cmd = "lynx -source http://www.gutenberg.net/pgwhole.zip | cat >> " + dwmloader; 363 // QString cmd = "lynx -source http://www.gutenberg.net/pgwhole.zip | cat >> " + dwmloader;
364 // system(cmd); 364 // system(cmd);
365 365
366 // QString outputFile= local_library+ "GUTINDEX.ALL"; 366 // QString outputFile= local_library+ "GUTINDEX.ALL";
367 // config.setGroup( "FTPsite" ); // ftp server config 367 // config.setGroup( "FTPsite" ); // ftp server config
368 // ftp_host=config.readEntry("SiteName", ""); 368 // ftp_host=config.readEntry("SiteName", "");
369 // ftp_base_dir= config.readEntry("base", ""); 369 // ftp_base_dir= config.readEntry("base", "");
370 // QString networkUrl= "ftp://"+ftp_host+ftp_base_dir+"/GUTINDEX.ALL"; 370 // QString networkUrl= "ftp://"+ftp_host+ftp_base_dir+"/GUTINDEX.ALL";
371 QDir dir( local_library); 371 QDir dir( local_library);
372 dir.cd("", TRUE); 372 dir.cd("", TRUE);
373 goGetit( "http://sailor.gutenberg.org/GUTINDEX.ALL", false); // until ghttp works on binaries -qt3 373 goGetit( "http://sailor.gutenberg.org/GUTINDEX.ALL", false); // until ghttp works on binaries -qt3
374 // goGetit( "http://www.gutenberg.net/pgwhole.zip", true); // until ghttp works on binaries -qt3 374 // goGetit( "http://www.gutenberg.net/pgwhole.zip", true); // until ghttp works on binaries -qt3
375 // NetworkDialog *NetworkDlg; 375 // NetworkDialog *NetworkDlg;
376 // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, outputFile ); 376 // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, outputFile );
377 // if( NetworkDlg->exec() != 0 ) 377 // if( NetworkDlg->exec() != 0 )
378 // { // use new, improved, *INSTANT* network-dialog-file-getterer 378 // { // use new, improved, *INSTANT* network-dialog-file-getterer
379 //// QMessageBox::message("Note",""); 379 //// QMessageBox::message("Note","");
380 // } 380 // }
381 // if(NetworkDlg) 381 // if(NetworkDlg)
382 // delete NetworkDlg; 382 // delete NetworkDlg;
383} 383}
384 384
385 385
386void Gutenbrowser::PrintBtn() { 386void Gutenbrowser::PrintBtn() {
387} 387}
388 388
389void Gutenbrowser::SearchBtn() { 389void Gutenbrowser::SearchBtn() {
390 if( loadCheck) { 390 if( loadCheck) {
391 odebug << "loadCheck: we have a loaded doc" << oendl; 391 odebug << "loadCheck: we have a loaded doc" << oendl;
392 Search(); 392 Search();
393 } 393 }
394 // else 394 // else
395 // QMessageBox::message("Note","Sorry, can't search. No etext is loaded"); 395 // QMessageBox::message("Note","Sorry, can't search. No etext is loaded");
396} 396}
397 397
398 398
399void Gutenbrowser::ForwardBtn() { 399void Gutenbrowser::ForwardBtn() {
400 400
401 if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) { 401 if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) {
402 402
403 QString s; 403 QString s;
404 QString insertString; 404 QString insertString;
405 int pageSize= Lview->PageSize(); 405 int pageSize= Lview->PageSize();
406 Lview->clear(); 406 Lview->clear();
407 407
408 for(int fd=0; fd < pageSize - 1;fd++) { 408 for(int fd=0; fd < pageSize - 1;fd++) {
409 f.readLine(s, 256); 409 f.readLine(s, 256);
410 if(useWrap) 410 if(useWrap)
411 s.replace(QRegExp("\n"),""); 411 s.replace(QRegExp("\n"),"");
412 insertString+=s; 412 insertString+=s;
413 Lview->insertLine( s, -1); 413 Lview->insertLine( s, -1);
414 // odebug << s << oendl; 414 // odebug << s << oendl;
415 currentLine++; 415 currentLine++;
416 } 416 }
417 // Lview->insertAt( insertString,0,0, FALSE); 417 // Lview->insertAt( insertString,0,0, FALSE);
418 currentFilePos = f.at(); 418 currentFilePos = f.at();
419 // if( i_pageNum != pages) { 419 // if( i_pageNum != pages) {
420 // Lview->MultiLine_Ex::pageDown( FALSE); 420 // Lview->MultiLine_Ex::pageDown( FALSE);
421 i_pageNum++; 421 i_pageNum++;
422 pageStopArray.resize(i_pageNum + 1); 422 pageStopArray.resize(i_pageNum + 1);
423 // int length = Lview->length(); 423 // int length = Lview->length();
424 424
425 pageStopArray[i_pageNum ] = currentFilePos; 425 pageStopArray[i_pageNum ] = currentFilePos;
426 odebug << currentFilePos << " current page is number " << i_pageNum 426 odebug << currentFilePos << " current page is number " << i_pageNum
427 << ", pagesize " << pageSize << ", length " << Lview->length() 427 << ", pagesize " << pageSize << ", length " << Lview->length()
428 << ", current " << pageStopArray[i_pageNum] << oendl; 428 << ", current " << pageStopArray[i_pageNum] << oendl;
429 setStatus(); 429 setStatus();
430// Lview->setCursorPosition( 0, 0, FALSE); 430// Lview->setCursorPosition( 0, 0, FALSE);
431 // } 431 // }
432 432
433 } else { 433 } else {
434 odebug << "bal" << oendl; 434 odebug << "bal" << oendl;
435 // if( i_pageNum != pages) { 435 // if( i_pageNum != pages) {
436 436
437 // // int newTop = Lview->Top(); 437 // // int newTop = Lview->Top();
438 // // if(Lview->lastRow() > i) 438 // // if(Lview->lastRow() > i)
439 // Lview->ScrollUp(1); 439 // Lview->ScrollUp(1);
440 // // i_pageNum++; 440 // // i_pageNum++;
441 // setStatus(); 441 // setStatus();
442 // Lview->setCursorPosition( Lview->Top(), 0, FALSE); 442 // Lview->setCursorPosition( Lview->Top(), 0, FALSE);
443 443
444 // } 444 // }
445 445
446 } 446 }
447 Lview->setFocus(); 447 Lview->setFocus();
448 448
449 odebug << "page number " << i_pageNum << " line number " << currentLine << "" << oendl; 449 odebug << "page number " << i_pageNum << " line number " << currentLine << "" << oendl;
450} 450}
451 451
452 452
453void Gutenbrowser::BackBtn() { 453void Gutenbrowser::BackBtn() {
454 if( i_pageNum > 0) { 454 if( i_pageNum > 0) {
455 int pageSize= Lview->PageSize(); 455 int pageSize= Lview->PageSize();
456 // int length=Lview->length(); 456 // int length=Lview->length();
457 457
458 i_pageNum--; 458 i_pageNum--;
459 currentFilePos = f.at(); 459 currentFilePos = f.at();
460 460
461 odebug << currentFilePos << " move back to " << pageStopArray[i_pageNum - 1 ] 461 odebug << currentFilePos << " move back to " << pageStopArray[i_pageNum - 1 ]
462 << ", current page number " << i_pageNum 462 << ", current page number " << i_pageNum
463 << ", " << pageSize << ", length " << Lview->length() << oendl; 463 << ", " << pageSize << ", length " << Lview->length() << oendl;
464 464
465 if( i_pageNum < 2) { 465 if( i_pageNum < 2) {
466 f.at( 0); 466 f.at( 0);
467 } else { 467 } else {
468 if(!f.at( pageStopArray[i_pageNum - 1] )) 468 if(!f.at( pageStopArray[i_pageNum - 1] ))
469 odebug << "File positioned backward did not work" << oendl; 469 odebug << "File positioned backward did not work" << oendl;
470 } 470 }
471 QString s; 471 QString s;
472 // int sizeLine=0; 472 // int sizeLine=0;
473 Lview->clear(); 473 Lview->clear();
474 // QString insertString; 474 // QString insertString;
475 475
476 for(int fd = 0; fd < pageSize ;fd++) { 476 for(int fd = 0; fd < pageSize ;fd++) {
477 // Lview->removeLine( Lview->PageSize() ); 477 // Lview->removeLine( Lview->PageSize() );
478 f.readLine(s, 256); 478 f.readLine(s, 256);
479 if(useWrap) 479 if(useWrap)
480 s.replace(QRegExp("\n"),""); 480 s.replace(QRegExp("\n"),"");
481 currentLine++; 481 currentLine++;
482 // insertString+=s; 482 // insertString+=s;
483 Lview->insertLine( s, -1); 483 Lview->insertLine( s, -1);
484 } 484 }
485 485
486 // Lview->insertAt( insertString,0,0, FALSE); 486 // Lview->insertAt( insertString,0,0, FALSE);
487 487
488 if( !BackButton->autoRepeat() && !BackButton->isDown()) { 488 if( !BackButton->autoRepeat() && !BackButton->isDown()) {
489 QString topR; 489 QString topR;
490 QString lastR; 490 QString lastR;
491 QString pageR; 491 QString pageR;
492 // int sizer = Lview->lastRow() - Lview->topRow(); 492 // int sizer = Lview->lastRow() - Lview->topRow();
493 // int i_topRow = Lview->topRow(); 493 // int i_topRow = Lview->topRow();
494 if( i_pageNum < 1) 494 if( i_pageNum < 1)
495 i_pageNum = 1; 495 i_pageNum = 1;
496 setCaption(QString::number(i_pageNum)); 496 setCaption(QString::number(i_pageNum));
497 } else { 497 } else {
498 // int newTop = Lview->Top(); 498 // int newTop = Lview->Top();
499 // if(Lview->lastRow() > i) 499 // if(Lview->lastRow() > i)
500 Lview->MultiLine_Ex::pageUp( FALSE); 500 Lview->MultiLine_Ex::pageUp( FALSE);
501 // Lview->ScrollDown(1); 501 // Lview->ScrollDown(1);
502 // i_pageNum--; 502 // i_pageNum--;
503 if( i_pageNum < 1) 503 if( i_pageNum < 1)
504 i_pageNum = 1; 504 i_pageNum = 1;
505 setStatus(); 505 setStatus();
506// Lview->setCursorPosition( Lview->Top(), 0, FALSE); 506// Lview->setCursorPosition( Lview->Top(), 0, FALSE);
507 507
508 } 508 }
509 } 509 }
510 Lview->setFocus(); 510 Lview->setFocus();
511} 511}
512 512
513void Gutenbrowser::doBeginBtn() { 513void Gutenbrowser::doBeginBtn() {
514 if(loadCheck) { 514 if(loadCheck) {
515 qApp->processEvents(); 515 qApp->processEvents();
516 BeginBtn(); 516 BeginBtn();
517 } 517 }
518} 518}
519 519
520 // moves text to the very top = 0 520 // moves text to the very top = 0
521void Gutenbrowser::TopBtn() { 521void Gutenbrowser::TopBtn() {
522 522
523 if(loadCheck) { 523 if(loadCheck) {
524 if( i_pageNum != 0) { 524 if( i_pageNum != 0) {
525 odebug << "top" << oendl; 525 odebug << "top" << oendl;
526 qApp->processEvents(); 526 qApp->processEvents();
527 currentLine = 0; 527 currentLine = 0;
528 i_pageNum = 1; 528 i_pageNum = 1;
529 int pageSize = Lview->PageSize() ; 529 int pageSize = Lview->PageSize() ;
530 Lview->clear(); 530 Lview->clear();
531 QString s; 531 QString s;
532 f.at(0); 532 f.at(0);
533 for(int fd=0; fd < pageSize ;fd++) { 533 for(int fd=0; fd < pageSize ;fd++) {
534 f.readLine(s, 256); 534 f.readLine(s, 256);
535 if(useWrap) 535 if(useWrap)
536 s.replace(QRegExp("\n"),""); 536 s.replace(QRegExp("\n"),"");
537 Lview->insertLine(s ,-1); 537 Lview->insertLine(s ,-1);
538 currentLine++; 538 currentLine++;
539 } 539 }
540// Lview->setCursorPosition( 0,0, FALSE); 540// Lview->setCursorPosition( 0,0, FALSE);
541 i_pageNum=1; 541 i_pageNum=1;
542 setStatus(); 542 setStatus();
543 } 543 }
544 Lview->setFocus(); 544 Lview->setFocus();
545 } 545 }
546} 546}
547 547
548 //moves text to the start of the EText 548 //moves text to the start of the EText
549void Gutenbrowser::BeginBtn() { 549void Gutenbrowser::BeginBtn() {
550 i_pageNum = 1; 550 i_pageNum = 1;
551 currentLine = 0; 551 currentLine = 0;
552 QString s_pattern="*END*THE SMALL PRINT"; 552 QString s_pattern="*END*THE SMALL PRINT";
553 QString sPattern2 = "*END THE SMALL PRINT"; 553 QString sPattern2 = "*END THE SMALL PRINT";
554 554
555 int pageSize = Lview->PageSize(); 555 int pageSize = Lview->PageSize();
556 Lview->clear(); 556 Lview->clear();
557 557
558 // int lines = Lview->numLines(); 558 // int lines = Lview->numLines();
559 int pos = 0;//, i = 0; 559 int pos = 0;//, i = 0;
560 int i_topRow = Lview->topRow(); 560 int i_topRow = Lview->topRow();
561 561
562 QString LeftText;// = Lview->text(); 562 QString LeftText;// = Lview->text();
563 563
564 // int linesPerPage = Lview->lastRow() - Lview->topRow(); 564 // int linesPerPage = Lview->lastRow() - Lview->topRow();
565 // int pages = (( linesPerPage / Lview->editSize() ) ) +1; 565 // int pages = (( linesPerPage / Lview->editSize() ) ) +1;
566 // int pageN = 0; 566 // int pageN = 0;
567 i_pageNum = 1; 567 i_pageNum = 1;
568 int lastPage=1; 568 int lastPage=1;
569 int lineNo=0; 569 int lineNo=0;
570 QString s; 570 QString s;
571 f.at( 0); 571 f.at( 0);
572 572
573 while ( !f.atEnd() ) { 573 while ( !f.atEnd() ) {
574 f.readLine(s, 256); 574 f.readLine(s, 256);
575 lineNo++; 575 lineNo++;
576 LeftText = s; 576 LeftText = s;
577 currentFilePos = f.at(); 577 currentFilePos = f.at();
578 578
579 i_pageNum = lineNo/pageSize; 579 i_pageNum = lineNo/pageSize;
580 if(lastPage < i_pageNum) { 580 if(lastPage < i_pageNum) {
581 pageStopArray.resize(i_pageNum + 1); 581 pageStopArray.resize(i_pageNum + 1);
582 pageStopArray[i_pageNum ] = currentFilePos; 582 pageStopArray[i_pageNum ] = currentFilePos;
583 // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; 583 // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl;
584 } 584 }
585 // lastPage = i_pageNum; 585 // lastPage = i_pageNum;
586 if( LeftText.find( s_pattern, 0 , TRUE) != -1 || LeftText.find( sPattern2, 0 , TRUE) != -1 ) { 586 if( LeftText.find( s_pattern, 0 , TRUE) != -1 || LeftText.find( sPattern2, 0 , TRUE) != -1 ) {
587 odebug << "<<<<<< FOUND IT!! new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; 587 odebug << "<<<<<< FOUND IT!! new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl;
588 break; 588 break;
589 } 589 }
590 } 590 }
591 if(f.atEnd()) //in case we didnt find anything, we need to show something 591 if(f.atEnd()) //in case we didnt find anything, we need to show something
592 f.at(0); 592 f.at(0);
593 Lview->clear(); 593 Lview->clear();
594 for(int fd=0; fd < pageSize - 1;fd++) { 594 for(int fd=0; fd < pageSize - 1;fd++) {
595 f.readLine(s, 256); 595 f.readLine(s, 256);
596 if(useWrap) 596 if(useWrap)
597 s.replace(QRegExp("\n"),""); 597 s.replace(QRegExp("\n"),"");
598 Lview->insertLine( s, -1); 598 Lview->insertLine( s, -1);
599 currentLine++; 599 currentLine++;
600 } 600 }
601 601
602 i_pageNum = lineNo/pageSize; 602 i_pageNum = lineNo/pageSize;
603 pageStopArray.resize(i_pageNum + 1); 603 pageStopArray.resize(i_pageNum + 1);
604 // int length = Lview->length(); 604 // int length = Lview->length();
605 605
606 qApp->processEvents(); 606 qApp->processEvents();
607 607
608 if( pos > i_topRow ) { 608 if( pos > i_topRow ) {
609// Lview->setCursorPosition( pos+linesPerPage+2/* - i_topRow+3 */,0, FALSE); 609// Lview->setCursorPosition( pos+linesPerPage+2/* - i_topRow+3 */,0, FALSE);
610 } else { 610 } else {
611// Lview->setCursorPosition( pos+2 , 0, FALSE ); 611// Lview->setCursorPosition( pos+2 , 0, FALSE );
612 } 612 }
613 613
614 Lview->deselect(); 614 Lview->deselect();
615 // AdjustStatus(); 615 // AdjustStatus();
616 Lview->setFocus(); 616 Lview->setFocus();
617} 617}
618 618
619 /* 619 /*
620 sets the current page and place as a bookmark*/ 620 sets the current page and place as a bookmark*/
621void Gutenbrowser::setBookmark() { 621void Gutenbrowser::setBookmark() {
622 int eexit=QMessageBox::information(this, "Note", 622 int eexit=QMessageBox::information(this, "Note",
623 "Do you really want to \nset this bookmark?." 623 "Do you really want to \nset this bookmark?."
624 ,QMessageBox::Yes, QMessageBox::No); 624 ,QMessageBox::Yes, QMessageBox::No);
625 if (eexit== 3) { 625 if (eexit== 3) {
626 626
627 currentFilePos = f.at(); 627 currentFilePos = f.at();
628 628
629 Config cfg("Gutenbrowser"); 629 Config cfg("Gutenbrowser");
630 cfg.setGroup("General"); 630 cfg.setGroup("General");
631 file_name = cfg.readEntry("Current",""); 631 file_name = cfg.readEntry("Current","");
632 qApp->processEvents(); 632 qApp->processEvents();
633 odebug << "Setting book mark "+file_name << oendl; 633 odebug << "Setting book mark "+file_name << oendl;
634 634
635 cfg.setGroup("Titles"); 635 cfg.setGroup("Titles");
636 title = cfg.readEntry(file_name,""); 636 title = cfg.readEntry(file_name,"");
637 odebug << "title is "+ title << oendl; 637 odebug << "title is "+ title << oendl;
638 638
639 cfg.setGroup( "Bookmarks" ); 639 cfg.setGroup( "Bookmarks" );
640 640
641 cfg.writeEntry("File Name",file_name); 641 cfg.writeEntry("File Name",file_name);
642 cfg.writeEntry("Page Number",QString::number(i_pageNum) ); 642 cfg.writeEntry("Page Number",QString::number(i_pageNum) );
643 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1])); 643 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1]));
644 cfg.writeEntry("Title", title); 644 cfg.writeEntry("Title", title);
645 645
646 int row = Lview->topRow();// Lview->Top(); 646 int row = Lview->topRow();// Lview->Top();
647 cfg.writeEntry("LineNumber",QString::number(row) ); 647 cfg.writeEntry("LineNumber",QString::number(row) );
648 648
649 cfg.setGroup(title); 649 cfg.setGroup(title);
650 cfg.writeEntry("File Name",file_name); 650 cfg.writeEntry("File Name",file_name);
651 cfg.writeEntry( "LineNumber", QString::number( row)); 651 cfg.writeEntry( "LineNumber", QString::number( row));
652 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1])); 652 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1]));
653 cfg.writeEntry( "Page Number", QString::number( i_pageNum) ); 653 cfg.writeEntry( "Page Number", QString::number( i_pageNum) );
654 cfg.write(); 654 cfg.write();
655 bookmarksMenu->insertItem( title); 655 bookmarksMenu->insertItem( title);
656 } 656 }
657} //end setBookmark 657} //end setBookmark
658 658
659 659
660 /* goes to last set bookmark*/ 660 /* goes to last set bookmark*/
661void Gutenbrowser::Bookmark( int itemId) { 661void Gutenbrowser::Bookmark( int itemId) {
662 662
663 // qApp->processEvents(); 663 // qApp->processEvents();
664 Config config("Gutenbrowser"); 664 Config config("Gutenbrowser");
665 config.setGroup( "Bookmarks" ); 665 config.setGroup( "Bookmarks" );
666 666
667 odebug << "<<<<<< " << Lview->PageSize() << ", " << Lview->lastRow() - Lview->topRow() << "" << oendl; 667 odebug << "<<<<<< " << Lview->PageSize() << ", " << Lview->lastRow() - Lview->topRow() << "" << oendl;
668 668
669 QString itemString; 669 QString itemString;
670 670
671 odebug << "menu item " << itemId << "" << oendl; 671 odebug << "menu item " << itemId << "" << oendl;
672 QString tempTitle; 672 QString tempTitle;
673 QString s_Bmrkrow; 673 QString s_Bmrkrow;
674 QString s_pageNum; 674 QString s_pageNum;
675 int Bmrkrow=0; 675 int Bmrkrow=0;
676 int bookmarkPosition = 0; 676 int bookmarkPosition = 0;
677 677
678 // qApp->processEvents(); 678 // qApp->processEvents();
679 config.setGroup( "Bookmarks" ); 679 config.setGroup( "Bookmarks" );
680 title = config.readEntry("Title", ""); 680 title = config.readEntry("Title", "");
681 file_name = config.readEntry("File Name", ""); 681 file_name = config.readEntry("File Name", "");
682 i_pageNum = config.readNumEntry("Page Number", 0); 682 i_pageNum = config.readNumEntry("Page Number", 0);
683 bookmarkPosition = config.readNumEntry( "PagePosition",0); 683 bookmarkPosition = config.readNumEntry( "PagePosition",0);
684 Bmrkrow = config.readNumEntry("LineNumber",0); 684 Bmrkrow = config.readNumEntry("LineNumber",0);
685 if( !file_name.contains("/")) { 685 if( !file_name.contains("/")) {
686 file_name = local_library + file_name; 686 file_name = local_library + file_name;
687 } 687 }
688 688
689 // getTitle(file_name); 689 // getTitle(file_name);
690 // qApp->processEvents(); 690 // qApp->processEvents();
691 // Lview->setFocus(); 691 // Lview->setFocus();
692 this->setFocus(); 692 this->setFocus();
693 693
694 Lview->clear(); 694 Lview->clear();
695 695
696 if(!load(file_name)) return; 696 if(!load(file_name)) return;
697 697
698 int pageSize = Lview->PageSize(); 698 int pageSize = Lview->PageSize();
699 f.at(0); 699 f.at(0);
700 // Lview->clear(); 700 // Lview->clear();
701 QString s; 701 QString s;
702 int lineNo=0; 702 int lineNo=0;
703 int lastPage=1; 703 int lastPage=1;
704 while ( !f.atEnd() ) { 704 while ( !f.atEnd() ) {
705 f.readLine(s, 256); 705 f.readLine(s, 256);
706 lineNo++; 706 lineNo++;
707 currentFilePos = f.at(); 707 currentFilePos = f.at();
708 708
709 i_pageNum = lineNo/pageSize; 709 i_pageNum = lineNo/pageSize;
710 if(lastPage < i_pageNum) { 710 if(lastPage < i_pageNum) {
711 pageStopArray.resize(i_pageNum + 1); 711 pageStopArray.resize(i_pageNum + 1);
712 pageStopArray[i_pageNum ] = currentFilePos; 712 pageStopArray[i_pageNum ] = currentFilePos;
713 // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; 713 // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl;
714 } 714 }
715 if(currentFilePos == bookmarkPosition) 715 if(currentFilePos == bookmarkPosition)
716 break; 716 break;
717 } 717 }
718 if(f.atEnd()) 718 if(f.atEnd())
719 f.at(0); 719 f.at(0);
720 else 720 else
721 f.at( bookmarkPosition); 721 f.at( bookmarkPosition);
722 722
723 for(int fd=0; fd < pageSize - 1;fd++) { 723 for(int fd=0; fd < pageSize - 1;fd++) {
724 f.readLine(s, 256); 724 f.readLine(s, 256);
725 lineNo++; 725 lineNo++;
726 if(useWrap) 726 if(useWrap)
727 s.replace(QRegExp("\n"),""); 727 s.replace(QRegExp("\n"),"");
728 Lview->insertLine( s, -1); 728 Lview->insertLine( s, -1);
729 currentLine++; 729 currentLine++;
730 } 730 }
731 731
732 i_pageNum = lineNo/pageSize; 732 i_pageNum = lineNo/pageSize;
733 pageStopArray.resize(i_pageNum + 1); 733 pageStopArray.resize(i_pageNum + 1);
734 734
735 if(showMainList) { 735 if(showMainList) {
736 showMainList=FALSE; 736 showMainList=FALSE;
737 mainList->hide(); 737 mainList->hide();
738 Lview->show(); 738 Lview->show();
739 // qApp->processEvents(); 739 // qApp->processEvents();
740 } 740 }
741 741
742 odebug << "bookmark loaded" << oendl; 742 odebug << "bookmark loaded" << oendl;
743 setCaption(title); 743 setCaption(title);
744} 744}
745 745
746 746
747bool Gutenbrowser::load( const char *fileName) { 747bool Gutenbrowser::load( const char *fileName) {
748 748
749 // QCopEnvelope ( "QPE/System", "busy()" ); 749 // QCopEnvelope ( "QPE/System", "busy()" );
750 odebug << "Title is already set as "+title << oendl; 750 odebug << "Title is already set as "+title << oendl;
751 odebug << "sizeHint " << sizeHint().height() << " pageSize " << Lview->PageSize() << "" << oendl; 751 odebug << "sizeHint " << sizeHint().height() << " pageSize " << Lview->PageSize() << "" << oendl;
752 // pointSize = Lview->fontInfo().pointSize(); 752 // pointSize = Lview->fontInfo().pointSize();
753 // odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl; 753 // odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl;
754 if( Lview->PageSize() < 4) { 754 if( Lview->PageSize() < 4) {
755 755
756 //Lview->setMaximumHeight( sizeHint().height() ); 756 //Lview->setMaximumHeight( sizeHint().height() );
757 Lview->setMinimumHeight( sizeHint().height() ); 757 Lview->setMinimumHeight( sizeHint().height() );
758 pointSize = Lview->fontInfo().pointSize(); 758 pointSize = Lview->fontInfo().pointSize();
759 odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl; 759 odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl;
760 if(pointSize < 15) 760 if(pointSize < 15)
761 Lview->setFixedVisibleLines(19); 761 Lview->setFixedVisibleLines(19);
762 else 762 else
763 Lview->setFixedVisibleLines( ( (sizeHint().height() / pointSize ) * 2) -2); 763 Lview->setFixedVisibleLines( ( (sizeHint().height() / pointSize ) * 2) -2);
764 } 764 }
765 765
766 Config cfg("Gutenbrowser"); 766 Config cfg("Gutenbrowser");
767 cfg.setGroup("General"); 767 cfg.setGroup("General");
768 cfg.writeEntry("Current",fileName); 768 cfg.writeEntry("Current",fileName);
769 cfg.write(); 769 cfg.write();
770 currentLine=0; 770 currentLine=0;
771 771
772 file_name=fileName; 772 file_name=fileName;
773 QString o_file = fileName; 773 QString o_file = fileName;
774 774
775 // if (i_pageNum < 1) { 775 // if (i_pageNum < 1) {
776 i_pageNum = 1; 776 i_pageNum = 1;
777 // } 777 // }
778 odebug << "ready to open "+o_file << oendl; 778 odebug << "ready to open "+o_file << oendl;
779 779
780 if(f.isOpen()) f.close(); 780 if(f.isOpen()) f.close();
781 f.setName( o_file); 781 f.setName( o_file);
782 782
783 if ( !f.open( IO_ReadOnly)) { 783 if ( !f.open( IO_ReadOnly)) {
784 QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n" +o_file)) ); 784 QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n" +o_file)) );
785 return false; 785 return false;
786 } 786 }
787 currentFilePos = 0; 787 currentFilePos = 0;
788 pageStopArray.resize(3); 788 pageStopArray.resize(3);
789 pageStopArray[0] = currentFilePos; 789 pageStopArray[0] = currentFilePos;
790 790
791 fileHandle = f.handle(); 791 fileHandle = f.handle();
792 QString insertString; 792 QString insertString;
793 QTextStream t(&f); 793 QTextStream t(&f);
794 QString s; 794 QString s;
795 for(int fd=0; fd < Lview->PageSize() ;fd++) { 795 for(int fd=0; fd < Lview->PageSize() ;fd++) {
796 s=t.readLine(); 796 s=t.readLine();
797 // insertString+=s; 797 // insertString+=s;
798 if(useWrap) 798 if(useWrap)
799 s.replace(QRegExp("\n"),""); 799 s.replace(QRegExp("\n"),"");
800 // s.replace(QRegExp("\r"),""); 800 // s.replace(QRegExp("\r"),"");
801 Lview->insertLine( s,-1); 801 Lview->insertLine( s,-1);
802 currentLine++; 802 currentLine++;
803 } 803 }
804 804
805 // int length = Lview->length(); 805 // int length = Lview->length();
806 currentFilePos = f.at(); 806 currentFilePos = f.at();
807 807
808 pageStopArray[1] = currentFilePos; 808 pageStopArray[1] = currentFilePos;
809 809
810 odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum 810 odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum
811 << ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum] 811 << ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum]
812 << ", pageSize " << Lview->PageSize() << oendl; 812 << ", pageSize " << Lview->PageSize() << oendl;
813 813
814 Lview->setMaxLines(Lview->PageSize()*2); 814 Lview->setMaxLines(Lview->PageSize()*2);
815// odebug << "Gulped " << currentLine << "" << oendl; 815// odebug << "Gulped " << currentLine << "" << oendl;
816 setCaption(title); 816 setCaption(title);
817 Lview->setAutoUpdate( TRUE); 817 Lview->setAutoUpdate( TRUE);
818 818
819// Lview->setCursorPosition(0,0,FALSE); 819// Lview->setCursorPosition(0,0,FALSE);
820 820
821 // pages = (int)(( Lview->numLines() / Lview->editSize() ) / 2 ) +1; 821 // pages = (int)(( Lview->numLines() / Lview->editSize() ) / 2 ) +1;
822 //odebug << "number of pages " << pages << "" << oendl; 822 //odebug << "number of pages " << pages << "" << oendl;
823 823
824 loadCheck = true; 824 loadCheck = true;
825 enableButtons(true); 825 enableButtons(true);
826 if( donateMenu->count() == 3) { 826 if( donateMenu->count() == 3) {
827 donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() )); 827 donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() ));
828 } 828 }
829 Lview->setFocus(); 829 Lview->setFocus();
830 830
831 // QCopEnvelope("QPE/System", "notBusy()" ); 831 // QCopEnvelope("QPE/System", "notBusy()" );
832 return true; 832 return true;
833} // end load 833} // end load
834 834
835void Gutenbrowser::Search() { 835void Gutenbrowser::Search() {
836 836
837 // if( searchDlg->isHidden()) 837 // if( searchDlg->isHidden())
838 { 838 {
839 odebug << "Starting search dialog" << oendl; 839 odebug << "Starting search dialog" << oendl;
840 searchDlg = new SearchDialog( this, "Etext Search", true); 840 searchDlg = new SearchDialog( this, "Etext Search", true);
841 searchDlg->setCaption( tr( "Etext Search" )); 841 searchDlg->setCaption( tr( "Etext Search" ));
842 // searchDlg->setLabel( "- searches etext"); 842 // searchDlg->setLabel( "- searches etext");
843 connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot())); 843 connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot()));
844 connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot())); 844 connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot()));
845 845
846 QString resultString; 846 QString resultString;
847 QString string = searchDlg->searchString; 847 QString string = searchDlg->searchString;
848 Lview->deselect(); 848 Lview->deselect();
849 searchDlg->show(); 849 searchDlg->show();
850 searchDlg->result(); 850 searchDlg->result();
851 } 851 }
852} 852}
853 853
854void Gutenbrowser::search_slot( ) { 854void Gutenbrowser::search_slot( ) {
855 int line, col; 855 int line, col;
856 if (!searchDlg /*&& !loadCheck */) 856 if (!searchDlg /*&& !loadCheck */)
857 return; 857 return;
858 858
859 Lview->getCursorPosition(&line,&col); 859 Lview->getCursorPosition(&line,&col);
860 QString to_find_string=searchDlg->get_text(); 860 QString to_find_string=searchDlg->get_text();
861 861
862 // searchDlg->get_direction();// is true if searching backward 862 // searchDlg->get_direction();// is true if searching backward
863 if ( last_search != 0 && searchDlg->get_direction() ){ 863 if ( last_search != 0 && searchDlg->get_direction() ){
864 col = col - pattern.length() - 1 ; 864 col = col - pattern.length() - 1 ;
865 } 865 }
866 again: 866 again:
867 int result = doSearch( to_find_string , /* searchDlg->case_sensitive()*/ TRUE, searchDlg->forward_search(), line, col); 867 int result = doSearch( to_find_string , /* searchDlg->case_sensitive()*/ TRUE, searchDlg->forward_search(), line, col);
868 if(result == 0){ 868 if(result == 0){
869 if(!searchDlg->get_direction()){ // forward search 869 if(!searchDlg->get_direction()){ // forward search
870 int query = QMessageBox::information( searchDlg, "Find", 870 int query = QMessageBox::information( searchDlg, "Find",
871 "End of document reached.\nContinue from the beginning?", 871 "End of document reached.\nContinue from the beginning?",
872 "Yes", "No", "", 0,1); 872 "Yes", "No", "", 0,1);
873 if (query == 0){ 873 if (query == 0){
874 line = 0; 874 line = 0;
875 col = 0; 875 col = 0;
876 goto again; 876 goto again;
877 } 877 }
878 } else { //backward search 878 } else { //backward search
879 int query = QMessageBox::information( searchDlg, "Find", 879 int query = QMessageBox::information( searchDlg, "Find",
880 "End of document reached.\nContinue from the beginning?", 880 "End of document reached.\nContinue from the beginning?",
881 "Yes", "No", "", 0,1); 881 "Yes", "No", "", 0,1);
882 if (query == 0){ 882 if (query == 0){
883 QString string = Lview->textLine( Lview->numLines() - 1 ); 883 QString string = Lview->textLine( Lview->numLines() - 1 );
884 line = Lview->numLines() - 1; 884 line = Lview->numLines() - 1;
885 lineCheck = line; 885 lineCheck = line;
886 col = string.length(); 886 col = string.length();
887 last_search = -1; //BACKWARD; 887 last_search = -1; //BACKWARD;
888 goto again; 888 goto again;
889 } 889 }
890 } 890 }
891 } else { 891 } else {
892 892
893 //// emit CursorPositionChanged(); textLine 893 //// emit CursorPositionChanged(); textLine
894 } 894 }
895} 895}
896 896
897int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) { 897int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) {
898 int i, length; 898 int i, length;
899 int pos = -1; 899 int pos = -1;
900 if(forward) { 900 if(forward) {
901 QString string; 901 QString string;
902 for(i = line; i < Lview->numLines(); i++) { 902 for(i = line; i < Lview->numLines(); i++) {
903 903
904 string = Lview->textLine(i); 904 string = Lview->textLine(i);
905 pos = string.find(s_pattern, i == line ? col : 0, case_sensitive); 905 pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);
906 if( pos != -1) { 906 if( pos != -1) {
907 int top = Lview->Top(); 907 int top = Lview->Top();
908 length = s_pattern.length(); 908 length = s_pattern.length();
909 if( i > Lview->lastRow() ) { 909 if( i > Lview->lastRow() ) {
910// Lview->setCursorPosition(i,pos,FALSE); 910// Lview->setCursorPosition(i,pos,FALSE);
911 for(int l = 0 ; l < length; l++) { 911 for(int l = 0 ; l < length; l++) {
912 Lview->cursorRight(TRUE); 912 Lview->cursorRight(TRUE);
913 } 913 }
914// Lview->setCursorPosition( i , pos + length, TRUE ); 914// Lview->setCursorPosition( i , pos + length, TRUE );
915 int newTop = Lview->Top(); 915 int newTop = Lview->Top();
916 if(Lview->lastRow() > i) 916 if(Lview->lastRow() > i)
917 Lview->ScrollUp( newTop - top); 917 Lview->ScrollUp( newTop - top);
918 // AdjustStatus(); 918 // AdjustStatus();
919 } else { 919 } else {
920// Lview->setCursorPosition(i,pos,FALSE); 920// Lview->setCursorPosition(i,pos,FALSE);
921 for(int l = 0 ; l < length; l++) { 921 for(int l = 0 ; l < length; l++) {
922 Lview->cursorRight(TRUE); 922 Lview->cursorRight(TRUE);
923 } 923 }
924// Lview->setCursorPosition( i , pos + length, TRUE ); 924// Lview->setCursorPosition( i , pos + length, TRUE );
925 // AdjustStatus(); 925 // AdjustStatus();
926 } 926 }
927 pattern = s_pattern; 927 pattern = s_pattern;
928 last_search = 1; //FORWARD; 928 last_search = 1; //FORWARD;
929 return 1; 929 return 1;
930 } 930 }
931 } 931 }
932 } else { //////////////// searching backwards 932 } else { //////////////// searching backwards
933 QString string; 933 QString string;
934 for( i = line; i >= 0; i--) { 934 for( i = line; i >= 0; i--) {
935 string = Lview->textLine(i); 935 string = Lview->textLine(i);
936 int line_length = string.length(); 936 int line_length = string.length();
937 pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive); 937 pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
938 if (pos != -1) { 938 if (pos != -1) {
939 // int top = Lview->Top(); 939 // int top = Lview->Top();
940 length = s_pattern.length(); 940 length = s_pattern.length();
941 if( i < Lview->Top() ) { 941 if( i < Lview->Top() ) {
942 Lview->ScrollDown( Lview->PageSize() ); 942 Lview->ScrollDown( Lview->PageSize() );
943 Lview->MultiLine_Ex::pageUp( FALSE ); 943 Lview->MultiLine_Ex::pageUp( FALSE );
944 if( ! (line == i && pos > col ) ) { 944 if( ! (line == i && pos > col ) ) {
945// Lview->setCursorPosition( i ,pos ,FALSE ); 945// Lview->setCursorPosition( i ,pos ,FALSE );
946 for(int l = 0 ; l < length; l++) { 946 for(int l = 0 ; l < length; l++) {
947 Lview->cursorRight(TRUE); 947 Lview->cursorRight(TRUE);
948 } 948 }
949// Lview->setCursorPosition(i ,pos + length ,TRUE ); 949// Lview->setCursorPosition(i ,pos + length ,TRUE );
950 // int newTop = Lview->Top(); 950 // int newTop = Lview->Top();
951 /* if(useSplitter) Rview->ScrollUp( newTop - top); 951 /* if(useSplitter) Rview->ScrollUp( newTop - top);
952 */ } 952 */ }
953 } else { 953 } else {
954 if( ! (line == i && pos > col ) ) { 954 if( ! (line == i && pos > col ) ) {
955// Lview->setCursorPosition( i, pos, FALSE ); 955// Lview->setCursorPosition( i, pos, FALSE );
956 for( int l = 0 ; l < length; l++) { 956 for( int l = 0 ; l < length; l++) {
957 Lview->cursorRight( TRUE); 957 Lview->cursorRight( TRUE);
958 } 958 }
959// Lview->setCursorPosition( i, pos + length, TRUE ); 959// Lview->setCursorPosition( i, pos + length, TRUE );
960 } 960 }
961 pattern = s_pattern; 961 pattern = s_pattern;
962 last_search = -1; 962 last_search = -1;
963 return 1; 963 return 1;
964 } 964 }
965 } 965 }
966 } 966 }
967 } 967 }
968 return 0; 968 return 0;
969} 969}
970 970
971void Gutenbrowser::LibraryBtn() { 971void Gutenbrowser::LibraryBtn() {
972 972
973 QString newestLibraryFile ="pgwhole.zip"; 973 QString newestLibraryFile ="pgwhole.zip";
974 QString zipFile; 974 QString zipFile;
975 // odebug << "Local Library is " << local_library << " " << oendl; 975 // odebug << "Local Library is " << local_library << " " << oendl;
976 zipFile="/usr/bin/unzip"; 976 zipFile="/usr/bin/unzip";
977 // odebug << "newestLibraryFile is " << newestLibraryFile << " " << oendl; 977 // odebug << "newestLibraryFile is " << newestLibraryFile << " " << oendl;
978 if( QFile::exists( local_library+newestLibraryFile)) { 978 if( QFile::exists( local_library+newestLibraryFile)) {
979 if( QFile::exists(zipFile) ) { 979 if( QFile::exists(zipFile) ) {
980 UnZipIt(newestLibraryFile); 980 UnZipIt(newestLibraryFile);
981 } 981 }
982 else 982 else
983 QMessageBox::message( "Note",( tr("Please install unzip")) ); 983 QMessageBox::message( "Note",( tr("Please install unzip")) );
984 } 984 }
985 // LibraryDlg = new LibraryDialog( this, "Library Index"); 985 // LibraryDlg = new LibraryDialog( this, "Library Index");
986 LibraryDlg->setCaption( tr( "Gutenberg Library")); 986 LibraryDlg->setCaption( tr( "Gutenberg Library"));
987 Config config("Gutenbrowser"); 987 Config config("Gutenbrowser");
988 config.setGroup("General"); 988 config.setGroup("General");
989 989
990 if(useSplitter) 990 if(useSplitter)
991 LibraryDlg->useSmallInterface=FALSE; 991 LibraryDlg->useSmallInterface=FALSE;
992 992
993 LibraryDlg->showMaximized(); 993 LibraryDlg->showMaximized();
994 994
995 if( LibraryDlg->exec() != 0 ) { 995 if( LibraryDlg->exec() != 0 ) {
996 listItemNumber = LibraryDlg->DlglistItemNumber; 996 listItemNumber = LibraryDlg->DlglistItemNumber;
997 listItemFile = LibraryDlg->DlglistItemFile; 997 listItemFile = LibraryDlg->DlglistItemFile;
998 listItemYear = LibraryDlg->DlglistItemYear; 998 listItemYear = LibraryDlg->DlglistItemYear;
999 listItemTitle = LibraryDlg->DlglistItemTitle; 999 listItemTitle = LibraryDlg->DlglistItemTitle;
1000 file_name = LibraryDlg->File_Name; 1000 file_name = LibraryDlg->File_Name;
1001 // odebug << "title is being set as "+title << oendl; 1001 // odebug << "title is being set as "+title << oendl;
1002 title = listItemTitle; 1002 title = listItemTitle;
1003 1003
1004 // config.setGroup( "Proxy" ); 1004 // config.setGroup( "Proxy" );
1005 // if( LibraryDlg->checked == 1) { 1005 // if( LibraryDlg->checked == 1) {
1006 // config.writeEntry("IsChecked", "TRUE"); 1006 // config.writeEntry("IsChecked", "TRUE");
1007 // } else { 1007 // } else {
1008 // config.writeEntry("IsChecked", "FALSE"); 1008 // config.writeEntry("IsChecked", "FALSE");
1009 // } 1009 // }
1010 // config.write(); 1010 // config.write();
1011 // config.read(); 1011 // config.read();
1012 if ( listItemNumber.isNull()) { 1012 if ( listItemNumber.isNull()) {
1013 } else { 1013 } else {
1014 i_pageNum = 1; 1014 i_pageNum = 1;
1015 if( file_name !="Error" && file_name.length() >2 && !file_name.isEmpty() ) { 1015 if( file_name !="Error" && file_name.length() >2 && !file_name.isEmpty() ) {
1016 //replace .zip with txt for opening it. 1016 //replace .zip with txt for opening it.
1017 // printf("\nFile name is now\n"); 1017 // printf("\nFile name is now\n");
1018 // printf(file_name); 1018 // printf(file_name);
1019 // printf("\n"); 1019 // printf("\n");
1020 // 1020 //
1021 if( file_name.find(".zip")) 1021 if( file_name.find(".zip"))
1022 { 1022 {
1023 odebug << "Found zip file\n" << oendl; 1023 odebug << "Found zip file\n" << oendl;
1024 // QStringList args; 1024 // QStringList args;
1025 // args="unzip"; 1025 // args="unzip";
1026 // args+="-o"; 1026 // args+="-o";
1027 // args+=local_library+file_name; 1027 // args+=local_library+file_name;
1028 // args+="-d"; 1028 // args+="-d";
1029 // args+=local_library; 1029 // args+=local_library;
1030 QString cmd = "/usr/bin/unzip -o " + local_library+file_name + " -d " + local_library; 1030 QString cmd = "/usr/bin/unzip -o " + local_library+file_name + " -d " + local_library;
1031 odebug << "Issuing the command "+ cmd << oendl; 1031 odebug << "Issuing the command "+ cmd << oendl;
1032 // unzipProc=new QProcess( this, "unzipProc" ); /// fark that idea! 1032 // unzipProc=new QProcess( this, "unzipProc" ); /// fark that idea!
1033 // unzipProc->start(); 1033 // unzipProc->start();
1034 system(cmd); 1034 system(cmd);
1035 remove( file_name); 1035 remove( file_name);
1036 1036
1037 } 1037 }
1038 // // 1038 // //
1039 // file_name = file_name.left(4)+ ".txt"; 1039 // file_name = file_name.left(4)+ ".txt";
1040 if( LibraryDlg) 1040 if( LibraryDlg)
1041 delete LibraryDlg; 1041 delete LibraryDlg;
1042 setTitle(); 1042 setTitle();
1043 // QCopEnvelope ( "QPE/System", "busy()" ); 1043 // QCopEnvelope ( "QPE/System", "busy()" );
1044 if( !load( file_name)) return; 1044 if( !load( file_name)) return;
1045 } else { 1045 } else {
1046 printf("Not opening the file.\n"); 1046 printf("Not opening the file.\n");
1047 } 1047 }
1048 } 1048 }
1049 } 1049 }
1050 if(showMainList) { 1050 if(showMainList) {
1051 if(!Lview->isHidden()) 1051 if(!Lview->isHidden())
1052 Lview->hide(); 1052 Lview->hide();
1053 qApp->processEvents(); 1053 qApp->processEvents();
1054 showMainList=TRUE; 1054 showMainList=TRUE;
1055 if(mainList->isHidden()) 1055 if(mainList->isHidden())
1056 mainList->show(); 1056 mainList->show();
1057 fillWithTitles(); 1057 fillWithTitles();
1058 qApp->processEvents(); 1058 qApp->processEvents();
1059 } else 1059 } else
1060 setCentralWidget( Lview); 1060 setCentralWidget( Lview);
1061 // QPEApplication::grabKeyboard(); 1061 // QPEApplication::grabKeyboard();
1062 // fixKeys(); 1062 // fixKeys();
1063} 1063}
1064 1064
1065void Gutenbrowser::OpenBtn() { 1065void Gutenbrowser::OpenBtn() {
1066 QString s_temp; 1066 QString s_temp;
1067 s_temp = status; 1067 s_temp = status;
1068 OpenEtext* OpenDlg; 1068 OpenEtext* OpenDlg;
1069 OpenDlg = new OpenEtext(this,"OpenDlg"); 1069 OpenDlg = new OpenEtext(this,"OpenDlg");
1070 OpenDlg->showMaximized(); 1070 OpenDlg->showMaximized();
1071 1071
1072 if( OpenDlg->exec() != 0) { 1072 if( OpenDlg->exec() != 0) {
1073 title = OpenDlg->openFileTitle; 1073 title = OpenDlg->openFileTitle;
1074 odebug << "title open as "+title << oendl; 1074 odebug << "title open as "+title << oendl;
1075 file_name = OpenDlg->file; 1075 file_name = OpenDlg->file;
1076 i_pageNum = 1; 1076 i_pageNum = 1;
1077 1077
1078 if( !file_name.isEmpty() || file_name.length() > 2 ) { 1078 if( !file_name.isEmpty() || file_name.length() > 2 ) {
1079 if(showMainList) { 1079 if(showMainList) {
1080 showMainList=FALSE; 1080 showMainList=FALSE;
1081 odebug << "ShowMainList is now false" << oendl; 1081 odebug << "ShowMainList is now false" << oendl;
1082 mainList->hide(); 1082 mainList->hide();
1083 Lview->show(); 1083 Lview->show();
1084 qApp->processEvents(); 1084 qApp->processEvents();
1085 } 1085 }
1086 Lview->clear(); 1086 Lview->clear();
1087 // QCopEnvelope ( "QPE/System", "busy()" ); 1087 // QCopEnvelope ( "QPE/System", "busy()" );
1088 if(!load(file_name)) return; 1088 if(!load(file_name)) return;
1089 } else { 1089 } else {
1090 odebug << "file_name is empty!" << oendl; 1090 odebug << "file_name is empty!" << oendl;
1091 if(showMainList) { 1091 if(showMainList) {
1092 if(!Lview->isHidden()) 1092 if(!Lview->isHidden())
1093 Lview->hide(); 1093 Lview->hide();
1094 qApp->processEvents(); 1094 qApp->processEvents();
1095 if(mainList->isHidden()) 1095 if(mainList->isHidden())
1096 mainList->show(); 1096 mainList->show();
1097 fillWithTitles(); 1097 fillWithTitles();
1098 qApp->processEvents(); 1098 qApp->processEvents();
1099 } 1099 }
1100 1100
1101 } 1101 }
1102 } 1102 }
1103 if( OpenDlg) 1103 if( OpenDlg)
1104 delete OpenDlg; 1104 delete OpenDlg;
1105 /* 1105 /*
1106 Config config("Gutenbrowser"); 1106 Config config("Gutenbrowser");
1107 config.setGroup( title); 1107 config.setGroup( title);
1108 file_name = config.readEntry("File Name", ""); 1108 file_name = config.readEntry("File Name", "");
1109 i_pageNum = config.readNumEntry("Page Number", -1); 1109 i_pageNum = config.readNumEntry("Page Number", -1);
1110 int Bmrkrow = config.readNumEntry("LineNumber", -1); 1110 int Bmrkrow = config.readNumEntry("LineNumber", -1);
1111 if(Bmrkrow > -1) { 1111 if(Bmrkrow > -1) {
1112 if( Bmrkrow > Lview->topRow() ) { 1112 if( Bmrkrow > Lview->topRow() ) {
1113 Lview->setCursorPosition( Bmrkrow ,0, FALSE ); 1113 Lview->setCursorPosition( Bmrkrow ,0, FALSE );
1114 Lview->ScrollUp( Bmrkrow - Lview->topRow() ); 1114 Lview->ScrollUp( Bmrkrow - Lview->topRow() );
1115 // AdjustStatus(); 1115 // AdjustStatus();
1116 } 1116 }
1117 else if( Bmrkrow < Lview->topRow() ) { 1117 else if( Bmrkrow < Lview->topRow() ) {
1118 Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE ); 1118 Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE );
1119 Lview->ScrollDown( Lview->topRow() - Bmrkrow ); 1119 Lview->ScrollDown( Lview->topRow() - Bmrkrow );
1120 // AdjustStatus(); 1120 // AdjustStatus();
1121 } 1121 }
1122 } 1122 }
1123 */ 1123 */
1124 // ResizeEdits(); 1124 // ResizeEdits();
1125 1125
1126} 1126}
1127 1127
1128void Gutenbrowser::ChangeFont() { 1128void Gutenbrowser::ChangeFont() {
1129#ifndef Q_WS_QWS 1129#ifndef Q_WS_QWS
1130 bool ok; 1130 bool ok;
1131 1131
1132 weight= Lview->fontInfo().weight(); 1132 weight= Lview->fontInfo().weight();
1133 italic = Lview->fontInfo().italic(); 1133 italic = Lview->fontInfo().italic();
1134 bold=Lview->fontInfo().bold(); 1134 bold=Lview->fontInfo().bold();
1135 pointSize= Lview->fontInfo().pointSize(); 1135 pointSize= Lview->fontInfo().pointSize();
1136 fontStr=Lview->fontInfo().family(); 1136 fontStr=Lview->fontInfo().family();
1137 1137
1138 if(italic == true) 1138 if(italic == true)
1139 italicStr="TRUE"; 1139 italicStr="TRUE";
1140 else 1140 else
1141 italicStr="FALSE"; 1141 italicStr="FALSE";
1142 1142
1143 QFont currentfont( fontStr, pointSize, weight, italic ); 1143 QFont currentfont( fontStr, pointSize, weight, italic );
1144 1144
1145 if (ok) { 1145 if (ok) {
1146 QFontInfo fontInfo(font ); 1146 QFontInfo fontInfo(font );
1147 fontStr=fontInfo.family(); 1147 fontStr=fontInfo.family();
1148 1148
1149 pointSize= fontInfo.pointSize(); 1149 pointSize= fontInfo.pointSize();
1150 1150
1151 font.setFontSize(pointSize); 1151 font.setFontSize(pointSize);
1152 1152
1153 pointSizeStr.setNum( pointSize); 1153 pointSizeStr.setNum( pointSize);
1154 1154
1155 weight= fontInfo.weight(); 1155 weight= fontInfo.weight();
1156 weightStr.setNum( weight); 1156 weightStr.setNum( weight);
1157 italic =fontInfo.italic(); 1157 italic =fontInfo.italic();
1158 bold=fontInfo.bold(); 1158 bold=fontInfo.bold();
1159 1159
1160 if(italic == true) 1160 if(italic == true)
1161 italicStr="TRUE"; 1161 italicStr="TRUE";
1162 else 1162 else
1163 italicStr="FALSE"; 1163 italicStr="FALSE";
1164 if(bold == true) 1164 if(bold == true)
1165 boldStr="TRUE"; 1165 boldStr="TRUE";
1166 else 1166 else
1167 boldStr="FALSE"; 1167 boldStr="FALSE";
1168 1168
1169 pointSizeStr.setNum( pointSize); 1169 pointSizeStr.setNum( pointSize);
1170 config.setGroup( "Font" ); 1170 config.setGroup( "Font" );
1171 config.writeEntry("Family", fontStr ); 1171 config.writeEntry("Family", fontStr );
1172 config.writeEntry("Size", pointSizeStr ); 1172 config.writeEntry("Size", pointSizeStr );
1173 config.writeEntry("Weight", weightStr ); 1173 config.writeEntry("Weight", weightStr );
1174 config.writeEntry("Italic", italicStr ); 1174 config.writeEntry("Italic", italicStr );
1175 config.writeEntry("Bold", boldStr ); 1175 config.writeEntry("Bold", boldStr );
1176 // config.write(); 1176 // config.write();
1177 1177
1178 Lview->setFont(font); 1178 Lview->setFont(font);
1179 1179
1180 QRect lRect; 1180 QRect lRect;
1181 QRect rRect; 1181 QRect rRect;
1182 lRect = Lview->rect(); 1182 lRect = Lview->rect();
1183 if(useSplitter) { 1183 if(useSplitter) {
1184 } 1184 }
1185 // if(loadCheck) { 1185 // if(loadCheck) {
1186 // ResizeEdits(); 1186 // ResizeEdits();
1187 // } 1187 // }
1188 update(); 1188 update();
1189 } 1189 }
1190#endif 1190#endif
1191} 1191}
1192 1192
1193 1193
1194 /* 1194 /*
1195 performs dictionary look ups on the web */ 1195 performs dictionary look ups on the web */
1196void Gutenbrowser::LookupBtn() { 1196void Gutenbrowser::LookupBtn() {
1197 QString text; 1197 QString text;
1198 if( Lview->hasSelectedText()) { 1198 if( Lview->hasSelectedText()) {
1199 Lview->copy(); 1199 Lview->copy();
1200 } 1200 }
1201 QClipboard *cb = QApplication::clipboard(); 1201 QClipboard *cb = QApplication::clipboard();
1202 text = cb->text(); 1202 text = cb->text();
1203 int eexit=QMessageBox::information(this, 1203 int eexit=QMessageBox::information(this,
1204 "Note","Do you want to lookup\n\""+text+"\"\non websters web dictionary?", 1204 "Note","Do you want to lookup\n\""+text+"\"\non websters web dictionary?",
1205 QMessageBox::Yes, QMessageBox::No); 1205 QMessageBox::Yes, QMessageBox::No);
1206 if (eexit== 3) { 1206 if (eexit== 3) {
1207 // this link for sale!! 1207 // this link for sale!!
1208 qApp->processEvents(); 1208 qApp->processEvents();
1209 goGetit( "http://www.m-w.com/cgi-bin/dictionary?" + text, true); 1209 goGetit( "http://www.m-w.com/cgi-bin/dictionary?" + text, true);
1210 } 1210 }
1211} 1211}
1212 1212
1213void Gutenbrowser::ClearEdit() { 1213void Gutenbrowser::ClearEdit() {
1214 Lview->setText(""); 1214 Lview->setText("");
1215 loadCheck = false; 1215 loadCheck = false;
1216 status = ( tr("Gutenbrowser")); 1216 status = ( tr("Gutenbrowser"));
1217 InfoBar->setText( ""); 1217 InfoBar->setText( "");
1218 setCaption( tr("Gutenbrowser")); 1218 setCaption( tr("Gutenbrowser"));
1219 i_pageNum = 0; 1219 i_pageNum = 0;
1220 enableButtons(false); 1220 enableButtons(false);
1221 1221
1222 if(!showMainList) { 1222 if(!showMainList) {
1223 Lview->hide(); 1223 Lview->hide();
1224 showMainList=TRUE; 1224 showMainList=TRUE;
1225 mainList->show(); 1225 mainList->show();
1226 fillWithTitles(); 1226 fillWithTitles();
1227 qApp->processEvents(); 1227 qApp->processEvents();
1228 } 1228 }
1229 if(donateMenu->idAt(3) != -1) 1229 if(donateMenu->idAt(3) != -1)
1230 donateMenu->removeItemAt(3); 1230 donateMenu->removeItemAt(3);
1231} 1231}
1232 1232
1233 1233
1234bool Gutenbrowser::getTitle( const char *file ) { 1234bool Gutenbrowser::getTitle( const char *file ) {
1235 QString s_file; 1235 QString s_file;
1236 QString filer = file; 1236 QString filer = file;
1237 if( filer.contains(local_library, TRUE)) { 1237 if( filer.contains(local_library, TRUE)) {
1238 QFileInfo f(file); 1238 QFileInfo f(file);
1239 s_file = f.fileName(); 1239 s_file = f.fileName();
1240 } else { 1240 } else {
1241 s_file = filer; 1241 s_file = filer;
1242 } 1242 }
1243 Config config("Gutenbrowser"); 1243 Config config("Gutenbrowser");
1244 config.setGroup( "Files" ); 1244 config.setGroup( "Files" );
1245 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); 1245 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
1246 int i_numofFiles = s_numofFiles.toInt(); 1246 int i_numofFiles = s_numofFiles.toInt();
1247 1247
1248 for (int i = 1; i <= i_numofFiles; i++) { 1248 for (int i = 1; i <= i_numofFiles; i++) {
1249 QString temp; 1249 QString temp;
1250 temp.setNum(i); 1250 temp.setNum(i);
1251 QString ramble = config.readEntry(temp, "" ); 1251 QString ramble = config.readEntry(temp, "" );
1252 1252
1253 if( strcmp(ramble, s_file) == 0) { 1253 if( strcmp(ramble, s_file) == 0) {
1254 config.setGroup( "Titles" ); 1254 config.setGroup( "Titles" );
1255 title = config.readEntry(ramble, ""); 1255 title = config.readEntry(ramble, "");
1256 // odebug << "(getTitle)title is being set as "+title << oendl; 1256 // odebug << "(getTitle)title is being set as "+title << oendl;
1257 } 1257 }
1258 } 1258 }
1259 return true; 1259 return true;
1260} 1260}
1261 1261
1262void Gutenbrowser::searchdone_slot() { 1262void Gutenbrowser::searchdone_slot() {
1263 // if (!searchDlg) 1263 // if (!searchDlg)
1264 // return; 1264 // return;
1265 // searchDlg->hide(); 1265 // searchDlg->hide();
1266 // Lview->setFocus(); 1266 // Lview->setFocus();
1267 this->setFocus(); 1267 this->setFocus();
1268 last_search = 0; 1268 last_search = 0;
1269 // ResizeEdits(); 1269 // ResizeEdits();
1270} 1270}
1271 1271
1272 /* 1272 /*
1273 sets the status message */ 1273 sets the status message */
1274bool Gutenbrowser::setStatus() { 1274bool Gutenbrowser::setStatus() {
1275 1275
1276#ifndef Q_WS_QWS 1276#ifndef Q_WS_QWS
1277 QString s_pages; 1277 QString s_pages;
1278 s_pages.setNum( pages); 1278 s_pages.setNum( pages);
1279 QString chNum; 1279 QString chNum;
1280 statusTop = status.left( status.find(" ", TRUE) ); 1280 statusTop = status.left( status.find(" ", TRUE) );
1281 status.append(chNum.setNum( i_pageNum)); 1281 status.append(chNum.setNum( i_pageNum));
1282 status += " / " + s_pages; 1282 status += " / " + s_pages;
1283 1283
1284 if(loadCheck) { 1284 if(loadCheck) {
1285 statusBar->message( status); 1285 statusBar->message( status);
1286 InfoBar->setText( title); 1286 InfoBar->setText( title);
1287 } else { 1287 } else {
1288 } 1288 }
1289#else 1289#else
1290 QString msg; 1290 QString msg;
1291 msg.sprintf(title+" %d", i_pageNum); 1291 msg.sprintf(title+" %d", i_pageNum);
1292 setCaption( msg); 1292 setCaption( msg);
1293#endif 1293#endif
1294 return true; 1294 return true;
1295} 1295}
1296 1296
1297void Gutenbrowser::keyReleaseEvent( QKeyEvent *e) { 1297void Gutenbrowser::keyReleaseEvent( QKeyEvent *e) {
1298 switch ( e->key() ) { 1298 switch ( e->key() ) {
1299 1299
1300 case Key_M: 1300 case Key_M:
1301 // Bookmark(); 1301 // Bookmark();
1302 break; 1302 break;
1303 case Key_D: 1303 case Key_D:
1304 DownloadIndex(); 1304 DownloadIndex();
1305 break; 1305 break;
1306 case Key_L: 1306 case Key_L:
1307 LibraryBtn(); 1307 LibraryBtn();
1308 break; 1308 break;
1309 case Key_O: 1309 case Key_O:
1310 OpenBtn(); 1310 OpenBtn();
1311 break; 1311 break;
1312 case Key_F: 1312 case Key_F:
1313 ForwardBtn(); 1313 ForwardBtn();
1314 break; 1314 break;
1315 case Key_B: 1315 case Key_B:
1316 BackBtn(); 1316 BackBtn();
1317 break; 1317 break;
1318 case Key_P: 1318 case Key_P:
1319 PrintBtn(); 1319 PrintBtn();
1320 break; 1320 break;
1321 case Key_S: 1321 case Key_S:
1322 SearchBtn(); 1322 SearchBtn();
1323 break; 1323 break;
1324 case Key_E: 1324 case Key_E:
1325 ByeBye(); 1325 ByeBye();
1326 break; 1326 break;
1327 case Key_R: 1327 case Key_R:
1328 // setBookmark(); 1328 // setBookmark();
1329 break; 1329 break;
1330 case Key_T: 1330 case Key_T:
1331 ChangeFont(); 1331 ChangeFont();
1332 break; 1332 break;
1333 case Key_C: 1333 case Key_C:
1334 ClearEdit(); 1334 ClearEdit();
1335 break; 1335 break;
1336 case Key_H: 1336 case Key_H:
1337 HelpBtn(); 1337 HelpBtn();
1338 break; 1338 break;
1339 case Key_K: 1339 case Key_K:
1340 LookupBtn(); 1340 LookupBtn();
1341 break; 1341 break;
1342 case Key_U:// hide menu 1342 case Key_U:// hide menu
1343 if(menubar->isHidden() ) 1343 if(menubar->isHidden() )
1344 menubar->show(); 1344 menubar->show();
1345 else 1345 else
1346 menubar->hide(); 1346 menubar->hide();
1347 break; 1347 break;
1348 case Key_I: 1348 case Key_I:
1349 hideButtons(); 1349 hideButtons();
1350 break; 1350 break;
1351 ////////////////////////////// Zaurus keys 1351 ////////////////////////////// Zaurus keys
1352 case Key_Home: 1352 case Key_Home:
1353 // BeginBtn(); 1353 // BeginBtn();
1354 break; 1354 break;
1355 case Key_F9: //activity 1355 case Key_F9: //activity
1356 OpenBtn(); 1356 OpenBtn();
1357 break; 1357 break;
1358 case Key_F10: //contacts 1358 case Key_F10: //contacts
1359 hideButtons(); 1359 hideButtons();
1360 break; 1360 break;
1361 case Key_F11: //menu 1361 case Key_F11: //menu
1362 if(menubar->isHidden() ) 1362 if(menubar->isHidden() )
1363 menubar->show(); 1363 menubar->show();
1364 else 1364 else
1365 menubar->hide(); 1365 menubar->hide();
1366 break; 1366 break;
1367 case Key_F12: //home 1367 case Key_F12: //home
1368 BeginBtn(); 1368 BeginBtn();
1369 break; 1369 break;
1370 case Key_F13: //mail 1370 case Key_F13: //mail
1371 LibraryBtn(); 1371 LibraryBtn();
1372 break; 1372 break;
1373 case Key_Space: 1373 case Key_Space:
1374 if(loadCheck) 1374 if(loadCheck)
1375 ForwardBtn(); 1375 ForwardBtn();
1376 // else 1376 // else
1377 // Bookmark(); 1377 // Bookmark();
1378 break; 1378 break;
1379 case Key_Down: 1379 case Key_Down:
1380 if(loadCheck) { 1380 if(loadCheck) {
1381 // if( !e->isAutoRepeat() ) 1381 // if( !e->isAutoRepeat() )
1382 // AdjustStatus(); 1382 // AdjustStatus();
1383 // } else { 1383 // } else {
1384 // LibraryBtn(); 1384 // LibraryBtn();
1385 // ForwardBtn(); 1385 // ForwardBtn();
1386 } 1386 }
1387 1387
1388 // ForwardButton->setFocus(); 1388 // ForwardButton->setFocus();
1389 // Lview->setFocus(); 1389 // Lview->setFocus();
1390 // if(s_Wrap=="FALSE") 1390 // if(s_Wrap=="FALSE")
1391 // Lview->MultiLine_Ex::ScrollDown( 1); 1391 // Lview->MultiLine_Ex::ScrollDown( 1);
1392 // LibraryBtn(); 1392 // LibraryBtn();
1393 break; 1393 break;
1394 case Key_Up: 1394 case Key_Up:
1395 if(loadCheck) { 1395 if(loadCheck) {
1396 // if( !e->isAutoRepeat() ) 1396 // if( !e->isAutoRepeat() )
1397 // AdjustStatus(); 1397 // AdjustStatus();
1398 // } else { 1398 // } else {
1399 // OpenBtn(); 1399 // OpenBtn();
1400 // BackBtn(); 1400 // BackBtn();
1401 } 1401 }
1402 // BackButton->setFocus(); 1402 // BackButton->setFocus();
1403 // Lview->setFocus(); 1403 // Lview->setFocus();
1404 // if(s_Wrap=="FALSE") 1404 // if(s_Wrap=="FALSE")
1405 // Lview->MultiLine_Ex::ScrollUp( 1); 1405 // Lview->MultiLine_Ex::ScrollUp( 1);
1406 1406
1407 // LibraryBtn(); 1407 // LibraryBtn();
1408 break; 1408 break;
1409 case Key_Right: 1409 case Key_Right:
1410 ForwardButton->setFocus(); 1410 ForwardButton->setFocus();
1411 ForwardBtn(); 1411 ForwardBtn();
1412 // LibraryBtn(); 1412 // LibraryBtn();
1413 break; 1413 break;
1414 case Key_Left: 1414 case Key_Left:
1415 BackBtn(); 1415 BackBtn();
1416 BackButton->setFocus(); 1416 BackButton->setFocus();
1417 // OpenBtn(); 1417 // OpenBtn();
1418 break; 1418 break;
1419 case Key_Escape: 1419 case Key_Escape:
1420 ByeBye(); 1420 ByeBye();
1421 break; 1421 break;
1422 case Key_PageUp: 1422 case Key_PageUp:
1423 BackBtn(); 1423 BackBtn();
1424 break; 1424 break;
1425 case Key_PageDown: 1425 case Key_PageDown:
1426 ForwardBtn(); 1426 ForwardBtn();
1427 break; 1427 break;
1428 1428
1429 ////////////////////////////// Zaurus keys 1429 ////////////////////////////// Zaurus keys
1430 }; 1430 };
1431} 1431}
1432 1432
1433void Gutenbrowser::keyPressEvent( QKeyEvent *e) { 1433void Gutenbrowser::keyPressEvent( QKeyEvent *e) {
1434 switch ( e->key() ) { 1434 switch ( e->key() ) {
1435 // case Key_Next: 1435 // case Key_Next:
1436 // ForwardBtn(); 1436 // ForwardBtn();
1437 // break; 1437 // break;
1438 // case Key_Prior: 1438 // case Key_Prior:
1439 // BackBtn(); 1439 // BackBtn();
1440 // break; 1440 // break;
1441 // case Key_Space: 1441 // case Key_Space:
1442 // ForwardBtn(); 1442 // ForwardBtn();
1443 // break; 1443 // break;
1444 // case Key_Down: 1444 // case Key_Down:
1445 // Lview->MultiLine_Ex::ScrollUp( 1); 1445 // Lview->MultiLine_Ex::ScrollUp( 1);
1446 // if(useSplitter) Rview->MultiLine_Ex::ScrollUp( 1); 1446 // if(useSplitter) Rview->MultiLine_Ex::ScrollUp( 1);
1447 // break; 1447 // break;
1448 // case Key_Up: 1448 // case Key_Up:
1449 // if( Lview->Top() != 0) { 1449 // if( Lview->Top() != 0) {
1450 // Lview->MultiLine_Ex::ScrollDown( 1); 1450 // Lview->MultiLine_Ex::ScrollDown( 1);
1451 // if(useSplitter) Rview->MultiLine_Ex::ScrollDown( 1); 1451 // if(useSplitter) Rview->MultiLine_Ex::ScrollDown( 1);
1452 // } 1452 // }
1453 // break; 1453 // break;
1454 } 1454 }
1455} 1455}
1456 1456
1457void Gutenbrowser::resizeEvent( QResizeEvent *ev) { 1457void Gutenbrowser::resizeEvent( QResizeEvent *ev) {
1458 // odebug << "resize: " << ev->size().width() << "," << ev->size().height() << "\n" << oendl; 1458 // odebug << "resize: " << ev->size().width() << "," << ev->size().height() << "\n" << oendl;
1459 1459
1460 if( !LibraryDlg->isHidden()) 1460 if( !LibraryDlg->isHidden())
1461 LibraryDlg->resize(ev->size().width(),ev->size().height() ); 1461 LibraryDlg->resize(ev->size().width(),ev->size().height() );
1462 1462
1463 // if( loadCheck == true) { 1463 // if( loadCheck == true) {
1464 // ResizeEdits(); 1464 // ResizeEdits();
1465 // AdjustStatus(); 1465 // AdjustStatus();
1466 // } 1466 // }
1467} 1467}
1468 1468
1469 1469
1470void Gutenbrowser::doOptions() { 1470void Gutenbrowser::doOptions() {
1471 optionsDialog* optDlg; 1471 optionsDialog* optDlg;
1472 optDlg = new optionsDialog( this,"Options_Dlg", true); 1472 optDlg = new optionsDialog( this,"Options_Dlg", true);
1473 QString Ddir; 1473 QString Ddir;
1474 Config config("Gutenbrowser"); 1474 Config config("Gutenbrowser");
1475 config.setGroup( "General" ); 1475 config.setGroup( "General" );
1476 QFont myFont; 1476 QFont myFont;
1477 optDlg->showMaximized(); 1477 optDlg->showMaximized();
1478 1478
1479 if( optDlg->exec() !=0) { 1479 if( optDlg->exec() !=0) {
1480 qApp->processEvents(); 1480 qApp->processEvents();
1481 brow=optDlg->browserName; 1481 brow=optDlg->browserName;
1482 toggleButtonIcons( optDlg->useIcon); 1482 toggleButtonIcons( optDlg->useIcon);
1483 ftp_host= optDlg->ftp_host; 1483 ftp_host= optDlg->ftp_host;
1484 ftp_base_dir= optDlg->ftp_base_dir; 1484 ftp_base_dir= optDlg->ftp_base_dir;
1485 brow=optDlg->browserName; 1485 brow=optDlg->browserName;
1486 Ddir=optDlg->downloadDirEdit->text(); 1486 Ddir=optDlg->downloadDirEdit->text();
1487 1487
1488 odebug << "writing library config" << oendl; 1488 odebug << "writing library config" << oendl;
1489 Config config("Gutenbrowser"); 1489 Config config("Gutenbrowser");
1490 config.setGroup("General"); 1490 config.setGroup("General");
1491 1491
1492 QString dirname= optDlg->downloadDirEdit->text(); 1492 QString dirname= optDlg->downloadDirEdit->text();
1493 if(dirname.right(1)!="/") 1493 if(dirname.right(1)!="/")
1494 dirname+="/"; 1494 dirname+="/";
1495 config.writeEntry( "DownloadDirectory",dirname); 1495 config.writeEntry( "DownloadDirectory",dirname);
1496 QDir newDir( optDlg->downloadDirEdit->text()); 1496 QDir newDir( optDlg->downloadDirEdit->text());
1497 1497
1498 if( !newDir.exists() ) { 1498 if( !newDir.exists() ) {
1499 int exit=QMessageBox::information(this, "Note", "Ok, to make a new directory\n"+Ddir+" ?", 1499 int exit=QMessageBox::information(this, "Note", "Ok, to make a new directory\n"+Ddir+" ?",
1500 QMessageBox::Ok, QMessageBox::Cancel); 1500 QMessageBox::Ok, QMessageBox::Cancel);
1501 if (exit==1) { 1501 if (exit==1) {
1502 QString cmd="mkdir -p "; 1502 QString cmd="mkdir -p ";
1503 cmd+=Ddir.latin1(); 1503 cmd+=Ddir.latin1();
1504 system(cmd); 1504 system(cmd);
1505 odebug << "Making new dir "+cmd << oendl; 1505 odebug << "Making new dir "+cmd << oendl;
1506 if(Ddir.right(1)!="/") { 1506 if(Ddir.right(1)!="/") {
1507 Ddir+="/"; 1507 Ddir+="/";
1508 } 1508 }
1509 config.writeEntry("DownloadDirectory",Ddir); 1509 config.writeEntry("DownloadDirectory",Ddir);
1510 } 1510 }
1511 } 1511 }
1512 1512
1513// if(optDlg->styleChanged) 1513// if(optDlg->styleChanged)
1514// setStyle( optDlg->styleInt); 1514// setStyle( optDlg->styleInt);
1515 if(optDlg->b_qExit==TRUE) 1515 if(optDlg->b_qExit==TRUE)
1516 b_queryExit=TRUE; 1516 b_queryExit=TRUE;
1517 else 1517 else
1518 b_queryExit=FALSE; 1518 b_queryExit=FALSE;
1519 1519
1520 if(optDlg->fontDlg-> changedFonts) { 1520 if(optDlg->fontDlg-> changedFonts) {
1521 odebug << "Setting font" << oendl; 1521 odebug << "Setting font" << oendl;
1522 myFont=optDlg->fontDlg->selectedFont; 1522 myFont=optDlg->fontDlg->selectedFont;
1523 Lview->setFont( myFont); 1523 Lview->setFont( myFont);
1524 } 1524 }
1525 1525
1526 if(optDlg->useWordWrap_CheckBox->isChecked() ) { 1526 if(optDlg->useWordWrap_CheckBox->isChecked() ) {
1527 odebug << "WORD WRAP is set" << oendl; 1527 odebug << "WORD WRAP is set" << oendl;
1528 Lview->setWordWrap(QMultiLineEdit::WidgetWidth); 1528 Lview->setWordWrap(QMultiLineEdit::WidgetWidth);
1529 useWrap=true; 1529 useWrap=true;
1530 } else { 1530 } else {
1531 odebug << "Word wrap is NOT set" << oendl; 1531 odebug << "Word wrap is NOT set" << oendl;
1532 Lview->setWordWrap(QMultiLineEdit::NoWrap); 1532 Lview->setWordWrap(QMultiLineEdit::NoWrap);
1533 useWrap=false; 1533 useWrap=false;
1534 } 1534 }
1535 } 1535 }
1536 if(showMainList) { 1536 if(showMainList) {
1537 if(!Lview->isHidden()) 1537 if(!Lview->isHidden())
1538 Lview->hide(); 1538 Lview->hide();
1539 qApp->processEvents(); 1539 qApp->processEvents();
1540 if(mainList->isHidden()) 1540 if(mainList->isHidden())
1541 mainList->show(); 1541 mainList->show();
1542 fillWithTitles(); 1542 fillWithTitles();
1543 } else { 1543 } else {
1544 Lview->show(); 1544 Lview->show();
1545 showMainList=FALSE; 1545 showMainList=FALSE;
1546 mainList->hide(); 1546 mainList->hide();
1547 } 1547 }
1548 qApp->processEvents(); 1548 qApp->processEvents();
1549 update(); 1549 update();
1550} 1550}
1551 1551
1552bool Gutenbrowser::setTitle() { 1552bool Gutenbrowser::setTitle() {
1553 if( file_name.contains( local_library)) { 1553 if( file_name.contains( local_library)) {
1554 QFileInfo f( file_name); 1554 QFileInfo f( file_name);
1555 QString s_file = f.fileName(); 1555 QString s_file = f.fileName();
1556 file_name = s_file; 1556 file_name = s_file;
1557 } 1557 }
1558 1558
1559 int test = 0; 1559 int test = 0;
1560 Config config("Gutenbrowser"); 1560 Config config("Gutenbrowser");
1561 config.setGroup( "Files" ); 1561 config.setGroup( "Files" );
1562 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); 1562 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
1563 int i_numofFiles = s_numofFiles.toInt(); 1563 int i_numofFiles = s_numofFiles.toInt();
1564 1564
1565 for (int i = 1; i <= i_numofFiles; i++) { 1565 for (int i = 1; i <= i_numofFiles; i++) {
1566 QString temp; 1566 QString temp;
1567 temp.setNum(i); 1567 temp.setNum(i);
1568 QString ramble = config.readEntry(temp, "" ); 1568 QString ramble = config.readEntry(temp, "" );
1569 1569
1570 if( strcmp(ramble, file_name) == 0) { 1570 if( strcmp(ramble, file_name) == 0) {
1571 test = 1; 1571 test = 1;
1572 } 1572 }
1573 } 1573 }
1574 if (test == 0) { 1574 if (test == 0) {
1575 config.writeEntry("NumberOfFiles",i_numofFiles +1 ); 1575 config.writeEntry("NumberOfFiles",i_numofFiles +1 );
1576 QString interger; 1576 QString interger;
1577 interger.setNum( i_numofFiles +1); 1577 interger.setNum( i_numofFiles +1);
1578 config.writeEntry(interger, file_name); 1578 config.writeEntry(interger, file_name);
1579 1579
1580 config.setGroup( "Titles" ); 1580 config.setGroup( "Titles" );
1581 config.writeEntry(file_name,listItemTitle); 1581 config.writeEntry(file_name,listItemTitle);
1582 } 1582 }
1583 test = 0; 1583 test = 0;
1584 // config.write(); 1584 // config.write();
1585 return true; 1585 return true;
1586} 1586}
1587 /*Calls new fangled network dialog */ 1587 /*Calls new fangled network dialog */
1588void Gutenbrowser::OnNetworkDialog( const QString &/*networkUrl*/, const QString &/*output*/) 1588void Gutenbrowser::OnNetworkDialog( const QString &/*networkUrl*/, const QString &/*output*/)
1589{ 1589{
1590 // odebug << networkUrl << oendl; 1590 // odebug << networkUrl << oendl;
1591 // odebug << output << oendl; 1591 // odebug << output << oendl;
1592 // #ifndef Q_WS_QWS 1592 // #ifndef Q_WS_QWS
1593 // NetworkDialog *NetworkDlg; 1593 // NetworkDialog *NetworkDlg;
1594 // if( networkUrl.length() < 4 ) networkUrl= "http://sailor.gutenberg.org/mirror.sites.html"; 1594 // if( networkUrl.length() < 4 ) networkUrl= "http://sailor.gutenberg.org/mirror.sites.html";
1595 // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, output); 1595 // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, output);
1596 // if( NetworkDlg->exec() != 0 ) { 1596 // if( NetworkDlg->exec() != 0 ) {
1597 // } 1597 // }
1598 // if(NetworkDlg) 1598 // if(NetworkDlg)
1599 // delete NetworkDlg; 1599 // delete NetworkDlg;
1600 // #endif 1600 // #endif
1601} 1601}
1602 1602
1603void Gutenbrowser::donateGutenberg() 1603void Gutenbrowser::donateGutenberg()
1604{ 1604{
1605 int exit=QMessageBox::information(this, "Info", "http://www.gutenberg.org\ndonate@gutenberg.net", 1605 int exit=QMessageBox::information(this, "Info", "http://www.gutenberg.org\ndonate@gutenberg.net",
1606 QMessageBox::Ok, QMessageBox::Cancel); 1606 QMessageBox::Ok, QMessageBox::Cancel);
1607 1607
1608 if (exit==1) { 1608 if (exit==1) {
1609 } else { 1609 } else {
1610 }; 1610 };
1611} 1611}
1612 1612
1613void Gutenbrowser::donateByteMonkie() 1613void Gutenbrowser::donateByteMonkie()
1614{ 1614{
1615} 1615}
1616 1616
1617void Gutenbrowser::writeConfig() 1617void Gutenbrowser::writeConfig()
1618{ 1618{
1619 // config.read(); 1619 // config.read();
1620 // Config config("Gutenbrowser"); 1620 // Config config("Gutenbrowser");
1621 // #ifndef Q_WS_QWS 1621 // #ifndef Q_WS_QWS
1622 // config.setGroup( "Geometry" ); 1622 // config.setGroup( "Geometry" );
1623 // QString s; 1623 // QString s;
1624 // QString globalPosition; 1624 // QString globalPosition;
1625 // QPoint point; 1625 // QPoint point;
1626 // point=mapToGlobal(QPoint(0,0) ); 1626 // point=mapToGlobal(QPoint(0,0) );
1627 // int posiX, posiY; 1627 // int posiX, posiY;
1628 // posiX=point.x(); 1628 // posiX=point.x();
1629 // posiY=point.y(); 1629 // posiY=point.y();
1630 // globalPosition.sprintf("%i,%i", posiX, posiY); 1630 // globalPosition.sprintf("%i,%i", posiX, posiY);
1631 1631
1632 // QRect frameRect; 1632 // QRect frameRect;
1633 // frameRect = geometry(); 1633 // frameRect = geometry();
1634 // s.sprintf("%i,%i", frameRect.width(), frameRect.height()); 1634 // s.sprintf("%i,%i", frameRect.width(), frameRect.height());
1635 // config.writeEntry("Frame", s); 1635 // config.writeEntry("Frame", s);
1636 // config.writeEntry("Position", globalPosition); 1636 // config.writeEntry("Position", globalPosition);
1637 1637
1638 // if( useIcons==TRUE) 1638 // if( useIcons==TRUE)
1639 // config.writeEntry("Icons", "TRUE"); 1639 // config.writeEntry("Icons", "TRUE");
1640 // else 1640 // else
1641 // config.writeEntry("Icons", "FALSE"); 1641 // config.writeEntry("Icons", "FALSE");
1642 // #endif 1642 // #endif
1643 1643
1644 // #ifndef Q_WS_QWS 1644 // #ifndef Q_WS_QWS
1645 // QString temp; 1645 // QString temp;
1646 // temp.setNum(styleI, 10); 1646 // temp.setNum(styleI, 10);
1647 // config.setGroup( "StyleIze" ); 1647 // config.setGroup( "StyleIze" );
1648 // config.writeEntry( "Style", temp); 1648 // config.writeEntry( "Style", temp);
1649 // #endif 1649 // #endif
1650 1650
1651 // config.setGroup("General"); 1651 // config.setGroup("General");
1652} 1652}
1653 1653
1654void Gutenbrowser::annotations() 1654void Gutenbrowser::annotations()
1655{ 1655{
1656 // #ifndef Q_WS_QWS 1656 // #ifndef Q_WS_QWS
1657 // QMessageBox::message("Note","hi annotate"); 1657 // QMessageBox::message("Note","hi annotate");
1658 // lastBmkButton->setDown(FALSE); 1658 // lastBmkButton->setDown(FALSE);
1659 // #endif 1659 // #endif
1660} 1660}
1661 1661
1662void Gutenbrowser::hideButtons() 1662void Gutenbrowser::hideButtons()
1663{ 1663{
1664 1664
1665 if( !buttonsHidden) { 1665 if( !buttonsHidden) {
1666 buttonsHidden=TRUE; 1666 buttonsHidden=TRUE;
1667 LibraryButton->hide(); 1667 LibraryButton->hide();
1668 SearchButton->hide(); 1668 SearchButton->hide();
1669 InfoBar->hide(); 1669 InfoBar->hide();
1670 OpenButton->hide(); 1670 OpenButton->hide();
1671 BackButton->hide(); 1671 BackButton->hide();
1672 ForwardButton->hide(); 1672 ForwardButton->hide();
1673 setBookmarkButton->hide(); 1673 setBookmarkButton->hide();
1674 lastBmkButton->hide(); 1674 lastBmkButton->hide();
1675 dictionaryButton->hide(); 1675 dictionaryButton->hide();
1676 if(useSplitter) { 1676 if(useSplitter) {
1677 ClearButton->hide(); 1677 ClearButton->hide();
1678 PrintButton->hide(); 1678 PrintButton->hide();
1679 beginButton->hide(); 1679 beginButton->hide();
1680 HelpButton->hide(); 1680 HelpButton->hide();
1681 FontButton->hide(); 1681 FontButton->hide();
1682 ExitButton->hide(); 1682 ExitButton->hide();
1683 OptionsButton->hide(); 1683 OptionsButton->hide();
1684 DownloadButton->hide(); 1684 DownloadButton->hide();
1685 } 1685 }
1686 } else { 1686 } else {
1687 buttonsHidden=FALSE; 1687 buttonsHidden=FALSE;
1688 1688
1689 LibraryButton->show(); 1689 LibraryButton->show();
1690 SearchButton->show(); 1690 SearchButton->show();
1691 InfoBar->show(); 1691 InfoBar->show();
1692 OpenButton->show(); 1692 OpenButton->show();
1693 BackButton->show(); 1693 BackButton->show();
1694 ForwardButton->show(); 1694 ForwardButton->show();
1695 setBookmarkButton->show(); 1695 setBookmarkButton->show();
1696 lastBmkButton->show(); 1696 lastBmkButton->show();
1697 dictionaryButton->show(); 1697 dictionaryButton->show();
1698 if(useSplitter) { 1698 if(useSplitter) {
1699 ClearButton->show(); 1699 ClearButton->show();
1700 PrintButton->show(); 1700 PrintButton->show();
1701 beginButton->show(); 1701 beginButton->show();
1702 HelpButton->show(); 1702 HelpButton->show();
1703 FontButton->show(); 1703 FontButton->show();
1704 ExitButton->show(); 1704 ExitButton->show();
1705 OptionsButton->show(); 1705 OptionsButton->show();
1706 DownloadButton->show(); 1706 DownloadButton->show();
1707 } 1707 }
1708 } 1708 }
1709} 1709}
1710 1710
1711void Gutenbrowser::focusInEvent( QFocusEvent* ) 1711void Gutenbrowser::focusInEvent( QFocusEvent* )
1712{ 1712{
1713} 1713}
1714void Gutenbrowser::focusOutEvent( QFocusEvent* ) 1714void Gutenbrowser::focusOutEvent( QFocusEvent* )
1715{ 1715{
1716} 1716}
1717 1717
1718void Gutenbrowser::cleanUp( ) 1718void Gutenbrowser::cleanUp( )
1719{ 1719{
1720 writeConfig(); 1720 writeConfig();
1721 QPEApplication::grabKeyboard(); 1721 QPEApplication::grabKeyboard();
1722 1722
1723 QPEApplication::ungrabKeyboard(); 1723 QPEApplication::ungrabKeyboard();
1724 // odebug << "Cleanup" << oendl; 1724 // odebug << "Cleanup" << oendl;
1725 if(f.isOpen()) f.close(); 1725 if(f.isOpen()) f.close();
1726} 1726}
1727 1727
1728void Gutenbrowser::fixKeys() 1728void Gutenbrowser::fixKeys()
1729{ 1729{
1730 odebug << "Attempting to fix keys" << oendl; 1730 odebug << "Attempting to fix keys" << oendl;
1731 1731
1732} 1732}
1733 1733
1734void Gutenbrowser::enableButtons(bool b) 1734void Gutenbrowser::enableButtons(bool b)
1735{ 1735{
1736 BackButton->setEnabled(b); 1736 BackButton->setEnabled(b);
1737 ForwardButton->setEnabled(b); 1737 ForwardButton->setEnabled(b);
1738 SearchButton->setEnabled(b); 1738 SearchButton->setEnabled(b);
1739 setBookmarkButton->setEnabled(b); 1739 setBookmarkButton->setEnabled(b);
1740 dictionaryButton->setEnabled(b); 1740 dictionaryButton->setEnabled(b);
1741 InfoBar->setEnabled(b); 1741 InfoBar->setEnabled(b);
1742 1742
1743 editMenu->setItemEnabled( -5, b); 1743 editMenu->setItemEnabled( -5, b);
1744 editMenu->setItemEnabled( -6, b); 1744 editMenu->setItemEnabled( -6, b);
1745 editMenu->setItemEnabled( -7, b); 1745 editMenu->setItemEnabled( -7, b);
1746 editMenu->setItemEnabled( -8, b); 1746 editMenu->setItemEnabled( -8, b);
1747 1747
1748} 1748}
1749 1749
1750void Gutenbrowser::fillWithTitles() { 1750void Gutenbrowser::fillWithTitles() {
1751 Config config("Gutenbrowser"); 1751 Config config("Gutenbrowser");
1752 config.setGroup( "Files" ); 1752 config.setGroup( "Files" );
1753 int i_numofFiles = config.readNumEntry("NumberOfFiles", 0); 1753 int i_numofFiles = config.readNumEntry("NumberOfFiles", 0);
1754 mainList->clear(); 1754 mainList->clear();
1755 QString temp; 1755 QString temp;
1756 for (int i = 1; i <= i_numofFiles; i++) { 1756 for (int i = 1; i <= i_numofFiles; i++) {
1757 temp.setNum(i); 1757 temp.setNum(i);
1758 config.setGroup( "Files" ); 1758 config.setGroup( "Files" );
1759 QString ramble = config.readEntry(temp, "" ); 1759 QString ramble = config.readEntry(temp, "" );
1760 config.setGroup( "Titles" ); 1760 config.setGroup( "Titles" );
1761 temp = config.readEntry(ramble, ""); 1761 temp = config.readEntry(ramble, "");
1762 if( !temp.isEmpty()) { 1762 if( !temp.isEmpty()) {
1763 mainList->insertItem ( Resource::loadPixmap("gutenbrowser/gutenbrowser_sm"), temp, -1); 1763 mainList->insertItem ( Resource::loadPixmap("gutenbrowser/gutenbrowser_sm"), temp, -1);
1764 } 1764 }
1765 } 1765 }
1766} 1766}
1767 1767
1768void Gutenbrowser::listClickedSlot( QListBoxItem * index) { 1768void Gutenbrowser::listClickedSlot( QListBoxItem * index) {
1769 // if( !working) { 1769 // if( !working) {
1770 // working=true; 1770 // working=true;
1771 if(index) { 1771 if(index) {
1772 // QCopEnvelope ( "QPE/System", "busy()" ); 1772 // QCopEnvelope ( "QPE/System", "busy()" );
1773 title = index->text(); 1773 title = index->text();
1774 showMainList=FALSE; 1774 showMainList=FALSE;
1775 mainList->hide(); 1775 mainList->hide();
1776 Lview->show(); 1776 Lview->show();
1777 qApp->processEvents(); 1777 qApp->processEvents();
1778 QString temp; 1778 QString temp;
1779 temp.setNum( mainList->currentItem() + 1); 1779 temp.setNum( mainList->currentItem() + 1);
1780 // openFileTitle = title; 1780 // openFileTitle = title;
1781 Config config("Gutenbrowser"); 1781 Config config("Gutenbrowser");
1782 config.setGroup( "Files" ); 1782 config.setGroup( "Files" );
1783 QString file = config.readEntry(temp, ""); 1783 QString file = config.readEntry(temp, "");
1784 odebug << "About to load" << oendl; 1784 odebug << "About to load" << oendl;
1785 if( Lview->isVisible()) 1785 if( Lview->isVisible())
1786 if(!load(file)) return; 1786 if(!load(file)) return;
1787 1787
1788 config.setGroup( title); 1788 config.setGroup( title);
1789 file_name = config.readEntry("File Name", ""); 1789 file_name = config.readEntry("File Name", "");
1790 i_pageNum = config.readNumEntry("Page Number", 1); 1790 i_pageNum = config.readNumEntry("Page Number", 1);
1791 int Bmrkrow = config.readNumEntry("LineNumber", -1); 1791 int Bmrkrow = config.readNumEntry("LineNumber", -1);
1792 if(Bmrkrow > -1) { 1792 if(Bmrkrow > -1) {
1793 if( Bmrkrow > Lview->topRow() ) { 1793 if( Bmrkrow > Lview->topRow() ) {
1794// Lview->setCursorPosition( Bmrkrow /* - Lview->topRow() */,0, FALSE ); 1794// Lview->setCursorPosition( Bmrkrow /* - Lview->topRow() */,0, FALSE );
1795 Lview->ScrollUp( Bmrkrow - Lview->topRow() ); 1795 Lview->ScrollUp( Bmrkrow - Lview->topRow() );
1796 // AdjustStatus(); 1796 // AdjustStatus();
1797 } 1797 }
1798 else if( Bmrkrow < Lview->topRow() ) { 1798 else if( Bmrkrow < Lview->topRow() ) {
1799// Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE ); 1799// Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE );
1800 Lview->ScrollDown( Lview->topRow() - Bmrkrow ); 1800 Lview->ScrollDown( Lview->topRow() - Bmrkrow );
1801 // AdjustStatus(); 1801 // AdjustStatus();
1802 } 1802 }
1803 } 1803 }
1804 } 1804 }
1805} 1805}
1806 1806
1807void Gutenbrowser::infoGutenbrowser() { 1807void Gutenbrowser::infoGutenbrowser() {
1808 QMessageBox::message("Info","Gutenbrowser was developed by\n" 1808 QMessageBox::message("Info","Gutenbrowser was developed by\n"
1809 "Lorn Potter\n" 1809 "Lorn Potter\n"
1810 "ljp<ljp@llornkcor.com>\n"); 1810 "ljp<ljp@llornkcor.com>\n");
1811} 1811}
1812 1812
1813void Gutenbrowser::setDocument(const QString & frozenBoogers) { 1813void Gutenbrowser::setDocument(const QString & frozenBoogers) {
1814 // this->hide(); 1814 // this->hide();
1815 qWarning("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSET DOCUMENT\n"); 1815 qWarning("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSET DOCUMENT\n");
1816 if(showMainList) { 1816 if(showMainList) {
1817 showMainList=FALSE; 1817 showMainList=FALSE;
1818 if(!mainList->isHidden()) 1818 if(!mainList->isHidden())
1819 mainList->hide(); 1819 mainList->hide();
1820 if(Lview->isHidden()) 1820 if(Lview->isHidden())
1821 Lview->show(); 1821 Lview->show();
1822 qApp->processEvents(); 1822 qApp->processEvents();
1823 } 1823 }
1824 DocLnk lnk; 1824 DocLnk lnk;
1825 lnk = DocLnk(frozenBoogers); 1825 lnk = DocLnk(frozenBoogers);
1826 qWarning("open "+frozenBoogers); 1826 qWarning("open "+frozenBoogers);
1827 // odebug << lnk.file() << oendl; 1827 // odebug << lnk.file() << oendl;
1828 title=lnk.comment(); 1828 title=lnk.comment();
1829 if(!load( lnk.file())) return; 1829 if(!load( lnk.file())) return;
1830 this->show(); 1830 this->show();
1831 // odebug << title << oendl; 1831 // odebug << title << oendl;
1832 // qApp->processEvents(); 1832 // qApp->processEvents();
1833 // repaint(); 1833 // repaint();
1834} 1834}
1835 1835
1836void Gutenbrowser::mainListPressed(int mouse, QListBoxItem * , const QPoint & ) 1836void Gutenbrowser::mainListPressed(int mouse, QListBoxItem * , const QPoint & )
1837{ 1837{
1838 switch (mouse) { 1838 switch (mouse) {
1839 case 1: 1839 case 1:
1840 break; 1840 break;
1841 case 2: { 1841 case 2: {
1842 QPopupMenu m;// = new QPopupMenu( Local_View ); 1842 QPopupMenu m;// = new QPopupMenu( Local_View );
1843 m.insertItem( tr( "Open" ), this, SLOT( menuOpen() )); 1843 m.insertItem( tr( "Open" ), this, SLOT( menuOpen() ));
1844 m.insertSeparator(); 1844 m.insertSeparator();
1845 m.insertItem( tr( "Search google.com" ), this, SLOT( menuGoogle())); 1845 m.insertItem( tr( "Search google.com" ), this, SLOT( menuGoogle()));
1846 m.insertItem( tr( "Edit Title" ), this, SLOT( menuEditTitle())); 1846 m.insertItem( tr( "Edit Title" ), this, SLOT( menuEditTitle()));
1847 // m.insertSeparator(); 1847 // m.insertSeparator();
1848 // m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); 1848 // m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() ));
1849 m.exec( QCursor::pos() ); 1849 m.exec( QCursor::pos() );
1850 } 1850 }
1851 break; 1851 break;
1852 }; 1852 };
1853} 1853}
1854 1854
1855void Gutenbrowser::menuOpen() { 1855void Gutenbrowser::menuOpen() {
1856 listClickedSlot( mainList->item( mainList->currentItem())); 1856 listClickedSlot( mainList->item( mainList->currentItem()));
1857} 1857}
1858 1858
1859void Gutenbrowser::menuGoogle() { 1859void Gutenbrowser::menuGoogle() {
1860 searchGoogle( mainList->text(mainList->currentItem())); 1860 searchGoogle( mainList->text(mainList->currentItem()));
1861} 1861}
1862 1862
1863void Gutenbrowser::searchGoogle( const QString &tempText) { 1863void Gutenbrowser::searchGoogle( const QString &tempText) {
1864 QString text = tempText; 1864 QString text = tempText;
1865 1865
1866 int eexit=QMessageBox::information(this, "Note","Do you want to search for\n"+text+ 1866 int eexit=QMessageBox::information(this, "Note","Do you want to search for\n"+text+
1867 "\non google.com?",QMessageBox::Yes, QMessageBox::No); 1867 "\non google.com?",QMessageBox::Yes, QMessageBox::No);
1868 if (eexit== 3) { 1868 if (eexit== 3) {
1869 qApp->processEvents(); 1869 qApp->processEvents();
1870 text.replace( QRegExp("\\s"), "%20"); 1870 text.replace( QRegExp("\\s"), "%20");
1871 text.replace( QRegExp("#"), ""); 1871 text.replace( QRegExp("#"), "");
1872 text.replace( QRegExp(","), "%20"); 1872 text.replace( QRegExp(","), "%20");
1873 text.replace( QRegExp("'"), "%20"); 1873 text.replace( QRegExp("'"), "%20");
1874 text.replace( QRegExp("("), ""); 1874 text.replace( QRegExp("("), "");
1875 text.replace( QRegExp(")"), ""); 1875 text.replace( QRegExp(")"), "");
1876 // text.replace( QRegExp("[0-9]"), ""); 1876 // text.replace( QRegExp("[0-9]"), "");
1877 QString s_lookup = "http://google.com/search?q="+text+"&num=30&sa=Google+Search"; 1877 QString s_lookup = "http://google.com/search?q="+text+"&num=30&sa=Google+Search";
1878 goGetit( s_lookup, true); 1878 goGetit( s_lookup, true);
1879 } 1879 }
1880 1880
1881} 1881}
1882 1882
1883void Gutenbrowser::menuEditTitle() 1883void Gutenbrowser::menuEditTitle()
1884{ 1884{
1885 int currentItem = mainList->currentItem(); 1885 int currentItem = mainList->currentItem();
1886 QString title_text = mainList->text( currentItem); 1886 QString title_text = mainList->text( currentItem);
1887 //odebug << "Selected "+title_text << oendl; 1887 //odebug << "Selected "+title_text << oendl;
1888 1888
1889 Config config("Gutenbrowser"); 1889 Config config("Gutenbrowser");
1890 config.setGroup( "Files" ); 1890 config.setGroup( "Files" );
1891 QString s_numofFiles = config.readEntry("NumberOfFiles", "0"); 1891 QString s_numofFiles = config.readEntry("NumberOfFiles", "0");
1892 int i_numofFiles = s_numofFiles.toInt(); 1892 int i_numofFiles = s_numofFiles.toInt();
1893 QString fileNum; 1893 QString fileNum;
1894 for (int i = 1; i <= i_numofFiles+1; i++) { 1894 for (int i = 1; i <= i_numofFiles+1; i++) {
1895 1895
1896 fileNum.setNum(i); 1896 fileNum.setNum(i);
1897 config.setGroup( "Files" ); 1897 config.setGroup( "Files" );
1898 QString s_filename = config.readEntry(fileNum, "" ); 1898 QString s_filename = config.readEntry(fileNum, "" );
1899 config.setGroup( "Titles" ); 1899 config.setGroup( "Titles" );
1900 QString file_title = config.readEntry( s_filename, ""); 1900 QString file_title = config.readEntry( s_filename, "");
1901 //odebug << "file_title is "+file_title << oendl; 1901 //odebug << "file_title is "+file_title << oendl;
1902 if(title_text == file_title ) { 1902 if(title_text == file_title ) {
1903 // selFile = s_filename; 1903 // selFile = s_filename;
1904 //odebug << "Edit: "+ file_title << oendl; 1904 //odebug << "Edit: "+ file_title << oendl;
1905 i=i_numofFiles+1; 1905 i=i_numofFiles+1;
1906 Edit_Title *titleEdit; 1906 Edit_Title *titleEdit;
1907 titleEdit = new Edit_Title(this,file_title ,TRUE); 1907 titleEdit = new Edit_Title(this,file_title ,TRUE);
1908 if(titleEdit->exec() !=0) { 1908 if(titleEdit->exec() !=0) {
1909 //odebug << titleEdit->newTitle << oendl; 1909 //odebug << titleEdit->newTitle << oendl;
1910 config.writeEntry( s_filename, titleEdit->newTitle); 1910 config.writeEntry( s_filename, titleEdit->newTitle);
1911 mainList->removeItem(currentItem); 1911 mainList->removeItem(currentItem);
1912 mainList->insertItem ( Resource::loadPixmap("gutenbrowser/gutenbrowser_sm"), titleEdit->newTitle, currentItem); 1912 mainList->insertItem ( Resource::loadPixmap("gutenbrowser/gutenbrowser_sm"), titleEdit->newTitle, currentItem);
1913 } 1913 }
1914 } 1914 }
1915 } 1915 }
1916 1916
1917 // getTitles(); 1917 // getTitles();
1918 mainList->triggerUpdate(true); 1918 mainList->triggerUpdate(true);
1919 1919
1920} 1920}
1921 1921
1922 1922
1923 1923
1924bool Gutenbrowser::UnZipIt(const QString &zipFile) { 1924bool Gutenbrowser::UnZipIt(const QString &zipFile) {
1925 odebug << zipFile << oendl; 1925 odebug << zipFile << oendl;
1926#ifndef Q_WS_QWS 1926#ifndef Q_WS_QWS
1927 if( QFile::exists( zipFile)) { // TODO findsome other way of dealingwithzip files. 1927 if( QFile::exists( zipFile)) { // TODO findsome other way of dealingwithzip files.
1928 bool isPgWhole=false; 1928 bool isPgWhole=false;
1929 QString thatFile; 1929 QString thatFile;
1930 if(zipFile.find("pgwhole",0,TRUE)) { 1930 if(zipFile.find("pgwhole",0,TRUE)) {
1931 isPgWhole=TRUE; 1931 isPgWhole=TRUE;
1932 thatFile= local_library +"PGWHOLE.TXT"; 1932 thatFile= local_library +"PGWHOLE.TXT";
1933 } 1933 }
1934 // else { 1934 // else {
1935 // thatFile=zipFile.left(4); 1935 // thatFile=zipFile.left(4);
1936 // } 1936 // }
1937 // odebug << (const char*)local_library.latin1() << oendl; 1937 // odebug << (const char*)local_library.latin1() << oendl;
1938 QString cmd; 1938 QString cmd;
1939#if defined(_WS_X11_) 1939#if defined(_WS_X11_)
1940 if( chdir((const char*)local_library.latin1())!=0) 1940 if( chdir((const char*)local_library.latin1())!=0)
1941 odebug << "chdir failed." << oendl; 1941 odebug << "chdir failed." << oendl;
1942 cmd = "gunzip -S .zip " + local_library+zipFile; 1942 cmd = "gunzip -S .zip " + local_library+zipFile;
1943 //cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library; 1943 //cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library;
1944#endif 1944#endif
1945#ifdef Q_WS_QWS 1945#ifdef Q_WS_QWS
1946 if( chdir((const char*)local_library.latin1())!=0) 1946 if( chdir((const char*)local_library.latin1())!=0)
1947 odebug << "chdir failed." << oendl; 1947 odebug << "chdir failed." << oendl;
1948 cmd = "unzip " + local_library+zipFile; 1948 cmd = "unzip " + local_library+zipFile;
1949 // cmd = "/usr/bin/unzip -o " + local_library+zipFile +" -d /usr/share/doc/gutenbrowser" ;//+ local_library; 1949 // cmd = "/usr/bin/unzip -o " + local_library+zipFile +" -d /usr/share/doc/gutenbrowser" ;//+ local_library;
1950#endif 1950#endif
1951 int exit=QMessageBox::information(this, "Ok to unzip?", 1951 int exit=QMessageBox::information(this, "Ok to unzip?",
1952 "Ok to unnzip\n"+ zipFile+" ?", 1952 "Ok to unnzip\n"+ zipFile+" ?",
1953 QMessageBox::Yes, QMessageBox::No); 1953 QMessageBox::Yes, QMessageBox::No);
1954 if (exit==QMessageBox::Yes) { 1954 if (exit==QMessageBox::Yes) {
1955#if defined(_WS_X11_)// 1955#if defined(_WS_X11_)//
1956 odebug << "Issuing the command "+cmd << oendl; 1956 odebug << "Issuing the command "+cmd << oendl;
1957 system( cmd); 1957 system( cmd);
1958 if( QFile::exists(thatFile)) 1958 if( QFile::exists(thatFile))
1959 remove (thatFile); 1959 remove (thatFile);
1960 if(isPgWhole) { 1960 if(isPgWhole) {
1961 if( rename("pgwhole","PGWHOLE.TXT") !=0) 1961 if( rename("pgwhole","PGWHOLE.TXT") !=0)
1962 odebug << "rename failed" << oendl; 1962 odebug << "rename failed" << oendl;
1963 } else { 1963 } else {
1964 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0) 1964 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0)
1965 odebug << "rename failed" << oendl; 1965 odebug << "rename failed" << oendl;
1966 } 1966 }
1967#endif 1967#endif
1968#ifdef Q_WS_QWS 1968#ifdef Q_WS_QWS
1969 odebug << "Issuing the command "+cmd << oendl; 1969 odebug << "Issuing the command "+cmd << oendl;
1970 system( cmd); 1970 system( cmd);
1971 if( QFile::exists(thatFile)) 1971 if( QFile::exists(thatFile))
1972 remove(thatFile); 1972 remove(thatFile);
1973 if(isPgWhole) { 1973 if(isPgWhole) {
1974 if( rename("pgwhole","PGWHOLE.TXT") !=0) 1974 if( rename("pgwhole","PGWHOLE.TXT") !=0)
1975 odebug << "rename failed" << oendl; 1975 odebug << "rename failed" << oendl;
1976 } else { 1976 } else {
1977 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0) 1977 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0)
1978 odebug << "rename failed" << oendl; 1978 odebug << "rename failed" << oendl;
1979 } 1979 }
1980#endif 1980#endif
1981 // remove( zipFile); 1981 // remove( zipFile);
1982 return true; 1982 return true;
1983 } 1983 }
1984 else if(exit==QMessageBox::No) { 1984 else if(exit==QMessageBox::No) {
1985 // odebug << "unzip" << oendl; 1985 // odebug << "unzip" << oendl;
1986 return false; 1986 return false;
1987 } 1987 }
1988 } 1988 }
1989 else 1989 else
1990 QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) ); 1990 QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) );
1991#endif 1991#endif
1992 return false; 1992 return false;
1993} 1993}
1994 1994
1995 1995
diff --git a/noncore/apps/opie-gutenbrowser/helpme.cpp b/noncore/apps/opie-gutenbrowser/helpme.cpp
index 53e0236..0e23114 100644
--- a/noncore/apps/opie-gutenbrowser/helpme.cpp
+++ b/noncore/apps/opie-gutenbrowser/helpme.cpp
@@ -1,127 +1,127 @@
1/*************************************************************************** 1/***************************************************************************
2 helpme.cpp - description 2 helpme.cpp - description
3 ------------------- 3 -------------------
4 begin : Tue Jul 25 2000 4 begin : Tue Jul 25 2000
5 begin : Sat Dec 4 1999 5 begin : Sat Dec 4 1999
6 copyright : (C) 2000 -2004 by llornkcor 6 copyright : (C) 2000 -2004 by llornkcor
7 email : ljp@llornkcor.com 7 email : ljp@llornkcor.com
8 ***************************************************************************/ 8 ***************************************************************************/
9/*************************************************************************** 9/***************************************************************************
10 * * 10 * *
11 * This program is free software; you can redistribute it and/or modify * 11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. * 14 * (at your option) any later version. *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#include "helpme.h" 18#include "helpme.h"
19#include "helpwindow.h" 19#include "helpwindow.h"
20 20
21/* OPIE */ 21/* OPIE */
22#include <qpe/qcopenvelope_qws.h> 22#include <qpe/qcopenvelope_qws.h>
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24#include <opie2/odebug.h> 24#include <opie2/odebug.h>
25 25
26/* QT */ 26/* QT */
27#include <qprogressdialog.h> 27#include <qprogressdialog.h>
28#include <qlayout.h> 28#include <qlayout.h>
29 29
30/* STD */ 30/* STD */
31#include <sys/stat.h> 31#include <sys/stat.h>
32#include <unistd.h> 32#include <unistd.h>
33 33
34HelpMe::HelpMe(QWidget *parent, QString name ) : QDialog(parent,name) 34HelpMe::HelpMe(QWidget *parent, QString name ) : QDialog(parent,name)
35{ 35{
36 local_library = ( QDir::homeDirPath ())+"/Applications/gutenbrowser/"; 36 local_library = ( QDir::homeDirPath ())+"/Applications/gutenbrowser/";
37 setCaption(tr("Gutenbrowser About " VERSION)); 37 setCaption(tr("Gutenbrowser About " VERSION));
38 38
39 QGridLayout *layout = new QGridLayout( this ); 39 QGridLayout *layout = new QGridLayout( this );
40 layout->setSpacing( 4 ); 40 layout->setSpacing( 4 );
41 layout->setMargin( 4 ); 41 layout->setMargin( 4 );
42 42
43 Edit = new QMultiLineEdit(this, ""); 43 Edit = new QMultiLineEdit(this, "");
44 Edit->setReadOnly(true); 44 Edit->setReadOnly(true);
45 Edit->append(tr("Based on gutenbook.pl, available from http://www.gutenbook.org")); 45 Edit->append(tr("Based on gutenbook.pl, available from http://www.gutenbook.org"));
46 Edit->append(tr("Much appreciation to Lee Burgess,")); 46 Edit->append(tr("Much appreciation to Lee Burgess,"));
47 Edit->append(tr("for the original idea and concept of gutenbook.\n")); 47 Edit->append(tr("for the original idea and concept of gutenbook.\n"));
48 Edit->append(tr("A list of current Gutenberg ftp sites is at http://promo.net/pg/index.html\n")); 48 Edit->append(tr("A list of current Gutenberg ftp sites is at http://promo.net/pg/index.html\n"));
49 Edit->append(tr("For bug reports, comments or questions about Gutenbrowser, email")); 49 Edit->append(tr("For bug reports, comments or questions about Gutenbrowser, email"));
50 Edit->append(tr("ljp@llornkcor.com\n")); 50 Edit->append(tr("ljp@llornkcor.com\n"));
51 Edit->append(tr("\nMade using Qt, Qt Embedded, and Qtopia, a cross platform development API\nhttp://www.trolltech.com\n\n")); 51 Edit->append(tr("\nMade using Qt, Qt Embedded, and Qtopia, a cross platform development API\nhttp://www.trolltech.com\n\n"));
52 Edit->append(tr("Arnold's Laws of Documentation:")); 52 Edit->append(tr("Arnold's Laws of Documentation:"));
53 Edit->append(tr("(1) If it should exist, it doesn't.")); 53 Edit->append(tr("(1) If it should exist, it doesn't."));
54 Edit->append(tr("(2) If it does exist, it's out of date.")); 54 Edit->append(tr("(2) If it does exist, it's out of date."));
55 Edit->append(tr("(3) Only documentation for")); 55 Edit->append(tr("(3) Only documentation for"));
56 Edit->append(tr("useless programs transcends the")); 56 Edit->append(tr("useless programs transcends the"));
57 Edit->append(tr("first two laws.\n")); 57 Edit->append(tr("first two laws.\n"));
58 Edit->append(tr("Everything is temporary, anyway....\n :o)")); 58 Edit->append(tr("Everything is temporary, anyway....\n :o)"));
59 Edit->setWordWrap(QMultiLineEdit::WidgetWidth); 59 Edit->setWordWrap(QMultiLineEdit::WidgetWidth);
60 QString pixDir; 60 QString pixDir;
61 pixDir=QPEApplication::qpeDir()+"/pics/"; 61 pixDir=QPEApplication::qpeDir()+"pics/";
62 QPushButton *help; 62 QPushButton *help;
63 help = new QPushButton(this); 63 help = new QPushButton(this);
64 help->setPixmap( QPixmap( pixDir+"gutenbrowser/help.png")); 64 help->setPixmap( QPixmap( pixDir+"gutenbrowser/help.png"));
65 help->setText("Help"); 65 help->setText("Help");
66 connect( help,SIGNAL(clicked()),this,SLOT( help() )); 66 connect( help,SIGNAL(clicked()),this,SLOT( help() ));
67 67
68/* QPushButton *ok; 68/* QPushButton *ok;
69 ok = new QPushButton(this); 69 ok = new QPushButton(this);
70 ok->setPixmap( QPixmap( pixDir+"/gutenbrowser/exit.png")); 70 ok->setPixmap( QPixmap( pixDir+"/gutenbrowser/exit.png"));
71 ok->setText("ok"); 71 ok->setText("ok");
72 connect(ok,SIGNAL(clicked()),this,SLOT(accept() )); 72 connect(ok,SIGNAL(clicked()),this,SLOT(accept() ));
73*/ 73*/
74 help->setFixedHeight(25); 74 help->setFixedHeight(25);
75// ok->setFixedHeight(25); 75// ok->setFixedHeight(25);
76 76
77// layout->addMultiCellWidget( ok, 0, 0, 4, 4 ); 77// layout->addMultiCellWidget( ok, 0, 0, 4, 4 );
78 layout->addMultiCellWidget( help, 0, 0, 4, 4 ); 78 layout->addMultiCellWidget( help, 0, 0, 4, 4 );
79 layout->addMultiCellWidget( Edit, 1, 1, 0, 4 ); 79 layout->addMultiCellWidget( Edit, 1, 1, 0, 4 );
80} 80}
81 81
82HelpMe::~HelpMe() 82HelpMe::~HelpMe()
83{ 83{
84//delete Edit; 84//delete Edit;
85 85
86} 86}
87 87
88void HelpMe::goToURL() 88void HelpMe::goToURL()
89{ 89{
90 90
91 url = "http://www.llornkcor.com/"; 91 url = "http://www.llornkcor.com/";
92 goGetit( url); 92 goGetit( url);
93} 93}
94 94
95void HelpMe::goToURL2() 95void HelpMe::goToURL2()
96{ 96{
97 url = "http://www.gutenberg.org"; 97 url = "http://www.gutenberg.org";
98 goGetit( url); 98 goGetit( url);
99} 99}
100 100
101void HelpMe::goToURL3() 101void HelpMe::goToURL3()
102{ 102{
103 url = "http://www.gutenbook.org"; 103 url = "http://www.gutenbook.org";
104 goGetit( url); 104 goGetit( url);
105} 105}
106 106
107void HelpMe::goGetit( QString url) 107void HelpMe::goGetit( QString url)
108{ 108{
109 HelpWindow *help = new HelpWindow( url, ".", 0, "gutenbrowser"); 109 HelpWindow *help = new HelpWindow( url, ".", 0, "gutenbrowser");
110 help->setCaption("Qt Example - Helpviewer"); 110 help->setCaption("Qt Example - Helpviewer");
111 help->showMaximized(); 111 help->showMaximized();
112 help->show(); 112 help->show();
113} 113}
114 114
115void HelpMe::help() 115void HelpMe::help()
116{ 116{
117 QString msg ; 117 QString msg ;
118 msg=QPEApplication::qpeDir()+"help/html/gutenbrowser-index.html"; // or where ever this ends up to be 118 msg=QPEApplication::qpeDir()+"help/html/gutenbrowser-index.html"; // or where ever this ends up to be
119odebug << msg << oendl; 119odebug << msg << oendl;
120 QString url = "file://"+msg; 120 QString url = "file://"+msg;
121 goGetit( url); 121 goGetit( url);
122 122
123// QCopEnvelope e("QPE/Application/helpbrowser", "setDocument(QString)" ); 123// QCopEnvelope e("QPE/Application/helpbrowser", "setDocument(QString)" );
124// e << msg; 124// e << msg;
125 125
126// goGetit( msg); 126// goGetit( msg);
127} 127}
diff --git a/noncore/apps/zsafe/zsafe.cpp b/noncore/apps/zsafe/zsafe.cpp
index 6aa6392..1ae3b15 100644
--- a/noncore/apps/zsafe/zsafe.cpp
+++ b/noncore/apps/zsafe/zsafe.cpp
@@ -1,3879 +1,3879 @@
1/**************************************************************************** 1/****************************************************************************
2** 2**
3** Created: Sat Apr 6 17:57:45 2002 3** Created: Sat Apr 6 17:57:45 2002
4** 4**
5** Author: Carsten Schneider <CarstenSchneider@t-online.de> 5** Author: Carsten Schneider <CarstenSchneider@t-online.de>
6** 6**
7** $Id$ 7** $Id$
8** 8**
9** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html 9** Homepage: http://home.t-online.de/home/CarstenSchneider/zsafe/index.html
10** 10**
11** Compile Flags: 11** Compile Flags:
12** Zaurus arm : -DNO_OPIE 12** Zaurus arm : -DNO_OPIE
13** Zaurus Opie arm: none 13** Zaurus Opie arm: none
14** Linux Desktop : -DDESKTOP -DNO_OPIE 14** Linux Desktop : -DDESKTOP -DNO_OPIE
15** Windows Desktop: -DDESKTOP -DNO_OPIE 15** Windows Desktop: -DDESKTOP -DNO_OPIE
16** use qmake 16** use qmake
17** for japanese version additional use: -DJPATCH_HDE 17** for japanese version additional use: -DJPATCH_HDE
18** 18**
19****************************************************************************/ 19****************************************************************************/
20#include "zsafe.h" 20#include "zsafe.h"
21#include "newdialog.h" 21#include "newdialog.h"
22#include "searchdialog.h" 22#include "searchdialog.h"
23#include "categorydialog.h" 23#include "categorydialog.h"
24#include "passworddialog.h" 24#include "passworddialog.h"
25#include "infoform.h" 25#include "infoform.h"
26#include "zlistview.h" 26#include "zlistview.h"
27#include "shadedlistitem.h" 27#include "shadedlistitem.h"
28 28
29#ifndef DESKTOP 29#ifndef DESKTOP
30#ifndef NO_OPIE 30#ifndef NO_OPIE
31#include <opie2/ofiledialog.h> 31#include <opie2/ofiledialog.h>
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33using namespace Opie::Core; 33using namespace Opie::Core;
34using namespace Opie::Ui; 34using namespace Opie::Ui;
35#else 35#else
36#include "scqtfileedit.h" 36#include "scqtfileedit.h"
37#endif 37#endif
38#endif 38#endif
39 39
40#include <qclipboard.h> 40#include <qclipboard.h>
41 41
42#include <sys/types.h> 42#include <sys/types.h>
43#include <sys/stat.h> 43#include <sys/stat.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <stdlib.h> 45#include <stdlib.h>
46#ifndef Q_WS_WIN 46#ifndef Q_WS_WIN
47#include <unistd.h> 47#include <unistd.h>
48#endif 48#endif
49#include <string.h> 49#include <string.h>
50#include <errno.h> 50#include <errno.h>
51 51
52#include <qmenubar.h> 52#include <qmenubar.h>
53#include <qpopupmenu.h> 53#include <qpopupmenu.h>
54 54
55#ifdef DESKTOP 55#ifdef DESKTOP
56#include <qfiledialog.h> 56#include <qfiledialog.h>
57#include <qdragobject.h> 57#include <qdragobject.h>
58#ifndef Q_WS_WIN 58#ifndef Q_WS_WIN
59#include <qsettings.h> 59#include <qsettings.h>
60#else 60#else
61#include "qsettings.h" 61#include "qsettings.h"
62#endif 62#endif
63#include <qapplication.h> 63#include <qapplication.h>
64#else 64#else
65#include <qfile.h> 65#include <qfile.h>
66#include <qpe/fileselector.h> 66#include <qpe/fileselector.h>
67#include <qpe/global.h> 67#include <qpe/global.h>
68#include <qpe/qpeapplication.h> 68#include <qpe/qpeapplication.h>
69#include <qpe/resource.h> 69#include <qpe/resource.h>
70#include <qpe/config.h> 70#include <qpe/config.h>
71#endif 71#endif
72 72
73#include <qtimer.h> 73#include <qtimer.h>
74#include <qlayout.h> 74#include <qlayout.h>
75#include <qmessagebox.h> 75#include <qmessagebox.h>
76#include <qfile.h> 76#include <qfile.h>
77#include <qtextstream.h> 77#include <qtextstream.h>
78#include <qheader.h> 78#include <qheader.h>
79#include <qlistview.h> 79#include <qlistview.h>
80#include <qtoolbutton.h> 80#include <qtoolbutton.h>
81#include <qvariant.h> 81#include <qvariant.h>
82#include <qtooltip.h> 82#include <qtooltip.h>
83#include <qwhatsthis.h> 83#include <qwhatsthis.h>
84#include <qimage.h> 84#include <qimage.h>
85#include <qpixmap.h> 85#include <qpixmap.h>
86#include <qlineedit.h> 86#include <qlineedit.h>
87#include <qmultilineedit.h> 87#include <qmultilineedit.h>
88#include <qregexp.h> 88#include <qregexp.h>
89#include <qdir.h> 89#include <qdir.h>
90#include <qtextbrowser.h> 90#include <qtextbrowser.h>
91#include <qlabel.h> 91#include <qlabel.h>
92#include <qcombobox.h> 92#include <qcombobox.h>
93 93
94#include "krc2.h" 94#include "krc2.h"
95 95
96#include "wait.h" 96#include "wait.h"
97 97
98extern int DeskW, DeskH; 98extern int DeskW, DeskH;
99#ifdef DESKTOP 99#ifdef DESKTOP
100extern QApplication *appl; 100extern QApplication *appl;
101#else 101#else
102extern QPEApplication *appl; 102extern QPEApplication *appl;
103#endif 103#endif
104 104
105#ifdef JPATCH_HDE 105#ifdef JPATCH_HDE
106#define tr(arg) arg 106#define tr(arg) arg
107#endif 107#endif
108 108
109 109
110#ifdef DESKTOP 110#ifdef DESKTOP
111#ifndef Q_WS_WIN 111#ifndef Q_WS_WIN
112const QString APP_KEY="/.zsafe/"; 112const QString APP_KEY="/.zsafe/";
113#else 113#else
114const QString APP_KEY=""; 114const QString APP_KEY="";
115#endif 115#endif
116#else 116#else
117const QString APP_KEY=""; 117const QString APP_KEY="";
118#endif 118#endif
119 119
120// include xmp images 120// include xmp images
121#include "pics/zsafe/copy.xpm" 121#include "pics/zsafe/copy.xpm"
122#include "pics/zsafe/cut.xpm" 122#include "pics/zsafe/cut.xpm"
123#include "pics/zsafe/edit.xpm" 123#include "pics/zsafe/edit.xpm"
124#include "pics/zsafe/editdelete.xpm" 124#include "pics/zsafe/editdelete.xpm"
125#include "pics/zsafe/find.xpm" 125#include "pics/zsafe/find.xpm"
126#include "pics/zsafe/folder_open.xpm" 126#include "pics/zsafe/folder_open.xpm"
127#include "pics/zsafe/help_icon.xpm" 127#include "pics/zsafe/help_icon.xpm"
128#include "pics/zsafe/new.xpm" 128#include "pics/zsafe/new.xpm"
129#include "pics/zsafe/paste.xpm" 129#include "pics/zsafe/paste.xpm"
130#include "pics/zsafe/quit_icon.xpm" 130#include "pics/zsafe/quit_icon.xpm"
131#include "pics/zsafe/save.xpm" 131#include "pics/zsafe/save.xpm"
132#include "pics/zsafe/trash.xpm" 132#include "pics/zsafe/trash.xpm"
133#include "pics/zsafe/expand.xpm" 133#include "pics/zsafe/expand.xpm"
134#include "pics/zsafe/export.xpm" 134#include "pics/zsafe/export.xpm"
135#include "pics/zsafe/import.xpm" 135#include "pics/zsafe/import.xpm"
136#include "pics/zsafe/zsafe.xpm" 136#include "pics/zsafe/zsafe.xpm"
137 137
138static const char* const bank_cards_data[] = { 138static const char* const bank_cards_data[] = {
139"14 14 16 1", 139"14 14 16 1",
140". c None", 140". c None",
141"# c #000000", 141"# c #000000",
142"b c #0000de", 142"b c #0000de",
143"a c #0000e6", 143"a c #0000e6",
144"j c #41de83", 144"j c #41de83",
145"k c #4acecd", 145"k c #4acecd",
146"h c #4aced5", 146"h c #4aced5",
147"g c #5a40cd", 147"g c #5a40cd",
148"d c #5a44d5", 148"d c #5a44d5",
149"l c #9440d5", 149"l c #9440d5",
150"m c #b4ce4a", 150"m c #b4ce4a",
151"n c #cd4883", 151"n c #cd4883",
152"e c #d5ae10", 152"e c #d5ae10",
153"f c #de3ce6", 153"f c #de3ce6",
154"i c #e640e6", 154"i c #e640e6",
155"c c #ffffff", 155"c c #ffffff",
156"..............", 156"..............",
157".###########..", 157".###########..",
158".#ababababa#..", 158".#ababababa#..",
159".#babbbabbb#..", 159".#babbbabbb#..",
160".#ccccccccc#..", 160".#ccccccccc#..",
161".#cdcefcghc#..", 161".#cdcefcghc#..",
162".#ccccccccc#..", 162".#ccccccccc#..",
163".#cicjkclic#..", 163".#cicjkclic#..",
164".#ccccccccc#..", 164".#ccccccccc#..",
165".#cmchlcnec#..", 165".#cmchlcnec#..",
166".#ccccccccc#..", 166".#ccccccccc#..",
167".###########..", 167".###########..",
168"..............", 168"..............",
169".............."}; 169".............."};
170 170
171 171
172static const char* const passwords_data[] = { 172static const char* const passwords_data[] = {
173"16 16 20 1", 173"16 16 20 1",
174". c None", 174". c None",
175"# c #000000", 175"# c #000000",
176"r c #000083", 176"r c #000083",
177"p c #0000c5", 177"p c #0000c5",
178"q c #0000ff", 178"q c #0000ff",
179"n c #008100", 179"n c #008100",
180"l c #00c200", 180"l c #00c200",
181"m c #00ff00", 181"m c #00ff00",
182"j c #838100", 182"j c #838100",
183"a c #c55900", 183"a c #c55900",
184"h c #c5c200", 184"h c #c5c200",
185"o c #c5c2ff", 185"o c #c5c2ff",
186"k c #c5ffc5", 186"k c #c5ffc5",
187"f c #ff0000", 187"f c #ff0000",
188"d c #ff8100", 188"d c #ff8100",
189"b c #ffaa5a", 189"b c #ffaa5a",
190"e c #ffc2c5", 190"e c #ffc2c5",
191"c c #ffdeac", 191"c c #ffdeac",
192"i c #ffff00", 192"i c #ffff00",
193"g c #ffffc5", 193"g c #ffffc5",
194"............###.", 194"............###.",
195"...........#abb#", 195"...........#abb#",
196"..........#cbab#", 196"..........#cbab#",
197".........#cbdd#.", 197".........#cbdd#.",
198"######..#cbdd#..", 198"######..#cbdd#..",
199"#eeff#..#add#...", 199"#eeff#..#add#...",
200"#eeff#######....", 200"#eeff#######....",
201"#ccdbdd#........", 201"#ccdbdd#........",
202"#dddbdd###......", 202"#dddbdd###......",
203"#gghihhjj#......", 203"#gghihhjj#......",
204"#hhhihhjj###....", 204"#hhhihhjj###....",
205"#kklmllnnnn#....", 205"#kklmllnnnn#....",
206"#lllmllnnnn#....", 206"#lllmllnnnn#....",
207"#oopqpprprr#....", 207"#oopqpprprr#....",
208"#oopqpprprr#....", 208"#oopqpprprr#....",
209"############...."}; 209"############...."};
210 210
211static const char* const software_data[] = { 211static const char* const software_data[] = {
212"16 16 5 1", 212"16 16 5 1",
213". c None", 213". c None",
214"# c #000000", 214"# c #000000",
215"b c #838183", 215"b c #838183",
216"c c #c5ffff", 216"c c #c5ffff",
217"a c #ffffff", 217"a c #ffffff",
218"................", 218"................",
219".##############.", 219".##############.",
220"#aaaaaaaaaaaaaa#", 220"#aaaaaaaaaaaaaa#",
221"#abbbbbbbbbbbbb#", 221"#abbbbbbbbbbbbb#",
222"#ab##########ab#", 222"#ab##########ab#",
223"#ab#c########ab#", 223"#ab#c########ab#",
224"#ab#c#c######ab#", 224"#ab#c#c######ab#",
225"#ab##########ab#", 225"#ab##########ab#",
226"#ab##########ab#", 226"#ab##########ab#",
227"#ab##########ab#", 227"#ab##########ab#",
228"#ab##########ab#", 228"#ab##########ab#",
229"#ab##########ab#", 229"#ab##########ab#",
230"#aaaaaaaaaaaaab#", 230"#aaaaaaaaaaaaab#",
231"#bbbbbbbbbbbbbb#", 231"#bbbbbbbbbbbbbb#",
232".##############.", 232".##############.",
233"................"}; 233"................"};
234 234
235static const char* const general_data[] = { 235static const char* const general_data[] = {
236"14 14 98 2", 236"14 14 98 2",
237"Qt c None", 237"Qt c None",
238".k c #000000", 238".k c #000000",
239"#x c #080808", 239"#x c #080808",
240"#F c #101008", 240"#F c #101008",
241"#q c #101010", 241"#q c #101010",
242"#i c #101410", 242"#i c #101410",
243"## c #101810", 243"## c #101810",
244".m c #181818", 244".m c #181818",
245".3 c #181c18", 245".3 c #181c18",
246".I c #182018", 246".I c #182018",
247".T c #202420", 247".T c #202420",
248"#D c #202820", 248"#D c #202820",
249"#y c #292c29", 249"#y c #292c29",
250".c c #293029", 250".c c #293029",
251".d c #313031", 251".d c #313031",
252"#E c #313429", 252"#E c #313429",
253"#r c #313831", 253"#r c #313831",
254".j c #393c31", 254".j c #393c31",
255"#j c #394039", 255"#j c #394039",
256"#C c #414841", 256"#C c #414841",
257".w c #4a554a", 257".w c #4a554a",
258".a c #4a594a", 258".a c #4a594a",
259".# c #525052", 259".# c #525052",
260".l c #52594a", 260".l c #52594a",
261"#f c #525952", 261"#f c #525952",
262"#v c #525d52", 262"#v c #525d52",
263".O c #5a4c4a", 263".O c #5a4c4a",
264".9 c #5a595a", 264".9 c #5a595a",
265".A c #5a5d52", 265".A c #5a5d52",
266".B c #624c52", 266".B c #624c52",
267".0 c #625552", 267".0 c #625552",
268"#o c #626562", 268"#o c #626562",
269".R c #626962", 269".R c #626962",
270"#. c #626d5a", 270"#. c #626d5a",
271"#p c #626d62", 271"#p c #626d62",
272".2 c #627162", 272".2 c #627162",
273"#h c #6a6d62", 273"#h c #6a6d62",
274"#z c #6a7562", 274"#z c #6a7562",
275"#w c #6a756a", 275"#w c #6a756a",
276".C c #73656a", 276".C c #73656a",
277".P c #73696a", 277".P c #73696a",
278"#a c #737d6a", 278"#a c #737d6a",
279".U c #738573", 279".U c #738573",
280".E c #7b817b", 280".E c #7b817b",
281"#B c #7b857b", 281"#B c #7b857b",
282"#s c #7b897b", 282"#s c #7b897b",
283"#n c #7b917b", 283"#n c #7b917b",
284".b c #838d83", 284".b c #838d83",
285".7 c #839583", 285".7 c #839583",
286".n c #8b7d7b", 286".n c #8b7d7b",
287"#g c #8b8583", 287"#g c #8b8583",
288".g c #8b858b", 288".g c #8b858b",
289".r c #8b898b", 289".r c #8b898b",
290".s c #8b8d8b", 290".s c #8b8d8b",
291".i c #8b9183", 291".i c #8b9183",
292".8 c #8b918b", 292".8 c #8b918b",
293"#A c #8b9d8b", 293"#A c #8b9d8b",
294".S c #8ba183", 294".S c #8ba183",
295".Z c #94918b", 295".Z c #94918b",
296".N c #949994", 296".N c #949994",
297".F c #949d94", 297".F c #949d94",
298".x c #94a18b", 298".x c #94a18b",
299".v c #94a194", 299".v c #94a194",
300".Y c #94aa94", 300".Y c #94aa94",
301".h c #9c999c", 301".h c #9c999c",
302".Q c #9ca19c", 302".Q c #9ca19c",
303"#u c #9ca59c", 303"#u c #9ca59c",
304".H c #9caa9c", 304".H c #9caa9c",
305"#e c #9cb29c", 305"#e c #9cb29c",
306"#m c #a4b29c", 306"#m c #a4b29c",
307"#t c #a4b2a4", 307"#t c #a4b2a4",
308".M c #a4b69c", 308".M c #a4b69c",
309"#l c #a4b6a4", 309"#l c #a4b6a4",
310".z c #a4baa4", 310".z c #a4baa4",
311".f c #aca5ac", 311".f c #aca5ac",
312".q c #acaaac", 312".q c #acaaac",
313"#d c #acbeac", 313"#d c #acbeac",
314".6 c #acc2ac", 314".6 c #acc2ac",
315".o c #b4b2b4", 315".o c #b4b2b4",
316".t c #b4beb4", 316".t c #b4beb4",
317"#k c #b4c2ac", 317"#k c #b4c2ac",
318".5 c #b4cab4", 318".5 c #b4cab4",
319".D c #bdb6bd", 319".D c #bdb6bd",
320".G c #bdc6b4", 320".G c #bdc6b4",
321"#c c #bdceb4", 321"#c c #bdceb4",
322".X c #bdd2bd", 322".X c #bdd2bd",
323".4 c #bdd6bd", 323".4 c #bdd6bd",
324".1 c #c5bec5", 324".1 c #c5bec5",
325".e c #c5c2c5", 325".e c #c5c2c5",
326".u c #c5cac5", 326".u c #c5cac5",
327"#b c #c5d6c5", 327"#b c #c5d6c5",
328".J c #c5dec5", 328".J c #c5dec5",
329".p c #cdcacd", 329".p c #cdcacd",
330".W c #cddecd", 330".W c #cddecd",
331".L c #cde2cd", 331".L c #cde2cd",
332".K c #d5eacd", 332".K c #d5eacd",
333".V c #d5ead5", 333".V c #d5ead5",
334".y c #d5eed5", 334".y c #d5eed5",
335"QtQtQtQtQtQtQtQtQtQtQtQtQtQt", 335"QtQtQtQtQtQtQtQtQtQtQtQtQtQt",
336"QtQtQt.#.a.b.cQtQtQtQtQtQtQt", 336"QtQtQt.#.a.b.cQtQtQtQtQtQtQt",
337"QtQt.d.e.f.g.h.i.c.j.dQt.kQt", 337"QtQt.d.e.f.g.h.i.c.j.dQt.kQt",
338".a.l.m.n.o.p.q.r.s.t.u.v.wQt", 338".a.l.m.n.o.p.q.r.s.t.u.v.wQt",
339".x.y.z.A.B.C.D.p.q.E.F.G.H.I", 339".x.y.z.A.B.C.D.p.q.E.F.G.H.I",
340".I.J.K.L.M.N.O.P.o.p.Q.R.S.T", 340".I.J.K.L.M.N.O.P.o.p.Q.R.S.T",
341"Qt.U.V.L.W.X.Y.Z.0.P.1.s.2.3", 341"Qt.U.V.L.W.X.Y.Z.0.P.1.s.2.3",
342"Qt.3.X.W.4.X.5.6.7.8.9.s#.##", 342"Qt.3.X.W.4.X.5.6.7.8.9.s#.##",
343"QtQt#a.X#b#c.5.6#d#e#f#g#h#i", 343"QtQt#a.X#b#c.5.6#d#e#f#g#h#i",
344"QtQtQt#j.7#k.6#d#l#m#n#o#p#q", 344"QtQtQt#j.7#k.6#d#l#m#n#o#p#q",
345"QtQtQtQt.k#r#s#m#t.H#u#v#w#x", 345"QtQtQtQt.k#r#s#m#t.H#u#v#w#x",
346"QtQtQtQtQtQt.k#y#z.v#A#B#C#x", 346"QtQtQtQtQtQt.k#y#z.v#A#B#C#x",
347"QtQtQtQtQtQtQtQt.k#D.w#s#E.k", 347"QtQtQtQtQtQtQtQt.k#D.w#s#E.k",
348"QtQtQtQtQtQtQtQtQtQtQt#x#FQt"}; 348"QtQtQtQtQtQtQtQtQtQtQt#x#FQt"};
349 349
350// exit ZSafe and clear the clipboard for security reasons 350// exit ZSafe and clear the clipboard for security reasons
351 void ZSafe::exitZs (int ec) 351 void ZSafe::exitZs (int ec)
352 { 352 {
353 QClipboard *cb = QApplication::clipboard(); 353 QClipboard *cb = QApplication::clipboard();
354 cb->clear(); 354 cb->clear();
355 355
356 exit (ec); 356 exit (ec);
357 } 357 }
358 358
359 359
360// save the configuration into the file 360// save the configuration into the file
361 void ZSafe::saveConf () 361 void ZSafe::saveConf ()
362 { 362 {
363 if (conf) 363 if (conf)
364 { 364 {
365 delete conf; 365 delete conf;
366 366
367#ifdef DESKTOP 367#ifdef DESKTOP
368#ifndef Q_WS_WIN 368#ifndef Q_WS_WIN
369 conf = new QSettings(); 369 conf = new QSettings();
370 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); 370 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath());
371#else 371#else
372 conf = new QSettings (cfgFile); 372 conf = new QSettings (cfgFile);
373 conf->insertSearchPath (QSettings::Unix, cfgFile); 373 conf->insertSearchPath (QSettings::Unix, cfgFile);
374#endif 374#endif
375#else 375#else
376 conf = new Config (cfgFile, Config::File); 376 conf = new Config (cfgFile, Config::File);
377 conf->setGroup ("zsafePrefs"); 377 conf->setGroup ("zsafePrefs");
378#endif 378#endif
379 } 379 }
380 } 380 }
381 381
382 382
383/* 383/*
384 * Constructs a ZSafe which is a child of 'parent', with the 384 * Constructs a ZSafe which is a child of 'parent', with the
385 * name 'name' and widget flags set to 'f' 385 * name 'name' and widget flags set to 'f'
386 * 386 *
387 * The dialog will by default be modeless, unless you set 'modal' to 387 * The dialog will by default be modeless, unless you set 'modal' to
388 * TRUE to construct a modal dialog. 388 * TRUE to construct a modal dialog.
389 */ 389 */
390ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl ) 390ZSafe::ZSafe( QWidget* parent, const char* name, bool modal, WFlags fl )
391 : QDialog( parent, name, modal, fl ), 391 : QDialog( parent, name, modal, fl ),
392 Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l) 392 Edit(0l), Delete(0l), Find(0l), New(0l), ListView(0l)
393{ 393{
394 IsCut = false; 394 IsCut = false;
395 IsCopy = false; 395 IsCopy = false;
396 modified = false; 396 modified = false;
397 showpwd = false; 397 showpwd = false;
398 398
399 // set the config file 399 // set the config file
400 cfgFile=QDir::homeDirPath(); 400 cfgFile=QDir::homeDirPath();
401 cfgFile += "/.zsafe.cfg"; 401 cfgFile += "/.zsafe.cfg";
402 // set the icon path 402 // set the icon path
403#ifdef NO_OPIE 403#ifdef NO_OPIE
404 QString qpedir ((const char *)getenv("QPEDIR")); 404 QString qpedir ((const char *)getenv("QPEDIR"));
405#else 405#else
406 QString qpedir ((const char *)getenv("OPIEDIR")); 406 QString qpedir ((const char *)getenv("OPIEDIR"));
407#endif 407#endif
408 408
409#ifdef DESKTOP 409#ifdef DESKTOP
410 iconPath = QDir::homeDirPath() + "/pics/"; 410 iconPath = QDir::homeDirPath() + "/pics/";
411#else 411#else
412 if (qpedir.isEmpty()) 412 if (qpedir.isEmpty())
413 iconPath = "/home/QtPalmtop/pics/"; 413 iconPath = "/home/QtPalmtop/pics/";
414 else 414 else
415 iconPath = qpedir + "/pics/"; 415 iconPath = qpedir + "/pics/";
416#endif 416#endif
417 417
418 // create a zsafe configuration object 418 // create a zsafe configuration object
419#ifdef DESKTOP 419#ifdef DESKTOP
420#ifndef Q_WS_WIN 420#ifndef Q_WS_WIN
421 conf = new QSettings (); 421 conf = new QSettings ();
422 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath()); 422 conf->insertSearchPath (QSettings::Unix, QDir::homeDirPath());
423#else 423#else
424 conf = new QSettings (cfgFile); 424 conf = new QSettings (cfgFile);
425 conf->insertSearchPath (QSettings::Unix, cfgFile); 425 conf->insertSearchPath (QSettings::Unix, cfgFile);
426#endif 426#endif
427#else 427#else
428 conf = new Config (cfgFile, Config::File); 428 conf = new Config (cfgFile, Config::File);
429 conf->setGroup ("zsafePrefs"); 429 conf->setGroup ("zsafePrefs");
430#endif 430#endif
431#ifdef DESKTOP 431#ifdef DESKTOP
432// #ifndef Q_WS_WIN 432// #ifndef Q_WS_WIN
433 expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false); 433 expandTree = conf->readBoolEntry(APP_KEY+"expandTree", false);
434// #endif 434// #endif
435#else 435#else
436 expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0); 436 expandTree = conf->readNumEntry(APP_KEY+"expandTree", 0);
437#endif 437#endif
438#ifndef DESKTOP 438#ifndef DESKTOP
439 conf->setGroup ("zsafe"); 439 conf->setGroup ("zsafe");
440#endif 440#endif
441 441
442 QPixmap copy_img((const char**) copy_xpm); 442 QPixmap copy_img((const char**) copy_xpm);
443 QPixmap cut_img((const char**) cut_xpm); 443 QPixmap cut_img((const char**) cut_xpm);
444 QPixmap edit_img((const char**) edit_xpm); 444 QPixmap edit_img((const char**) edit_xpm);
445 QPixmap editdelete_img((const char**) editdelete_xpm); 445 QPixmap editdelete_img((const char**) editdelete_xpm);
446 QPixmap find_img((const char**) find_xpm); 446 QPixmap find_img((const char**) find_xpm);
447 QPixmap folder_open_img((const char**) folder_open_xpm); 447 QPixmap folder_open_img((const char**) folder_open_xpm);
448 QPixmap help_icon_img((const char**) help_icon_xpm); 448 QPixmap help_icon_img((const char**) help_icon_xpm);
449 QPixmap new_img((const char**) new_xpm); 449 QPixmap new_img((const char**) new_xpm);
450 QPixmap paste_img((const char**) paste_xpm); 450 QPixmap paste_img((const char**) paste_xpm);
451 QPixmap quit_icon_img((const char**) quit_icon_xpm); 451 QPixmap quit_icon_img((const char**) quit_icon_xpm);
452 QPixmap save_img((const char**) save_xpm); 452 QPixmap save_img((const char**) save_xpm);
453 QPixmap trash_img((const char**) trash_xpm); 453 QPixmap trash_img((const char**) trash_xpm);
454 QPixmap expand_img((const char**) expand_xpm); 454 QPixmap expand_img((const char**) expand_xpm);
455 QPixmap export_img((const char**) export_xpm); 455 QPixmap export_img((const char**) export_xpm);
456 QPixmap import_img((const char**) import_xpm); 456 QPixmap import_img((const char**) import_xpm);
457 457
458 QPixmap bank_cards( ( const char** ) bank_cards_data ); 458 QPixmap bank_cards( ( const char** ) bank_cards_data );
459 QPixmap passwords( ( const char** ) passwords_data ); 459 QPixmap passwords( ( const char** ) passwords_data );
460 QPixmap software( ( const char** ) software_data ); 460 QPixmap software( ( const char** ) software_data );
461 QPixmap general( ( const char** ) general_data ); 461 QPixmap general( ( const char** ) general_data );
462 QPixmap image0( ( const char** ) zsafe_xpm ); 462 QPixmap image0( ( const char** ) zsafe_xpm );
463 if ( !name ) 463 if ( !name )
464 setName( "ZSafe" ); 464 setName( "ZSafe" );
465 465
466#ifdef DESKTOP 466#ifdef DESKTOP
467#ifdef Q_WS_WIN 467#ifdef Q_WS_WIN
468 setGeometry(100, 150, DeskW, DeskH-30 ); 468 setGeometry(100, 150, DeskW, DeskH-30 );
469#else 469#else
470 resize( DeskW, DeskH-30 ); 470 resize( DeskW, DeskH-30 );
471#endif 471#endif
472 472
473#else 473#else
474 474
475#ifdef JPATCH_HDE 475#ifdef JPATCH_HDE
476 int DeskS; 476 int DeskS;
477 if(DeskW > DeskH) 477 if(DeskW > DeskH)
478 { 478 {
479 DeskS = DeskW; 479 DeskS = DeskW;
480 } 480 }
481 else 481 else
482 { 482 {
483 DeskS = DeskH; 483 DeskS = DeskH;
484 } 484 }
485 resize( DeskW, DeskH ); 485 resize( DeskW, DeskH );
486 setMinimumSize( QSize( DeskS, DeskS ) ); 486 setMinimumSize( QSize( DeskS, DeskS ) );
487 setMaximumSize( QSize( DeskS, DeskS ) ); 487 setMaximumSize( QSize( DeskS, DeskS ) );
488#else 488#else
489 resize( DeskW, DeskH-30 ); 489 resize( DeskW, DeskH-30 );
490#endif 490#endif
491 491
492#endif 492#endif
493 setCaption( tr( "ZSafe" ) ); 493 setCaption( tr( "ZSafe" ) );
494 QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe"; 494 QString zsafeAppDirPath = QDir::homeDirPath() + "/Documents/application/zsafe";
495 filename = conf->readEntry(APP_KEY+"document"); 495 filename = conf->readEntry(APP_KEY+"document");
496 if ( !QFileInfo(filename).exists() || !QDir(zsafeAppDirPath).exists() ) 496 if ( !QFileInfo(filename).exists() || !QDir(zsafeAppDirPath).exists() )
497 { 497 {
498 // check if the directory application exists, if not 498 // check if the directory application exists, if not
499 // create it 499 // create it
500// #ifndef Q_WS_WIN 500// #ifndef Q_WS_WIN
501 // QString d1("Documents/application"); 501 // QString d1("Documents/application");
502// #else 502// #else
503 QString d1(QDir::homeDirPath() + "/Documents/application"); 503 QString d1(QDir::homeDirPath() + "/Documents/application");
504// #endif 504// #endif
505 QDir pd1(d1); 505 QDir pd1(d1);
506 if (!pd1.exists()) 506 if (!pd1.exists())
507 { 507 {
508 QDir pd2(QDir::homeDirPath() + "/Documents"); 508 QDir pd2(QDir::homeDirPath() + "/Documents");
509 if (!pd2.exists()) { 509 if (!pd2.exists()) {
510 QDir pd3(QDir::homeDirPath()); 510 QDir pd3(QDir::homeDirPath());
511 if (!pd3.mkdir("Documents", FALSE)) { 511 if (!pd3.mkdir("Documents", FALSE)) {
512 } 512 }
513 } 513 }
514 514
515 if (!pd2.mkdir("application", FALSE)) 515 if (!pd2.mkdir("application", FALSE))
516 { 516 {
517 QMessageBox::critical( 0, tr("ZSafe"), 517 QMessageBox::critical( 0, tr("ZSafe"),
518#ifdef JPATCH_HDE 518#ifdef JPATCH_HDE
519 tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>")); 519 tr("<P>Can't create directory ..."+d1+"</P><P>ZSafe will now exit.</P>"));
520#else 520#else
521 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1)); 521 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d1));
522#endif 522#endif
523 exitZs (1); 523 exitZs (1);
524 } 524 }
525 } 525 }
526// #ifndef Q_WS_WIN 526// #ifndef Q_WS_WIN
527 // QString d2("Documents/application/zsafe"); 527 // QString d2("Documents/application/zsafe");
528// #else 528// #else
529 QString d2(QDir::homeDirPath() + "/Documents/application/zsafe"); 529 QString d2(QDir::homeDirPath() + "/Documents/application/zsafe");
530// #endif 530// #endif
531 QDir pd2(d2); 531 QDir pd2(d2);
532 if (!pd2.exists()) 532 if (!pd2.exists())
533 { 533 {
534 if (!pd1.mkdir("zsafe", FALSE)) 534 if (!pd1.mkdir("zsafe", FALSE))
535 { 535 {
536 QMessageBox::critical( 0, tr("ZSafe"), 536 QMessageBox::critical( 0, tr("ZSafe"),
537#ifdef JPATCH_HDE 537#ifdef JPATCH_HDE
538 tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P")); 538 tr("<P>Can't create directory ...//Documents/application/zsafe</P><P>ZSafe will now exit.</P"));
539#else 539#else
540 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2)); 540 tr("<P>Can't create directory %1</P><P>ZSafe will now exit.</P>").arg(d2));
541#endif 541#endif
542 exitZs (1); 542 exitZs (1);
543 } 543 }
544 } 544 }
545 545
546 filename = zsafeAppDirPath + "/passwords.zsf"; 546 filename = zsafeAppDirPath + "/passwords.zsf";
547 547
548 // save the current filename to the config file 548 // save the current filename to the config file
549 conf->writeEntry(APP_KEY+"document", filename); 549 conf->writeEntry(APP_KEY+"document", filename);
550 saveConf(); 550 saveConf();
551 } 551 }
552 //if (filename == "INVALIDPWD") 552 //if (filename == "INVALIDPWD")
553 //filename = ""; 553 //filename = "";
554 554
555 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 555 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
556#ifdef Q_WS_WIN 556#ifdef Q_WS_WIN
557 this->setCaption("Qt ZSafe: " + ti); 557 this->setCaption("Qt ZSafe: " + ti);
558#else 558#else
559 this->setCaption("ZSafe: " + ti); 559 this->setCaption("ZSafe: " + ti);
560#endif 560#endif
561 561
562 selectedItem = NULL; 562 selectedItem = NULL;
563 lastSearchedCategory = NULL; 563 lastSearchedCategory = NULL;
564 lastSearchedItem = NULL; 564 lastSearchedItem = NULL;
565 lastSearchedName = ""; 565 lastSearchedName = "";
566 lastSearchedUsername = ""; 566 lastSearchedUsername = "";
567 lastSearchedComment = ""; 567 lastSearchedComment = "";
568 568
569 infoForm = new InfoForm(this, "show_info", TRUE); 569 infoForm = new InfoForm(this, "show_info", TRUE);
570 categoryDialog = NULL; 570 categoryDialog = NULL;
571 infoForm->setIcon( image0); 571 infoForm->setIcon( image0);
572 572
573 // add a menu bar 573 // add a menu bar
574 QMenuBar *menu = new QMenuBar( this ); 574 QMenuBar *menu = new QMenuBar( this );
575 575
576 // add file menu 576 // add file menu
577 // QPopupMenu *file = new QPopupMenu( this ); 577 // QPopupMenu *file = new QPopupMenu( this );
578 file = new QPopupMenu( this ); 578 file = new QPopupMenu( this );
579 579
580// #ifdef DESKTOP 580// #ifdef DESKTOP
581 file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) ); 581 file->insertItem( new_img, tr("&New document"), this, SLOT(newDocument()) );
582 file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) ); 582 file->insertItem( folder_open_img, tr("&Open document"), this, SLOT(loadDocument()) );
583 file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) ); 583 file->insertItem( save_img, tr("&Save document as .."), this, SLOT(saveDocumentAs()) );
584 file->insertSeparator(); 584 file->insertSeparator();
585// #endif 585// #endif
586 586
587 file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) ); 587 file->insertItem( save_img, tr("&Save document"), this, SLOT(saveDocumentWithoutPwd()) );
588 file->insertItem( save_img, tr("S&ave document with new Password"), this, 588 file->insertItem( save_img, tr("S&ave document with new Password"), this,
589 SLOT(saveDocumentWithPwd()) ); 589 SLOT(saveDocumentWithPwd()) );
590 file->insertSeparator(); 590 file->insertSeparator();
591 file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) ); 591 file->insertItem( export_img, tr("&Export text file"), this, SLOT(writeAllEntries()) );
592 file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) ); 592 file->insertItem( import_img, tr("&Import text file"), this, SLOT(readAllEntries()) );
593 file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) ); 593 file->insertItem( trash_img, tr("&Remove text file"), this, SLOT(removeAsciiFile()) );
594 file->insertSeparator(); 594 file->insertSeparator();
595 file->insertItem( expand_img, tr("&Open entries expanded"), this, 595 file->insertItem( expand_img, tr("&Open entries expanded"), this,
596 SLOT(setExpandFlag()), 0, 'o'); 596 SLOT(setExpandFlag()), 0, 'o');
597 file->setItemChecked('o', expandTree); 597 file->setItemChecked('o', expandTree);
598 file->insertSeparator(); 598 file->insertSeparator();
599 file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) ); 599 file->insertItem( quit_icon_img, tr("E&xit"), this, SLOT(quitMe()) );
600 menu->insertItem( tr("&File"), file ); 600 menu->insertItem( tr("&File"), file );
601 601
602 QPopupMenu *cat = new QPopupMenu( this ); 602 QPopupMenu *cat = new QPopupMenu( this );
603 cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) ); 603 cat->insertItem( new_img, tr("&New"), this, SLOT(addCategory()) );
604 cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) ); 604 cat->insertItem( edit_img, tr("&Edit"), this, SLOT(editCategory()) );
605 cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) ); 605 cat->insertItem( trash_img, tr("&Delete"), this, SLOT(delCategory()) );
606 menu->insertItem( tr("&Category"), cat ); 606 menu->insertItem( tr("&Category"), cat );
607 607
608 QPopupMenu *it = new QPopupMenu( this ); 608 QPopupMenu *it = new QPopupMenu( this );
609 it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) ); 609 it->insertItem( cut_img, tr("&Cut"), this, SLOT(cutItem()) );
610 it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) ); 610 it->insertItem( copy_img, tr("C&opy"), this, SLOT(copyItem()) );
611 it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) ); 611 it->insertItem( paste_img, tr("&Paste"), this, SLOT(pasteItem()) );
612 it->insertSeparator(); 612 it->insertSeparator();
613 it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) ); 613 it->insertItem( new_img, tr("&New"), this, SLOT(newPwd()) );
614 it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) ); 614 it->insertItem( edit_img, tr("&Edit"), this, SLOT(editPwd()) );
615 it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) ); 615 it->insertItem( trash_img, tr("&Delete"), this, SLOT(deletePwd()) );
616 it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) ); 616 it->insertItem( find_img, tr("&Search"), this, SLOT(findPwd()) );
617 menu->insertItem( tr("&Entry"), it ); 617 menu->insertItem( tr("&Entry"), it );
618 618
619 QPopupMenu *help = new QPopupMenu( this ); 619 QPopupMenu *help = new QPopupMenu( this );
620 help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) ); 620 help->insertItem( help_icon_img, tr("&About"), this, SLOT(about()) );
621 menu->insertItem( tr("&Help"), help ); 621 menu->insertItem( tr("&Help"), help );
622 622
623 // toolbar icons 623 // toolbar icons
624 624
625 New = new QToolButton( menu, "New" ); 625 New = new QToolButton( menu, "New" );
626 New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) ); 626 New->setGeometry( QRect( DeskW-84, 2, 20, 20 ) );
627 New->setMouseTracking( TRUE ); 627 New->setMouseTracking( TRUE );
628 New->setText( "" ); 628 New->setText( "" );
629 New->setPixmap( new_img ); 629 New->setPixmap( new_img );
630 QToolTip::add( New, tr( "New entry" ) ); 630 QToolTip::add( New, tr( "New entry" ) );
631 631
632 Edit = new QToolButton( menu, "Edit" ); 632 Edit = new QToolButton( menu, "Edit" );
633 Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) ); 633 Edit->setGeometry( QRect( DeskW-64, 2, 20, 20 ) );
634 Edit->setText( "" ); 634 Edit->setText( "" );
635 Edit->setPixmap( edit_img ); 635 Edit->setPixmap( edit_img );
636 QToolTip::add( Edit, tr( "Edit category or entry" ) ); 636 QToolTip::add( Edit, tr( "Edit category or entry" ) );
637 637
638 Delete = new QToolButton( menu, "Delete" ); 638 Delete = new QToolButton( menu, "Delete" );
639 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); 639 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
640 Delete->setText( "" ); 640 Delete->setText( "" );
641 Delete->setPixmap( trash_img ); 641 Delete->setPixmap( trash_img );
642 QToolTip::add( Delete, tr( "Delete category or entry" ) ); 642 QToolTip::add( Delete, tr( "Delete category or entry" ) );
643 643
644 Find = new QToolButton( menu, "Find" ); 644 Find = new QToolButton( menu, "Find" );
645 Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) ); 645 Find->setGeometry( QRect( DeskW-24, 2, 20, 20 ) );
646 Find->setText( "" ); 646 Find->setText( "" );
647 Find->setPixmap( find_img ); 647 Find->setPixmap( find_img );
648 QToolTip::add( Find, tr( "Find entry" ) ); 648 QToolTip::add( Find, tr( "Find entry" ) );
649 649
650/* 650/*
651 QBoxLayout * h = new QHBoxLayout( this ); 651 QBoxLayout * h = new QHBoxLayout( this );
652 h->addWidget (menu); 652 h->addWidget (menu);
653 h->addWidget (New); 653 h->addWidget (New);
654 h->addWidget (Edit); 654 h->addWidget (Edit);
655 h->addWidget (Delete); 655 h->addWidget (Delete);
656 h->addWidget (Find); 656 h->addWidget (Find);
657*/ 657*/
658 658
659 ListView = new ZListView( this, "ListView" ); 659 ListView = new ZListView( this, "ListView" );
660 ListView->addColumn( tr( "Name" ) ); 660 ListView->addColumn( tr( "Name" ) );
661 ListView->addColumn( tr( "Field 2" ) ); 661 ListView->addColumn( tr( "Field 2" ) );
662 ListView->addColumn( tr( "Field 3" ) ); 662 ListView->addColumn( tr( "Field 3" ) );
663 ListView->addColumn( tr( "Comment" ) ); 663 ListView->addColumn( tr( "Comment" ) );
664 ListView->addColumn( tr( "Field 4" ) ); 664 ListView->addColumn( tr( "Field 4" ) );
665 ListView->addColumn( tr( "Field 5" ) ); 665 ListView->addColumn( tr( "Field 5" ) );
666 ListView->setAllColumnsShowFocus(TRUE); 666 ListView->setAllColumnsShowFocus(TRUE);
667 667
668#ifdef DESKTOP 668#ifdef DESKTOP
669 // ListView->setResizePolicy(QScrollView::AutoOneFit); 669 // ListView->setResizePolicy(QScrollView::AutoOneFit);
670 // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) ); 670 // ListView->setGeometry( QRect( 0, 22, this->width(), this->height() - 30 ) );
671#else 671#else
672 ListView->setResizePolicy(QScrollView::AutoOneFit); 672 ListView->setResizePolicy(QScrollView::AutoOneFit);
673 // ListView->setGeometry( QRect( 0, 22, 673 // ListView->setGeometry( QRect( 0, 22,
674 // this->width(), this->height() - 30 ) ); 674 // this->width(), this->height() - 30 ) );
675 // ListView->setMaximumSize( QSize( 440, 290 ) ); 675 // ListView->setMaximumSize( QSize( 440, 290 ) );
676#endif 676#endif
677 // ListView->setVScrollBarMode( QListView::Auto ); 677 // ListView->setVScrollBarMode( QListView::Auto );
678 678
679 QBoxLayout * l = new QVBoxLayout( this ); 679 QBoxLayout * l = new QVBoxLayout( this );
680 l->addWidget (menu); 680 l->addWidget (menu);
681 l->addWidget (ListView); 681 l->addWidget (ListView);
682 682
683#ifndef DESKTOP 683#ifndef DESKTOP
684 // start a timer (100 ms) to load the default document 684 // start a timer (100 ms) to load the default document
685 docuTimer.start( 100, true ); 685 docuTimer.start( 100, true );
686 connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) ); 686 connect( &docuTimer, SIGNAL(timeout()), SLOT( slotLoadDocu() ) );
687 raiseFlag = true; 687 raiseFlag = true;
688 connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) ); 688 connect( &raiseTimer, SIGNAL(timeout()), SLOT( slotRaiseTimer() ) );
689#else 689#else
690 // open the default document 690 // open the default document
691 openDocument(filename); 691 openDocument(filename);
692#endif 692#endif
693 693
694 // signals and slots connections for QTollButton 694 // signals and slots connections for QTollButton
695 connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) ); 695 connect( New, SIGNAL( clicked() ), this, SLOT( newPwd() ) );
696 connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) ); 696 connect( Edit, SIGNAL( clicked() ), this, SLOT( editPwd() ) );
697 connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) ); 697 connect( Delete, SIGNAL( clicked() ), this, SLOT( deletePwd() ) );
698 connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) ); 698 connect( Find, SIGNAL( clicked() ), this, SLOT( findPwd() ) );
699 // signals and slots connections for QListView 699 // signals and slots connections for QListView
700 connect( ListView, SIGNAL( selectionChanged(QListViewItem*) ), 700 connect( ListView, SIGNAL( selectionChanged(QListViewItem*) ),
701 this, SLOT( listViewSelected(QListViewItem*) ) ); 701 this, SLOT( listViewSelected(QListViewItem*) ) );
702 connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ), 702 connect( ListView, SIGNAL( doubleClicked(QListViewItem*) ),
703 this, SLOT( showInfo(QListViewItem*) ) ); 703 this, SLOT( showInfo(QListViewItem*) ) );
704 connect( ListView, SIGNAL( returnPressed(QListViewItem*) ), 704 connect( ListView, SIGNAL( returnPressed(QListViewItem*) ),
705 this, SLOT( showInfo(QListViewItem*) ) ); 705 this, SLOT( showInfo(QListViewItem*) ) );
706 706
707 #ifndef DESKTOP 707 #ifndef DESKTOP
708 QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold); 708 QPEApplication::setStylusOperation( ListView->viewport(),QPEApplication::RightOnHold);
709#endif 709#endif
710 connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), 710 connect( ListView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)),
711 this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); 711 this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) );
712 712
713 this->setIcon( image0); 713 this->setIcon( image0);
714#ifdef Q_WS_WIN 714#ifdef Q_WS_WIN
715 ListView->setSelected( ListView->firstChild() , true); 715 ListView->setSelected( ListView->firstChild() , true);
716 ListView->setSelected( ListView->firstChild() , false); 716 ListView->setSelected( ListView->firstChild() , false);
717#endif 717#endif
718} 718}
719 719
720const QColor *ZSafe::evenRowColor = &Qt::white; 720const QColor *ZSafe::evenRowColor = &Qt::white;
721// const QColor *ZSafe::oddRowColor = &Qt::lightGray; 721// const QColor *ZSafe::oddRowColor = &Qt::lightGray;
722const QColor *ZSafe::oddRowColor = new QColor(216,240,255); 722const QColor *ZSafe::oddRowColor = new QColor(216,240,255);
723 723
724/* 724/*
725 * Destroys the object and frees any allocated resources 725 * Destroys the object and frees any allocated resources
726 */ 726 */
727ZSafe::~ZSafe() 727ZSafe::~ZSafe()
728{ 728{
729 // no need to delete child widgets, Qt does it all for us 729 // no need to delete child widgets, Qt does it all for us
730 quitMe(); 730 quitMe();
731} 731}
732 732
733// load the default document 733// load the default document
734void ZSafe::slotLoadDocu() 734void ZSafe::slotLoadDocu()
735{ 735{
736 openDocument (filename); 736 openDocument (filename);
737} 737}
738 738
739void ZSafe::deletePwd() 739void ZSafe::deletePwd()
740{ 740{
741 741
742 if (!selectedItem) 742 if (!selectedItem)
743 return; 743 return;
744 if (!isCategory(selectedItem)) 744 if (!isCategory(selectedItem))
745 { 745 {
746 switch( QMessageBox::information( this, tr("ZSafe"), 746 switch( QMessageBox::information( this, tr("ZSafe"),
747 tr("Do you want to delete?"), 747 tr("Do you want to delete?"),
748 tr("&Delete"), tr("D&on't Delete"), 748 tr("&Delete"), tr("D&on't Delete"),
749 0 // Enter == button 0 749 0 // Enter == button 0
750 ) ) { // Escape == button 2 750 ) ) { // Escape == button 2
751 case 0: // Delete clicked, Alt-S or Enter pressed. 751 case 0: // Delete clicked, Alt-S or Enter pressed.
752 // Delete 752 // Delete
753 modified = true; 753 modified = true;
754 selectedItem->parent()->takeItem(selectedItem); 754 selectedItem->parent()->takeItem(selectedItem);
755 selectedItem = NULL; 755 selectedItem = NULL;
756 break; 756 break;
757 case 1: // Don't delete 757 case 1: // Don't delete
758 break; 758 break;
759 } 759 }
760 } 760 }
761 else 761 else
762 { 762 {
763 delCategory(); 763 delCategory();
764 } 764 }
765} 765}
766 766
767void ZSafe::editPwd() 767void ZSafe::editPwd()
768{ 768{
769 if (!selectedItem) 769 if (!selectedItem)
770 return; 770 return;
771 if (!isCategory(selectedItem)) 771 if (!isCategory(selectedItem))
772 { 772 {
773 // open the 'New Entry' dialog 773 // open the 'New Entry' dialog
774 NewDialog *dialog = new NewDialog(this, "edit_entry", TRUE); 774 NewDialog *dialog = new NewDialog(this, "edit_entry", TRUE);
775#ifdef Q_WS_WIN 775#ifdef Q_WS_WIN
776 dialog->setCaption ("Qt " + tr("Edit Entry")); 776 dialog->setCaption ("Qt " + tr("Edit Entry"));
777 dialog->setGeometry(200, 250, 220, 310 ); 777 dialog->setGeometry(200, 250, 220, 310 );
778#endif 778#endif
779 779
780 // set the labels 780 // set the labels
781 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 781 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
782 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 782 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
783 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 783 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
784 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 784 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
785 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); 785 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
786 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); 786 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
787 787
788 // set the fields 788 // set the fields
789 dialog->NameField->setText(selectedItem->text (0)); 789 dialog->NameField->setText(selectedItem->text (0));
790 dialog->UsernameField->setText(selectedItem->text (1)); 790 dialog->UsernameField->setText(selectedItem->text (1));
791 dialog->PasswordField->setText(selectedItem->text (2)); 791 dialog->PasswordField->setText(selectedItem->text (2));
792 QString comment = selectedItem->text (3); 792 QString comment = selectedItem->text (3);
793 comment.replace (QRegExp("<br>"), "\n"); 793 comment.replace (QRegExp("<br>"), "\n");
794 dialog->Field5->setText(selectedItem->text (4)); 794 dialog->Field5->setText(selectedItem->text (4));
795 dialog->Field6->setText(selectedItem->text (5)); 795 dialog->Field6->setText(selectedItem->text (5));
796 dialog->CommentField->insertLine(comment); 796 dialog->CommentField->insertLine(comment);
797 dialog->CommentField->setCursorPosition(0,0); 797 dialog->CommentField->setCursorPosition(0,0);
798 798
799#ifdef Q_WS_QWS 799#ifdef Q_WS_QWS
800 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); 800 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog );
801#endif 801#endif
802 802
803#ifdef DESKTOP 803#ifdef DESKTOP
804#ifndef Q_QW_QWIN 804#ifndef Q_QW_QWIN
805 dialog->show(); 805 dialog->show();
806#endif 806#endif
807#else 807#else
808 dialog->showMaximized(); 808 dialog->showMaximized();
809#endif 809#endif
810#ifdef DESKTOP 810#ifdef DESKTOP
811 int result = dialog->exec(); 811 int result = dialog->exec();
812 result = QDialog::Accepted; 812 result = QDialog::Accepted;
813#endif 813#endif
814 if (result == Accepted) 814 if (result == Accepted)
815 { 815 {
816 modified = true; 816 modified = true;
817 // edit the selected item 817 // edit the selected item
818 QString name = dialog->NameField->text(); 818 QString name = dialog->NameField->text();
819 selectedItem->setText (0, tr (name)); 819 selectedItem->setText (0, tr (name));
820 QString user = dialog->UsernameField->text(); 820 QString user = dialog->UsernameField->text();
821 selectedItem->setText (1, tr (user)); 821 selectedItem->setText (1, tr (user));
822 QString pwd = dialog->PasswordField->text(); 822 QString pwd = dialog->PasswordField->text();
823 selectedItem->setText (2, tr (pwd)); 823 selectedItem->setText (2, tr (pwd));
824 QString comment = dialog->CommentField->text(); 824 QString comment = dialog->CommentField->text();
825 comment.replace (QRegExp("\n"), "<br>"); 825 comment.replace (QRegExp("\n"), "<br>");
826 selectedItem->setText (3, tr (comment)); 826 selectedItem->setText (3, tr (comment));
827 QString f5 = dialog->Field5->text(); 827 QString f5 = dialog->Field5->text();
828 selectedItem->setText (4, tr (f5)); 828 selectedItem->setText (4, tr (f5));
829 QString f6 = dialog->Field6->text(); 829 QString f6 = dialog->Field6->text();
830 selectedItem->setText (5, tr (f6)); 830 selectedItem->setText (5, tr (f6));
831 } 831 }
832 832
833 delete dialog; 833 delete dialog;
834 } 834 }
835 else 835 else
836 { 836 {
837 editCategory(); 837 editCategory();
838 } 838 }
839} 839}
840 840
841void ZSafe::newPwd() 841void ZSafe::newPwd()
842{ 842{
843 if (!selectedItem) 843 if (!selectedItem)
844 return; 844 return;
845 qWarning("new item"); 845 qWarning("new item");
846 if (!isCategory(selectedItem)) 846 if (!isCategory(selectedItem))
847 selectedItem = selectedItem->parent(); 847 selectedItem = selectedItem->parent();
848 848
849 if (isCategory(selectedItem)) 849 if (isCategory(selectedItem))
850 { 850 {
851 QString cat = selectedItem->text(0); 851 QString cat = selectedItem->text(0);
852 qWarning(cat); 852 qWarning(cat);
853 // open the 'New Entry' dialog 853 // open the 'New Entry' dialog
854 NewDialog *dialog = new NewDialog(this, "new_entry", TRUE); 854 NewDialog *dialog = new NewDialog(this, "new_entry", TRUE);
855#ifdef Q_WS_WIN 855#ifdef Q_WS_WIN
856 dialog->setCaption ("Qt " + tr("New Entry")); 856 dialog->setCaption ("Qt " + tr("New Entry"));
857 dialog->setGeometry(200, 250, 220, 310 ); 857 dialog->setGeometry(200, 250, 220, 310 );
858#endif 858#endif
859 // set the labels 859 // set the labels
860 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 860 dialog->Name->setText(getFieldLabel (selectedItem, "1", tr("Name")));
861 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 861 dialog->Username->setText(getFieldLabel (selectedItem, "2", tr("Username")));
862 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 862 dialog->Password->setText(getFieldLabel (selectedItem, "3", tr("Password")));
863 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 863 dialog->Comment->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
864 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4"))); 864 dialog->Field5Label->setText(getFieldLabel (selectedItem,"5", tr("Field 4")));
865 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5"))); 865 dialog->Field6Label->setText(getFieldLabel (selectedItem,"6", tr("Field 5")));
866retype: 866retype:
867 867
868#ifdef Q_WS_QWS 868#ifdef Q_WS_QWS
869 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog ); 869 DialogCode result = (DialogCode) QPEApplication::execDialog( dialog );
870#endif 870#endif
871 871
872#ifdef DESKTOP 872#ifdef DESKTOP
873#ifndef Q_QW_QWIN 873#ifndef Q_QW_QWIN
874 dialog->show(); 874 dialog->show();
875#endif 875#endif
876#else 876#else
877 dialog->showMaximized(); 877 dialog->showMaximized();
878#endif 878#endif
879#ifdef DESKTOP 879#ifdef DESKTOP
880 int result = dialog->exec(); 880 int result = dialog->exec();
881 result = QDialog::Accepted; 881 result = QDialog::Accepted;
882#endif 882#endif
883 883
884 if (result == Accepted) 884 if (result == Accepted)
885 { 885 {
886 886
887 QString name = dialog->NameField->text(); 887 QString name = dialog->NameField->text();
888 if (cat == name) 888 if (cat == name)
889 { 889 {
890 QMessageBox::critical( 0, tr("ZSafe"), 890 QMessageBox::critical( 0, tr("ZSafe"),
891 tr("Entry name must be different\nfrom the category name.") ); 891 tr("Entry name must be different\nfrom the category name.") );
892 goto retype; // it's not a good programming style :-) 892 goto retype; // it's not a good programming style :-)
893 } 893 }
894 894
895 modified = true; 895 modified = true;
896 // add the new item 896 // add the new item
897 QListViewItem *i = new ShadedListItem (0, selectedItem); 897 QListViewItem *i = new ShadedListItem (0, selectedItem);
898 i->setOpen (TRUE); 898 i->setOpen (TRUE);
899 899
900 i->setText (0, tr (name)); 900 i->setText (0, tr (name));
901 QString user = dialog->UsernameField->text(); 901 QString user = dialog->UsernameField->text();
902 i->setText (1, tr (user)); 902 i->setText (1, tr (user));
903 QString pwd = dialog->PasswordField->text(); 903 QString pwd = dialog->PasswordField->text();
904 i->setText (2, tr (pwd)); 904 i->setText (2, tr (pwd));
905 QString comment = dialog->CommentField->text(); 905 QString comment = dialog->CommentField->text();
906 comment.replace (QRegExp("\n"), "<br>"); 906 comment.replace (QRegExp("\n"), "<br>");
907 i->setText (3, tr (comment)); 907 i->setText (3, tr (comment));
908 QString f5 = dialog->Field5->text(); 908 QString f5 = dialog->Field5->text();
909 i->setText (4, tr (f5)); 909 i->setText (4, tr (f5));
910 QString f6 = dialog->Field6->text(); 910 QString f6 = dialog->Field6->text();
911 i->setText (5, tr (f6)); 911 i->setText (5, tr (f6));
912 } 912 }
913 913
914 delete dialog; 914 delete dialog;
915 } 915 }
916} 916}
917 917
918void ZSafe::findPwd() 918void ZSafe::findPwd()
919{ 919{
920 920
921 // open the 'Search' dialog 921 // open the 'Search' dialog
922 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE); 922 SearchDialog *dialog = new SearchDialog(this, tr("Search"), TRUE);
923#ifdef Q_WS_WIN 923#ifdef Q_WS_WIN
924 dialog->setCaption ("Qt " + tr("Search")); 924 dialog->setCaption ("Qt " + tr("Search"));
925#endif 925#endif
926 926
927#ifdef DESKTOP 927#ifdef DESKTOP
928#endif 928#endif
929 if (lastSearchedName) 929 if (lastSearchedName)
930 dialog->NameField->setText(lastSearchedName); 930 dialog->NameField->setText(lastSearchedName);
931 else 931 else
932 dialog->NameField->setText(""); 932 dialog->NameField->setText("");
933 if (lastSearchedUsername) 933 if (lastSearchedUsername)
934 dialog->UsernameField->setText(lastSearchedUsername); 934 dialog->UsernameField->setText(lastSearchedUsername);
935 else 935 else
936 dialog->UsernameField->setText(""); 936 dialog->UsernameField->setText("");
937 if (lastSearchedComment) 937 if (lastSearchedComment)
938 dialog->CommentField->setText(lastSearchedComment); 938 dialog->CommentField->setText(lastSearchedComment);
939 else 939 else
940 dialog->CommentField->setText(""); 940 dialog->CommentField->setText("");
941 DialogCode result = (DialogCode) dialog->exec(); 941 DialogCode result = (DialogCode) dialog->exec();
942#ifdef DESKTOP 942#ifdef DESKTOP
943 result = Accepted; 943 result = Accepted;
944#endif 944#endif
945 945
946 QString name; 946 QString name;
947 QString username; 947 QString username;
948 QString comment; 948 QString comment;
949 if (result == Accepted) 949 if (result == Accepted)
950 { 950 {
951 name = dialog->NameField->text(); 951 name = dialog->NameField->text();
952 username = dialog->UsernameField->text(); 952 username = dialog->UsernameField->text();
953 comment = dialog->CommentField->text(); 953 comment = dialog->CommentField->text();
954#ifndef NO_OPIE 954#ifndef NO_OPIE
955 owarn << name << oendl; 955 owarn << name << oendl;
956#else 956#else
957 qWarning (name); 957 qWarning (name);
958#endif 958#endif
959 } 959 }
960 else 960 else
961 { 961 {
962 delete dialog; 962 delete dialog;
963 return; 963 return;
964 } 964 }
965 965
966 if (!name.isEmpty() && name != lastSearchedName || 966 if (!name.isEmpty() && name != lastSearchedName ||
967 lastSearchedName.isEmpty() && !name.isEmpty()) 967 lastSearchedName.isEmpty() && !name.isEmpty())
968 { 968 {
969 // set search at the beginning if a new name is given 969 // set search at the beginning if a new name is given
970 lastSearchedCategory = NULL; 970 lastSearchedCategory = NULL;
971 lastSearchedItem = NULL; 971 lastSearchedItem = NULL;
972 } 972 }
973 lastSearchedName = name; 973 lastSearchedName = name;
974 if (!username.isEmpty() && username != lastSearchedUsername || 974 if (!username.isEmpty() && username != lastSearchedUsername ||
975 lastSearchedUsername.isEmpty() && !username.isEmpty()) 975 lastSearchedUsername.isEmpty() && !username.isEmpty())
976 { 976 {
977 // set search at the beginning if a new name is given 977 // set search at the beginning if a new name is given
978 lastSearchedCategory = NULL; 978 lastSearchedCategory = NULL;
979 lastSearchedItem = NULL; 979 lastSearchedItem = NULL;
980 } 980 }
981 lastSearchedUsername = username; 981 lastSearchedUsername = username;
982 if (!comment.isEmpty() && comment != lastSearchedComment || 982 if (!comment.isEmpty() && comment != lastSearchedComment ||
983 lastSearchedComment.isEmpty() && !comment.isEmpty()) 983 lastSearchedComment.isEmpty() && !comment.isEmpty())
984 { 984 {
985 // set search at the beginning if a new name is given 985 // set search at the beginning if a new name is given
986 lastSearchedCategory = NULL; 986 lastSearchedCategory = NULL;
987 lastSearchedItem = NULL; 987 lastSearchedItem = NULL;
988 } 988 }
989 lastSearchedComment = comment; 989 lastSearchedComment = comment;
990 990
991 ListView->clearSelection(); 991 ListView->clearSelection();
992 992
993 bool found=FALSE; 993 bool found=FALSE;
994 // step through all categories 994 // step through all categories
995 QListViewItem *i; 995 QListViewItem *i;
996 if (lastSearchedCategory) 996 if (lastSearchedCategory)
997 i = lastSearchedCategory; 997 i = lastSearchedCategory;
998 else 998 else
999 i = ListView->firstChild(); 999 i = ListView->firstChild();
1000 for (; 1000 for (;
1001 i != NULL; 1001 i != NULL;
1002 i = i->nextSibling()) 1002 i = i->nextSibling())
1003 { 1003 {
1004#ifndef NO_OPIE 1004#ifndef NO_OPIE
1005 owarn << i->text(0) << oendl; 1005 owarn << i->text(0) << oendl;
1006#endif 1006#endif
1007 i->setSelected(FALSE); 1007 i->setSelected(FALSE);
1008 1008
1009 // step through all subitems 1009 // step through all subitems
1010 QListViewItem *si; 1010 QListViewItem *si;
1011 if (lastSearchedItem) 1011 if (lastSearchedItem)
1012 si = lastSearchedItem; 1012 si = lastSearchedItem;
1013 else 1013 else
1014 si = i->firstChild(); 1014 si = i->firstChild();
1015 // for (si = i->firstChild(); 1015 // for (si = i->firstChild();
1016 for (; 1016 for (;
1017 si != NULL; 1017 si != NULL;
1018 si = si->nextSibling()) 1018 si = si->nextSibling())
1019 { 1019 {
1020#ifndef NO_OPIE 1020#ifndef NO_OPIE
1021 owarn << si->text(0) << oendl; 1021 owarn << si->text(0) << oendl;
1022#else 1022#else
1023 qWarning (si->text(0)); 1023 qWarning (si->text(0));
1024#endif 1024#endif
1025 if (si->isSelected()) 1025 if (si->isSelected())
1026 si->setSelected(FALSE); 1026 si->setSelected(FALSE);
1027 // ListView->repaintItem(si); 1027 // ListView->repaintItem(si);
1028 1028
1029 bool n=TRUE; 1029 bool n=TRUE;
1030 bool u=TRUE; 1030 bool u=TRUE;
1031 bool c=TRUE; 1031 bool c=TRUE;
1032 if (!name.isEmpty()) 1032 if (!name.isEmpty())
1033 n = (si->text(0)).contains (name, FALSE); 1033 n = (si->text(0)).contains (name, FALSE);
1034 if (!username.isEmpty()) 1034 if (!username.isEmpty())
1035 u = (si->text(1)).contains (username, FALSE); 1035 u = (si->text(1)).contains (username, FALSE);
1036 if (!comment.isEmpty()) 1036 if (!comment.isEmpty())
1037 c = (si->text(3)).contains (comment, FALSE); 1037 c = (si->text(3)).contains (comment, FALSE);
1038 1038
1039 if ((n && u && c ) && !found) 1039 if ((n && u && c ) && !found)
1040 { 1040 {
1041#ifndef NO_OPIE 1041#ifndef NO_OPIE
1042 owarn << "Found" << oendl; 1042 owarn << "Found" << oendl;
1043#else 1043#else
1044 qWarning ("Found"); 1044 qWarning ("Found");
1045#endif 1045#endif
1046 selectedItem = si; 1046 selectedItem = si;
1047 si->setSelected(TRUE); 1047 si->setSelected(TRUE);
1048 ListView->setCurrentItem(si); 1048 ListView->setCurrentItem(si);
1049 ListView->ensureItemVisible(si); 1049 ListView->ensureItemVisible(si);
1050 ListView->triggerUpdate(); 1050 ListView->triggerUpdate();
1051 1051
1052 lastSearchedCategory = i; 1052 lastSearchedCategory = i;
1053 // set to the next item 1053 // set to the next item
1054 lastSearchedItem = si->nextSibling(); 1054 lastSearchedItem = si->nextSibling();
1055 if (!lastSearchedItem) 1055 if (!lastSearchedItem)
1056 { 1056 {
1057 // no next item within category -> set next category 1057 // no next item within category -> set next category
1058 lastSearchedCategory = i->nextSibling(); 1058 lastSearchedCategory = i->nextSibling();
1059 if (!lastSearchedCategory) 1059 if (!lastSearchedCategory)
1060 lastSearchedItem = NULL; // END 1060 lastSearchedItem = NULL; // END
1061 } 1061 }
1062 1062
1063 found = TRUE; 1063 found = TRUE;
1064 delete dialog; 1064 delete dialog;
1065 update(); 1065 update();
1066 return; 1066 return;
1067 } 1067 }
1068 } 1068 }
1069 lastSearchedCategory = i->nextSibling(); 1069 lastSearchedCategory = i->nextSibling();
1070 lastSearchedItem = NULL; 1070 lastSearchedItem = NULL;
1071 } 1071 }
1072 lastSearchedCategory = NULL; 1072 lastSearchedCategory = NULL;
1073 lastSearchedItem = NULL; 1073 lastSearchedItem = NULL;
1074 delete dialog; 1074 delete dialog;
1075 update(); 1075 update();
1076 QMessageBox::information( this, tr("ZSafe"), 1076 QMessageBox::information( this, tr("ZSafe"),
1077 tr("Entry not found"), tr("&OK"), 0); 1077 tr("Entry not found"), tr("&OK"), 0);
1078 1078
1079} 1079}
1080 1080
1081QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def) 1081QString ZSafe::getFieldLabel (QListViewItem *_item, QString field, QString def)
1082{ 1082{
1083 QString category; 1083 QString category;
1084 if (_item) 1084 if (_item)
1085 { 1085 {
1086 if (isCategory(_item)) 1086 if (isCategory(_item))
1087 { 1087 {
1088 category = _item->text(0); 1088 category = _item->text(0);
1089 } 1089 }
1090 else 1090 else
1091 { 1091 {
1092 QListViewItem *cat = _item->parent(); 1092 QListViewItem *cat = _item->parent();
1093 category = cat->text(0); 1093 category = cat->text(0);
1094 } 1094 }
1095 } 1095 }
1096 else 1096 else
1097 { 1097 {
1098 return def; 1098 return def;
1099 } 1099 }
1100 1100
1101 QString app_key = APP_KEY; 1101 QString app_key = APP_KEY;
1102#ifndef DESKTOP 1102#ifndef DESKTOP
1103#ifndef Q_WS_WIN 1103#ifndef Q_WS_WIN
1104 conf->setGroup ("fieldDefs"); 1104 conf->setGroup ("fieldDefs");
1105#endif 1105#endif
1106#else 1106#else
1107#ifndef Q_WS_WIN 1107#ifndef Q_WS_WIN
1108 app_key += "/fieldDefs/"; 1108 app_key += "/fieldDefs/";
1109#endif 1109#endif
1110#endif 1110#endif
1111// #ifndef Q_WS_WIN 1111// #ifndef Q_WS_WIN
1112 QString label = conf->readEntry(app_key+category+"-field"+field,def); 1112 QString label = conf->readEntry(app_key+category+"-field"+field,def);
1113// #else 1113// #else
1114// QString label(def); 1114// QString label(def);
1115// #endif 1115// #endif
1116 1116
1117#ifndef DESKTOP 1117#ifndef DESKTOP
1118 conf->setGroup ("zsafe"); 1118 conf->setGroup ("zsafe");
1119#endif 1119#endif
1120 return label; 1120 return label;
1121} 1121}
1122 1122
1123QString ZSafe::getFieldLabel (QString category, QString field, QString def) 1123QString ZSafe::getFieldLabel (QString category, QString field, QString def)
1124{ 1124{
1125 QString app_key = APP_KEY; 1125 QString app_key = APP_KEY;
1126#ifndef DESKTOP 1126#ifndef DESKTOP
1127 conf->setGroup ("fieldDefs"); 1127 conf->setGroup ("fieldDefs");
1128#else 1128#else
1129#ifndef Q_WS_WIN 1129#ifndef Q_WS_WIN
1130 app_key += "/fieldDefs/"; 1130 app_key += "/fieldDefs/";
1131#endif 1131#endif
1132#endif 1132#endif
1133// #ifndef Q_WS_WIN 1133// #ifndef Q_WS_WIN
1134 QString label = conf->readEntry(app_key+category+"-field"+field, 1134 QString label = conf->readEntry(app_key+category+"-field"+field,
1135 def); 1135 def);
1136// #else 1136// #else
1137 // QString label(def); 1137 // QString label(def);
1138// #endif 1138// #endif
1139#ifndef DESKTOP 1139#ifndef DESKTOP
1140 conf->setGroup ("zsafe"); 1140 conf->setGroup ("zsafe");
1141#endif 1141#endif
1142 return label; 1142 return label;
1143} 1143}
1144 1144
1145void ZSafe::showInfo( QListViewItem *_item) 1145void ZSafe::showInfo( QListViewItem *_item)
1146{ 1146{
1147 if (!_item) 1147 if (!_item)
1148 return; 1148 return;
1149 if (selectedItem != NULL) 1149 if (selectedItem != NULL)
1150 selectedItem->setSelected(FALSE); 1150 selectedItem->setSelected(FALSE);
1151 1151
1152 selectedItem = _item; 1152 selectedItem = _item;
1153 selectedItem->setSelected(TRUE); 1153 selectedItem->setSelected(TRUE);
1154 1154
1155 if (!isCategory(_item)) 1155 if (!isCategory(_item))
1156 { 1156 {
1157/* 1157/*
1158 QString label=selectedItem->text(0); 1158 QString label=selectedItem->text(0);
1159 label+="\n"; 1159 label+="\n";
1160 label+=selectedItem->text(1); 1160 label+=selectedItem->text(1);
1161 label+="\n"; 1161 label+="\n";
1162 label+=selectedItem->text(2); 1162 label+=selectedItem->text(2);
1163 label+="\n"; 1163 label+="\n";
1164 label+=selectedItem->text(3); 1164 label+=selectedItem->text(3);
1165*/ 1165*/
1166 1166
1167 QString text; 1167 QString text;
1168 QString entry; 1168 QString entry;
1169 1169
1170 text = "<html><body><div align=""center""><u><b>"; 1170 text = "<html><body><div align=""center""><u><b>";
1171 text += selectedItem->text(0); 1171 text += selectedItem->text(0);
1172 text += "</b></u><br></div><br>"; 1172 text += "</b></u><br></div><br>";
1173 1173
1174 entry = selectedItem->text(1); 1174 entry = selectedItem->text(1);
1175 if (!entry.isEmpty() && entry.compare(" ")) 1175 if (!entry.isEmpty() && entry.compare(" "))
1176 { 1176 {
1177 text += "<u><b>"; 1177 text += "<u><b>";
1178 text += getFieldLabel (selectedItem, "2", tr("Username")); 1178 text += getFieldLabel (selectedItem, "2", tr("Username"));
1179 text += ":<br></b></u><blockquote>"; 1179 text += ":<br></b></u><blockquote>";
1180 text += entry; 1180 text += entry;
1181 text += "</blockquote>"; 1181 text += "</blockquote>";
1182 // text += "<br>"; 1182 // text += "<br>";
1183 } 1183 }
1184 1184
1185 entry = selectedItem->text(2); 1185 entry = selectedItem->text(2);
1186 if (!entry.isEmpty() && entry.compare(" ")) 1186 if (!entry.isEmpty() && entry.compare(" "))
1187 { 1187 {
1188 text += "<u><b>"; 1188 text += "<u><b>";
1189 text += getFieldLabel (selectedItem, "3", tr("Password")); 1189 text += getFieldLabel (selectedItem, "3", tr("Password"));
1190 text += ":<br> </b></u><blockquote>"; 1190 text += ":<br> </b></u><blockquote>";
1191 text += entry; 1191 text += entry;
1192 text += "</blockquote>"; 1192 text += "</blockquote>";
1193 // text += "<br>"; 1193 // text += "<br>";
1194 } 1194 }
1195 1195
1196 entry = selectedItem->text(4); 1196 entry = selectedItem->text(4);
1197 if (!entry.isEmpty() && entry.compare(" ")) 1197 if (!entry.isEmpty() && entry.compare(" "))
1198 { 1198 {
1199 text += "<u><b>"; 1199 text += "<u><b>";
1200 text += getFieldLabel (selectedItem, "5", tr("Field 4")); 1200 text += getFieldLabel (selectedItem, "5", tr("Field 4"));
1201 text += ":<br> </b></u><blockquote>"; 1201 text += ":<br> </b></u><blockquote>";
1202 text += entry; 1202 text += entry;
1203 text += "</blockquote>"; 1203 text += "</blockquote>";
1204 // text += "<br>"; 1204 // text += "<br>";
1205 } 1205 }
1206 1206
1207 entry = selectedItem->text(5); 1207 entry = selectedItem->text(5);
1208 if (!entry.isEmpty() && entry.compare(" ")) 1208 if (!entry.isEmpty() && entry.compare(" "))
1209 { 1209 {
1210 text += "<u><b>"; 1210 text += "<u><b>";
1211 text += getFieldLabel (selectedItem, "6", tr("Field 5")); 1211 text += getFieldLabel (selectedItem, "6", tr("Field 5"));
1212 text += ":<br> </b></u><blockquote>"; 1212 text += ":<br> </b></u><blockquote>";
1213 text += entry; 1213 text += entry;
1214 text += "</blockquote>"; 1214 text += "</blockquote>";
1215 // text += "<br>"; 1215 // text += "<br>";
1216 } 1216 }
1217 1217
1218 entry = selectedItem->text(3); 1218 entry = selectedItem->text(3);
1219 if (!entry.isEmpty() && entry.compare(" ")) 1219 if (!entry.isEmpty() && entry.compare(" "))
1220 { 1220 {
1221 text += "<u><b>"; 1221 text += "<u><b>";
1222 text += getFieldLabel (selectedItem, "4", tr("Comment")); 1222 text += getFieldLabel (selectedItem, "4", tr("Comment"));
1223 text += ":<br> </b></u>"; 1223 text += ":<br> </b></u>";
1224 QString comment = selectedItem->text(3); 1224 QString comment = selectedItem->text(3);
1225 comment.replace (QRegExp("\n"), "<br>"); 1225 comment.replace (QRegExp("\n"), "<br>");
1226 text += comment; 1226 text += comment;
1227 // text += "<br>"; 1227 // text += "<br>";
1228 } 1228 }
1229 1229
1230 text += "</body></html>"; 1230 text += "</body></html>";
1231 1231
1232 infoForm->InfoText->setText(text); 1232 infoForm->InfoText->setText(text);
1233// infoForm->hide(); 1233// infoForm->hide();
1234#ifdef Q_WS_QWS 1234#ifdef Q_WS_QWS
1235 QPEApplication::showDialog( infoForm ); 1235 QPEApplication::showDialog( infoForm );
1236#endif 1236#endif
1237 1237
1238#ifdef DESKTOP 1238#ifdef DESKTOP
1239 infoForm->show(); 1239 infoForm->show();
1240 #endif 1240 #endif
1241 } 1241 }
1242} 1242}
1243 1243
1244void ZSafe::listViewSelected( QListViewItem *_item) 1244void ZSafe::listViewSelected( QListViewItem *_item)
1245{ 1245{
1246 if (!_item) 1246 if (!_item)
1247 return; 1247 return;
1248 if (selectedItem != NULL) 1248 if (selectedItem != NULL)
1249 selectedItem->setSelected(FALSE); 1249 selectedItem->setSelected(FALSE);
1250 1250
1251 selectedItem = _item; 1251 selectedItem = _item;
1252 1252
1253#ifndef DESKTOP 1253#ifndef DESKTOP
1254 // set the column text dependent on the selected item 1254 // set the column text dependent on the selected item
1255 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1255 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1256 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1256 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1257 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1257 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1258 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1258 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1259 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1259 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1260 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1260 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1261#endif 1261#endif
1262#ifdef Q_WS_WIN 1262#ifdef Q_WS_WIN
1263 // set the column text dependent on the selected item 1263 // set the column text dependent on the selected item
1264 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name"))); 1264 ListView->setColumnText(0, getFieldLabel (selectedItem, "1", tr("Name")));
1265 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2"))); 1265 ListView->setColumnText(1, getFieldLabel (selectedItem, "2", tr("Field 2")));
1266 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3"))); 1266 ListView->setColumnText(2, getFieldLabel (selectedItem, "3", tr("Field 3")));
1267 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment"))); 1267 ListView->setColumnText(3, getFieldLabel (selectedItem, "4", tr("Comment")));
1268 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4"))); 1268 ListView->setColumnText(4, getFieldLabel (selectedItem, "5", tr("Field 4")));
1269 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5"))); 1269 ListView->setColumnText(5, getFieldLabel (selectedItem, "6", tr("Field 5")));
1270#endif 1270#endif
1271 1271
1272} 1272}
1273 1273
1274bool ZSafe::isCategory(QListViewItem *_item) 1274bool ZSafe::isCategory(QListViewItem *_item)
1275{ 1275{
1276 if (_item == NULL) 1276 if (_item == NULL)
1277 return FALSE; 1277 return FALSE;
1278 1278
1279 QString categoryName = _item->text (0); 1279 QString categoryName = _item->text (0);
1280 if (categories.find (categoryName)) 1280 if (categories.find (categoryName))
1281 return TRUE; 1281 return TRUE;
1282 else 1282 else
1283 return FALSE; 1283 return FALSE;
1284} 1284}
1285 1285
1286void ZSafe::removeAsciiFile() 1286void ZSafe::removeAsciiFile()
1287{ 1287{
1288 // QString fn = filename + ".txt"; 1288 // QString fn = filename + ".txt";
1289 // open the file dialog 1289 // open the file dialog
1290#ifndef DESKTOP 1290#ifndef DESKTOP
1291#ifndef NO_OPIE 1291#ifndef NO_OPIE
1292 QMap<QString, QStringList> mimeTypes; 1292 QMap<QString, QStringList> mimeTypes;
1293 mimeTypes.insert(tr("All"), QStringList() ); 1293 mimeTypes.insert(tr("All"), QStringList() );
1294 mimeTypes.insert(tr("Text"), "text/*" ); 1294 mimeTypes.insert(tr("Text"), "text/*" );
1295 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1295 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1296 QDir::homeDirPath() + "/Documents/application/zsafe", 1296 QDir::homeDirPath() + "/Documents/application/zsafe",
1297 QString::null, 1297 QString::null,
1298 mimeTypes, 1298 mimeTypes,
1299 this, 1299 this,
1300 tr ("Remove text file")); 1300 tr ("Remove text file"));
1301#else 1301#else
1302 QString fn = ScQtFileEdit::getOpenFileName(this, 1302 QString fn = ScQtFileEdit::getOpenFileName(this,
1303 tr ("Remove text file"), 1303 tr ("Remove text file"),
1304 QDir::homeDirPath() + "/Documents/application/zsafe", 1304 QDir::homeDirPath() + "/Documents/application/zsafe",
1305 "*.txt"); 1305 "*.txt");
1306#endif 1306#endif
1307#else 1307#else
1308 QString fn = QFileDialog::getOpenFileName( 1308 QString fn = QFileDialog::getOpenFileName(
1309 QDir::homeDirPath() + "/Documents/application/zsafe", 1309 QDir::homeDirPath() + "/Documents/application/zsafe",
1310 "ZSafe (*.txt)", 1310 "ZSafe (*.txt)",
1311 this, 1311 this,
1312 "ZSafe File Dialog" 1312 "ZSafe File Dialog"
1313 "Choose a text file" ); 1313 "Choose a text file" );
1314#endif 1314#endif
1315 1315
1316 if (fn && fn.length() > 0 ) 1316 if (fn && fn.length() > 0 )
1317 { 1317 {
1318 QFile f( fn ); 1318 QFile f( fn );
1319 if ( !f.remove() ) 1319 if ( !f.remove() )
1320 { 1320 {
1321#ifndef NO_OPIE 1321#ifndef NO_OPIE
1322 owarn << "Could not remove file " << fn << oendl; 1322 owarn << "Could not remove file " << fn << oendl;
1323#else 1323#else
1324 qWarning( QString("Could not remove file %1").arg(fn),2000 ); 1324 qWarning( QString("Could not remove file %1").arg(fn),2000 );
1325#endif 1325#endif
1326 QMessageBox::critical( 0, tr("ZSafe"), 1326 QMessageBox::critical( 0, tr("ZSafe"),
1327 tr("Could not remove text file.") ); 1327 tr("Could not remove text file.") );
1328 return; 1328 return;
1329 } 1329 }
1330 } 1330 }
1331} 1331}
1332 1332
1333void ZSafe::writeAllEntries() 1333void ZSafe::writeAllEntries()
1334{ 1334{
1335 if (filename.isEmpty()) 1335 if (filename.isEmpty())
1336 { 1336 {
1337 QMessageBox::critical( 0, tr("ZSafe"), 1337 QMessageBox::critical( 0, tr("ZSafe"),
1338 tr("No document defined.\nYou have to create a new document")); 1338 tr("No document defined.\nYou have to create a new document"));
1339 return; 1339 return;
1340 } 1340 }
1341 1341
1342 // open the file dialog 1342 // open the file dialog
1343 QString fn = zsaveDialog(); 1343 QString fn = zsaveDialog();
1344 // open the new document 1344 // open the new document
1345 if (fn && fn.length() > 0 ) 1345 if (fn && fn.length() > 0 )
1346 { 1346 {
1347 QFile f( fn ); 1347 QFile f( fn );
1348 if ( !f.open( IO_WriteOnly ) ) { 1348 if ( !f.open( IO_WriteOnly ) ) {
1349#ifndef NO_OPIE 1349#ifndef NO_OPIE
1350 owarn << "Could not write to file " << fn << oendl; 1350 owarn << "Could not write to file " << fn << oendl;
1351#else 1351#else
1352 qWarning( QString("Could not write to file %1").arg(fn),2000 ); 1352 qWarning( QString("Could not write to file %1").arg(fn),2000 );
1353#endif 1353#endif
1354 QMessageBox::critical( 0, "ZSafe", 1354 QMessageBox::critical( 0, "ZSafe",
1355 QString("Could not export to text file.") ); 1355 QString("Could not export to text file.") );
1356 return; 1356 return;
1357 } 1357 }
1358 QTextStream t( &f ); 1358 QTextStream t( &f );
1359 1359
1360 QListViewItem *i; 1360 QListViewItem *i;
1361 // step through all categories 1361 // step through all categories
1362 for (i = ListView->firstChild(); 1362 for (i = ListView->firstChild();
1363 i != NULL; 1363 i != NULL;
1364 i = i->nextSibling()) 1364 i = i->nextSibling())
1365 { 1365 {
1366 // step through all subitems 1366 // step through all subitems
1367 QListViewItem *si; 1367 QListViewItem *si;
1368 for (si = i->firstChild(); 1368 for (si = i->firstChild();
1369 si != NULL; 1369 si != NULL;
1370 si = si->nextSibling()) 1370 si = si->nextSibling())
1371 { 1371 {
1372 QString oneEntry; 1372 QString oneEntry;
1373 oneEntry += "\""; 1373 oneEntry += "\"";
1374 oneEntry += i->text(0); 1374 oneEntry += i->text(0);
1375 oneEntry += "\";"; 1375 oneEntry += "\";";
1376 oneEntry += "\""; 1376 oneEntry += "\"";
1377 oneEntry += si->text(0); 1377 oneEntry += si->text(0);
1378 oneEntry += "\";"; 1378 oneEntry += "\";";
1379 oneEntry += "\""; 1379 oneEntry += "\"";
1380 oneEntry += si->text(1); 1380 oneEntry += si->text(1);
1381 oneEntry += "\";"; 1381 oneEntry += "\";";
1382 oneEntry += "\""; 1382 oneEntry += "\"";
1383 oneEntry += si->text(2); 1383 oneEntry += si->text(2);
1384 oneEntry += "\";"; 1384 oneEntry += "\";";
1385 oneEntry += "\""; 1385 oneEntry += "\"";
1386 QString comment = si->text(3); 1386 QString comment = si->text(3);
1387 comment.replace (QRegExp("\n"), "<br>"); 1387 comment.replace (QRegExp("\n"), "<br>");
1388 oneEntry += comment; 1388 oneEntry += comment;
1389 oneEntry += "\";"; 1389 oneEntry += "\";";
1390 oneEntry += "\""; 1390 oneEntry += "\"";
1391 oneEntry += si->text(4); 1391 oneEntry += si->text(4);
1392 oneEntry += "\";"; 1392 oneEntry += "\";";
1393 oneEntry += "\""; 1393 oneEntry += "\"";
1394 oneEntry += si->text(5); 1394 oneEntry += si->text(5);
1395 oneEntry += "\""; 1395 oneEntry += "\"";
1396 // owarn << oneEntry << oendl; 1396 // owarn << oneEntry << oendl;
1397 t << oneEntry << endl; 1397 t << oneEntry << endl;
1398 1398
1399 // owarn << si->text(0) << oendl; 1399 // owarn << si->text(0) << oendl;
1400 } 1400 }
1401 } 1401 }
1402 f.close(); 1402 f.close();
1403 } 1403 }
1404} 1404}
1405 1405
1406void ZSafe::readAllEntries() 1406void ZSafe::readAllEntries()
1407{ 1407{
1408 if (filename.isEmpty()) 1408 if (filename.isEmpty())
1409 { 1409 {
1410 QMessageBox::critical( 0, tr("ZSafe"), 1410 QMessageBox::critical( 0, tr("ZSafe"),
1411 tr("No document defined.\nYou have to create a new document")); 1411 tr("No document defined.\nYou have to create a new document"));
1412 return; 1412 return;
1413 } 1413 }
1414 1414
1415 // open the file dialog 1415 // open the file dialog
1416#ifndef DESKTOP 1416#ifndef DESKTOP
1417#ifndef NO_OPIE 1417#ifndef NO_OPIE
1418 QMap<QString, QStringList> mimeTypes; 1418 QMap<QString, QStringList> mimeTypes;
1419 mimeTypes.insert(tr("All"), QStringList() ); 1419 mimeTypes.insert(tr("All"), QStringList() );
1420 mimeTypes.insert(tr("Text"), "text/*" ); 1420 mimeTypes.insert(tr("Text"), "text/*" );
1421 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 1421 QString fn = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
1422 QDir::homeDirPath() + "/Documents/application/zsafe", 1422 QDir::homeDirPath() + "/Documents/application/zsafe",
1423 QString::null, 1423 QString::null,
1424 mimeTypes, 1424 mimeTypes,
1425 this, 1425 this,
1426 tr ("Import text file")); 1426 tr ("Import text file"));
1427#else 1427#else
1428 QString fn = ScQtFileEdit::getOpenFileName(this, 1428 QString fn = ScQtFileEdit::getOpenFileName(this,
1429 tr ("Import text file"), 1429 tr ("Import text file"),
1430 QDir::homeDirPath() + "/Documents/application/zsafe", 1430 QDir::homeDirPath() + "/Documents/application/zsafe",
1431 "*.txt"); 1431 "*.txt");
1432#endif 1432#endif
1433#else 1433#else
1434 QString fn = QFileDialog::getOpenFileName( 1434 QString fn = QFileDialog::getOpenFileName(
1435 QDir::homeDirPath() + "/Documents/application/zsafe", 1435 QDir::homeDirPath() + "/Documents/application/zsafe",
1436 "ZSafe (*.txt)", 1436 "ZSafe (*.txt)",
1437 this, 1437 this,
1438 "ZSafe File Dialog" 1438 "ZSafe File Dialog"
1439 "Choose a text file" ); 1439 "Choose a text file" );
1440#endif 1440#endif
1441 1441
1442 if (fn && fn.length() > 0 ) 1442 if (fn && fn.length() > 0 )
1443 { 1443 {
1444 QFile f( fn ); 1444 QFile f( fn );
1445 if ( !f.open( IO_ReadOnly ) ) 1445 if ( !f.open( IO_ReadOnly ) )
1446 { 1446 {
1447#ifndef NO_OPIE 1447#ifndef NO_OPIE
1448 owarn << "Could not read file " << fn << oendl; 1448 owarn << "Could not read file " << fn << oendl;
1449#else 1449#else
1450 qWarning( QString("Could not read file %1").arg(fn), 2000 ); 1450 qWarning( QString("Could not read file %1").arg(fn), 2000 );
1451#endif 1451#endif
1452 QMessageBox::critical( 0, "ZSafe", 1452 QMessageBox::critical( 0, "ZSafe",
1453 QString("Could not import text file.") ); 1453 QString("Could not import text file.") );
1454 return; 1454 return;
1455 } 1455 }
1456 1456
1457 modified = true; 1457 modified = true;
1458 1458
1459 // clear the password list 1459 // clear the password list
1460 selectedItem = NULL; 1460 selectedItem = NULL;
1461 QListViewItem *i; 1461 QListViewItem *i;
1462 // step through all categories 1462 // step through all categories
1463 for (i = ListView->firstChild(); 1463 for (i = ListView->firstChild();
1464 i != NULL; 1464 i != NULL;
1465 i = i->nextSibling()) 1465 i = i->nextSibling())
1466 { 1466 {
1467 // step through all subitems 1467 // step through all subitems
1468 QListViewItem *si; 1468 QListViewItem *si;
1469 for (si = i->firstChild(); 1469 for (si = i->firstChild();
1470 si != NULL; ) 1470 si != NULL; )
1471 // si = si->nextSibling()) 1471 // si = si->nextSibling())
1472 { 1472 {
1473 QListViewItem *_si = si; 1473 QListViewItem *_si = si;
1474 si = si->nextSibling(); 1474 si = si->nextSibling();
1475 i->takeItem(_si); // remove from view list 1475 i->takeItem(_si); // remove from view list
1476 if (_si) delete _si; 1476 if (_si) delete _si;
1477 } 1477 }
1478 } 1478 }
1479 1479
1480#ifndef NO_OPIE 1480#ifndef NO_OPIE
1481 owarn << "ReadAllEntries(): " << oendl; 1481 owarn << "ReadAllEntries(): " << oendl;
1482#else 1482#else
1483 qWarning ("ReadAllEntries(): "); 1483 qWarning ("ReadAllEntries(): ");
1484#endif 1484#endif
1485 1485
1486 QTextStream t(&f); 1486 QTextStream t(&f);
1487 while ( !t.eof() ) 1487 while ( !t.eof() )
1488 { 1488 {
1489 QString s = t.readLine(); 1489 QString s = t.readLine();
1490 s.replace (QRegExp("\";\""), "\"|\""); 1490 s.replace (QRegExp("\";\""), "\"|\"");
1491 // char buffer[1024]; 1491 // char buffer[1024];
1492#ifndef Q_WS_WIN 1492#ifndef Q_WS_WIN
1493 char buffer[s.length()+1]; 1493 char buffer[s.length()+1];
1494#else 1494#else
1495 char buffer[4048]; 1495 char buffer[4048];
1496#endif 1496#endif
1497 1497
1498 1498
1499 /* modify QString -> QCString::utf8 */ 1499 /* modify QString -> QCString::utf8 */
1500 1500
1501 strcpy (buffer, s.utf8()); 1501 strcpy (buffer, s.utf8());
1502 1502
1503 QString name; 1503 QString name;
1504 QString user; 1504 QString user;
1505 QString password; 1505 QString password;
1506 QString comment; 1506 QString comment;
1507 QString field5=""; 1507 QString field5="";
1508 QString field6=""; 1508 QString field6="";
1509 1509
1510 // separete the entries 1510 // separete the entries
1511 char *i = strtok (buffer, "|"); 1511 char *i = strtok (buffer, "|");
1512 QString category(QString::fromUtf8(&i[1])); 1512 QString category(QString::fromUtf8(&i[1]));
1513 category.truncate(category.length() -1); 1513 category.truncate(category.length() -1);
1514 1514
1515 int idx=0; 1515 int idx=0;
1516 while ((i = strtok (NULL, "|")) != NULL) 1516 while ((i = strtok (NULL, "|")) != NULL)
1517 { 1517 {
1518 switch (idx) 1518 switch (idx)
1519 { 1519 {
1520 case 0: 1520 case 0:
1521 name = QString::fromUtf8(&i[1]); 1521 name = QString::fromUtf8(&i[1]);
1522 name.truncate(name.length() -1); 1522 name.truncate(name.length() -1);
1523 // name 1523 // name
1524 break; 1524 break;
1525 case 1: 1525 case 1:
1526 // user 1526 // user
1527 user = QString::fromUtf8(&i[1]); 1527 user = QString::fromUtf8(&i[1]);
1528 user.truncate(user.length() -1); 1528 user.truncate(user.length() -1);
1529 break; 1529 break;
1530 case 2: 1530 case 2:
1531 // password 1531 // password
1532 password = QString::fromUtf8(&i[1]); 1532 password = QString::fromUtf8(&i[1]);
1533 password.truncate(password.length() -1); 1533 password.truncate(password.length() -1);
1534 break; 1534 break;
1535 case 3: 1535 case 3:
1536 // comment 1536 // comment
1537 comment = QString::fromUtf8(&i[1]); 1537 comment = QString::fromUtf8(&i[1]);
1538 comment.truncate(comment.length() -1); 1538 comment.truncate(comment.length() -1);
1539 break; 1539 break;
1540 case 4: 1540 case 4:
1541 // field5 1541 // field5
1542 field5 = QString::fromUtf8(&i[1]); 1542 field5 = QString::fromUtf8(&i[1]);
1543 field5.truncate(field5.length() -1); 1543 field5.truncate(field5.length() -1);
1544 break; 1544 break;
1545 case 5: 1545 case 5:
1546 // field6 1546 // field6
1547 field6 = QString::fromUtf8(&i[1]); 1547 field6 = QString::fromUtf8(&i[1]);
1548 field6.truncate(field6.length() -1); 1548 field6.truncate(field6.length() -1);
1549 break; 1549 break;
1550 } 1550 }
1551 idx++; 1551 idx++;
1552 } 1552 }
1553 1553
1554 Category *cat= categories.find (category); 1554 Category *cat= categories.find (category);
1555 if (cat) 1555 if (cat)
1556 { 1556 {
1557 // use the existend item 1557 // use the existend item
1558 QListViewItem *catItem = cat->getListItem(); 1558 QListViewItem *catItem = cat->getListItem();
1559 if (catItem) 1559 if (catItem)
1560 { 1560 {
1561 QListViewItem * item = new ShadedListItem( 0, catItem ); 1561 QListViewItem * item = new ShadedListItem( 0, catItem );
1562 item->setText( 0, tr( name ) ); 1562 item->setText( 0, tr( name ) );
1563 item->setText( 1, tr( user ) ); 1563 item->setText( 1, tr( user ) );
1564 item->setText( 2, tr( password ) ); 1564 item->setText( 2, tr( password ) );
1565 item->setText( 3, tr( comment ) ); 1565 item->setText( 3, tr( comment ) );
1566 item->setText( 4, tr( field5 ) ); 1566 item->setText( 4, tr( field5 ) );
1567 item->setText( 5, tr( field6 ) ); 1567 item->setText( 5, tr( field6 ) );
1568 catItem->setOpen( TRUE ); 1568 catItem->setOpen( TRUE );
1569 } 1569 }
1570 } 1570 }
1571 else 1571 else
1572 { 1572 {
1573 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1573 QListViewItem *catI = new ShadedListItem( 1, ListView );
1574 // create and insert a new item 1574 // create and insert a new item
1575 QListViewItem * item = new ShadedListItem( 0, catI ); 1575 QListViewItem * item = new ShadedListItem( 0, catI );
1576 item->setText( 0, tr( name ) ); 1576 item->setText( 0, tr( name ) );
1577 item->setText( 1, tr( user ) ); 1577 item->setText( 1, tr( user ) );
1578 item->setText( 2, tr( password ) ); 1578 item->setText( 2, tr( password ) );
1579 item->setText( 3, tr( comment ) ); 1579 item->setText( 3, tr( comment ) );
1580 item->setText( 4, tr( field5 ) ); 1580 item->setText( 4, tr( field5 ) );
1581 item->setText( 5, tr( field6 ) ); 1581 item->setText( 5, tr( field6 ) );
1582 1582
1583 catI->setOpen( TRUE ); 1583 catI->setOpen( TRUE );
1584 1584
1585 Category *c1 = new Category(); 1585 Category *c1 = new Category();
1586 c1->setCategoryName(category); 1586 c1->setCategoryName(category);
1587 1587
1588 QString icon; 1588 QString icon;
1589 QString fullIconPath; 1589 QString fullIconPath;
1590 QPixmap *pix; 1590 QPixmap *pix;
1591// #ifndef Q_WS_WIN 1591// #ifndef Q_WS_WIN
1592 icon = conf->readEntry(APP_KEY+category); 1592 icon = conf->readEntry(APP_KEY+category);
1593// #endif 1593// #endif
1594 bool isIconAv = false; 1594 bool isIconAv = false;
1595 if (!icon.isEmpty() && !icon.isNull()) 1595 if (!icon.isEmpty() && !icon.isNull())
1596 { 1596 {
1597 // build the full path 1597 // build the full path
1598 fullIconPath = iconPath + icon; 1598 fullIconPath = iconPath + icon;
1599 pix = new QPixmap (fullIconPath); 1599 pix = new QPixmap (fullIconPath);
1600 if (!pix->isNull()) 1600 if (!pix->isNull())
1601 { 1601 {
1602 QImage img = pix->convertToImage(); 1602 QImage img = pix->convertToImage();
1603 pix->convertFromImage(img.smoothScale(14,14)); 1603 pix->convertFromImage(img.smoothScale(14,14));
1604 c1->setIconName (icon); 1604 c1->setIconName (icon);
1605 c1->setIcon (*pix); 1605 c1->setIcon (*pix);
1606 isIconAv = true; 1606 isIconAv = true;
1607 } 1607 }
1608 } 1608 }
1609 if (!isIconAv) 1609 if (!isIconAv)
1610 { 1610 {
1611 c1->setIcon (*getPredefinedIcon(category)); 1611 c1->setIcon (*getPredefinedIcon(category));
1612 } 1612 }
1613 c1->setListItem (catI); 1613 c1->setListItem (catI);
1614 c1->initListItem(); 1614 c1->initListItem();
1615 categories.insert (c1->getCategoryName(), c1); 1615 categories.insert (c1->getCategoryName(), c1);
1616 } 1616 }
1617 1617
1618 } 1618 }
1619 f.close(); 1619 f.close();
1620 1620
1621 } 1621 }
1622 else 1622 else
1623 { 1623 {
1624 } 1624 }
1625 1625
1626} 1626}
1627 1627
1628#ifdef UNUSED 1628#ifdef UNUSED
1629void ZSafe::writeAllEntries() 1629void ZSafe::writeAllEntries()
1630{ 1630{
1631 if (filename.isEmpty()) 1631 if (filename.isEmpty())
1632 { 1632 {
1633 QMessageBox::critical( 0, tr("ZSafe"), 1633 QMessageBox::critical( 0, tr("ZSafe"),
1634 tr("<P>No document defined. You have to create a new document</P>")); 1634 tr("<P>No document defined. You have to create a new document</P>"));
1635 return; 1635 return;
1636 } 1636 }
1637 1637
1638 // open the file for writing 1638 // open the file for writing
1639 QString fn = filename + ".txt"; 1639 QString fn = filename + ".txt";
1640 QFile f( fn ); 1640 QFile f( fn );
1641 if ( !f.open( IO_WriteOnly ) ) { 1641 if ( !f.open( IO_WriteOnly ) ) {
1642#ifndef NO_OPIE 1642#ifndef NO_OPIE
1643 owarn << "Could not write to file " << fn << oendl; 1643 owarn << "Could not write to file " << fn << oendl;
1644#else 1644#else
1645 qWarning( QString("Could not write to file %1").arg(fn), 2000 ); 1645 qWarning( QString("Could not write to file %1").arg(fn), 2000 );
1646#endif 1646#endif
1647 QMessageBox::critical( 0, tr("ZSafe"), 1647 QMessageBox::critical( 0, tr("ZSafe"),
1648 tr("Could not export to text file.") ); 1648 tr("Could not export to text file.") );
1649 return; 1649 return;
1650 } 1650 }
1651 QTextStream t( &f ); 1651 QTextStream t( &f );
1652 1652
1653 QListViewItem *i; 1653 QListViewItem *i;
1654 // step through all categories 1654 // step through all categories
1655 for (i = ListView->firstChild(); 1655 for (i = ListView->firstChild();
1656 i != NULL; 1656 i != NULL;
1657 i = i->nextSibling()) 1657 i = i->nextSibling())
1658 { 1658 {
1659 // step through all subitems 1659 // step through all subitems
1660 QListViewItem *si; 1660 QListViewItem *si;
1661 for (si = i->firstChild(); 1661 for (si = i->firstChild();
1662 si != NULL; 1662 si != NULL;
1663 si = si->nextSibling()) 1663 si = si->nextSibling())
1664 { 1664 {
1665 QString oneEntry; 1665 QString oneEntry;
1666 oneEntry += "\""; 1666 oneEntry += "\"";
1667 oneEntry += i->text(0); 1667 oneEntry += i->text(0);
1668 oneEntry += "\";"; 1668 oneEntry += "\";";
1669 oneEntry += "\""; 1669 oneEntry += "\"";
1670 oneEntry += si->text(0); 1670 oneEntry += si->text(0);
1671 oneEntry += "\";"; 1671 oneEntry += "\";";
1672 oneEntry += "\""; 1672 oneEntry += "\"";
1673 oneEntry += si->text(1); 1673 oneEntry += si->text(1);
1674 oneEntry += "\";"; 1674 oneEntry += "\";";
1675 oneEntry += "\""; 1675 oneEntry += "\"";
1676 oneEntry += si->text(2); 1676 oneEntry += si->text(2);
1677 oneEntry += "\";"; 1677 oneEntry += "\";";
1678 oneEntry += "\""; 1678 oneEntry += "\"";
1679 // oneEntry += si->text(3); 1679 // oneEntry += si->text(3);
1680 QString comment = si->text(3); 1680 QString comment = si->text(3);
1681 comment.replace (QRegExp("\n"), "<br>"); 1681 comment.replace (QRegExp("\n"), "<br>");
1682 oneEntry += comment; 1682 oneEntry += comment;
1683 oneEntry += "\""; 1683 oneEntry += "\"";
1684 // owarn << oneEntry << oendl; 1684 // owarn << oneEntry << oendl;
1685 t << oneEntry << endl; 1685 t << oneEntry << endl;
1686 1686
1687 // owarn << si->text(0) << oendl; 1687 // owarn << si->text(0) << oendl;
1688 } 1688 }
1689 } 1689 }
1690 f.close(); 1690 f.close();
1691} 1691}
1692 1692
1693void ZSafe::readAllEntries() 1693void ZSafe::readAllEntries()
1694{ 1694{
1695 QString fn = filename + ".txt"; 1695 QString fn = filename + ".txt";
1696 QFile f( fn ); 1696 QFile f( fn );
1697 if ( !f.open( IO_ReadOnly ) ) 1697 if ( !f.open( IO_ReadOnly ) )
1698 { 1698 {
1699#ifndef NO_OPIE 1699#ifndef NO_OPIE
1700 owarn << "Could not read file " << fn << oendl; 1700 owarn << "Could not read file " << fn << oendl;
1701#else 1701#else
1702 qWarning( QString("Could not read file %1").arg(fn), 2000 ); 1702 qWarning( QString("Could not read file %1").arg(fn), 2000 );
1703#endif 1703#endif
1704 QMessageBox::critical( 0, tr("ZSafe"), 1704 QMessageBox::critical( 0, tr("ZSafe"),
1705 tr("Could not import text file.") ); 1705 tr("Could not import text file.") );
1706 return; 1706 return;
1707 } 1707 }
1708 1708
1709 modified = true; 1709 modified = true;
1710 1710
1711 // clear the password list 1711 // clear the password list
1712 selectedItem = NULL; 1712 selectedItem = NULL;
1713 QListViewItem *i; 1713 QListViewItem *i;
1714 // step through all categories 1714 // step through all categories
1715 for (i = ListView->firstChild(); 1715 for (i = ListView->firstChild();
1716 i != NULL; 1716 i != NULL;
1717 i = i->nextSibling()) 1717 i = i->nextSibling())
1718 { 1718 {
1719 // step through all subitems 1719 // step through all subitems
1720 QListViewItem *si; 1720 QListViewItem *si;
1721 for (si = i->firstChild(); 1721 for (si = i->firstChild();
1722 si != NULL; ) 1722 si != NULL; )
1723 // si = si->nextSibling()) 1723 // si = si->nextSibling())
1724 { 1724 {
1725 QListViewItem *_si = si; 1725 QListViewItem *_si = si;
1726 si = si->nextSibling(); 1726 si = si->nextSibling();
1727 i->takeItem(_si); // remove from view list 1727 i->takeItem(_si); // remove from view list
1728 if (_si) delete _si; 1728 if (_si) delete _si;
1729 } 1729 }
1730 } 1730 }
1731 1731
1732#ifndef NO_OPIE 1732#ifndef NO_OPIE
1733 owarn << "ReadAllEntries(): " << oendl; 1733 owarn << "ReadAllEntries(): " << oendl;
1734#else 1734#else
1735 qWarning ("ReadAllEntries(): "); 1735 qWarning ("ReadAllEntries(): ");
1736#endif 1736#endif
1737 QTextStream t(&f); 1737 QTextStream t(&f);
1738 while ( !t.eof() ) 1738 while ( !t.eof() )
1739 { 1739 {
1740 QString s = t.readLine(); 1740 QString s = t.readLine();
1741 s.replace (QRegExp("\";\""), "\"|\""); 1741 s.replace (QRegExp("\";\""), "\"|\"");
1742 // char buffer[1024]; 1742 // char buffer[1024];
1743 int len=s.length()+1; 1743 int len=s.length()+1;
1744#ifdef Q_WS_WIN 1744#ifdef Q_WS_WIN
1745 char buffer[512]; 1745 char buffer[512];
1746#else 1746#else
1747 char buffer[len]; 1747 char buffer[len];
1748#endif 1748#endif
1749 strcpy (buffer, s); 1749 strcpy (buffer, s);
1750 1750
1751 QString name; 1751 QString name;
1752 QString user; 1752 QString user;
1753 QString password; 1753 QString password;
1754 QString comment; 1754 QString comment;
1755 1755
1756 // separete the entries 1756 // separete the entries
1757 char *i = strtok (buffer, "|"); 1757 char *i = strtok (buffer, "|");
1758 QString category(&i[1]); 1758 QString category(&i[1]);
1759 category.truncate(category.length() -1); 1759 category.truncate(category.length() -1);
1760 1760
1761 int idx=0; 1761 int idx=0;
1762 while (i = strtok (NULL, "|")) 1762 while (i = strtok (NULL, "|"))
1763 { 1763 {
1764 switch (idx) 1764 switch (idx)
1765 { 1765 {
1766 case 0: 1766 case 0:
1767 name = &i[1]; 1767 name = &i[1];
1768 name.truncate(name.length() -1); 1768 name.truncate(name.length() -1);
1769 // name 1769 // name
1770 break; 1770 break;
1771 case 1: 1771 case 1:
1772 // user 1772 // user
1773 user = &i[1]; 1773 user = &i[1];
1774 user.truncate(user.length() -1); 1774 user.truncate(user.length() -1);
1775 break; 1775 break;
1776 case 2: 1776 case 2:
1777 // password 1777 // password
1778 password = &i[1]; 1778 password = &i[1];
1779 password.truncate(password.length() -1); 1779 password.truncate(password.length() -1);
1780 break; 1780 break;
1781 case 3: 1781 case 3:
1782 // comment 1782 // comment
1783 comment = &i[1]; 1783 comment = &i[1];
1784 comment.truncate(comment.length() -1); 1784 comment.truncate(comment.length() -1);
1785 break; 1785 break;
1786 } 1786 }
1787 idx++; 1787 idx++;
1788 } 1788 }
1789 1789
1790 Category *cat= categories.find (category); 1790 Category *cat= categories.find (category);
1791 if (cat) 1791 if (cat)
1792 { 1792 {
1793 // use the existend item 1793 // use the existend item
1794 QListViewItem *catItem = cat->getListItem(); 1794 QListViewItem *catItem = cat->getListItem();
1795 if (catItem) 1795 if (catItem)
1796 { 1796 {
1797 QListViewItem * item = new ShadedListItem( 0, catItem ); 1797 QListViewItem * item = new ShadedListItem( 0, catItem );
1798 item->setText( 0, tr( name ) ); 1798 item->setText( 0, tr( name ) );
1799 item->setText( 1, tr( user ) ); 1799 item->setText( 1, tr( user ) );
1800 item->setText( 2, tr( password ) ); 1800 item->setText( 2, tr( password ) );
1801 item->setText( 3, tr( comment ) ); 1801 item->setText( 3, tr( comment ) );
1802 1802
1803 catItem->setOpen( TRUE ); 1803 catItem->setOpen( TRUE );
1804 } 1804 }
1805 } 1805 }
1806 else 1806 else
1807 { 1807 {
1808 QListViewItem *catI = new ShadedListItem( 1, ListView ); 1808 QListViewItem *catI = new ShadedListItem( 1, ListView );
1809 // create and insert a new item 1809 // create and insert a new item
1810 QListViewItem * item = new ShadedListItem( 0, catI ); 1810 QListViewItem * item = new ShadedListItem( 0, catI );
1811 item->setText( 0, tr( name ) ); 1811 item->setText( 0, tr( name ) );
1812 item->setText( 1, tr( user ) ); 1812 item->setText( 1, tr( user ) );
1813 item->setText( 2, tr( password ) ); 1813 item->setText( 2, tr( password ) );
1814 item->setText( 3, tr( comment ) ); 1814 item->setText( 3, tr( comment ) );
1815 1815
1816 catI->setOpen( TRUE ); 1816 catI->setOpen( TRUE );
1817 1817
1818 Category *c1 = new Category(); 1818 Category *c1 = new Category();
1819 c1->setCategoryName(category); 1819 c1->setCategoryName(category);
1820 1820
1821 QString icon; 1821 QString icon;
1822 QString fullIconPath; 1822 QString fullIconPath;
1823 QPixmap *pix; 1823 QPixmap *pix;
1824// #ifndef Q_WS_WIN 1824// #ifndef Q_WS_WIN
1825 icon = conf->readEntry(APP_KEY+category); 1825 icon = conf->readEntry(APP_KEY+category);
1826// #endif 1826// #endif
1827 bool isIconAv = false; 1827 bool isIconAv = false;
1828 if (!icon.isEmpty() && !icon.isNull()) 1828 if (!icon.isEmpty() && !icon.isNull())
1829 { 1829 {
1830 // build the full path 1830 // build the full path
1831 fullIconPath = iconPath + icon; 1831 fullIconPath = iconPath + icon;
1832 pix = new QPixmap (fullIconPath); 1832 pix = new QPixmap (fullIconPath);
1833 if (!pix->isNull()) 1833 if (!pix->isNull())
1834 { 1834 {
1835 QImage img = pix->convertToImage(); 1835 QImage img = pix->convertToImage();
1836 pix->convertFromImage(img.smoothScale(14,14)); 1836 pix->convertFromImage(img.smoothScale(14,14));
1837 c1->setIconName (icon); 1837 c1->setIconName (icon);
1838 c1->setIcon (*pix); 1838 c1->setIcon (*pix);
1839 isIconAv = true; 1839 isIconAv = true;
1840 } 1840 }
1841 } 1841 }
1842 if (!isIconAv) 1842 if (!isIconAv)
1843 { 1843 {
1844 c1->setIcon (*getPredefinedIcon(category)); 1844 c1->setIcon (*getPredefinedIcon(category));
1845 } 1845 }
1846 c1->setListItem (catI); 1846 c1->setListItem (catI);
1847 c1->initListItem(); 1847 c1->initListItem();
1848 categories.insert (c1->getCategoryName(), c1); 1848 categories.insert (c1->getCategoryName(), c1);
1849 } 1849 }
1850 1850
1851 } 1851 }
1852 f.close(); 1852 f.close();
1853 1853
1854} 1854}
1855#endif // UNUSED 1855#endif // UNUSED
1856 1856
1857void ZSafe::resume(int) 1857void ZSafe::resume(int)
1858{ 1858{
1859#ifndef NO_OPIE 1859#ifndef NO_OPIE
1860 owarn << "Resume" << oendl; 1860 owarn << "Resume" << oendl;
1861#endif 1861#endif
1862 // hide the main window 1862 // hide the main window
1863 1863
1864 if ( !showpwd ) 1864 if ( !showpwd )
1865 { 1865 {
1866 infoForm->hide(); 1866 infoForm->hide();
1867 // open zsafe again 1867 // open zsafe again
1868 m_password = ""; 1868 m_password = "";
1869 selectedItem = NULL; 1869 selectedItem = NULL;
1870 1870
1871 // clear the password list 1871 // clear the password list
1872 QListViewItem *i; 1872 QListViewItem *i;
1873 // step through all categories 1873 // step through all categories
1874 for (i = ListView->firstChild(); 1874 for (i = ListView->firstChild();
1875 i != NULL; 1875 i != NULL;
1876 i = i->nextSibling()) 1876 i = i->nextSibling())
1877 { 1877 {
1878 // step through all subitems 1878 // step through all subitems
1879 QListViewItem *si; 1879 QListViewItem *si;
1880 for (si = i->firstChild(); 1880 for (si = i->firstChild();
1881 si != NULL; ) 1881 si != NULL; )
1882 { 1882 {
1883 QListViewItem *_si = si; 1883 QListViewItem *_si = si;
1884 si = si->nextSibling(); 1884 si = si->nextSibling();
1885 i->takeItem(_si); // remove from view list 1885 i->takeItem(_si); // remove from view list
1886 if (_si) delete _si; 1886 if (_si) delete _si;
1887 } 1887 }
1888 } 1888 }
1889 1889
1890 // ask for password and read again 1890 // ask for password and read again
1891 openDocument(filename); 1891 openDocument(filename);
1892 } 1892 }
1893} 1893}
1894 1894
1895//--------------------------------------------- 1895//---------------------------------------------
1896 1896
1897 1897
1898bool ZSafe::openDocument(const char* _filename, const char* ) 1898bool ZSafe::openDocument(const char* _filename, const char* )
1899{ 1899{
1900 QString name= _filename; 1900 QString name= _filename;
1901 qWarning("openDocument "+name); 1901 qWarning("openDocument "+name);
1902 int retval; 1902 int retval;
1903 char* entry[FIELD_SIZE]; 1903 char* entry[FIELD_SIZE];
1904// #ifndef Q_WS_WIN 1904// #ifndef Q_WS_WIN
1905 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1); 1905 int validationFlag = conf->readNumEntry(APP_KEY+"valzsafe", 1);
1906// #else 1906// #else
1907 // int validationFlag = 1; 1907 // int validationFlag = 1;
1908// #endif 1908// #endif
1909 1909
1910 int pwdOk = 0; 1910 int pwdOk = 0;
1911 int numberOfTries = 3; 1911 int numberOfTries = 3;
1912 for (int i=0; i < numberOfTries; i++) 1912 for (int i=0; i < numberOfTries; i++)
1913 { 1913 {
1914 QFile f(_filename); 1914 QFile f(_filename);
1915 if (f.exists()) 1915 if (f.exists())
1916 { 1916 {
1917 // ask with a dialog for the password 1917 // ask with a dialog for the password
1918 if (m_password.isEmpty()) 1918 if (m_password.isEmpty())
1919 getDocPassword(tr("Enter Password")); 1919 getDocPassword(tr("Enter Password"));
1920 if (m_password.isEmpty() && validationFlag == 0) 1920 if (m_password.isEmpty() && validationFlag == 0)
1921 { 1921 {
1922#ifndef NO_OPIE 1922#ifndef NO_OPIE
1923 owarn << "Wrong password" << oendl; 1923 owarn << "Wrong password" << oendl;
1924#else 1924#else
1925 qWarning ("Wrong password"); 1925 qWarning ("Wrong password");
1926#endif 1926#endif
1927 QMessageBox::critical( 0, tr("ZSafe"), 1927 QMessageBox::critical( 0, tr("ZSafe"),
1928 tr("Wrong password.\n\nZSafe will now exit.") ); 1928 tr("Wrong password.\n\nZSafe will now exit.") );
1929 exitZs (1); 1929 exitZs (1);
1930 } 1930 }
1931 1931
1932 retval = loadInit(_filename, m_password); 1932 retval = loadInit(_filename, m_password);
1933 if (retval != PWERR_GOOD) 1933 if (retval != PWERR_GOOD)
1934 { 1934 {
1935#ifndef NO_OPIE 1935#ifndef NO_OPIE
1936 owarn << "Error loading Document" << oendl; 1936 owarn << "Error loading Document" << oendl;
1937#else 1937#else
1938 qWarning ("Error loading Document"); 1938 qWarning ("Error loading Document");
1939#endif 1939#endif
1940 return false; 1940 return false;
1941 } 1941 }
1942 } 1942 }
1943 else 1943 else
1944 { 1944 {
1945#ifdef Q_WS_WIN 1945#ifdef Q_WS_WIN
1946 this->setCaption("Qt ZSafe"); 1946 this->setCaption("Qt ZSafe");
1947#else 1947#else
1948 this->setCaption("ZSafe"); 1948 this->setCaption("ZSafe");
1949#endif 1949#endif
1950 filename = ""; 1950 filename = "";
1951 switch( QMessageBox::warning( this, tr("ZSafe"), 1951 switch( QMessageBox::warning( this, tr("ZSafe"),
1952 tr("<P>You must create a new document first. Ok to create?</P>"), 1952 tr("<P>You must create a new document first. Ok to create?</P>"),
1953 tr("&Yes"), tr("&No."), 1953 tr("&Yes"), tr("&No."),
1954 0 1954 0
1955 ) ) 1955 ) )
1956 { 1956 {
1957 case 1: // No 1957 case 1: // No
1958 return false; 1958 return false;
1959 break; 1959 break;
1960 case 0: // Yes 1960 case 0: // Yes
1961 newDocument(); 1961 newDocument();
1962 return false; 1962 return false;
1963 break; 1963 break;
1964 } 1964 }
1965 1965
1966 } 1966 }
1967 1967
1968 1968
1969 // load the validation entry 1969 // load the validation entry
1970 if (validationFlag == 0) 1970 if (validationFlag == 0)
1971 { 1971 {
1972 pwdOk = 1; 1972 pwdOk = 1;
1973 break; 1973 break;
1974 } 1974 }
1975 1975
1976 retval = loadEntry(entry); 1976 retval = loadEntry(entry);
1977 if (retval == 1 && 1977 if (retval == 1 &&
1978 !strcmp (entry[0], "ZSAFECATEGORY") && 1978 !strcmp (entry[0], "ZSAFECATEGORY") &&
1979 !strcmp (entry[1], "name") && 1979 !strcmp (entry[1], "name") &&
1980 !strcmp (entry[2], "username") && 1980 !strcmp (entry[2], "username") &&
1981 !strcmp (entry[3], "password") && 1981 !strcmp (entry[3], "password") &&
1982 !strcmp (entry[4], "comment") ) 1982 !strcmp (entry[4], "comment") )
1983 { 1983 {
1984 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1984 for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1985 pwdOk = 1; 1985 pwdOk = 1;
1986 break; 1986 break;
1987 } 1987 }
1988 else 1988 else
1989 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]); 1989 // for (int count = 0; count < FIELD_SIZE; count++) free(entry[count]);
1990 fclose (fd); 1990 fclose (fd);
1991 m_password = ""; 1991 m_password = "";
1992 1992
1993 if (i < numberOfTries - 1) 1993 if (i < numberOfTries - 1)
1994 { 1994 {
1995 switch( QMessageBox::warning( this, tr("ZSafe"), 1995 switch( QMessageBox::warning( this, tr("ZSafe"),
1996 tr("Wrong password.\nEnter again?"), 1996 tr("Wrong password.\nEnter again?"),
1997 tr("&Yes"), tr("&No."), 1997 tr("&Yes"), tr("&No."),
1998 0 1998 0
1999 ) ) 1999 ) )
2000 { 2000 {
2001 case 1: // No 2001 case 1: // No
2002 exitZs (1); 2002 exitZs (1);
2003 break; 2003 break;
2004 case 0: // Yes 2004 case 0: // Yes
2005 continue; 2005 continue;
2006 } 2006 }
2007 } 2007 }
2008 } 2008 }
2009 if (pwdOk == 0) 2009 if (pwdOk == 0)
2010 { 2010 {
2011 // unset the document entry 2011 // unset the document entry
2012 conf->writeEntry(APP_KEY+"document", "INVALIDPWD"); 2012 conf->writeEntry(APP_KEY+"document", "INVALIDPWD");
2013 if (conf) 2013 if (conf)
2014 delete conf; 2014 delete conf;
2015 2015
2016 exitZs (1); 2016 exitZs (1);
2017 } 2017 }
2018 2018
2019 2019
2020 retval = loadEntry(entry); 2020 retval = loadEntry(entry);
2021 2021
2022 int numberOfEntries=0; 2022 int numberOfEntries=0;
2023 while (retval == 1) { 2023 while (retval == 1) {
2024 2024
2025 QString category( QString::fromUtf8(entry[0]) ); 2025 QString category( QString::fromUtf8(entry[0]) );
2026 QString name( QString::fromUtf8(entry[1]) ); 2026 QString name( QString::fromUtf8(entry[1]) );
2027 QString user( QString::fromUtf8(entry[2]) ); 2027 QString user( QString::fromUtf8(entry[2]) );
2028 QString password( QString::fromUtf8(entry[3]) ); 2028 QString password( QString::fromUtf8(entry[3]) );
2029 QString comment( QString::fromUtf8(entry[4]) ); 2029 QString comment( QString::fromUtf8(entry[4]) );
2030 QString field5( QString::fromUtf8(entry[5]) ); 2030 QString field5( QString::fromUtf8(entry[5]) );
2031 QString field6( QString::fromUtf8(entry[6]) ); 2031 QString field6( QString::fromUtf8(entry[6]) );
2032 // add the subitems to the categories 2032 // add the subitems to the categories
2033 2033
2034 Category *cat= categories.find (category); 2034 Category *cat= categories.find (category);
2035 if (cat) 2035 if (cat)
2036 { 2036 {
2037 // use the existend item 2037 // use the existend item
2038 QListViewItem *catItem = cat->getListItem(); 2038 QListViewItem *catItem = cat->getListItem();
2039 if (catItem) 2039 if (catItem)
2040 { 2040 {
2041 QListViewItem * item = new ShadedListItem( 0, catItem ); 2041 QListViewItem * item = new ShadedListItem( 0, catItem );
2042 item->setText( 0, tr( name ) ); 2042 item->setText( 0, tr( name ) );
2043 item->setText( 1, tr( user ) ); 2043 item->setText( 1, tr( user ) );
2044 item->setText( 2, tr( password ) ); 2044 item->setText( 2, tr( password ) );
2045 item->setText( 3, tr( comment ) ); 2045 item->setText( 3, tr( comment ) );
2046 item->setText( 4, tr( field5 ) ); 2046 item->setText( 4, tr( field5 ) );
2047 item->setText( 5, tr( field6 ) ); 2047 item->setText( 5, tr( field6 ) );
2048 2048
2049 if (expandTree) 2049 if (expandTree)
2050 catItem->setOpen( TRUE ); 2050 catItem->setOpen( TRUE );
2051 numberOfEntries++; 2051 numberOfEntries++;
2052 } 2052 }
2053 } 2053 }
2054 else 2054 else
2055 { 2055 {
2056 QListViewItem *catI = new ShadedListItem( 1, ListView ); 2056 QListViewItem *catI = new ShadedListItem( 1, ListView );
2057 // create and insert a new item 2057 // create and insert a new item
2058 QListViewItem * item = new ShadedListItem( 0, catI ); 2058 QListViewItem * item = new ShadedListItem( 0, catI );
2059 2059
2060 item->setText( 0, tr( name ) ); 2060 item->setText( 0, tr( name ) );
2061 item->setText( 1, tr( user ) ); 2061 item->setText( 1, tr( user ) );
2062 item->setText( 2, tr( password ) ); 2062 item->setText( 2, tr( password ) );
2063 item->setText( 3, tr( comment ) ); 2063 item->setText( 3, tr( comment ) );
2064 item->setText( 4, tr( field5 ) ); 2064 item->setText( 4, tr( field5 ) );
2065 item->setText( 5, tr( field6 ) ); 2065 item->setText( 5, tr( field6 ) );
2066 2066
2067 if (expandTree) 2067 if (expandTree)
2068 catI->setOpen( TRUE ); 2068 catI->setOpen( TRUE );
2069 2069
2070 Category *c1 = new Category(); 2070 Category *c1 = new Category();
2071 c1->setCategoryName(category); 2071 c1->setCategoryName(category);
2072 2072
2073 QString icon; 2073 QString icon;
2074 QString fullIconPath; 2074 QString fullIconPath;
2075 QPixmap *pix; 2075 QPixmap *pix;
2076// #ifndef Q_WS_WIN 2076// #ifndef Q_WS_WIN
2077 icon = conf->readEntry(APP_KEY+category); 2077 icon = conf->readEntry(APP_KEY+category);
2078// #endif 2078// #endif
2079 bool isIconAv = false; 2079 bool isIconAv = false;
2080 if (!icon.isEmpty() && !icon.isNull()) 2080 if (!icon.isEmpty() && !icon.isNull())
2081 { 2081 {
2082 // build the full path 2082 // build the full path
2083 fullIconPath = iconPath + icon; 2083 fullIconPath = iconPath + icon;
2084 pix = new QPixmap (fullIconPath); 2084 pix = new QPixmap (fullIconPath);
2085 if (!pix->isNull()) 2085 if (!pix->isNull())
2086 { 2086 {
2087 QImage img = pix->convertToImage(); 2087 QImage img = pix->convertToImage();
2088 pix->convertFromImage(img.smoothScale(14,14)); 2088 pix->convertFromImage(img.smoothScale(14,14));
2089 c1->setIconName (icon); 2089 c1->setIconName (icon);
2090 c1->setIcon (*pix); 2090 c1->setIcon (*pix);
2091 isIconAv = true; 2091 isIconAv = true;
2092 } 2092 }
2093 } 2093 }
2094 if (!isIconAv) 2094 if (!isIconAv)
2095 { 2095 {
2096 c1->setIcon (*getPredefinedIcon(category)); 2096 c1->setIcon (*getPredefinedIcon(category));
2097 } 2097 }
2098 2098
2099 c1->setListItem (catI); 2099 c1->setListItem (catI);
2100 c1->initListItem(); 2100 c1->initListItem();
2101 categories.insert (c1->getCategoryName(), c1); 2101 categories.insert (c1->getCategoryName(), c1);
2102 numberOfEntries++; 2102 numberOfEntries++;
2103 } 2103 }
2104 2104
2105 for (int count = 0; count < FIELD_SIZE; count++) { 2105 for (int count = 0; count < FIELD_SIZE; count++) {
2106 free(entry[count]); 2106 free(entry[count]);
2107 } 2107 }
2108 retval = loadEntry(entry); 2108 retval = loadEntry(entry);
2109 if (retval == 2) { 2109 if (retval == 2) {
2110 // m_parent->slotStatusHelpMsg("Last entry loaded"); 2110 // m_parent->slotStatusHelpMsg("Last entry loaded");
2111 } 2111 }
2112 } // end while 2112 } // end while
2113 2113
2114 if (numberOfEntries == 0) 2114 if (numberOfEntries == 0)
2115 { 2115 {
2116 2116
2117 switch( QMessageBox::warning( this, tr("ZSafe"), 2117 switch( QMessageBox::warning( this, tr("ZSafe"),
2118 tr("Empty document or\nwrong password.\nContinue?"), 2118 tr("Empty document or\nwrong password.\nContinue?"),
2119 tr("&No"), tr("&Yes."), 2119 tr("&No"), tr("&Yes."),
2120 0 2120 0
2121 ) ) { 2121 ) ) {
2122 case 0: // No 2122 case 0: // No
2123 retval = loadFinalize(); 2123 retval = loadFinalize();
2124 exitZs (1); 2124 exitZs (1);
2125 break; 2125 break;
2126 case 1: // Yes 2126 case 1: // Yes
2127 break; 2127 break;
2128 } 2128 }
2129 } 2129 }
2130 2130
2131 retval = loadFinalize(); 2131 retval = loadFinalize();
2132 2132
2133 return true; 2133 return true;
2134} 2134}
2135 2135
2136int ZSafe::loadInit(const char* _filename, const char *password) 2136int ZSafe::loadInit(const char* _filename, const char *password)
2137{ 2137{
2138 unsigned int j = 0; 2138 unsigned int j = 0;
2139 unsigned int keylength=0; 2139 unsigned int keylength=0;
2140 int count=0, count2=0, count3=0; 2140 int count=0, count2=0, count3=0;
2141 unsigned char charbuf[8]; 2141 unsigned char charbuf[8];
2142 unsigned short ciphertext[4]; 2142 unsigned short ciphertext[4];
2143 char key[128]; 2143 char key[128];
2144 Krc2* krc2 = new Krc2(); 2144 Krc2* krc2 = new Krc2();
2145 2145
2146 fd = fopen (_filename, "rb"); 2146 fd = fopen (_filename, "rb");
2147 2147
2148 QFileInfo f (_filename); 2148 QFileInfo f (_filename);
2149 load_buffer_length = f.size(); 2149 load_buffer_length = f.size();
2150 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2; 2150 load_buffer_length = ((load_buffer_length / 1024)+1) * 1024 * 2;
2151 2151
2152 if (fd == NULL) 2152 if (fd == NULL)
2153 return PWERR_OPEN; 2153 return PWERR_OPEN;
2154 2154
2155 buffer = (char *)malloc(load_buffer_length); 2155 buffer = (char *)malloc(load_buffer_length);
2156 for (j = 0; password[j] != '\0'; j++) { 2156 for (j = 0; password[j] != '\0'; j++) {
2157 key[j] = password[j]; 2157 key[j] = password[j];
2158 } 2158 }
2159 keylength = j; 2159 keylength = j;
2160 krc2->rc2_expandkey (key, keylength, 128); 2160 krc2->rc2_expandkey (key, keylength, 128);
2161 2161
2162#ifndef Q_WS_WIN 2162#ifndef Q_WS_WIN
2163 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8); 2163 size = read(fileno (fd), (unsigned char *) (charbuf + count), 8);
2164#else 2164#else
2165 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2165 size = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2166#endif 2166#endif
2167 2167
2168 if (size < 8) 2168 if (size < 8)
2169 return PWERR_DATA; 2169 return PWERR_DATA;
2170 2170
2171 for (count = 0; count < 4; count++) { 2171 for (count = 0; count < 4; count++) {
2172 count2 = count << 1; 2172 count2 = count << 1;
2173 iv[count] = charbuf[count2] << 8; 2173 iv[count] = charbuf[count2] << 8;
2174 iv[count] += charbuf[count2 + 1]; 2174 iv[count] += charbuf[count2 + 1];
2175 } 2175 }
2176 2176
2177 size = 0; 2177 size = 0;
2178 bufferIndex = 0; 2178 bufferIndex = 0;
2179#ifndef Q_WS_WIN 2179#ifndef Q_WS_WIN
2180 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) { 2180 while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) {
2181 while (count < 8) { 2181 while (count < 8) {
2182 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8); 2182 count2 = read (fileno (fd), (unsigned char *) (charbuf + count), 8);
2183#else 2183#else
2184 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) { 2184 while ((count = fread ((unsigned char *) (charbuf), sizeof(unsigned char), 8, fd)) > 0) {
2185 while (count < 8) { 2185 while (count < 8) {
2186 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd); 2186 count2 = fread ((unsigned char *) (charbuf + count), sizeof(unsigned char), 8, fd);
2187#endif 2187#endif
2188 if (count2 == 0) { 2188 if (count2 == 0) {
2189 return PWERR_DATA; 2189 return PWERR_DATA;
2190 } 2190 }
2191 count += count2; 2191 count += count2;
2192 } /* while (count < 8) */ 2192 } /* while (count < 8) */
2193 2193
2194 size += 8; 2194 size += 8;
2195 for (count2 = 0; count2 < 8; count2 += 2) { 2195 for (count2 = 0; count2 < 8; count2 += 2) {
2196 count3 = count2 >> 1; 2196 count3 = count2 >> 1;
2197 ciphertext[count3] = charbuf[count2] << 8; 2197 ciphertext[count3] = charbuf[count2] << 8;
2198 ciphertext[count3] += charbuf[count2 + 1]; 2198 ciphertext[count3] += charbuf[count2 + 1];
2199 2199
2200 plaintext[count3] = ciphertext[count3] ^ iv[count3]; 2200 plaintext[count3] = ciphertext[count3] ^ iv[count3];
2201 iv[count3] = plaintext[count3]; 2201 iv[count3] = plaintext[count3];
2202 } /* for (count2) */ 2202 } /* for (count2) */
2203 2203
2204 krc2->rc2_decrypt (plaintext); 2204 krc2->rc2_decrypt (plaintext);
2205 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8); 2205 memcpy ((unsigned char *) (buffer + bufferIndex), plaintext, 8);
2206 bufferIndex += 8; 2206 bufferIndex += 8;
2207 buffer[bufferIndex + 1] = '\0'; 2207 buffer[bufferIndex + 1] = '\0';
2208 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */ 2208 } /* while ((count = read (fileno (fd), (unsigned char *) charbuf, 8)) > 0) */
2209 size -= buffer[size - 1]; 2209 size -= buffer[size - 1];
2210 lastcount = 0; 2210 lastcount = 0;
2211 2211
2212 /* This will point to the starting index */ 2212 /* This will point to the starting index */
2213 bufferIndex = 0; 2213 bufferIndex = 0;
2214 return PWERR_GOOD; 2214 return PWERR_GOOD;
2215} 2215}
2216 2216
2217int ZSafe::loadEntry(char *entry[FIELD_SIZE]) 2217int ZSafe::loadEntry(char *entry[FIELD_SIZE])
2218{ 2218{
2219 /* Strip off PKCS 5 padding 2219 /* Strip off PKCS 5 padding
2220 * Should check to make sure it's good here 2220 * Should check to make sure it's good here
2221 */ 2221 */
2222 int count, count1=0; 2222 int count, count1=0;
2223 2223
2224 for (count = lastcount; count < size; count++) { 2224 for (count = lastcount; count < size; count++) {
2225 if ((unsigned char) (buffer[count]) == 255) { 2225 if ((unsigned char) (buffer[count]) == 255) {
2226 if (buffer[bufferIndex] == '\0') { 2226 if (buffer[bufferIndex] == '\0') {
2227 bufferIndex++; 2227 bufferIndex++;
2228 } 2228 }
2229 entry[count1] = (char *) malloc (count - bufferIndex + 1); 2229 entry[count1] = (char *) malloc (count - bufferIndex + 1);
2230 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex); 2230 memcpy (entry[count1], (unsigned char *) (buffer + bufferIndex), count - bufferIndex);
2231 entry[count1][count - bufferIndex] = '\0'; 2231 entry[count1][count - bufferIndex] = '\0';
2232 count++; 2232 count++;
2233 bufferIndex = count; 2233 bufferIndex = count;
2234 count1++; 2234 count1++;
2235 if (count1 == FIELD_SIZE) { 2235 if (count1 == FIELD_SIZE) {
2236 lastcount = count; 2236 lastcount = count;
2237 return 1; 2237 return 1;
2238 } 2238 }
2239 } /* if ((unsigned char) (buffer[count]) == 255) */ 2239 } /* if ((unsigned char) (buffer[count]) == 255) */
2240 } /* for (count = 0; count < size; count++) */ 2240 } /* for (count = 0; count < size; count++) */
2241 2241
2242 return 2; 2242 return 2;
2243} 2243}
2244 2244
2245int ZSafe::loadFinalize(void) 2245int ZSafe::loadFinalize(void)
2246{ 2246{
2247 fclose (fd); 2247 fclose (fd);
2248 if (buffer) free(buffer); 2248 if (buffer) free(buffer);
2249 return PWERR_GOOD; 2249 return PWERR_GOOD;
2250} 2250}
2251 2251
2252bool ZSafe::saveDocument(const char* _filename, 2252bool ZSafe::saveDocument(const char* _filename,
2253 bool withPwd, 2253 bool withPwd,
2254 const char* ) 2254 const char* )
2255{ 2255{
2256 if (filename.isEmpty()) 2256 if (filename.isEmpty())
2257 { 2257 {
2258 QMessageBox::critical( 0, tr("ZSafe"), 2258 QMessageBox::critical( 0, tr("ZSafe"),
2259 tr("No document defined.\nYou have to create a new document")); 2259 tr("No document defined.\nYou have to create a new document"));
2260 return false; 2260 return false;
2261 } 2261 }
2262 2262
2263 // if (m_password.isEmpty()) 2263 // if (m_password.isEmpty())
2264 // withPwd = true; // the document must be saved with a valid password 2264 // withPwd = true; // the document must be saved with a valid password
2265 if (withPwd) 2265 if (withPwd)
2266 { 2266 {
2267 bool pwdOk = FALSE; 2267 bool pwdOk = FALSE;
2268 while (!pwdOk) 2268 while (!pwdOk)
2269 { 2269 {
2270 getDocPassword(tr("Enter Password")); 2270 getDocPassword(tr("Enter Password"));
2271 if (m_password.isEmpty()) 2271 if (m_password.isEmpty())
2272 { 2272 {
2273 2273
2274 QMessageBox::critical( 0, tr("ZSafe"), 2274 QMessageBox::critical( 0, tr("ZSafe"),
2275 tr("Password is empty.\nPlease enter again.")); 2275 tr("Password is empty.\nPlease enter again."));
2276 continue; 2276 continue;
2277 } 2277 }
2278 2278
2279 QString firstPasswd = m_password; 2279 QString firstPasswd = m_password;
2280 2280
2281 getDocPassword(tr("Reenter Password")); 2281 getDocPassword(tr("Reenter Password"));
2282 if (m_password.isEmpty()) 2282 if (m_password.isEmpty())
2283 { 2283 {
2284 QMessageBox::critical( 0, tr("ZSafe"), 2284 QMessageBox::critical( 0, tr("ZSafe"),
2285 tr("Password is empty.\nPlease enter again.")); 2285 tr("Password is empty.\nPlease enter again."));
2286 continue; 2286 continue;
2287 } 2287 }
2288 if (firstPasswd != m_password) 2288 if (firstPasswd != m_password)
2289 { 2289 {
2290 2290
2291 QMessageBox::critical( 0, tr("ZSafe"), 2291 QMessageBox::critical( 0, tr("ZSafe"),
2292 tr("Passwords must be identical.\nPlease enter again.")); 2292 tr("Passwords must be identical.\nPlease enter again."));
2293 continue; 2293 continue;
2294 } 2294 }
2295 pwdOk = TRUE; 2295 pwdOk = TRUE;
2296 modified = false; 2296 modified = false;
2297 } 2297 }
2298 } 2298 }
2299 else if (modified) 2299 else if (modified)
2300 { 2300 {
2301 QString fns(_filename); 2301 QString fns(_filename);
2302 fns = fns.right (fns.length() - fns.findRev ('/') - 1); 2302 fns = fns.right (fns.length() - fns.findRev ('/') - 1);
2303 switch( QMessageBox::information( this, tr("ZSafe"), 2303 switch( QMessageBox::information( this, tr("ZSafe"),
2304 tr("Do you want to save ") + fns + tr("\nbefore continuing?"), 2304 tr("Do you want to save ") + fns + tr("\nbefore continuing?"),
2305 tr("&Save"), 2305 tr("&Save"),
2306 tr("&Don't Save"), 2306 tr("&Don't Save"),
2307 0 // Enter == button 0 2307 0 // Enter == button 0
2308 ) ) 2308 ) )
2309 { // Escape == button 2 2309 { // Escape == button 2
2310 case 0: // Save clicked, Alt-S or Enter pressed. 2310 case 0: // Save clicked, Alt-S or Enter pressed.
2311 modified = false; 2311 modified = false;
2312 break; 2312 break;
2313 case 1: // Don't Save clicked or Alt-D pressed 2313 case 1: // Don't Save clicked or Alt-D pressed
2314 modified = false; 2314 modified = false;
2315 return true; 2315 return true;
2316 } 2316 }
2317 } 2317 }
2318 modified = false; 2318 modified = false;
2319 2319
2320 if (m_password.isEmpty()) 2320 if (m_password.isEmpty())
2321 return false; 2321 return false;
2322 2322
2323 int retval = saveInit(_filename, m_password); 2323 int retval = saveInit(_filename, m_password);
2324 // int retval = saveInit(_filename, "test"); 2324 // int retval = saveInit(_filename, "test");
2325 if (retval != PWERR_GOOD) { 2325 if (retval != PWERR_GOOD) {
2326 return false; 2326 return false;
2327 } 2327 }
2328 2328
2329 char* entry[FIELD_SIZE]; 2329 char* entry[FIELD_SIZE];
2330 2330
2331 // save the validation entry 2331 // save the validation entry
2332 { 2332 {
2333 int i=0; 2333 int i=0;
2334 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1); 2334 entry[i] = (char*)malloc(strlen("ZSAFECATEGORY")+1);
2335 strcpy(entry[i++], "ZSAFECATEGORY"); 2335 strcpy(entry[i++], "ZSAFECATEGORY");
2336 entry[i] = (char*)malloc(strlen("name")+1); 2336 entry[i] = (char*)malloc(strlen("name")+1);
2337 strcpy(entry[i++], "name"); 2337 strcpy(entry[i++], "name");
2338 entry[i] = (char*)malloc(strlen("username")+1); 2338 entry[i] = (char*)malloc(strlen("username")+1);
2339 strcpy(entry[i++], "username"); 2339 strcpy(entry[i++], "username");
2340 entry[i] = (char*)malloc(strlen("password")+1); 2340 entry[i] = (char*)malloc(strlen("password")+1);
2341 strcpy(entry[i++], "password"); 2341 strcpy(entry[i++], "password");
2342 entry[i] = (char*)malloc(strlen("comment")+1); 2342 entry[i] = (char*)malloc(strlen("comment")+1);
2343 strcpy(entry[i++], "comment"); 2343 strcpy(entry[i++], "comment");
2344 2344
2345 entry[i] = (char*)malloc(strlen("field5")+1); 2345 entry[i] = (char*)malloc(strlen("field5")+1);
2346 strcpy(entry[i++], "field5"); 2346 strcpy(entry[i++], "field5");
2347 entry[i] = (char*)malloc(strlen("field6")+1); 2347 entry[i] = (char*)malloc(strlen("field6")+1);
2348 strcpy(entry[i++], "field6"); 2348 strcpy(entry[i++], "field6");
2349 2349
2350 retval = saveEntry(entry); 2350 retval = saveEntry(entry);
2351 for (int z=0; z<i; z++) free(entry[z]); 2351 for (int z=0; z<i; z++) free(entry[z]);
2352 if (retval == PWERR_DATA) { 2352 if (retval == PWERR_DATA) {
2353#ifndef NO_OPIE 2353#ifndef NO_OPIE
2354 owarn << "1: Error writing file, contents not saved" << oendl; 2354 owarn << "1: Error writing file, contents not saved" << oendl;
2355#else 2355#else
2356 qWarning("1: Error writing file, contents not saved"); 2356 qWarning("1: Error writing file, contents not saved");
2357#endif 2357#endif
2358 saveFinalize(); 2358 saveFinalize();
2359 return false; 2359 return false;
2360 } 2360 }
2361// #ifndef Q_WS_WIN 2361// #ifndef Q_WS_WIN
2362 conf->writeEntry(APP_KEY+"valzsafe", 1); 2362 conf->writeEntry(APP_KEY+"valzsafe", 1);
2363// #endif 2363// #endif
2364 saveConf(); 2364 saveConf();
2365 } 2365 }
2366 2366
2367 QListViewItem *i; 2367 QListViewItem *i;
2368 // step through all categories 2368 // step through all categories
2369 for (i = ListView->firstChild(); 2369 for (i = ListView->firstChild();
2370 i != NULL; 2370 i != NULL;
2371 i = i->nextSibling()) 2371 i = i->nextSibling())
2372 { 2372 {
2373 // step through all subitems 2373 // step through all subitems
2374 QListViewItem *si; 2374 QListViewItem *si;
2375 for (si = i->firstChild(); 2375 for (si = i->firstChild();
2376 si != NULL; 2376 si != NULL;
2377 si = si->nextSibling()) 2377 si = si->nextSibling())
2378 { 2378 {
2379 int j=0; 2379 int j=0;
2380 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1); 2380 entry[j] = (char*)malloc(strlen(i->text(0).utf8())+1);
2381 strcpy(entry[j++], i->text(0).utf8()); 2381 strcpy(entry[j++], i->text(0).utf8());
2382 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1); 2382 entry[j] = (char*)malloc(strlen(si->text(0).utf8())+1);
2383 strcpy(entry[j++], si->text(0).utf8()); 2383 strcpy(entry[j++], si->text(0).utf8());
2384 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1); 2384 entry[j] = (char*)malloc(strlen(si->text(1).utf8())+1);
2385 strcpy(entry[j++], si->text(1).utf8()); 2385 strcpy(entry[j++], si->text(1).utf8());
2386 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1); 2386 entry[j] = (char*)malloc(strlen(si->text(2).utf8())+1);
2387 strcpy(entry[j++], si->text(2).utf8()); 2387 strcpy(entry[j++], si->text(2).utf8());
2388 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1); 2388 entry[j] = (char*)malloc(strlen(si->text(3).utf8())+1);
2389 strcpy(entry[j++], si->text(3).utf8()); 2389 strcpy(entry[j++], si->text(3).utf8());
2390 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1); 2390 entry[j] = (char*)malloc(strlen(si->text(4).utf8())+1);
2391 strcpy(entry[j++], si->text(4).utf8()); 2391 strcpy(entry[j++], si->text(4).utf8());
2392 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1); 2392 entry[j] = (char*)malloc(strlen(si->text(5).utf8())+1);
2393 strcpy(entry[j++], si->text(5).utf8()); 2393 strcpy(entry[j++], si->text(5).utf8());
2394 2394
2395 retval = saveEntry(entry); 2395 retval = saveEntry(entry);
2396 for (int z=0; z<j; z++) 2396 for (int z=0; z<j; z++)
2397 { 2397 {
2398 free(entry[z]); 2398 free(entry[z]);
2399 } 2399 }
2400 if (retval == PWERR_DATA) { 2400 if (retval == PWERR_DATA) {
2401#ifndef NO_OPIE 2401#ifndef NO_OPIE
2402 owarn << "1: Error writing file, contents not saved" << oendl; 2402 owarn << "1: Error writing file, contents not saved" << oendl;
2403#else 2403#else
2404 qWarning("1: Error writing file, contents not saved"); 2404 qWarning("1: Error writing file, contents not saved");
2405#endif 2405#endif
2406 saveFinalize(); 2406 saveFinalize();
2407 return false; 2407 return false;
2408 } 2408 }
2409 2409
2410 } 2410 }
2411 } 2411 }
2412 2412
2413 if (saveFinalize() == PWERR_DATA) { 2413 if (saveFinalize() == PWERR_DATA) {
2414#ifndef NO_OPIE 2414#ifndef NO_OPIE
2415 owarn << "2: Error writing file, contents not saved" << oendl; 2415 owarn << "2: Error writing file, contents not saved" << oendl;
2416#else 2416#else
2417 qWarning("2: Error writing file, contents not saved"); 2417 qWarning("2: Error writing file, contents not saved");
2418#endif 2418#endif
2419 return false; 2419 return false;
2420 } else { 2420 } else {
2421#ifndef DESKTOP 2421#ifndef DESKTOP
2422 Global::statusMessage (tr("Password file saved.")); 2422 Global::statusMessage (tr("Password file saved."));
2423#endif 2423#endif
2424 modified = false; 2424 modified = false;
2425 return true; 2425 return true;
2426 } 2426 }
2427} 2427}
2428 2428
2429PasswordForm *newPwdDialog; 2429PasswordForm *newPwdDialog;
2430bool newPwdDialogResult = false; 2430bool newPwdDialogResult = false;
2431void ZSafe::setPasswordDialogDone() 2431void ZSafe::setPasswordDialogDone()
2432{ 2432{
2433 newPwdDialogResult = true; 2433 newPwdDialogResult = true;
2434 newPwdDialog->close(); 2434 newPwdDialog->close();
2435} 2435}
2436 2436
2437void ZSafe::getDocPassword(QString title) 2437void ZSafe::getDocPassword(QString title)
2438{ 2438{
2439#ifndef NO_OPIE 2439#ifndef NO_OPIE
2440 owarn << "getDocPassword" << oendl; 2440 owarn << "getDocPassword" << oendl;
2441#endif 2441#endif
2442 // open the 'Password' dialog 2442 // open the 'Password' dialog
2443 PasswordForm *dialog = new PasswordForm(this, title, TRUE); 2443 PasswordForm *dialog = new PasswordForm(this, title, TRUE);
2444 newPwdDialog = dialog; 2444 newPwdDialog = dialog;
2445 newPwdDialogResult = false; 2445 newPwdDialogResult = false;
2446 2446
2447 QPixmap image0( ( const char** ) zsafe_xpm ); 2447 QPixmap image0( ( const char** ) zsafe_xpm );
2448 dialog->setIcon( image0); 2448 dialog->setIcon( image0);
2449 2449
2450 connect( dialog->PasswordField, SIGNAL( returnPressed() ), 2450 connect( dialog->PasswordField, SIGNAL( returnPressed() ),
2451 this, SLOT( setPasswordDialogDone() ) ); 2451 this, SLOT( setPasswordDialogDone() ) );
2452 2452
2453 // CS: !!! 2453 // CS: !!!
2454 // int pos = filename.findRev ('/'); 2454 // int pos = filename.findRev ('/');
2455 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 2455 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
2456#ifdef Q_WS_WIN 2456#ifdef Q_WS_WIN
2457 dialog->setCaption("Qt " + ti); 2457 dialog->setCaption("Qt " + ti);
2458#else 2458#else
2459 dialog->setCaption(ti); 2459 dialog->setCaption(ti);
2460#endif 2460#endif
2461 // dialog->setCaption(title); 2461 // dialog->setCaption(title);
2462 2462
2463 dialog->PasswordField->setFocus(); 2463 dialog->PasswordField->setFocus();
2464 DialogCode result = (DialogCode) dialog->exec(); 2464 DialogCode result = (DialogCode) dialog->exec();
2465#ifdef DESKTOP 2465#ifdef DESKTOP
2466 result = Accepted; 2466 result = Accepted;
2467#endif 2467#endif
2468 2468
2469 QString password; 2469 QString password;
2470 if (result == Accepted || newPwdDialogResult) 2470 if (result == Accepted || newPwdDialogResult)
2471 { 2471 {
2472 m_password = dialog->PasswordField->text(); 2472 m_password = dialog->PasswordField->text();
2473 } 2473 }
2474 else 2474 else
2475 { 2475 {
2476 exitZs (1); 2476 exitZs (1);
2477 } 2477 }
2478} 2478}
2479 2479
2480int ZSafe::saveInit(const char *_filename, const char *password) 2480int ZSafe::saveInit(const char *_filename, const char *password)
2481{ 2481{
2482 char key[128]; 2482 char key[128];
2483 unsigned int j = 0; 2483 unsigned int j = 0;
2484 unsigned int keylength; 2484 unsigned int keylength;
2485 // int val; 2485 // int val;
2486 int count2; 2486 int count2;
2487 Krc2* krc2 = new Krc2(); 2487 Krc2* krc2 = new Krc2();
2488 2488
2489 /* first we should check the permissions of the filename */ 2489 /* first we should check the permissions of the filename */
2490/* 2490/*
2491 if (QFile::exists(_filename)) { 2491 if (QFile::exists(_filename)) {
2492 val = checkFile(_filename); 2492 val = checkFile(_filename);
2493 if (val != PWERR_GOOD) 2493 if (val != PWERR_GOOD)
2494 return val; 2494 return val;
2495 } else 2495 } else
2496 { 2496 {
2497 val = creat (_filename, (S_IRUSR | S_IWUSR)); 2497 val = creat (_filename, (S_IRUSR | S_IWUSR));
2498 if (val == -1) 2498 if (val == -1)
2499 return PWERR_OPEN; 2499 return PWERR_OPEN;
2500 else 2500 else
2501 close(val); 2501 close(val);
2502 } 2502 }
2503*/ 2503*/
2504 QFileInfo f (_filename); 2504 QFileInfo f (_filename);
2505 save_buffer_length = f.size(); 2505 save_buffer_length = f.size();
2506 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024; 2506 save_buffer_length = ((save_buffer_length / 1024)+1) * 1024;
2507 2507
2508 fd = fopen (_filename, "wb"); 2508 fd = fopen (_filename, "wb");
2509 if (fd == NULL) 2509 if (fd == NULL)
2510 return PWERR_OPEN; 2510 return PWERR_OPEN;
2511 2511
2512 buffer = (char*)malloc(save_buffer_length); 2512 buffer = (char*)malloc(save_buffer_length);
2513 2513
2514 /* make the key ready */ 2514 /* make the key ready */
2515 for (j = 0; password[j] != '\0'; j++) { 2515 for (j = 0; password[j] != '\0'; j++) {
2516 key[j] = password[j]; 2516 key[j] = password[j];
2517 } 2517 }
2518 keylength = j; 2518 keylength = j;
2519 krc2->rc2_expandkey (key, keylength, 128); 2519 krc2->rc2_expandkey (key, keylength, 128);
2520 2520
2521 /* First, we make the IV */ 2521 /* First, we make the IV */
2522 for (count2 = 0; count2 < 4; count2++) { 2522 for (count2 = 0; count2 < 4; count2++) {
2523 iv[count2] = rand (); 2523 iv[count2] = rand ();
2524 putc ((unsigned char) (iv[count2] >> 8), fd); 2524 putc ((unsigned char) (iv[count2] >> 8), fd);
2525 putc ((unsigned char) (iv[count2] & 0xff), fd); 2525 putc ((unsigned char) (iv[count2] & 0xff), fd);
2526 } 2526 }
2527 2527
2528 bufferIndex = 0; 2528 bufferIndex = 0;
2529 return PWERR_GOOD; 2529 return PWERR_GOOD;
2530} 2530}
2531 2531
2532 2532
2533int ZSafe::saveEntry(char *entry[FIELD_SIZE]) 2533int ZSafe::saveEntry(char *entry[FIELD_SIZE])
2534{ 2534{
2535 char *text1; 2535 char *text1;
2536 int count2, count3; 2536 int count2, count3;
2537 unsigned short ciphertext[4]; 2537 unsigned short ciphertext[4];
2538 Krc2* krc2 = new Krc2(); 2538 Krc2* krc2 = new Krc2();
2539 2539
2540 buffer = (char*)memset(buffer, '\0', save_buffer_length); 2540 buffer = (char*)memset(buffer, '\0', save_buffer_length);
2541 2541
2542 for (count2 = 0; count2 < FIELD_SIZE; count2++) { 2542 for (count2 = 0; count2 < FIELD_SIZE; count2++) {
2543 text1 = entry[count2]; 2543 text1 = entry[count2];
2544 if (strlen (text1) == 0) { 2544 if (strlen (text1) == 0) {
2545 strncat(buffer, " ", strlen(" ")); 2545 strncat(buffer, " ", strlen(" "));
2546 } else { 2546 } else {
2547 strncat(buffer, text1, strlen(text1)); 2547 strncat(buffer, text1, strlen(text1));
2548 } 2548 }
2549 /* Use 255 as the marker. \n is too tough to test for */ 2549 /* Use 255 as the marker. \n is too tough to test for */
2550 buffer[strlen (buffer)] = 255; 2550 buffer[strlen (buffer)] = 255;
2551 } /*for (count2 = 0; count2 < 5; count2++)*/ 2551 } /*for (count2 = 0; count2 < 5; count2++)*/
2552 count2 = 0; 2552 count2 = 0;
2553 /* I'm using CBC mode and encrypting the data straight from top down. 2553 /* I'm using CBC mode and encrypting the data straight from top down.
2554 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually. 2554 * At the bottom, encrypted, I will append an MD5 hash of the file, eventually.
2555 * PKCS 5 padding (explained at the code section 2555 * PKCS 5 padding (explained at the code section
2556 */ 2556 */
2557 while (count2 < (int)strlen (buffer)) { 2557 while (count2 < (int)strlen (buffer)) {
2558#ifndef WORDS_BIGENDIAN 2558#ifndef WORDS_BIGENDIAN
2559 plaintext[bufferIndex] = buffer[count2 + 1] << 8; 2559 plaintext[bufferIndex] = buffer[count2 + 1] << 8;
2560 plaintext[bufferIndex] += buffer[count2] & 0xff; 2560 plaintext[bufferIndex] += buffer[count2] & 0xff;
2561#endif 2561#endif
2562#ifdef WORDS_BIGENDIAN 2562#ifdef WORDS_BIGENDIAN
2563 plaintext[bufferIndex] = buffer[count2] << 8; 2563 plaintext[bufferIndex] = buffer[count2] << 8;
2564 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff; 2564 plaintext[bufferIndex] += buffer[count2 + 1] & 0xff;
2565#endif 2565#endif
2566 bufferIndex++; 2566 bufferIndex++;
2567 if (bufferIndex == 4) { 2567 if (bufferIndex == 4) {
2568 krc2->rc2_encrypt (plaintext); 2568 krc2->rc2_encrypt (plaintext);
2569 2569
2570 for (count3 = 0; count3 < 4; count3++) { 2570 for (count3 = 0; count3 < 4; count3++) {
2571 ciphertext[count3] = iv[count3] ^ plaintext[count3]; 2571 ciphertext[count3] = iv[count3] ^ plaintext[count3];
2572 2572
2573 /* Now store the ciphertext as the iv */ 2573 /* Now store the ciphertext as the iv */
2574 iv[count3] = plaintext[count3]; 2574 iv[count3] = plaintext[count3];
2575 2575
2576 /* reset the buffer index */ 2576 /* reset the buffer index */
2577 bufferIndex = 0; 2577 bufferIndex = 0;
2578 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA; 2578 if (putc ((unsigned char) (ciphertext[count3] >> 8), fd) == EOF) return PWERR_DATA;
2579 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA; 2579 if (putc ((unsigned char) (ciphertext[count3] & 0xff), fd) == EOF) return PWERR_DATA;
2580 } /*for (count3 = 0; count3 < 5; count3++)*/ 2580 } /*for (count3 = 0; count3 < 5; count3++)*/
2581 } /*if (bufferIndex == 5)*/ 2581 } /*if (bufferIndex == 5)*/
2582 /* increment a short, not a byte */ 2582 /* increment a short, not a byte */
2583 count2 += 2; 2583 count2 += 2;
2584 } /*while (count2 < strlen (buffer))*/ 2584 } /*while (count2 < strlen (buffer))*/
2585 int ret = PWERR_GOOD; 2585 int ret = PWERR_GOOD;
2586 return ret; 2586 return ret;
2587} 2587}
2588 2588
2589int ZSafe::saveFinalize(void) 2589int ZSafe::saveFinalize(void)
2590{ 2590{
2591 int count1, retval = PWERR_GOOD; 2591 int count1, retval = PWERR_GOOD;
2592 unsigned short ciphertext[4]; 2592 unsigned short ciphertext[4];
2593 Krc2* krc2 = new Krc2(); 2593 Krc2* krc2 = new Krc2();
2594 2594
2595 /* Tack on the PKCS 5 padding 2595 /* Tack on the PKCS 5 padding
2596 * How it works is we fill up the last n bytes with the value n 2596 * How it works is we fill up the last n bytes with the value n
2597 * 2597 *
2598 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left 2598 * So, if we have, say, 13 bytes, 8 of which are used, we have 5 left
2599 * over, leaving us 3 short, so we fill it in with 3's. 2599 * over, leaving us 3 short, so we fill it in with 3's.
2600 * 2600 *
2601 * If we come out even, we fill it with 8 8s 2601 * If we come out even, we fill it with 8 8s
2602 * 2602 *
2603 * um, except that in this instance we are using 4 shorts instead of 8 bytes. 2603 * um, except that in this instance we are using 4 shorts instead of 8 bytes.
2604 * so, half everything 2604 * so, half everything
2605 */ 2605 */
2606 for (count1 = bufferIndex; count1 < 4; count1++) { 2606 for (count1 = bufferIndex; count1 < 4; count1++) {
2607 plaintext[count1] = (4 - bufferIndex); 2607 plaintext[count1] = (4 - bufferIndex);
2608 } 2608 }
2609 krc2->rc2_encrypt (plaintext); 2609 krc2->rc2_encrypt (plaintext);
2610 for (count1 = 0; count1 < 4; count1++) { 2610 for (count1 = 0; count1 < 4; count1++) {
2611 ciphertext[count1] = iv[count1] ^ plaintext[count1]; 2611 ciphertext[count1] = iv[count1] ^ plaintext[count1];
2612 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA; 2612 if (putc ((unsigned char) (ciphertext[count1] >> 8), fd) == EOF) retval = PWERR_DATA;
2613 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA; 2613 if (putc ((unsigned char) (ciphertext[count1] & 0xff), fd) == EOF) retval = PWERR_DATA;
2614 } 2614 }
2615 2615
2616 fclose (fd); 2616 fclose (fd);
2617 free(buffer); 2617 free(buffer);
2618 return retval; 2618 return retval;
2619} 2619}
2620 2620
2621void ZSafe::quitMe () 2621void ZSafe::quitMe ()
2622{ 2622{
2623#ifndef NO_OPIE 2623#ifndef NO_OPIE
2624 owarn << "QUIT..." << oendl; 2624 owarn << "QUIT..." << oendl;
2625#endif 2625#endif
2626 2626
2627 if (modified) 2627 if (modified)
2628 { 2628 {
2629 switch( QMessageBox::information( this, tr("ZSafe"), 2629 switch( QMessageBox::information( this, tr("ZSafe"),
2630 tr("Do you want to save\nbefore exiting?"), 2630 tr("Do you want to save\nbefore exiting?"),
2631 tr("&Save"), 2631 tr("&Save"),
2632 tr("S&ave with\nnew\npassword"), 2632 tr("S&ave with\nnew\npassword"),
2633 tr("&Don't Save"), 2633 tr("&Don't Save"),
2634 0 // Enter == button 0 2634 0 // Enter == button 0
2635 ) ) 2635 ) )
2636 { // Escape == button 2 2636 { // Escape == button 2
2637 case 0: // Save clicked, Alt-S or Enter pressed. 2637 case 0: // Save clicked, Alt-S or Enter pressed.
2638 // save 2638 // save
2639 modified = false; 2639 modified = false;
2640 saveDocument(filename, FALSE); 2640 saveDocument(filename, FALSE);
2641 exitZs (1); 2641 exitZs (1);
2642 break; 2642 break;
2643 case 1: // 2643 case 1: //
2644 // Save with new password 2644 // Save with new password
2645 modified = false; 2645 modified = false;
2646 saveDocument(filename, TRUE); 2646 saveDocument(filename, TRUE);
2647 exitZs (1); 2647 exitZs (1);
2648 break; 2648 break;
2649 case 2: // Don't Save clicked or Alt-D pressed 2649 case 2: // Don't Save clicked or Alt-D pressed
2650 // don't save but exitZs 2650 // don't save but exitZs
2651 exitZs (1); 2651 exitZs (1);
2652 break; 2652 break;
2653 } 2653 }
2654 } 2654 }
2655 exitZs (1); 2655 exitZs (1);
2656 2656
2657} 2657}
2658 2658
2659void ZSafe::categoryFieldActivated( const QString& category) 2659void ZSafe::categoryFieldActivated( const QString& category)
2660{ 2660{
2661 if (categoryDialog) 2661 if (categoryDialog)
2662 setCategoryDialogFields(categoryDialog, category); 2662 setCategoryDialogFields(categoryDialog, category);
2663} 2663}
2664 2664
2665void ZSafe::addCategory() 2665void ZSafe::addCategory()
2666{ 2666{
2667 if (filename.isEmpty()) 2667 if (filename.isEmpty())
2668 { 2668 {
2669 QMessageBox::critical( 0, tr("ZSafe"), 2669 QMessageBox::critical( 0, tr("ZSafe"),
2670 tr("No document defined.\nYou have to create a new document")); 2670 tr("No document defined.\nYou have to create a new document"));
2671 return; 2671 return;
2672 } 2672 }
2673 else 2673 else
2674 { 2674 {
2675 // open the 'Category' dialog 2675 // open the 'Category' dialog
2676 bool initIcons = false; 2676 bool initIcons = false;
2677 // open the 'Category' dialog 2677 // open the 'Category' dialog
2678 CategoryDialog *dialog; 2678 CategoryDialog *dialog;
2679 if (categoryDialog) 2679 if (categoryDialog)
2680 { 2680 {
2681 dialog = categoryDialog; 2681 dialog = categoryDialog;
2682 } 2682 }
2683 else 2683 else
2684 { 2684 {
2685 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 2685 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
2686#ifdef Q_WS_WIN 2686#ifdef Q_WS_WIN
2687 categoryDialog->setCaption ("Qt " + tr("Category")); 2687 categoryDialog->setCaption ("Qt " + tr("Category"));
2688#endif 2688#endif
2689 dialog = categoryDialog; 2689 dialog = categoryDialog;
2690 connect( dialog->CategoryField, 2690 connect( dialog->CategoryField,
2691 SIGNAL( activated(const QString&)), 2691 SIGNAL( activated(const QString&)),
2692 this, SLOT( categoryFieldActivated(const QString&) ) ); 2692 this, SLOT( categoryFieldActivated(const QString&) ) );
2693 initIcons = true; 2693 initIcons = true;
2694 } 2694 }
2695 2695
2696#ifdef DESKTOP 2696#ifdef DESKTOP
2697#ifndef Q_WS_WIN 2697#ifndef Q_WS_WIN
2698 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 2698 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
2699#else 2699#else
2700 // read all categories from the config file and store 2700 // read all categories from the config file and store
2701 // into a list 2701 // into a list
2702 QFile f (cfgFile); 2702 QFile f (cfgFile);
2703 QStringList list; 2703 QStringList list;
2704 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2704 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2705 QTextStream t( &f ); // use a text stream 2705 QTextStream t( &f ); // use a text stream
2706 QString s; 2706 QString s;
2707 int n = 1; 2707 int n = 1;
2708 while ( !t.eof() ) { // until end of file... 2708 while ( !t.eof() ) { // until end of file...
2709 s = t.readLine(); // line of text excluding '\n' 2709 s = t.readLine(); // line of text excluding '\n'
2710 list.append(s); 2710 list.append(s);
2711 } 2711 }
2712 f.close(); 2712 f.close();
2713 } 2713 }
2714#endif 2714#endif
2715#else 2715#else
2716 // read all categories from the config file and store 2716 // read all categories from the config file and store
2717 // into a list 2717 // into a list
2718 QFile f (cfgFile); 2718 QFile f (cfgFile);
2719 QStringList list; 2719 QStringList list;
2720 if ( f.open(IO_ReadOnly) ) { // file opened successfully 2720 if ( f.open(IO_ReadOnly) ) { // file opened successfully
2721 QTextStream t( &f ); // use a text stream 2721 QTextStream t( &f ); // use a text stream
2722 QString s; 2722 QString s;
2723 while ( !t.eof() ) { // until end of file... 2723 while ( !t.eof() ) { // until end of file...
2724 s = t.readLine(); // line of text excluding '\n' 2724 s = t.readLine(); // line of text excluding '\n'
2725 list.append(s); 2725 list.append(s);
2726 } 2726 }
2727 f.close(); 2727 f.close();
2728 } 2728 }
2729#endif 2729#endif
2730 QStringList::Iterator it = list.begin(); 2730 QStringList::Iterator it = list.begin();
2731 QString categ; 2731 QString categ;
2732 QString firstCategory; 2732 QString firstCategory;
2733 dialog->CategoryField->clear(); // remove all items 2733 dialog->CategoryField->clear(); // remove all items
2734 while( it != list.end() ) 2734 while( it != list.end() )
2735 { 2735 {
2736 QString *cat = new QString (*it); 2736 QString *cat = new QString (*it);
2737 if (cat->contains("-field1", FALSE)) 2737 if (cat->contains("-field1", FALSE))
2738 { 2738 {
2739#ifdef DESKTOP 2739#ifdef DESKTOP
2740#ifndef Q_WS_WIN 2740#ifndef Q_WS_WIN
2741 categ = cat->section ("-field1", 0, 0); 2741 categ = cat->section ("-field1", 0, 0);
2742#else 2742#else
2743 int pos = cat->find ("-field1"); 2743 int pos = cat->find ("-field1");
2744 categ = cat->left (pos); 2744 categ = cat->left (pos);
2745#endif 2745#endif
2746#else 2746#else
2747 int pos = cat->find ("-field1"); 2747 int pos = cat->find ("-field1");
2748 cat->truncate(pos); 2748 cat->truncate(pos);
2749 categ = *cat; 2749 categ = *cat;
2750#endif 2750#endif
2751 if (!categ.isEmpty()) 2751 if (!categ.isEmpty())
2752 { 2752 {
2753 dialog->CategoryField->insertItem (categ, -1); 2753 dialog->CategoryField->insertItem (categ, -1);
2754 if (firstCategory.isEmpty()) 2754 if (firstCategory.isEmpty())
2755 firstCategory = categ; 2755 firstCategory = categ;
2756 } 2756 }
2757 } 2757 }
2758 ++it; 2758 ++it;
2759 } 2759 }
2760 2760
2761 2761
2762 if (firstCategory.isEmpty()) 2762 if (firstCategory.isEmpty())
2763 setCategoryDialogFields(dialog); 2763 setCategoryDialogFields(dialog);
2764 else 2764 else
2765 setCategoryDialogFields(dialog, firstCategory); 2765 setCategoryDialogFields(dialog, firstCategory);
2766 2766
2767 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE); 2767 // CategoryDialog *dialog = new CategoryDialog(this, "Category", TRUE);
2768 2768
2769 if (initIcons) 2769 if (initIcons)
2770 { 2770 {
2771 Wait waitDialog(this, tr("Wait dialog")); 2771 Wait waitDialog(this, tr("Wait dialog"));
2772 waitDialog.waitLabel->setText(tr("Gathering icons...")); 2772 waitDialog.waitLabel->setText(tr("Gathering icons..."));
2773 waitDialog.show(); 2773 waitDialog.show();
2774 qApp->processEvents(); 2774 qApp->processEvents();
2775 2775
2776#ifdef DESKTOP 2776#ifdef DESKTOP
2777 QDir d(iconPath); 2777 QDir d(iconPath);
2778#else 2778#else
2779 QDir d(QPEApplication::qpeDir() + "/pics/"); 2779 QDir d(QPEApplication::qpeDir() + "pics/");
2780#endif 2780#endif
2781 d.setFilter( QDir::Files); 2781 d.setFilter( QDir::Files);
2782 2782
2783 const QFileInfoList *list = d.entryInfoList(); 2783 const QFileInfoList *list = d.entryInfoList();
2784 QFileInfoListIterator it( *list ); // create list iterator 2784 QFileInfoListIterator it( *list ); // create list iterator
2785 QFileInfo *fi; // pointer for traversing 2785 QFileInfo *fi; // pointer for traversing
2786 2786
2787 dialog->IconField->insertItem("predefined"); 2787 dialog->IconField->insertItem("predefined");
2788 while ( (fi=it.current()) ) { // for each file... 2788 while ( (fi=it.current()) ) { // for each file...
2789 QString fileName = fi->fileName(); 2789 QString fileName = fi->fileName();
2790 if(fileName.right(4) == ".png"){ 2790 if(fileName.right(4) == ".png"){
2791 fileName = fileName.mid(0,fileName.length()-4); 2791 fileName = fileName.mid(0,fileName.length()-4);
2792#ifdef DESKTOP 2792#ifdef DESKTOP
2793 QPixmap imageOfFile; 2793 QPixmap imageOfFile;
2794 imageOfFile.load(iconPath + fi->fileName()); 2794 imageOfFile.load(iconPath + fi->fileName());
2795#else 2795#else
2796 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 2796 QPixmap imageOfFile(Resource::loadPixmap(fileName));
2797#endif 2797#endif
2798 QImage foo = imageOfFile.convertToImage(); 2798 QImage foo = imageOfFile.convertToImage();
2799 foo = foo.smoothScale(16,16); 2799 foo = foo.smoothScale(16,16);
2800 imageOfFile.convertFromImage(foo); 2800 imageOfFile.convertFromImage(foo);
2801 dialog->IconField->insertItem(imageOfFile,fileName); 2801 dialog->IconField->insertItem(imageOfFile,fileName);
2802 } 2802 }
2803 ++it; 2803 ++it;
2804 } 2804 }
2805 waitDialog.hide(); 2805 waitDialog.hide();
2806 } 2806 }
2807 2807
2808#ifndef Q_WS_WIN 2808#ifndef Q_WS_WIN
2809 dialog->show(); 2809 dialog->show();
2810#endif 2810#endif
2811#ifndef DESKTOP 2811#ifndef DESKTOP
2812 // dialog->move (20, 100); 2812 // dialog->move (20, 100);
2813#endif 2813#endif
2814 DialogCode result = (DialogCode) dialog->exec(); 2814 DialogCode result = (DialogCode) dialog->exec();
2815#ifdef DESKTOP 2815#ifdef DESKTOP
2816 result = Accepted; 2816 result = Accepted;
2817#endif 2817#endif
2818 2818
2819 QString category; 2819 QString category;
2820 QString icon; 2820 QString icon;
2821 QString fullIconPath; 2821 QString fullIconPath;
2822 QPixmap *pix; 2822 QPixmap *pix;
2823 if (result == Accepted) 2823 if (result == Accepted)
2824 { 2824 {
2825 modified = true; 2825 modified = true;
2826 category = dialog->CategoryField->currentText(); 2826 category = dialog->CategoryField->currentText();
2827 icon = dialog->IconField->currentText()+".png"; 2827 icon = dialog->IconField->currentText()+".png";
2828 2828
2829#ifndef NO_OPIE 2829#ifndef NO_OPIE
2830 owarn << category << oendl; 2830 owarn << category << oendl;
2831#endif 2831#endif
2832 2832
2833 QListViewItem *li = new ShadedListItem( 1, ListView ); 2833 QListViewItem *li = new ShadedListItem( 1, ListView );
2834 Category *c1 = new Category(); 2834 Category *c1 = new Category();
2835 c1->setCategoryName(category); 2835 c1->setCategoryName(category);
2836 2836
2837 // if (!icon.isEmpty() && !icon.isNull()) 2837 // if (!icon.isEmpty() && !icon.isNull())
2838 if (icon != "predefined.png") 2838 if (icon != "predefined.png")
2839 { 2839 {
2840 // build the full path 2840 // build the full path
2841 fullIconPath = iconPath + icon; 2841 fullIconPath = iconPath + icon;
2842 pix = new QPixmap (fullIconPath); 2842 pix = new QPixmap (fullIconPath);
2843 // pix->resize(14, 14); 2843 // pix->resize(14, 14);
2844 if (!pix->isNull()) 2844 if (!pix->isNull())
2845 { 2845 {
2846 // save the full pixmap name into the config file 2846 // save the full pixmap name into the config file
2847// #ifndef Q_WS_WIN 2847// #ifndef Q_WS_WIN
2848 conf->writeEntry(APP_KEY+category, icon); 2848 conf->writeEntry(APP_KEY+category, icon);
2849// #endif 2849// #endif
2850 saveConf(); 2850 saveConf();
2851 QImage img = pix->convertToImage(); 2851 QImage img = pix->convertToImage();
2852 pix->convertFromImage(img.smoothScale(14,14)); 2852 pix->convertFromImage(img.smoothScale(14,14));
2853 c1->setIcon (*pix); 2853 c1->setIcon (*pix);
2854 c1->setIconName(icon); 2854 c1->setIconName(icon);
2855 } 2855 }
2856 else 2856 else
2857 { 2857 {
2858 QPixmap folder( ( const char** ) general_data ); 2858 QPixmap folder( ( const char** ) general_data );
2859 c1->setIcon (folder); 2859 c1->setIcon (folder);
2860 } 2860 }
2861 } 2861 }
2862 else 2862 else
2863 { 2863 {
2864 c1->setIcon (*getPredefinedIcon(category)); 2864 c1->setIcon (*getPredefinedIcon(category));
2865 } 2865 }
2866 2866
2867 c1->setListItem (li); 2867 c1->setListItem (li);
2868 c1->initListItem(); 2868 c1->initListItem();
2869 categories.insert (c1->getCategoryName(), c1); 2869 categories.insert (c1->getCategoryName(), c1);
2870 2870
2871 saveCategoryDialogFields(dialog); 2871 saveCategoryDialogFields(dialog);
2872 } 2872 }
2873 else 2873 else
2874 { 2874 {
2875 // delete dialog; 2875 // delete dialog;
2876 dialog->hide(); 2876 dialog->hide();
2877 return; 2877 return;
2878 } 2878 }
2879 2879
2880 } 2880 }
2881 2881
2882} 2882}
2883 2883
2884void ZSafe::delCategory() 2884void ZSafe::delCategory()
2885{ 2885{
2886 if (!selectedItem) 2886 if (!selectedItem)
2887 return; 2887 return;
2888 if (isCategory(selectedItem)) 2888 if (isCategory(selectedItem))
2889 { 2889 {
2890 switch( QMessageBox::information( this, tr("ZSafe"), 2890 switch( QMessageBox::information( this, tr("ZSafe"),
2891 tr("Do you want to delete?"), 2891 tr("Do you want to delete?"),
2892 tr("&Delete"), tr("D&on't Delete"), 2892 tr("&Delete"), tr("D&on't Delete"),
2893 0 // Enter == button 0 2893 0 // Enter == button 0
2894 ) ) { // Escape == button 2 2894 ) ) { // Escape == button 2
2895 case 0: // Delete clicked, Alt-S or Enter pressed. 2895 case 0: // Delete clicked, Alt-S or Enter pressed.
2896 // Delete from the category list 2896 // Delete from the category list
2897 modified = true; 2897 modified = true;
2898 categories.remove (selectedItem->text(0)); 2898 categories.remove (selectedItem->text(0));
2899// #ifndef Q_WS_WIN 2899// #ifndef Q_WS_WIN
2900 conf->removeEntry (selectedItem->text(0)); 2900 conf->removeEntry (selectedItem->text(0));
2901// #endif 2901// #endif
2902 saveConf(); 2902 saveConf();
2903 2903
2904 // Delete the selected item and all subitems 2904 // Delete the selected item and all subitems
2905 // step through all subitems 2905 // step through all subitems
2906 QListViewItem *si; 2906 QListViewItem *si;
2907 for (si = selectedItem->firstChild(); 2907 for (si = selectedItem->firstChild();
2908 si != NULL; ) 2908 si != NULL; )
2909 { 2909 {
2910 QListViewItem *_si = si; 2910 QListViewItem *_si = si;
2911 si = si->nextSibling(); 2911 si = si->nextSibling();
2912 selectedItem->takeItem(_si); // remove from view list 2912 selectedItem->takeItem(_si); // remove from view list
2913 if (_si) delete _si; 2913 if (_si) delete _si;
2914 } 2914 }
2915 ListView->takeItem(selectedItem); 2915 ListView->takeItem(selectedItem);
2916 delete selectedItem; 2916 delete selectedItem;
2917 2917
2918 selectedItem = NULL; 2918 selectedItem = NULL;
2919 break; 2919 break;
2920 case 1: // Don't delete 2920 case 1: // Don't delete
2921 break; 2921 break;
2922 } 2922 }
2923 2923
2924 } 2924 }
2925} 2925}
2926 2926
2927void ZSafe::setCategoryDialogFields(CategoryDialog *dialog) 2927void ZSafe::setCategoryDialogFields(CategoryDialog *dialog)
2928{ 2928{
2929 if (!dialog) 2929 if (!dialog)
2930 return; 2930 return;
2931 2931
2932 QString icon; 2932 QString icon;
2933 if (selectedItem) 2933 if (selectedItem)
2934 { 2934 {
2935 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name"))); 2935 dialog->Field1->setText(getFieldLabel (selectedItem, "1", tr("Name")));
2936 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username"))); 2936 dialog->Field2->setText(getFieldLabel (selectedItem, "2", tr("Username")));
2937 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password"))); 2937 dialog->Field3->setText(getFieldLabel (selectedItem, "3", tr("Password")));
2938 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment"))); 2938 dialog->Field4->setText(getFieldLabel (selectedItem, "4", tr("Comment")));
2939 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4"))); 2939 dialog->Field5->setText(getFieldLabel (selectedItem, "5", tr("Field 4")));
2940 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5"))); 2940 dialog->Field6->setText(getFieldLabel (selectedItem, "6", tr("Field 5")));
2941 2941
2942 Category *cat= categories.find (selectedItem->text(0)); 2942 Category *cat= categories.find (selectedItem->text(0));
2943 if (cat) 2943 if (cat)
2944 { 2944 {
2945 icon = cat->getIconName(); 2945 icon = cat->getIconName();
2946 } 2946 }
2947 else 2947 else
2948 icon = conf->readEntry(APP_KEY+selectedItem->text(0)); 2948 icon = conf->readEntry(APP_KEY+selectedItem->text(0));
2949 } 2949 }
2950 else 2950 else
2951 { 2951 {
2952 dialog->Field1->setText(tr("Name")); 2952 dialog->Field1->setText(tr("Name"));
2953 dialog->Field2->setText(tr("Username")); 2953 dialog->Field2->setText(tr("Username"));
2954 dialog->Field3->setText(tr("Password")); 2954 dialog->Field3->setText(tr("Password"));
2955 dialog->Field4->setText(tr("Comment")); 2955 dialog->Field4->setText(tr("Comment"));
2956 dialog->Field5->setText(tr("Field 4")); 2956 dialog->Field5->setText(tr("Field 4"));
2957 dialog->Field6->setText(tr("Field 5")); 2957 dialog->Field6->setText(tr("Field 5"));
2958 } 2958 }
2959 2959
2960#ifdef DESKTOP 2960#ifdef DESKTOP
2961 QDir d(iconPath); 2961 QDir d(iconPath);
2962#else 2962#else
2963 QDir d(QPEApplication::qpeDir() + "/pics/"); 2963 QDir d(QPEApplication::qpeDir() + "pics/");
2964#endif 2964#endif
2965 d.setFilter( QDir::Files); 2965 d.setFilter( QDir::Files);
2966 2966
2967 const QFileInfoList *list = d.entryInfoList(); 2967 const QFileInfoList *list = d.entryInfoList();
2968 int i=0; 2968 int i=0;
2969 QFileInfoListIterator it( *list ); // create list iterator 2969 QFileInfoListIterator it( *list ); // create list iterator
2970 QFileInfo *fi; // pointer for traversing 2970 QFileInfo *fi; // pointer for traversing
2971 if (icon.isEmpty() || icon.isNull()) 2971 if (icon.isEmpty() || icon.isNull())
2972 { 2972 {
2973 dialog->IconField->setCurrentItem(0); 2973 dialog->IconField->setCurrentItem(0);
2974 } 2974 }
2975 else 2975 else
2976 { 2976 {
2977 while ( (fi=it.current()) ) 2977 while ( (fi=it.current()) )
2978 { // for each file... 2978 { // for each file...
2979 QString fileName = fi->fileName(); 2979 QString fileName = fi->fileName();
2980 if(fileName.right(4) == ".png") 2980 if(fileName.right(4) == ".png")
2981 { 2981 {
2982 fileName = fileName.mid(0,fileName.length()-4); 2982 fileName = fileName.mid(0,fileName.length()-4);
2983 2983
2984 if(fileName+".png"==icon) 2984 if(fileName+".png"==icon)
2985 { 2985 {
2986 dialog->IconField->setCurrentItem(i+1); 2986 dialog->IconField->setCurrentItem(i+1);
2987 break; 2987 break;
2988 } 2988 }
2989 ++i; 2989 ++i;
2990 } 2990 }
2991 ++it; 2991 ++it;
2992 } 2992 }
2993 } 2993 }
2994} 2994}
2995 2995
2996void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category) 2996void ZSafe::setCategoryDialogFields(CategoryDialog *dialog, QString category)
2997{ 2997{
2998 if (!dialog) 2998 if (!dialog)
2999 return; 2999 return;
3000 3000
3001 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name"))); 3001 dialog->Field1->setText(getFieldLabel (category, "1", tr("Name")));
3002 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username"))); 3002 dialog->Field2->setText(getFieldLabel (category, "2", tr("Username")));
3003 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password"))); 3003 dialog->Field3->setText(getFieldLabel (category, "3", tr("Password")));
3004 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment"))); 3004 dialog->Field4->setText(getFieldLabel (category, "4", tr("Comment")));
3005 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4"))); 3005 dialog->Field5->setText(getFieldLabel (category, "5", tr("Field 4")));
3006 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5"))); 3006 dialog->Field6->setText(getFieldLabel (category, "6", tr("Field 5")));
3007 3007
3008 QString icon; 3008 QString icon;
3009 Category *cat= categories.find (category); 3009 Category *cat= categories.find (category);
3010 if (cat) 3010 if (cat)
3011 { 3011 {
3012 icon = cat->getIconName(); 3012 icon = cat->getIconName();
3013 } 3013 }
3014 else 3014 else
3015 icon = conf->readEntry(APP_KEY+category); 3015 icon = conf->readEntry(APP_KEY+category);
3016 3016
3017#ifdef DESKTOP 3017#ifdef DESKTOP
3018 QDir d(iconPath); 3018 QDir d(iconPath);
3019#else 3019#else
3020 QDir d(QPEApplication::qpeDir() + "/pics/"); 3020 QDir d(QPEApplication::qpeDir() + "pics/");
3021#endif 3021#endif
3022 d.setFilter( QDir::Files); 3022 d.setFilter( QDir::Files);
3023 3023
3024 const QFileInfoList *list = d.entryInfoList(); 3024 const QFileInfoList *list = d.entryInfoList();
3025 int i=0; 3025 int i=0;
3026 QFileInfoListIterator it( *list ); // create list iterator 3026 QFileInfoListIterator it( *list ); // create list iterator
3027 QFileInfo *fi; // pointer for traversing 3027 QFileInfo *fi; // pointer for traversing
3028 if (icon.isEmpty() || icon.isNull()) 3028 if (icon.isEmpty() || icon.isNull())
3029 { 3029 {
3030 dialog->IconField->setCurrentItem(0); 3030 dialog->IconField->setCurrentItem(0);
3031 } 3031 }
3032 else 3032 else
3033 { 3033 {
3034 while ( (fi=it.current()) ) 3034 while ( (fi=it.current()) )
3035 { // for each file... 3035 { // for each file...
3036 QString fileName = fi->fileName(); 3036 QString fileName = fi->fileName();
3037 if(fileName.right(4) == ".png") 3037 if(fileName.right(4) == ".png")
3038 { 3038 {
3039 fileName = fileName.mid(0,fileName.length()-4); 3039 fileName = fileName.mid(0,fileName.length()-4);
3040 3040
3041 if(fileName+".png"==icon) 3041 if(fileName+".png"==icon)
3042 { 3042 {
3043 dialog->IconField->setCurrentItem(i+1); 3043 dialog->IconField->setCurrentItem(i+1);
3044 break; 3044 break;
3045 } 3045 }
3046 ++i; 3046 ++i;
3047 } 3047 }
3048 ++it; 3048 ++it;
3049 } 3049 }
3050 } 3050 }
3051} 3051}
3052 3052
3053void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog) 3053void ZSafe::saveCategoryDialogFields(CategoryDialog *dialog)
3054{ 3054{
3055 QString app_key = APP_KEY; 3055 QString app_key = APP_KEY;
3056#ifndef DESKTOP 3056#ifndef DESKTOP
3057 conf->setGroup ("fieldDefs"); 3057 conf->setGroup ("fieldDefs");
3058#else 3058#else
3059#ifndef Q_WS_WIN 3059#ifndef Q_WS_WIN
3060 app_key += "/fieldDefs/"; 3060 app_key += "/fieldDefs/";
3061#endif 3061#endif
3062#endif 3062#endif
3063 QString category = dialog->CategoryField->currentText(); 3063 QString category = dialog->CategoryField->currentText();
3064// #ifndef Q_WS_WIN 3064// #ifndef Q_WS_WIN
3065 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text()); 3065 conf->writeEntry(app_key+category+"-field1", dialog->Field1->text());
3066 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text()); 3066 conf->writeEntry(app_key+category+"-field2", dialog->Field2->text());
3067 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text()); 3067 conf->writeEntry(app_key+category+"-field3", dialog->Field3->text());
3068 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text()); 3068 conf->writeEntry(app_key+category+"-field4", dialog->Field4->text());
3069 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text()); 3069 conf->writeEntry(app_key+category+"-field5", dialog->Field5->text());
3070 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text()); 3070 conf->writeEntry(app_key+category+"-field6", dialog->Field6->text());
3071// #endif 3071// #endif
3072 saveConf(); 3072 saveConf();
3073#ifndef DESKTOP 3073#ifndef DESKTOP
3074 conf->setGroup ("zsafe"); 3074 conf->setGroup ("zsafe");
3075#endif 3075#endif
3076} 3076}
3077 3077
3078void ZSafe::editCategory() 3078void ZSafe::editCategory()
3079{ 3079{
3080 if (!selectedItem) 3080 if (!selectedItem)
3081 return; 3081 return;
3082 if (isCategory(selectedItem)) 3082 if (isCategory(selectedItem))
3083 { 3083 {
3084 QString category = selectedItem->text(0); 3084 QString category = selectedItem->text(0);
3085 bool initIcons = false; 3085 bool initIcons = false;
3086 // open the 'Category' dialog 3086 // open the 'Category' dialog
3087 CategoryDialog *dialog; 3087 CategoryDialog *dialog;
3088 if (categoryDialog) 3088 if (categoryDialog)
3089 { 3089 {
3090 dialog = categoryDialog; 3090 dialog = categoryDialog;
3091 } 3091 }
3092 else 3092 else
3093 { 3093 {
3094 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE); 3094 categoryDialog = new CategoryDialog(this, tr("Category"), TRUE);
3095#ifdef Q_WS_WIN 3095#ifdef Q_WS_WIN
3096 categoryDialog->setCaption ("Qt " + tr("Category")); 3096 categoryDialog->setCaption ("Qt " + tr("Category"));
3097#endif 3097#endif
3098 dialog = categoryDialog; 3098 dialog = categoryDialog;
3099 connect( dialog->CategoryField, 3099 connect( dialog->CategoryField,
3100 SIGNAL( activated(const QString&)), 3100 SIGNAL( activated(const QString&)),
3101 this, SLOT( categoryFieldActivated(const QString&) ) ); 3101 this, SLOT( categoryFieldActivated(const QString&) ) );
3102 initIcons = true; 3102 initIcons = true;
3103 } 3103 }
3104 setCategoryDialogFields(dialog); 3104 setCategoryDialogFields(dialog);
3105 3105
3106#ifdef DESKTOP 3106#ifdef DESKTOP
3107#ifndef Q_WS_WIN 3107#ifndef Q_WS_WIN
3108 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" ); 3108 QStringList list = conf->entryList( APP_KEY+"/fieldDefs" );
3109#else 3109#else
3110 // read all categories from the config file and store 3110 // read all categories from the config file and store
3111 // into a list 3111 // into a list
3112 QFile f (cfgFile); 3112 QFile f (cfgFile);
3113 QStringList list; 3113 QStringList list;
3114 if ( f.open(IO_ReadOnly) ) { // file opened successfully 3114 if ( f.open(IO_ReadOnly) ) { // file opened successfully
3115 QTextStream t( &f ); // use a text stream 3115 QTextStream t( &f ); // use a text stream
3116 QString s; 3116 QString s;
3117 int n = 1; 3117 int n = 1;
3118 while ( !t.eof() ) { // until end of file... 3118 while ( !t.eof() ) { // until end of file...
3119 s = t.readLine(); // line of text excluding '\n' 3119 s = t.readLine(); // line of text excluding '\n'
3120 list.append(s); 3120 list.append(s);
3121 } 3121 }
3122 f.close(); 3122 f.close();
3123 } 3123 }
3124#endif 3124#endif
3125#else 3125#else
3126 // read all categories from the config file and store 3126 // read all categories from the config file and store
3127 // into a list 3127 // into a list
3128 QFile f (cfgFile); 3128 QFile f (cfgFile);
3129 QStringList list; 3129 QStringList list;
3130 if ( f.open(IO_ReadOnly) ) { // file opened successfully 3130 if ( f.open(IO_ReadOnly) ) { // file opened successfully
3131 QTextStream t( &f ); // use a text stream 3131 QTextStream t( &f ); // use a text stream
3132 QString s; 3132 QString s;
3133 while ( !t.eof() ) { // until end of file... 3133 while ( !t.eof() ) { // until end of file...
3134 s = t.readLine(); // line of text excluding '\n' 3134 s = t.readLine(); // line of text excluding '\n'
3135 list.append(s); 3135 list.append(s);
3136 } 3136 }
3137 f.close(); 3137 f.close();
3138 } 3138 }
3139#endif 3139#endif
3140 QStringList::Iterator it = list.begin(); 3140 QStringList::Iterator it = list.begin();
3141 QString categ; 3141 QString categ;
3142 dialog->CategoryField->clear(); // remove all items 3142 dialog->CategoryField->clear(); // remove all items
3143 int i=0; 3143 int i=0;
3144 bool foundCategory = false; 3144 bool foundCategory = false;
3145 while( it != list.end() ) 3145 while( it != list.end() )
3146 { 3146 {
3147 QString *cat = new QString (*it); 3147 QString *cat = new QString (*it);
3148 if (cat->contains("-field1", FALSE)) 3148 if (cat->contains("-field1", FALSE))
3149 { 3149 {
3150#ifdef DESKTOP 3150#ifdef DESKTOP
3151#ifndef Q_WS_WIN 3151#ifndef Q_WS_WIN
3152 categ = cat->section ("-field1", 0, 0); 3152 categ = cat->section ("-field1", 0, 0);
3153#else 3153#else
3154 int pos = cat->find ("-field1"); 3154 int pos = cat->find ("-field1");
3155 categ = cat->left (pos); 3155 categ = cat->left (pos);
3156#endif 3156#endif
3157#else 3157#else
3158 int pos = cat->find ("-field1"); 3158 int pos = cat->find ("-field1");
3159 cat->truncate(pos); 3159 cat->truncate(pos);
3160 categ = *cat; 3160 categ = *cat;
3161#endif 3161#endif
3162 if (!categ.isEmpty()) 3162 if (!categ.isEmpty())
3163 { 3163 {
3164 dialog->CategoryField->insertItem (categ, i); 3164 dialog->CategoryField->insertItem (categ, i);
3165 if (category.compare(categ) == 0) 3165 if (category.compare(categ) == 0)
3166 { 3166 {
3167 dialog->CategoryField->setCurrentItem(i); 3167 dialog->CategoryField->setCurrentItem(i);
3168 foundCategory = true; 3168 foundCategory = true;
3169 } 3169 }
3170 i++; 3170 i++;
3171 } 3171 }
3172 } 3172 }
3173 ++it; 3173 ++it;
3174 } 3174 }
3175 if (!foundCategory) 3175 if (!foundCategory)
3176 { 3176 {
3177 dialog->CategoryField->insertItem (category, i); 3177 dialog->CategoryField->insertItem (category, i);
3178 dialog->CategoryField->setCurrentItem(i); 3178 dialog->CategoryField->setCurrentItem(i);
3179 } 3179 }
3180 3180
3181 QString icon; 3181 QString icon;
3182 Category *cat= categories.find (selectedItem->text(0)); 3182 Category *cat= categories.find (selectedItem->text(0));
3183 if (cat) 3183 if (cat)
3184 { 3184 {
3185 icon = cat->getIconName(); 3185 icon = cat->getIconName();
3186 } 3186 }
3187 3187
3188 if (initIcons) 3188 if (initIcons)
3189 { 3189 {
3190 3190
3191 Wait waitDialog(this, tr("Wait dialog")); 3191 Wait waitDialog(this, tr("Wait dialog"));
3192 waitDialog.waitLabel->setText(tr("Gathering icons...")); 3192 waitDialog.waitLabel->setText(tr("Gathering icons..."));
3193 waitDialog.show(); 3193 waitDialog.show();
3194 qApp->processEvents(); 3194 qApp->processEvents();
3195 3195
3196#ifdef DESKTOP 3196#ifdef DESKTOP
3197 QDir d(iconPath); 3197 QDir d(iconPath);
3198#else 3198#else
3199 QDir d(QPEApplication::qpeDir() + "/pics/"); 3199 QDir d(QPEApplication::qpeDir() + "pics/");
3200#endif 3200#endif
3201 d.setFilter( QDir::Files); 3201 d.setFilter( QDir::Files);
3202 3202
3203 const QFileInfoList *list = d.entryInfoList(); 3203 const QFileInfoList *list = d.entryInfoList();
3204 int i=0; 3204 int i=0;
3205 QFileInfoListIterator it( *list ); // create list iterator 3205 QFileInfoListIterator it( *list ); // create list iterator
3206 QFileInfo *fi; // pointer for traversing 3206 QFileInfo *fi; // pointer for traversing
3207 if (icon.isEmpty() || icon.isNull()) 3207 if (icon.isEmpty() || icon.isNull())
3208 { 3208 {
3209 dialog->IconField->setCurrentItem(0); 3209 dialog->IconField->setCurrentItem(0);
3210 } 3210 }
3211 3211
3212 dialog->IconField->insertItem("predefined"); 3212 dialog->IconField->insertItem("predefined");
3213 while ( (fi=it.current()) ) { // for each file... 3213 while ( (fi=it.current()) ) { // for each file...
3214 QString fileName = fi->fileName(); 3214 QString fileName = fi->fileName();
3215 if(fileName.right(4) == ".png") 3215 if(fileName.right(4) == ".png")
3216 { 3216 {
3217 fileName = fileName.mid(0,fileName.length()-4); 3217 fileName = fileName.mid(0,fileName.length()-4);
3218#ifdef DESKTOP 3218#ifdef DESKTOP
3219 QPixmap imageOfFile; 3219 QPixmap imageOfFile;
3220 imageOfFile.load(iconPath + fi->fileName()); 3220 imageOfFile.load(iconPath + fi->fileName());
3221#else 3221#else
3222 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 3222 QPixmap imageOfFile(Resource::loadPixmap(fileName));
3223#endif 3223#endif
3224 QImage foo = imageOfFile.convertToImage(); 3224 QImage foo = imageOfFile.convertToImage();
3225 foo = foo.smoothScale(16,16); 3225 foo = foo.smoothScale(16,16);
3226 imageOfFile.convertFromImage(foo); 3226 imageOfFile.convertFromImage(foo);
3227 dialog->IconField->insertItem(imageOfFile,fileName); 3227 dialog->IconField->insertItem(imageOfFile,fileName);
3228 if(fileName+".png"==icon) 3228 if(fileName+".png"==icon)
3229 dialog->IconField->setCurrentItem(i+1); 3229 dialog->IconField->setCurrentItem(i+1);
3230 ++i; 3230 ++i;
3231 } 3231 }
3232 ++it; 3232 ++it;
3233 } 3233 }
3234 waitDialog.hide(); 3234 waitDialog.hide();
3235 } 3235 }
3236 else 3236 else
3237 { 3237 {
3238#ifdef DESKTOP 3238#ifdef DESKTOP
3239 // QDir d(QDir::homeDirPath() + "/pics/"); 3239 // QDir d(QDir::homeDirPath() + "/pics/");
3240 QDir d(iconPath); 3240 QDir d(iconPath);
3241#else 3241#else
3242 QDir d(QPEApplication::qpeDir() + "/pics/"); 3242 QDir d(QPEApplication::qpeDir() + "pics/");
3243#endif 3243#endif
3244 d.setFilter( QDir::Files); 3244 d.setFilter( QDir::Files);
3245 3245
3246 const QFileInfoList *list = d.entryInfoList(); 3246 const QFileInfoList *list = d.entryInfoList();
3247 int i=0; 3247 int i=0;
3248 QFileInfoListIterator it( *list ); // create list iterator 3248 QFileInfoListIterator it( *list ); // create list iterator
3249 QFileInfo *fi; // pointer for traversing 3249 QFileInfo *fi; // pointer for traversing
3250 if (icon.isEmpty() || icon.isNull()) 3250 if (icon.isEmpty() || icon.isNull())
3251 { 3251 {
3252 dialog->IconField->setCurrentItem(0); 3252 dialog->IconField->setCurrentItem(0);
3253 } 3253 }
3254 else 3254 else
3255 { 3255 {
3256 3256
3257 while ( (fi=it.current()) ) 3257 while ( (fi=it.current()) )
3258 { // for each file... 3258 { // for each file...
3259 QString fileName = fi->fileName(); 3259 QString fileName = fi->fileName();
3260 if(fileName.right(4) == ".png") 3260 if(fileName.right(4) == ".png")
3261 { 3261 {
3262 fileName = fileName.mid(0,fileName.length()-4); 3262 fileName = fileName.mid(0,fileName.length()-4);
3263 3263
3264 3264
3265 if(fileName+".png"==icon) 3265 if(fileName+".png"==icon)
3266 { 3266 {
3267 dialog->IconField->setCurrentItem(i+1); 3267 dialog->IconField->setCurrentItem(i+1);
3268 break; 3268 break;
3269 } 3269 }
3270 ++i; 3270 ++i;
3271 } 3271 }
3272 ++it; 3272 ++it;
3273 } 3273 }
3274 } 3274 }
3275 } 3275 }
3276 3276
3277 // dialog->show(); 3277 // dialog->show();
3278#ifndef DESKTOP 3278#ifndef DESKTOP
3279 // dialog->move (20, 100); 3279 // dialog->move (20, 100);
3280#endif 3280#endif
3281 DialogCode result = (DialogCode) dialog->exec(); 3281 DialogCode result = (DialogCode) dialog->exec();
3282#ifdef DESKTOP 3282#ifdef DESKTOP
3283 result = Accepted; 3283 result = Accepted;
3284#endif 3284#endif
3285 3285
3286 QString fullIconPath; 3286 QString fullIconPath;
3287 QPixmap *pix; 3287 QPixmap *pix;
3288 if (result == Accepted) 3288 if (result == Accepted)
3289 { 3289 {
3290 modified = true; 3290 modified = true;
3291 if (category != dialog->CategoryField->currentText()) 3291 if (category != dialog->CategoryField->currentText())
3292 { 3292 {
3293 categories.remove (category); 3293 categories.remove (category);
3294// #ifndef Q_WS_WIN 3294// #ifndef Q_WS_WIN
3295 conf->removeEntry(category); 3295 conf->removeEntry(category);
3296// #endif 3296// #endif
3297 saveConf(); 3297 saveConf();
3298 } 3298 }
3299 3299
3300 category = dialog->CategoryField->currentText(); 3300 category = dialog->CategoryField->currentText();
3301 icon = dialog->IconField->currentText()+".png"; 3301 icon = dialog->IconField->currentText()+".png";
3302 3302
3303 if (cat) 3303 if (cat)
3304 { 3304 {
3305#ifndef NO_OPIE 3305#ifndef NO_OPIE
3306 owarn << "Category found" << oendl; 3306 owarn << "Category found" << oendl;
3307#else 3307#else
3308 qWarning("Category found"); 3308 qWarning("Category found");
3309#endif 3309#endif
3310 3310
3311 // if (!icon.isEmpty() && !icon.isNull()) 3311 // if (!icon.isEmpty() && !icon.isNull())
3312 if (icon != "predefined.png") 3312 if (icon != "predefined.png")
3313 { 3313 {
3314 // build the full path 3314 // build the full path
3315 fullIconPath = iconPath + icon; 3315 fullIconPath = iconPath + icon;
3316 pix = new QPixmap (fullIconPath); 3316 pix = new QPixmap (fullIconPath);
3317 if (!pix->isNull()) 3317 if (!pix->isNull())
3318 { 3318 {
3319 // save the full pixmap name into the config file 3319 // save the full pixmap name into the config file
3320// #ifndef Q_WS_WIN 3320// #ifndef Q_WS_WIN
3321 conf->writeEntry(APP_KEY+category, icon); 3321 conf->writeEntry(APP_KEY+category, icon);
3322// #endif 3322// #endif
3323 saveConf(); 3323 saveConf();
3324 QImage img = pix->convertToImage(); 3324 QImage img = pix->convertToImage();
3325 pix->convertFromImage(img.smoothScale(14,14)); 3325 pix->convertFromImage(img.smoothScale(14,14));
3326 cat->setIconName (icon); 3326 cat->setIconName (icon);
3327 cat->setIcon (*pix); 3327 cat->setIcon (*pix);
3328 } 3328 }
3329 } 3329 }
3330 else 3330 else
3331 { 3331 {
3332// #ifndef Q_WS_WIN 3332// #ifndef Q_WS_WIN
3333 conf->removeEntry (category); 3333 conf->removeEntry (category);
3334// #endif 3334// #endif
3335 saveConf(); 3335 saveConf();
3336 cat->setIcon (*getPredefinedIcon(category)); 3336 cat->setIcon (*getPredefinedIcon(category));
3337 } 3337 }
3338 3338
3339 // change the category name of the selected category 3339 // change the category name of the selected category
3340 QListViewItem *catItem = cat->getListItem(); 3340 QListViewItem *catItem = cat->getListItem();
3341 if (catItem) 3341 if (catItem)
3342 { 3342 {
3343#ifndef NO_OPIE 3343#ifndef NO_OPIE
3344 owarn << category << oendl; 3344 owarn << category << oendl;
3345#else 3345#else
3346 qWarning (category); 3346 qWarning (category);
3347#endif 3347#endif
3348 catItem->setText( 0, tr( category ) ); 3348 catItem->setText( 0, tr( category ) );
3349 cat->setCategoryName (tr(category)); 3349 cat->setCategoryName (tr(category));
3350 3350
3351 cat->initListItem(); 3351 cat->initListItem();
3352 categories.insert (category, cat); 3352 categories.insert (category, cat);
3353 } 3353 }
3354 } 3354 }
3355 saveCategoryDialogFields(dialog); 3355 saveCategoryDialogFields(dialog);
3356 } 3356 }
3357 else 3357 else
3358 { 3358 {
3359 // delete dialog; 3359 // delete dialog;
3360 dialog->hide(); 3360 dialog->hide();
3361 return; 3361 return;
3362 } 3362 }
3363 3363
3364 } 3364 }
3365} 3365}
3366 3366
3367void ZSafe::cutItem() 3367void ZSafe::cutItem()
3368{ 3368{
3369 if (!selectedItem) 3369 if (!selectedItem)
3370 return; 3370 return;
3371 if (!isCategory(selectedItem)) 3371 if (!isCategory(selectedItem))
3372 { 3372 {
3373 IsCut = true; 3373 IsCut = true;
3374 copiedItem = selectedItem; 3374 copiedItem = selectedItem;
3375 } 3375 }
3376} 3376}
3377 3377
3378void ZSafe::copyItem() 3378void ZSafe::copyItem()
3379{ 3379{
3380 if (!selectedItem) 3380 if (!selectedItem)
3381 return; 3381 return;
3382 if (!isCategory(selectedItem)) 3382 if (!isCategory(selectedItem))
3383 { 3383 {
3384 IsCopy = true; 3384 IsCopy = true;
3385 copiedItem = selectedItem; 3385 copiedItem = selectedItem;
3386 } 3386 }
3387} 3387}
3388 3388
3389// paste item into category 3389// paste item into category
3390void ZSafe::pasteItem() 3390void ZSafe::pasteItem()
3391{ 3391{
3392 if (!selectedItem) 3392 if (!selectedItem)
3393 return; 3393 return;
3394 if (isCategory(selectedItem)) 3394 if (isCategory(selectedItem))
3395 { 3395 {
3396 modified = true; 3396 modified = true;
3397 if (IsCut) 3397 if (IsCut)
3398 { 3398 {
3399 if (copiedItem) 3399 if (copiedItem)
3400 { 3400 {
3401 // add the new item 3401 // add the new item
3402 QListViewItem *i = new ShadedListItem (0, selectedItem); 3402 QListViewItem *i = new ShadedListItem (0, selectedItem);
3403 // i->setOpen (TRUE); 3403 // i->setOpen (TRUE);
3404 i->setText (0, copiedItem->text(0)); 3404 i->setText (0, copiedItem->text(0));
3405 i->setText (1, copiedItem->text(1)); 3405 i->setText (1, copiedItem->text(1));
3406 i->setText (2, copiedItem->text(2)); 3406 i->setText (2, copiedItem->text(2));
3407 i->setText (3, copiedItem->text(3)); 3407 i->setText (3, copiedItem->text(3));
3408 i->setText (4, copiedItem->text(4)); 3408 i->setText (4, copiedItem->text(4));
3409 i->setText (5, copiedItem->text(5)); 3409 i->setText (5, copiedItem->text(5));
3410 selectedItem->setOpen( TRUE ); 3410 selectedItem->setOpen( TRUE );
3411 3411
3412 // remove the cutted item 3412 // remove the cutted item
3413 copiedItem->parent()->takeItem(copiedItem); 3413 copiedItem->parent()->takeItem(copiedItem);
3414 selectedItem = NULL; 3414 selectedItem = NULL;
3415 } 3415 }
3416 } 3416 }
3417 else if (IsCopy) 3417 else if (IsCopy)
3418 { 3418 {
3419 if (copiedItem) 3419 if (copiedItem)
3420 { 3420 {
3421 // add the new item 3421 // add the new item
3422 QListViewItem *i = new ShadedListItem (0, selectedItem); 3422 QListViewItem *i = new ShadedListItem (0, selectedItem);
3423 // i->setOpen (TRUE); 3423 // i->setOpen (TRUE);
3424 i->setText (0, copiedItem->text(0)); 3424 i->setText (0, copiedItem->text(0));
3425 i->setText (1, copiedItem->text(1)); 3425 i->setText (1, copiedItem->text(1));
3426 i->setText (2, copiedItem->text(2)); 3426 i->setText (2, copiedItem->text(2));
3427 i->setText (3, copiedItem->text(3)); 3427 i->setText (3, copiedItem->text(3));
3428 i->setText (4, copiedItem->text(4)); 3428 i->setText (4, copiedItem->text(4));
3429 i->setText (5, copiedItem->text(5)); 3429 i->setText (5, copiedItem->text(5));
3430 selectedItem->setOpen( TRUE ); 3430 selectedItem->setOpen( TRUE );
3431 } 3431 }
3432 } 3432 }
3433 } 3433 }
3434 IsCut = false; 3434 IsCut = false;
3435 IsCopy = false; 3435 IsCopy = false;
3436} 3436}
3437 3437
3438void ZSafe::newDocument() 3438void ZSafe::newDocument()
3439{ 3439{
3440 3440
3441 // open the file dialog 3441 // open the file dialog
3442 QString newFile = zsaveDialog(); 3442 QString newFile = zsaveDialog();
3443 3443
3444 // open the new document 3444 // open the new document
3445 if (newFile && newFile.length() > 0 ) 3445 if (newFile && newFile.length() > 0 )
3446 { 3446 {
3447 // save the previous opened document 3447 // save the previous opened document
3448 if (!filename.isEmpty()) 3448 if (!filename.isEmpty())
3449 saveDocument(filename, FALSE); 3449 saveDocument(filename, FALSE);
3450 3450
3451 modified = true; 3451 modified = true;
3452 3452
3453 // clear the password list 3453 // clear the password list
3454 QListViewItem *i; 3454 QListViewItem *i;
3455 QListViewItem *c = NULL; 3455 QListViewItem *c = NULL;
3456 // step through all categories 3456 // step through all categories
3457 for (i = ListView->firstChild(); 3457 for (i = ListView->firstChild();
3458 i != NULL; 3458 i != NULL;
3459 i = i->nextSibling()) 3459 i = i->nextSibling())
3460 { 3460 {
3461 if (c) delete c; // delete the previous category 3461 if (c) delete c; // delete the previous category
3462 3462
3463 c = i; 3463 c = i;
3464 // step through all subitems 3464 // step through all subitems
3465 QListViewItem *si; 3465 QListViewItem *si;
3466 for (si = i->firstChild(); 3466 for (si = i->firstChild();
3467 si != NULL; ) 3467 si != NULL; )
3468 { 3468 {
3469 QListViewItem *_si = si; 3469 QListViewItem *_si = si;
3470 si = si->nextSibling(); 3470 si = si->nextSibling();
3471 i->takeItem(_si); // remove from view list 3471 i->takeItem(_si); // remove from view list
3472 if (_si) delete _si; 3472 if (_si) delete _si;
3473 } 3473 }
3474 } 3474 }
3475 if (c) delete c; // delete the previous category 3475 if (c) delete c; // delete the previous category
3476 categories.clear(); 3476 categories.clear();
3477 3477
3478 // m_password = ""; 3478 // m_password = "";
3479 selectedItem = NULL; 3479 selectedItem = NULL;
3480 3480
3481 filename = newFile; 3481 filename = newFile;
3482 3482
3483 // save the current filename to the config file 3483 // save the current filename to the config file
3484 conf->writeEntry(APP_KEY+"document", filename); 3484 conf->writeEntry(APP_KEY+"document", filename);
3485 saveConf(); 3485 saveConf();
3486 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3486 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3487#ifdef Q_WS_WIN 3487#ifdef Q_WS_WIN
3488 this->setCaption("Qt ZSafe: " + ti); 3488 this->setCaption("Qt ZSafe: " + ti);
3489#else 3489#else
3490 this->setCaption("ZSafe: " + ti); 3490 this->setCaption("ZSafe: " + ti);
3491#endif 3491#endif
3492 3492
3493 // openDocument(filename); 3493 // openDocument(filename);
3494 3494
3495 QMessageBox::information( this, tr("ZSafe"), 3495 QMessageBox::information( this, tr("ZSafe"),
3496 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); 3496 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0);
3497 3497
3498 saveDocumentWithPwd(); 3498 saveDocumentWithPwd();
3499 } 3499 }
3500} 3500}
3501 3501
3502void ZSafe::loadDocument() 3502void ZSafe::loadDocument()
3503{ 3503{
3504 3504
3505 // open the file dialog 3505 // open the file dialog
3506#ifndef DESKTOP 3506#ifndef DESKTOP
3507#ifndef NO_OPIE 3507#ifndef NO_OPIE
3508 QMap<QString, QStringList> mimeTypes; 3508 QMap<QString, QStringList> mimeTypes;
3509 mimeTypes.insert(tr("All"), QStringList() ); 3509 mimeTypes.insert(tr("All"), QStringList() );
3510 mimeTypes.insert(tr("ZSafe"), "zsafe/*" ); 3510 mimeTypes.insert(tr("ZSafe"), "zsafe/*" );
3511 QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL, 3511 QString newFile = OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
3512 QDir::homeDirPath() + "/Documents/application/zsafe", 3512 QDir::homeDirPath() + "/Documents/application/zsafe",
3513 QString::null, 3513 QString::null,
3514 mimeTypes, 3514 mimeTypes,
3515 this, 3515 this,
3516 tr ("Open ZSafe document")); 3516 tr ("Open ZSafe document"));
3517#else 3517#else
3518 QString newFile = ScQtFileEdit::getOpenFileName(this, 3518 QString newFile = ScQtFileEdit::getOpenFileName(this,
3519 tr ("Open ZSafe document"), 3519 tr ("Open ZSafe document"),
3520 QDir::homeDirPath() + "/Documents/application/zsafe", 3520 QDir::homeDirPath() + "/Documents/application/zsafe",
3521 "*.zsf"); 3521 "*.zsf");
3522#endif 3522#endif
3523#else 3523#else
3524 QString newFile = QFileDialog::getOpenFileName( 3524 QString newFile = QFileDialog::getOpenFileName(
3525 QDir::homeDirPath() + "/Documents/application/zsafe", 3525 QDir::homeDirPath() + "/Documents/application/zsafe",
3526 "ZSafe (*.zsf)", 3526 "ZSafe (*.zsf)",
3527 this, 3527 this,
3528 "ZSafe File Dialog" 3528 "ZSafe File Dialog"
3529 "Choose a ZSafe file" ); 3529 "Choose a ZSafe file" );
3530#endif 3530#endif
3531 3531
3532 // open the new document 3532 // open the new document
3533 if (newFile && newFile.length() > 0 ) 3533 if (newFile && newFile.length() > 0 )
3534 { 3534 {
3535 // save the previous opened document 3535 // save the previous opened document
3536 if (!filename.isEmpty()) 3536 if (!filename.isEmpty())
3537 saveDocument(filename, FALSE); 3537 saveDocument(filename, FALSE);
3538 3538
3539 // clear the password list 3539 // clear the password list
3540 QListViewItem *i; 3540 QListViewItem *i;
3541 QListViewItem *c = NULL; 3541 QListViewItem *c = NULL;
3542 // step through all categories 3542 // step through all categories
3543 for (i = ListView->firstChild(); 3543 for (i = ListView->firstChild();
3544 i != NULL; 3544 i != NULL;
3545 i = i->nextSibling()) 3545 i = i->nextSibling())
3546 { 3546 {
3547 if (c) delete c; // delete the previous category 3547 if (c) delete c; // delete the previous category
3548 3548
3549 c = i; 3549 c = i;
3550 // step through all subitems 3550 // step through all subitems
3551 QListViewItem *si; 3551 QListViewItem *si;
3552 for (si = i->firstChild(); 3552 for (si = i->firstChild();
3553 si != NULL; ) 3553 si != NULL; )
3554 { 3554 {
3555 QListViewItem *_si = si; 3555 QListViewItem *_si = si;
3556 si = si->nextSibling(); 3556 si = si->nextSibling();
3557 i->takeItem(_si); // remove from view list 3557 i->takeItem(_si); // remove from view list
3558 if (_si) delete _si; 3558 if (_si) delete _si;
3559 } 3559 }
3560 } 3560 }
3561 if (c) delete c; // delete the previous category 3561 if (c) delete c; // delete the previous category
3562 categories.clear(); 3562 categories.clear();
3563 m_password = ""; 3563 m_password = "";
3564 selectedItem = NULL; 3564 selectedItem = NULL;
3565 filename = newFile; 3565 filename = newFile;
3566 3566
3567 // save the current filename to the config file 3567 // save the current filename to the config file
3568 conf->writeEntry(APP_KEY+"document", filename); 3568 conf->writeEntry(APP_KEY+"document", filename);
3569 saveConf(); 3569 saveConf();
3570 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3570 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3571#ifdef Q_WS_WIN 3571#ifdef Q_WS_WIN
3572 this->setCaption("Qt ZSafe: " + ti); 3572 this->setCaption("Qt ZSafe: " + ti);
3573#else 3573#else
3574 this->setCaption("ZSafe: " + ti); 3574 this->setCaption("ZSafe: " + ti);
3575#endif 3575#endif
3576 3576
3577 openDocument(filename); 3577 openDocument(filename);
3578 } 3578 }
3579} 3579}
3580 3580
3581void ZSafe::saveDocumentAs() 3581void ZSafe::saveDocumentAs()
3582{ 3582{
3583 3583
3584QString newFile = zsaveDialog(); 3584QString newFile = zsaveDialog();
3585 // open the new document 3585 // open the new document
3586 if (newFile && newFile.length() > 0 ) 3586 if (newFile && newFile.length() > 0 )
3587 { 3587 {
3588 // save the previous opened document 3588 // save the previous opened document
3589 if (!filename.isEmpty()) 3589 if (!filename.isEmpty())
3590 saveDocument(filename, FALSE); 3590 saveDocument(filename, FALSE);
3591 3591
3592 selectedItem = NULL; 3592 selectedItem = NULL;
3593 filename = newFile; 3593 filename = newFile;
3594 3594
3595 // save the current filename to the config file 3595 // save the current filename to the config file
3596 conf->writeEntry(APP_KEY+"document", filename); 3596 conf->writeEntry(APP_KEY+"document", filename);
3597 saveConf(); 3597 saveConf();
3598 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3598 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3599#ifdef Q_WS_WIN 3599#ifdef Q_WS_WIN
3600 this->setCaption("Qt ZSafe: " + ti); 3600 this->setCaption("Qt ZSafe: " + ti);
3601#else 3601#else
3602 this->setCaption("ZSafe: " + ti); 3602 this->setCaption("ZSafe: " + ti);
3603#endif 3603#endif
3604 3604
3605 QMessageBox::information( this, tr("ZSafe"), 3605 QMessageBox::information( this, tr("ZSafe"),
3606 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0); 3606 tr("Now you have to enter\na password twice for your\nnewly created document."), tr("&OK"), 0);
3607 3607
3608 saveDocumentWithPwd(); 3608 saveDocumentWithPwd();
3609 } 3609 }
3610} 3610}
3611 3611
3612void ZSafe::saveDocumentWithoutPwd() 3612void ZSafe::saveDocumentWithoutPwd()
3613{ 3613{
3614 saveDocument(filename, FALSE); 3614 saveDocument(filename, FALSE);
3615} 3615}
3616 3616
3617void ZSafe::saveDocumentWithPwd() 3617void ZSafe::saveDocumentWithPwd()
3618{ 3618{
3619 saveDocument(filename, TRUE); 3619 saveDocument(filename, TRUE);
3620} 3620}
3621 3621
3622void ZSafe::about() 3622void ZSafe::about()
3623{ 3623{
3624 QString info; 3624 QString info;
3625#ifdef JPATCH_HDE 3625#ifdef JPATCH_HDE
3626 info = "<html><body><div align=""center"">"; 3626 info = "<html><body><div align=""center"">";
3627 info += "<b>"; 3627 info += "<b>";
3628 info += tr("Zaurus Password Manager<br>"); 3628 info += tr("Zaurus Password Manager<br>");
3629 info += tr("ZSafe version 2.1.2-jv01b<br>"); 3629 info += tr("ZSafe version 2.1.2-jv01b<br>");
3630 info += "</b>"; 3630 info += "</b>";
3631 info += tr("by Carsten Schneider<br>"); 3631 info += tr("by Carsten Schneider<br>");
3632 info += "zcarsten@gmx.net<br>"; 3632 info += "zcarsten@gmx.net<br>";
3633 info += "http://z-soft.z-portal.info/zsafe"; 3633 info += "http://z-soft.z-portal.info/zsafe";
3634 info += "<br>"; 3634 info += "<br>";
3635 info += tr("Translations by Robert Ernst<br>"); 3635 info += tr("Translations by Robert Ernst<br>");
3636 info += "robert.ernst@linux-solutions.at<br>"; 3636 info += "robert.ernst@linux-solutions.at<br>";
3637 3637
3638 info += "<br><br>"; 3638 info += "<br><br>";
3639 info += QString::fromUtf8("~W~\\~^/VGA Zaurus対~\\~C~Q~C~C~C~A~\\ ~H~P<br>"); 3639 info += QString::fromUtf8("~W~\\~^/VGA Zaurus対~\\~C~Q~C~C~C~A~\\ ~H~P<br>");
3640 info += "HADECO R&D<br>"; 3640 info += "HADECO R&D<br>";
3641 info += "r&d@hadeco.co.jp<br>"; 3641 info += "r&d@hadeco.co.jp<br>";
3642 info += "http://www.hadeco.co.jp/r&d/<br>"; 3642 info += "http://www.hadeco.co.jp/r&d/<br>";
3643 info += "<br></div>"; 3643 info += "<br></div>";
3644 info += "</body></html>"; 3644 info += "</body></html>";
3645#else 3645#else
3646 info = "<html><body><div align=""center"">"; 3646 info = "<html><body><div align=""center"">";
3647 info += "<b>"; 3647 info += "<b>";
3648 info += tr("Zaurus Password Manager<br>"); 3648 info += tr("Zaurus Password Manager<br>");
3649 info += tr("ZSafe version 2.1.2<br>"); 3649 info += tr("ZSafe version 2.1.2<br>");
3650 info += "</b>"; 3650 info += "</b>";
3651 info += tr("by Carsten Schneider<br>"); 3651 info += tr("by Carsten Schneider<br>");
3652 info += "zcarsten@gmx.net<br>"; 3652 info += "zcarsten@gmx.net<br>";
3653 info += "http://z-soft.z-portal.info/zsafe"; 3653 info += "http://z-soft.z-portal.info/zsafe";
3654 info += "<br>"; 3654 info += "<br>";
3655 info += tr("Translations by Robert Ernst<br>"); 3655 info += tr("Translations by Robert Ernst<br>");
3656 info += "robert.ernst@linux-solutions.at<br>"; 3656 info += "robert.ernst@linux-solutions.at<br>";
3657 info += "<br></div>"; 3657 info += "<br></div>";
3658 info += "</body></html>"; 3658 info += "</body></html>";
3659#endif 3659#endif
3660 3660
3661 // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0); 3661 // QMessageBox::information( this, tr("ZSafe"), info, tr("&OK"), 0);
3662 3662
3663 QMessageBox mb( this, tr("ZSafe")); 3663 QMessageBox mb( this, tr("ZSafe"));
3664 mb.setText (info); 3664 mb.setText (info);
3665 mb.setButtonText (QMessageBox::Ok, tr ("&OK")); 3665 mb.setButtonText (QMessageBox::Ok, tr ("&OK"));
3666 QPixmap zsafe_img((const char**) zsafe_xpm); 3666 QPixmap zsafe_img((const char**) zsafe_xpm);
3667 mb.setIconPixmap (zsafe_img); 3667 mb.setIconPixmap (zsafe_img);
3668 mb.exec(); 3668 mb.exec();
3669} 3669}
3670 3670
3671void ZSafe::setExpandFlag() 3671void ZSafe::setExpandFlag()
3672{ 3672{
3673 expandTree = !expandTree; 3673 expandTree = !expandTree;
3674 file->setItemChecked('o', expandTree); 3674 file->setItemChecked('o', expandTree);
3675#ifndef DESKTOP 3675#ifndef DESKTOP
3676 conf->setGroup ("zsafePrefs"); 3676 conf->setGroup ("zsafePrefs");
3677#endif 3677#endif
3678// #ifndef Q_WS_WIN 3678// #ifndef Q_WS_WIN
3679 conf->writeEntry (APP_KEY+"expandTree", expandTree); 3679 conf->writeEntry (APP_KEY+"expandTree", expandTree);
3680// #endif 3680// #endif
3681 saveConf(); 3681 saveConf();
3682 3682
3683} 3683}
3684 3684
3685void ZSafe::paintEvent( QPaintEvent * ) 3685void ZSafe::paintEvent( QPaintEvent * )
3686{ 3686{
3687 if (raiseFlag) 3687 if (raiseFlag)
3688 { 3688 {
3689 raiseFlag = false; 3689 raiseFlag = false;
3690 raiseTimer.start (1, true); 3690 raiseTimer.start (1, true);
3691 if (infoForm->isVisible()) 3691 if (infoForm->isVisible())
3692 infoForm->raise(); 3692 infoForm->raise();
3693 } 3693 }
3694} 3694}
3695 3695
3696void ZSafe::resizeEvent ( QResizeEvent * ) 3696void ZSafe::resizeEvent ( QResizeEvent * )
3697{ 3697{
3698 // owarn << "resizeEvent" << oendl; 3698 // owarn << "resizeEvent" << oendl;
3699#ifndef DESKTOP 3699#ifndef DESKTOP
3700 DeskW = appl->desktop()->width(); 3700 DeskW = appl->desktop()->width();
3701 DeskH = appl->desktop()->height(); 3701 DeskH = appl->desktop()->height();
3702#else 3702#else
3703 DeskW = this->width(); 3703 DeskW = this->width();
3704 DeskH = this->height(); 3704 DeskH = this->height();
3705#endif 3705#endif
3706 3706
3707 if (New) 3707 if (New)
3708 New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) ); 3708 New->setGeometry ( QRect( DeskW-84, 2, 20, 20 ) );
3709 if (Edit) 3709 if (Edit)
3710 Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) ); 3710 Edit->setGeometry ( QRect( DeskW-64, 2, 20, 20 ) );
3711 if (Delete) 3711 if (Delete)
3712 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) ); 3712 Delete->setGeometry( QRect( DeskW-44, 2, 20, 20 ) );
3713 if (Find) 3713 if (Find)
3714 Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) ); 3714 Find->setGeometry ( QRect( DeskW-24, 2, 20, 20 ) );
3715} 3715}
3716 3716
3717void ZSafe::slotRaiseTimer() 3717void ZSafe::slotRaiseTimer()
3718{ 3718{
3719 if (infoForm->isVisible()) 3719 if (infoForm->isVisible())
3720 infoForm->raise(); 3720 infoForm->raise();
3721 raiseFlag = true; 3721 raiseFlag = true;
3722} 3722}
3723 3723
3724QPixmap * ZSafe::getPredefinedIcon(QString category) 3724QPixmap * ZSafe::getPredefinedIcon(QString category)
3725{ 3725{
3726 QPixmap *pm; 3726 QPixmap *pm;
3727 if (category == "Bank cards") 3727 if (category == "Bank cards")
3728 pm = new QPixmap((const char**)bank_cards_data); 3728 pm = new QPixmap((const char**)bank_cards_data);
3729 else if (category == "Passwords") 3729 else if (category == "Passwords")
3730 pm = new QPixmap((const char**)passwords_data); 3730 pm = new QPixmap((const char**)passwords_data);
3731 else if (category == "Software") 3731 else if (category == "Software")
3732 pm = new QPixmap((const char**)software_data); 3732 pm = new QPixmap((const char**)software_data);
3733 else if (category == "General") 3733 else if (category == "General")
3734 pm = new QPixmap((const char**)general_data); 3734 pm = new QPixmap((const char**)general_data);
3735 else 3735 else
3736 pm = new QPixmap((const char**)general_data); 3736 pm = new QPixmap((const char**)general_data);
3737 return pm; 3737 return pm;
3738} 3738}
3739 3739
3740void ZSafe::setDocument(const QString& fileref) 3740void ZSafe::setDocument(const QString& fileref)
3741{ 3741{
3742#ifndef DESKTOP 3742#ifndef DESKTOP
3743 // stop the timer to prevent loading of the default document 3743 // stop the timer to prevent loading of the default document
3744 docuTimer.stop(); 3744 docuTimer.stop();
3745 3745
3746 DocLnk link(fileref); 3746 DocLnk link(fileref);
3747 if ( link.isValid() ) 3747 if ( link.isValid() )
3748 { 3748 {
3749 // if (filename != link.file()) 3749 // if (filename != link.file())
3750 // saveDocument(filename, FALSE); 3750 // saveDocument(filename, FALSE);
3751 filename = link.file(); 3751 filename = link.file();
3752 } 3752 }
3753 else 3753 else
3754 { 3754 {
3755 // if (filename != fileref) 3755 // if (filename != fileref)
3756 // saveDocument(filename, FALSE); 3756 // saveDocument(filename, FALSE);
3757 filename = fileref; 3757 filename = fileref;
3758 } 3758 }
3759 // save the current filename to the config file 3759 // save the current filename to the config file
3760 conf->writeEntry(APP_KEY+"document", filename); 3760 conf->writeEntry(APP_KEY+"document", filename);
3761 saveConf(); 3761 saveConf();
3762 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1); 3762 QString ti = filename.right (filename.length() - filename.findRev ('/') - 1);
3763#ifdef Q_WS_WIN 3763#ifdef Q_WS_WIN
3764 this->setCaption("Qt ZSafe: " + ti); 3764 this->setCaption("Qt ZSafe: " + ti);
3765#else 3765#else
3766 this->setCaption("ZSafe: " + ti); 3766 this->setCaption("ZSafe: " + ti);
3767#endif 3767#endif
3768 3768
3769 // clear the password list 3769 // clear the password list
3770 QListViewItem *i; 3770 QListViewItem *i;
3771 QListViewItem *c = NULL; 3771 QListViewItem *c = NULL;
3772 // step through all categories 3772 // step through all categories
3773 for (i = ListView->firstChild(); 3773 for (i = ListView->firstChild();
3774 i != NULL; 3774 i != NULL;
3775 i = i->nextSibling()) 3775 i = i->nextSibling())
3776 { 3776 {
3777 if (c) delete c; // delete the previous category 3777 if (c) delete c; // delete the previous category
3778 3778
3779 c = i; 3779 c = i;
3780 // step through all subitems 3780 // step through all subitems
3781 QListViewItem *si; 3781 QListViewItem *si;
3782 for (si = i->firstChild(); 3782 for (si = i->firstChild();
3783 si != NULL; ) 3783 si != NULL; )
3784 { 3784 {
3785 QListViewItem *_si = si; 3785 QListViewItem *_si = si;
3786 si = si->nextSibling(); 3786 si = si->nextSibling();
3787 i->takeItem(_si); // remove from view list 3787 i->takeItem(_si); // remove from view list
3788 if (_si) delete _si; 3788 if (_si) delete _si;
3789 } 3789 }
3790 } 3790 }
3791 if (c) delete c; // delete the previous category 3791 if (c) delete c; // delete the previous category
3792 categories.clear(); 3792 categories.clear();
3793 3793
3794 m_password = ""; 3794 m_password = "";
3795 selectedItem = NULL; 3795 selectedItem = NULL;
3796 3796
3797 openDocument(filename); 3797 openDocument(filename);
3798#else 3798#else
3799Q_UNUSED(fileref); 3799Q_UNUSED(fileref);
3800#endif 3800#endif
3801} 3801}
3802 3802
3803 3803
3804void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) { 3804void ZSafe::ListPressed(int mouse, QListViewItem *item, const QPoint&, int column) {
3805 if(item ==0) return; 3805 if(item ==0) return;
3806 switch (mouse) { 3806 switch (mouse) {
3807 case 1: 3807 case 1:
3808 { 3808 {
3809#ifdef DESKTOP 3809#ifdef DESKTOP
3810 QDragObject *d = new QTextDrag( item->text(column) , this ); 3810 QDragObject *d = new QTextDrag( item->text(column) , this );
3811 d->dragCopy(); 3811 d->dragCopy();
3812#endif 3812#endif
3813 } 3813 }
3814 break; 3814 break;
3815 case 2: 3815 case 2:
3816 { 3816 {
3817 QClipboard *cb = QApplication::clipboard(); 3817 QClipboard *cb = QApplication::clipboard();
3818 3818
3819 QIconSet copy_img((const char**) copy_xpm); 3819 QIconSet copy_img((const char**) copy_xpm);
3820 QIconSet edit_img((const char**) edit_xpm); 3820 QIconSet edit_img((const char**) edit_xpm);
3821 QPixmap folder_open_img((const char**) folder_open_xpm); 3821 QPixmap folder_open_img((const char**) folder_open_xpm);
3822 QPixmap editdelete_img((const char**) editdelete_xpm); 3822 QPixmap editdelete_img((const char**) editdelete_xpm);
3823 3823
3824 QPopupMenu *m = new QPopupMenu(this); 3824 QPopupMenu *m = new QPopupMenu(this);
3825 int copyItem = m->insertItem( copy_img, tr( "Copy to Clipboard" )); 3825 int copyItem = m->insertItem( copy_img, tr( "Copy to Clipboard" ));
3826 int editItem = m->insertItem(edit_img, tr( "Edit" )); 3826 int editItem = m->insertItem(edit_img, tr( "Edit" ));
3827 int showItem = m->insertItem(folder_open_img, tr( "Show Info" )); 3827 int showItem = m->insertItem(folder_open_img, tr( "Show Info" ));
3828 int cancelItem = m->insertItem( editdelete_img, tr( "Cancel" )); 3828 int cancelItem = m->insertItem( editdelete_img, tr( "Cancel" ));
3829 m->setFocus(); 3829 m->setFocus();
3830 int me=m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y() ) ) ; 3830 int me=m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y() ) ) ;
3831 if(me == copyItem) { 3831 if(me == copyItem) {
3832 copyClip( item->text(column) ) ; 3832 copyClip( item->text(column) ) ;
3833 } else if (me == cancelItem) { 3833 } else if (me == cancelItem) {
3834 cb->clear(); 3834 cb->clear();
3835 } else if (me == editItem) { 3835 } else if (me == editItem) {
3836 editPwd(); 3836 editPwd();
3837 } else if (me == showItem) { 3837 } else if (me == showItem) {
3838 showInfo(item); 3838 showInfo(item);
3839 } 3839 }
3840 } 3840 }
3841 break; 3841 break;
3842 }; 3842 };
3843} 3843}
3844 3844
3845void ZSafe::copyClip( const QString &text) { 3845void ZSafe::copyClip( const QString &text) {
3846 QClipboard *cb = QApplication::clipboard(); 3846 QClipboard *cb = QApplication::clipboard();
3847 cb->setText( text); 3847 cb->setText( text);
3848} 3848}
3849 3849
3850 3850
3851QString ZSafe::zsaveDialog() { 3851QString ZSafe::zsaveDialog() {
3852 3852
3853 QString fn; 3853 QString fn;
3854#ifndef DESKTOP 3854#ifndef DESKTOP
3855#ifndef NO_OPIE 3855#ifndef NO_OPIE
3856 QMap<QString, QStringList> mimeTypes; 3856 QMap<QString, QStringList> mimeTypes;
3857 mimeTypes.insert(tr("All"), QStringList() ); 3857 mimeTypes.insert(tr("All"), QStringList() );
3858 mimeTypes.insert(tr("Text"), "text/*" ); 3858 mimeTypes.insert(tr("Text"), "text/*" );
3859 fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL, 3859 fn = OFileDialog::getSaveFileName( OFileSelector::EXTENDED_ALL,
3860 QDir::homeDirPath() + "/Documents/application/zsafe", 3860 QDir::homeDirPath() + "/Documents/application/zsafe",
3861 QString::null, 3861 QString::null,
3862 mimeTypes, 3862 mimeTypes,
3863 this, 3863 this,
3864 tr ("Export text file")); 3864 tr ("Export text file"));
3865#else 3865#else
3866 fn = ScQtFileEdit::getSaveAsFileName(this, 3866 fn = ScQtFileEdit::getSaveAsFileName(this,
3867 tr ("Export text file"), 3867 tr ("Export text file"),
3868 QDir::homeDirPath() + "/Documents/application/zsafe", 3868 QDir::homeDirPath() + "/Documents/application/zsafe",
3869 "*.txt"); 3869 "*.txt");
3870#endif 3870#endif
3871#else 3871#else
3872 fn = QFileDialog::getSaveFileName( 3872 fn = QFileDialog::getSaveFileName(
3873 QDir::homeDirPath() + "/Documents/application/zsafe", 3873 QDir::homeDirPath() + "/Documents/application/zsafe",
3874 "ZSafe (*.txt)", 3874 "ZSafe (*.txt)",
3875 this, 3875 this,
3876 "ZSafe"); 3876 "ZSafe");
3877#endif 3877#endif
3878 return fn; 3878 return fn;
3879} 3879}
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp
index bdb1c78..c286a36 100644
--- a/noncore/games/backgammon/backgammon.cpp
+++ b/noncore/games/backgammon/backgammon.cpp
@@ -1,975 +1,975 @@
1#include "backgammon.h" 1#include "backgammon.h"
2#include "aidialog.h" 2#include "aidialog.h"
3#include "filedialog.h" 3#include "filedialog.h"
4#include "playerdialog.h" 4#include "playerdialog.h"
5#include "rulesdialog.h" 5#include "rulesdialog.h"
6#include "themedialog.h" 6#include "themedialog.h"
7 7
8/* OPIE */ 8/* OPIE */
9#include <opie2/odebug.h> 9#include <opie2/odebug.h>
10#include <qpe/qpeapplication.h> 10#include <qpe/qpeapplication.h>
11#include <qpe/config.h> 11#include <qpe/config.h>
12#include <qpe/resource.h> 12#include <qpe/resource.h>
13using namespace Opie::Core; 13using namespace Opie::Core;
14 14
15/* QT */ 15/* QT */
16#include <qfile.h> 16#include <qfile.h>
17#include <qlayout.h> 17#include <qlayout.h>
18#include <qmessagebox.h> 18#include <qmessagebox.h>
19#include <qtimer.h> 19#include <qtimer.h>
20#include <qmenubar.h> 20#include <qmenubar.h>
21 21
22#include <stdlib.h> 22#include <stdlib.h>
23 23
24 24
25BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) 25BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl)
26 : QMainWindow(parent, name, fl) 26 : QMainWindow(parent, name, fl)
27{ 27{
28 if (!name) setName("BackGammon"); 28 if (!name) setName("BackGammon");
29 setCaption(tr( "Backgammon") ); 29 setCaption(tr( "Backgammon") );
30 setIcon( Resource::loadPixmap( "backgammon" ) ); 30 setIcon( Resource::loadPixmap( "backgammon" ) );
31 //general counter varaible 31 //general counter varaible
32 int a=0; 32 int a=0;
33 //the game engine 33 //the game engine
34 move=new MoveEngine(); 34 move=new MoveEngine();
35 35
36 //load the default theme 36 //load the default theme
37 Config conf("backgammon"); 37 Config conf("backgammon");
38 if(!conf.isValid()) 38 if(!conf.isValid())
39 { 39 {
40 odebug << "config file does not exist" << oendl; 40 odebug << "config file does not exist" << oendl;
41 conf.setGroup("general"); 41 conf.setGroup("general");
42 conf.writeEntry("theme","default"); 42 conf.writeEntry("theme","default");
43 conf.setGroup("rules"); 43 conf.setGroup("rules");
44 conf.writeEntry("move_with_pieces_out",false); 44 conf.writeEntry("move_with_pieces_out",false);
45 conf.writeEntry("nice_dice",false); 45 conf.writeEntry("nice_dice",false);
46 conf.setGroup("display"); 46 conf.setGroup("display");
47 conf.writeEntry("small",false); 47 conf.writeEntry("small",false);
48 conf.writeEntry("warning",true); 48 conf.writeEntry("warning",true);
49 conf.setGroup("ai"); 49 conf.setGroup("ai");
50 conf.writeEntry("rescue",6); 50 conf.writeEntry("rescue",6);
51 conf.writeEntry("eliminate",4); 51 conf.writeEntry("eliminate",4);
52 conf.writeEntry("expose",1); 52 conf.writeEntry("expose",1);
53 conf.writeEntry("protect",5); 53 conf.writeEntry("protect",5);
54 conf.writeEntry("safe",3); 54 conf.writeEntry("safe",3);
55 conf.writeEntry("empty",2); 55 conf.writeEntry("empty",2);
56 56
57 } 57 }
58 conf.setGroup("general"); 58 conf.setGroup("general");
59 theme_name=conf.readEntry("theme","default"); 59 theme_name=conf.readEntry("theme","default");
60 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; 60 QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme";
61 61
62 //the rules 62 //the rules
63 conf.setGroup("rules"); 63 conf.setGroup("rules");
64 rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false); 64 rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false);
65 rules.generous_dice=conf.readBoolEntry("nice_dice",false); 65 rules.generous_dice=conf.readBoolEntry("nice_dice",false);
66 66
67 move->setRules(rules); 67 move->setRules(rules);
68 68
69 //get the AI settings 69 //get the AI settings
70 AISettings ai; 70 AISettings ai;
71 conf.setGroup("ai"); 71 conf.setGroup("ai");
72 ai.rescue=conf.readNumEntry("rescue",6); 72 ai.rescue=conf.readNumEntry("rescue",6);
73 ai.eliminate=conf.readNumEntry("eliminate",4); 73 ai.eliminate=conf.readNumEntry("eliminate",4);
74 ai.expose=conf.readNumEntry("expose",1); 74 ai.expose=conf.readNumEntry("expose",1);
75 ai.protect=conf.readNumEntry("protect",5); 75 ai.protect=conf.readNumEntry("protect",5);
76 ai.safe=conf.readNumEntry("safe",3); 76 ai.safe=conf.readNumEntry("safe",3);
77 ai.empty=conf.readNumEntry("empty",2); 77 ai.empty=conf.readNumEntry("empty",2);
78 move->setAISettings(ai); 78 move->setAISettings(ai);
79 79
80 80
81 //get the theme component names 81 //get the theme component names
82 Config theme(theme_file,Config::File); 82 Config theme(theme_file,Config::File);
83 if(!theme.isValid()) 83 if(!theme.isValid())
84 { 84 {
85 odebug << "theme file does not exist" << oendl; 85 odebug << "theme file does not exist" << oendl;
86 theme.setGroup("theme"); 86 theme.setGroup("theme");
87 theme.writeEntry("board","casino_board_1"); 87 theme.writeEntry("board","casino_board_1");
88 theme.writeEntry("pieces1","casino_pieces_blue"); 88 theme.writeEntry("pieces1","casino_pieces_blue");
89 theme.writeEntry("pieces2","casino_pieces_white"); 89 theme.writeEntry("pieces2","casino_pieces_white");
90 theme.writeEntry("dice1","casino_dice"); 90 theme.writeEntry("dice1","casino_dice");
91 theme.writeEntry("dice2","casino_dice"); 91 theme.writeEntry("dice2","casino_dice");
92 theme.writeEntry("table","casino_table_green"); 92 theme.writeEntry("table","casino_table_green");
93 theme.writeEntry("odds","casino_odds"); 93 theme.writeEntry("odds","casino_odds");
94 } 94 }
95 theme.setGroup("theme"); 95 theme.setGroup("theme");
96 board_name=theme.readEntry("board","casino_board_1"); 96 board_name=theme.readEntry("board","casino_board_1");
97 piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); 97 piecesA_name=theme.readEntry("pieces1","casino_pieces_blue");
98 piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); 98 piecesB_name=theme.readEntry("pieces2","casino_pieces_white");
99 diceA_name=theme.readEntry("dice1","casino_dice"); 99 diceA_name=theme.readEntry("dice1","casino_dice");
100 diceB_name=theme.readEntry("dice2","casino_dice"); 100 diceB_name=theme.readEntry("dice2","casino_dice");
101 table_name=theme.readEntry("table","casino_table_green"); 101 table_name=theme.readEntry("table","casino_table_green");
102 odds_name=theme.readEntry("odds","casino_odds"); 102 odds_name=theme.readEntry("odds","casino_odds");
103 103
104 104
105 //the menu 105 //the menu
106 QMenuBar* menuBar = new QMenuBar(this); 106 QMenuBar* menuBar = new QMenuBar(this);
107 107
108 QPopupMenu* gamemenu= new QPopupMenu(this); 108 QPopupMenu* gamemenu= new QPopupMenu(this);
109 gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); 109 gamemenu->insertItem(tr( "New" ),this,SLOT(newgame()));
110 gamemenu->insertSeparator(); 110 gamemenu->insertSeparator();
111 gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); 111 gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame()));
112 gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); 112 gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame()));
113 gamemenu->insertSeparator(); 113 gamemenu->insertSeparator();
114 gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); 114 gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame()));
115 menuBar->insertItem(tr( "Game" ),gamemenu); 115 menuBar->insertItem(tr( "Game" ),gamemenu);
116 116
117 QPopupMenu* thememenu= new QPopupMenu(this); 117 QPopupMenu* thememenu= new QPopupMenu(this);
118 thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); 118 thememenu->insertItem(tr( "New" ),this,SLOT(newtheme()));
119 thememenu->insertSeparator(); 119 thememenu->insertSeparator();
120 thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); 120 thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme()));
121 thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); 121 thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme()));
122 thememenu->insertSeparator(); 122 thememenu->insertSeparator();
123 thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); 123 thememenu->insertItem(tr( "Default"),this,SLOT(themedefault()));
124 thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); 124 thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme()));
125 menuBar->insertItem(tr( "Theme" ),thememenu); 125 menuBar->insertItem(tr( "Theme" ),thememenu);
126 126
127 QPopupMenu* optionmenu=new QPopupMenu(this); 127 QPopupMenu* optionmenu=new QPopupMenu(this);
128 optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); 128 optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect()));
129 optionmenu->insertSeparator(); 129 optionmenu->insertSeparator();
130 optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); 130 optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI()));
131 optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); 131 optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules()));
132 menuBar->insertItem(tr( "Options"),optionmenu); 132 menuBar->insertItem(tr( "Options"),optionmenu);
133 133
134 QWidget* mainarea=new QWidget(this); 134 QWidget* mainarea=new QWidget(this);
135 setCentralWidget(mainarea); 135 setCentralWidget(mainarea);
136 //the main area 136 //the main area
137 QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); 137 QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom);
138 area=new QCanvas(235,235); 138 area=new QCanvas(235,235);
139 boardview=new BackGammonView(area,mainarea); 139 boardview=new BackGammonView(area,mainarea);
140 boardview->setMaximumHeight(240); 140 boardview->setMaximumHeight(240);
141 layout->addWidget(boardview); 141 layout->addWidget(boardview);
142 connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); 142 connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int)));
143 //status bar 143 //status bar
144 message=new QLabel("<b>Backgammon</b>",mainarea); 144 message=new QLabel("<b>Backgammon</b>",mainarea);
145 message->setAlignment(AlignHCenter); 145 message->setAlignment(AlignHCenter);
146 layout->addWidget(message); 146 layout->addWidget(message);
147 147
148 //the marker 148 //the marker
149 marker_current=new QCanvasRectangle(area); 149 marker_current=new QCanvasRectangle(area);
150 marker_current->setBrush(QColor(0,0,255)); 150 marker_current->setBrush(QColor(0,0,255));
151 marker_current->setSize(15,5); 151 marker_current->setSize(15,5);
152 marker_current->setZ(1); 152 marker_current->setZ(1);
153 153
154 for(a=0;a<4;a++) 154 for(a=0;a<4;a++)
155 { 155 {
156 marker_next[a]=new QCanvasRectangle(area); 156 marker_next[a]=new QCanvasRectangle(area);
157 marker_next[a]->setBrush(QColor(0,255,0)); 157 marker_next[a]->setBrush(QColor(0,255,0));
158 marker_next[a]->setSize(15,5); 158 marker_next[a]->setSize(15,5);
159 marker_next[a]->setZ(1); 159 marker_next[a]->setZ(1);
160 } 160 }
161 161
162 connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); 162 connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1()));
163 connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); 163 connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2()));
164 connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); 164 connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3()));
165 connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); 165 connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4()));
166 connect(move,SIGNAL(nomove()),this,SLOT(nomove())); 166 connect(move,SIGNAL(nomove()),this,SLOT(nomove()));
167 connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); 167 connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int)));
168 168
169 //the pieces 169 //the pieces
170 p1=new CanvasImageItem*[15]; 170 p1=new CanvasImageItem*[15];
171 p1_side=new CanvasImageItem*[15]; 171 p1_side=new CanvasImageItem*[15];
172 QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); 172 QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name));
173 QImage piece_1_front=piece_1_all.copy(0,0,15,15); 173 QImage piece_1_front=piece_1_all.copy(0,0,15,15);
174 QImage piece_1_side=piece_1_all.copy(0,15,15,5); 174 QImage piece_1_side=piece_1_all.copy(0,15,15,5);
175 175
176 p2=new CanvasImageItem*[15]; 176 p2=new CanvasImageItem*[15];
177 p2_side=new CanvasImageItem*[15]; 177 p2_side=new CanvasImageItem*[15];
178 QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); 178 QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name));
179 QImage piece_2_front=piece_2_all.copy(0,0,15,15); 179 QImage piece_2_front=piece_2_all.copy(0,0,15,15);
180 QImage piece_2_side=piece_2_all.copy(0,15,15,5); 180 QImage piece_2_side=piece_2_all.copy(0,15,15,5);
181 181
182 182
183 for(a=0;a<15;a++) 183 for(a=0;a<15;a++)
184 { 184 {
185 p1[a]=new CanvasImageItem(piece_1_front,area); 185 p1[a]=new CanvasImageItem(piece_1_front,area);
186 p1[a]->setSize(15,15); 186 p1[a]->setSize(15,15);
187 p1_side[a]=new CanvasImageItem(piece_1_side,area); 187 p1_side[a]=new CanvasImageItem(piece_1_side,area);
188 p1_side[a]->setSize(15,5); 188 p1_side[a]->setSize(15,5);
189 189
190 p2[a]=new CanvasImageItem(piece_2_front,area); 190 p2[a]=new CanvasImageItem(piece_2_front,area);
191 p2[a]->setSize(15,15); 191 p2[a]->setSize(15,15);
192 p2_side[a]=new CanvasImageItem(piece_2_side,area); 192 p2_side[a]=new CanvasImageItem(piece_2_side,area);
193 p2_side[a]->setSize(15,5); 193 p2_side[a]->setSize(15,5);
194 } 194 }
195 draw(); 195 draw();
196 196
197 //the dice 197 //the dice
198 QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); 198 QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name));
199 diceA1=new CanvasImageItem*[7]; 199 diceA1=new CanvasImageItem*[7];
200 diceA2=new CanvasImageItem*[7]; 200 diceA2=new CanvasImageItem*[7];
201 QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); 201 QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name));
202 diceB1=new CanvasImageItem*[7]; 202 diceB1=new CanvasImageItem*[7];
203 diceB2=new CanvasImageItem*[7]; 203 diceB2=new CanvasImageItem*[7];
204 QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); 204 QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name));
205 //oddsDice=new CanvasImageItem*[6]; 205 //oddsDice=new CanvasImageItem*[6];
206 206
207 207
208 for(a=0;a<7;a++) 208 for(a=0;a<7;a++)
209 { 209 {
210 QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); 210 QImage dicebgA=dicebgA_all.copy(a*25,0,25,25);
211 diceA1[a]=new CanvasImageItem(dicebgA,area); 211 diceA1[a]=new CanvasImageItem(dicebgA,area);
212 diceA1[a]->setX(5); 212 diceA1[a]->setX(5);
213 diceA1[a]->setY(205-2); 213 diceA1[a]->setY(205-2);
214 diceA1[a]->setZ(1); 214 diceA1[a]->setZ(1);
215 diceA1[a]->setSize(25,25); 215 diceA1[a]->setSize(25,25);
216 diceA2[a]=new CanvasImageItem(dicebgA,area); 216 diceA2[a]=new CanvasImageItem(dicebgA,area);
217 diceA2[a]->setX(35); 217 diceA2[a]->setX(35);
218 diceA2[a]->setY(205-2); 218 diceA2[a]->setY(205-2);
219 diceA2[a]->setZ(1); 219 diceA2[a]->setZ(1);
220 diceA2[a]->setSize(25,25); 220 diceA2[a]->setSize(25,25);
221 221
222 QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); 222 QImage dicebgB=dicebgB_all.copy(a*25,0,25,25);
223 diceB1[a]=new CanvasImageItem(dicebgB,area); 223 diceB1[a]=new CanvasImageItem(dicebgB,area);
224 diceB1[a]->setX(175); 224 diceB1[a]->setX(175);
225 diceB1[a]->setY(205-2); 225 diceB1[a]->setY(205-2);
226 diceB1[a]->setZ(1); 226 diceB1[a]->setZ(1);
227 diceB1[a]->setSize(25,25); 227 diceB1[a]->setSize(25,25);
228 diceB2[a]=new CanvasImageItem(dicebgB,area); 228 diceB2[a]=new CanvasImageItem(dicebgB,area);
229 diceB2[a]->setX(205); 229 diceB2[a]->setX(205);
230 diceB2[a]->setY(205-2); 230 diceB2[a]->setY(205-2);
231 diceB2[a]->setZ(1); 231 diceB2[a]->setZ(1);
232 diceB2[a]->setSize(25,25); 232 diceB2[a]->setSize(25,25);
233 233
234 /* 234 /*
235 if(a<6) 235 if(a<6)
236 { 236 {
237 QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); 237 QImage oddsbg=oddsbg_all.copy(a*15,0,15,15);
238 oddsDice[a]=new CanvasImageItem(oddsbg,area); 238 oddsDice[a]=new CanvasImageItem(oddsbg,area);
239 oddsDice[a]->setX(110); 239 oddsDice[a]->setX(110);
240 oddsDice[a]->setY(210-2); 240 oddsDice[a]->setY(210-2);
241 oddsDice[a]->setZ(1); 241 oddsDice[a]->setZ(1);
242 oddsDice[a]->setSize(15,15); 242 oddsDice[a]->setSize(15,15);
243 oddsDice[a]->hide(); 243 oddsDice[a]->hide();
244 } 244 }
245 */ 245 */
246 } 246 }
247 //oddsDice[0]->show(); 247 //oddsDice[0]->show();
248 248
249 //set the board 249 //set the board
250 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); 250 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
251 board=new CanvasImageItem(boardbg,area); 251 board=new CanvasImageItem(boardbg,area);
252 board->setX(0); 252 board->setX(0);
253 board->setY(0); 253 board->setY(0);
254 board->setZ(0); 254 board->setZ(0);
255 board->setSize(235-2,200-2); 255 board->setSize(235-2,200-2);
256 board->show(); 256 board->show();
257 257
258 //the table 258 //the table
259 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); 259 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
260 table=new CanvasImageItem(tablebg,area); 260 table=new CanvasImageItem(tablebg,area);
261 table->setX(0); 261 table->setX(0);
262 table->setY(200-2); 262 table->setY(200-2);
263 table->setZ(0); 263 table->setZ(0);
264 table->setSize(235-2,20); 264 table->setSize(235-2,20);
265 table->show(); 265 table->show();
266 266
267 //the no move marker 267 //the no move marker
268 QImage nomovebg(Resource::loadImage("backgammon/no_move")); 268 QImage nomovebg(Resource::loadImage("backgammon/no_move"));
269 nomove_marker=new CanvasImageItem(nomovebg,area); 269 nomove_marker=new CanvasImageItem(nomovebg,area);
270 nomove_marker->setX(0); 270 nomove_marker->setX(0);
271 nomove_marker->setY(200); 271 nomove_marker->setY(200);
272 nomove_marker->setZ(2); 272 nomove_marker->setZ(2);
273 nomove_marker->hide(); 273 nomove_marker->hide();
274 274
275 //default human against computer 275 //default human against computer
276 player1_auto=false; 276 player1_auto=false;
277 player2_auto=true; 277 player2_auto=true;
278 //start new game 278 //start new game
279 newgame(); 279 newgame();
280} 280}
281 281
282BackGammon::~BackGammon() 282BackGammon::~BackGammon()
283{ 283{
284 //DESTRUCTOR 284 //DESTRUCTOR
285} 285}
286 286
287void BackGammon::newgame() 287void BackGammon::newgame()
288{ 288{
289 gameFinished=false; 289 gameFinished=false;
290 QDateTime now=QDateTime::currentDateTime(); 290 QDateTime now=QDateTime::currentDateTime();
291 game_name=now.date().toString()+"_"+now.time().toString(); 291 game_name=now.date().toString()+"_"+now.time().toString();
292 move->reset(); 292 move->reset();
293 draw(); 293 draw();
294 diceA1_value=7; 294 diceA1_value=7;
295 diceA2_value=7; 295 diceA2_value=7;
296 diceA3_value=7; 296 diceA3_value=7;
297 diceA4_value=7; 297 diceA4_value=7;
298 diceB1_value=7; 298 diceB1_value=7;
299 diceB2_value=7; 299 diceB2_value=7;
300 diceB3_value=7; 300 diceB3_value=7;
301 diceB4_value=7; 301 diceB4_value=7;
302 showdice(); 302 showdice();
303 player=2; 303 player=2;
304 dice1_played=true; 304 dice1_played=true;
305 dice2_played=true; 305 dice2_played=true;
306 dice3_played=true; 306 dice3_played=true;
307 dice4_played=true; 307 dice4_played=true;
308 dice_rolled=false; 308 dice_rolled=false;
309 setplayer(); 309 setplayer();
310 area->update(); 310 area->update();
311} 311}
312 312
313void BackGammon::playerselect() 313void BackGammon::playerselect()
314{ 314{
315 PlayerDialog* playerdialog=new PlayerDialog(this); 315 PlayerDialog* playerdialog=new PlayerDialog(this);
316 playerdialog->setAuto1(player1_auto); 316 playerdialog->setAuto1(player1_auto);
317 playerdialog->setAuto2(player2_auto); 317 playerdialog->setAuto2(player2_auto);
318 if(!playerdialog->exec()) 318 if(!playerdialog->exec())
319 return; 319 return;
320 player1_auto=playerdialog->getAuto1(); 320 player1_auto=playerdialog->getAuto1();
321 player2_auto=playerdialog->getAuto2(); 321 player2_auto=playerdialog->getAuto2();
322} 322}
323 323
324void BackGammon::loadgame() 324void BackGammon::loadgame()
325{ 325{
326 FileDialog* file=new FileDialog(this,"Load Game",".game"); 326 FileDialog* file=new FileDialog(this,"Load Game",".game");
327 if(!file->exec()) 327 if(!file->exec())
328 return; 328 return;
329 329
330 game_name=file->filename(); 330 game_name=file->filename();
331 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; 331 QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game";
332 332
333 Config game(game_file,Config::File); 333 Config game(game_file,Config::File);
334 game.setGroup("dice"); 334 game.setGroup("dice");
335 diceA1_value=game.readNumEntry("diceA1_value"); 335 diceA1_value=game.readNumEntry("diceA1_value");
336 diceA2_value=game.readNumEntry("diceA2_value"); 336 diceA2_value=game.readNumEntry("diceA2_value");
337 diceA3_value=game.readNumEntry("diceA3_value"); 337 diceA3_value=game.readNumEntry("diceA3_value");
338 diceA4_value=game.readNumEntry("diceA4_value"); 338 diceA4_value=game.readNumEntry("diceA4_value");
339 diceB1_value=game.readNumEntry("diceB1_value"); 339 diceB1_value=game.readNumEntry("diceB1_value");
340 diceB2_value=game.readNumEntry("diceB2_value"); 340 diceB2_value=game.readNumEntry("diceB2_value");
341 diceB3_value=game.readNumEntry("diceB3_value"); 341 diceB3_value=game.readNumEntry("diceB3_value");
342 diceB4_value=game.readNumEntry("diceB4_value"); 342 diceB4_value=game.readNumEntry("diceB4_value");
343 player=game.readNumEntry("player"); 343 player=game.readNumEntry("player");
344 dice1_played=game.readBoolEntry("dice1_played"); 344 dice1_played=game.readBoolEntry("dice1_played");
345 dice2_played=game.readBoolEntry("dice2_played"); 345 dice2_played=game.readBoolEntry("dice2_played");
346 dice3_played=game.readBoolEntry("dice3_played"); 346 dice3_played=game.readBoolEntry("dice3_played");
347 dice4_played=game.readBoolEntry("dice4_played"); 347 dice4_played=game.readBoolEntry("dice4_played");
348 dice_rolled=game.readBoolEntry("dice_rolled"); 348 dice_rolled=game.readBoolEntry("dice_rolled");
349 player1_auto=game.readBoolEntry("player1_auto"); 349 player1_auto=game.readBoolEntry("player1_auto");
350 player2_auto=game.readBoolEntry("player2_auto"); 350 player2_auto=game.readBoolEntry("player2_auto");
351 351
352 game.setGroup("pieces"); 352 game.setGroup("pieces");
353 QString label; 353 QString label;
354 LoadSave load; 354 LoadSave load;
355 for(int a=0;a<28;a++) 355 for(int a=0;a<28;a++)
356 { 356 {
357 label.setNum(a); 357 label.setNum(a);
358 load.pop[a].total = game.readNumEntry(label,0); 358 load.pop[a].total = game.readNumEntry(label,0);
359 } 359 }
360 360
361 move->loadGame(load); 361 move->loadGame(load);
362 setplayer(); 362 setplayer();
363 showdice(); 363 showdice();
364 draw(); 364 draw();
365 area->update(); 365 area->update();
366} 366}
367 367
368void BackGammon::savegame() 368void BackGammon::savegame()
369{ 369{
370 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; 370 QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game";
371 371
372 Config game(game_file,Config::File); 372 Config game(game_file,Config::File);
373 game.setGroup("dice"); 373 game.setGroup("dice");
374 game.writeEntry("diceA1_value",diceA1_value); 374 game.writeEntry("diceA1_value",diceA1_value);
375 game.writeEntry("diceA2_value",diceA2_value); 375 game.writeEntry("diceA2_value",diceA2_value);
376 game.writeEntry("diceA3_value",diceA3_value); 376 game.writeEntry("diceA3_value",diceA3_value);
377 game.writeEntry("diceA4_value",diceA4_value); 377 game.writeEntry("diceA4_value",diceA4_value);
378 game.writeEntry("diceB1_value",diceB1_value); 378 game.writeEntry("diceB1_value",diceB1_value);
379 game.writeEntry("diceB2_value",diceB3_value); 379 game.writeEntry("diceB2_value",diceB3_value);
380 game.writeEntry("diceB3_value",diceB4_value); 380 game.writeEntry("diceB3_value",diceB4_value);
381 game.writeEntry("diceB4_value",diceB4_value); 381 game.writeEntry("diceB4_value",diceB4_value);
382 game.writeEntry("player",player); 382 game.writeEntry("player",player);
383 game.writeEntry("dice1_played",dice1_played); 383 game.writeEntry("dice1_played",dice1_played);
384 game.writeEntry("dice2_played",dice2_played); 384 game.writeEntry("dice2_played",dice2_played);
385 game.writeEntry("dice3_played",dice3_played); 385 game.writeEntry("dice3_played",dice3_played);
386 game.writeEntry("dice4_played",dice4_played); 386 game.writeEntry("dice4_played",dice4_played);
387 game.writeEntry("dice_rolled",dice_rolled); 387 game.writeEntry("dice_rolled",dice_rolled);
388 game.writeEntry("player1_auto",player1_auto); 388 game.writeEntry("player1_auto",player1_auto);
389 game.writeEntry("player2_auto",player2_auto); 389 game.writeEntry("player2_auto",player2_auto);
390 390
391 game.setGroup("pieces"); 391 game.setGroup("pieces");
392 QString label; 392 QString label;
393 LoadSave save=move->saveGame(); 393 LoadSave save=move->saveGame();
394 for(int a=0;a<28;a++) 394 for(int a=0;a<28;a++)
395 { 395 {
396 label.setNum(a); 396 label.setNum(a);
397 game.writeEntry(label,save.pop[a].total); 397 game.writeEntry(label,save.pop[a].total);
398 } 398 }
399 QMessageBox::information(this,"Backgammon","Game saved","OK"); 399 QMessageBox::information(this,"Backgammon","Game saved","OK");
400} 400}
401 401
402void BackGammon::deletegame() 402void BackGammon::deletegame()
403{ 403{
404 FileDialog* file=new FileDialog(this,"Delete Game",".game"); 404 FileDialog* file=new FileDialog(this,"Delete Game",".game");
405 if(!file->exec()) 405 if(!file->exec())
406 return; 406 return;
407 407
408 game_name=file->filename(); 408 game_name=file->filename();
409 QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; 409 QString game_file=QPEApplication::qpeDir()+"backgammon/"+game_name+".game";
410 410
411 if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) 411 if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel"))
412 { 412 {
413 QFile(game_file).remove(); 413 QFile(game_file).remove();
414 } 414 }
415} 415}
416 416
417 417
418void BackGammon::newtheme() 418void BackGammon::newtheme()
419{ 419{
420 ThemeDialog* theme=new ThemeDialog(this); 420 ThemeDialog* theme=new ThemeDialog(this);
421 421
422 ImageNames names; 422 ImageNames names;
423 names.theme=theme_name; 423 names.theme=theme_name;
424 names.board=board_name; 424 names.board=board_name;
425 names.pieces1=piecesA_name; 425 names.pieces1=piecesA_name;
426 names.pieces2=piecesB_name; 426 names.pieces2=piecesB_name;
427 names.dice1=diceA_name; 427 names.dice1=diceA_name;
428 names.dice2=diceB_name; 428 names.dice2=diceB_name;
429 names.odds=odds_name; 429 names.odds=odds_name;
430 names.table=table_name; 430 names.table=table_name;
431 431
432 theme->setCurrent(names); 432 theme->setCurrent(names);
433 if(!theme->exec()) 433 if(!theme->exec())
434 return; 434 return;
435 435
436 names=theme->getNames(); 436 names=theme->getNames();
437 theme_name=names.theme; 437 theme_name=names.theme;
438 board_name=names.board; 438 board_name=names.board;
439 piecesA_name=names.pieces1; 439 piecesA_name=names.pieces1;
440 piecesB_name=names.pieces2; 440 piecesB_name=names.pieces2;
441 diceA_name=names.dice1; 441 diceA_name=names.dice1;
442 diceB_name=names.dice2; 442 diceB_name=names.dice2;
443 odds_name=names.odds; 443 odds_name=names.odds;
444 table_name=names.table; 444 table_name=names.table;
445 445
446 applytheme(); 446 applytheme();
447} 447}
448 448
449void BackGammon::loadtheme() 449void BackGammon::loadtheme()
450{ 450{
451 FileDialog* file=new FileDialog(this,"Load Theme",".theme"); 451 FileDialog* file=new FileDialog(this,"Load Theme",".theme");
452 if(!file->exec()) 452 if(!file->exec())
453 return; 453 return;
454 454
455 theme_name=file->filename(); 455 theme_name=file->filename();
456 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; 456 QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme";
457 457
458 Config theme(theme_file,Config::File); 458 Config theme(theme_file,Config::File);
459 theme.setGroup("theme"); 459 theme.setGroup("theme");
460 board_name=theme.readEntry("board","board_1"); 460 board_name=theme.readEntry("board","board_1");
461 piecesA_name=theme.readEntry("pieces1","pieces_1"); 461 piecesA_name=theme.readEntry("pieces1","pieces_1");
462 piecesB_name=theme.readEntry("pieces2","pieces_2"); 462 piecesB_name=theme.readEntry("pieces2","pieces_2");
463 diceA_name=theme.readEntry("dice1","dice_1"); 463 diceA_name=theme.readEntry("dice1","dice_1");
464 diceB_name=theme.readEntry("dice2","dice_2"); 464 diceB_name=theme.readEntry("dice2","dice_2");
465 table_name=theme.readEntry("table","table_1"); 465 table_name=theme.readEntry("table","table_1");
466 odds_name=theme.readEntry("odds","odds_1"); 466 odds_name=theme.readEntry("odds","odds_1");
467 467
468 applytheme(); 468 applytheme();
469 469
470} 470}
471 471
472void BackGammon::savetheme() 472void BackGammon::savetheme()
473{ 473{
474 if(theme_name=="default") 474 if(theme_name=="default")
475 { 475 {
476 QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); 476 QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK");
477 return; 477 return;
478 } 478 }
479 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; 479 QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme";
480 if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) 480 if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No"))
481 return; 481 return;
482 482
483 Config theme(theme_file,Config::File); 483 Config theme(theme_file,Config::File);
484 theme.setGroup("theme"); 484 theme.setGroup("theme");
485 theme.writeEntry("board",board_name); 485 theme.writeEntry("board",board_name);
486 theme.writeEntry("pieces1",piecesA_name); 486 theme.writeEntry("pieces1",piecesA_name);
487 theme.writeEntry("pieces2",piecesB_name); 487 theme.writeEntry("pieces2",piecesB_name);
488 theme.writeEntry("dice1",diceA_name); 488 theme.writeEntry("dice1",diceA_name);
489 theme.writeEntry("dice2",diceB_name); 489 theme.writeEntry("dice2",diceB_name);
490 theme.writeEntry("table",table_name); 490 theme.writeEntry("table",table_name);
491 theme.writeEntry("odds",odds_name); 491 theme.writeEntry("odds",odds_name);
492 492
493} 493}
494 494
495void BackGammon::themedefault() 495void BackGammon::themedefault()
496{ 496{
497 if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) 497 if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No"))
498 return; 498 return;
499 499
500 Config conf("backgammon"); 500 Config conf("backgammon");
501 conf.setGroup("general"); 501 conf.setGroup("general");
502 conf.writeEntry("theme",theme_name); 502 conf.writeEntry("theme",theme_name);
503} 503}
504 504
505void BackGammon::deletetheme() 505void BackGammon::deletetheme()
506{ 506{
507 FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); 507 FileDialog* file=new FileDialog(this,"Delete Theme",".theme");
508 if(!file->exec()) 508 if(!file->exec())
509 return; 509 return;
510 510
511 theme_name=file->filename(); 511 theme_name=file->filename();
512 QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; 512 QString theme_file=QPEApplication::qpeDir()+"backgammon/"+theme_name+".theme";
513 513
514 if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" ))) 514 if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" )))
515 { 515 {
516 QFile(theme_file).remove(); 516 QFile(theme_file).remove();
517 } 517 }
518} 518}
519 519
520void BackGammon::modify_AI() 520void BackGammon::modify_AI()
521{ 521{
522 AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme"); 522 AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme");
523 ai_mod->setAISettings(move->getAISettings()); 523 ai_mod->setAISettings(move->getAISettings());
524 if(!ai_mod->exec()) 524 if(!ai_mod->exec())
525 return; 525 return;
526 526
527 //get the AI settings 527 //get the AI settings
528 AISettings ai=ai_mod->getAISettings(); 528 AISettings ai=ai_mod->getAISettings();
529 move->setAISettings(ai); 529 move->setAISettings(ai);
530 //write new settings to conf file 530 //write new settings to conf file
531 Config conf("backgammon"); 531 Config conf("backgammon");
532 conf.setGroup("ai"); 532 conf.setGroup("ai");
533 conf.writeEntry("rescue",ai.rescue); 533 conf.writeEntry("rescue",ai.rescue);
534 conf.writeEntry("eliminate",ai.eliminate); 534 conf.writeEntry("eliminate",ai.eliminate);
535 conf.writeEntry("expose",ai.expose); 535 conf.writeEntry("expose",ai.expose);
536 conf.writeEntry("protect",ai.protect); 536 conf.writeEntry("protect",ai.protect);
537 conf.writeEntry("safe",ai.safe); 537 conf.writeEntry("safe",ai.safe);
538 conf.writeEntry("empty",ai.empty); 538 conf.writeEntry("empty",ai.empty);
539} 539}
540 540
541void BackGammon::setrules() 541void BackGammon::setrules()
542{ 542{
543 RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme"); 543 RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme");
544 rulesdialog->setRules(rules); 544 rulesdialog->setRules(rules);
545 if(!rulesdialog->exec()) 545 if(!rulesdialog->exec())
546 return; 546 return;
547 rules=rulesdialog->getRules(); 547 rules=rulesdialog->getRules();
548 Config conf("backgammon"); 548 Config conf("backgammon");
549 conf.setGroup("rules"); 549 conf.setGroup("rules");
550 conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); 550 conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out);
551 conf.writeEntry("nice_dice",rules.generous_dice); 551 conf.writeEntry("nice_dice",rules.generous_dice);
552 move->setRules(rules); 552 move->setRules(rules);
553} 553}
554 554
555 555
556void BackGammon::draw() 556void BackGammon::draw()
557{ 557{
558 Pieces pieces; 558 Pieces pieces;
559 move->position(pieces); 559 move->position(pieces);
560 for(int a=0;a<15;a++) 560 for(int a=0;a<15;a++)
561 { 561 {
562 if(!pieces.player1[a].side) 562 if(!pieces.player1[a].side)
563 { 563 {
564 p1[a]->setX(pieces.player1[a].x); 564 p1[a]->setX(pieces.player1[a].x);
565 p1[a]->setY(pieces.player1[a].y); 565 p1[a]->setY(pieces.player1[a].y);
566 p1[a]->setZ(pieces.player1[a].z); 566 p1[a]->setZ(pieces.player1[a].z);
567 p1[a]->show(); 567 p1[a]->show();
568 p1_side[a]->hide(); 568 p1_side[a]->hide();
569 } 569 }
570 else 570 else
571 { 571 {
572 p1_side[a]->setX(pieces.player1[a].x); 572 p1_side[a]->setX(pieces.player1[a].x);
573 p1_side[a]->setY(pieces.player1[a].y); 573 p1_side[a]->setY(pieces.player1[a].y);
574 p1_side[a]->setZ(pieces.player1[a].z); 574 p1_side[a]->setZ(pieces.player1[a].z);
575 p1_side[a]->show(); 575 p1_side[a]->show();
576 p1[a]->hide(); 576 p1[a]->hide();
577 } 577 }
578 578
579 if(!pieces.player2[a].side) 579 if(!pieces.player2[a].side)
580 { 580 {
581 p2[a]->setX(pieces.player2[a].x); 581 p2[a]->setX(pieces.player2[a].x);
582 p2[a]->setY(pieces.player2[a].y); 582 p2[a]->setY(pieces.player2[a].y);
583 p2[a]->setZ(pieces.player2[a].z); 583 p2[a]->setZ(pieces.player2[a].z);
584 p2[a]->show(); 584 p2[a]->show();
585 p2_side[a]->hide(); 585 p2_side[a]->hide();
586 } 586 }
587 else 587 else
588 { 588 {
589 p2_side[a]->setX(pieces.player2[a].x); 589 p2_side[a]->setX(pieces.player2[a].x);
590 p2_side[a]->setY(pieces.player2[a].y); 590 p2_side[a]->setY(pieces.player2[a].y);
591 p2_side[a]->setZ(pieces.player2[a].z); 591 p2_side[a]->setZ(pieces.player2[a].z);
592 p2_side[a]->show(); 592 p2_side[a]->show();
593 p2[a]->hide(); 593 p2[a]->hide();
594 } 594 }
595 } 595 }
596} 596}
597 597
598void BackGammon::mouse(int x,int y) 598void BackGammon::mouse(int x,int y)
599{ 599{
600 if(gameFinished) 600 if(gameFinished)
601 { 601 {
602 newgame(); 602 newgame();
603 return; 603 return;
604 } 604 }
605 if(y<=200) //move pieces 605 if(y<=200) //move pieces
606 { 606 {
607 if((player==1 && player1_auto) || (player==2 && player2_auto)) 607 if((player==1 && player1_auto) || (player==2 && player2_auto))
608 return; 608 return;
609 609
610 Marker marker; 610 Marker marker;
611 611
612 move->boardpressed(x,y,marker); 612 move->boardpressed(x,y,marker);
613 if(marker.visible_current) 613 if(marker.visible_current)
614 { 614 {
615 marker_current->setX(marker.x_current); 615 marker_current->setX(marker.x_current);
616 marker_current->setY(marker.y_current); 616 marker_current->setY(marker.y_current);
617 marker_current->show(); 617 marker_current->show();
618 } 618 }
619 else 619 else
620 { 620 {
621 marker_current->hide(); 621 marker_current->hide();
622 } 622 }
623 623
624 for(int a=0;a<4;a++) 624 for(int a=0;a<4;a++)
625 { 625 {
626 if(marker.visible_next[a]) 626 if(marker.visible_next[a])
627 { 627 {
628 marker_next[a]->setX(marker.x_next[a]); 628 marker_next[a]->setX(marker.x_next[a]);
629 marker_next[a]->setY(marker.y_next[a]); 629 marker_next[a]->setY(marker.y_next[a]);
630 marker_next[a]->show(); 630 marker_next[a]->show();
631 } 631 }
632 else 632 else
633 { 633 {
634 marker_next[a]->hide(); 634 marker_next[a]->hide();
635 } 635 }
636 } 636 }
637 area->update(); 637 area->update();
638 } 638 }
639 else //roll dice 639 else //roll dice
640 { 640 {
641 if(x>=10 && x<=65 && player==1 && !dice_rolled) 641 if(x>=10 && x<=65 && player==1 && !dice_rolled)
642 { 642 {
643 dice1_played=false; 643 dice1_played=false;
644 dice2_played=false; 644 dice2_played=false;
645 dice3_played=false; 645 dice3_played=false;
646 dice4_played=false; 646 dice4_played=false;
647 dice_rolled=true; 647 dice_rolled=true;
648 srand(QTime::currentTime().msec()); 648 srand(QTime::currentTime().msec());
649 diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); 649 diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
650 diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); 650 diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
651 if(diceA1_value==diceA2_value) 651 if(diceA1_value==diceA2_value)
652 { 652 {
653 diceA3_value=diceA1_value; 653 diceA3_value=diceA1_value;
654 diceA4_value=diceA1_value; 654 diceA4_value=diceA1_value;
655 } 655 }
656 else 656 else
657 { 657 {
658 diceA3_value=7; 658 diceA3_value=7;
659 dice3_played=true; 659 dice3_played=true;
660 diceA4_value=7; 660 diceA4_value=7;
661 dice4_played=true; 661 dice4_played=true;
662 } 662 }
663 showdice(); 663 showdice();
664 area->update(); 664 area->update();
665 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 665 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
666 666
667 } 667 }
668 else if(x>=160 && x<=225 && player==2 && !dice_rolled) 668 else if(x>=160 && x<=225 && player==2 && !dice_rolled)
669 { 669 {
670 dice1_played=false; 670 dice1_played=false;
671 dice2_played=false; 671 dice2_played=false;
672 dice3_played=false; 672 dice3_played=false;
673 dice4_played=false; 673 dice4_played=false;
674 dice_rolled=true; 674 dice_rolled=true;
675 srand(QTime::currentTime().msec()); 675 srand(QTime::currentTime().msec());
676 diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); 676 diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
677 diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); 677 diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0));
678 if(diceB1_value==diceB2_value) 678 if(diceB1_value==diceB2_value)
679 { 679 {
680 diceB3_value=diceB1_value; 680 diceB3_value=diceB1_value;
681 diceB4_value=diceB1_value; 681 diceB4_value=diceB1_value;
682 } 682 }
683 else 683 else
684 { 684 {
685 diceB3_value=7; 685 diceB3_value=7;
686 dice3_played=true; 686 dice3_played=true;
687 diceB4_value=7; 687 diceB4_value=7;
688 dice4_played=true; 688 dice4_played=true;
689 } 689 }
690 showdice(); 690 showdice();
691 area->update(); 691 area->update();
692 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 692 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
693 } 693 }
694 } 694 }
695} 695}
696 696
697void BackGammon::done_dice1() 697void BackGammon::done_dice1()
698{ 698{
699 dice1_played=true; 699 dice1_played=true;
700 if(player==1) 700 if(player==1)
701 diceA1_value=7; 701 diceA1_value=7;
702 else 702 else
703 diceB1_value=7; 703 diceB1_value=7;
704 setplayer(); 704 setplayer();
705 showdice(); 705 showdice();
706 draw(); 706 draw();
707 area->update(); 707 area->update();
708 if(!dice2_played || !dice3_played || !dice4_played) 708 if(!dice2_played || !dice3_played || !dice4_played)
709 { 709 {
710 if(player==1) 710 if(player==1)
711 { 711 {
712 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 712 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
713 } 713 }
714 else 714 else
715 { 715 {
716 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 716 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
717 } 717 }
718 } 718 }
719} 719}
720 720
721void BackGammon::done_dice2() 721void BackGammon::done_dice2()
722{ 722{
723 dice2_played=true; 723 dice2_played=true;
724 if(player==1) 724 if(player==1)
725 diceA2_value=7; 725 diceA2_value=7;
726 else 726 else
727 diceB2_value=7; 727 diceB2_value=7;
728 setplayer(); 728 setplayer();
729 showdice(); 729 showdice();
730 draw(); 730 draw();
731 area->update(); 731 area->update();
732 if(!dice1_played || !dice3_played || !dice4_played) 732 if(!dice1_played || !dice3_played || !dice4_played)
733 { 733 {
734 if(player==1) 734 if(player==1)
735 { 735 {
736 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 736 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
737 } 737 }
738 else 738 else
739 { 739 {
740 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 740 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
741 } 741 }
742 } 742 }
743} 743}
744 744
745 745
746void BackGammon::done_dice3() 746void BackGammon::done_dice3()
747{ 747{
748 dice3_played=true; 748 dice3_played=true;
749 if(player==1) 749 if(player==1)
750 diceA3_value=7; 750 diceA3_value=7;
751 else 751 else
752 diceB3_value=7; 752 diceB3_value=7;
753 setplayer(); 753 setplayer();
754 showdice(); 754 showdice();
755 draw(); 755 draw();
756 area->update(); 756 area->update();
757 if(!dice1_played || !dice2_played || !dice4_played) 757 if(!dice1_played || !dice2_played || !dice4_played)
758 { 758 {
759 if(player==1) 759 if(player==1)
760 { 760 {
761 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 761 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
762 } 762 }
763 else 763 else
764 { 764 {
765 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 765 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
766 } 766 }
767 } 767 }
768} 768}
769 769
770 770
771void BackGammon::done_dice4() 771void BackGammon::done_dice4()
772{ 772{
773 dice4_played=true; 773 dice4_played=true;
774 if(player==1) 774 if(player==1)
775 diceA4_value=7; 775 diceA4_value=7;
776 else 776 else
777 diceB4_value=7; 777 diceB4_value=7;
778 setplayer(); 778 setplayer();
779 showdice(); 779 showdice();
780 draw(); 780 draw();
781 area->update(); 781 area->update();
782 if(!dice1_played || !dice2_played || !dice3_played) 782 if(!dice1_played || !dice2_played || !dice3_played)
783 { 783 {
784 if(player==1) 784 if(player==1)
785 { 785 {
786 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); 786 move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto);
787 } 787 }
788 else 788 else
789 { 789 {
790 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); 790 move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto);
791 } 791 }
792 } 792 }
793} 793}
794 794
795 795
796void BackGammon::nomove() 796void BackGammon::nomove()
797{ 797{
798 if(player==1) 798 if(player==1)
799 nomove_marker->setX(0); 799 nomove_marker->setX(0);
800 else 800 else
801 nomove_marker->setX(170); 801 nomove_marker->setX(170);
802 nomove_marker->show(); 802 nomove_marker->show();
803 message->setText(tr( "<b>no move</b>" )); 803 message->setText(tr( "<b>no move</b>" ));
804 dice1_played=true; 804 dice1_played=true;
805 dice2_played=true; 805 dice2_played=true;
806 dice3_played=true; 806 dice3_played=true;
807 dice4_played=true; 807 dice4_played=true;
808 if(player==1) 808 if(player==1)
809 { 809 {
810 diceA1_value=7; 810 diceA1_value=7;
811 diceA2_value=7; 811 diceA2_value=7;
812 diceA3_value=7; 812 diceA3_value=7;
813 diceA4_value=7; 813 diceA4_value=7;
814 } 814 }
815 else 815 else
816 { 816 {
817 diceB1_value=7; 817 diceB1_value=7;
818 diceB2_value=7; 818 diceB2_value=7;
819 diceB3_value=7; 819 diceB3_value=7;
820 diceB4_value=7; 820 diceB4_value=7;
821 } 821 }
822 area->update(); 822 area->update();
823 QTimer::singleShot(2000,this,SLOT(nomove2())); 823 QTimer::singleShot(2000,this,SLOT(nomove2()));
824} 824}
825 825
826void BackGammon::nomove2() 826void BackGammon::nomove2()
827{ 827{
828 nomove_marker->hide(); 828 nomove_marker->hide();
829 setplayer(); 829 setplayer();
830 showdice(); 830 showdice();
831 draw(); 831 draw();
832 area->update(); 832 area->update();
833} 833}
834 834
835void BackGammon::finished(int theplayer) 835void BackGammon::finished(int theplayer)
836{ 836{
837 nomove_marker->hide(); 837 nomove_marker->hide();
838 if(theplayer==1) 838 if(theplayer==1)
839 message->setText(tr( "<b>Player 1 wins. Click on board for new game.</b>" )); 839 message->setText(tr( "<b>Player 1 wins. Click on board for new game.</b>" ));
840 else 840 else
841 message->setText(tr( "<b>Player 2 wins. Click on board for new game.</b>" )); 841 message->setText(tr( "<b>Player 2 wins. Click on board for new game.</b>" ));
842 diceA1_value=7; 842 diceA1_value=7;
843 diceA2_value=7; 843 diceA2_value=7;
844 diceB1_value=7; 844 diceB1_value=7;
845 diceB2_value=7; 845 diceB2_value=7;
846 player=0; 846 player=0;
847 showdice(); 847 showdice();
848 draw(); 848 draw();
849 area->update(); 849 area->update();
850 gameFinished=true; 850 gameFinished=true;
851} 851}
852 852
853void BackGammon::showdice() 853void BackGammon::showdice()
854{ 854{
855 int value_diceA1=diceA1_value-1; 855 int value_diceA1=diceA1_value-1;
856 if(diceA1_value==7 && diceA3_value!=7) 856 if(diceA1_value==7 && diceA3_value!=7)
857 value_diceA1=diceA3_value-1; 857 value_diceA1=diceA3_value-1;
858 858
859 int value_diceA2=diceA2_value-1; 859 int value_diceA2=diceA2_value-1;
860 if(diceA2_value==7 && diceA4_value!=7) 860 if(diceA2_value==7 && diceA4_value!=7)
861 value_diceA2=diceA4_value-1; 861 value_diceA2=diceA4_value-1;
862 862
863 int value_diceB1=diceB1_value-1; 863 int value_diceB1=diceB1_value-1;
864 if(diceB1_value==7 && diceB3_value!=7) 864 if(diceB1_value==7 && diceB3_value!=7)
865 value_diceB1=diceB3_value-1; 865 value_diceB1=diceB3_value-1;
866 866
867 int value_diceB2=diceB2_value-1; 867 int value_diceB2=diceB2_value-1;
868 if(diceB2_value==7 && diceB4_value!=7) 868 if(diceB2_value==7 && diceB4_value!=7)
869 value_diceB2=diceB4_value-1; 869 value_diceB2=diceB4_value-1;
870 870
871 for(int index=0;index<7;index++) 871 for(int index=0;index<7;index++)
872 { 872 {
873 if(value_diceA1==index) 873 if(value_diceA1==index)
874 diceA1[index]->show(); 874 diceA1[index]->show();
875 else 875 else
876 diceA1[index]->hide(); 876 diceA1[index]->hide();
877 877
878 if(value_diceA2==index) 878 if(value_diceA2==index)
879 diceA2[index]->show(); 879 diceA2[index]->show();
880 else 880 else
881 diceA2[index]->hide(); 881 diceA2[index]->hide();
882 882
883 if(value_diceB1==index) 883 if(value_diceB1==index)
884 diceB1[index]->show(); 884 diceB1[index]->show();
885 else 885 else
886 diceB1[index]->hide(); 886 diceB1[index]->hide();
887 887
888 if(value_diceB2==index) 888 if(value_diceB2==index)
889 diceB2[index]->show(); 889 diceB2[index]->show();
890 else 890 else
891 diceB2[index]->hide(); 891 diceB2[index]->hide();
892 } 892 }
893} 893}
894 894
895void BackGammon::setplayer() 895void BackGammon::setplayer()
896{ 896{
897 if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) 897 if(dice1_played && dice2_played && dice3_played && dice4_played && player==1)
898 { 898 {
899 message->setText(tr( "<b>P2 turn</b>", "P means player" )); 899 message->setText(tr( "<b>P2 turn</b>", "P means player" ));
900 dice_rolled=false; 900 dice_rolled=false;
901 player=2; 901 player=2;
902 if(player2_auto) 902 if(player2_auto)
903 QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); 903 QTimer::singleShot(2000,this,SLOT(autoroll_dice2()));
904 } 904 }
905 else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) 905 else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2)
906 { 906 {
907 message->setText(tr( "<b>P1 turn</b>", "P means player" )); 907 message->setText(tr( "<b>P1 turn</b>", "P means player" ));
908 dice_rolled=false; 908 dice_rolled=false;
909 player=1; 909 player=1;
910 if(player1_auto) 910 if(player1_auto)
911 QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); 911 QTimer::singleShot(2000,this,SLOT(autoroll_dice1()));
912 } 912 }
913} 913}
914 914
915void BackGammon::autoroll_dice1() 915void BackGammon::autoroll_dice1()
916{ 916{
917 mouse(20,210); 917 mouse(20,210);
918} 918}
919 919
920void BackGammon::autoroll_dice2() 920void BackGammon::autoroll_dice2()
921{ 921{
922 mouse(170,210); 922 mouse(170,210);
923} 923}
924 924
925void BackGammon::applytheme() 925void BackGammon::applytheme()
926{ 926{
927 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); 927 QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name));
928 board->setImage(boardbg); 928 board->setImage(boardbg);
929 929
930 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); 930 QImage tablebg(Resource::loadImage("backgammon/table/"+table_name));
931 table->setImage(tablebg); 931 table->setImage(tablebg);
932 932
933 QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); 933 QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name));
934 QImage piece_1_front=piece_1_all.copy(0,0,15,15); 934 QImage piece_1_front=piece_1_all.copy(0,0,15,15);
935 QImage piece_1_side=piece_1_all.copy(0,15,15,5); 935 QImage piece_1_side=piece_1_all.copy(0,15,15,5);
936 936
937 QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); 937 QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name));
938 QImage piece_2_front=piece_2_all.copy(0,0,15,15); 938 QImage piece_2_front=piece_2_all.copy(0,0,15,15);
939 QImage piece_2_side=piece_2_all.copy(0,15,15,5); 939 QImage piece_2_side=piece_2_all.copy(0,15,15,5);
940 940
941 int a=0; 941 int a=0;
942 for(a=0;a<15;a++) 942 for(a=0;a<15;a++)
943 { 943 {
944 p1[a]->setImage(piece_1_front); 944 p1[a]->setImage(piece_1_front);
945 p1_side[a]->setImage(piece_1_side); 945 p1_side[a]->setImage(piece_1_side);
946 946
947 p2[a]->setImage(piece_2_front); 947 p2[a]->setImage(piece_2_front);
948 p2_side[a]->setImage(piece_2_side); 948 p2_side[a]->setImage(piece_2_side);
949 } 949 }
950 draw(); 950 draw();
951 951
952 QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); 952 QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name));
953 QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); 953 QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name));
954 QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); 954 QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name));
955 955
956 for(a=0;a<7;a++) 956 for(a=0;a<7;a++)
957 { 957 {
958 QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); 958 QImage dicebgA=dicebgA_all.copy(a*25,0,25,25);
959 diceA1[a]->setImage(dicebgA); 959 diceA1[a]->setImage(dicebgA);
960 diceA2[a]->setImage(dicebgA); 960 diceA2[a]->setImage(dicebgA);
961 961
962 QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); 962 QImage dicebgB=dicebgB_all.copy(a*25,0,25,25);
963 diceB1[a]->setImage(dicebgB); 963 diceB1[a]->setImage(dicebgB);
964 diceB2[a]->setImage(dicebgB); 964 diceB2[a]->setImage(dicebgB);
965 /* 965 /*
966 if(a<6) 966 if(a<6)
967 { 967 {
968 QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); 968 QImage oddsbg=oddsbg_all.copy(a*15,0,15,15);
969 oddsDice[a]->setImage(oddsbg); 969 oddsDice[a]->setImage(oddsbg);
970 } 970 }
971 */ 971 */
972 } 972 }
973} 973}
974 974
975 975
diff --git a/noncore/games/backgammon/filedialog.cpp b/noncore/games/backgammon/filedialog.cpp
index e0a2914..f185188 100644
--- a/noncore/games/backgammon/filedialog.cpp
+++ b/noncore/games/backgammon/filedialog.cpp
@@ -1,61 +1,61 @@
1#include "filedialog.h" 1#include "filedialog.h"
2 2
3#include <qdir.h> 3#include <qdir.h>
4#include <qpe/qpeapplication.h> 4#include <qpe/qpeapplication.h>
5 5
6FileDialog::FileDialog(QWidget* parent,QString header,QString extension,const char* name,bool modal,WFlags f) 6FileDialog::FileDialog(QWidget* parent,QString header,QString extension,const char* name,bool modal,WFlags f)
7 :QDialog(parent,name,modal,f) 7 :QDialog(parent,name,modal,f)
8{ 8{
9 setCaption(header); 9 setCaption(header);
10 ext=extension; 10 ext=extension;
11 dirselector=new QListView(this); 11 dirselector=new QListView(this);
12 dirselector->setGeometry(1,10,235,200); 12 dirselector->setGeometry(1,10,235,200);
13 dirselector->addColumn("Files"); 13 dirselector->addColumn("Files");
14 connect(dirselector,SIGNAL(clicked(QListViewItem*)),this,SLOT(selectorclicked(QListViewItem*))); 14 connect(dirselector,SIGNAL(clicked(QListViewItem*)),this,SLOT(selectorclicked(QListViewItem*)));
15 15
16 getCurrentDir(); 16 getCurrentDir();
17 17
18 file_name="user"; 18 file_name="user";
19 fileinput=new QLineEdit(file_name,this); 19 fileinput=new QLineEdit(file_name,this);
20 fileinput->setGeometry(1,220,235,20); 20 fileinput->setGeometry(1,220,235,20);
21 21
22 QPEApplication::showDialog( this ); 22 QPEApplication::showDialog( this );
23} 23}
24 24
25FileDialog::~FileDialog() 25FileDialog::~FileDialog()
26{} 26{}
27 27
28 28
29void FileDialog::selectorclicked(QListViewItem* entry) 29void FileDialog::selectorclicked(QListViewItem* entry)
30{ 30{
31 if(entry==NULL) 31 if(entry==NULL)
32 return; 32 return;
33 file_name=entry->text(0); 33 file_name=entry->text(0);
34 fileinput->setText(file_name); 34 fileinput->setText(file_name);
35} 35}
36 36
37void FileDialog::getCurrentDir() 37void FileDialog::getCurrentDir()
38{ 38{
39 dirselector->clear(); 39 dirselector->clear();
40 QDir dir(QPEApplication::qpeDir()+"/backgammon"); 40 QDir dir(QPEApplication::qpeDir()+"backgammon");
41 dir.setFilter(QDir::Files); 41 dir.setFilter(QDir::Files);
42 QFileInfoListIterator it(*(dir.entryInfoList())); 42 QFileInfoListIterator it(*(dir.entryInfoList()));
43 QFileInfo* fi; 43 QFileInfo* fi;
44 44
45 int ext_length=ext.length(); 45 int ext_length=ext.length();
46 while((fi=it.current())) // go through all file and subdirs 46 while((fi=it.current())) // go through all file and subdirs
47 { 47 {
48 QString file=fi->fileName(); 48 QString file=fi->fileName();
49 if(file.right(ext_length)==ext && file) 49 if(file.right(ext_length)==ext && file)
50 { 50 {
51 file=file.left(file.length()-ext_length); 51 file=file.left(file.length()-ext_length);
52 new QListViewItem(dirselector,file); 52 new QListViewItem(dirselector,file);
53 } 53 }
54 ++it; 54 ++it;
55 } 55 }
56} 56}
57 57
58QString FileDialog::filename() 58QString FileDialog::filename()
59{ 59{
60 return file_name; 60 return file_name;
61} 61}
diff --git a/noncore/games/backgammon/themedialog.cpp b/noncore/games/backgammon/themedialog.cpp
index afd6a1b..9bdb6a9 100644
--- a/noncore/games/backgammon/themedialog.cpp
+++ b/noncore/games/backgammon/themedialog.cpp
@@ -1,161 +1,161 @@
1#include "themedialog.h" 1#include "themedialog.h"
2 2
3#include <qdir.h> 3#include <qdir.h>
4#include <qlabel.h> 4#include <qlabel.h>
5#include <qpe/qpeapplication.h> 5#include <qpe/qpeapplication.h>
6 6
7 7
8ThemeDialog::ThemeDialog(QWidget* parent,const char* name,bool modal,WFlags f) 8ThemeDialog::ThemeDialog(QWidget* parent,const char* name,bool modal,WFlags f)
9 :QDialog(parent,name,modal,f) 9 :QDialog(parent,name,modal,f)
10{ 10{
11 setCaption("Theme Dialog"); 11 setCaption("Theme Dialog");
12 QLabel* labelname=new QLabel("name",this); 12 QLabel* labelname=new QLabel("name",this);
13 labelname->setGeometry(0,5,40,20); 13 labelname->setGeometry(0,5,40,20);
14 lineName=new QLineEdit("user",this); 14 lineName=new QLineEdit("user",this);
15 lineName->setGeometry(40,5,195,20); 15 lineName->setGeometry(40,5,195,20);
16 16
17 QLabel* labelboard=new QLabel("board",this); 17 QLabel* labelboard=new QLabel("board",this);
18 labelboard->setGeometry(0,30,40,20); 18 labelboard->setGeometry(0,30,40,20);
19 boxboard=new QComboBox(this,""); 19 boxboard=new QComboBox(this,"");
20 boxboard->setGeometry(40,30,195,20); 20 boxboard->setGeometry(40,30,195,20);
21 fillBox("boards",boxboard); 21 fillBox("boards",boxboard);
22 22
23 QLabel* labelpiecesA=new QLabel("pieces1",this); 23 QLabel* labelpiecesA=new QLabel("pieces1",this);
24 labelpiecesA->setGeometry(0,70,40,20); 24 labelpiecesA->setGeometry(0,70,40,20);
25 boxpiecesA=new QComboBox(this); 25 boxpiecesA=new QComboBox(this);
26 boxpiecesA->setGeometry(40,70,195,20); 26 boxpiecesA->setGeometry(40,70,195,20);
27 fillBox("pieces",boxpiecesA); 27 fillBox("pieces",boxpiecesA);
28 28
29 QLabel* labelpiecesB=new QLabel("pieces2",this); 29 QLabel* labelpiecesB=new QLabel("pieces2",this);
30 labelpiecesB->setGeometry(0,95,40,20); 30 labelpiecesB->setGeometry(0,95,40,20);
31 boxpiecesB=new QComboBox(this); 31 boxpiecesB=new QComboBox(this);
32 boxpiecesB->setGeometry(40,95,195,20); 32 boxpiecesB->setGeometry(40,95,195,20);
33 fillBox("pieces",boxpiecesB); 33 fillBox("pieces",boxpiecesB);
34 34
35 QLabel* labeldiceA=new QLabel("dice1",this); 35 QLabel* labeldiceA=new QLabel("dice1",this);
36 labeldiceA->setGeometry(0,135,40,20); 36 labeldiceA->setGeometry(0,135,40,20);
37 boxdiceA=new QComboBox(this); 37 boxdiceA=new QComboBox(this);
38 boxdiceA->setGeometry(40,135,195,20); 38 boxdiceA->setGeometry(40,135,195,20);
39 fillBox("dice",boxdiceA); 39 fillBox("dice",boxdiceA);
40 40
41 QLabel* labeldiceB=new QLabel("dice2",this); 41 QLabel* labeldiceB=new QLabel("dice2",this);
42 labeldiceB->setGeometry(0,160,40,20); 42 labeldiceB->setGeometry(0,160,40,20);
43 boxdiceB=new QComboBox(this); 43 boxdiceB=new QComboBox(this);
44 boxdiceB->setGeometry(40,160,195,20); 44 boxdiceB->setGeometry(40,160,195,20);
45 fillBox("dice",boxdiceB); 45 fillBox("dice",boxdiceB);
46 46
47 QLabel* labelodds=new QLabel("odds",this); 47 QLabel* labelodds=new QLabel("odds",this);
48 labelodds->setGeometry(0,200,40,20); 48 labelodds->setGeometry(0,200,40,20);
49 boxodds=new QComboBox(this); 49 boxodds=new QComboBox(this);
50 boxodds->setGeometry(40,200,195,20); 50 boxodds->setGeometry(40,200,195,20);
51 fillBox("odds",boxodds); 51 fillBox("odds",boxodds);
52 boxodds->setEnabled(false); 52 boxodds->setEnabled(false);
53 53
54 QLabel* labeltable=new QLabel("table",this); 54 QLabel* labeltable=new QLabel("table",this);
55 labeltable->setGeometry(0,225,40,20); 55 labeltable->setGeometry(0,225,40,20);
56 boxtable=new QComboBox(this); 56 boxtable=new QComboBox(this);
57 boxtable->setGeometry(40,225,195,20); 57 boxtable->setGeometry(40,225,195,20);
58 fillBox("table",boxtable); 58 fillBox("table",boxtable);
59 59
60 QPEApplication::showDialog( this ); 60 QPEApplication::showDialog( this );
61} 61}
62 62
63ThemeDialog::~ThemeDialog() 63ThemeDialog::~ThemeDialog()
64{} 64{}
65 65
66 66
67ImageNames ThemeDialog::getNames() 67ImageNames ThemeDialog::getNames()
68{ 68{
69 ImageNames names; 69 ImageNames names;
70 names.theme=lineName->text(); 70 names.theme=lineName->text();
71 names.board=boxboard->currentText(); 71 names.board=boxboard->currentText();
72 names.pieces1=boxpiecesA->currentText(); 72 names.pieces1=boxpiecesA->currentText();
73 names.pieces2=boxpiecesB->currentText(); 73 names.pieces2=boxpiecesB->currentText();
74 names.dice1=boxdiceA->currentText(); 74 names.dice1=boxdiceA->currentText();
75 names.dice2=boxdiceB->currentText(); 75 names.dice2=boxdiceB->currentText();
76 names.odds=boxodds->currentText(); 76 names.odds=boxodds->currentText();
77 names.table=boxtable->currentText(); 77 names.table=boxtable->currentText();
78 return names; 78 return names;
79} 79}
80 80
81void ThemeDialog::setCurrent(const ImageNames& current) 81void ThemeDialog::setCurrent(const ImageNames& current)
82{ 82{
83 int a=0; 83 int a=0;
84 lineName->setText(current.theme); 84 lineName->setText(current.theme);
85 for(a=0;a<boxboard->count();a++) 85 for(a=0;a<boxboard->count();a++)
86 { 86 {
87 if(boxboard->text(a)==current.board) 87 if(boxboard->text(a)==current.board)
88 { 88 {
89 boxboard->setCurrentItem(a); 89 boxboard->setCurrentItem(a);
90 break; 90 break;
91 } 91 }
92 } 92 }
93 for(a=0;a<boxpiecesA->count();a++) 93 for(a=0;a<boxpiecesA->count();a++)
94 { 94 {
95 if(boxpiecesA->text(a)==current.pieces1) 95 if(boxpiecesA->text(a)==current.pieces1)
96 { 96 {
97 boxpiecesA->setCurrentItem(a); 97 boxpiecesA->setCurrentItem(a);
98 break; 98 break;
99 } 99 }
100 } 100 }
101 for(a=0;a<boxpiecesB->count();a++) 101 for(a=0;a<boxpiecesB->count();a++)
102 { 102 {
103 if(boxpiecesB->text(a)==current.pieces2) 103 if(boxpiecesB->text(a)==current.pieces2)
104 { 104 {
105 boxpiecesB->setCurrentItem(a); 105 boxpiecesB->setCurrentItem(a);
106 break; 106 break;
107 } 107 }
108 } 108 }
109 for(a=0;a<boxdiceA->count();a++) 109 for(a=0;a<boxdiceA->count();a++)
110 { 110 {
111 if(boxdiceA->text(a)==current.dice1) 111 if(boxdiceA->text(a)==current.dice1)
112 { 112 {
113 boxdiceA->setCurrentItem(a); 113 boxdiceA->setCurrentItem(a);
114 break; 114 break;
115 } 115 }
116 } 116 }
117 for(a=0;a<boxdiceB->count();a++) 117 for(a=0;a<boxdiceB->count();a++)
118 { 118 {
119 if(boxdiceB->text(a)==current.dice2) 119 if(boxdiceB->text(a)==current.dice2)
120 { 120 {
121 boxdiceB->setCurrentItem(a); 121 boxdiceB->setCurrentItem(a);
122 break; 122 break;
123 } 123 }
124 } 124 }
125 for(a=0;a<boxodds->count();a++) 125 for(a=0;a<boxodds->count();a++)
126 { 126 {
127 if(boxodds->text(a)==current.odds) 127 if(boxodds->text(a)==current.odds)
128 { 128 {
129 boxodds->setCurrentItem(a); 129 boxodds->setCurrentItem(a);
130 break; 130 break;
131 } 131 }
132 } 132 }
133 for(a=0;a<boxtable->count();a++) 133 for(a=0;a<boxtable->count();a++)
134 { 134 {
135 if(boxtable->text(a)==current.table) 135 if(boxtable->text(a)==current.table)
136 { 136 {
137 boxtable->setCurrentItem(a); 137 boxtable->setCurrentItem(a);
138 break; 138 break;
139 } 139 }
140 } 140 }
141} 141}
142 142
143void ThemeDialog::fillBox(QString dirname,QComboBox* thebox) 143void ThemeDialog::fillBox(QString dirname,QComboBox* thebox)
144{ 144{
145 thebox->clear(); 145 thebox->clear();
146 QDir dir(QPEApplication::qpeDir()+"/pics/backgammon/"+dirname); 146 QDir dir(QPEApplication::qpeDir()+"pics/backgammon/"+dirname);
147 dir.setFilter(QDir::Dirs | QDir::Files); 147 dir.setFilter(QDir::Dirs | QDir::Files);
148 QFileInfoListIterator it(*(dir.entryInfoList())); 148 QFileInfoListIterator it(*(dir.entryInfoList()));
149 QFileInfo* fi; 149 QFileInfo* fi;
150 150
151 while((fi=it.current())) // go through all file and subdirs 151 while((fi=it.current())) // go through all file and subdirs
152 { 152 {
153 QString file=fi->fileName(); 153 QString file=fi->fileName();
154 if(file.right(4)==".png") 154 if(file.right(4)==".png")
155 { 155 {
156 thebox->insertItem(file.left(file.find(".png"))); 156 thebox->insertItem(file.left(file.find(".png")));
157 } 157 }
158 ++it; 158 ++it;
159 } 159 }
160 delete fi; 160 delete fi;
161} 161}
diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp
index dc2c496..2e9553f 100644
--- a/noncore/multimedia/opieplayer2/playlistwidget.cpp
+++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp
@@ -1,1066 +1,1066 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 3
4 Copyright (c) 2002,2003 Max Reiss <harlekin@handhelds.org> 4 Copyright (c) 2002,2003 Max Reiss <harlekin@handhelds.org>
5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com> 5 Copyright (c) 2002 L. Potter <ljp@llornkcor.com>
6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org> 6 Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
7 =. 7 =.
8 .=l. 8 .=l.
9 .>+-= 9 .>+-=
10_;:, .> :=|. This program is free software; you can 10_;:, .> :=|. This program is free software; you can
11.> <`_, > . <= redistribute it and/or modify it under 11.> <`_, > . <= redistribute it and/or modify it under
12:`=1 )Y*s>-.-- : the terms of the GNU General Public 12:`=1 )Y*s>-.-- : the terms of the GNU General Public
13.="- .-=="i, .._ License as published by the Free Software 13.="- .-=="i, .._ License as published by the Free Software
14- . .-<_> .<> Foundation; either version 2 of the License, 14- . .-<_> .<> Foundation; either version 2 of the License,
15 ._= =} : or (at your option) any later version. 15 ._= =} : or (at your option) any later version.
16 .%`+i> _;_. 16 .%`+i> _;_.
17 .i_,=:_. -<s. This program is distributed in the hope that 17 .i_,=:_. -<s. This program is distributed in the hope that
18 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 18 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
19 : .. .:, . . . without even the implied warranty of 19 : .. .:, . . . without even the implied warranty of
20 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 20 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
21 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 21 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.= = ; General Public License for more 22..}^=.= = ; General Public License for more
23++= -. .` .: details. 23++= -. .` .: details.
24: = ...= . :.=- 24: = ...= . :.=-
25-. .:....=;==+<; You should have received a copy of the GNU 25-. .:....=;==+<; You should have received a copy of the GNU
26 -_. . . )=. = General Public License along with 26 -_. . . )=. = General Public License along with
27 -- :-=` this library; see the file COPYING.LIB. 27 -- :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#include "playlistselection.h" 34#include "playlistselection.h"
35#include "playlistwidget.h" 35#include "playlistwidget.h"
36#include "mediaplayer.h" 36#include "mediaplayer.h"
37#include "inputDialog.h" 37#include "inputDialog.h"
38#include "om3u.h" 38#include "om3u.h"
39#include "playlistfileview.h" 39#include "playlistfileview.h"
40 40
41/* OPIE */ 41/* OPIE */
42#include <opie2/odebug.h> 42#include <opie2/odebug.h>
43#include <opie2/ofiledialog.h> 43#include <opie2/ofiledialog.h>
44using namespace Opie::Core; 44using namespace Opie::Core;
45using namespace Opie::Ui; 45using namespace Opie::Ui;
46 46
47/* QT */ 47/* QT */
48#include <qmessagebox.h> 48#include <qmessagebox.h>
49#include <qtoolbar.h> 49#include <qtoolbar.h>
50 50
51/* STD */ 51/* STD */
52#include <assert.h> 52#include <assert.h>
53 53
54PlayListWidget::PlayListWidget(QWidget* parent, const char* name, WFlags fl ) 54PlayListWidget::PlayListWidget(QWidget* parent, const char* name, WFlags fl )
55 : PlayListWidgetGui( parent, "playList" ) , currentFileListView( 0 ) 55 : PlayListWidgetGui( parent, "playList" ) , currentFileListView( 0 )
56{ 56{
57 Global::statusMessage( tr( "Loading of Skin started" ) ); 57 Global::statusMessage( tr( "Loading of Skin started" ) );
58 mediaPlayerState = new MediaPlayerState(0, "mediaPlayerState" ); 58 mediaPlayerState = new MediaPlayerState(0, "mediaPlayerState" );
59 m_mp = new MediaPlayer(*this, *mediaPlayerState, 0, "mediaPlayer"); 59 m_mp = new MediaPlayer(*this, *mediaPlayerState, 0, "mediaPlayer");
60 60
61 61
62 62
63 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), 63 d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ),
64 "opieplayer2/add_to_playlist", 64 "opieplayer2/add_to_playlist",
65 this , SLOT(addSelected() ) ); 65 this , SLOT(addSelected() ) );
66 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), 66 d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ),
67 "opieplayer2/remove_from_playlist", 67 "opieplayer2/remove_from_playlist",
68 this , SLOT(removeSelected() ) ); 68 this , SLOT(removeSelected() ) );
69 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play", 69 d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer2/play",
70 this , SLOT( btnPlay(bool) ), TRUE ); 70 this , SLOT( btnPlay(bool) ), TRUE );
71 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle", 71 d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer2/shuffle",
72 mediaPlayerState, SLOT( setShuffled(bool) ), TRUE ); 72 mediaPlayerState, SLOT( setShuffled(bool) ), TRUE );
73 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop", 73 d->tbLoop = new ToolButton( bar, tr( "Loop" ), "opieplayer2/loop",
74 mediaPlayerState, SLOT( setLooping(bool) ), TRUE ); 74 mediaPlayerState, SLOT( setLooping(bool) ), TRUE );
75 75
76 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); 76 (void)new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) );
77 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ), 77 (void)new MenuItem( pmPlayList, tr( "Add all audio files" ),
78 this, SLOT( addAllMusicToList() ) ); 78 this, SLOT( addAllMusicToList() ) );
79 (void)new MenuItem( pmPlayList, tr( "Add all video files" ), 79 (void)new MenuItem( pmPlayList, tr( "Add all video files" ),
80 this, SLOT( addAllVideoToList() ) ); 80 this, SLOT( addAllVideoToList() ) );
81 (void)new MenuItem( pmPlayList, tr( "Add all files" ), 81 (void)new MenuItem( pmPlayList, tr( "Add all files" ),
82 this, SLOT( addAllToList() ) ); 82 this, SLOT( addAllToList() ) );
83 pmPlayList->insertSeparator(-1); 83 pmPlayList->insertSeparator(-1);
84 (void)new MenuItem( pmPlayList, tr( "Add File" ), 84 (void)new MenuItem( pmPlayList, tr( "Add File" ),
85 this,SLOT( openFile() ) ); 85 this,SLOT( openFile() ) );
86 (void)new MenuItem( pmPlayList, tr("Add URL"), 86 (void)new MenuItem( pmPlayList, tr("Add URL"),
87 this,SLOT( openURL() ) ); 87 this,SLOT( openURL() ) );
88 (void)new MenuItem( pmPlayList, tr( "Add Directory"), 88 (void)new MenuItem( pmPlayList, tr( "Add Directory"),
89 this, SLOT(openDirectory())); 89 this, SLOT(openDirectory()));
90 pmPlayList->insertSeparator(-1); 90 pmPlayList->insertSeparator(-1);
91 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ), 91 (void)new MenuItem( pmPlayList, tr( "Save Playlist" ),
92 this, SLOT(writem3u() ) ); 92 this, SLOT(writem3u() ) );
93 pmPlayList->insertSeparator(-1); 93 pmPlayList->insertSeparator(-1);
94 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), 94 (void)new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ),
95 audioView, SLOT( scanFiles() ) ); 95 audioView, SLOT( scanFiles() ) );
96 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), 96 (void)new MenuItem( pmPlayList, tr( "Rescan for Video Files" ),
97 videoView, SLOT( scanFiles() ) ); 97 videoView, SLOT( scanFiles() ) );
98 98
99 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"), 99 pmView->insertItem( Resource::loadPixmap("fullscreen") , tr( "Full Screen"),
100 mediaPlayerState, SLOT( toggleFullscreen() ) ); 100 mediaPlayerState, SLOT( toggleFullscreen() ) );
101 101
102 Config cfg( "OpiePlayer" ); 102 Config cfg( "OpiePlayer" );
103 bool b= cfg.readBoolEntry("FullScreen", 0); 103 bool b= cfg.readBoolEntry("FullScreen", 0);
104 mediaPlayerState->setFullscreen( b ); 104 mediaPlayerState->setFullscreen( b );
105 pmView->setItemChecked( -16, b ); 105 pmView->setItemChecked( -16, b );
106 106
107 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up", 107 (void)new ToolButton( vbox1, tr( "Move Up" ), "opieplayer2/up",
108 d->selectedFiles, SLOT(moveSelectedUp() ) ); 108 d->selectedFiles, SLOT(moveSelectedUp() ) );
109 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut", 109 (void)new ToolButton( vbox1, tr( "Remove" ), "opieplayer2/cut",
110 d->selectedFiles, SLOT(removeSelected() ) ); 110 d->selectedFiles, SLOT(removeSelected() ) );
111 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down", 111 (void)new ToolButton( vbox1, tr( "Move Down" ), "opieplayer2/down",
112 d->selectedFiles, SLOT(moveSelectedDown() ) ); 112 d->selectedFiles, SLOT(moveSelectedDown() ) );
113 QVBox *stretch2 = new QVBox( vbox1 ); 113 QVBox *stretch2 = new QVBox( vbox1 );
114 114
115 connect( tbDeletePlaylist, ( SIGNAL( released() ) ), 115 connect( tbDeletePlaylist, ( SIGNAL( released() ) ),
116 SLOT( deletePlaylist() ) ); 116 SLOT( deletePlaylist() ) );
117 connect( pmView, SIGNAL( activated(int) ), 117 connect( pmView, SIGNAL( activated(int) ),
118 this, SLOT( pmViewActivated(int) ) ); 118 this, SLOT( pmViewActivated(int) ) );
119 connect( skinsMenu, SIGNAL( activated(int) ) , 119 connect( skinsMenu, SIGNAL( activated(int) ) ,
120 this, SLOT( skinsMenuActivated(int) ) ); 120 this, SLOT( skinsMenuActivated(int) ) );
121 connect( d->selectedFiles, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ), 121 connect( d->selectedFiles, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
122 this,SLOT( playlistViewPressed(int,QListViewItem*,const QPoint&,int) ) ); 122 this,SLOT( playlistViewPressed(int,QListViewItem*,const QPoint&,int) ) );
123 connect( audioView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ), 123 connect( audioView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
124 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int) ) ); 124 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int) ) );
125 connect( audioView, SIGNAL( returnPressed(QListViewItem*) ), 125 connect( audioView, SIGNAL( returnPressed(QListViewItem*) ),
126 this,SLOT( playIt(QListViewItem*) ) ); 126 this,SLOT( playIt(QListViewItem*) ) );
127 connect( audioView, SIGNAL( doubleClicked(QListViewItem*) ), 127 connect( audioView, SIGNAL( doubleClicked(QListViewItem*) ),
128 this, SLOT( addToSelection(QListViewItem*) ) ); 128 this, SLOT( addToSelection(QListViewItem*) ) );
129 connect( videoView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ), 129 connect( videoView, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),
130 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int) ) ); 130 this,SLOT( viewPressed(int,QListViewItem*,const QPoint&,int) ) );
131 connect( videoView, SIGNAL( returnPressed(QListViewItem*) ), 131 connect( videoView, SIGNAL( returnPressed(QListViewItem*) ),
132 this,SLOT( playIt(QListViewItem*) ) ); 132 this,SLOT( playIt(QListViewItem*) ) );
133 connect( videoView, SIGNAL( doubleClicked(QListViewItem*) ), 133 connect( videoView, SIGNAL( doubleClicked(QListViewItem*) ),
134 this, SLOT( addToSelection(QListViewItem*) ) ); 134 this, SLOT( addToSelection(QListViewItem*) ) );
135 connect( playLists, SIGNAL( fileSelected(const DocLnk&) ), 135 connect( playLists, SIGNAL( fileSelected(const DocLnk&) ),
136 this, SLOT( loadList(const DocLnk&) ) ); 136 this, SLOT( loadList(const DocLnk&) ) );
137 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ), 137 connect( tabWidget, SIGNAL ( currentChanged(QWidget*) ),
138 this, SLOT( tabChanged(QWidget*) ) ); 138 this, SLOT( tabChanged(QWidget*) ) );
139 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ), 139 connect( mediaPlayerState, SIGNAL( playingToggled(bool) ),
140 d->tbPlay, SLOT( setOn(bool) ) ); 140 d->tbPlay, SLOT( setOn(bool) ) );
141 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ), 141 connect( mediaPlayerState, SIGNAL( loopingToggled(bool) ),
142 d->tbLoop, SLOT( setOn(bool) ) ); 142 d->tbLoop, SLOT( setOn(bool) ) );
143 connect( mediaPlayerState, SIGNAL( shuffledToggled(bool) ), 143 connect( mediaPlayerState, SIGNAL( shuffledToggled(bool) ),
144 d->tbShuffle, SLOT( setOn(bool) ) ); 144 d->tbShuffle, SLOT( setOn(bool) ) );
145 connect( d->selectedFiles, SIGNAL( doubleClicked(QListViewItem*) ), 145 connect( d->selectedFiles, SIGNAL( doubleClicked(QListViewItem*) ),
146 this, SLOT( playIt(QListViewItem*) ) ); 146 this, SLOT( playIt(QListViewItem*) ) );
147 connect ( gammaSlider, SIGNAL( valueChanged(int) ), 147 connect ( gammaSlider, SIGNAL( valueChanged(int) ),
148 mediaPlayerState, SLOT( setVideoGamma(int) ) ); 148 mediaPlayerState, SLOT( setVideoGamma(int) ) );
149 149
150 connect( this, SIGNAL(skinSelected() ), 150 connect( this, SIGNAL(skinSelected() ),
151 m_mp, SLOT( reloadSkins() ) ); 151 m_mp, SLOT( reloadSkins() ) );
152 152
153 // see which skins are installed 153 // see which skins are installed
154 populateSkinsMenu(); 154 populateSkinsMenu();
155 initializeStates(); 155 initializeStates();
156 156
157 channel = new QCopChannel( "QPE/Application/opieplayer2", this ); 157 channel = new QCopChannel( "QPE/Application/opieplayer2", this );
158 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 158 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
159 this, SLOT( qcopReceive(const QCString&,const QByteArray&)) ); 159 this, SLOT( qcopReceive(const QCString&,const QByteArray&)) );
160 160
161 161
162 cfg.setGroup("PlayList"); 162 cfg.setGroup("PlayList");
163 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default"); 163 QString currentPlaylist = cfg.readEntry( "CurrentPlaylist", "default");
164 loadList(DocLnk( currentPlaylist ) ); 164 loadList(DocLnk( currentPlaylist ) );
165 165
166 tabWidget->showPage( playListTab ); 166 tabWidget->showPage( playListTab );
167} 167}
168 168
169 169
170PlayListWidget::~PlayListWidget() { 170PlayListWidget::~PlayListWidget() {
171 delete d; 171 delete d;
172 delete m_mp; 172 delete m_mp;
173} 173}
174 174
175 175
176void PlayListWidget::initializeStates() { 176void PlayListWidget::initializeStates() {
177 d->tbPlay->setOn( mediaPlayerState->isPlaying() ); 177 d->tbPlay->setOn( mediaPlayerState->isPlaying() );
178 d->tbLoop->setOn( mediaPlayerState->isLooping() ); 178 d->tbLoop->setOn( mediaPlayerState->isLooping() );
179 d->tbShuffle->setOn( mediaPlayerState->isShuffled() ); 179 d->tbShuffle->setOn( mediaPlayerState->isShuffled() );
180 d->playListFrame->show(); 180 d->playListFrame->show();
181} 181}
182 182
183void PlayListWidget::writeDefaultPlaylist() { 183void PlayListWidget::writeDefaultPlaylist() {
184 184
185 Config config( "OpiePlayer" ); 185 Config config( "OpiePlayer" );
186 config.setGroup( "PlayList" ); 186 config.setGroup( "PlayList" );
187 QString filename=QPEApplication::documentDir() + "/default.m3u"; 187 QString filename=QPEApplication::documentDir() + "/default.m3u";
188 QString currentString = config.readEntry( "CurrentPlaylist", filename); 188 QString currentString = config.readEntry( "CurrentPlaylist", filename);
189 if( currentString == filename) { 189 if( currentString == filename) {
190 Om3u *m3uList; 190 Om3u *m3uList;
191 if( d->selectedFiles->first() ) { 191 if( d->selectedFiles->first() ) {
192 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); 192 m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate);
193 do { 193 do {
194 m3uList->add( d->selectedFiles->current()->file() ); 194 m3uList->add( d->selectedFiles->current()->file() );
195 } 195 }
196 while ( d->selectedFiles->next() ); 196 while ( d->selectedFiles->next() );
197 197
198 m3uList->write(); 198 m3uList->write();
199 m3uList->close(); 199 m3uList->close();
200 delete m3uList; 200 delete m3uList;
201 201
202 } 202 }
203 } 203 }
204} 204}
205 205
206void PlayListWidget::addToSelection( const DocLnk& lnk ) { 206void PlayListWidget::addToSelection( const DocLnk& lnk ) {
207 d->setDocumentUsed = FALSE; 207 d->setDocumentUsed = FALSE;
208 if( QFileInfo( lnk.file() ).exists() || 208 if( QFileInfo( lnk.file() ).exists() ||
209 lnk.file().left(4) == "http" ) { 209 lnk.file().left(4) == "http" ) {
210 d->selectedFiles->addToSelection( lnk ); 210 d->selectedFiles->addToSelection( lnk );
211 } 211 }
212} 212}
213 213
214 214
215void PlayListWidget::clearList() { 215void PlayListWidget::clearList() {
216 while ( first() ) { 216 while ( first() ) {
217 d->selectedFiles->removeSelected(); 217 d->selectedFiles->removeSelected();
218 } 218 }
219 Config cfg( "OpiePlayer" ); 219 Config cfg( "OpiePlayer" );
220 cfg.setGroup("PlayList"); 220 cfg.setGroup("PlayList");
221 cfg.writeEntry("CurrentPlaylist","default"); 221 cfg.writeEntry("CurrentPlaylist","default");
222 setCaption("OpiePlayer"); 222 setCaption("OpiePlayer");
223} 223}
224 224
225void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) { 225void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint& , int) {
226 switch (mouse) { 226 switch (mouse) {
227 case LeftButton: 227 case LeftButton:
228 break; 228 break;
229 case RightButton: 229 case RightButton:
230 { 230 {
231 QPopupMenu m; 231 QPopupMenu m;
232 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); 232 m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() ));
233 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); 233 m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() ));
234 m.exec( QCursor::pos() ); 234 m.exec( QCursor::pos() );
235 } 235 }
236 break; 236 break;
237 } 237 }
238} 238}
239 239
240 240
241void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) { 241void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint& , int ) {
242 switch (mouse) { 242 switch (mouse) {
243 case LeftButton: 243 case LeftButton:
244 break; 244 break;
245 case RightButton: 245 case RightButton:
246 { 246 {
247 QPopupMenu m; 247 QPopupMenu m;
248 m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); 248 m.insertItem( tr( "Play" ), this, SLOT( playSelected() ));
249 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); 249 m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() ));
250 m.exec( QCursor::pos() ); 250 m.exec( QCursor::pos() );
251 } 251 }
252 break; 252 break;
253 } 253 }
254} 254}
255 255
256 256
257void PlayListWidget::addAllToList() { 257void PlayListWidget::addAllToList() {
258 258
259 259
260 audioView->populateView(); 260 audioView->populateView();
261 261
262 QListViewItemIterator audioIt( audioView ); 262 QListViewItemIterator audioIt( audioView );
263 DocLnk lnk; 263 DocLnk lnk;
264 QString filename; 264 QString filename;
265 // iterate through all items of the listview 265 // iterate through all items of the listview
266 for ( ; audioIt.current(); ++audioIt ) { 266 for ( ; audioIt.current(); ++audioIt ) {
267 filename = audioIt.current()->text(3); 267 filename = audioIt.current()->text(3);
268 lnk.setName( QFileInfo(filename).baseName() ); //sets name 268 lnk.setName( QFileInfo(filename).baseName() ); //sets name
269 lnk.setFile( filename ); //sets file name 269 lnk.setFile( filename ); //sets file name
270 d->selectedFiles->addToSelection( lnk); 270 d->selectedFiles->addToSelection( lnk);
271 } 271 }
272 272
273 videoView->populateView(); 273 videoView->populateView();
274 274
275 QListViewItemIterator videoIt( videoView ); 275 QListViewItemIterator videoIt( videoView );
276 for ( ; videoIt.current(); ++videoIt ) { 276 for ( ; videoIt.current(); ++videoIt ) {
277 filename = videoIt.current()->text(3); 277 filename = videoIt.current()->text(3);
278 lnk.setName( QFileInfo(filename).baseName() ); //sets name 278 lnk.setName( QFileInfo(filename).baseName() ); //sets name
279 lnk.setFile( filename ); //sets file name 279 lnk.setFile( filename ); //sets file name
280 d->selectedFiles->addToSelection( lnk); 280 d->selectedFiles->addToSelection( lnk);
281 } 281 }
282 282
283 tabWidget->setCurrentPage(0); 283 tabWidget->setCurrentPage(0);
284 284
285 writeCurrentM3u(); 285 writeCurrentM3u();
286 d->selectedFiles->first(); 286 d->selectedFiles->first();
287} 287}
288 288
289 289
290void PlayListWidget::addAllMusicToList() { 290void PlayListWidget::addAllMusicToList() {
291 291
292 audioView->populateView(); 292 audioView->populateView();
293 293
294 QListViewItemIterator audioIt( audioView ); 294 QListViewItemIterator audioIt( audioView );
295 DocLnk lnk; 295 DocLnk lnk;
296 QString filename; 296 QString filename;
297 // iterate through all items of the listview 297 // iterate through all items of the listview
298 for ( ; audioIt.current(); ++audioIt ) { 298 for ( ; audioIt.current(); ++audioIt ) {
299 filename = audioIt.current()->text(3); 299 filename = audioIt.current()->text(3);
300 lnk.setName( QFileInfo(filename).baseName() ); //sets name 300 lnk.setName( QFileInfo(filename).baseName() ); //sets name
301 lnk.setFile( filename ); //sets file name 301 lnk.setFile( filename ); //sets file name
302 d->selectedFiles->addToSelection( lnk); 302 d->selectedFiles->addToSelection( lnk);
303 } 303 }
304 304
305 tabWidget->setCurrentPage(0); 305 tabWidget->setCurrentPage(0);
306 writeCurrentM3u(); 306 writeCurrentM3u();
307 d->selectedFiles->first(); 307 d->selectedFiles->first();
308} 308}
309 309
310 310
311void PlayListWidget::addAllVideoToList() { 311void PlayListWidget::addAllVideoToList() {
312 312
313 videoView->populateView(); 313 videoView->populateView();
314 314
315 QListViewItemIterator videoIt( videoView ); 315 QListViewItemIterator videoIt( videoView );
316 DocLnk lnk; 316 DocLnk lnk;
317 QString filename; 317 QString filename;
318 for ( ; videoIt.current(); ++videoIt ) { 318 for ( ; videoIt.current(); ++videoIt ) {
319 filename = videoIt.current()->text(3); 319 filename = videoIt.current()->text(3);
320 lnk.setName( QFileInfo(filename).baseName() ); //sets name 320 lnk.setName( QFileInfo(filename).baseName() ); //sets name
321 lnk.setFile( filename ); //sets file name 321 lnk.setFile( filename ); //sets file name
322 d->selectedFiles->addToSelection( lnk); 322 d->selectedFiles->addToSelection( lnk);
323 } 323 }
324 tabWidget->setCurrentPage(0); 324 tabWidget->setCurrentPage(0);
325 writeCurrentM3u(); 325 writeCurrentM3u();
326 d->selectedFiles->first(); 326 d->selectedFiles->first();
327} 327}
328 328
329 329
330void PlayListWidget::setDocument( const QString& _fileref ) { 330void PlayListWidget::setDocument( const QString& _fileref ) {
331 // odebug << "<<<<<<<<set document>>>>>>>>>> "+fileref << oendl; 331 // odebug << "<<<<<<<<set document>>>>>>>>>> "+fileref << oendl;
332 QString fileref = _fileref; 332 QString fileref = _fileref;
333 fromSetDocument = TRUE; 333 fromSetDocument = TRUE;
334 334
335 DocLnk lnk(_fileref); 335 DocLnk lnk(_fileref);
336 if(lnk.isValid()) 336 if(lnk.isValid())
337 fileref = lnk.file(); 337 fileref = lnk.file();
338 338
339 QFileInfo fileInfo(fileref); 339 QFileInfo fileInfo(fileref);
340 340
341 if ( !fileInfo.exists() ) { 341 if ( !fileInfo.exists() ) {
342 QMessageBox::warning( this, tr( "Invalid File" ), 342 QMessageBox::warning( this, tr( "Invalid File" ),
343 tr( "There was a problem in getting the file." ) ); 343 tr( "There was a problem in getting the file." ) );
344 return; 344 return;
345 } 345 }
346 346
347 clearList(); 347 clearList();
348 QString extension = fileInfo.extension(false); 348 QString extension = fileInfo.extension(false);
349 349
350 if( extension.find( "m3u", 0, false) != -1 350 if( extension.find( "m3u", 0, false) != -1
351 || extension.find( "pls", 0, false) != -1 ) { 351 || extension.find( "pls", 0, false) != -1 ) {
352 readListFromFile( fileref ); 352 readListFromFile( fileref );
353 } else { 353 } else {
354 clearList(); 354 clearList();
355 DocLnk lnk; 355 DocLnk lnk;
356 lnk.setName( fileInfo.baseName() ); //sets name 356 lnk.setName( fileInfo.baseName() ); //sets name
357 lnk.setFile( fileref ); //sets file name 357 lnk.setFile( fileref ); //sets file name
358 addToSelection( lnk ); 358 addToSelection( lnk );
359 writeCurrentM3u(); 359 writeCurrentM3u();
360 360
361 d->setDocumentUsed = TRUE; 361 d->setDocumentUsed = TRUE;
362 mediaPlayerState->setPlaying( FALSE ); 362 mediaPlayerState->setPlaying( FALSE );
363 mediaPlayerState->setPlaying( TRUE ); 363 mediaPlayerState->setPlaying( TRUE );
364 } 364 }
365} 365}
366 366
367 367
368void PlayListWidget::useSelectedDocument() { 368void PlayListWidget::useSelectedDocument() {
369 d->setDocumentUsed = FALSE; 369 d->setDocumentUsed = FALSE;
370} 370}
371 371
372 372
373const DocLnk *PlayListWidget::current() const { // this is fugly 373const DocLnk *PlayListWidget::current() const { // this is fugly
374 assert( currentTab() == CurrentPlayList ); 374 assert( currentTab() == CurrentPlayList );
375 375
376 const DocLnk *lnk = d->selectedFiles->current(); 376 const DocLnk *lnk = d->selectedFiles->current();
377 if ( !lnk ) { 377 if ( !lnk ) {
378 d->selectedFiles->first(); 378 d->selectedFiles->first();
379 lnk = d->selectedFiles->current(); 379 lnk = d->selectedFiles->current();
380 } 380 }
381 assert( lnk ); 381 assert( lnk );
382 return lnk; 382 return lnk;
383} 383}
384 384
385 385
386bool PlayListWidget::prev() { 386bool PlayListWidget::prev() {
387 if ( mediaPlayerState->isShuffled() ) { 387 if ( mediaPlayerState->isShuffled() ) {
388 const DocLnk *cur = current(); 388 const DocLnk *cur = current();
389 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); 389 int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0));
390 for ( int i = 0; i < j; i++ ) { 390 for ( int i = 0; i < j; i++ ) {
391 if ( !d->selectedFiles->next() ) 391 if ( !d->selectedFiles->next() )
392 d->selectedFiles->first(); 392 d->selectedFiles->first();
393 } 393 }
394 if ( cur == current() ) 394 if ( cur == current() )
395 if ( !d->selectedFiles->next() ) { 395 if ( !d->selectedFiles->next() ) {
396 d->selectedFiles->first(); 396 d->selectedFiles->first();
397 } 397 }
398 return TRUE; 398 return TRUE;
399 } else { 399 } else {
400 if ( !d->selectedFiles->prev() ) { 400 if ( !d->selectedFiles->prev() ) {
401 if ( mediaPlayerState->isLooping() ) { 401 if ( mediaPlayerState->isLooping() ) {
402 return d->selectedFiles->last(); 402 return d->selectedFiles->last();
403 } else { 403 } else {
404 return FALSE; 404 return FALSE;
405 } 405 }
406 } 406 }
407 return TRUE; 407 return TRUE;
408 } 408 }
409} 409}
410 410
411 411
412bool PlayListWidget::next() { 412bool PlayListWidget::next() {
413//odebug << "<<<<<<<<<<<<next()" << oendl; 413//odebug << "<<<<<<<<<<<<next()" << oendl;
414 if ( mediaPlayerState->isShuffled() ) { 414 if ( mediaPlayerState->isShuffled() ) {
415 return prev(); 415 return prev();
416 } else { 416 } else {
417 if ( !d->selectedFiles->next() ) { 417 if ( !d->selectedFiles->next() ) {
418 if ( mediaPlayerState->isLooping() ) { 418 if ( mediaPlayerState->isLooping() ) {
419 return d->selectedFiles->first(); 419 return d->selectedFiles->first();
420 } else { 420 } else {
421 return FALSE; 421 return FALSE;
422 } 422 }
423 } 423 }
424 return TRUE; 424 return TRUE;
425 } 425 }
426} 426}
427 427
428 428
429bool PlayListWidget::first() { 429bool PlayListWidget::first() {
430 return d->selectedFiles->first(); 430 return d->selectedFiles->first();
431} 431}
432 432
433 433
434bool PlayListWidget::last() { 434bool PlayListWidget::last() {
435 return d->selectedFiles->last(); 435 return d->selectedFiles->last();
436} 436}
437 437
438 438
439 void PlayListWidget::saveList() { 439 void PlayListWidget::saveList() {
440 writem3u(); 440 writem3u();
441 } 441 }
442 442
443 443
444void PlayListWidget::loadList( const DocLnk & lnk) { 444void PlayListWidget::loadList( const DocLnk & lnk) {
445 QString name = lnk.name(); 445 QString name = lnk.name();
446 446
447 if( name.length()>0) { 447 if( name.length()>0) {
448 setCaption("OpiePlayer: "+name); 448 setCaption("OpiePlayer: "+name);
449 clearList(); 449 clearList();
450 readListFromFile(lnk.file()); 450 readListFromFile(lnk.file());
451 tabWidget->setCurrentPage(0); 451 tabWidget->setCurrentPage(0);
452 } 452 }
453} 453}
454 454
455void PlayListWidget::addSelected() { 455void PlayListWidget::addSelected() {
456 assert( inFileListMode() ); 456 assert( inFileListMode() );
457 457
458 QListViewItemIterator it( currentFileListView ); 458 QListViewItemIterator it( currentFileListView );
459 for ( ; it.current(); ++it ) 459 for ( ; it.current(); ++it )
460 if ( it.current()->isSelected() ) { 460 if ( it.current()->isSelected() ) {
461 QString filename = it.current()->text(3); 461 QString filename = it.current()->text(3);
462 462
463 DocLnk lnk; 463 DocLnk lnk;
464 lnk.setName( QFileInfo( filename ).baseName() ); //sets name 464 lnk.setName( QFileInfo( filename ).baseName() ); //sets name
465 lnk.setFile( filename ); //sets file name 465 lnk.setFile( filename ); //sets file name
466 466
467 d->selectedFiles->addToSelection( lnk ); 467 d->selectedFiles->addToSelection( lnk );
468 } 468 }
469 469
470 currentFileListView->clearSelection(); 470 currentFileListView->clearSelection();
471 471
472 writeCurrentM3u(); 472 writeCurrentM3u();
473} 473}
474 474
475 475
476void PlayListWidget::removeSelected() { 476void PlayListWidget::removeSelected() {
477 d->selectedFiles->removeSelected( ); 477 d->selectedFiles->removeSelected( );
478 writeCurrentM3u(); 478 writeCurrentM3u();
479} 479}
480 480
481 481
482void PlayListWidget::playIt( QListViewItem *it) { 482void PlayListWidget::playIt( QListViewItem *it) {
483 if(!it) return; 483 if(!it) return;
484 mediaPlayerState->setPlaying(FALSE); 484 mediaPlayerState->setPlaying(FALSE);
485 mediaPlayerState->setPlaying(TRUE); 485 mediaPlayerState->setPlaying(TRUE);
486 d->selectedFiles->unSelect(); 486 d->selectedFiles->unSelect();
487} 487}
488 488
489 489
490void PlayListWidget::addToSelection( QListViewItem *it) { 490void PlayListWidget::addToSelection( QListViewItem *it) {
491 d->setDocumentUsed = FALSE; 491 d->setDocumentUsed = FALSE;
492 492
493 if(it) { 493 if(it) {
494 if ( currentTab() == CurrentPlayList ) 494 if ( currentTab() == CurrentPlayList )
495 return; 495 return;
496 DocLnk lnk; 496 DocLnk lnk;
497 QString filename; 497 QString filename;
498 498
499 filename=it->text(3); 499 filename=it->text(3);
500 lnk.setName( QFileInfo(filename).baseName() ); //sets name 500 lnk.setName( QFileInfo(filename).baseName() ); //sets name
501 lnk.setFile( filename ); //sets file name 501 lnk.setFile( filename ); //sets file name
502 d->selectedFiles->addToSelection( lnk); 502 d->selectedFiles->addToSelection( lnk);
503 503
504 writeCurrentM3u(); 504 writeCurrentM3u();
505// tabWidget->setCurrentPage(0); 505// tabWidget->setCurrentPage(0);
506 506
507 } 507 }
508} 508}
509 509
510 510
511void PlayListWidget::tabChanged(QWidget *) { 511void PlayListWidget::tabChanged(QWidget *) {
512 512
513 d->tbPlay->setEnabled( true ); 513 d->tbPlay->setEnabled( true );
514 514
515 disconnect( audioView, SIGNAL( itemsSelected(bool) ), 515 disconnect( audioView, SIGNAL( itemsSelected(bool) ),
516 d->tbPlay, SLOT( setEnabled(bool) ) ); 516 d->tbPlay, SLOT( setEnabled(bool) ) );
517 disconnect( videoView, SIGNAL( itemsSelected(bool) ), 517 disconnect( videoView, SIGNAL( itemsSelected(bool) ),
518 d->tbPlay, SLOT( setEnabled(bool) ) ); 518 d->tbPlay, SLOT( setEnabled(bool) ) );
519 519
520 currentFileListView = 0; 520 currentFileListView = 0;
521 521
522 switch ( currentTab() ) { 522 switch ( currentTab() ) {
523 case CurrentPlayList: 523 case CurrentPlayList:
524 { 524 {
525 if( !tbDeletePlaylist->isHidden() ) { 525 if( !tbDeletePlaylist->isHidden() ) {
526 tbDeletePlaylist->hide(); 526 tbDeletePlaylist->hide();
527 } 527 }
528 d->tbRemoveFromList->setEnabled(TRUE); 528 d->tbRemoveFromList->setEnabled(TRUE);
529 d->tbAddToList->setEnabled(FALSE); 529 d->tbAddToList->setEnabled(FALSE);
530 530
531 d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() ); 531 d->tbPlay->setEnabled( !d->selectedFiles->isEmpty() );
532 } 532 }
533 break; 533 break;
534 case AudioFiles: 534 case AudioFiles:
535 { 535 {
536 audioView->populateView(); 536 audioView->populateView();
537 537
538 if( !tbDeletePlaylist->isHidden() ) { 538 if( !tbDeletePlaylist->isHidden() ) {
539 tbDeletePlaylist->hide(); 539 tbDeletePlaylist->hide();
540 } 540 }
541 d->tbRemoveFromList->setEnabled(FALSE); 541 d->tbRemoveFromList->setEnabled(FALSE);
542 d->tbAddToList->setEnabled(TRUE); 542 d->tbAddToList->setEnabled(TRUE);
543 543
544 connect( audioView, SIGNAL( itemsSelected(bool) ), 544 connect( audioView, SIGNAL( itemsSelected(bool) ),
545 d->tbPlay, SLOT( setEnabled(bool) ) ); 545 d->tbPlay, SLOT( setEnabled(bool) ) );
546 546
547 d->tbPlay->setEnabled( audioView->hasSelection() ); 547 d->tbPlay->setEnabled( audioView->hasSelection() );
548 548
549 currentFileListView = audioView; 549 currentFileListView = audioView;
550 } 550 }
551 break; 551 break;
552 case VideoFiles: 552 case VideoFiles:
553 { 553 {
554 videoView->populateView(); 554 videoView->populateView();
555 if( !tbDeletePlaylist->isHidden() ) { 555 if( !tbDeletePlaylist->isHidden() ) {
556 tbDeletePlaylist->hide(); 556 tbDeletePlaylist->hide();
557 } 557 }
558 d->tbRemoveFromList->setEnabled(FALSE); 558 d->tbRemoveFromList->setEnabled(FALSE);
559 d->tbAddToList->setEnabled(TRUE); 559 d->tbAddToList->setEnabled(TRUE);
560 560
561 connect( videoView, SIGNAL( itemsSelected(bool) ), 561 connect( videoView, SIGNAL( itemsSelected(bool) ),
562 d->tbPlay, SLOT( setEnabled(bool) ) ); 562 d->tbPlay, SLOT( setEnabled(bool) ) );
563 563
564 d->tbPlay->setEnabled( videoView->hasSelection() ); 564 d->tbPlay->setEnabled( videoView->hasSelection() );
565 565
566 currentFileListView = videoView; 566 currentFileListView = videoView;
567 } 567 }
568 break; 568 break;
569 case PlayLists: 569 case PlayLists:
570 { 570 {
571 if( tbDeletePlaylist->isHidden() ) { 571 if( tbDeletePlaylist->isHidden() ) {
572 tbDeletePlaylist->show(); 572 tbDeletePlaylist->show();
573 } 573 }
574 playLists->reread(); 574 playLists->reread();
575 d->tbAddToList->setEnabled(FALSE); 575 d->tbAddToList->setEnabled(FALSE);
576 576
577 d->tbPlay->setEnabled( false ); 577 d->tbPlay->setEnabled( false );
578 } 578 }
579 break; 579 break;
580 }; 580 };
581} 581}
582 582
583 583
584void PlayListWidget::btnPlay(bool b) { 584void PlayListWidget::btnPlay(bool b) {
585// mediaPlayerState->setPlaying(false); 585// mediaPlayerState->setPlaying(false);
586 mediaPlayerState->setPlaying(b); 586 mediaPlayerState->setPlaying(b);
587 insanityBool=FALSE; 587 insanityBool=FALSE;
588} 588}
589 589
590void PlayListWidget::deletePlaylist() { 590void PlayListWidget::deletePlaylist() {
591 switch( QMessageBox::information( this, (tr("Remove Playlist?")), 591 switch( QMessageBox::information( this, (tr("Remove Playlist?")),
592 (tr("You really want to delete\nthis playlist?")), 592 (tr("You really want to delete\nthis playlist?")),
593 (tr("Yes")), (tr("No")), 0 )){ 593 (tr("Yes")), (tr("No")), 0 )){
594 case 0: // Yes clicked, 594 case 0: // Yes clicked,
595 QFile().remove(playLists->selectedDocument().file()); 595 QFile().remove(playLists->selectedDocument().file());
596 QFile().remove(playLists->selectedDocument().linkFile()); 596 QFile().remove(playLists->selectedDocument().linkFile());
597 playLists->reread(); 597 playLists->reread();
598 break; 598 break;
599 case 1: // Cancel 599 case 1: // Cancel
600 break; 600 break;
601 }; 601 };
602} 602}
603 603
604 604
605void PlayListWidget::playSelected() { 605void PlayListWidget::playSelected() {
606 btnPlay( TRUE); 606 btnPlay( TRUE);
607} 607}
608 608
609bool PlayListWidget::inFileListMode() const 609bool PlayListWidget::inFileListMode() const
610{ 610{
611 TabType tab = currentTab(); 611 TabType tab = currentTab();
612 return tab == AudioFiles || tab == VideoFiles; 612 return tab == AudioFiles || tab == VideoFiles;
613} 613}
614 614
615void PlayListWidget::openURL() { 615void PlayListWidget::openURL() {
616 // http://66.28.164.33:2080 616 // http://66.28.164.33:2080
617 // http://somafm.com/star0242.m3u 617 // http://somafm.com/star0242.m3u
618 QString filename, name; 618 QString filename, name;
619 InputDialog *fileDlg; 619 InputDialog *fileDlg;
620 fileDlg = new InputDialog(this,tr("Add URL"),TRUE, 0); 620 fileDlg = new InputDialog(this,tr("Add URL"),TRUE, 0);
621 fileDlg->exec(); 621 fileDlg->exec();
622 if( fileDlg->result() == 1 ) { 622 if( fileDlg->result() == 1 ) {
623 filename = fileDlg->text(); 623 filename = fileDlg->text();
624 odebug << "Selected filename is " + filename << oendl; 624 odebug << "Selected filename is " + filename << oendl;
625 // Om3u *m3uList; 625 // Om3u *m3uList;
626 DocLnk lnk; 626 DocLnk lnk;
627 Config cfg( "OpiePlayer" ); 627 Config cfg( "OpiePlayer" );
628 cfg.setGroup("PlayList"); 628 cfg.setGroup("PlayList");
629 629
630 if(filename.left(4) == "http") { 630 if(filename.left(4) == "http") {
631 QString m3uFile, m3uFilePath; 631 QString m3uFile, m3uFilePath;
632 if(filename.find(":",8,TRUE) != -1) { //found a port 632 if(filename.find(":",8,TRUE) != -1) { //found a port
633 m3uFile = filename.left( filename.find( ":",8,TRUE)); 633 m3uFile = filename.left( filename.find( ":",8,TRUE));
634 m3uFile = m3uFile.right( 7); 634 m3uFile = m3uFile.right( 7);
635 } else if(filename.left(4) == "http"){ 635 } else if(filename.left(4) == "http"){
636 m3uFile=filename; 636 m3uFile=filename;
637 m3uFile = m3uFile.right( m3uFile.length() - 7); 637 m3uFile = m3uFile.right( m3uFile.length() - 7);
638 } else{ 638 } else{
639 m3uFile=filename; 639 m3uFile=filename;
640 } 640 }
641 641
642 lnk.setName( filename ); //sets name 642 lnk.setName( filename ); //sets name
643 lnk.setFile( filename ); //sets file name 643 lnk.setFile( filename ); //sets file name
644 644
645// lnk.setIcon("opieplayer2/musicfile"); 645// lnk.setIcon("opieplayer2/musicfile");
646 646
647 d->selectedFiles->addToSelection( lnk ); 647 d->selectedFiles->addToSelection( lnk );
648 writeCurrentM3u(); 648 writeCurrentM3u();
649 d->selectedFiles->setSelectedItem( lnk.name()); 649 d->selectedFiles->setSelectedItem( lnk.name());
650 } 650 }
651 else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) { 651 else if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) {
652 readListFromFile( filename ); 652 readListFromFile( filename );
653 } else { 653 } else {
654 lnk.setName( QFileInfo(filename).baseName() ); //sets name 654 lnk.setName( QFileInfo(filename).baseName() ); //sets name
655 lnk.setFile( filename ); //sets file name 655 lnk.setFile( filename ); //sets file name
656 d->selectedFiles->addToSelection( lnk); 656 d->selectedFiles->addToSelection( lnk);
657 writeCurrentM3u(); 657 writeCurrentM3u();
658 d->selectedFiles->setSelectedItem( lnk.name()); 658 d->selectedFiles->setSelectedItem( lnk.name());
659 } 659 }
660 } 660 }
661 661
662 662
663 delete fileDlg; 663 delete fileDlg;
664} 664}
665 665
666 666
667static MimeTypes fileSelectorMimeTypes() { 667static MimeTypes fileSelectorMimeTypes() {
668 MimeTypes types; 668 MimeTypes types;
669 QStringList audio, video, all; 669 QStringList audio, video, all;
670 audio << "audio/*"; 670 audio << "audio/*";
671 audio << "playlist/plain"; 671 audio << "playlist/plain";
672 audio << "audio/x-ogg"; 672 audio << "audio/x-ogg";
673 audio << "audio/x-mpegurl"; 673 audio << "audio/x-mpegurl";
674 674
675 video << "video/*"; 675 video << "video/*";
676 video << "playlist/plain"; 676 video << "playlist/plain";
677 677
678 all += audio; 678 all += audio;
679 all += video; 679 all += video;
680 types.insert("All Media Files", all ); 680 types.insert("All Media Files", all );
681 types.insert("Audio", audio ); 681 types.insert("Audio", audio );
682 types.insert("Video", video ); 682 types.insert("Video", video );
683 683
684 return types; 684 return types;
685} 685}
686 686
687void PlayListWidget::openFile() { 687void PlayListWidget::openFile() {
688 688
689 QString filename, name; 689 QString filename, name;
690 690
691 Config cfg( "OpiePlayer" ); 691 Config cfg( "OpiePlayer" );
692 cfg.setGroup("Dialog"); 692 cfg.setGroup("Dialog");
693 MimeTypes types = fileSelectorMimeTypes(); 693 MimeTypes types = fileSelectorMimeTypes();
694 694
695 695
696 QString str = OFileDialog::getOpenFileName( 1, QString::null, 696 QString str = OFileDialog::getOpenFileName( 1, QString::null,
697 QString::null, types, 0, 697 QString::null, types, 0,
698 tr("Add File to Playlist") ); 698 tr("Add File to Playlist") );
699 699
700 if( str.isEmpty() ) 700 if( str.isEmpty() )
701 return; 701 return;
702 702
703 if(str.left(2) == "//") str=str.right(str.length()-1); 703 if(str.left(2) == "//") str=str.right(str.length()-1);
704 704
705 705
706 if( str.right( 3) == "m3u" || str.right(3) == "pls" ) { 706 if( str.right( 3) == "m3u" || str.right(3) == "pls" ) {
707 readListFromFile( str ); 707 readListFromFile( str );
708 } else { 708 } else {
709 QFileInfo info( str ); 709 QFileInfo info( str );
710 DocLnk lnk = addFileToPlaylist( str, info.baseName() ); 710 DocLnk lnk = addFileToPlaylist( str, info.baseName() );
711 d->selectedFiles->setSelectedItem( lnk.name() ); 711 d->selectedFiles->setSelectedItem( lnk.name() );
712 } 712 }
713} 713}
714 714
715void PlayListWidget::openDirectory() { 715void PlayListWidget::openDirectory() {
716 QString str = OFileDialog::getDirectory( OFileSelector::DirectorySelector, 716 QString str = OFileDialog::getDirectory( OFileSelector::DirectorySelector,
717 QString::null, 0, 717 QString::null, 0,
718 tr( "Add Files from Directory")); 718 tr( "Add Files from Directory"));
719 719
720 if(str.isEmpty() ) 720 if(str.isEmpty() )
721 return; 721 return;
722 722
723 if(str.left(2) == "//") str=str.right(str.length()-1); 723 if(str.left(2) == "//") str=str.right(str.length()-1);
724 QDir dir( str ); 724 QDir dir( str );
725 QStringList lst = dir.entryList(QDir::Files|QDir::Readable); 725 QStringList lst = dir.entryList(QDir::Files|QDir::Readable);
726 726
727 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) { 727 for ( QStringList::Iterator it = lst.begin(); it != lst.end(); ++it ) {
728 QString filename = str + "/" + *it; 728 QString filename = str + "/" + *it;
729 729
730 if( filename.right( 3) == "m3u" || filename.right(3) == "pls" ) 730 if( filename.right( 3) == "m3u" || filename.right(3) == "pls" )
731 readListFromFile( filename ); 731 readListFromFile( filename );
732 else { 732 else {
733 addFileToPlaylist( filename, QFileInfo(*it).baseName() ); 733 addFileToPlaylist( filename, QFileInfo(*it).baseName() );
734 } 734 }
735 } 735 }
736} 736}
737 737
738void PlayListWidget::readListFromFile( const QString &filename ) { 738void PlayListWidget::readListFromFile( const QString &filename ) {
739 odebug << "read list filename " + filename << oendl; 739 odebug << "read list filename " + filename << oendl;
740 QFileInfo fi(filename); 740 QFileInfo fi(filename);
741 Om3u *m3uList; 741 Om3u *m3uList;
742 QString s, name; 742 QString s, name;
743 m3uList = new Om3u( filename, IO_ReadOnly ); 743 m3uList = new Om3u( filename, IO_ReadOnly );
744 if(fi.extension(false).find("m3u",0,false) != -1 ) 744 if(fi.extension(false).find("m3u",0,false) != -1 )
745 m3uList->readM3u(); 745 m3uList->readM3u();
746 else if(fi.extension(false).find("pls",0,false) != -1 ) 746 else if(fi.extension(false).find("pls",0,false) != -1 )
747 m3uList->readPls(); 747 m3uList->readPls();
748 748
749 DocLnk lnk; 749 DocLnk lnk;
750 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { 750 for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) {
751 s = *it; 751 s = *it;
752 // odebug << s << oendl; 752 // odebug << s << oendl;
753 if(s.left(4)=="http") { 753 if(s.left(4)=="http") {
754 lnk.setName( s ); //sets file name 754 lnk.setName( s ); //sets file name
755 lnk.setIcon("opieplayer2/musicfile"); 755 lnk.setIcon("opieplayer2/musicfile");
756 lnk.setFile( s ); //sets file name 756 lnk.setFile( s ); //sets file name
757 757
758 } else { //is file 758 } else { //is file
759 lnk.setName( QFileInfo(s).baseName()); 759 lnk.setName( QFileInfo(s).baseName());
760 if(s.left(1) != "/") { 760 if(s.left(1) != "/") {
761 761
762 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); 762 lnk.setFile( QFileInfo(filename).dirPath()+"/"+s);
763 } else { 763 } else {
764 lnk.setFile( s); 764 lnk.setFile( s);
765 } 765 }
766 } 766 }
767 d->selectedFiles->addToSelection( lnk ); 767 d->selectedFiles->addToSelection( lnk );
768 } 768 }
769 Config config( "OpiePlayer" ); 769 Config config( "OpiePlayer" );
770 config.setGroup( "PlayList" ); 770 config.setGroup( "PlayList" );
771 771
772 config.writeEntry("CurrentPlaylist",filename); 772 config.writeEntry("CurrentPlaylist",filename);
773 config.write(); 773 config.write();
774 currentPlayList=filename; 774 currentPlayList=filename;
775 775
776 m3uList->close(); 776 m3uList->close();
777 delete m3uList; 777 delete m3uList;
778 778
779 d->selectedFiles->setSelectedItem( s); 779 d->selectedFiles->setSelectedItem( s);
780 setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName()); 780 setCaption(tr("OpiePlayer: ")+ QFileInfo(filename).baseName());
781 781
782} 782}
783 783
784// writes current playlist to current m3u file */ 784// writes current playlist to current m3u file */
785 void PlayListWidget::writeCurrentM3u() { 785 void PlayListWidget::writeCurrentM3u() {
786 odebug << "writing to current m3u" << oendl; 786 odebug << "writing to current m3u" << oendl;
787 Config cfg( "OpiePlayer" ); 787 Config cfg( "OpiePlayer" );
788 cfg.setGroup("PlayList"); 788 cfg.setGroup("PlayList");
789 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default"); 789 QString currentPlaylist = cfg.readEntry("CurrentPlaylist","default");
790 790
791 Om3u *m3uList; 791 Om3u *m3uList;
792 m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate ); 792 m3uList = new Om3u( currentPlaylist, IO_ReadWrite | IO_Truncate );
793 if( d->selectedFiles->first()) { 793 if( d->selectedFiles->first()) {
794 794
795 do { 795 do {
796 // odebug << "add writeCurrentM3u " +d->selectedFiles->current()->file() << oendl; 796 // odebug << "add writeCurrentM3u " +d->selectedFiles->current()->file() << oendl;
797 m3uList->add( d->selectedFiles->current()->file() ); 797 m3uList->add( d->selectedFiles->current()->file() );
798 } 798 }
799 while ( d->selectedFiles->next() ); 799 while ( d->selectedFiles->next() );
800 // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl; 800 // odebug << "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" << oendl;
801 m3uList->write(); 801 m3uList->write();
802 m3uList->close(); 802 m3uList->close();
803 } 803 }
804 delete m3uList; 804 delete m3uList;
805 805
806 } 806 }
807 807
808 /* 808 /*
809 writes current playlist to m3u file */ 809 writes current playlist to m3u file */
810void PlayListWidget::writem3u() { 810void PlayListWidget::writem3u() {
811 811
812 Config cfg( "OpiePlayer" ); 812 Config cfg( "OpiePlayer" );
813 cfg.setGroup("Dialog"); 813 cfg.setGroup("Dialog");
814 MimeTypes types = fileSelectorMimeTypes(); 814 MimeTypes types = fileSelectorMimeTypes();
815 815
816 QString str = OFileDialog::getOpenFileName( 1, QString::null, 816 QString str = OFileDialog::getOpenFileName( 1, QString::null,
817 QString::null, types, 0, 817 QString::null, types, 0,
818 tr( "Save Playlist" )); 818 tr( "Save Playlist" ));
819 819
820 if(str.left(2) == "//") str=str.right(str.length()-1); 820 if(str.left(2) == "//") str=str.right(str.length()-1);
821 821
822 QString name, filename, list; 822 QString name, filename, list;
823 Om3u *m3uList; 823 Om3u *m3uList;
824 824
825 if( !str.isEmpty() ) { 825 if( !str.isEmpty() ) {
826 name = str; 826 name = str;
827 // name = fileDlg->text(); 827 // name = fileDlg->text();
828// odebug << filename << oendl; 828// odebug << filename << oendl;
829 if( name.find("/",0,true) != -1) {// assume they specify a file path 829 if( name.find("/",0,true) != -1) {// assume they specify a file path
830 filename = name; 830 filename = name;
831 name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); 831 name = name.right(name.length()- name.findRev("/",-1,true) - 1 );
832 } 832 }
833 else //otherwise dump it somewhere noticable 833 else //otherwise dump it somewhere noticable
834 filename = QPEApplication::documentDir() + "/" + name; 834 filename = QPEApplication::documentDir() + "/" + name;
835 835
836 if( filename.right( 3 ) != "m3u" ) //needs filename extension 836 if( filename.right( 3 ) != "m3u" ) //needs filename extension
837 filename += ".m3u"; 837 filename += ".m3u";
838 838
839 if( d->selectedFiles->first()) { //ramble through playlist view 839 if( d->selectedFiles->first()) { //ramble through playlist view
840 m3uList = new Om3u( filename, IO_ReadWrite | IO_Truncate); 840 m3uList = new Om3u( filename, IO_ReadWrite | IO_Truncate);
841 841
842 do { 842 do {
843 m3uList->add( d->selectedFiles->current()->file()); 843 m3uList->add( d->selectedFiles->current()->file());
844 } 844 }
845 while ( d->selectedFiles->next() ); 845 while ( d->selectedFiles->next() );
846 // odebug << list << oendl; 846 // odebug << list << oendl;
847 m3uList->write(); 847 m3uList->write();
848 m3uList->close(); 848 m3uList->close();
849 delete m3uList; 849 delete m3uList;
850 850
851 //delete fileDlg; 851 //delete fileDlg;
852 852
853 DocLnk lnk; 853 DocLnk lnk;
854 lnk.setFile( filename); 854 lnk.setFile( filename);
855 lnk.setIcon("opieplayer2/playlist2"); 855 lnk.setIcon("opieplayer2/playlist2");
856 lnk.setName( name); //sets file name 856 lnk.setName( name); //sets file name
857 857
858 // odebug << filename << oendl; 858 // odebug << filename << oendl;
859 Config config( "OpiePlayer" ); 859 Config config( "OpiePlayer" );
860 config.setGroup( "PlayList" ); 860 config.setGroup( "PlayList" );
861 861
862 config.writeEntry("CurrentPlaylist",filename); 862 config.writeEntry("CurrentPlaylist",filename);
863 currentPlayList=filename; 863 currentPlayList=filename;
864 864
865 if(!lnk.writeLink()) { 865 if(!lnk.writeLink()) {
866 odebug << "Writing doclink did not work" << oendl; 866 odebug << "Writing doclink did not work" << oendl;
867 } 867 }
868 868
869 setCaption(tr("OpiePlayer: ") + name); 869 setCaption(tr("OpiePlayer: ") + name);
870 } 870 }
871 } 871 }
872} 872}
873 873
874void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { 874void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) {
875 switch ( e->key() ) { 875 switch ( e->key() ) {
876 ////////////////////////////// Zaurus keys 876 ////////////////////////////// Zaurus keys
877 case Key_F9: //activity 877 case Key_F9: //activity
878 // if(audioUI->isHidden()) 878 // if(audioUI->isHidden())
879 // audioUI->showMaximized(); 879 // audioUI->showMaximized();
880 break; 880 break;
881 case Key_F10: //contacts 881 case Key_F10: //contacts
882 // if( videoUI->isHidden()) 882 // if( videoUI->isHidden())
883 // videoUI->showMaximized(); 883 // videoUI->showMaximized();
884 break; 884 break;
885 case Key_F11: //menu 885 case Key_F11: //menu
886 break; 886 break;
887 case Key_F12: //home 887 case Key_F12: //home
888 // doBlank(); 888 // doBlank();
889 break; 889 break;
890 case Key_F13: //mail 890 case Key_F13: //mail
891 // doUnblank(); 891 // doUnblank();
892 break; 892 break;
893 case Key_Q: //add to playlist 893 case Key_Q: //add to playlist
894 addSelected(); 894 addSelected();
895 break; 895 break;
896 case Key_R: //remove from playlist 896 case Key_R: //remove from playlist
897 removeSelected(); 897 removeSelected();
898 break; 898 break;
899 // case Key_P: //play 899 // case Key_P: //play
900 // odebug << "Play" << oendl; 900 // odebug << "Play" << oendl;
901 // playSelected(); 901 // playSelected();
902 // break; 902 // break;
903 case Key_Space: 903 case Key_Space:
904 // playSelected(); puh 904 // playSelected(); puh
905 break; 905 break;
906 case Key_1: 906 case Key_1:
907 tabWidget->setCurrentPage( 0 ); 907 tabWidget->setCurrentPage( 0 );
908 break; 908 break;
909 case Key_2: 909 case Key_2:
910 tabWidget->setCurrentPage( 1 ); 910 tabWidget->setCurrentPage( 1 );
911 break; 911 break;
912 case Key_3: 912 case Key_3:
913 tabWidget->setCurrentPage( 2 ); 913 tabWidget->setCurrentPage( 2 );
914 break; 914 break;
915 case Key_4: 915 case Key_4:
916 tabWidget->setCurrentPage( 3 ); 916 tabWidget->setCurrentPage( 3 );
917 break; 917 break;
918 case Key_Down: 918 case Key_Down:
919 if ( !d->selectedFiles->next() ) 919 if ( !d->selectedFiles->next() )
920 d->selectedFiles->first(); 920 d->selectedFiles->first();
921 break; 921 break;
922 case Key_Up: 922 case Key_Up:
923 if ( !d->selectedFiles->prev() ) 923 if ( !d->selectedFiles->prev() )
924 // d->selectedFiles->last(); 924 // d->selectedFiles->last();
925 break; 925 break;
926 } 926 }
927} 927}
928 928
929void PlayListWidget::pmViewActivated(int index) { 929void PlayListWidget::pmViewActivated(int index) {
930// odebug << "" << index << "" << oendl; 930// odebug << "" << index << "" << oendl;
931 switch(index) { 931 switch(index) {
932 case -16: 932 case -16:
933 { 933 {
934 mediaPlayerState->toggleFullscreen(); 934 mediaPlayerState->toggleFullscreen();
935 bool b=mediaPlayerState->isFullscreen(); 935 bool b=mediaPlayerState->isFullscreen();
936 pmView->setItemChecked( index, b); 936 pmView->setItemChecked( index, b);
937 Config cfg( "OpiePlayer" ); 937 Config cfg( "OpiePlayer" );
938 cfg.writeEntry( "FullScreen", b ); 938 cfg.writeEntry( "FullScreen", b );
939 } 939 }
940 break; 940 break;
941 }; 941 };
942} 942}
943 943
944void PlayListWidget::populateSkinsMenu() { 944void PlayListWidget::populateSkinsMenu() {
945 int item = 0; 945 int item = 0;
946 defaultSkinIndex = 0; 946 defaultSkinIndex = 0;
947 QString skinName; 947 QString skinName;
948 Config cfg( "OpiePlayer" ); 948 Config cfg( "OpiePlayer" );
949 cfg.setGroup("Options" ); 949 cfg.setGroup("Options" );
950 QString skin = cfg.readEntry( "Skin", "default" ); 950 QString skin = cfg.readEntry( "Skin", "default" );
951 951
952 QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); 952 QDir skinsDir( QPEApplication::qpeDir() + "pics/opieplayer2/skins" );
953 skinsDir.setFilter( QDir::Dirs ); 953 skinsDir.setFilter( QDir::Dirs );
954 skinsDir.setSorting(QDir::Name ); 954 skinsDir.setSorting(QDir::Name );
955 const QFileInfoList *skinslist = skinsDir.entryInfoList(); 955 const QFileInfoList *skinslist = skinsDir.entryInfoList();
956 QFileInfoListIterator it( *skinslist ); 956 QFileInfoListIterator it( *skinslist );
957 QFileInfo *fi; 957 QFileInfo *fi;
958 while ( ( fi = it.current() ) ) { 958 while ( ( fi = it.current() ) ) {
959 skinName = fi->fileName(); 959 skinName = fi->fileName();
960// odebug << fi->fileName() << oendl; 960// odebug << fi->fileName() << oendl;
961 if( skinName != "." && skinName != ".." && skinName !="CVS" ) { 961 if( skinName != "." && skinName != ".." && skinName !="CVS" ) {
962 item = skinsMenu->insertItem( fi->fileName() ) ; 962 item = skinsMenu->insertItem( fi->fileName() ) ;
963 } 963 }
964 if( skinName == "default" ) { 964 if( skinName == "default" ) {
965 defaultSkinIndex = item; 965 defaultSkinIndex = item;
966 } 966 }
967 if( skinName == skin ) { 967 if( skinName == skin ) {
968 skinsMenu->setItemChecked( item, TRUE ); 968 skinsMenu->setItemChecked( item, TRUE );
969 } 969 }
970 ++it; 970 ++it;
971 } 971 }
972} 972}
973 973
974void PlayListWidget::skinsMenuActivated( int item ) { 974void PlayListWidget::skinsMenuActivated( int item ) {
975 for(unsigned int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { 975 for(unsigned int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) {
976 skinsMenu->setItemChecked( i, FALSE ); 976 skinsMenu->setItemChecked( i, FALSE );
977 } 977 }
978 skinsMenu->setItemChecked( item, TRUE ); 978 skinsMenu->setItemChecked( item, TRUE );
979 979
980 { 980 {
981 Config cfg( "OpiePlayer" ); 981 Config cfg( "OpiePlayer" );
982 cfg.setGroup("Options"); 982 cfg.setGroup("Options");
983 cfg.writeEntry("Skin", skinsMenu->text( item ) ); 983 cfg.writeEntry("Skin", skinsMenu->text( item ) );
984 } 984 }
985 985
986 emit skinSelected(); 986 emit skinSelected();
987} 987}
988 988
989PlayListWidget::TabType PlayListWidget::currentTab() const 989PlayListWidget::TabType PlayListWidget::currentTab() const
990{ 990{
991 static const TabType indexToTabType[ TabTypeCount ] = 991 static const TabType indexToTabType[ TabTypeCount ] =
992 { CurrentPlayList, AudioFiles, VideoFiles, PlayLists }; 992 { CurrentPlayList, AudioFiles, VideoFiles, PlayLists };
993 993
994 int index = tabWidget->currentPageIndex(); 994 int index = tabWidget->currentPageIndex();
995 assert( index < TabTypeCount && index >= 0 ); 995 assert( index < TabTypeCount && index >= 0 );
996 996
997 return indexToTabType[ index ]; 997 return indexToTabType[ index ];
998} 998}
999 999
1000PlayListWidget::Entry PlayListWidget::currentEntry() const 1000PlayListWidget::Entry PlayListWidget::currentEntry() const
1001{ 1001{
1002 if ( currentTab() == CurrentPlayList ) { 1002 if ( currentTab() == CurrentPlayList ) {
1003 const DocLnk *lnk = current(); 1003 const DocLnk *lnk = current();
1004 return Entry( lnk->name(), lnk->file() ); 1004 return Entry( lnk->name(), lnk->file() );
1005 } 1005 }
1006 1006
1007 return Entry( currentFileListPathName() ); 1007 return Entry( currentFileListPathName() );
1008} 1008}
1009 1009
1010QString PlayListWidget::currentFileListPathName() const { 1010QString PlayListWidget::currentFileListPathName() const {
1011 return currentFileListView->currentItem()->text( 3 ); 1011 return currentFileListView->currentItem()->text( 3 );
1012} 1012}
1013 1013
1014 1014
1015void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { 1015void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) {
1016 QDataStream stream ( data, IO_ReadOnly ); 1016 QDataStream stream ( data, IO_ReadOnly );
1017 if ( msg == "play()" ) { //plays current selection 1017 if ( msg == "play()" ) { //plays current selection
1018 btnPlay( true); 1018 btnPlay( true);
1019 } else if ( msg == "stop()" ) { 1019 } else if ( msg == "stop()" ) {
1020 mediaPlayerState->setPlaying( false); 1020 mediaPlayerState->setPlaying( false);
1021 } else if ( msg == "togglePause()" ) { 1021 } else if ( msg == "togglePause()" ) {
1022 mediaPlayerState->togglePaused(); 1022 mediaPlayerState->togglePaused();
1023 } else if ( msg == "next()" ) { //select next in list 1023 } else if ( msg == "next()" ) { //select next in list
1024 mediaPlayerState->setNext(); 1024 mediaPlayerState->setNext();
1025 } else if ( msg == "prev()" ) { //select previous in list 1025 } else if ( msg == "prev()" ) { //select previous in list
1026 mediaPlayerState->setPrev(); 1026 mediaPlayerState->setPrev();
1027 } else if ( msg == "toggleLooping()" ) { //loop or not loop 1027 } else if ( msg == "toggleLooping()" ) { //loop or not loop
1028 mediaPlayerState->toggleLooping(); 1028 mediaPlayerState->toggleLooping();
1029 } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled 1029 } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled
1030 mediaPlayerState->toggleShuffled(); 1030 mediaPlayerState->toggleShuffled();
1031 } else if ( msg == "volUp()" ) { //volume more 1031 } else if ( msg == "volUp()" ) { //volume more
1032// emit moreClicked(); 1032// emit moreClicked();
1033// emit moreReleased(); 1033// emit moreReleased();
1034 } else if ( msg == "volDown()" ) { //volume less 1034 } else if ( msg == "volDown()" ) { //volume less
1035// emit lessClicked(); 1035// emit lessClicked();
1036// emit lessReleased(); 1036// emit lessReleased();
1037 } else if ( msg == "play(QString)" ) { //play this now 1037 } else if ( msg == "play(QString)" ) { //play this now
1038 QString file; 1038 QString file;
1039 stream >> file; 1039 stream >> file;
1040 setDocument( (const QString &) file); 1040 setDocument( (const QString &) file);
1041 } else if ( msg == "add(QString)" ) { //add to playlist 1041 } else if ( msg == "add(QString)" ) { //add to playlist
1042 QString file; 1042 QString file;
1043 stream >> file; 1043 stream >> file;
1044 QFileInfo fileInfo(file); 1044 QFileInfo fileInfo(file);
1045 DocLnk lnk; 1045 DocLnk lnk;
1046 lnk.setName( fileInfo.baseName() ); //sets name 1046 lnk.setName( fileInfo.baseName() ); //sets name
1047 lnk.setFile( file ); //sets file name 1047 lnk.setFile( file ); //sets file name
1048 addToSelection( lnk ); 1048 addToSelection( lnk );
1049 } else if ( msg == "rem(QString)" ) { //remove from playlist 1049 } else if ( msg == "rem(QString)" ) { //remove from playlist
1050 QString file; 1050 QString file;
1051 stream >> file; 1051 stream >> file;
1052 1052
1053 } 1053 }
1054 1054
1055} 1055}
1056 1056
1057DocLnk PlayListWidget::addFileToPlaylist( const QString& file, 1057DocLnk PlayListWidget::addFileToPlaylist( const QString& file,
1058 const QString& name ) { 1058 const QString& name ) {
1059 DocLnk lnk; 1059 DocLnk lnk;
1060 lnk.setName( name ); //sets name 1060 lnk.setName( name ); //sets name
1061 lnk.setFile( file ); //sets file name 1061 lnk.setFile( file ); //sets file name
1062 d->selectedFiles->addToSelection( lnk ); 1062 d->selectedFiles->addToSelection( lnk );
1063 writeCurrentM3u(); 1063 writeCurrentM3u();
1064 1064
1065 return lnk; 1065 return lnk;
1066} 1066}
diff --git a/noncore/settings/language/language.cpp b/noncore/settings/language/language.cpp
index 81d6717..14750ac 100644
--- a/noncore/settings/language/language.cpp
+++ b/noncore/settings/language/language.cpp
@@ -1,159 +1,159 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "settings.h" 21#include "settings.h"
22 22
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/fontmanager.h> 24#include <qpe/fontmanager.h>
25#include <qpe/config.h> 25#include <qpe/config.h>
26#include <qpe/applnk.h> 26#include <qpe/applnk.h>
27#include <qpe/qpedialog.h> 27#include <qpe/qpedialog.h>
28#include <qpe/qpeapplication.h> 28#include <qpe/qpeapplication.h>
29#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 29#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
30#include <qpe/qcopenvelope_qws.h> 30#include <qpe/qcopenvelope_qws.h>
31#endif 31#endif
32 32
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qcheckbox.h> 34#include <qcheckbox.h>
35#include <qradiobutton.h> 35#include <qradiobutton.h>
36#include <qtabwidget.h> 36#include <qtabwidget.h>
37#include <qslider.h> 37#include <qslider.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qdatastream.h> 40#include <qdatastream.h>
41#include <qmessagebox.h> 41#include <qmessagebox.h>
42#include <qcombobox.h> 42#include <qcombobox.h>
43#include <qspinbox.h> 43#include <qspinbox.h>
44#include <qlistbox.h> 44#include <qlistbox.h>
45#include <qdir.h> 45#include <qdir.h>
46#if QT_VERSION >= 300 46#if QT_VERSION >= 300
47#include <qstylefactory.h> 47#include <qstylefactory.h>
48#endif 48#endif
49 49
50#include <stdlib.h> 50#include <stdlib.h>
51 51
52 52
53LanguageSettings::LanguageSettings( QWidget* parent, const char* name, WFlags fl ) 53LanguageSettings::LanguageSettings( QWidget* parent, const char* name, WFlags fl )
54 : LanguageSettingsBase( parent, name, TRUE, fl ) 54 : LanguageSettingsBase( parent, name, TRUE, fl )
55{ 55{
56 if ( FontManager::hasUnicodeFont() ) 56 if ( FontManager::hasUnicodeFont() )
57 languages->setFont(FontManager::unicodeFont(FontManager::Proportional)); 57 languages->setFont(FontManager::unicodeFont(FontManager::Proportional));
58 58
59 59
60 QString tfn = QPEApplication::qpeDir() + "/i18n/"; 60 QString tfn = QPEApplication::qpeDir() + "i18n/";
61 QDir langDir = tfn; 61 QDir langDir = tfn;
62 QStringList list = langDir.entryList("*", QDir::Dirs ); 62 QStringList list = langDir.entryList("*", QDir::Dirs );
63 63
64 QStringList::Iterator it; 64 QStringList::Iterator it;
65 65
66 for ( it = list.begin(); it != list.end(); ++it ) { 66 for ( it = list.begin(); it != list.end(); ++it ) {
67 QString name = (*it); 67 QString name = (*it);
68 QFileInfo desktopFile( tfn + "/" + name + "/.directory" ); 68 QFileInfo desktopFile( tfn + "/" + name + "/.directory" );
69 if ( desktopFile.exists() ) { 69 if ( desktopFile.exists() ) {
70 langAvail.append(name); 70 langAvail.append(name);
71 Config conf( desktopFile.filePath(), Config::File ); 71 Config conf( desktopFile.filePath(), Config::File );
72 QString langName = conf.readEntry( "Name" ); 72 QString langName = conf.readEntry( "Name" );
73 QString ownName = conf.readEntryDirect( "Name[" + name + "]" ); 73 QString ownName = conf.readEntryDirect( "Name[" + name + "]" );
74 if ( ownName.isEmpty() ) 74 if ( ownName.isEmpty() )
75 ownName = conf.readEntryDirect( "Name" ); 75 ownName = conf.readEntryDirect( "Name" );
76 if ( !ownName.isEmpty() && ownName != langName ) 76 if ( !ownName.isEmpty() && ownName != langName )
77 langName = langName + " [" + ownName + "]"; 77 langName = langName + " [" + ownName + "]";
78 languages->insertItem( langName ); 78 languages->insertItem( langName );
79 79
80 } 80 }
81 } 81 }
82 if ( langAvail. find ( "en" ) == -1 ) { 82 if ( langAvail. find ( "en" ) == -1 ) {
83 langAvail. prepend ( "" ); // no tr 83 langAvail. prepend ( "" ); // no tr
84 languages-> insertItem ( QString ( "English [%1] (%2)" /* no tr (!) */ ). arg ( tr ( "English" )). arg ( tr( "default" )), 0 ); 84 languages-> insertItem ( QString ( "English [%1] (%2)" /* no tr (!) */ ). arg ( tr ( "English" )). arg ( tr( "default" )), 0 );
85 } 85 }
86 86
87 dl = new QPEDialogListener(this); 87 dl = new QPEDialogListener(this);
88 reset(); 88 reset();
89} 89}
90 90
91LanguageSettings::~LanguageSettings() 91LanguageSettings::~LanguageSettings()
92{} 92{}
93 93
94void LanguageSettings::accept() 94void LanguageSettings::accept()
95{ 95{
96 Config c( "qpe" ); 96 Config c( "qpe" );
97 c.setGroup( "Startup" ); 97 c.setGroup( "Startup" );
98 if ( ( c.readNumEntry( "FirstUse", 42 ) == 0 ) && 98 if ( ( c.readNumEntry( "FirstUse", 42 ) == 0 ) &&
99 ( QMessageBox::warning( this, tr("Language"), tr("<qt>Attention, all windows will be closed by changing the language\n" 99 ( QMessageBox::warning( this, tr("Language"), tr("<qt>Attention, all windows will be closed by changing the language\n"
100 "without saving the Data.<br><br>Go on?</qt>"), 1, 2) ) 100 "without saving the Data.<br><br>Go on?</qt>"), 1, 2) )
101 == QMessageBox::Cancel ) 101 == QMessageBox::Cancel )
102 return; 102 return;
103 applyLanguage(); 103 applyLanguage();
104 QDialog::accept(); 104 QDialog::accept();
105} 105}
106 106
107void LanguageSettings::applyLanguage() 107void LanguageSettings::applyLanguage()
108{ 108{
109 setLanguage ( langAvail. at ( languages-> currentItem ( ))); 109 setLanguage ( langAvail. at ( languages-> currentItem ( )));
110} 110}
111 111
112 112
113void LanguageSettings::reject() 113void LanguageSettings::reject()
114{ 114{
115 reset(); 115 reset();
116 QDialog::reject(); 116 QDialog::reject();
117} 117}
118 118
119void LanguageSettings::reset() 119void LanguageSettings::reset()
120{ 120{
121 QString l = getenv("LANG"); 121 QString l = getenv("LANG");
122 Config config("locale"); 122 Config config("locale");
123 config.setGroup("Language"); 123 config.setGroup("Language");
124 l = config.readEntry( "Language", l ); 124 l = config.readEntry( "Language", l );
125 actualLanguage = l; 125 actualLanguage = l;
126 if (l.isEmpty()) 126 if (l.isEmpty())
127 l = "en"; 127 l = "en";
128 128
129 int n = langAvail.find( l ); 129 int n = langAvail.find( l );
130 languages->setCurrentItem( n ); 130 languages->setCurrentItem( n );
131} 131}
132 132
133QString LanguageSettings::actualLanguage; 133QString LanguageSettings::actualLanguage;
134 134
135void LanguageSettings::setLanguage(const QString& lang) 135void LanguageSettings::setLanguage(const QString& lang)
136{ 136{
137 if ( lang != actualLanguage ) { 137 if ( lang != actualLanguage ) {
138 Config config("locale"); 138 Config config("locale");
139 config.setGroup( "Language" ); 139 config.setGroup( "Language" );
140 if ( lang. isEmpty ( )) 140 if ( lang. isEmpty ( ))
141 config. removeEntry ( "Language" ); 141 config. removeEntry ( "Language" );
142 else 142 else
143 config.writeEntry( "Language", lang ); 143 config.writeEntry( "Language", lang );
144 config.write(); 144 config.write();
145 145
146#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 146#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
147 147
148 QCopEnvelope e("QPE/System", "language(QString)"); 148 QCopEnvelope e("QPE/System", "language(QString)");
149 e << lang; 149 e << lang;
150#endif 150#endif
151 151
152 } 152 }
153} 153}
154 154
155void LanguageSettings::done(int r) 155void LanguageSettings::done(int r)
156{ 156{
157 QDialog::done(r); 157 QDialog::done(r);
158 close(); 158 close();
159} 159}
diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
index fb7d7c9..5f23aea 100644
--- a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp
@@ -1,713 +1,713 @@
1 1
2#include "mainwindowimp.h" 2#include "mainwindowimp.h"
3#include "addconnectionimp.h" 3#include "addconnectionimp.h"
4#include "interfaceinformationimp.h" 4#include "interfaceinformationimp.h"
5#include "interfacesetupimp.h" 5#include "interfacesetupimp.h"
6#include "interfaces.h" 6#include "interfaces.h"
7#include "module.h" 7#include "module.h"
8 8
9/* OPIE */ 9/* OPIE */
10#include <opie2/odebug.h> 10#include <opie2/odebug.h>
11#include <qpe/qcopenvelope_qws.h> 11#include <qpe/qcopenvelope_qws.h>
12#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
13#include <qpe/config.h> 13#include <qpe/config.h>
14#include <qpe/qlibrary.h> 14#include <qpe/qlibrary.h>
15#include <qpe/resource.h> 15#include <qpe/resource.h>
16 16
17/* QT */ 17/* QT */
18#include <qpushbutton.h> 18#include <qpushbutton.h>
19#include <qlistbox.h> 19#include <qlistbox.h>
20#include <qlineedit.h> 20#include <qlineedit.h>
21#include <qlistview.h> 21#include <qlistview.h>
22#include <qheader.h> 22#include <qheader.h>
23#include <qlabel.h> 23#include <qlabel.h>
24#include <qtabwidget.h> // in order to disable the profiles tab 24#include <qtabwidget.h> // in order to disable the profiles tab
25#include <qmessagebox.h> 25#include <qmessagebox.h>
26 26
27 27
28#if QT_VERSION < 300 28#if QT_VERSION < 300
29#include <qlist.h> 29#include <qlist.h>
30#else 30#else
31#include <qptrlist.h> 31#include <qptrlist.h>
32#endif 32#endif
33#include <qdir.h> 33#include <qdir.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qregexp.h> 36#include <qregexp.h>
37 37
38/* STD */ 38/* STD */
39#include <net/if.h> 39#include <net/if.h>
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41#include <sys/socket.h> 41#include <sys/socket.h>
42 42
43#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" 43#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
44#define _PROCNETDEV "/proc/net/dev" 44#define _PROCNETDEV "/proc/net/dev"
45 45
46MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME) 46MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME)
47{ 47{
48 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 48 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
49 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 49 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
50 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 50 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
51 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 51 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
52 52
53 //remove tab with no function 53 //remove tab with no function
54 tabWidget->removePage( tab ); 54 tabWidget->removePage( tab );
55 55
56 // Load connections. 56 // Load connections.
57 // /usr/local/kde/lib/libinterfaces.la 57 // /usr/local/kde/lib/libinterfaces.la
58 loadModules(QPEApplication::qpeDir() + "plugins/networksettings"); 58 loadModules(QPEApplication::qpeDir() + "plugins/networksettings");
59 getAllInterfaces(); 59 getAllInterfaces();
60 60
61 Interfaces i; 61 Interfaces i;
62 QStringList list = i.getInterfaceList(); 62 QStringList list = i.getInterfaceList();
63 QMap<QString, Interface*>::Iterator it; 63 QMap<QString, Interface*>::Iterator it;
64 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) 64 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni )
65 { 65 {
66 /* 66 /*
67 * we skipped it in getAllInterfaces now 67 * we skipped it in getAllInterfaces now
68 * we need to ignore it as well 68 * we need to ignore it as well
69 */ 69 */
70 if (m_handledIfaces.contains( *ni) ) 70 if (m_handledIfaces.contains( *ni) )
71 { 71 {
72 odebug << "Not up iface handled by module" << oendl; 72 odebug << "Not up iface handled by module" << oendl;
73 continue; 73 continue;
74 } 74 }
75 bool found = false; 75 bool found = false;
76 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ) 76 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it )
77 { 77 {
78 if(it.key() == (*ni)) 78 if(it.key() == (*ni))
79 found = true; 79 found = true;
80 } 80 }
81 if(!found) 81 if(!found)
82 { 82 {
83 if(!(*ni).contains("_")) 83 if(!(*ni).contains("_"))
84 { 84 {
85 Interface *i = new Interface(this, *ni, false); 85 Interface *i = new Interface(this, *ni, false);
86 i->setAttached(false); 86 i->setAttached(false);
87 i->setHardwareName(tr("Disconnected")); 87 i->setHardwareName(tr("Disconnected"));
88 interfaceNames.insert(i->getInterfaceName(), i); 88 interfaceNames.insert(i->getInterfaceName(), i);
89 updateInterface(i); 89 updateInterface(i);
90 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*))); 90 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*)));
91 } 91 }
92 } 92 }
93 } 93 }
94 94
95 //getInterfaceList(); 95 //getInterfaceList();
96 connectionList->header()->hide(); 96 connectionList->header()->hide();
97 97
98 Config cfg("NetworkSetup"); 98 Config cfg("NetworkSetup");
99 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 99 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
100 for ( QStringList::Iterator it = profiles.begin(); 100 for ( QStringList::Iterator it = profiles.begin();
101 it != profiles.end(); ++it) 101 it != profiles.end(); ++it)
102 profilesList->insertItem((*it)); 102 profilesList->insertItem((*it));
103 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 103 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
104 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 104 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
105 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 105 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
106 106
107 QFile file(scheme); 107 QFile file(scheme);
108 if ( file.open(IO_ReadOnly) ) 108 if ( file.open(IO_ReadOnly) )
109 { // file opened successfully 109 { // file opened successfully
110 QTextStream stream( &file ); // use a text stream 110 QTextStream stream( &file ); // use a text stream
111 while ( !stream.eof() ) 111 while ( !stream.eof() )
112 { // until end of file... 112 { // until end of file...
113 QString line = stream.readLine(); // line of text excluding '\n' 113 QString line = stream.readLine(); // line of text excluding '\n'
114 if(line.contains("SCHEME")) 114 if(line.contains("SCHEME"))
115 { 115 {
116 line = line.mid(7, line.length()); 116 line = line.mid(7, line.length());
117 currentProfileLabel->setText(line); 117 currentProfileLabel->setText(line);
118 break; 118 break;
119 } 119 }
120 } 120 }
121 file.close(); 121 file.close();
122 } 122 }
123 makeChannel(); 123 makeChannel();
124} 124}
125 125
126/** 126/**
127 * Deconstructor. Save profiles. Delete loaded libraries. 127 * Deconstructor. Save profiles. Delete loaded libraries.
128 */ 128 */
129MainWindowImp::~MainWindowImp() 129MainWindowImp::~MainWindowImp()
130{ 130{
131 // Save profiles. 131 // Save profiles.
132 Config cfg("NetworkSetup"); 132 Config cfg("NetworkSetup");
133 cfg.setGroup("General"); 133 cfg.setGroup("General");
134 cfg.writeEntry("Profiles", profiles.join(" ")); 134 cfg.writeEntry("Profiles", profiles.join(" "));
135 135
136 // Delete all interfaces that don't have owners. 136 // Delete all interfaces that don't have owners.
137 QMap<Interface*, QListViewItem*>::Iterator iIt; 137 QMap<Interface*, QListViewItem*>::Iterator iIt;
138 for( iIt = items.begin(); iIt != items.end(); ++iIt ) 138 for( iIt = items.begin(); iIt != items.end(); ++iIt )
139 { 139 {
140 if(iIt.key()->getModuleOwner() == NULL) 140 if(iIt.key()->getModuleOwner() == NULL)
141 delete iIt.key(); 141 delete iIt.key();
142 } 142 }
143 143
144 // Delete Modules and Libraries 144 // Delete Modules and Libraries
145 QMap<Module*, QLibrary*>::Iterator it; 145 QMap<Module*, QLibrary*>::Iterator it;
146 for( it = libraries.begin(); it != libraries.end(); ++it ) 146 for( it = libraries.begin(); it != libraries.end(); ++it )
147 { 147 {
148 delete it.key(); 148 delete it.key();
149 // I wonder why I can't delete the libraries 149 // I wonder why I can't delete the libraries
150 // What fucking shit this is. 150 // What fucking shit this is.
151 //delete it.data(); 151 //delete it.data();
152 } 152 }
153} 153}
154 154
155/** 155/**
156 * Query the kernel for all of the interfaces. 156 * Query the kernel for all of the interfaces.
157 */ 157 */
158void MainWindowImp::getAllInterfaces() 158void MainWindowImp::getAllInterfaces()
159{ 159{
160 int sockfd = socket(PF_INET, SOCK_DGRAM, 0); 160 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
161 if(sockfd == -1) 161 if(sockfd == -1)
162 return; 162 return;
163 163
164 struct ifreq ifr; 164 struct ifreq ifr;
165 QStringList ifaces; 165 QStringList ifaces;
166 QFile procFile(QString(_PROCNETDEV)); 166 QFile procFile(QString(_PROCNETDEV));
167 int result; 167 int result;
168 Interface *i; 168 Interface *i;
169 169
170 if (! procFile.exists()) 170 if (! procFile.exists())
171 { 171 {
172 struct ifreq ifrs[100]; 172 struct ifreq ifrs[100];
173 struct ifconf ifc; 173 struct ifconf ifc;
174 ifc.ifc_len = sizeof(ifrs); 174 ifc.ifc_len = sizeof(ifrs);
175 ifc.ifc_req = ifrs; 175 ifc.ifc_req = ifrs;
176 result = ioctl(sockfd, SIOCGIFCONF, &ifc); 176 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
177 177
178 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) 178 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
179 { 179 {
180 struct ifreq *pifr = &ifrs[i]; 180 struct ifreq *pifr = &ifrs[i];
181 181
182 ifaces += pifr->ifr_name; 182 ifaces += pifr->ifr_name;
183 } 183 }
184 } 184 }
185 else 185 else
186 { 186 {
187 procFile.open(IO_ReadOnly); 187 procFile.open(IO_ReadOnly);
188 QString line; 188 QString line;
189 QTextStream procTs(&procFile); 189 QTextStream procTs(&procFile);
190 int loc = -1; 190 int loc = -1;
191 191
192 procTs.readLine(); // eat a line 192 procTs.readLine(); // eat a line
193 procTs.readLine(); // eat a line 193 procTs.readLine(); // eat a line
194 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) 194 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null)
195 { 195 {
196 if((loc = line.find(":")) != -1) 196 if((loc = line.find(":")) != -1)
197 { 197 {
198 ifaces += line.left(loc); 198 ifaces += line.left(loc);
199 } 199 }
200 } 200 }
201 } 201 }
202 202
203 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) 203 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it)
204 { 204 {
205 int flags = 0; 205 int flags = 0;
206 if ( m_handledIfaces.contains( (*it) ) ) 206 if ( m_handledIfaces.contains( (*it) ) )
207 { 207 {
208 odebug << " " << (*it).latin1() << " is handled by a module" << oendl; 208 odebug << " " << (*it).latin1() << " is handled by a module" << oendl;
209 continue; 209 continue;
210 } 210 }
211 // int family; 211 // int family;
212 i = NULL; 212 i = NULL;
213 213
214 strcpy(ifr.ifr_name, (*it).latin1()); 214 strcpy(ifr.ifr_name, (*it).latin1());
215 215
216 struct ifreq ifcopy; 216 struct ifreq ifcopy;
217 ifcopy = ifr; 217 ifcopy = ifr;
218 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); 218 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
219 flags = ifcopy.ifr_flags; 219 flags = ifcopy.ifr_flags;
220 i = new Interface(this, ifr.ifr_name, false); 220 i = new Interface(this, ifr.ifr_name, false);
221 i->setAttached(true); 221 i->setAttached(true);
222 if ((flags & IFF_UP) == IFF_UP) 222 if ((flags & IFF_UP) == IFF_UP)
223 i->setStatus(true); 223 i->setStatus(true);
224 else 224 else
225 i->setStatus(false); 225 i->setStatus(false);
226 226
227 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 227 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
228 i->setHardwareName("Ethernet"); 228 i->setHardwareName("Ethernet");
229 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 229 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
230 i->setHardwareName("Point to Point"); 230 i->setHardwareName("Point to Point");
231 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 231 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
232 i->setHardwareName("Multicast"); 232 i->setHardwareName("Multicast");
233 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 233 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
234 i->setHardwareName("Loopback"); 234 i->setHardwareName("Loopback");
235 else 235 else
236 i->setHardwareName("Unknown"); 236 i->setHardwareName("Unknown");
237 237
238 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl; 238 owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl;
239 interfaceNames.insert(i->getInterfaceName(), i); 239 interfaceNames.insert(i->getInterfaceName(), i);
240 updateInterface(i); 240 updateInterface(i);
241 connect(i, SIGNAL(updateInterface(Interface*)), 241 connect(i, SIGNAL(updateInterface(Interface*)),
242 this, SLOT(updateInterface(Interface*))); 242 this, SLOT(updateInterface(Interface*)));
243 } 243 }
244 // now lets ask the plugins too ;) 244 // now lets ask the plugins too ;)
245 QMap<Module*, QLibrary*>::Iterator it; 245 QMap<Module*, QLibrary*>::Iterator it;
246 QList<Interface> ilist; 246 QList<Interface> ilist;
247 for( it = libraries.begin(); it != libraries.end(); ++it ) 247 for( it = libraries.begin(); it != libraries.end(); ++it )
248 { 248 {
249 if(it.key()) 249 if(it.key())
250 { 250 {
251 ilist = it.key()->getInterfaces(); 251 ilist = it.key()->getInterfaces();
252 for( i = ilist.first(); i != 0; i = ilist.next() ) 252 for( i = ilist.first(); i != 0; i = ilist.next() )
253 { 253 {
254 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl; 254 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl;
255 interfaceNames.insert(i->getInterfaceName(), i); 255 interfaceNames.insert(i->getInterfaceName(), i);
256 updateInterface(i); 256 updateInterface(i);
257 connect(i, SIGNAL(updateInterface(Interface*)), 257 connect(i, SIGNAL(updateInterface(Interface*)),
258 this, SLOT(updateInterface(Interface*))); 258 this, SLOT(updateInterface(Interface*)));
259 } 259 }
260 } 260 }
261 } 261 }
262} 262}
263 263
264/** 264/**
265 * Load all modules that are found in the path 265 * Load all modules that are found in the path
266 * @param path a directory that is scaned for any plugins that can be loaded 266 * @param path a directory that is scaned for any plugins that can be loaded
267 * and attempts to load them 267 * and attempts to load them
268 */ 268 */
269void MainWindowImp::loadModules(const QString &path) 269void MainWindowImp::loadModules(const QString &path)
270{ 270{
271#ifdef DEBUG 271#ifdef DEBUG
272 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl; 272 odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl;
273#endif 273#endif
274 QDir d(path); 274 QDir d(path);
275 if(!d.exists()) 275 if(!d.exists())
276 return; 276 return;
277 277
278 QString lang = ::getenv("LANG"); 278 QString lang = ::getenv("LANG");
279 // Don't want sym links 279 // Don't want sym links
280 d.setFilter( QDir::Files | QDir::NoSymLinks ); 280 d.setFilter( QDir::Files | QDir::NoSymLinks );
281 const QFileInfoList *list = d.entryInfoList(); 281 const QFileInfoList *list = d.entryInfoList();
282 QFileInfoListIterator it( *list ); 282 QFileInfoListIterator it( *list );
283 QFileInfo *fi; 283 QFileInfo *fi;
284 while ( (fi=it.current()) ) 284 while ( (fi=it.current()) )
285 { 285 {
286 if(fi->fileName().contains(".so")) 286 if(fi->fileName().contains(".so"))
287 { 287 {
288 /* if loaded install translation */ 288 /* if loaded install translation */
289 if( loadPlugin(path + "/" + fi->fileName()) != 0l ){ 289 if( loadPlugin(path + "/" + fi->fileName()) != 0l ){
290 QTranslator *trans = new QTranslator(qApp); 290 QTranslator *trans = new QTranslator(qApp);
291 QString fn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+".qm"; 291 QString fn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+".qm";
292 if( trans->load( fn ) ) 292 if( trans->load( fn ) )
293 qApp->installTranslator( trans ); 293 qApp->installTranslator( trans );
294 else 294 else
295 delete trans; 295 delete trans;
296 } 296 }
297 odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl; 297 odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl;
298 } 298 }
299 ++it; 299 ++it;
300 } 300 }
301} 301}
302 302
303/** 303/**
304 * Attempt to load a function and resolve a function. 304 * Attempt to load a function and resolve a function.
305 * @param pluginFileName - the name of the file in which to attempt to load 305 * @param pluginFileName - the name of the file in which to attempt to load
306 * @param resolveString - function pointer to resolve 306 * @param resolveString - function pointer to resolve
307 * @return pointer to the function with name resolveString or NULL 307 * @return pointer to the function with name resolveString or NULL
308 */ 308 */
309Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString) 309Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString)
310{ 310{
311#ifdef DEBUG 311#ifdef DEBUG
312 odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl; 312 odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl;
313#endif 313#endif
314 QLibrary *lib = new QLibrary(pluginFileName); 314 QLibrary *lib = new QLibrary(pluginFileName);
315 void *functionPointer = lib->resolve(resolveString); 315 void *functionPointer = lib->resolve(resolveString);
316 if( !functionPointer ) 316 if( !functionPointer )
317 { 317 {
318#ifdef DEBUG 318#ifdef DEBUG
319 odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl; 319 odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl;
320#endif 320#endif
321 delete lib; 321 delete lib;
322 return 0; 322 return 0;
323 } 323 }
324 // Try to get an object. 324 // Try to get an object.
325 Module *object = ((Module* (*)()) functionPointer)(); 325 Module *object = ((Module* (*)()) functionPointer)();
326 if(object == 0) 326 if(object == 0)
327 { 327 {
328#ifdef DEBUG 328#ifdef DEBUG
329 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl; 329 odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl;
330#endif 330#endif
331 delete lib; 331 delete lib;
332 return 0; 332 return 0;
333 } 333 }
334 334
335 m_handledIfaces += object->handledInterfaceNames(); 335 m_handledIfaces += object->handledInterfaceNames();
336 // Store for deletion later 336 // Store for deletion later
337 libraries.insert(object, lib); 337 libraries.insert(object, lib);
338 return object; 338 return object;
339} 339}
340 340
341/** 341/**
342 * The Add button was clicked. Bring up the add dialog and if OK is hit 342 * The Add button was clicked. Bring up the add dialog and if OK is hit
343 * load the plugin and append it to the list 343 * load the plugin and append it to the list
344 */ 344 */
345void MainWindowImp::addClicked() 345void MainWindowImp::addClicked()
346{ 346{
347 QMap<Module*, QLibrary*>::Iterator it; 347 QMap<Module*, QLibrary*>::Iterator it;
348 QMap<QString, QString> list; 348 QMap<QString, QString> list;
349 QMap<QString, Module*> newInterfaceOwners; 349 QMap<QString, Module*> newInterfaceOwners;
350 350
351 for( it = libraries.begin(); it != libraries.end(); ++it ) 351 for( it = libraries.begin(); it != libraries.end(); ++it )
352 { 352 {
353 if(it.key()) 353 if(it.key())
354 { 354 {
355 (it.key())->possibleNewInterfaces(list); 355 (it.key())->possibleNewInterfaces(list);
356 } 356 }
357 } 357 }
358 // See if the list has anything that we can add. 358 // See if the list has anything that we can add.
359 if(list.count() == 0) 359 if(list.count() == 0)
360 { 360 {
361 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); 361 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
362 return; 362 return;
363 } 363 }
364 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 364 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
365 addNewConnection.addConnections(list); 365 addNewConnection.addConnections(list);
366 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) ) 366 if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) )
367 { 367 {
368 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 368 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
369 if(!item) 369 if(!item)
370 return; 370 return;
371 371
372 for( it = libraries.begin(); it != libraries.end(); ++it ) 372 for( it = libraries.begin(); it != libraries.end(); ++it )
373 { 373 {
374 if(it.key()) 374 if(it.key())
375 { 375 {
376 Interface *i = (it.key())->addNewInterface(item->text(0)); 376 Interface *i = (it.key())->addNewInterface(item->text(0));
377 if(i) 377 if(i)
378 { 378 {
379 odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl; 379 odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl;
380 interfaceNames.insert(i->getInterfaceName(), i); 380 interfaceNames.insert(i->getInterfaceName(), i);
381 updateInterface(i); 381 updateInterface(i);
382 } 382 }
383 } 383 }
384 } 384 }
385 } 385 }
386} 386}
387 387
388/** 388/**
389 * Prompt the user to see if they really want to do this. 389 * Prompt the user to see if they really want to do this.
390 * If they do then remove from the list and unload. 390 * If they do then remove from the list and unload.
391 */ 391 */
392void MainWindowImp::removeClicked() 392void MainWindowImp::removeClicked()
393{ 393{
394 QListViewItem *item = connectionList->currentItem(); 394 QListViewItem *item = connectionList->currentItem();
395 if(!item) 395 if(!item)
396 { 396 {
397 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 397 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
398 return; 398 return;
399 } 399 }
400 400
401 Interface *i = interfaceItems[item]; 401 Interface *i = interfaceItems[item];
402 if(i->getModuleOwner() == NULL) 402 if(i->getModuleOwner() == NULL)
403 { 403 {
404 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 404 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
405 } 405 }
406 else 406 else
407 { 407 {
408 if(!i->getModuleOwner()->remove(i)) 408 if(!i->getModuleOwner()->remove(i))
409 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok); 409 QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok);
410 else 410 else
411 { 411 {
412 delete item; 412 delete item;
413 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 413 // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
414 } 414 }
415 } 415 }
416} 416}
417 417
418/** 418/**
419 * Pull up the configure about the currently selected interface. 419 * Pull up the configure about the currently selected interface.
420 * Report an error if no interface is selected. 420 * Report an error if no interface is selected.
421 * If the interface has a module owner then request its configure. 421 * If the interface has a module owner then request its configure.
422 */ 422 */
423void MainWindowImp::configureClicked() 423void MainWindowImp::configureClicked()
424{ 424{
425 QListViewItem *item = connectionList->currentItem(); 425 QListViewItem *item = connectionList->currentItem();
426 if(!item) 426 if(!item)
427 { 427 {
428 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); 428 QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok);
429 return; 429 return;
430 } 430 }
431 431
432 QString currentProfileText = currentProfileLabel->text(); 432 QString currentProfileText = currentProfileLabel->text();
433 if(currentProfileText.upper() == "ALL"); 433 if(currentProfileText.upper() == "ALL");
434 currentProfileText = ""; 434 currentProfileText = "";
435 435
436 Interface *i = interfaceItems[item]; 436 Interface *i = interfaceItems[item];
437 437
438 if(i->getModuleOwner()) 438 if(i->getModuleOwner())
439 { 439 {
440 QWidget *moduleConfigure = i->getModuleOwner()->configure(i); 440 QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
441 if(moduleConfigure != NULL) 441 if(moduleConfigure != NULL)
442 { 442 {
443 i->getModuleOwner()->setProfile(currentProfileText); 443 i->getModuleOwner()->setProfile(currentProfileText);
444 QPEApplication::showWidget( moduleConfigure ); 444 QPEApplication::showWidget( moduleConfigure );
445 return; 445 return;
446 } 446 }
447 } 447 }
448 448
449 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp ); 449 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp );
450 configure->setProfile(currentProfileText); 450 configure->setProfile(currentProfileText);
451 QPEApplication::showDialog( configure ); 451 QPEApplication::showDialog( configure );
452} 452}
453 453
454/** 454/**
455 * Pull up the information about the currently selected interface. 455 * Pull up the information about the currently selected interface.
456 * Report an error if no interface is selected. 456 * Report an error if no interface is selected.
457 * If the interface has a module owner then request its configure. 457 * If the interface has a module owner then request its configure.
458 */ 458 */
459void MainWindowImp::informationClicked() 459void MainWindowImp::informationClicked()
460{ 460{
461 QListViewItem *item = connectionList->currentItem(); 461 QListViewItem *item = connectionList->currentItem();
462 if(!item) 462 if(!item)
463 { 463 {
464 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 464 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
465 return; 465 return;
466 } 466 }
467 467
468 Interface *i = interfaceItems[item]; 468 Interface *i = interfaceItems[item];
469 // if(!i->isAttached()){ 469 // if(!i->isAttached()){
470 // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); 470 // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
471 // return; 471 // return;
472 // } 472 // }
473 473
474 if(i->getModuleOwner()) 474 if(i->getModuleOwner())
475 { 475 {
476 QWidget *moduleInformation = i->getModuleOwner()->information(i); 476 QWidget *moduleInformation = i->getModuleOwner()->information(i);
477 if(moduleInformation != NULL) 477 if(moduleInformation != NULL)
478 { 478 {
479 QPEApplication::showWidget( moduleInformation ); 479 QPEApplication::showWidget( moduleInformation );
480#ifdef DEBUG 480#ifdef DEBUG
481 odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl; 481 odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl;
482#endif 482#endif
483 return; 483 return;
484 } 484 }
485 } 485 }
486 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp); 486 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp);
487 QPEApplication::showWidget( information ); 487 QPEApplication::showWidget( information );
488} 488}
489 489
490/** 490/**
491 * Update this interface. If no QListViewItem exists create one. 491 * Update this interface. If no QListViewItem exists create one.
492 * @param Interface* pointer to the interface that needs to be updated. 492 * @param Interface* pointer to the interface that needs to be updated.
493 */ 493 */
494void MainWindowImp::updateInterface(Interface *i) 494void MainWindowImp::updateInterface(Interface *i)
495{ 495{
496 if(!advancedUserMode) 496 if(!advancedUserMode)
497 { 497 {
498 if(i->getInterfaceName() == "lo") 498 if(i->getInterfaceName() == "lo")
499 return; 499 return;
500 } 500 }
501 501
502 QListViewItem *item = NULL; 502 QListViewItem *item = NULL;
503 503
504 // Find the interface, making it if needed. 504 // Find the interface, making it if needed.
505 if(items.find(i) == items.end()) 505 if(items.find(i) == items.end())
506 { 506 {
507 item = new QListViewItem(connectionList, "", "", ""); 507 item = new QListViewItem(connectionList, "", "", "");
508 // See if you can't find a module owner for this interface 508 // See if you can't find a module owner for this interface
509 QMap<Module*, QLibrary*>::Iterator it; 509 QMap<Module*, QLibrary*>::Iterator it;
510 for( it = libraries.begin(); it != libraries.end(); ++it ) 510 for( it = libraries.begin(); it != libraries.end(); ++it )
511 { 511 {
512 if(it.key()->isOwner(i)) 512 if(it.key()->isOwner(i))
513 i->setModuleOwner(it.key()); 513 i->setModuleOwner(it.key());
514 } 514 }
515 items.insert(i, item); 515 items.insert(i, item);
516 interfaceItems.insert(item, i); 516 interfaceItems.insert(item, i);
517 } 517 }
518 else 518 else
519 item = items[i]; 519 item = items[i];
520 520
521 // Update the icons and information 521 // Update the icons and information
522#ifdef QWS 522#ifdef QWS
523 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 523 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
524#else 524#else
525 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); 525 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down")));
526#endif 526#endif
527 527
528 QString typeName = "lan"; 528 QString typeName = "lan";
529 if(i->getInterfaceName() == "lo") 529 if(i->getInterfaceName() == "lo")
530 typeName = "lo"; 530 typeName = "lo";
531 if(i->getInterfaceName().contains("irda")) 531 if(i->getInterfaceName().contains("irda"))
532 typeName = "irda"; 532 typeName = "irda";
533 if(i->getInterfaceName().contains("wlan")) 533 if(i->getInterfaceName().contains("wlan"))
534 typeName = "wlan"; 534 typeName = "wlan";
535 if(i->getInterfaceName().contains("usb")) 535 if(i->getInterfaceName().contains("usb"))
536 typeName = "usb"; 536 typeName = "usb";
537 537
538 if(!i->isAttached()) 538 if(!i->isAttached())
539 typeName = "connect_no"; 539 typeName = "connect_no";
540 // Actually try to use the Module 540 // Actually try to use the Module
541 if(i->getModuleOwner() != NULL) 541 if(i->getModuleOwner() != NULL)
542 typeName = i->getModuleOwner()->getPixmapName(i); 542 typeName = i->getModuleOwner()->getPixmapName(i);
543 543
544#ifdef QWS 544#ifdef QWS
545 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); 545 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName)));
546#else 546#else
547 item->setPixmap(1, (SmallIcon(typeName))); 547 item->setPixmap(1, (SmallIcon(typeName)));
548#endif 548#endif
549 item->setText(2, i->getHardwareName()); 549 item->setText(2, i->getHardwareName());
550 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 550 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
551 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 551 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
552} 552}
553 553
554void MainWindowImp::newProfileChanged(const QString& newText) 554void MainWindowImp::newProfileChanged(const QString& newText)
555{ 555{
556 if(newText.length() > 0) 556 if(newText.length() > 0)
557 newProfileButton->setEnabled(true); 557 newProfileButton->setEnabled(true);
558 else 558 else
559 newProfileButton->setEnabled(false); 559 newProfileButton->setEnabled(false);
560} 560}
561 561
562/** 562/**
563 * Adds a new profile to the list of profiles. 563 * Adds a new profile to the list of profiles.
564 * Don't add profiles that already exists. 564 * Don't add profiles that already exists.
565 * Appends to the list and QStringList 565 * Appends to the list and QStringList
566 */ 566 */
567void MainWindowImp::addProfile() 567void MainWindowImp::addProfile()
568{ 568{
569 QString newProfileName = newProfile->text(); 569 QString newProfileName = newProfile->text();
570 if(profiles.grep(newProfileName).count() > 0) 570 if(profiles.grep(newProfileName).count() > 0)
571 { 571 {
572 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); 572 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
573 return; 573 return;
574 } 574 }
575 profiles.append(newProfileName); 575 profiles.append(newProfileName);
576 profilesList->insertItem(newProfileName); 576 profilesList->insertItem(newProfileName);
577} 577}
578 578
579/** 579/**
580 * Removes the currently selected profile in the combo. 580 * Removes the currently selected profile in the combo.
581 * Doesn't delete if there are less then 2 profiles. 581 * Doesn't delete if there are less then 2 profiles.
582 */ 582 */
583void MainWindowImp::removeProfile() 583void MainWindowImp::removeProfile()
584{ 584{
585 if(profilesList->count() <= 1) 585 if(profilesList->count() <= 1)
586 { 586 {
587 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); 587 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
588 return; 588 return;
589 } 589 }
590 QString profileToRemove = profilesList->currentText(); 590 QString profileToRemove = profilesList->currentText();
591 if(profileToRemove == "All") 591 if(profileToRemove == "All")
592 { 592 {
593 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); 593 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
594 return; 594 return;
595 } 595 }
596 // Can't remove the curent profile 596 // Can't remove the curent profile
597 if(profileToRemove == currentProfileLabel->text()) 597 if(profileToRemove == currentProfileLabel->text())
598 { 598 {
599 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); 599 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok);
600 return; 600 return;
601 601
602 } 602 }
603 603
604 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) 604 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
605 { 605 {
606 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 606 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
607 profilesList->clear(); 607 profilesList->clear();
608 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 608 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
609 profilesList->insertItem((*it)); 609 profilesList->insertItem((*it));
610 610
611 // Remove any interface settings and mappings. 611 // Remove any interface settings and mappings.
612 Interfaces interfaces; 612 Interfaces interfaces;
613 // Go through them one by one 613 // Go through them one by one
614 QMap<Interface*, QListViewItem*>::Iterator it; 614 QMap<Interface*, QListViewItem*>::Iterator it;
615 for( it = items.begin(); it != items.end(); ++it ) 615 for( it = items.begin(); it != items.end(); ++it )
616 { 616 {
617 QString interfaceName = it.key()->getInterfaceName(); 617 QString interfaceName = it.key()->getInterfaceName();
618 odebug << interfaceName.latin1() << oendl; 618 odebug << interfaceName.latin1() << oendl;
619 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)) 619 if(interfaces.setInterface(interfaceName + "_" + profileToRemove))
620 { 620 {
621 interfaces.removeInterface(); 621 interfaces.removeInterface();
622 if(interfaces.setMapping(interfaceName)) 622 if(interfaces.setMapping(interfaceName))
623 { 623 {
624 if(profilesList->count() == 1) 624 if(profilesList->count() == 1)
625 interfaces.removeMapping(); 625 interfaces.removeMapping();
626 else 626 else
627 { 627 {
628 interfaces.removeMap("map", interfaceName + "_" + profileToRemove); 628 interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
629 } 629 }
630 } 630 }
631 interfaces.write(); 631 interfaces.write();
632 break; 632 break;
633 } 633 }
634 } 634 }
635 } 635 }
636} 636}
637 637
638/** 638/**
639 * A new profile has been selected, change. 639 * A new profile has been selected, change.
640 * @param newProfile the new profile. 640 * @param newProfile the new profile.
641 */ 641 */
642void MainWindowImp::changeProfile() 642void MainWindowImp::changeProfile()
643{ 643{
644 if(profilesList->currentItem() == -1) 644 if(profilesList->currentItem() == -1)
645 { 645 {
646 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); 646 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
647 return; 647 return;
648 } 648 }
649 QString newProfile = profilesList->text(profilesList->currentItem()); 649 QString newProfile = profilesList->text(profilesList->currentItem());
650 if(newProfile != currentProfileLabel->text()) 650 if(newProfile != currentProfileLabel->text())
651 { 651 {
652 currentProfileLabel->setText(newProfile); 652 currentProfileLabel->setText(newProfile);
653 QFile::remove(scheme); 653 QFile::remove(scheme);
654 QFile file(scheme); 654 QFile file(scheme);
655 if ( file.open(IO_ReadWrite) ) 655 if ( file.open(IO_ReadWrite) )
656 { 656 {
657 QTextStream stream( &file ); 657 QTextStream stream( &file );
658 stream << QString("SCHEME=%1").arg(newProfile); 658 stream << QString("SCHEME=%1").arg(newProfile);
659 file.close(); 659 file.close();
660 } 660 }
661 // restart all up devices? 661 // restart all up devices?
662 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok) 662 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok)
663 { 663 {
664 // Go through them one by one 664 // Go through them one by one
665 QMap<Interface*, QListViewItem*>::Iterator it; 665 QMap<Interface*, QListViewItem*>::Iterator it;
666 for( it = items.begin(); it != items.end(); ++it ) 666 for( it = items.begin(); it != items.end(); ++it )
667 { 667 {
668 if(it.key()->getStatus() == true) 668 if(it.key()->getStatus() == true)
669 it.key()->restart(); 669 it.key()->restart();
670 } 670 }
671 } 671 }
672 } 672 }
673 // TODO change the profile in the modules 673 // TODO change the profile in the modules
674} 674}
675 675
676 676
677void MainWindowImp::makeChannel() 677void MainWindowImp::makeChannel()
678{ 678{
679 channel = new QCopChannel( "QPE/Application/networksettings", this ); 679 channel = new QCopChannel( "QPE/Application/networksettings", this );
680 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), 680 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
681 this, SLOT(receive(const QCString&,const QByteArray&)) ); 681 this, SLOT(receive(const QCString&,const QByteArray&)) );
682} 682}
683 683
684void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) 684void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
685{ 685{
686 bool found = false; 686 bool found = false;
687 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl; 687 odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl;
688 if (msg == "raise") 688 if (msg == "raise")
689 { 689 {
690 raise(); 690 raise();
691 return; 691 return;
692 } 692 }
693 693
694 QString dest = msg.left(msg.find("(")); 694 QString dest = msg.left(msg.find("("));
695 QCString param = msg.right(msg.length() - msg.find("(") - 1); 695 QCString param = msg.right(msg.length() - msg.find("(") - 1);
696 param = param.left( param.length() - 1 ); 696 param = param.left( param.length() - 1 );
697 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl; 697 odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl;
698 698
699 QMap<Module*, QLibrary*>::Iterator it; 699 QMap<Module*, QLibrary*>::Iterator it;
700 for( it = libraries.begin(); it != libraries.end(); ++it ) 700 for( it = libraries.begin(); it != libraries.end(); ++it )
701 { 701 {
702 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl; 702 odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl;
703 if(it.key()->type() == dest) 703 if(it.key()->type() == dest)
704 { 704 {
705 it.key()->receive( param, arg ); 705 it.key()->receive( param, arg );
706 found = true; 706 found = true;
707 } 707 }
708 } 708 }
709 709
710 710
711 if (found) QPEApplication::setKeepRunning(); 711 if (found) QPEApplication::setKeepRunning();
712 else odebug << "Huh what do ya want" << oendl; 712 else odebug << "Huh what do ya want" << oendl;
713} 713}
diff --git a/noncore/settings/sysinfo/benchmarkinfo.cpp b/noncore/settings/sysinfo/benchmarkinfo.cpp
index 793fcb1..060185a 100644
--- a/noncore/settings/sysinfo/benchmarkinfo.cpp
+++ b/noncore/settings/sysinfo/benchmarkinfo.cpp
@@ -1,408 +1,408 @@
1/********************************************************************** 1/**********************************************************************
2** BenchmarkInfo 2** BenchmarkInfo
3** 3**
4** A benchmark widget for Qt/Embedded 4** A benchmark widget for Qt/Embedded
5** 5**
6** Copyright (C) 2004 Michael Lauer <mickey@vanille.de> 6** Copyright (C) 2004 Michael Lauer <mickey@vanille.de>
7** Inspired by ZBench (C) 2002 Satoshi <af230533@im07.alpha-net.ne.jp> 7** Inspired by ZBench (C) 2002 Satoshi <af230533@im07.alpha-net.ne.jp>
8** 8**
9** This file may be distributed and/or modified under the terms of the 9** This file may be distributed and/or modified under the terms of the
10** GNU General Public License version 2 as published by the Free Software 10** GNU General Public License version 2 as published by the Free Software
11** Foundation and appearing in the file LICENSE.GPL included in the 11** Foundation and appearing in the file LICENSE.GPL included in the
12** packaging of this file. 12** packaging of this file.
13** 13**
14** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 14** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
15** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 15** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16** 16**
17**********************************************************************/ 17**********************************************************************/
18 18
19#include "benchmarkinfo.h" 19#include "benchmarkinfo.h"
20 20
21/* OPIE */ 21/* OPIE */
22#include <opie2/odebug.h> 22#include <opie2/odebug.h>
23#include <opie2/ostorageinfo.h> 23#include <opie2/ostorageinfo.h>
24#include <opie2/olistview.h> 24#include <opie2/olistview.h>
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
27#include <qpe/qpedecoration_qws.h> 27#include <qpe/qpedecoration_qws.h>
28#include <qpe/resource.h> 28#include <qpe/resource.h>
29#include <qpe/config.h> 29#include <qpe/config.h>
30using namespace Opie::Core; 30using namespace Opie::Core;
31using namespace Opie::Ui; 31using namespace Opie::Ui;
32 32
33/* QT */ 33/* QT */
34#include <qclipboard.h> 34#include <qclipboard.h>
35#include <qcolor.h> 35#include <qcolor.h>
36#include <qcombobox.h> 36#include <qcombobox.h>
37#include <qdirectpainter_qws.h> 37#include <qdirectpainter_qws.h>
38#include <qfile.h> 38#include <qfile.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40#include <qfiledialog.h> 40#include <qfiledialog.h>
41#include <qlabel.h> 41#include <qlabel.h>
42#include <qlayout.h> 42#include <qlayout.h>
43#include <qpainter.h> 43#include <qpainter.h>
44#include <qpushbutton.h> 44#include <qpushbutton.h>
45#include <qtimer.h> 45#include <qtimer.h>
46#include <qwhatsthis.h> 46#include <qwhatsthis.h>
47 47
48/* STD */ 48/* STD */
49#include <time.h> 49#include <time.h>
50#include <stdio.h> 50#include <stdio.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <math.h> 52#include <math.h>
53#if defined (__GNUC__) && (__GNUC__ < 3) 53#if defined (__GNUC__) && (__GNUC__ < 3)
54#define round qRound 54#define round qRound
55#endif 55#endif
56 56
57extern "C" 57extern "C"
58{ 58{
59 void BenchFFT( void ); 59 void BenchFFT( void );
60 double dhry_main( int ); 60 double dhry_main( int );
61} 61}
62 62
63#define DHRYSTONE_RUNS 20000000 63#define DHRYSTONE_RUNS 20000000
64#define TEST_DURATION 3 64#define TEST_DURATION 3
65 65
66//=========================================================================== 66//===========================================================================
67 67
68class BenchmarkPaintWidget : public QWidget 68class BenchmarkPaintWidget : public QWidget
69{ 69{
70 public: 70 public:
71 BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever ) 71 BenchmarkPaintWidget() : QWidget( 0, "Benchmark Paint Widget", WStyle_Customize|WStyle_StaysOnTop|WPaintUnclipped|WPaintClever )
72 { 72 {
73 resize( QApplication::desktop()->size() ); 73 resize( QApplication::desktop()->size() );
74 show(); 74 show();
75 p.begin( this ); 75 p.begin( this );
76 }; 76 };
77 77
78 ~BenchmarkPaintWidget() 78 ~BenchmarkPaintWidget()
79 { 79 {
80 p.end(); 80 p.end();
81 hide(); 81 hide();
82 }; 82 };
83 83
84 QPainter p; 84 QPainter p;
85}; 85};
86 86
87//=========================================================================== 87//===========================================================================
88 88
89BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags ) 89BenchmarkInfo::BenchmarkInfo( QWidget *parent, const char *name, int wFlags )
90 : QWidget( parent, name, wFlags ) 90 : QWidget( parent, name, wFlags )
91{ 91{
92 92
93 setMinimumSize( 200, 150 ); 93 setMinimumSize( 200, 150 );
94 94
95 QVBoxLayout* vb = new QVBoxLayout( this ); 95 QVBoxLayout* vb = new QVBoxLayout( this );
96 vb->setSpacing( 4 ); 96 vb->setSpacing( 4 );
97 vb->setMargin( 4 ); 97 vb->setMargin( 4 );
98 98
99 tests = new OListView( this ); 99 tests = new OListView( this );
100 QWhatsThis::add( tests->viewport(), tr( "This area shows the available tests, the results for which the tests " 100 QWhatsThis::add( tests->viewport(), tr( "This area shows the available tests, the results for which the tests "
101 "have been performed, and comparison values for one selected device. " 101 "have been performed, and comparison values for one selected device. "
102 "Use the checkboxes to define which tests you want to perform." ) ); 102 "Use the checkboxes to define which tests you want to perform." ) );
103 tests->setMargin( 0 ); 103 tests->setMargin( 0 );
104 tests->addColumn( tr( "Tests" ) ); 104 tests->addColumn( tr( "Tests" ) );
105 tests->addColumn( tr( "Results" ) ); 105 tests->addColumn( tr( "Results" ) );
106 tests->addColumn( tr( "Comparison" ) ); 106 tests->addColumn( tr( "Comparison" ) );
107 tests->setShowSortIndicator( true ); 107 tests->setShowSortIndicator( true );
108 108
109 test_alu = new OCheckListItem( tests, tr( "1. Integer Arithmetic " ), OCheckListItem::CheckBox ); 109 test_alu = new OCheckListItem( tests, tr( "1. Integer Arithmetic " ), OCheckListItem::CheckBox );
110 test_fpu = new OCheckListItem( tests, tr( "2. Floating Point Unit " ), OCheckListItem::CheckBox ); 110 test_fpu = new OCheckListItem( tests, tr( "2. Floating Point Unit " ), OCheckListItem::CheckBox );
111 test_txt = new OCheckListItem( tests, tr( "3. Text Rendering " ), OCheckListItem::CheckBox ); 111 test_txt = new OCheckListItem( tests, tr( "3. Text Rendering " ), OCheckListItem::CheckBox );
112 test_gfx = new OCheckListItem( tests, tr( "4. Gfx Rendering " ), OCheckListItem::CheckBox ); 112 test_gfx = new OCheckListItem( tests, tr( "4. Gfx Rendering " ), OCheckListItem::CheckBox );
113 test_ram = new OCheckListItem( tests, tr( "5. RAM Performance " ), OCheckListItem::CheckBox ); 113 test_ram = new OCheckListItem( tests, tr( "5. RAM Performance " ), OCheckListItem::CheckBox );
114#ifndef QT_QWS_RAMSES 114#ifndef QT_QWS_RAMSES
115 test_sd = new OCheckListItem( tests, tr( "6. SD Card Performance " ), OCheckListItem::CheckBox ); 115 test_sd = new OCheckListItem( tests, tr( "6. SD Card Performance " ), OCheckListItem::CheckBox );
116 test_cf = new OCheckListItem( tests, tr( "7. CF Card Performance " ), OCheckListItem::CheckBox ); 116 test_cf = new OCheckListItem( tests, tr( "7. CF Card Performance " ), OCheckListItem::CheckBox );
117#endif 117#endif
118 test_alu->setText( 1, "n/a" ); 118 test_alu->setText( 1, "n/a" );
119 test_fpu->setText( 1, "n/a" ); 119 test_fpu->setText( 1, "n/a" );
120 test_txt->setText( 1, "n/a" ); 120 test_txt->setText( 1, "n/a" );
121 test_gfx->setText( 1, "n/a" ); 121 test_gfx->setText( 1, "n/a" );
122 test_ram->setText( 1, "n/a" ); 122 test_ram->setText( 1, "n/a" );
123#ifndef QT_QWS_RAMSES 123#ifndef QT_QWS_RAMSES
124 test_sd->setText( 1, "n/a" ); 124 test_sd->setText( 1, "n/a" );
125 test_cf->setText( 1, "n/a" ); 125 test_cf->setText( 1, "n/a" );
126#endif 126#endif
127 test_alu->setText( 2, "n/a" ); 127 test_alu->setText( 2, "n/a" );
128 test_fpu->setText( 2, "n/a" ); 128 test_fpu->setText( 2, "n/a" );
129 test_txt->setText( 2, "n/a" ); 129 test_txt->setText( 2, "n/a" );
130 test_gfx->setText( 2, "n/a" ); 130 test_gfx->setText( 2, "n/a" );
131 test_ram->setText( 2, "n/a" ); 131 test_ram->setText( 2, "n/a" );
132#ifndef QT_QWS_RAMSES 132#ifndef QT_QWS_RAMSES
133 test_sd->setText( 2, "n/a" ); 133 test_sd->setText( 2, "n/a" );
134 test_cf->setText( 2, "n/a" ); 134 test_cf->setText( 2, "n/a" );
135#endif 135#endif
136 136
137 startButton = new QPushButton( tr( "&Start Tests!" ), this ); 137 startButton = new QPushButton( tr( "&Start Tests!" ), this );
138 QWhatsThis::add( startButton, tr( "Click here to perform the selected tests." ) ); 138 QWhatsThis::add( startButton, tr( "Click here to perform the selected tests." ) );
139 connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) ); 139 connect( startButton, SIGNAL( clicked() ), this, SLOT( run() ) );
140 vb->addWidget( tests, 2 ); 140 vb->addWidget( tests, 2 );
141 141
142 QHBoxLayout* hb = new QHBoxLayout( vb ); 142 QHBoxLayout* hb = new QHBoxLayout( vb );
143 hb->addWidget( startButton, 2 ); 143 hb->addWidget( startButton, 2 );
144 144
145 QFile f( QPEApplication::qpeDir() + "/share/sysinfo/results" ); 145 QFile f( QPEApplication::qpeDir() + "share/sysinfo/results" );
146 if ( f.open( IO_ReadOnly ) ) 146 if ( f.open( IO_ReadOnly ) )
147 { 147 {
148 machineCombo = new QComboBox( this ); 148 machineCombo = new QComboBox( this );
149 QWhatsThis::add( machineCombo, tr( "Choose a model to compare your results with." ) ); 149 QWhatsThis::add( machineCombo, tr( "Choose a model to compare your results with." ) );
150 150
151 QTextStream ts( &f ); 151 QTextStream ts( &f );
152 while( !ts.eof() ) 152 while( !ts.eof() )
153 { 153 {
154 QString machline = ts.readLine(); 154 QString machline = ts.readLine();
155 odebug << "sysinfo: parsing benchmark results for '" << machline << "'" << oendl; 155 odebug << "sysinfo: parsing benchmark results for '" << machline << "'" << oendl;
156 QString resline = ts.readLine(); 156 QString resline = ts.readLine();
157 machines.insert( machline, new QStringList( QStringList::split( ",", resline ) ) ); 157 machines.insert( machline, new QStringList( QStringList::split( ",", resline ) ) );
158 machineCombo->insertItem( machline ); 158 machineCombo->insertItem( machline );
159 } 159 }
160 160
161 hb->addWidget( new QLabel( tr( "Compare:" ), this ) ); 161 hb->addWidget( new QLabel( tr( "Compare:" ), this ) );
162 hb->addWidget( machineCombo, 2 ); 162 hb->addWidget( machineCombo, 2 );
163 connect( machineCombo, SIGNAL( activated(int) ), this, SLOT( machineActivated(int) ) ); 163 connect( machineCombo, SIGNAL( activated(int) ), this, SLOT( machineActivated(int) ) );
164 } 164 }
165} 165}
166 166
167 167
168BenchmarkInfo::~BenchmarkInfo() 168BenchmarkInfo::~BenchmarkInfo()
169{} 169{}
170 170
171 171
172void BenchmarkInfo::machineActivated( int index ) 172void BenchmarkInfo::machineActivated( int index )
173{ 173{
174 QStringList* results = machines[ machineCombo->text( index ) ]; 174 QStringList* results = machines[ machineCombo->text( index ) ];
175 if ( !results ) 175 if ( !results )
176 { 176 {
177 odebug << "sysinfo: no results available." << oendl; 177 odebug << "sysinfo: no results available." << oendl;
178 return; 178 return;
179 } 179 }
180 QStringList::Iterator it = results->begin(); 180 QStringList::Iterator it = results->begin();
181 test_alu->setText( 2, *(it++) ); 181 test_alu->setText( 2, *(it++) );
182 test_fpu->setText( 2, *(it++) ); 182 test_fpu->setText( 2, *(it++) );
183 test_txt->setText( 2, *(it++) ); 183 test_txt->setText( 2, *(it++) );
184 test_gfx->setText( 2, *(it++) ); 184 test_gfx->setText( 2, *(it++) );
185 test_ram->setText( 2, *(it++) ); 185 test_ram->setText( 2, *(it++) );
186#ifndef QT_QWS_RAMSES 186#ifndef QT_QWS_RAMSES
187 test_sd->setText( 2, *(it++) ); 187 test_sd->setText( 2, *(it++) );
188 test_cf->setText( 2, *(it++) ); 188 test_cf->setText( 2, *(it++) );
189#endif 189#endif
190} 190}
191 191
192 192
193void BenchmarkInfo::run() 193void BenchmarkInfo::run()
194{ 194{
195 startButton->setText( "> Don't touch! <" ); 195 startButton->setText( "> Don't touch! <" );
196 qApp->processEvents(); 196 qApp->processEvents();
197 QTime t; 197 QTime t;
198 198
199 if ( test_alu->isOn() ) 199 if ( test_alu->isOn() )
200 { 200 {
201 int d = round( dhry_main( DHRYSTONE_RUNS ) ); 201 int d = round( dhry_main( DHRYSTONE_RUNS ) );
202 test_alu->setText( 1, QString().sprintf( "%d dhrys", d ) ); 202 test_alu->setText( 1, QString().sprintf( "%d dhrys", d ) );
203 test_alu->setOn( false ); 203 test_alu->setOn( false );
204 } 204 }
205 205
206 if ( test_fpu->isOn() ) 206 if ( test_fpu->isOn() )
207 { 207 {
208 t.start(); 208 t.start();
209 BenchFFT(); 209 BenchFFT();
210 test_fpu->setText( 1, QString().sprintf( "%.2f secs", t.elapsed() / 1000.0 ) );; 210 test_fpu->setText( 1, QString().sprintf( "%.2f secs", t.elapsed() / 1000.0 ) );;
211 test_fpu->setOn( false ); 211 test_fpu->setOn( false );
212 } 212 }
213 213
214 if ( test_txt->isOn() ) 214 if ( test_txt->isOn() )
215 { 215 {
216 int value = textRendering( TEST_DURATION ); 216 int value = textRendering( TEST_DURATION );
217 test_txt->setText( 1, QString().sprintf( "%d chars/sec", value / TEST_DURATION ) ); 217 test_txt->setText( 1, QString().sprintf( "%d chars/sec", value / TEST_DURATION ) );
218 test_txt->setOn( false ); 218 test_txt->setOn( false );
219 } 219 }
220 220
221 if ( test_gfx->isOn() ) 221 if ( test_gfx->isOn() )
222 { 222 {
223 int value = gfxRendering( TEST_DURATION ); 223 int value = gfxRendering( TEST_DURATION );
224 test_gfx->setText( 1, QString().sprintf( "%.2f gops/sec", value / 4.0 / TEST_DURATION ) ); // 4 tests 224 test_gfx->setText( 1, QString().sprintf( "%.2f gops/sec", value / 4.0 / TEST_DURATION ) ); // 4 tests
225 test_gfx->setOn( false ); 225 test_gfx->setOn( false );
226 } 226 }
227 227
228 if ( test_ram->isOn() ) // /tmp is supposed to be in RAM on a PDA 228 if ( test_ram->isOn() ) // /tmp is supposed to be in RAM on a PDA
229 { 229 {
230 performFileTest( "/tmp/benchmarkFile.dat", test_ram ); 230 performFileTest( "/tmp/benchmarkFile.dat", test_ram );
231 } 231 }
232 232
233#ifndef QT_QWS_RAMSES 233#ifndef QT_QWS_RAMSES
234 if ( test_cf->isOn() ) 234 if ( test_cf->isOn() )
235 { 235 {
236 OStorageInfo storage; 236 OStorageInfo storage;
237 performFileTest( storage.cfPath() + "/benchmarkFile.dat", test_cf ); 237 performFileTest( storage.cfPath() + "/benchmarkFile.dat", test_cf );
238 } 238 }
239 239
240 if ( test_sd->isOn() ) 240 if ( test_sd->isOn() )
241 { 241 {
242 OStorageInfo storage; 242 OStorageInfo storage;
243 performFileTest( storage.sdPath() + "/benchmarkFile.dat", test_sd ); 243 performFileTest( storage.sdPath() + "/benchmarkFile.dat", test_sd );
244 } 244 }
245#endif 245#endif
246 246
247 startButton->setText( tr( "&Start Tests!" ) ); 247 startButton->setText( tr( "&Start Tests!" ) );
248} 248}
249 249
250 250
251int BenchmarkInfo::textRendering( int seconds ) 251int BenchmarkInfo::textRendering( int seconds )
252{ 252{
253 QTime t; 253 QTime t;
254 t.start(); 254 t.start();
255 int stop = t.elapsed() + seconds * 1000; 255 int stop = t.elapsed() + seconds * 1000;
256 256
257 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; 257 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 };
258 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; 258 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 };
259 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; 259 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 };
260 const QString text( "Opie Benchmark Test" ); 260 const QString text( "Opie Benchmark Test" );
261 261
262 int w = QApplication::desktop()->width(); 262 int w = QApplication::desktop()->width();
263 int h = QApplication::desktop()->height(); 263 int h = QApplication::desktop()->height();
264 264
265 srand( time( NULL ) ); 265 srand( time( NULL ) );
266 266
267 BenchmarkPaintWidget bpw; 267 BenchmarkPaintWidget bpw;
268 268
269 int loops = 0; 269 int loops = 0;
270 270
271 while ( t.elapsed() < stop ) 271 while ( t.elapsed() < stop )
272 { 272 {
273 int k = rand() % 9; 273 int k = rand() % 9;
274 int s = rand() % 100; 274 int s = rand() % 100;
275 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 275 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
276 bpw.p.setFont( QFont( "Vera", s ) ); 276 bpw.p.setFont( QFont( "Vera", s ) );
277 bpw.p.drawText( rand() % w, rand() % h, text, text.length() ); 277 bpw.p.drawText( rand() % w, rand() % h, text, text.length() );
278 ++loops; 278 ++loops;
279 } 279 }
280 280
281 return loops * text.length(); 281 return loops * text.length();
282} 282}
283 283
284int BenchmarkInfo::gfxRendering( int seconds ) 284int BenchmarkInfo::gfxRendering( int seconds )
285{ 285{
286 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 }; 286 int rr[] = { 255, 255, 255, 0, 0, 0, 0, 128, 128 };
287 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 }; 287 int gg[] = { 0, 255, 0, 0, 255, 255, 0, 128, 128 };
288 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 }; 288 int bb[] = { 0, 0, 255, 0, 0, 255, 255, 128, 0 };
289 289
290 int w = QApplication::desktop()->width(); 290 int w = QApplication::desktop()->width();
291 int h = QApplication::desktop()->height(); 291 int h = QApplication::desktop()->height();
292 292
293 srand( time( NULL ) ); 293 srand( time( NULL ) );
294 294
295 BenchmarkPaintWidget bpw; 295 BenchmarkPaintWidget bpw;
296 296
297 QTime t; 297 QTime t;
298 t.start(); 298 t.start();
299 int stop = t.elapsed() + seconds*1000; 299 int stop = t.elapsed() + seconds*1000;
300 int loops = 0; 300 int loops = 0;
301 301
302 while ( t.elapsed() < stop ) 302 while ( t.elapsed() < stop )
303 { 303 {
304 int k = rand() % 9; 304 int k = rand() % 9;
305 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 305 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
306 bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h ); 306 bpw.p.drawLine( rand()%w, rand()%h, rand()%w, rand()%h );
307 ++loops; 307 ++loops;
308 } 308 }
309 309
310 t.restart(); 310 t.restart();
311 stop = t.elapsed() + seconds*1000; 311 stop = t.elapsed() + seconds*1000;
312 312
313 while ( t.elapsed() < stop ) 313 while ( t.elapsed() < stop )
314 { 314 {
315 int k = rand() % 9; 315 int k = rand() % 9;
316 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 316 bpw.p.setPen( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
317 bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 ); 317 bpw.p.drawArc( rand()%w, rand()%h, rand()%w, rand()%h, 360 * 16, 360 * 16 );
318 ++loops; 318 ++loops;
319 } 319 }
320 320
321 QBrush br1; 321 QBrush br1;
322 br1.setStyle( SolidPattern ); 322 br1.setStyle( SolidPattern );
323 t.restart(); 323 t.restart();
324 stop = t.elapsed() + seconds*1000; 324 stop = t.elapsed() + seconds*1000;
325 325
326 while ( t.elapsed() < stop ) 326 while ( t.elapsed() < stop )
327 { 327 {
328 int k = rand() % 9; 328 int k = rand() % 9;
329 br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) ); 329 br1.setColor( QColor( rr[ k ], gg[ k ], bb[ k ] ) );
330 bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 ); 330 bpw.p.fillRect( rand()%w, rand()%h, rand()%w, rand()%h, br1 );
331 ++loops; 331 ++loops;
332 } 332 }
333 333
334 QPixmap p = Resource::loadPixmap( "sysinfo/pattern" ); 334 QPixmap p = Resource::loadPixmap( "sysinfo/pattern" );
335 t.restart(); 335 t.restart();
336 stop = t.elapsed() + seconds*1000; 336 stop = t.elapsed() + seconds*1000;
337 337
338 while ( t.elapsed() < stop ) 338 while ( t.elapsed() < stop )
339 { 339 {
340 bpw.p.drawPixmap( rand()%w, rand()%h, p ); 340 bpw.p.drawPixmap( rand()%w, rand()%h, p );
341 ++loops; 341 ++loops;
342 } 342 }
343 343
344 return loops; 344 return loops;
345 345
346} 346}
347 347
348const unsigned int FILE_TEST_COUNT = 8000; 348const unsigned int FILE_TEST_COUNT = 8000;
349const unsigned int FILE_TEST_BLOCKSIZE = 1024; 349const unsigned int FILE_TEST_BLOCKSIZE = 1024;
350 350
351void BenchmarkInfo::performFileTest( const QString& fname, OCheckListItem* item ) 351void BenchmarkInfo::performFileTest( const QString& fname, OCheckListItem* item )
352{ 352{
353 QString filename = fname == "/benchmarkFile.dat" ? QString( "/tmp/bla" ) : fname; 353 QString filename = fname == "/benchmarkFile.dat" ? QString( "/tmp/bla" ) : fname;
354 odebug << "performing file test on " << filename << oendl; 354 odebug << "performing file test on " << filename << oendl;
355 355
356 QString writeCommand = QString( "dd if=/dev/zero of=%1 count=%2 bs=%3 && sync" ).arg( filename ) 356 QString writeCommand = QString( "dd if=/dev/zero of=%1 count=%2 bs=%3 && sync" ).arg( filename )
357 .arg( FILE_TEST_COUNT ) 357 .arg( FILE_TEST_COUNT )
358 .arg( FILE_TEST_BLOCKSIZE ); 358 .arg( FILE_TEST_BLOCKSIZE );
359 QString readCommand = QString( "dd if=%1 of=/dev/null count=%2 bs=%3").arg( filename ) 359 QString readCommand = QString( "dd if=%1 of=/dev/null count=%2 bs=%3").arg( filename )
360 .arg( FILE_TEST_COUNT ) 360 .arg( FILE_TEST_COUNT )
361 .arg( FILE_TEST_BLOCKSIZE ); 361 .arg( FILE_TEST_BLOCKSIZE );
362 ::system( "sync" ); 362 ::system( "sync" );
363 odebug << "performing file test on " << filename << oendl; 363 odebug << "performing file test on " << filename << oendl;
364 364
365 int write = 0; 365 int write = 0;
366 int read = 0; 366 int read = 0;
367 367
368 QTime time; 368 QTime time;
369 time.start(); 369 time.start();
370 if ( ::system( writeCommand ) == 0 ) 370 if ( ::system( writeCommand ) == 0 )
371 { 371 {
372 write = time.elapsed(); 372 write = time.elapsed();
373 } 373 }
374 else 374 else
375 { 375 {
376 item->setText( 1, tr( "error" ) ); 376 item->setText( 1, tr( "error" ) );
377 return; 377 return;
378 } 378 }
379 379
380 time.restart(); 380 time.restart();
381 if ( ::system( readCommand ) == 0 ) 381 if ( ::system( readCommand ) == 0 )
382 { 382 {
383 read = time.elapsed(); 383 read = time.elapsed();
384 } 384 }
385 else 385 else
386 { 386 {
387 item->setText( 1, tr( "error" ) ); 387 item->setText( 1, tr( "error" ) );
388 return; 388 return;
389 } 389 }
390 390
391 QFile::remove( filename ); 391 QFile::remove( filename );
392 double readSpeed = FILE_TEST_COUNT / ( read / 1000.0 ); 392 double readSpeed = FILE_TEST_COUNT / ( read / 1000.0 );
393 QString readUnit = "kB/s"; 393 QString readUnit = "kB/s";
394 if ( readSpeed > 1024 ) 394 if ( readSpeed > 1024 )
395 { 395 {
396 readSpeed /= 1024.0; 396 readSpeed /= 1024.0;
397 readUnit = "MB/s"; 397 readUnit = "MB/s";
398 } 398 }
399 double writeSpeed = FILE_TEST_COUNT / ( write / 1000.0 ); 399 double writeSpeed = FILE_TEST_COUNT / ( write / 1000.0 );
400 QString writeUnit = "kb/s"; 400 QString writeUnit = "kb/s";
401 if ( writeSpeed > 1024 ) 401 if ( writeSpeed > 1024 )
402 { 402 {
403 writeSpeed /= 1024.0; 403 writeSpeed /= 1024.0;
404 writeUnit = "MB/s"; 404 writeUnit = "MB/s";
405 } 405 }
406 item->setText( 1, QString().sprintf( "%.2f %s; %.2f %s", readSpeed, readUnit.latin1(), writeSpeed, writeUnit.latin1() ) ); 406 item->setText( 1, QString().sprintf( "%.2f %s; %.2f %s", readSpeed, readUnit.latin1(), writeSpeed, writeUnit.latin1() ) );
407 item->setOn( false ); 407 item->setOn( false );
408} 408}
diff --git a/noncore/settings/tabmanager/tabmanager.cpp b/noncore/settings/tabmanager/tabmanager.cpp
index 3eae424..85e5814 100644
--- a/noncore/settings/tabmanager/tabmanager.cpp
+++ b/noncore/settings/tabmanager/tabmanager.cpp
@@ -1,510 +1,510 @@
1#include "tabmanager.h" 1#include "tabmanager.h"
2#include "app.h" 2#include "app.h"
3#include "wait.h" 3#include "wait.h"
4#include "tabapplnk.h" 4#include "tabapplnk.h"
5 5
6#include <opie2/odebug.h> 6#include <opie2/odebug.h>
7 7
8#include <qpe/applnk.h> 8#include <qpe/applnk.h>
9#include <qdir.h> 9#include <qdir.h>
10#include <qfile.h> 10#include <qfile.h>
11#include <qtextstream.h> 11#include <qtextstream.h>
12#include <qlistview.h> 12#include <qlistview.h>
13#include <qheader.h> 13#include <qheader.h>
14#include <qcombobox.h> 14#include <qcombobox.h>
15#include <qlineedit.h> 15#include <qlineedit.h>
16#include <qlabel.h> 16#include <qlabel.h>
17#include <qmessagebox.h> 17#include <qmessagebox.h>
18#include <stdlib.h> 18#include <stdlib.h>
19#include <qpe/qcopenvelope_qws.h> 19#include <qpe/qcopenvelope_qws.h>
20#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21#include <qpe/resource.h> 21#include <qpe/resource.h>
22 22
23 23
24#define HOME_APP_DIR QPEApplication::qpeDir()+"/apps" 24#define HOME_APP_DIR QPEApplication::qpeDir()+"apps"
25#define HOME_APP_INSTALL_DIR "/usr/lib/ipkg/info" 25#define HOME_APP_INSTALL_DIR "/usr/lib/ipkg/info"
26#define NEW_FOLDER "EmptyTab" 26#define NEW_FOLDER "EmptyTab"
27#define NEW_APPLICATION "NewApp" 27#define NEW_APPLICATION "NewApp"
28#define APPLICATION_EXTENSION ".desktop" 28#define APPLICATION_EXTENSION ".desktop"
29#define APPLICATION_EXTENSION_LENGTH 8 29#define APPLICATION_EXTENSION_LENGTH 8
30 30
31/** 31/**
32 * Constructor. Sets up signals. Performs initial scan of applications 32 * Constructor. Sets up signals. Performs initial scan of applications
33 * and tabs 33 * and tabs
34 */ 34 */
35TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false), application(NULL){ 35TabManager::TabManager( QWidget* parent, const char* name):TabManagerBase(parent, name), changed(false), application(NULL){
36 rescanFolder(HOME_APP_DIR); 36 rescanFolder(HOME_APP_DIR);
37 37
38 // Connect the signals and slots 38 // Connect the signals and slots
39 connect(tabList, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(editItem(QListViewItem*))); 39 connect(tabList, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(editItem(QListViewItem*)));
40 (tabList->header())->hide(); 40 (tabList->header())->hide();
41 connect(tabList, SIGNAL(moveItem(QListViewItem*,QListViewItem*)), this, SLOT(moveApplication(QListViewItem*,QListViewItem*))); 41 connect(tabList, SIGNAL(moveItem(QListViewItem*,QListViewItem*)), this, SLOT(moveApplication(QListViewItem*,QListViewItem*)));
42} 42}
43 43
44/** 44/**
45 * If anything in the tab's have been changed then update the system or alert 45 * If anything in the tab's have been changed then update the system or alert
46 * the user. 46 * the user.
47 */ 47 */
48TabManager::~TabManager(){ 48TabManager::~TabManager(){
49 if(changed){ 49 if(changed){
50 // Prompt. 50 // Prompt.
51 //int answer = QMessageBox::warning(this, "Message", "Should your desktop be","Yes", "Cancel", 0, 1 ); 51 //int answer = QMessageBox::warning(this, "Message", "Should your desktop be","Yes", "Cancel", 0, 1 );
52 //if (answer) 52 //if (answer)
53 // return; 53 // return;
54 QCopEnvelope e("QPE/System", "linkChanged(QString)"); 54 QCopEnvelope e("QPE/System", "linkChanged(QString)");
55 QString link; //we'll just send an empty string 55 QString link; //we'll just send an empty string
56 e << link; 56 e << link;
57 } 57 }
58} 58}
59 59
60/** 60/**
61 * Scans root directory for any tabs or applications. Will recursivly go down, 61 * Scans root directory for any tabs or applications. Will recursivly go down,
62 * but will not follow symlinks. 62 * but will not follow symlinks.
63 * @param directory - the directory to look in. 63 * @param directory - the directory to look in.
64 * @param parent - the parent to place any new tabs or apps into. If parent is 64 * @param parent - the parent to place any new tabs or apps into. If parent is
65 * NULL then the item is a tab and should be placed as a child of the window. 65 * NULL then the item is a tab and should be placed as a child of the window.
66 */ 66 */
67void TabManager::rescanFolder(QString directory, QListViewItem* parent){ 67void TabManager::rescanFolder(QString directory, QListViewItem* parent){
68 //odebug << QString("rescanFolder: ") + directory.latin1() << oendl; 68 //odebug << QString("rescanFolder: ") + directory.latin1() << oendl;
69 69
70 QDir d; 70 QDir d;
71 d.setPath(directory); 71 d.setPath(directory);
72 // Show hidden files for .directories 72 // Show hidden files for .directories
73 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs); 73 d.setFilter( QDir::Files | QDir::Hidden | QDir::Dirs);
74 74
75 const QFileInfoList *list = d.entryInfoList(); 75 const QFileInfoList *list = d.entryInfoList();
76 QFileInfoListIterator it( *list ); // create list iterator 76 QFileInfoListIterator it( *list ); // create list iterator
77 QFileInfo *fi; // pointer for traversing 77 QFileInfo *fi; // pointer for traversing
78 78
79 while ( (fi=it.current()) ) { // for each file... 79 while ( (fi=it.current()) ) { // for each file...
80 // If it is a dir and not .. or . then add it as a tab and go down. 80 // If it is a dir and not .. or . then add it as a tab and go down.
81 if(fi->isDir()){ 81 if(fi->isDir()){
82 if(fi->fileName() != ".." && fi->fileName() != ".") { 82 if(fi->fileName() != ".." && fi->fileName() != ".") {
83 QListViewItem* newItem; 83 QListViewItem* newItem;
84 if(!parent) 84 if(!parent)
85 newItem = new QListViewItem(tabList, fi->fileName()); 85 newItem = new QListViewItem(tabList, fi->fileName());
86 else 86 else
87 newItem = new QListViewItem(parent, fi->fileName()); 87 newItem = new QListViewItem(parent, fi->fileName());
88 itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" ); 88 itemList.insert(newItem, directory + "/" + fi->fileName() + "/.directory" );
89 rescanFolder(directory + "/" + fi->fileName(), newItem); 89 rescanFolder(directory + "/" + fi->fileName(), newItem);
90 } 90 }
91 } 91 }
92 else{ 92 else{
93 // it is a file, if not a .directory add to parent. 93 // it is a file, if not a .directory add to parent.
94 94
95 // Change parents name and icon to reflect icon. 95 // Change parents name and icon to reflect icon.
96 if(fi->fileName() == ".directory"){ 96 if(fi->fileName() == ".directory"){
97 AppLnk app(directory + "/" + fi->fileName()); 97 AppLnk app(directory + "/" + fi->fileName());
98 if(parent){ 98 if(parent){
99 parent->setPixmap(0,app.pixmap()); 99 parent->setPixmap(0,app.pixmap());
100 parent->setText(0, app.name()); 100 parent->setText(0, app.name());
101 } 101 }
102 } 102 }
103 else{ 103 else{
104 // Add any desktop files found. 104 // Add any desktop files found.
105 QListViewItem* newItem; 105 QListViewItem* newItem;
106 if(directory != HOME_APP_DIR){ 106 if(directory != HOME_APP_DIR){
107 if(!parent) 107 if(!parent)
108 newItem = new QListViewItem(tabList, fi->fileName()); 108 newItem = new QListViewItem(tabList, fi->fileName());
109 else 109 else
110 newItem = new QListViewItem(parent, fi->fileName()); 110 newItem = new QListViewItem(parent, fi->fileName());
111 if(fi->fileName().right(APPLICATION_EXTENSION_LENGTH) == APPLICATION_EXTENSION){ 111 if(fi->fileName().right(APPLICATION_EXTENSION_LENGTH) == APPLICATION_EXTENSION){
112 AppLnk app(directory + "/" + fi->fileName()); 112 AppLnk app(directory + "/" + fi->fileName());
113 newItem->setPixmap(0,app.pixmap()); 113 newItem->setPixmap(0,app.pixmap());
114 newItem->setText(0, app.name()); 114 newItem->setText(0, app.name());
115 itemList.insert(newItem, directory + "/" + fi->fileName()); 115 itemList.insert(newItem, directory + "/" + fi->fileName());
116 } 116 }
117 } 117 }
118 } 118 }
119 } 119 }
120 ++it; // goto next list element 120 ++it; // goto next list element
121 } 121 }
122} 122}
123 123
124/** 124/**
125 * Create a new blank Tab. 125 * Create a new blank Tab.
126 * Create a physical folder with .directory file 126 * Create a physical folder with .directory file
127 * Create a item on the list 127 * Create a item on the list
128 */ 128 */
129void TabManager::newFolder(){ 129void TabManager::newFolder(){
130 QDir r; 130 QDir r;
131 r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER); 131 r.mkdir(QString(HOME_APP_DIR) + "/" + NEW_FOLDER);
132 system((QString("echo [Desktop Entry] | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); 132 system((QString("echo [Desktop Entry] | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1());
133 system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1()); 133 system((QString("echo Name=" NEW_FOLDER " | cat >> ") + HOME_APP_DIR + "/" + NEW_FOLDER "/.directory").latin1());
134 134
135 QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory"; 135 QString homeLocation = QString(HOME_APP_DIR) + "/" + NEW_FOLDER + "/.directory";
136 QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER); 136 QListViewItem *newItem = new QListViewItem(tabList, NEW_FOLDER);
137 itemList.insert(newItem, homeLocation ); 137 itemList.insert(newItem, homeLocation );
138 138
139 // We have changed something. 139 // We have changed something.
140 changed = true; 140 changed = true;
141} 141}
142 142
143/** 143/**
144 * Create a new blank application 144 * Create a new blank application
145 * Make sure a tab is selected 145 * Make sure a tab is selected
146 * create physical file 146 * create physical file
147 * fill file with default information (entry, name, type). 147 * fill file with default information (entry, name, type).
148 */ 148 */
149void TabManager::newApplication(){ 149void TabManager::newApplication(){
150 QListViewItem *item = tabList->currentItem(); 150 QListViewItem *item = tabList->currentItem();
151 if(!item || item->parent()) 151 if(!item || item->parent())
152 return; 152 return;
153 153
154 QString parentDir = itemList[item].mid(0,itemList[item].length()-11); 154 QString parentDir = itemList[item].mid(0,itemList[item].length()-11);
155 QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION; 155 QString homeLocation = parentDir + "/" NEW_APPLICATION APPLICATION_EXTENSION;
156 system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1()); 156 system((QString("echo [Desktop Entry] | cat >> ") + homeLocation).latin1());
157 system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1()); 157 system((QString("echo Name=" NEW_APPLICATION " | cat >> ") + homeLocation).latin1());
158 int slash = parentDir.findRev('/', -1); 158 int slash = parentDir.findRev('/', -1);
159 QString folderName = parentDir.mid(slash+1, parentDir.length()); 159 QString folderName = parentDir.mid(slash+1, parentDir.length());
160 160
161 system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1()); 161 system((QString("echo Type=") + folderName + " | cat >> " + homeLocation).latin1());
162 162
163 // Insert into the tree 163 // Insert into the tree
164 QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION); 164 QListViewItem *newItem = new QListViewItem(item, NEW_APPLICATION);
165 itemList.insert(newItem, homeLocation ); 165 itemList.insert(newItem, homeLocation );
166 166
167 // We have changed something. 167 // We have changed something.
168 changed = true; 168 changed = true;
169} 169}
170 170
171/** 171/**
172 * Remove the item. 172 * Remove the item.
173 * Check if we can 173 * Check if we can
174 * Prompt user 174 * Prompt user
175 * Delete physical file (Dir, remove .dir, then dir. File, remove file) 175 * Delete physical file (Dir, remove .dir, then dir. File, remove file)
176 * Remove from installer if need too. 176 * Remove from installer if need too.
177 */ 177 */
178void TabManager::removeItem(){ 178void TabManager::removeItem(){
179 // Make sure we can delete 179 // Make sure we can delete
180 QListViewItem *item = tabList->currentItem(); 180 QListViewItem *item = tabList->currentItem();
181 if(!item) 181 if(!item)
182 return; 182 return;
183 if(item->childCount() > 0){ 183 if(item->childCount() > 0){
184 QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), tr("Ok") ); 184 QMessageBox::critical(this, tr("Message"), tr("Can't remove with applications\nstill in the group."), tr("Ok") );
185 return; 185 return;
186 } 186 }
187 187
188 // Prompt. 188 // Prompt.
189 int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), tr("Yes"), tr("Cancel"), 0, 1 ); 189 int answer = QMessageBox::warning(this, tr("Message"), tr("Are you sure you want to delete?"), tr("Yes"), tr("Cancel"), 0, 1 );
190 if (answer) 190 if (answer)
191 return; 191 return;
192 192
193 bool removeSuccessful = true; 193 bool removeSuccessful = true;
194 QString location = itemList[item]; 194 QString location = itemList[item];
195 // Remove file (.directory in a Directory case) 195 // Remove file (.directory in a Directory case)
196 if(!QFile::remove(location)) 196 if(!QFile::remove(location))
197 removeSuccessful = false; 197 removeSuccessful = false;
198 198
199 // Remove directory 199 // Remove directory
200 if(item->parent() == NULL){ 200 if(item->parent() == NULL){
201 // Remove .directory file string 201 // Remove .directory file string
202 location = location.mid(0,location.length()-10); 202 location = location.mid(0,location.length()-10);
203 QDir dir; 203 QDir dir;
204 if(!dir.rmdir(location)) 204 if(!dir.rmdir(location))
205 removeSuccessful = false; 205 removeSuccessful = false;
206 else 206 else
207 removeSuccessful = true; 207 removeSuccessful = true;
208 } 208 }
209 209
210 // If removing failed. 210 // If removing failed.
211 if(!removeSuccessful){ 211 if(!removeSuccessful){
212 odebug << (QString("removeItem: ") + location).latin1() << oendl; 212 odebug << (QString("removeItem: ") + location).latin1() << oendl;
213 QMessageBox::critical(this, tr("Message"), tr("Can't remove."), tr("Ok") ); 213 QMessageBox::critical(this, tr("Message"), tr("Can't remove."), tr("Ok") );
214 return; 214 return;
215 } 215 }
216 216
217 // Remove from the installer so it wont fail. 217 // Remove from the installer so it wont fail.
218 // Don't need to do this sense the current install uses rm -f so no error 218 // Don't need to do this sense the current install uses rm -f so no error
219 219
220 // Remove from the gui list. 220 // Remove from the gui list.
221 itemList.remove(item); 221 itemList.remove(item);
222 if(item->parent()) 222 if(item->parent())
223 item->parent()->takeItem(item); 223 item->parent()->takeItem(item);
224 delete item; 224 delete item;
225 225
226 // We have changed something. 226 // We have changed something.
227 changed = true; 227 changed = true;
228} 228}
229 229
230/** 230/**
231 * Helper function. Edits the current item. 231 * Helper function. Edits the current item.
232 * calls editItem with the currently selected item. 232 * calls editItem with the currently selected item.
233 */ 233 */
234void TabManager::editCurrentItem(){ 234void TabManager::editCurrentItem(){
235 editItem(tabList->currentItem()); 235 editItem(tabList->currentItem());
236} 236}
237 237
238/** 238/**
239 * Edit the item that is passed in. 239 * Edit the item that is passed in.
240 * Show application dialog and if anything changed 240 * Show application dialog and if anything changed
241 * @param item the item to edit. 241 * @param item the item to edit.
242 */ 242 */
243void TabManager::editItem( QListViewItem * item){ 243void TabManager::editItem( QListViewItem * item){
244 if(!item) 244 if(!item)
245 return; 245 return;
246 246
247 TabAppLnk app(itemList[item]); 247 TabAppLnk app(itemList[item]);
248 if(!app.isValid()){ 248 if(!app.isValid()){
249 odebug << QString("editItem: Not a valid applnk file: ") + itemList[item].latin1() << oendl; 249 odebug << QString("editItem: Not a valid applnk file: ") + itemList[item].latin1() << oendl;
250 return; 250 return;
251 } 251 }
252 252
253 // Fill with all of the icons 253 // Fill with all of the icons
254 if(!application){ 254 if(!application){
255 Wait waitDialog(this, "Wait dialog"); 255 Wait waitDialog(this, "Wait dialog");
256 waitDialog.waitLabel->setText(tr("Gathering icons...")); 256 waitDialog.waitLabel->setText(tr("Gathering icons..."));
257 waitDialog.show(); 257 waitDialog.show();
258 qApp->processEvents(); 258 qApp->processEvents();
259 application = new AppEdit(this, "Application edit", true); 259 application = new AppEdit(this, "Application edit", true);
260 260
261 QDir d(QPEApplication::qpeDir() + "/pics/"); 261 QDir d(QPEApplication::qpeDir() + "pics/");
262 d.setFilter( QDir::Files); 262 d.setFilter( QDir::Files);
263 263
264 const QFileInfoList *list = d.entryInfoList(); 264 const QFileInfoList *list = d.entryInfoList();
265 QFileInfoListIterator it( *list ); // create list iterator 265 QFileInfoListIterator it( *list ); // create list iterator
266 QFileInfo *fi; // pointer for traversing 266 QFileInfo *fi; // pointer for traversing
267 267
268 while ( (fi=it.current()) ) { // for each file... 268 while ( (fi=it.current()) ) { // for each file...
269 QString fileName = fi->fileName(); 269 QString fileName = fi->fileName();
270 if(fileName.right(4) == ".png"){ 270 if(fileName.right(4) == ".png"){
271 fileName = fileName.mid(0,fileName.length()-4); 271 fileName = fileName.mid(0,fileName.length()-4);
272 QPixmap imageOfFile(Resource::loadPixmap(fileName)); 272 QPixmap imageOfFile(Resource::loadPixmap(fileName));
273 QImage foo = imageOfFile.convertToImage(); 273 QImage foo = imageOfFile.convertToImage();
274 foo = foo.smoothScale(16,16); 274 foo = foo.smoothScale(16,16);
275 imageOfFile.convertFromImage(foo); 275 imageOfFile.convertFromImage(foo);
276 application->iconLineEdit->insertItem(imageOfFile,fileName); 276 application->iconLineEdit->insertItem(imageOfFile,fileName);
277 } 277 }
278 //odebug << fi->fileName().latin1() << oendl; 278 //odebug << fi->fileName().latin1() << oendl;
279 ++it; 279 ++it;
280 } 280 }
281 waitDialog.hide(); 281 waitDialog.hide();
282 } 282 }
283 int pixmap = -1; 283 int pixmap = -1;
284 QString pixmapText = app.pixmapString(); 284 QString pixmapText = app.pixmapString();
285 QComboBox *f = application->iconLineEdit; 285 QComboBox *f = application->iconLineEdit;
286 for(int i = 0; i < application->iconLineEdit->count(); i++){ 286 for(int i = 0; i < application->iconLineEdit->count(); i++){
287 if(f->text(i) == pixmapText){ 287 if(f->text(i) == pixmapText){
288 pixmap = i; 288 pixmap = i;
289 break; 289 break;
290 } 290 }
291 } 291 }
292 if(pixmap != -1) 292 if(pixmap != -1)
293 application->iconLineEdit->setCurrentItem(pixmap); 293 application->iconLineEdit->setCurrentItem(pixmap);
294 else if(pixmapText.isEmpty()){ 294 else if(pixmapText.isEmpty()){
295 application->iconLineEdit->setCurrentItem(0); 295 application->iconLineEdit->setCurrentItem(0);
296 } 296 }
297 else{ 297 else{
298 QPixmap imageOfFile(Resource::loadPixmap(pixmapText)); 298 QPixmap imageOfFile(Resource::loadPixmap(pixmapText));
299 QImage foo = imageOfFile.convertToImage(); 299 QImage foo = imageOfFile.convertToImage();
300 foo = foo.smoothScale(16,16); 300 foo = foo.smoothScale(16,16);
301 imageOfFile.convertFromImage(foo); 301 imageOfFile.convertFromImage(foo);
302 application->iconLineEdit->insertItem(imageOfFile,pixmapText,0); 302 application->iconLineEdit->insertItem(imageOfFile,pixmapText,0);
303 application->iconLineEdit->setCurrentItem(0); 303 application->iconLineEdit->setCurrentItem(0);
304 } 304 }
305 305
306 application->nameLineEdit->setText(app.name()); 306 application->nameLineEdit->setText(app.name());
307 application->execLineEdit->setText(app.exec()); 307 application->execLineEdit->setText(app.exec());
308 application->commentLineEdit->setText(app.comment()); 308 application->commentLineEdit->setText(app.comment());
309 309
310 if(item->parent() == NULL){ 310 if(item->parent() == NULL){
311 application->execLineEdit->setEnabled(false); 311 application->execLineEdit->setEnabled(false);
312 application->TextLabel3->setEnabled(false); 312 application->TextLabel3->setEnabled(false);
313 application->setCaption(tr("Tab")); 313 application->setCaption(tr("Tab"));
314 } 314 }
315 else{ 315 else{
316 application->execLineEdit->setEnabled(true); 316 application->execLineEdit->setEnabled(true);
317 application->TextLabel3->setEnabled(true); 317 application->TextLabel3->setEnabled(true);
318 application->setCaption(tr("Application")); 318 application->setCaption(tr("Application"));
319 } 319 }
320 320
321 // Only do somthing if they hit OK 321 // Only do somthing if they hit OK
322 application->showMaximized(); 322 application->showMaximized();
323 if(application->exec() == 0) 323 if(application->exec() == 0)
324 return; 324 return;
325 325
326 // If nothing has changed exit (hmmm why did they hit ok?) 326 // If nothing has changed exit (hmmm why did they hit ok?)
327 if(app.name() == application->nameLineEdit->text() && 327 if(app.name() == application->nameLineEdit->text() &&
328 app.pixmapString() == application->iconLineEdit->currentText() && 328 app.pixmapString() == application->iconLineEdit->currentText() &&
329 app.comment() == application->commentLineEdit->text() && 329 app.comment() == application->commentLineEdit->text() &&
330 app.exec() == application->execLineEdit->text()) 330 app.exec() == application->execLineEdit->text())
331 return; 331 return;
332 332
333 // Change the applnk file 333 // Change the applnk file
334 QString oldName = app.name(); 334 QString oldName = app.name();
335 app.setName(application->nameLineEdit->text()); 335 app.setName(application->nameLineEdit->text());
336 app.setIcon(application->iconLineEdit->currentText()); 336 app.setIcon(application->iconLineEdit->currentText());
337 app.setComment(application->commentLineEdit->text()); 337 app.setComment(application->commentLineEdit->text());
338 app.setExec(application->execLineEdit->text()); 338 app.setExec(application->execLineEdit->text());
339 if(!app.writeLink()){ 339 if(!app.writeLink()){
340 QMessageBox::critical(this, tr("Message"), "Can't save.", tr("Ok") ); 340 QMessageBox::critical(this, tr("Message"), "Can't save.", tr("Ok") );
341 return; 341 return;
342 } 342 }
343 343
344 // Update the gui icon and name 344 // Update the gui icon and name
345 item->setText(0,app.name()); 345 item->setText(0,app.name());
346 item->setPixmap(0,app.pixmap()); 346 item->setPixmap(0,app.pixmap());
347 347
348 // We have changed something. 348 // We have changed something.
349 changed = true; 349 changed = true;
350 350
351 // If we were dealing with a new folder or new application change 351 // If we were dealing with a new folder or new application change
352 // the file names. Also change the item location in itemList 352 // the file names. Also change the item location in itemList
353 if(oldName == NEW_FOLDER){ 353 if(oldName == NEW_FOLDER){
354 QDir r; 354 QDir r;
355 QString oldName = itemList[item]; 355 QString oldName = itemList[item];
356 oldName = oldName.mid(0,oldName.length()-11); 356 oldName = oldName.mid(0,oldName.length()-11);
357 QString newName = oldName.mid(0,oldName.length()-9); 357 QString newName = oldName.mid(0,oldName.length()-9);
358 newName = newName + "/" + app.name(); 358 newName = newName + "/" + app.name();
359 r.rename(oldName, newName); 359 r.rename(oldName, newName);
360 itemList.remove(item); 360 itemList.remove(item);
361 itemList.insert(item, newName + "/.directory" ); 361 itemList.insert(item, newName + "/.directory" );
362 } 362 }
363 else if(oldName == NEW_APPLICATION){ 363 else if(oldName == NEW_APPLICATION){
364 if(!item->parent()) 364 if(!item->parent())
365 return; 365 return;
366 QString parentDir = itemList[item->parent()]; 366 QString parentDir = itemList[item->parent()];
367 QDir r; 367 QDir r;
368 QString oldName = itemList[item]; 368 QString oldName = itemList[item];
369 QString newName = oldName.mid(0, parentDir.length()-10); 369 QString newName = oldName.mid(0, parentDir.length()-10);
370 newName = newName + app.name() + APPLICATION_EXTENSION; 370 newName = newName + app.name() + APPLICATION_EXTENSION;
371 r.rename(oldName, newName); 371 r.rename(oldName, newName);
372 itemList.remove(item); 372 itemList.remove(item);
373 itemList.insert(item, newName); 373 itemList.insert(item, newName);
374 } 374 }
375} 375}
376 376
377/** 377/**
378 * Move an application from one directory to another. 378 * Move an application from one directory to another.
379 * Move in the gui, move in the applnk file, move in the installer. 379 * Move in the gui, move in the applnk file, move in the installer.
380 * @param item the application to move 380 * @param item the application to move
381 * @pearam newGroup the new parent of this application 381 * @pearam newGroup the new parent of this application
382 */ 382 */
383void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){ 383void TabManager::moveApplication(QListViewItem *item, QListViewItem *newGroup){
384 // Can we even move it? 384 // Can we even move it?
385 if(!item || !item->parent() || newGroup->parent()) 385 if(!item || !item->parent() || newGroup->parent())
386 return; 386 return;
387 if(item->parent() == newGroup) 387 if(item->parent() == newGroup)
388 return; 388 return;
389 389
390 // Get the new folder, new file name, 390 // Get the new folder, new file name,
391 QString newFolder = itemList[newGroup]; 391 QString newFolder = itemList[newGroup];
392 newFolder = newFolder.mid(0,newFolder.length()-11); 392 newFolder = newFolder.mid(0,newFolder.length()-11);
393 int slash = newFolder.findRev('/', -1); 393 int slash = newFolder.findRev('/', -1);
394 QString folderName = newFolder.mid(slash+1, newFolder.length()); 394 QString folderName = newFolder.mid(slash+1, newFolder.length());
395 395
396 QString desktopFile = itemList[item]; 396 QString desktopFile = itemList[item];
397 slash = desktopFile.findRev('/', -1); 397 slash = desktopFile.findRev('/', -1);
398 desktopFile = desktopFile.mid(slash, desktopFile.length()); 398 desktopFile = desktopFile.mid(slash, desktopFile.length());
399 newFolder = newFolder + desktopFile; 399 newFolder = newFolder + desktopFile;
400 400
401 // Move file 401 // Move file
402 QDir r; 402 QDir r;
403 if(!r.rename(itemList[item], newFolder)){ 403 if(!r.rename(itemList[item], newFolder)){
404 QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") ); 404 QMessageBox::critical(this, tr("Message"), "Can't move application.", tr("Ok") );
405 return; 405 return;
406 } 406 }
407 //odebug << (QString("moveApplication: ") + itemList[item]).latin1() << oendl; 407 //odebug << (QString("moveApplication: ") + itemList[item]).latin1() << oendl;
408 //odebug << (QString("moveApplication: ") + newFolder).latin1() << oendl; 408 //odebug << (QString("moveApplication: ") + newFolder).latin1() << oendl;
409 409
410 // Move in the gui 410 // Move in the gui
411 item->parent()->takeItem(item); 411 item->parent()->takeItem(item);
412 newGroup->insertItem(item); 412 newGroup->insertItem(item);
413 newGroup->setOpen(true); 413 newGroup->setOpen(true);
414 414
415 // Move file in the installer 415 // Move file in the installer
416 QString installedAppFile; 416 QString installedAppFile;
417 if(findInstalledApplication(desktopFile, installedAppFile)) 417 if(findInstalledApplication(desktopFile, installedAppFile))
418 swapInstalledLocation(installedAppFile, desktopFile, newFolder); 418 swapInstalledLocation(installedAppFile, desktopFile, newFolder);
419 else 419 else
420 odebug << "moveApplication: No installed app found for dekstop file" << oendl; 420 odebug << "moveApplication: No installed app found for dekstop file" << oendl;
421 421
422 // Move application type 422 // Move application type
423 AppLnk app(newFolder); 423 AppLnk app(newFolder);
424 app.setType(folderName); 424 app.setType(folderName);
425 app.writeLink(); 425 app.writeLink();
426 426
427 // Move in our internal list 427 // Move in our internal list
428 itemList.remove(item); 428 itemList.remove(item);
429 itemList.insert(item, newFolder); 429 itemList.insert(item, newFolder);
430 430
431 // We have changed something. 431 // We have changed something.
432 changed = true; 432 changed = true;
433} 433}
434 434
435/** 435/**
436 * File the installed application that has this desktop file. 436 * File the installed application that has this desktop file.
437 * Go through each file in HOME_APP_INSTALL_DIR and see if it contains desktop 437 * Go through each file in HOME_APP_INSTALL_DIR and see if it contains desktop
438 * file 438 * file
439 * @param desktopFile - the .desktop file to search for [foo.desktop] 439 * @param desktopFile - the .desktop file to search for [foo.desktop]
440 * @param installedAppFile - location of the app install list 440 * @param installedAppFile - location of the app install list
441 * @return true if successful, false if file not found. 441 * @return true if successful, false if file not found.
442 */ 442 */
443bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){ 443bool TabManager::findInstalledApplication(QString desktopFile, QString &installedAppFile){
444 444
445 QDir d; 445 QDir d;
446 d.setPath(HOME_APP_INSTALL_DIR); 446 d.setPath(HOME_APP_INSTALL_DIR);
447 d.setFilter( QDir::Files ); 447 d.setFilter( QDir::Files );
448 448
449 const QFileInfoList *list = d.entryInfoList(); 449 const QFileInfoList *list = d.entryInfoList();
450 QFileInfoListIterator it( *list ); // create list iterator 450 QFileInfoListIterator it( *list ); // create list iterator
451 QFileInfo *fi; // pointer for traversing 451 QFileInfo *fi; // pointer for traversing
452 452
453 while ( (fi=it.current()) ) { // for each file... 453 while ( (fi=it.current()) ) { // for each file...
454 QFile file(QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName()); 454 QFile file(QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName());
455 if ( file.open(IO_ReadOnly) ) { // file opened successfully 455 if ( file.open(IO_ReadOnly) ) { // file opened successfully
456 QTextStream stream( &file ); // use a text stream 456 QTextStream stream( &file ); // use a text stream
457 QString line; 457 QString line;
458 while ( !stream.eof() ) { // until end of file... 458 while ( !stream.eof() ) { // until end of file...
459 line = stream.readLine(); // line of text excluding '\n' 459 line = stream.readLine(); // line of text excluding '\n'
460 if(line.contains(desktopFile)){ 460 if(line.contains(desktopFile)){
461 installedAppFile = QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName(); 461 installedAppFile = QString(HOME_APP_INSTALL_DIR) + "/" + fi->fileName();
462 file.close(); 462 file.close();
463 return true; 463 return true;
464 } 464 }
465 } 465 }
466 file.close(); 466 file.close();
467 } 467 }
468 else 468 else
469 odebug << (QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1() << oendl; 469 odebug << (QString("findInstalledApplication: Can't open file") + HOME_APP_INSTALL_DIR + "/" + fi->fileName()).latin1() << oendl;
470 ++it; // goto next list element 470 ++it; // goto next list element
471 } 471 }
472 return false; 472 return false;
473} 473}
474 474
475/** 475/**
476 * Open a file and replace a file containing the old desktop file with the new. 476 * Open a file and replace a file containing the old desktop file with the new.
477 * @param installedAppFile application installed list 477 * @param installedAppFile application installed list
478 * @param desktopFile old .desktop file 478 * @param desktopFile old .desktop file
479 * @param newLocation new .desktop file 479 * @param newLocation new .desktop file
480 */ 480 */
481void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){ 481void TabManager::swapInstalledLocation( QString installedAppFile, QString desktopFile, QString newLocation ){
482 QFile file(installedAppFile); 482 QFile file(installedAppFile);
483 if ( !file.open(IO_ReadOnly) ){ 483 if ( !file.open(IO_ReadOnly) ){
484 odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl; 484 odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl;
485 return; 485 return;
486 } 486 }
487 487
488 QTextStream stream( &file ); // use a text stream 488 QTextStream stream( &file ); // use a text stream
489 QString allLines; 489 QString allLines;
490 while ( !stream.eof() ) { // until end of file... 490 while ( !stream.eof() ) { // until end of file...
491 QString line = stream.readLine(); // line of text excluding '\n' 491 QString line = stream.readLine(); // line of text excluding '\n'
492 if(line.contains(desktopFile)) 492 if(line.contains(desktopFile))
493 allLines += newLocation; 493 allLines += newLocation;
494 else 494 else
495 allLines += line; 495 allLines += line;
496 allLines += '\n'; 496 allLines += '\n';
497 } 497 }
498 file.close(); 498 file.close();
499 499
500 if ( !file.open(IO_ReadWrite) ){ 500 if ( !file.open(IO_ReadWrite) ){
501 odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl; 501 odebug << QString("swapInstalledLocation: Can't edit file: %1").arg(installedAppFile).latin1() << oendl;
502 return; 502 return;
503 } 503 }
504 QTextStream streamOut( &file ); 504 QTextStream streamOut( &file );
505 streamOut << allLines; 505 streamOut << allLines;
506 file.close(); 506 file.close();
507} 507}
508 508
509// tabmanager.cpp 509// tabmanager.cpp
510 510
diff --git a/noncore/styles/theme/othemebase.cpp b/noncore/styles/theme/othemebase.cpp
index d2226e6..4275dd6 100644
--- a/noncore/styles/theme/othemebase.cpp
+++ b/noncore/styles/theme/othemebase.cpp
@@ -1,1205 +1,1205 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org> 2 Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation. 6 License version 2 as published by the Free Software Foundation.
7 7
8 This library is distributed in the hope that it will be useful, 8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details. 11 Library General Public License for more details.
12 12
13 You should have received a copy of the GNU Library General Public License 13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to 14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA. 16 Boston, MA 02111-1307, USA.
17*/ 17*/
18 18
19#include "othemebase.h" 19#include "othemebase.h"
20#include "ogfxeffect.h" 20#include "ogfxeffect.h"
21 21
22/* OPIE */ 22/* OPIE */
23#include <opie2/odebug.h> 23#include <opie2/odebug.h>
24#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
25#include <qpe/config.h> 25#include <qpe/config.h>
26using namespace Opie::Core; 26using namespace Opie::Core;
27 27
28/* QT */ 28/* QT */
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <qtextstream.h>
31#include <qdir.h> 31#include <qdir.h>
32#include <qpainter.h> 32#include <qpainter.h>
33#include <qbitmap.h> 33#include <qbitmap.h>
34#include <qstringlist.h> 34#include <qstringlist.h>
35 35
36/* STD */ 36/* STD */
37#include <stdlib.h> 37#include <stdlib.h>
38 38
39 39
40template class QIntCache<OThemePixmap> 40template class QIntCache<OThemePixmap>
41; 41;
42 42
43static const char *widgetEntries[] = 43static const char *widgetEntries[] =
44 { // unsunken widgets (see header) 44 { // unsunken widgets (see header)
45 "PushButton", "ComboBox", "HSBarSlider", "VSBarSlider", "Bevel", "ToolButton", 45 "PushButton", "ComboBox", "HSBarSlider", "VSBarSlider", "Bevel", "ToolButton",
46 "ScrollButton", "HScrollDeco", "VScrollDeco", "ComboDeco", "MenuItem", "Tab", 46 "ScrollButton", "HScrollDeco", "VScrollDeco", "ComboDeco", "MenuItem", "Tab",
47 "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", 47 "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight",
48 // sunken widgets 48 // sunken widgets
49 "PushButtonDown", "ComboBoxDown", "HSBarSliderDown", "VSBarSliderDown", 49 "PushButtonDown", "ComboBoxDown", "HSBarSliderDown", "VSBarSliderDown",
50 "BevelDown", "ToolButtonDown", "ScrollButtonDown", "HScrollDecoDown", 50 "BevelDown", "ToolButtonDown", "ScrollButtonDown", "HScrollDecoDown",
51 "VScrollDecoDown", "ComboDecoDown", "MenuItemDown", "TabDown", "SunkenArrowUp", 51 "VScrollDecoDown", "ComboDecoDown", "MenuItemDown", "TabDown", "SunkenArrowUp",
52 "SunkenArrowDown", "SunkenArrowLeft", "SunkenArrowRight", 52 "SunkenArrowDown", "SunkenArrowLeft", "SunkenArrowRight",
53 // everything else 53 // everything else
54 "HScrollGroove", "VScrollGroove", "Slider", "SliderGroove", "CheckBoxDown", 54 "HScrollGroove", "VScrollGroove", "Slider", "SliderGroove", "CheckBoxDown",
55 "CheckBox", "RadioDown", "Radio", "HBarHandle", "VBarHandle", 55 "CheckBox", "RadioDown", "Radio", "HBarHandle", "VBarHandle",
56 "ToolBar", "Splitter", "CheckMark", "MenuBar", "DisableArrowUp", 56 "ToolBar", "Splitter", "CheckMark", "MenuBar", "DisableArrowUp",
57 "DisableArrowDown", "DisableArrowLeft", "DisableArrowRight", "ProgressBar", 57 "DisableArrowDown", "DisableArrowLeft", "DisableArrowRight", "ProgressBar",
58 "ProgressBackground", "MenuBarItem", "Background" 58 "ProgressBackground", "MenuBarItem", "Background"
59 }; 59 };
60 60
61#define INHERIT_ITEMS 16 61#define INHERIT_ITEMS 16
62 62
63 63
64// This is used to encode the keys. I used to use masks but I think this 64// This is used to encode the keys. I used to use masks but I think this
65// bitfield is nicer :) I don't know why C++ coders don't use these more.. 65// bitfield is nicer :) I don't know why C++ coders don't use these more..
66// (mosfet) 66// (mosfet)
67struct kthemeKeyData 67struct kthemeKeyData
68{ 68{
69unsigned int id : 69unsigned int id :
70 6; 70 6;
71unsigned int width : 71unsigned int width :
72 12; 72 12;
73unsigned int height : 73unsigned int height :
74 12; 74 12;
75unsigned int border : 75unsigned int border :
76 1; 76 1;
77unsigned int mask : 77unsigned int mask :
78 1; 78 1;
79}; 79};
80 80
81union kthemeKey{ 81union kthemeKey{
82 kthemeKeyData data; 82 kthemeKeyData data;
83 unsigned int cacheKey; 83 unsigned int cacheKey;
84}; 84};
85 85
86 86
87void OThemeBase::generateBorderPix( int i ) 87void OThemeBase::generateBorderPix( int i )
88{ 88{
89 // separate pixmap into separate components 89 // separate pixmap into separate components
90 if ( pbPixmaps[ i ] ) { 90 if ( pbPixmaps[ i ] ) {
91 // evidently I have to do masks manually... 91 // evidently I have to do masks manually...
92 const QBitmap * srcMask = pbPixmaps[ i ] ->mask(); 92 const QBitmap * srcMask = pbPixmaps[ i ] ->mask();
93 QBitmap destMask( pbWidth[ i ], pbWidth[ i ] ); 93 QBitmap destMask( pbWidth[ i ], pbWidth[ i ] );
94 QPixmap tmp( pbWidth[ i ], pbWidth[ i ] ); 94 QPixmap tmp( pbWidth[ i ], pbWidth[ i ] );
95 95
96 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], 0, 0, pbWidth[ i ], pbWidth[ i ], 96 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], 0, 0, pbWidth[ i ], pbWidth[ i ],
97 Qt::CopyROP, false ); 97 Qt::CopyROP, false );
98 if ( srcMask ) { 98 if ( srcMask ) {
99 bitBlt( &destMask, 0, 0, srcMask, 0, 0, pbWidth[ i ], pbWidth[ i ], 99 bitBlt( &destMask, 0, 0, srcMask, 0, 0, pbWidth[ i ], pbWidth[ i ],
100 Qt::CopyROP, false ); 100 Qt::CopyROP, false );
101 tmp.setMask( destMask ); 101 tmp.setMask( destMask );
102 } 102 }
103 pbPixmaps[ i ] ->setBorder( OThemePixmap::TopLeft, tmp ); 103 pbPixmaps[ i ] ->setBorder( OThemePixmap::TopLeft, tmp );
104 104
105 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ], 0, 105 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ], 0,
106 pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); 106 pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false );
107 if ( srcMask ) { 107 if ( srcMask ) {
108 bitBlt( &destMask, 0, 0, srcMask, pbPixmaps[ i ] ->width() - pbWidth[ i ], 108 bitBlt( &destMask, 0, 0, srcMask, pbPixmaps[ i ] ->width() - pbWidth[ i ],
109 0, pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); 109 0, pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false );
110 tmp.setMask( destMask ); 110 tmp.setMask( destMask );
111 } 111 }
112 pbPixmaps[ i ] ->setBorder( OThemePixmap::TopRight, tmp ); 112 pbPixmaps[ i ] ->setBorder( OThemePixmap::TopRight, tmp );
113 113
114 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], 0, pbPixmaps[ i ] ->height() - pbWidth[ i ], 114 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], 0, pbPixmaps[ i ] ->height() - pbWidth[ i ],
115 pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); 115 pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false );
116 if ( srcMask ) { 116 if ( srcMask ) {
117 bitBlt( &destMask, 0, 0, srcMask, 0, pbPixmaps[ i ] ->height() - pbWidth[ i ], 117 bitBlt( &destMask, 0, 0, srcMask, 0, pbPixmaps[ i ] ->height() - pbWidth[ i ],
118 pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false ); 118 pbWidth[ i ], pbWidth[ i ], Qt::CopyROP, false );
119 tmp.setMask( destMask ); 119 tmp.setMask( destMask );
120 } 120 }
121 pbPixmaps[ i ] ->setBorder( OThemePixmap::BottomLeft, tmp ); 121 pbPixmaps[ i ] ->setBorder( OThemePixmap::BottomLeft, tmp );
122 122
123 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ], 123 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ],
124 pbPixmaps[ i ] ->height() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ], 124 pbPixmaps[ i ] ->height() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ],
125 Qt::CopyROP, false ); 125 Qt::CopyROP, false );
126 if ( srcMask ) { 126 if ( srcMask ) {
127 bitBlt( &destMask, 0, 0, srcMask, pbPixmaps[ i ] ->width() - pbWidth[ i ], 127 bitBlt( &destMask, 0, 0, srcMask, pbPixmaps[ i ] ->width() - pbWidth[ i ],
128 pbPixmaps[ i ] ->height() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ], 128 pbPixmaps[ i ] ->height() - pbWidth[ i ], pbWidth[ i ], pbWidth[ i ],
129 Qt::CopyROP, false ); 129 Qt::CopyROP, false );
130 tmp.setMask( destMask ); 130 tmp.setMask( destMask );
131 } 131 }
132 pbPixmaps[ i ] ->setBorder( OThemePixmap::BottomRight, tmp ); 132 pbPixmaps[ i ] ->setBorder( OThemePixmap::BottomRight, tmp );
133 133
134 tmp.resize( pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ] ); 134 tmp.resize( pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ] );
135 destMask.resize( pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ] ); 135 destMask.resize( pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ] );
136 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbWidth[ i ], 0, 136 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbWidth[ i ], 0,
137 pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], Qt::CopyROP, false ); 137 pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], Qt::CopyROP, false );
138 if ( srcMask ) { 138 if ( srcMask ) {
139 bitBlt( &destMask, 0, 0, srcMask, pbWidth[ i ], 0, 139 bitBlt( &destMask, 0, 0, srcMask, pbWidth[ i ], 0,
140 pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], 140 pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ],
141 Qt::CopyROP, false ); 141 Qt::CopyROP, false );
142 tmp.setMask( destMask ); 142 tmp.setMask( destMask );
143 } 143 }
144 pbPixmaps[ i ] ->setBorder( OThemePixmap::Top, tmp ); 144 pbPixmaps[ i ] ->setBorder( OThemePixmap::Top, tmp );
145 145
146 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbWidth[ i ], 146 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbWidth[ i ],
147 pbPixmaps[ i ] ->height() - pbWidth[ i ], 147 pbPixmaps[ i ] ->height() - pbWidth[ i ],
148 pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], Qt::CopyROP, false ); 148 pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], Qt::CopyROP, false );
149 if ( srcMask ) { 149 if ( srcMask ) {
150 bitBlt( &destMask, 0, 0, srcMask, pbWidth[ i ], 150 bitBlt( &destMask, 0, 0, srcMask, pbWidth[ i ],
151 pbPixmaps[ i ] ->height() - pbWidth[ i ], 151 pbPixmaps[ i ] ->height() - pbWidth[ i ],
152 pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], Qt::CopyROP, false ); 152 pbPixmaps[ i ] ->width() - pbWidth[ i ] * 2, pbWidth[ i ], Qt::CopyROP, false );
153 tmp.setMask( destMask ); 153 tmp.setMask( destMask );
154 } 154 }
155 pbPixmaps[ i ] ->setBorder( OThemePixmap::Bottom, tmp ); 155 pbPixmaps[ i ] ->setBorder( OThemePixmap::Bottom, tmp );
156 156
157 tmp.resize( pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2 ); 157 tmp.resize( pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2 );
158 destMask.resize( pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2 ); 158 destMask.resize( pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2 );
159 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], 0, pbWidth[ i ], pbWidth[ i ], 159 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], 0, pbWidth[ i ], pbWidth[ i ],
160 pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, Qt::CopyROP, false ); 160 pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, Qt::CopyROP, false );
161 if ( srcMask ) { 161 if ( srcMask ) {
162 bitBlt( &destMask, 0, 0, srcMask, 0, pbWidth[ i ], pbWidth[ i ], 162 bitBlt( &destMask, 0, 0, srcMask, 0, pbWidth[ i ], pbWidth[ i ],
163 pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, Qt::CopyROP, false ); 163 pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, Qt::CopyROP, false );
164 tmp.setMask( destMask ); 164 tmp.setMask( destMask );
165 } 165 }
166 166
167 pbPixmaps[ i ] ->setBorder( OThemePixmap::Left, tmp ); 167 pbPixmaps[ i ] ->setBorder( OThemePixmap::Left, tmp );
168 168
169 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ], 169 bitBlt( &tmp, 0, 0, pbPixmaps[ i ], pbPixmaps[ i ] ->width() - pbWidth[ i ],
170 pbWidth[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, 170 pbWidth[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2,
171 Qt::CopyROP, false ); 171 Qt::CopyROP, false );
172 if ( srcMask ) { 172 if ( srcMask ) {
173 bitBlt( &destMask, 0, 0, srcMask, pbPixmaps[ i ] ->width() - pbWidth[ i ], 173 bitBlt( &destMask, 0, 0, srcMask, pbPixmaps[ i ] ->width() - pbWidth[ i ],
174 pbWidth[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2, 174 pbWidth[ i ], pbWidth[ i ], pbPixmaps[ i ] ->height() - pbWidth[ i ] * 2,
175 Qt::CopyROP, false ); 175 Qt::CopyROP, false );
176 tmp.setMask( destMask ); 176 tmp.setMask( destMask );
177 } 177 }
178 pbPixmaps[ i ] ->setBorder( OThemePixmap::Right, tmp ); 178 pbPixmaps[ i ] ->setBorder( OThemePixmap::Right, tmp );
179 } 179 }
180 else 180 else
181 odebug << "OThemeBase: Tried making border from empty pixmap" << oendl; 181 odebug << "OThemeBase: Tried making border from empty pixmap" << oendl;
182} 182}
183 183
184 184
185void OThemeBase::copyWidgetConfig( int sourceID, int destID, QString *pixnames, 185void OThemeBase::copyWidgetConfig( int sourceID, int destID, QString *pixnames,
186 QString *brdnames ) 186 QString *brdnames )
187{ 187{
188 scaleHints[ destID ] = scaleHints[ sourceID ]; 188 scaleHints[ destID ] = scaleHints[ sourceID ];
189 gradients[ destID ] = gradients[ sourceID ]; 189 gradients[ destID ] = gradients[ sourceID ];
190 blends[ destID ] = blends[ sourceID ]; 190 blends[ destID ] = blends[ sourceID ];
191 bContrasts[ destID ] = bContrasts[ sourceID ]; 191 bContrasts[ destID ] = bContrasts[ sourceID ];
192 borders[ destID ] = borders[ sourceID ]; 192 borders[ destID ] = borders[ sourceID ];
193 highlights[ destID ] = highlights[ sourceID ]; 193 highlights[ destID ] = highlights[ sourceID ];
194 194
195 if ( grLowColors[ sourceID ] ) 195 if ( grLowColors[ sourceID ] )
196 grLowColors[ destID ] = new QColor( *grLowColors[ sourceID ] ); 196 grLowColors[ destID ] = new QColor( *grLowColors[ sourceID ] );
197 else 197 else
198 grLowColors[ destID ] = NULL; 198 grLowColors[ destID ] = NULL;
199 199
200 if ( grHighColors[ sourceID ] ) 200 if ( grHighColors[ sourceID ] )
201 grHighColors[ destID ] = new QColor( *grHighColors[ sourceID ] ); 201 grHighColors[ destID ] = new QColor( *grHighColors[ sourceID ] );
202 else 202 else
203 grHighColors[ destID ] = NULL; 203 grHighColors[ destID ] = NULL;
204 204
205 if ( colors[ sourceID ] ) 205 if ( colors[ sourceID ] )
206 colors[ destID ] = new QColorGroup( *colors[ sourceID ] ); 206 colors[ destID ] = new QColorGroup( *colors[ sourceID ] );
207 else 207 else
208 colors[ destID ] = NULL; 208 colors[ destID ] = NULL;
209 209
210 // pixmap 210 // pixmap
211 pixnames[ destID ] = pixnames[ sourceID ]; 211 pixnames[ destID ] = pixnames[ sourceID ];
212 duplicate[ destID ] = false; 212 duplicate[ destID ] = false;
213 pixmaps[ destID ] = NULL; 213 pixmaps[ destID ] = NULL;
214 images[ destID ] = NULL; 214 images[ destID ] = NULL;
215 if ( !pixnames[ destID ].isEmpty() ) { 215 if ( !pixnames[ destID ].isEmpty() ) {
216 if ( scaleHints[ sourceID ] == TileScale && blends[ sourceID ] == 0.0 ) { 216 if ( scaleHints[ sourceID ] == TileScale && blends[ sourceID ] == 0.0 ) {
217 pixmaps[ destID ] = pixmaps[ sourceID ]; 217 pixmaps[ destID ] = pixmaps[ sourceID ];
218 duplicate[ destID ] = true; 218 duplicate[ destID ] = true;
219 } 219 }
220 if ( !duplicate[ destID ] ) { 220 if ( !duplicate[ destID ] ) {
221 pixmaps[ destID ] = loadPixmap( pixnames[ destID ] ); 221 pixmaps[ destID ] = loadPixmap( pixnames[ destID ] );
222 if ( scaleHints[ destID ] == TileScale && blends[ destID ] == 0.0 ) 222 if ( scaleHints[ destID ] == TileScale && blends[ destID ] == 0.0 )
223 images[ destID ] = NULL; 223 images[ destID ] = NULL;
224 else 224 else
225 images[ destID ] = loadImage( pixnames[ destID ] ); 225 images[ destID ] = loadImage( pixnames[ destID ] );
226 } 226 }
227 } 227 }
228 228
229 // border pixmap 229 // border pixmap
230 pbDuplicate[ destID ] = false; 230 pbDuplicate[ destID ] = false;
231 pbPixmaps[ destID ] = NULL; 231 pbPixmaps[ destID ] = NULL;
232 pbWidth[ destID ] = pbWidth[ sourceID ]; 232 pbWidth[ destID ] = pbWidth[ sourceID ];
233 brdnames[ destID ] = brdnames[ sourceID ]; 233 brdnames[ destID ] = brdnames[ sourceID ];
234 if ( !brdnames[ destID ].isEmpty() ) { 234 if ( !brdnames[ destID ].isEmpty() ) {
235 pbPixmaps[ destID ] = pbPixmaps[ sourceID ]; 235 pbPixmaps[ destID ] = pbPixmaps[ sourceID ];
236 pbDuplicate[ destID ] = true; 236 pbDuplicate[ destID ] = true;
237 } 237 }
238 238
239 if ( sourceID == ActiveTab && destID == InactiveTab ) 239 if ( sourceID == ActiveTab && destID == InactiveTab )
240 aTabLine = iTabLine; 240 aTabLine = iTabLine;
241 else if ( sourceID == InactiveTab && destID == ActiveTab ) 241 else if ( sourceID == InactiveTab && destID == ActiveTab )
242 iTabLine = aTabLine; 242 iTabLine = aTabLine;
243} 243}
244 244
245void OThemeBase::readConfig( Qt::GUIStyle /*style*/ ) 245void OThemeBase::readConfig( Qt::GUIStyle /*style*/ )
246{ 246{
247#define PREBLEND_ITEMS 12 247#define PREBLEND_ITEMS 12
248 static WidgetType preBlend[] = {Slider, IndicatorOn, IndicatorOff, 248 static WidgetType preBlend[] = {Slider, IndicatorOn, IndicatorOff,
249 ExIndicatorOn, ExIndicatorOff, HScrollDeco, VScrollDeco, HScrollDecoDown, 249 ExIndicatorOn, ExIndicatorOff, HScrollDeco, VScrollDeco, HScrollDecoDown,
250 VScrollDecoDown, ComboDeco, ComboDecoDown, CheckMark}; 250 VScrollDecoDown, ComboDeco, ComboDecoDown, CheckMark};
251 251
252 int i; 252 int i;
253 QString tmpStr; 253 QString tmpStr;
254 QString copyfrom[ WIDGETS ]; 254 QString copyfrom[ WIDGETS ];
255 QString pixnames[ WIDGETS ]; // used for duplicate check 255 QString pixnames[ WIDGETS ]; // used for duplicate check
256 QString brdnames[ WIDGETS ]; 256 QString brdnames[ WIDGETS ];
257 bool loaded[ WIDGETS ]; // used for preloading for CopyWidget 257 bool loaded[ WIDGETS ]; // used for preloading for CopyWidget
258 258
259 if ( configFileName.isEmpty() ) { 259 if ( configFileName.isEmpty() ) {
260 Config cfg ( "qpe" ); 260 Config cfg ( "qpe" );
261 cfg. setGroup ( "Appearance" ); 261 cfg. setGroup ( "Appearance" );
262 262
263 configFileName = cfg. readEntry ( "Theme", "default" ); 263 configFileName = cfg. readEntry ( "Theme", "default" );
264 } 264 }
265 Config config( configFilePath + "/themes/" + configFileName + ".themerc" , Config::File ); 265 Config config( configFilePath + "/themes/" + configFileName + ".themerc" , Config::File );
266 266
267 // Are we initalized? 267 // Are we initalized?
268 applyMiscResourceGroup( &config ); 268 applyMiscResourceGroup( &config );
269 for ( i = 0; i < INHERIT_ITEMS; ++i ) { 269 for ( i = 0; i < INHERIT_ITEMS; ++i ) {
270 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames ); 270 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames );
271 } 271 }
272 for ( ; i < INHERIT_ITEMS*2; ++i ) { 272 for ( ; i < INHERIT_ITEMS*2; ++i ) {
273 if ( config.hasGroup( QString( widgetEntries[ i ] ) ) ) { 273 if ( config.hasGroup( QString( widgetEntries[ i ] ) ) ) {
274 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames ); 274 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames );
275 } 275 }
276 else { 276 else {
277 copyfrom [ i ] = widgetEntries[ i - INHERIT_ITEMS ]; 277 copyfrom [ i ] = widgetEntries[ i - INHERIT_ITEMS ];
278 } 278 }
279 } 279 }
280 for ( ; i < WIDGETS; ++i ) { 280 for ( ; i < WIDGETS; ++i ) {
281 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames ); 281 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames );
282 } 282 }
283 283
284 // initalize defaults that may not be read 284 // initalize defaults that may not be read
285 for ( i = 0; i < WIDGETS; ++i ) 285 for ( i = 0; i < WIDGETS; ++i )
286 loaded[ i ] = false; 286 loaded[ i ] = false;
287 btnXShift = btnYShift = focus3DOffset = 0; 287 btnXShift = btnYShift = focus3DOffset = 0;
288 aTabLine = iTabLine = true; 288 aTabLine = iTabLine = true;
289 roundedButton = roundedCombo = roundedSlider = focus3D = false; 289 roundedButton = roundedCombo = roundedSlider = focus3D = false;
290 splitterWidth = 10; 290 splitterWidth = 10;
291 291
292 for ( i = 0; i < WIDGETS; ++i ) { 292 for ( i = 0; i < WIDGETS; ++i ) {
293 readResourceGroup( i, copyfrom, pixnames, brdnames, loaded ); 293 readResourceGroup( i, copyfrom, pixnames, brdnames, loaded );
294 } 294 }
295 295
296 // misc items 296 // misc items
297 readMiscResourceGroup(); 297 readMiscResourceGroup();
298 298
299 // Handle preblend items 299 // Handle preblend items
300 for ( i = 0; i < PREBLEND_ITEMS; ++i ) { 300 for ( i = 0; i < PREBLEND_ITEMS; ++i ) {
301 if ( pixmaps[ preBlend[ i ] ] != NULL && blends[ preBlend[ i ] ] != 0.0 ) 301 if ( pixmaps[ preBlend[ i ] ] != NULL && blends[ preBlend[ i ] ] != 0.0 )
302 blend( preBlend[ i ] ); 302 blend( preBlend[ i ] );
303 } 303 }
304} 304}
305 305
306OThemeBase::OThemeBase( const QString & configFile ) 306OThemeBase::OThemeBase( const QString & configFile )
307 : QWindowsStyle() 307 : QWindowsStyle()
308{ 308{
309 configFilePath = QPEApplication::qpeDir ( ) + "/plugins/styles/"; 309 configFilePath = QPEApplication::qpeDir ( ) + "plugins/styles/";
310 configFileName = configFile; 310 configFileName = configFile;
311 311
312 readConfig( Qt::WindowsStyle ); 312 readConfig( Qt::WindowsStyle );
313 cache = new OThemeCache( cacheSize ); 313 cache = new OThemeCache( cacheSize );
314} 314}
315 315
316void OThemeBase::applyConfigFile( const QString &/*file*/ ) 316void OThemeBase::applyConfigFile( const QString &/*file*/ )
317{ 317{
318#if 0 318#if 0
319 // handle std color scheme 319 // handle std color scheme
320 Config inConfig( file, Config::File ); 320 Config inConfig( file, Config::File );
321 Config globalConfig ( "qpe" ); 321 Config globalConfig ( "qpe" );
322 322
323 globalConfig. setGroup ( "Apperance" ); 323 globalConfig. setGroup ( "Apperance" );
324 inConfig. setGroup( "General" ); 324 inConfig. setGroup( "General" );
325 325
326 if ( inConfig.hasKey( "foreground" ) ) 326 if ( inConfig.hasKey( "foreground" ) )
327 globalConfig.writeEntry( "Text", inConfig.readEntry( "foreground", " " ) ); 327 globalConfig.writeEntry( "Text", inConfig.readEntry( "foreground", " " ) );
328 if ( inConfig.hasKey( "background" ) ) 328 if ( inConfig.hasKey( "background" ) )
329 globalConfig.writeEntry( "Background", inConfig.readEntry( "background", " " ) ); 329 globalConfig.writeEntry( "Background", inConfig.readEntry( "background", " " ) );
330 if ( inConfig.hasKey( "selectForeground" ) ) 330 if ( inConfig.hasKey( "selectForeground" ) )
331 globalConfig.writeEntry( "HighlightedText", inConfig.readEntry( "selectForeground", " " ) ); 331 globalConfig.writeEntry( "HighlightedText", inConfig.readEntry( "selectForeground", " " ) );
332 if ( inConfig.hasKey( "selectBackground" ) ) 332 if ( inConfig.hasKey( "selectBackground" ) )
333 globalConfig.writeEntry( "Highlight", inConfig.readEntry( "selectBackground", " " ) ); 333 globalConfig.writeEntry( "Highlight", inConfig.readEntry( "selectBackground", " " ) );
334 if ( inConfig.hasKey( "windowForeground" ) ) 334 if ( inConfig.hasKey( "windowForeground" ) )
335 globalConfig.writeEntry( "Text", inConfig.readEntry( "windowForeground", " " ) ); 335 globalConfig.writeEntry( "Text", inConfig.readEntry( "windowForeground", " " ) );
336 if ( inConfig.hasKey( "windowBackground" ) ) 336 if ( inConfig.hasKey( "windowBackground" ) )
337 globalConfig.writeEntry( "Base", inConfig.readEntry( "windowBackground", " " ) ); 337 globalConfig.writeEntry( "Base", inConfig.readEntry( "windowBackground", " " ) );
338 338
339 // Keep track of the current theme so that we can select the right one 339 // Keep track of the current theme so that we can select the right one
340 // in the KControl module. 340 // in the KControl module.
341 globalConfig.writeEntry ( "CurrentTheme", file ); 341 globalConfig.writeEntry ( "CurrentTheme", file );
342 342
343 globalConfig.write(); 343 globalConfig.write();
344#endif 344#endif
345} 345}
346 346
347OThemeBase::~OThemeBase() 347OThemeBase::~OThemeBase()
348{ 348{
349 int i; 349 int i;
350 for ( i = 0; i < WIDGETS; ++i ) { 350 for ( i = 0; i < WIDGETS; ++i ) {
351 if ( !duplicate[ i ] ) { 351 if ( !duplicate[ i ] ) {
352 if ( images[ i ] ) 352 if ( images[ i ] )
353 delete images[ i ]; 353 delete images[ i ];
354 if ( pixmaps[ i ] ) 354 if ( pixmaps[ i ] )
355 delete pixmaps[ i ]; 355 delete pixmaps[ i ];
356 } 356 }
357 if ( !pbDuplicate[ i ] && pbPixmaps[ i ] ) 357 if ( !pbDuplicate[ i ] && pbPixmaps[ i ] )
358 delete pbPixmaps[ i ]; 358 delete pbPixmaps[ i ];
359 if ( colors[ i ] ) 359 if ( colors[ i ] )
360 delete( colors[ i ] ); 360 delete( colors[ i ] );
361 if ( grLowColors[ i ] ) 361 if ( grLowColors[ i ] )
362 delete( grLowColors[ i ] ); 362 delete( grLowColors[ i ] );
363 if ( grHighColors[ i ] ) 363 if ( grHighColors[ i ] )
364 delete( grHighColors[ i ] ); 364 delete( grHighColors[ i ] );
365 } 365 }
366 delete cache; 366 delete cache;
367} 367}
368 368
369QImage* OThemeBase::loadImage( QString &name ) 369QImage* OThemeBase::loadImage( QString &name )
370{ 370{
371 QImage * image = new QImage; 371 QImage * image = new QImage;
372 QString path = configFilePath + "/pixmaps/" + name; 372 QString path = configFilePath + "/pixmaps/" + name;
373 image->load( path ); 373 image->load( path );
374 if ( !image->isNull() ) 374 if ( !image->isNull() )
375 return ( image ); 375 return ( image );
376 odebug << "OThemeBase: Unable to load image " << name.ascii ( ) << oendl; 376 odebug << "OThemeBase: Unable to load image " << name.ascii ( ) << oendl;
377 delete image; 377 delete image;
378 return ( NULL ); 378 return ( NULL );
379} 379}
380 380
381OThemePixmap* OThemeBase::loadPixmap( QString &name ) 381OThemePixmap* OThemeBase::loadPixmap( QString &name )
382{ 382{
383 OThemePixmap * pixmap = new OThemePixmap( false ); 383 OThemePixmap * pixmap = new OThemePixmap( false );
384 QString path = configFilePath + "/pixmaps/" + name; 384 QString path = configFilePath + "/pixmaps/" + name;
385 pixmap->load( path ); 385 pixmap->load( path );
386 if ( !pixmap->isNull() ) 386 if ( !pixmap->isNull() )
387 return pixmap; 387 return pixmap;
388 odebug << "OThemeBase: Unable to load pixmap " << name.ascii() << oendl; 388 odebug << "OThemeBase: Unable to load pixmap " << name.ascii() << oendl;
389 delete pixmap; 389 delete pixmap;
390 return ( NULL ); 390 return ( NULL );
391} 391}
392 392
393OThemePixmap* OThemeBase::scale( int w, int h, WidgetType widget ) 393OThemePixmap* OThemeBase::scale( int w, int h, WidgetType widget )
394{ 394{
395 if ( scaleHints[ widget ] == FullScale ) { 395 if ( scaleHints[ widget ] == FullScale ) {
396 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w || 396 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ||
397 pixmaps[ widget ] ->height() != h ) { 397 pixmaps[ widget ] ->height() != h ) {
398 OThemePixmap * cachePix = cache->pixmap( w, h, widget ); 398 OThemePixmap * cachePix = cache->pixmap( w, h, widget );
399 if ( cachePix ) { 399 if ( cachePix ) {
400 cachePix = new OThemePixmap( *cachePix ); 400 cachePix = new OThemePixmap( *cachePix );
401 if ( pixmaps[ widget ] ) 401 if ( pixmaps[ widget ] )
402 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, 402 cache->insert( pixmaps[ widget ], OThemeCache::FullScale,
403 widget ); 403 widget );
404 else 404 else
405 odebug << "We would have inserted a null pixmap!\n" << oendl; 405 odebug << "We would have inserted a null pixmap!\n" << oendl;
406 pixmaps[ widget ] = cachePix; 406 pixmaps[ widget ] = cachePix;
407 } 407 }
408 else { 408 else {
409 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); 409 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget );
410 QImage tmpImg = images[ widget ] ->smoothScale( w, h ); 410 QImage tmpImg = images[ widget ] ->smoothScale( w, h );
411 pixmaps[ widget ] = new OThemePixmap; 411 pixmaps[ widget ] = new OThemePixmap;
412 pixmaps[ widget ] ->convertFromImage( tmpImg ); 412 pixmaps[ widget ] ->convertFromImage( tmpImg );
413 if ( blends[ widget ] != 0.0 ) 413 if ( blends[ widget ] != 0.0 )
414 blend( widget ); 414 blend( widget );
415 } 415 }
416 } 416 }
417 } 417 }
418 else if ( scaleHints[ widget ] == HorizontalScale ) { 418 else if ( scaleHints[ widget ] == HorizontalScale ) {
419 if ( pixmaps[ widget ] ->width() != w ) { 419 if ( pixmaps[ widget ] ->width() != w ) {
420 OThemePixmap * cachePix = cache->horizontalPixmap( w, widget ); 420 OThemePixmap * cachePix = cache->horizontalPixmap( w, widget );
421 if ( cachePix ) { 421 if ( cachePix ) {
422 cachePix = new OThemePixmap( *cachePix ); 422 cachePix = new OThemePixmap( *cachePix );
423 if ( pixmaps[ widget ] ) 423 if ( pixmaps[ widget ] )
424 cache->insert( pixmaps[ widget ], OThemeCache::HorizontalScale, widget ); 424 cache->insert( pixmaps[ widget ], OThemeCache::HorizontalScale, widget );
425 else 425 else
426 odebug << "We would have inserted a null pixmap!" << oendl; 426 odebug << "We would have inserted a null pixmap!" << oendl;
427 pixmaps[ widget ] = cachePix; 427 pixmaps[ widget ] = cachePix;
428 } 428 }
429 else { 429 else {
430 cache->insert( pixmaps[ widget ], OThemeCache::HorizontalScale, widget ); 430 cache->insert( pixmaps[ widget ], OThemeCache::HorizontalScale, widget );
431 QImage tmpImg = images[ widget ] -> 431 QImage tmpImg = images[ widget ] ->
432 smoothScale( w, images[ widget ] ->height() ); 432 smoothScale( w, images[ widget ] ->height() );
433 pixmaps[ widget ] = new OThemePixmap; 433 pixmaps[ widget ] = new OThemePixmap;
434 pixmaps[ widget ] ->convertFromImage( tmpImg ); 434 pixmaps[ widget ] ->convertFromImage( tmpImg );
435 if ( blends[ widget ] != 0.0 ) 435 if ( blends[ widget ] != 0.0 )
436 blend( widget ); 436 blend( widget );
437 } 437 }
438 } 438 }
439 } 439 }
440 else if ( scaleHints[ widget ] == VerticalScale ) { 440 else if ( scaleHints[ widget ] == VerticalScale ) {
441 if ( pixmaps[ widget ] ->height() != h ) { 441 if ( pixmaps[ widget ] ->height() != h ) {
442 OThemePixmap * cachePix = cache->verticalPixmap( w, widget ); 442 OThemePixmap * cachePix = cache->verticalPixmap( w, widget );
443 if ( cachePix ) { 443 if ( cachePix ) {
444 cachePix = new OThemePixmap( *cachePix ); 444 cachePix = new OThemePixmap( *cachePix );
445 if ( pixmaps[ widget ] ) 445 if ( pixmaps[ widget ] )
446 cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale, widget ); 446 cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale, widget );
447 else 447 else
448 odebug << "We would have inserted a null pixmap!" << oendl; 448 odebug << "We would have inserted a null pixmap!" << oendl;
449 pixmaps[ widget ] = cachePix; 449 pixmaps[ widget ] = cachePix;
450 } 450 }
451 else { 451 else {
452 cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale, widget ); 452 cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale, widget );
453 QImage tmpImg = 453 QImage tmpImg =
454 images[ widget ] ->smoothScale( images[ widget ] ->width(), h ); 454 images[ widget ] ->smoothScale( images[ widget ] ->width(), h );
455 pixmaps[ widget ] = new OThemePixmap; 455 pixmaps[ widget ] = new OThemePixmap;
456 pixmaps[ widget ] ->convertFromImage( tmpImg ); 456 pixmaps[ widget ] ->convertFromImage( tmpImg );
457 if ( blends[ widget ] != 0.0 ) 457 if ( blends[ widget ] != 0.0 )
458 blend( widget ); 458 blend( widget );
459 } 459 }
460 } 460 }
461 } 461 }
462 // If blended tile here so the blend is scaled properly 462 // If blended tile here so the blend is scaled properly
463 else if ( scaleHints[ widget ] == TileScale && blends[ widget ] != 0.0 ) { 463 else if ( scaleHints[ widget ] == TileScale && blends[ widget ] != 0.0 ) {
464 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w || 464 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ||
465 pixmaps[ widget ] ->height() != h ) { 465 pixmaps[ widget ] ->height() != h ) {
466 OThemePixmap * cachePix = cache->pixmap( w, h, widget ); 466 OThemePixmap * cachePix = cache->pixmap( w, h, widget );
467 if ( cachePix ) { 467 if ( cachePix ) {
468 cachePix = new OThemePixmap( *cachePix ); 468 cachePix = new OThemePixmap( *cachePix );
469 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); 469 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget );
470 pixmaps[ widget ] = cachePix; 470 pixmaps[ widget ] = cachePix;
471 } 471 }
472 else { 472 else {
473 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); 473 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget );
474 QPixmap tile; 474 QPixmap tile;
475 tile.convertFromImage( *images[ widget ] ); 475 tile.convertFromImage( *images[ widget ] );
476 pixmaps[ widget ] = new OThemePixmap; 476 pixmaps[ widget ] = new OThemePixmap;
477 pixmaps[ widget ] ->resize( w, h ); 477 pixmaps[ widget ] ->resize( w, h );
478 QPainter p( pixmaps[ widget ] ); 478 QPainter p( pixmaps[ widget ] );
479 p.drawTiledPixmap( 0, 0, w, h, tile ); 479 p.drawTiledPixmap( 0, 0, w, h, tile );
480 if ( blends[ widget ] != 0.0 ) 480 if ( blends[ widget ] != 0.0 )
481 blend( widget ); 481 blend( widget );
482 } 482 }
483 } 483 }
484 } 484 }
485 return ( pixmaps[ widget ] ); 485 return ( pixmaps[ widget ] );
486} 486}
487 487
488OThemePixmap* OThemeBase::scaleBorder( int w, int h, WidgetType widget ) 488OThemePixmap* OThemeBase::scaleBorder( int w, int h, WidgetType widget )
489{ 489{
490 OThemePixmap * pixmap = NULL; 490 OThemePixmap * pixmap = NULL;
491 if ( !pbPixmaps[ widget ] && !pbWidth[ widget ] ) 491 if ( !pbPixmaps[ widget ] && !pbWidth[ widget ] )
492 return ( NULL ); 492 return ( NULL );
493 pixmap = cache->pixmap( w, h, widget, true ); 493 pixmap = cache->pixmap( w, h, widget, true );
494 if ( pixmap ) { 494 if ( pixmap ) {
495 pixmap = new OThemePixmap( *pixmap ); 495 pixmap = new OThemePixmap( *pixmap );
496 } 496 }
497 else { 497 else {
498 pixmap = new OThemePixmap(); 498 pixmap = new OThemePixmap();
499 pixmap->resize( w, h ); 499 pixmap->resize( w, h );
500 QBitmap mask; 500 QBitmap mask;
501 mask.resize( w, h ); 501 mask.resize( w, h );
502 mask.fill( color0 ); 502 mask.fill( color0 );
503 QPainter mPainter; 503 QPainter mPainter;
504 mPainter.begin( &mask ); 504 mPainter.begin( &mask );
505 505
506 QPixmap *tmp = borderPixmap( widget ) ->border( OThemePixmap::TopLeft ); 506 QPixmap *tmp = borderPixmap( widget ) ->border( OThemePixmap::TopLeft );
507 const QBitmap *srcMask = tmp->mask(); 507 const QBitmap *srcMask = tmp->mask();
508 int bdWidth = tmp->width(); 508 int bdWidth = tmp->width();
509 509
510 bitBlt( pixmap, 0, 0, tmp, 0, 0, bdWidth, bdWidth, 510 bitBlt( pixmap, 0, 0, tmp, 0, 0, bdWidth, bdWidth,
511 Qt::CopyROP, false ); 511 Qt::CopyROP, false );
512 if ( srcMask ) 512 if ( srcMask )
513 bitBlt( &mask, 0, 0, srcMask, 0, 0, bdWidth, bdWidth, 513 bitBlt( &mask, 0, 0, srcMask, 0, 0, bdWidth, bdWidth,
514 Qt::CopyROP, false ); 514 Qt::CopyROP, false );
515 else 515 else
516 mPainter.fillRect( 0, 0, bdWidth, bdWidth, color1 ); 516 mPainter.fillRect( 0, 0, bdWidth, bdWidth, color1 );
517 517
518 518
519 tmp = borderPixmap( widget ) ->border( OThemePixmap::TopRight ); 519 tmp = borderPixmap( widget ) ->border( OThemePixmap::TopRight );
520 srcMask = tmp->mask(); 520 srcMask = tmp->mask();
521 bitBlt( pixmap, w - bdWidth, 0, tmp, 0, 0, bdWidth, 521 bitBlt( pixmap, w - bdWidth, 0, tmp, 0, 0, bdWidth,
522 bdWidth, Qt::CopyROP, false ); 522 bdWidth, Qt::CopyROP, false );
523 if ( srcMask ) 523 if ( srcMask )
524 bitBlt( &mask, w - bdWidth, 0, srcMask, 0, 0, bdWidth, 524 bitBlt( &mask, w - bdWidth, 0, srcMask, 0, 0, bdWidth,
525 bdWidth, Qt::CopyROP, false ); 525 bdWidth, Qt::CopyROP, false );
526 else 526 else
527 mPainter.fillRect( w - bdWidth, 0, bdWidth, bdWidth, color1 ); 527 mPainter.fillRect( w - bdWidth, 0, bdWidth, bdWidth, color1 );
528 528
529 tmp = borderPixmap( widget ) ->border( OThemePixmap::BottomLeft ); 529 tmp = borderPixmap( widget ) ->border( OThemePixmap::BottomLeft );
530 srcMask = tmp->mask(); 530 srcMask = tmp->mask();
531 bitBlt( pixmap, 0, h - bdWidth, tmp, 0, 0, bdWidth, 531 bitBlt( pixmap, 0, h - bdWidth, tmp, 0, 0, bdWidth,
532 bdWidth, Qt::CopyROP, false ); 532 bdWidth, Qt::CopyROP, false );
533 if ( srcMask ) 533 if ( srcMask )
534 bitBlt( &mask, 0, h - bdWidth, srcMask, 0, 0, bdWidth, 534 bitBlt( &mask, 0, h - bdWidth, srcMask, 0, 0, bdWidth,
535 bdWidth, Qt::CopyROP, false ); 535 bdWidth, Qt::CopyROP, false );
536 else 536 else
537 mPainter.fillRect( 0, h - bdWidth, bdWidth, bdWidth, color1 ); 537 mPainter.fillRect( 0, h - bdWidth, bdWidth, bdWidth, color1 );
538 538
539 tmp = borderPixmap( widget ) ->border( OThemePixmap::BottomRight ); 539 tmp = borderPixmap( widget ) ->border( OThemePixmap::BottomRight );
540 srcMask = tmp->mask(); 540 srcMask = tmp->mask();
541 bitBlt( pixmap, w - bdWidth, h - bdWidth, tmp, 0, 0, 541 bitBlt( pixmap, w - bdWidth, h - bdWidth, tmp, 0, 0,
542 bdWidth, bdWidth, Qt::CopyROP, false ); 542 bdWidth, bdWidth, Qt::CopyROP, false );
543 if ( srcMask ) 543 if ( srcMask )
544 bitBlt( &mask, w - bdWidth, h - bdWidth, srcMask, 0, 0, 544 bitBlt( &mask, w - bdWidth, h - bdWidth, srcMask, 0, 0,
545 bdWidth, bdWidth, Qt::CopyROP, false ); 545 bdWidth, bdWidth, Qt::CopyROP, false );
546 else 546 else
547 mPainter.fillRect( w - bdWidth, h - bdWidth, bdWidth, bdWidth, color1 ); 547 mPainter.fillRect( w - bdWidth, h - bdWidth, bdWidth, bdWidth, color1 );
548 548
549 QPainter p; 549 QPainter p;
550 p.begin( pixmap ); 550 p.begin( pixmap );
551 if ( w - bdWidth * 2 > 0 ) { 551 if ( w - bdWidth * 2 > 0 ) {
552 tmp = borderPixmap( widget ) ->border( OThemePixmap::Top ); 552 tmp = borderPixmap( widget ) ->border( OThemePixmap::Top );
553 srcMask = tmp->mask(); 553 srcMask = tmp->mask();
554 p.drawTiledPixmap( bdWidth, 0, w - bdWidth * 2, bdWidth, *tmp ); 554 p.drawTiledPixmap( bdWidth, 0, w - bdWidth * 2, bdWidth, *tmp );
555 if ( srcMask ) 555 if ( srcMask )
556 mPainter.drawTiledPixmap( bdWidth, 0, w - bdWidth * 2, bdWidth, *srcMask ); 556 mPainter.drawTiledPixmap( bdWidth, 0, w - bdWidth * 2, bdWidth, *srcMask );
557 else 557 else
558 mPainter.fillRect( bdWidth, 0, w - bdWidth * 2, bdWidth, color1 ); 558 mPainter.fillRect( bdWidth, 0, w - bdWidth * 2, bdWidth, color1 );
559 559
560 tmp = borderPixmap( widget ) ->border( OThemePixmap::Bottom ); 560 tmp = borderPixmap( widget ) ->border( OThemePixmap::Bottom );
561 srcMask = tmp->mask(); 561 srcMask = tmp->mask();
562 p.drawTiledPixmap( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth, 562 p.drawTiledPixmap( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth,
563 *tmp ); 563 *tmp );
564 if ( srcMask ) 564 if ( srcMask )
565 mPainter.drawTiledPixmap( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth, *srcMask ); 565 mPainter.drawTiledPixmap( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth, *srcMask );
566 else 566 else
567 mPainter.fillRect( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth, 567 mPainter.fillRect( bdWidth, h - bdWidth, w - bdWidth * 2, bdWidth,
568 color1 ); 568 color1 );
569 } 569 }
570 if ( h - bdWidth * 2 > 0 ) { 570 if ( h - bdWidth * 2 > 0 ) {
571 tmp = borderPixmap( widget ) ->border( OThemePixmap::Left ); 571 tmp = borderPixmap( widget ) ->border( OThemePixmap::Left );
572 srcMask = tmp->mask(); 572 srcMask = tmp->mask();
573 p.drawTiledPixmap( 0, bdWidth, bdWidth, h - bdWidth * 2, *tmp ); 573 p.drawTiledPixmap( 0, bdWidth, bdWidth, h - bdWidth * 2, *tmp );
574 if ( srcMask ) 574 if ( srcMask )
575 mPainter.drawTiledPixmap( 0, bdWidth, bdWidth, h - bdWidth * 2, *srcMask ); 575 mPainter.drawTiledPixmap( 0, bdWidth, bdWidth, h - bdWidth * 2, *srcMask );
576 else 576 else
577 mPainter.fillRect( 0, bdWidth, bdWidth, h - bdWidth * 2, color1 ); 577 mPainter.fillRect( 0, bdWidth, bdWidth, h - bdWidth * 2, color1 );
578 578
579 tmp = borderPixmap( widget ) ->border( OThemePixmap::Right ); 579 tmp = borderPixmap( widget ) ->border( OThemePixmap::Right );
580 srcMask = tmp->mask(); 580 srcMask = tmp->mask();
581 p.drawTiledPixmap( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2, 581 p.drawTiledPixmap( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2,
582 *tmp ); 582 *tmp );
583 if ( srcMask ) 583 if ( srcMask )
584 mPainter.drawTiledPixmap( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2, *srcMask ); 584 mPainter.drawTiledPixmap( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2, *srcMask );
585 else 585 else
586 mPainter.fillRect( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2, color1 ); 586 mPainter.fillRect( w - bdWidth, bdWidth, bdWidth, h - bdWidth * 2, color1 );
587 } 587 }
588 p.end(); 588 p.end();
589 mPainter.end(); 589 mPainter.end();
590 pixmap->setMask( mask ); 590 pixmap->setMask( mask );
591 cache->insert( pixmap, OThemeCache::FullScale, widget, true ); 591 cache->insert( pixmap, OThemeCache::FullScale, widget, true );
592 if ( !pixmap->mask() ) 592 if ( !pixmap->mask() )
593 odebug << "No mask for border pixmap!" << oendl; 593 odebug << "No mask for border pixmap!" << oendl;
594 } 594 }
595 return ( pixmap ); 595 return ( pixmap );
596} 596}
597 597
598 598
599OThemePixmap* OThemeBase::blend( WidgetType widget ) 599OThemePixmap* OThemeBase::blend( WidgetType widget )
600{ 600{
601 OGfxEffect::GradientType g; 601 OGfxEffect::GradientType g;
602 switch ( gradients[ widget ] ) { 602 switch ( gradients[ widget ] ) {
603 case GrHorizontal: 603 case GrHorizontal:
604 g = OGfxEffect::HorizontalGradient; 604 g = OGfxEffect::HorizontalGradient;
605 break; 605 break;
606 case GrVertical: 606 case GrVertical:
607 g = OGfxEffect::VerticalGradient; 607 g = OGfxEffect::VerticalGradient;
608 break; 608 break;
609 case GrPyramid: 609 case GrPyramid:
610 g = OGfxEffect::PyramidGradient; 610 g = OGfxEffect::PyramidGradient;
611 break; 611 break;
612 case GrRectangle: 612 case GrRectangle:
613 g = OGfxEffect::RectangleGradient; 613 g = OGfxEffect::RectangleGradient;
614 break; 614 break;
615 case GrElliptic: 615 case GrElliptic:
616 g = OGfxEffect::EllipticGradient; 616 g = OGfxEffect::EllipticGradient;
617 break; 617 break;
618 default: 618 default:
619 g = OGfxEffect::DiagonalGradient; 619 g = OGfxEffect::DiagonalGradient;
620 break; 620 break;
621 } 621 }
622 OGfxEffect::blend( *pixmaps[ widget ], blends[ widget ], *grLowColors[ widget ], 622 OGfxEffect::blend( *pixmaps[ widget ], blends[ widget ], *grLowColors[ widget ],
623 g, false ); 623 g, false );
624 return ( pixmaps[ widget ] ); 624 return ( pixmaps[ widget ] );
625} 625}
626 626
627OThemePixmap* OThemeBase::gradient( int w, int h, WidgetType widget ) 627OThemePixmap* OThemeBase::gradient( int w, int h, WidgetType widget )
628{ 628{
629 if ( gradients[ widget ] == GrVertical ) { 629 if ( gradients[ widget ] == GrVertical ) {
630 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->height() != h ) { 630 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->height() != h ) {
631 OThemePixmap * cachePix = cache->verticalPixmap( h, widget ); 631 OThemePixmap * cachePix = cache->verticalPixmap( h, widget );
632 if ( cachePix ) { 632 if ( cachePix ) {
633 cachePix = new OThemePixmap( *cachePix ); 633 cachePix = new OThemePixmap( *cachePix );
634 if ( pixmaps[ widget ] ) 634 if ( pixmaps[ widget ] )
635 cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale, 635 cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale,
636 widget ); 636 widget );
637 pixmaps[ widget ] = cachePix; 637 pixmaps[ widget ] = cachePix;
638 } 638 }
639 else { 639 else {
640 if ( pixmaps[ widget ] ) 640 if ( pixmaps[ widget ] )
641 cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale, 641 cache->insert( pixmaps[ widget ], OThemeCache::VerticalScale,
642 widget ); 642 widget );
643 pixmaps[ widget ] = new OThemePixmap; 643 pixmaps[ widget ] = new OThemePixmap;
644 pixmaps[ widget ] ->resize( w, h ); 644 pixmaps[ widget ] ->resize( w, h );
645 OGfxEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ], 645 OGfxEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ],
646 *grLowColors[ widget ], 646 *grLowColors[ widget ],
647 OGfxEffect::VerticalGradient ); 647 OGfxEffect::VerticalGradient );
648 } 648 }
649 } 649 }
650 } 650 }
651 else if ( gradients[ widget ] == GrHorizontal ) { 651 else if ( gradients[ widget ] == GrHorizontal ) {
652 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ) { 652 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ) {
653 OThemePixmap * cachePix = cache->horizontalPixmap( w, widget ); 653 OThemePixmap * cachePix = cache->horizontalPixmap( w, widget );
654 if ( cachePix ) { 654 if ( cachePix ) {
655 cachePix = new OThemePixmap( *cachePix ); 655 cachePix = new OThemePixmap( *cachePix );
656 if ( pixmaps[ widget ] ) 656 if ( pixmaps[ widget ] )
657 cache->insert( pixmaps[ widget ], 657 cache->insert( pixmaps[ widget ],
658 OThemeCache::HorizontalScale, widget ); 658 OThemeCache::HorizontalScale, widget );
659 pixmaps[ widget ] = cachePix; 659 pixmaps[ widget ] = cachePix;
660 } 660 }
661 else { 661 else {
662 if ( pixmaps[ widget ] ) 662 if ( pixmaps[ widget ] )
663 cache->insert( pixmaps[ widget ], 663 cache->insert( pixmaps[ widget ],
664 OThemeCache::HorizontalScale, widget ); 664 OThemeCache::HorizontalScale, widget );
665 pixmaps[ widget ] = new OThemePixmap; 665 pixmaps[ widget ] = new OThemePixmap;
666 pixmaps[ widget ] ->resize( w, h ); 666 pixmaps[ widget ] ->resize( w, h );
667 OGfxEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ], 667 OGfxEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ],
668 *grLowColors[ widget ], 668 *grLowColors[ widget ],
669 OGfxEffect::HorizontalGradient ); 669 OGfxEffect::HorizontalGradient );
670 } 670 }
671 } 671 }
672 } 672 }
673 else if ( gradients[ widget ] == GrReverseBevel ) { 673 else if ( gradients[ widget ] == GrReverseBevel ) {
674 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w || 674 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ||
675 pixmaps[ widget ] ->height() != h ) { 675 pixmaps[ widget ] ->height() != h ) {
676 OThemePixmap * cachePix = cache->pixmap( w, h, widget ); 676 OThemePixmap * cachePix = cache->pixmap( w, h, widget );
677 if ( cachePix ) { 677 if ( cachePix ) {
678 cachePix = new OThemePixmap( *cachePix ); 678 cachePix = new OThemePixmap( *cachePix );
679 if ( pixmaps[ widget ] ) 679 if ( pixmaps[ widget ] )
680 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, 680 cache->insert( pixmaps[ widget ], OThemeCache::FullScale,
681 widget ); 681 widget );
682 pixmaps[ widget ] = cachePix; 682 pixmaps[ widget ] = cachePix;
683 } 683 }
684 else { 684 else {
685 if ( pixmaps[ widget ] ) 685 if ( pixmaps[ widget ] )
686 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, 686 cache->insert( pixmaps[ widget ], OThemeCache::FullScale,
687 widget ); 687 widget );
688 pixmaps[ widget ] = new OThemePixmap; 688 pixmaps[ widget ] = new OThemePixmap;
689 pixmaps[ widget ] ->resize( w, h ); 689 pixmaps[ widget ] ->resize( w, h );
690 690
691 QPixmap s; 691 QPixmap s;
692 int offset = decoWidth( widget ); 692 int offset = decoWidth( widget );
693 s.resize( w - offset * 2, h - offset * 2 ); 693 s.resize( w - offset * 2, h - offset * 2 );
694 QColor lc( *grLowColors[ widget ] ); 694 QColor lc( *grLowColors[ widget ] );
695 QColor hc( *grHighColors[ widget ] ); 695 QColor hc( *grHighColors[ widget ] );
696 if ( bevelContrast( widget ) ) { 696 if ( bevelContrast( widget ) ) {
697 int bc = bevelContrast( widget ); 697 int bc = bevelContrast( widget );
698 // want single increments, not factors like light()/dark() 698 // want single increments, not factors like light()/dark()
699 lc.setRgb( lc.red() - bc, lc.green() - bc, lc.blue() - bc ); 699 lc.setRgb( lc.red() - bc, lc.green() - bc, lc.blue() - bc );
700 hc.setRgb( hc.red() + bc, hc.green() + bc, hc.blue() + bc ); 700 hc.setRgb( hc.red() + bc, hc.green() + bc, hc.blue() + bc );
701 } 701 }
702 OGfxEffect::gradient( *pixmaps[ widget ], 702 OGfxEffect::gradient( *pixmaps[ widget ],
703 lc, hc, 703 lc, hc,
704 OGfxEffect::DiagonalGradient ); 704 OGfxEffect::DiagonalGradient );
705 OGfxEffect::gradient( s, *grHighColors[ widget ], 705 OGfxEffect::gradient( s, *grHighColors[ widget ],
706 *grLowColors[ widget ], 706 *grLowColors[ widget ],
707 OGfxEffect::DiagonalGradient ); 707 OGfxEffect::DiagonalGradient );
708 bitBlt( pixmaps[ widget ], offset, offset, &s, 0, 0, w - offset * 2, 708 bitBlt( pixmaps[ widget ], offset, offset, &s, 0, 0, w - offset * 2,
709 h - offset * 2, Qt::CopyROP ); 709 h - offset * 2, Qt::CopyROP );
710 } 710 }
711 } 711 }
712 } 712 }
713 else { 713 else {
714 OGfxEffect::GradientType g; 714 OGfxEffect::GradientType g;
715 switch ( gradients[ widget ] ) { 715 switch ( gradients[ widget ] ) {
716 case GrPyramid: 716 case GrPyramid:
717 g = OGfxEffect::PyramidGradient; 717 g = OGfxEffect::PyramidGradient;
718 break; 718 break;
719 case GrRectangle: 719 case GrRectangle:
720 g = OGfxEffect::RectangleGradient; 720 g = OGfxEffect::RectangleGradient;
721 break; 721 break;
722 case GrElliptic: 722 case GrElliptic:
723 g = OGfxEffect::EllipticGradient; 723 g = OGfxEffect::EllipticGradient;
724 break; 724 break;
725 default: 725 default:
726 g = OGfxEffect::DiagonalGradient; 726 g = OGfxEffect::DiagonalGradient;
727 break; 727 break;
728 } 728 }
729 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w || 729 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ||
730 pixmaps[ widget ] ->height() != h ) { 730 pixmaps[ widget ] ->height() != h ) {
731 OThemePixmap * cachePix = cache->pixmap( w, h, widget ); 731 OThemePixmap * cachePix = cache->pixmap( w, h, widget );
732 if ( cachePix ) { 732 if ( cachePix ) {
733 cachePix = new OThemePixmap( *cachePix ); 733 cachePix = new OThemePixmap( *cachePix );
734 if ( pixmaps[ widget ] ) 734 if ( pixmaps[ widget ] )
735 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, 735 cache->insert( pixmaps[ widget ], OThemeCache::FullScale,
736 widget ); 736 widget );
737 pixmaps[ widget ] = cachePix; 737 pixmaps[ widget ] = cachePix;
738 } 738 }
739 else { 739 else {
740 if ( pixmaps[ widget ] ) 740 if ( pixmaps[ widget ] )
741 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, 741 cache->insert( pixmaps[ widget ], OThemeCache::FullScale,
742 widget ); 742 widget );
743 pixmaps[ widget ] = new OThemePixmap; 743 pixmaps[ widget ] = new OThemePixmap;
744 pixmaps[ widget ] ->resize( w, h ); 744 pixmaps[ widget ] ->resize( w, h );
745 OGfxEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ], 745 OGfxEffect::gradient( *pixmaps[ widget ], *grHighColors[ widget ],
746 *grLowColors[ widget ], g ); 746 *grLowColors[ widget ], g );
747 } 747 }
748 } 748 }
749 } 749 }
750 return ( pixmaps[ widget ] ); 750 return ( pixmaps[ widget ] );
751} 751}
752 752
753OThemePixmap* OThemeBase::scalePixmap( int w, int h, WidgetType widget ) 753OThemePixmap* OThemeBase::scalePixmap( int w, int h, WidgetType widget )
754{ 754{
755 755
756 if ( gradients[ widget ] && blends[ widget ] == 0.0 ) 756 if ( gradients[ widget ] && blends[ widget ] == 0.0 )
757 return ( gradient( w, h, widget ) ); 757 return ( gradient( w, h, widget ) );
758 758
759 return ( scale( w, h, widget ) ); 759 return ( scale( w, h, widget ) );
760} 760}
761 761
762QColorGroup* OThemeBase::makeColorGroup( QColor &fg, QColor &bg, 762QColorGroup* OThemeBase::makeColorGroup( QColor &fg, QColor &bg,
763 Qt::GUIStyle ) 763 Qt::GUIStyle )
764{ 764{
765 if ( shading == Motif ) { 765 if ( shading == Motif ) {
766 int highlightVal, lowlightVal; 766 int highlightVal, lowlightVal;
767 highlightVal = 100 + ( 2* /*KGlobalSettings::contrast()*/ 3 + 4 ) * 16 / 10; 767 highlightVal = 100 + ( 2* /*KGlobalSettings::contrast()*/ 3 + 4 ) * 16 / 10;
768 lowlightVal = 100 + ( ( 2* /*KGlobalSettings::contrast()*/ 3 + 4 ) * 10 ); 768 lowlightVal = 100 + ( ( 2* /*KGlobalSettings::contrast()*/ 3 + 4 ) * 10 );
769 return ( new QColorGroup( fg, bg, bg.light( highlightVal ), 769 return ( new QColorGroup( fg, bg, bg.light( highlightVal ),
770 bg.dark( lowlightVal ), bg.dark( 120 ), 770 bg.dark( lowlightVal ), bg.dark( 120 ),
771 fg, qApp->palette().normal().base() ) ); 771 fg, qApp->palette().normal().base() ) );
772 } 772 }
773 else 773 else
774 return ( new QColorGroup( fg, bg, bg.light( 150 ), bg.dark(), 774 return ( new QColorGroup( fg, bg, bg.light( 150 ), bg.dark(),
775 bg.dark( 120 ), fg, 775 bg.dark( 120 ), fg,
776 qApp->palette().normal().base() ) ); 776 qApp->palette().normal().base() ) );
777} 777}
778 778
779static QColor strToColor ( const QString &str ) 779static QColor strToColor ( const QString &str )
780{ 780{
781 QString str2 = str. stripWhiteSpace ( ); 781 QString str2 = str. stripWhiteSpace ( );
782 782
783 if ( str2 [0] == '#' ) 783 if ( str2 [0] == '#' )
784 return QColor ( str2 ); 784 return QColor ( str2 );
785 else { 785 else {
786 QStringList sl = QStringList::split ( ',', str2 ); 786 QStringList sl = QStringList::split ( ',', str2 );
787 787
788 if ( sl. count ( ) >= 3 ) 788 if ( sl. count ( ) >= 3 )
789 return QColor ( sl [0]. toInt ( ), sl [1]. toInt ( ), sl [2]. toInt ( )); 789 return QColor ( sl [0]. toInt ( ), sl [1]. toInt ( ), sl [2]. toInt ( ));
790 } 790 }
791 return QColor ( 0, 0, 0 ); 791 return QColor ( 0, 0, 0 );
792} 792}
793 793
794 794
795 795
796void OThemeBase::applyMiscResourceGroup( Config *config ) 796void OThemeBase::applyMiscResourceGroup( Config *config )
797{ 797{
798 config-> setGroup ( "Misc" ); 798 config-> setGroup ( "Misc" );
799 QString tmpStr; 799 QString tmpStr;
800 800
801 tmpStr = config->readEntry( "SButtonPosition" ); 801 tmpStr = config->readEntry( "SButtonPosition" );
802 if ( tmpStr == "BottomLeft" ) 802 if ( tmpStr == "BottomLeft" )
803 sbPlacement = SBBottomLeft; 803 sbPlacement = SBBottomLeft;
804 else if ( tmpStr == "BottomRight" ) 804 else if ( tmpStr == "BottomRight" )
805 sbPlacement = SBBottomRight; 805 sbPlacement = SBBottomRight;
806 else { 806 else {
807 if ( tmpStr != "Opposite" && !tmpStr.isEmpty() ) 807 if ( tmpStr != "Opposite" && !tmpStr.isEmpty() )
808 odebug << "OThemeBase: Unrecognized sb button option " << tmpStr.ascii() 808 odebug << "OThemeBase: Unrecognized sb button option " << tmpStr.ascii()
809 << ", using Opposite." << oendl; 809 << ", using Opposite." << oendl;
810 sbPlacement = SBOpposite; 810 sbPlacement = SBOpposite;
811 } 811 }
812 tmpStr = config->readEntry( "ArrowType" ); 812 tmpStr = config->readEntry( "ArrowType" );
813 if ( tmpStr == "Small" ) 813 if ( tmpStr == "Small" )
814 arrowStyle = SmallArrow; 814 arrowStyle = SmallArrow;
815 else if ( tmpStr == "3D" ) 815 else if ( tmpStr == "3D" )
816 arrowStyle = MotifArrow; 816 arrowStyle = MotifArrow;
817 else { 817 else {
818 if ( tmpStr != "Normal" && !tmpStr.isEmpty() ) 818 if ( tmpStr != "Normal" && !tmpStr.isEmpty() )
819 odebug << "OThemeBase: Unrecognized arrow option " << tmpStr.ascii() 819 odebug << "OThemeBase: Unrecognized arrow option " << tmpStr.ascii()
820 << ", using Normal." << oendl; 820 << ", using Normal." << oendl;
821 arrowStyle = LargeArrow; 821 arrowStyle = LargeArrow;
822 } 822 }
823 tmpStr = config->readEntry( "ShadeStyle" ); 823 tmpStr = config->readEntry( "ShadeStyle" );
824 if ( tmpStr == "Motif" ) 824 if ( tmpStr == "Motif" )
825 shading = Motif; 825 shading = Motif;
826 else if ( tmpStr == "Next" ) 826 else if ( tmpStr == "Next" )
827 shading = Next; 827 shading = Next;
828 else if ( tmpStr == "KDE" ) 828 else if ( tmpStr == "KDE" )
829 shading = KDE; 829 shading = KDE;
830 else 830 else
831 shading = Windows; 831 shading = Windows;
832 832
833 defaultFrame = config->readNumEntry( "FrameWidth", 2 ); 833 defaultFrame = config->readNumEntry( "FrameWidth", 2 );
834 cacheSize = config->readNumEntry( "Cache", 1024 ); 834 cacheSize = config->readNumEntry( "Cache", 1024 );
835 sbExtent = config->readNumEntry( "ScrollBarExtent", 16 ); 835 sbExtent = config->readNumEntry( "ScrollBarExtent", 16 );
836 836
837 config-> setGroup ( "General" ); 837 config-> setGroup ( "General" );
838 838
839 if ( config-> hasKey ( "foreground" )) fgcolor = strToColor ( config-> readEntry ( "foreground" )); 839 if ( config-> hasKey ( "foreground" )) fgcolor = strToColor ( config-> readEntry ( "foreground" ));
840 if ( config-> hasKey ( "background" )) bgcolor = strToColor ( config-> readEntry ( "background" )); 840 if ( config-> hasKey ( "background" )) bgcolor = strToColor ( config-> readEntry ( "background" ));
841 if ( config-> hasKey ( "selectForeground" )) selfgcolor = strToColor ( config-> readEntry ( "selectForeground" )); 841 if ( config-> hasKey ( "selectForeground" )) selfgcolor = strToColor ( config-> readEntry ( "selectForeground" ));
842 if ( config-> hasKey ( "selectBackground" )) selbgcolor = strToColor ( config-> readEntry ( "selectBackground" )); 842 if ( config-> hasKey ( "selectBackground" )) selbgcolor = strToColor ( config-> readEntry ( "selectBackground" ));
843 if ( config-> hasKey ( "windowForeground" )) winfgcolor = strToColor ( config-> readEntry ( "windowForeground" )); 843 if ( config-> hasKey ( "windowForeground" )) winfgcolor = strToColor ( config-> readEntry ( "windowForeground" ));
844 if ( config-> hasKey ( "windowBackground" )) winbgcolor = strToColor ( config-> readEntry ( "windowBackground" )); 844 if ( config-> hasKey ( "windowBackground" )) winbgcolor = strToColor ( config-> readEntry ( "windowBackground" ));
845} 845}
846 846
847void OThemeBase::readMiscResourceGroup() 847void OThemeBase::readMiscResourceGroup()
848{} 848{}
849 849
850void OThemeBase::applyResourceGroup( Config *config, int i, QString *copyfrom, QString *pixnames, QString *brdnames ) 850void OThemeBase::applyResourceGroup( Config *config, int i, QString *copyfrom, QString *pixnames, QString *brdnames )
851{ 851{
852 QString tmpStr; 852 QString tmpStr;
853 853
854 config-> setGroup ( widgetEntries [ i ] ); 854 config-> setGroup ( widgetEntries [ i ] );
855 855
856 tmpStr = config->readEntry( "CopyWidget", "" ); 856 tmpStr = config->readEntry( "CopyWidget", "" );
857 copyfrom [ i ] = tmpStr; 857 copyfrom [ i ] = tmpStr;
858 if ( !tmpStr.isEmpty() ) 858 if ( !tmpStr.isEmpty() )
859 return ; 859 return ;
860 860
861 // Scale hint 861 // Scale hint
862 tmpStr = config->readEntry( "Scale" ); 862 tmpStr = config->readEntry( "Scale" );
863 if ( tmpStr == "Full" ) 863 if ( tmpStr == "Full" )
864 scaleHints [ i ] = FullScale; 864 scaleHints [ i ] = FullScale;
865 else if ( tmpStr == "Horizontal" ) 865 else if ( tmpStr == "Horizontal" )
866 scaleHints [ i ] = HorizontalScale; 866 scaleHints [ i ] = HorizontalScale;
867 else if ( tmpStr == "Vertical" ) 867 else if ( tmpStr == "Vertical" )
868 scaleHints [ i ] = VerticalScale; 868 scaleHints [ i ] = VerticalScale;
869 else { 869 else {
870 if ( tmpStr != "Tile" && !tmpStr.isEmpty() ) 870 if ( tmpStr != "Tile" && !tmpStr.isEmpty() )
871 odebug << "OThemeBase: Unrecognized scale option " << tmpStr.ascii() 871 odebug << "OThemeBase: Unrecognized scale option " << tmpStr.ascii()
872 << ", using Tile." << oendl; 872 << ", using Tile." << oendl;
873 scaleHints [ i ] = TileScale; 873 scaleHints [ i ] = TileScale;
874 } 874 }
875 875
876 876
877 // Gradient type 877 // Gradient type
878 tmpStr = config->readEntry( "Gradient" ); 878 tmpStr = config->readEntry( "Gradient" );
879 if ( tmpStr == "Diagonal" ) 879 if ( tmpStr == "Diagonal" )
880 gradients [ i ] = GrDiagonal; 880 gradients [ i ] = GrDiagonal;
881 else if ( tmpStr == "Horizontal" ) 881 else if ( tmpStr == "Horizontal" )
882 gradients [ i ] = GrHorizontal; 882 gradients [ i ] = GrHorizontal;
883 else if ( tmpStr == "Vertical" ) 883 else if ( tmpStr == "Vertical" )
884 gradients [ i ] = GrVertical; 884 gradients [ i ] = GrVertical;
885 else if ( tmpStr == "Pyramid" ) 885 else if ( tmpStr == "Pyramid" )
886 gradients [ i ] = GrPyramid; 886 gradients [ i ] = GrPyramid;
887 else if ( tmpStr == "Rectangle" ) 887 else if ( tmpStr == "Rectangle" )
888 gradients [ i ] = GrRectangle; 888 gradients [ i ] = GrRectangle;
889 else if ( tmpStr == "Elliptic" ) 889 else if ( tmpStr == "Elliptic" )
890 gradients [ i ] = GrElliptic; 890 gradients [ i ] = GrElliptic;
891 else if ( tmpStr == "ReverseBevel" ) 891 else if ( tmpStr == "ReverseBevel" )
892 gradients [ i ] = GrReverseBevel; 892 gradients [ i ] = GrReverseBevel;
893 else { 893 else {
894 if ( tmpStr != "None" && !tmpStr.isEmpty() ) 894 if ( tmpStr != "None" && !tmpStr.isEmpty() )
895 odebug << "OThemeBase: Unrecognized gradient option " << tmpStr.ascii() 895 odebug << "OThemeBase: Unrecognized gradient option " << tmpStr.ascii()
896 << ", using None." << oendl; 896 << ", using None." << oendl;
897 gradients [ i ] = GrNone; 897 gradients [ i ] = GrNone;
898 } 898 }
899 899
900 // Blend intensity 900 // Blend intensity
901 blends[ i ] = config->readEntry( "BlendIntensity", "0.0" ).toDouble(); 901 blends[ i ] = config->readEntry( "BlendIntensity", "0.0" ).toDouble();
902 902
903 // Bevel contrast 903 // Bevel contrast
904 bContrasts[ i ] = config->readNumEntry( "BevelContrast", 0 ); 904 bContrasts[ i ] = config->readNumEntry( "BevelContrast", 0 );
905 905
906 // Border width 906 // Border width
907 borders [ i ] = config->readNumEntry( "Border", 1 ); 907 borders [ i ] = config->readNumEntry( "Border", 1 );
908 908
909 // Highlight width 909 // Highlight width
910 highlights [ i ] = config->readNumEntry( "Highlight", 1 ); 910 highlights [ i ] = config->readNumEntry( "Highlight", 1 );
911 911
912 // Gradient low color or blend background 912 // Gradient low color or blend background
913 if ( config->hasKey( "GradientLow" ) && ( gradients[ i ] != GrNone || blends[ i ] != 0.0 )) 913 if ( config->hasKey( "GradientLow" ) && ( gradients[ i ] != GrNone || blends[ i ] != 0.0 ))
914 grLowColors[ i ] = new QColor( strToColor ( config->readEntry( "GradientLow", qApp->palette().normal().background().name() ))); 914 grLowColors[ i ] = new QColor( strToColor ( config->readEntry( "GradientLow", qApp->palette().normal().background().name() )));
915 else 915 else
916 grLowColors[ i ] = NULL; 916 grLowColors[ i ] = NULL;
917 917
918 918
919 // Gradient high color 919 // Gradient high color
920 if ( config->hasKey( "GradientHigh" ) && ( gradients[ i ] != GrNone )) 920 if ( config->hasKey( "GradientHigh" ) && ( gradients[ i ] != GrNone ))
921 grHighColors[ i ] = new QColor( strToColor ( config->readEntry( "GradientHigh", qApp->palette().normal().background().name() ))); 921 grHighColors[ i ] = new QColor( strToColor ( config->readEntry( "GradientHigh", qApp->palette().normal().background().name() )));
922 else 922 else
923 grHighColors[ i ] = NULL; 923 grHighColors[ i ] = NULL;
924 924
925 // Extended color attributes 925 // Extended color attributes
926 if ( config->hasKey( "Foreground" ) || config->hasKey( "Background" ) ) { 926 if ( config->hasKey( "Foreground" ) || config->hasKey( "Background" ) ) {
927 QColor bg = strToColor( config->readEntry( "Background", qApp->palette().normal().background().name() )); 927 QColor bg = strToColor( config->readEntry( "Background", qApp->palette().normal().background().name() ));
928 QColor fg = strToColor( config->readEntry( "Foreground", qApp->palette().normal().foreground().name() )); 928 QColor fg = strToColor( config->readEntry( "Foreground", qApp->palette().normal().foreground().name() ));
929 929
930 colors[ i ] = makeColorGroup( fg, bg, Qt::WindowsStyle ); 930 colors[ i ] = makeColorGroup( fg, bg, Qt::WindowsStyle );
931 } 931 }
932 else 932 else
933 colors[ i ] = NULL; 933 colors[ i ] = NULL;
934 934
935 // Pixmap 935 // Pixmap
936 tmpStr = config->readEntry( "Pixmap", "" ); 936 tmpStr = config->readEntry( "Pixmap", "" );
937 pixnames[ i ] = tmpStr; 937 pixnames[ i ] = tmpStr;
938 duplicate[ i ] = false; 938 duplicate[ i ] = false;
939 pixmaps[ i ] = NULL; 939 pixmaps[ i ] = NULL;
940 images[ i ] = NULL; 940 images[ i ] = NULL;
941 941
942 942
943 // Pixmap border 943 // Pixmap border
944 tmpStr = config->readEntry( "PixmapBorder", "" ); 944 tmpStr = config->readEntry( "PixmapBorder", "" );
945 brdnames[ i ] = tmpStr; 945 brdnames[ i ] = tmpStr;
946 pbDuplicate[ i ] = false; 946 pbDuplicate[ i ] = false;
947 pbPixmaps[ i ] = NULL; 947 pbPixmaps[ i ] = NULL;
948 pbWidth[ i ] = 0; 948 pbWidth[ i ] = 0;
949 if ( !tmpStr.isEmpty() ) { 949 if ( !tmpStr.isEmpty() ) {
950 pbWidth[ i ] = config->readNumEntry( "PixmapBWidth", 0 ); 950 pbWidth[ i ] = config->readNumEntry( "PixmapBWidth", 0 );
951 if ( pbWidth[ i ] == 0 ) { 951 if ( pbWidth[ i ] == 0 ) {
952 odebug << "OThemeBase: No border width specified for pixmapped border widget " 952 odebug << "OThemeBase: No border width specified for pixmapped border widget "
953 << widgetEntries[ i ] << oendl; 953 << widgetEntries[ i ] << oendl;
954 odebug << "OThemeBase: Using default of 2." << oendl; 954 odebug << "OThemeBase: Using default of 2." << oendl;
955 pbWidth[ i ] = 2; 955 pbWidth[ i ] = 2;
956 } 956 }
957 } 957 }
958 958
959 959
960 // Various widget specific settings. This was more efficent when bunched 960 // Various widget specific settings. This was more efficent when bunched
961 // together in the misc group, but this makes an easier to read config. 961 // together in the misc group, but this makes an easier to read config.
962 if ( i == SliderGroove ) 962 if ( i == SliderGroove )
963 roundedSlider = config->readBoolEntry( "SmallGroove", false ); 963 roundedSlider = config->readBoolEntry( "SmallGroove", false );
964 else if ( i == ActiveTab ) { 964 else if ( i == ActiveTab ) {
965 aTabLine = config->readBoolEntry( "BottomLine", true ); 965 aTabLine = config->readBoolEntry( "BottomLine", true );
966 } 966 }
967 else if ( i == InactiveTab ) { 967 else if ( i == InactiveTab ) {
968 iTabLine = config->readBoolEntry( "BottomLine", true ); 968 iTabLine = config->readBoolEntry( "BottomLine", true );
969 } 969 }
970 else if ( i == Splitter ) 970 else if ( i == Splitter )
971 splitterWidth = config->readNumEntry( "Width", 10 ); 971 splitterWidth = config->readNumEntry( "Width", 10 );
972 else if ( i == ComboBox || i == ComboBoxDown ) { 972 else if ( i == ComboBox || i == ComboBoxDown ) {
973 roundedCombo = config->readBoolEntry( "Round", false ); 973 roundedCombo = config->readBoolEntry( "Round", false );
974 } 974 }
975 else if ( i == PushButton || i == PushButtonDown ) { 975 else if ( i == PushButton || i == PushButtonDown ) {
976 btnXShift = config->readNumEntry( "XShift", 0 ); 976 btnXShift = config->readNumEntry( "XShift", 0 );
977 btnYShift = config->readNumEntry( "YShift", 0 ); 977 btnYShift = config->readNumEntry( "YShift", 0 );
978 focus3D = config->readBoolEntry( "3DFocusRect", false ); 978 focus3D = config->readBoolEntry( "3DFocusRect", false );
979 focus3DOffset = config->readBoolEntry( "3DFocusOffset", 0 ); 979 focus3DOffset = config->readBoolEntry( "3DFocusOffset", 0 );
980 roundedButton = config->readBoolEntry( "Round", false ); 980 roundedButton = config->readBoolEntry( "Round", false );
981 } 981 }
982} 982}
983 983
984 984
985void OThemeBase::readResourceGroup( int i, QString *copyfrom, QString *pixnames, QString *brdnames, 985void OThemeBase::readResourceGroup( int i, QString *copyfrom, QString *pixnames, QString *brdnames,
986 bool *loadArray ) 986 bool *loadArray )
987{ 987{
988 if ( loadArray[ i ] == true ) { 988 if ( loadArray[ i ] == true ) {
989 return ; // already been preloaded. 989 return ; // already been preloaded.
990 } 990 }
991 991
992 int tmpVal; 992 int tmpVal;
993 QString tmpStr; 993 QString tmpStr;
994 994
995 tmpStr = copyfrom [ i ]; 995 tmpStr = copyfrom [ i ];
996 if ( !tmpStr.isEmpty() ) { // Duplicate another widget's config 996 if ( !tmpStr.isEmpty() ) { // Duplicate another widget's config
997 int sIndex; 997 int sIndex;
998 loadArray[ i ] = true; 998 loadArray[ i ] = true;
999 for ( sIndex = 0; sIndex < WIDGETS; ++sIndex ) { 999 for ( sIndex = 0; sIndex < WIDGETS; ++sIndex ) {
1000 if ( tmpStr == widgetEntries[ sIndex ] ) { 1000 if ( tmpStr == widgetEntries[ sIndex ] ) {
1001 if ( !loadArray[ sIndex ] ) // hasn't been loaded yet 1001 if ( !loadArray[ sIndex ] ) // hasn't been loaded yet
1002 readResourceGroup( sIndex, copyfrom, pixnames, brdnames, 1002 readResourceGroup( sIndex, copyfrom, pixnames, brdnames,
1003 loadArray ); 1003 loadArray );
1004 break; 1004 break;
1005 } 1005 }
1006 } 1006 }
1007 if ( loadArray[ sIndex ] ) { 1007 if ( loadArray[ sIndex ] ) {
1008 copyWidgetConfig( sIndex, i, pixnames, brdnames ); 1008 copyWidgetConfig( sIndex, i, pixnames, brdnames );
1009 } 1009 }
1010 else 1010 else
1011 odebug << "OThemeBase: Unable to identify source widget for " << widgetEntries[ i ] << oendl; 1011 odebug << "OThemeBase: Unable to identify source widget for " << widgetEntries[ i ] << oendl;
1012 return ; 1012 return ;
1013 } 1013 }
1014 // special inheritance for disabled arrows (these are tri-state unlike 1014 // special inheritance for disabled arrows (these are tri-state unlike
1015 // the rest of what we handle). 1015 // the rest of what we handle).
1016 for ( tmpVal = DisArrowUp; tmpVal <= DisArrowRight; ++tmpVal ) { 1016 for ( tmpVal = DisArrowUp; tmpVal <= DisArrowRight; ++tmpVal ) {
1017 if ( tmpVal == i ) { 1017 if ( tmpVal == i ) {
1018 tmpStr = pixnames [ i ]; 1018 tmpStr = pixnames [ i ];
1019 if ( tmpStr.isEmpty() ) { 1019 if ( tmpStr.isEmpty() ) {
1020 copyWidgetConfig( ArrowUp + ( tmpVal - DisArrowUp ), i, pixnames, 1020 copyWidgetConfig( ArrowUp + ( tmpVal - DisArrowUp ), i, pixnames,
1021 brdnames ); 1021 brdnames );
1022 return ; 1022 return ;
1023 } 1023 }
1024 } 1024 }
1025 } 1025 }
1026 1026
1027 // Pixmap 1027 // Pixmap
1028 int existing; 1028 int existing;
1029 // Scan for duplicate pixmaps(two identical pixmaps, tile scale, no blend, 1029 // Scan for duplicate pixmaps(two identical pixmaps, tile scale, no blend,
1030 // no pixmapped border) 1030 // no pixmapped border)
1031 if ( !pixnames [ i ].isEmpty() ) { 1031 if ( !pixnames [ i ].isEmpty() ) {
1032 for ( existing = 0; existing < i; ++existing ) { 1032 for ( existing = 0; existing < i; ++existing ) {
1033 if ( pixnames[ i ] == pixnames[ existing ] && scaleHints[ i ] == TileScale && 1033 if ( pixnames[ i ] == pixnames[ existing ] && scaleHints[ i ] == TileScale &&
1034 scaleHints[ existing ] == TileScale && blends[ existing ] == 0.0 && 1034 scaleHints[ existing ] == TileScale && blends[ existing ] == 0.0 &&
1035 blends[ i ] == 0.0 ) { 1035 blends[ i ] == 0.0 ) {
1036 pixmaps[ i ] = pixmaps[ existing ]; 1036 pixmaps[ i ] = pixmaps[ existing ];
1037 duplicate[ i ] = true; 1037 duplicate[ i ] = true;
1038 break; 1038 break;
1039 } 1039 }
1040 } 1040 }
1041 } 1041 }
1042 // load 1042 // load
1043 if ( !duplicate[ i ] && !pixnames[ i ].isEmpty() ) { 1043 if ( !duplicate[ i ] && !pixnames[ i ].isEmpty() ) {
1044 pixmaps[ i ] = loadPixmap( pixnames[ i ] ); 1044 pixmaps[ i ] = loadPixmap( pixnames[ i ] );
1045 // load and save images for scaled/blended widgets for speed. 1045 // load and save images for scaled/blended widgets for speed.
1046 if ( scaleHints[ i ] == TileScale && blends[ i ] == 0.0 ) 1046 if ( scaleHints[ i ] == TileScale && blends[ i ] == 0.0 )
1047 images[ i ] = NULL; 1047 images[ i ] = NULL;
1048 else 1048 else
1049 images[ i ] = loadImage( pixnames[ i ] ); 1049 images[ i ] = loadImage( pixnames[ i ] );
1050 } 1050 }
1051 1051
1052 // Pixmap border 1052 // Pixmap border
1053 if ( !brdnames [ i ]. isEmpty () ) { 1053 if ( !brdnames [ i ]. isEmpty () ) {
1054 // duplicate check 1054 // duplicate check
1055 for ( existing = 0; existing < i; ++existing ) { 1055 for ( existing = 0; existing < i; ++existing ) {
1056 if ( brdnames [i] == brdnames[ existing ] ) { 1056 if ( brdnames [i] == brdnames[ existing ] ) {
1057 pbPixmaps[ i ] = pbPixmaps[ existing ]; 1057 pbPixmaps[ i ] = pbPixmaps[ existing ];
1058 pbDuplicate[ i ] = true; 1058 pbDuplicate[ i ] = true;
1059 break; 1059 break;
1060 } 1060 }
1061 } 1061 }
1062 } 1062 }
1063 // load 1063 // load
1064 if ( !pbDuplicate[ i ] && !brdnames[ i ].isEmpty() ) 1064 if ( !pbDuplicate[ i ] && !brdnames[ i ].isEmpty() )
1065 pbPixmaps[ i ] = loadPixmap( brdnames[ i ] ); 1065 pbPixmaps[ i ] = loadPixmap( brdnames[ i ] );
1066 1066
1067 if ( pbPixmaps[ i ] && !pbDuplicate[ i ] ) 1067 if ( pbPixmaps[ i ] && !pbDuplicate[ i ] )
1068 generateBorderPix( i ); 1068 generateBorderPix( i );
1069 1069
1070 loadArray[ i ] = true; 1070 loadArray[ i ] = true;
1071} 1071}
1072 1072
1073 1073
1074OThemePixmap::OThemePixmap( bool timer ) 1074OThemePixmap::OThemePixmap( bool timer )
1075 : QPixmap() 1075 : QPixmap()
1076{ 1076{
1077 if(timer){ 1077 if(timer){
1078 t = new QTime; 1078 t = new QTime;
1079 t->start(); 1079 t->start();
1080 } 1080 }
1081 else 1081 else
1082 t = NULL; 1082 t = NULL;
1083 int i; 1083 int i;
1084 for ( i = 0; i < 8; ++i ) 1084 for ( i = 0; i < 8; ++i )
1085 b[ i ] = NULL; 1085 b[ i ] = NULL;
1086} 1086}
1087 1087
1088OThemePixmap::OThemePixmap( const OThemePixmap &p ) 1088OThemePixmap::OThemePixmap( const OThemePixmap &p )
1089 : QPixmap( p ) 1089 : QPixmap( p )
1090{ 1090{
1091 if(p.t){ 1091 if(p.t){
1092 t = new QTime; 1092 t = new QTime;
1093 t->start(); 1093 t->start();
1094 } 1094 }
1095 else 1095 else
1096 t = NULL; 1096 t = NULL;
1097 int i; 1097 int i;
1098 for ( i = 0; i < 8; ++i ) 1098 for ( i = 0; i < 8; ++i )
1099 if ( p.b[ i ] ) 1099 if ( p.b[ i ] )
1100 b[ i ] = new QPixmap( *p.b[ i ] ); 1100 b[ i ] = new QPixmap( *p.b[ i ] );
1101 else 1101 else
1102 b[ i ] = NULL; 1102 b[ i ] = NULL;
1103} 1103}
1104 1104
1105 1105
1106 1106
1107OThemePixmap::~OThemePixmap() 1107OThemePixmap::~OThemePixmap()
1108{ 1108{
1109 if(t) 1109 if(t)
1110 delete t; 1110 delete t;
1111 int i; 1111 int i;
1112 for ( i = 0; i < 8; ++i ) 1112 for ( i = 0; i < 8; ++i )
1113 if ( b[ i ] ) 1113 if ( b[ i ] )
1114 delete b[ i ]; 1114 delete b[ i ];
1115} 1115}
1116 1116
1117OThemeCache::OThemeCache( int maxSize, QObject *parent, const char *name ) 1117OThemeCache::OThemeCache( int maxSize, QObject *parent, const char *name )
1118 : QObject( parent, name ) 1118 : QObject( parent, name )
1119{ 1119{
1120 cache.setMaxCost( maxSize * 1024 ); 1120 cache.setMaxCost( maxSize * 1024 );
1121 cache.setAutoDelete( true ); 1121 cache.setAutoDelete( true );
1122 flushTimer.start(300000); // 5 minutes 1122 flushTimer.start(300000); // 5 minutes
1123 connect(&flushTimer, SIGNAL(timeout()), SLOT(flushTimeout())); 1123 connect(&flushTimer, SIGNAL(timeout()), SLOT(flushTimeout()));
1124} 1124}
1125 1125
1126void OThemeCache::flushTimeout() 1126void OThemeCache::flushTimeout()
1127{ 1127{
1128 QIntCacheIterator<OThemePixmap> it( cache ); 1128 QIntCacheIterator<OThemePixmap> it( cache );
1129 while ( it.current() ) { 1129 while ( it.current() ) {
1130 if ( it.current() ->isOld() ) 1130 if ( it.current() ->isOld() )
1131 cache.remove( it.currentKey() ); 1131 cache.remove( it.currentKey() );
1132 else 1132 else
1133 ++it; 1133 ++it;
1134 } 1134 }
1135} 1135}
1136 1136
1137OThemePixmap* OThemeCache::pixmap( int w, int h, int widgetID, bool border, 1137OThemePixmap* OThemeCache::pixmap( int w, int h, int widgetID, bool border,
1138 bool mask ) 1138 bool mask )
1139{ 1139{
1140 1140
1141 kthemeKey key; 1141 kthemeKey key;
1142 key.cacheKey = 0; // shut up, gcc 1142 key.cacheKey = 0; // shut up, gcc
1143 key.data.id = widgetID; 1143 key.data.id = widgetID;
1144 key.data.width = w; 1144 key.data.width = w;
1145 key.data.height = h; 1145 key.data.height = h;
1146 key.data.border = border; 1146 key.data.border = border;
1147 key.data.mask = mask; 1147 key.data.mask = mask;
1148 1148
1149 OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); 1149 OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey );
1150 if ( pix ) 1150 if ( pix )
1151 pix->updateAccessed(); 1151 pix->updateAccessed();
1152 return ( pix ); 1152 return ( pix );
1153} 1153}
1154 1154
1155OThemePixmap* OThemeCache::horizontalPixmap( int w, int widgetID ) 1155OThemePixmap* OThemeCache::horizontalPixmap( int w, int widgetID )
1156{ 1156{
1157 kthemeKey key; 1157 kthemeKey key;
1158 key.cacheKey = 0; // shut up, gcc 1158 key.cacheKey = 0; // shut up, gcc
1159 key.data.id = widgetID; 1159 key.data.id = widgetID;
1160 key.data.width = w; 1160 key.data.width = w;
1161 key.data.height = 0; 1161 key.data.height = 0;
1162 key.data.border = false; 1162 key.data.border = false;
1163 key.data.mask = false; 1163 key.data.mask = false;
1164 OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); 1164 OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey );
1165 if ( pix ) 1165 if ( pix )
1166 pix->updateAccessed(); 1166 pix->updateAccessed();
1167 return ( pix ); 1167 return ( pix );
1168} 1168}
1169 1169
1170OThemePixmap* OThemeCache::verticalPixmap( int h, int widgetID ) 1170OThemePixmap* OThemeCache::verticalPixmap( int h, int widgetID )
1171{ 1171{
1172 kthemeKey key; 1172 kthemeKey key;
1173 key.cacheKey = 0; // shut up, gcc 1173 key.cacheKey = 0; // shut up, gcc
1174 key.data.id = widgetID; 1174 key.data.id = widgetID;
1175 key.data.width = 0; 1175 key.data.width = 0;
1176 key.data.height = h; 1176 key.data.height = h;
1177 key.data.border = false; 1177 key.data.border = false;
1178 key.data.mask = false; 1178 key.data.mask = false;
1179 OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey ); 1179 OThemePixmap *pix = cache.find( ( unsigned long ) key.cacheKey );
1180 if ( pix ) 1180 if ( pix )
1181 pix->updateAccessed(); 1181 pix->updateAccessed();
1182 return ( pix ); 1182 return ( pix );
1183} 1183}
1184 1184
1185bool OThemeCache::insert( OThemePixmap *pixmap, ScaleHint scale, int widgetID, 1185bool OThemeCache::insert( OThemePixmap *pixmap, ScaleHint scale, int widgetID,
1186 bool border, bool mask ) 1186 bool border, bool mask )
1187{ 1187{
1188 kthemeKey key; 1188 kthemeKey key;
1189 key.cacheKey = 0; // shut up, gcc 1189 key.cacheKey = 0; // shut up, gcc
1190 key.data.id = widgetID; 1190 key.data.id = widgetID;
1191 key.data.width = ( scale == FullScale || scale == HorizontalScale ) ? 1191 key.data.width = ( scale == FullScale || scale == HorizontalScale ) ?
1192 pixmap->width() : 0; 1192 pixmap->width() : 0;
1193 key.data.height = ( scale == FullScale || scale == VerticalScale ) ? 1193 key.data.height = ( scale == FullScale || scale == VerticalScale ) ?
1194 pixmap->height() : 0; 1194 pixmap->height() : 0;
1195 key.data.border = border; 1195 key.data.border = border;
1196 key.data.mask = mask; 1196 key.data.mask = mask;
1197 1197
1198 if ( cache.find( ( unsigned long ) key.cacheKey, true ) != NULL ) { 1198 if ( cache.find( ( unsigned long ) key.cacheKey, true ) != NULL ) {
1199 return ( true ); // a pixmap of this scale is already in there 1199 return ( true ); // a pixmap of this scale is already in there
1200 } 1200 }
1201 return ( cache.insert( ( unsigned long ) key.cacheKey, pixmap, 1201 return ( cache.insert( ( unsigned long ) key.cacheKey, pixmap,
1202 pixmap->width() * pixmap->height() * pixmap->depth() / 8 ) ); 1202 pixmap->width() * pixmap->height() * pixmap->depth() / 8 ) );
1203} 1203}
1204 1204
1205//#include "kthemebase.moc" 1205//#include "kthemebase.moc"
diff --git a/noncore/styles/theme/themeset.cpp b/noncore/styles/theme/themeset.cpp
index d4005bc..3205106 100644
--- a/noncore/styles/theme/themeset.cpp
+++ b/noncore/styles/theme/themeset.cpp
@@ -1,124 +1,124 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21 21
22 22
23#include "themeset.h" 23#include "themeset.h"
24 24
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/global.h> 26#include <qpe/global.h>
27 27
28#include <qlabel.h> 28#include <qlabel.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#include <qlistview.h> 30#include <qlistview.h>
31#include <qdir.h> 31#include <qdir.h>
32 32
33#include <qpe/config.h> 33#include <qpe/config.h>
34 34
35 35
36class MyConfig : public Config 36class MyConfig : public Config
37{ 37{
38public: 38public:
39 MyConfig ( const QString &f, Domain d ) : Config ( f, d ) 39 MyConfig ( const QString &f, Domain d ) : Config ( f, d )
40 { } 40 { }
41 41
42 bool hasGroup ( const QString &gname ) const 42 bool hasGroup ( const QString &gname ) const
43 { 43 {
44 QMap< QString, ConfigGroup>::ConstIterator it = groups. find ( gname ); 44 QMap< QString, ConfigGroup>::ConstIterator it = groups. find ( gname );
45 return ( it != groups.end() ); 45 return ( it != groups.end() );
46 } 46 }
47}; 47};
48 48
49class MyItem : public QListViewItem 49class MyItem : public QListViewItem
50{ 50{
51public: 51public:
52 MyItem ( QListView *lv, QListViewItem *after, const QString &name, const QString &comm, const QString &theme ) : QListViewItem ( lv, after, name, comm ) 52 MyItem ( QListView *lv, QListViewItem *after, const QString &name, const QString &comm, const QString &theme ) : QListViewItem ( lv, after, name, comm )
53 { 53 {
54 m_theme = theme; 54 m_theme = theme;
55 } 55 }
56 56
57 57
58 QString m_theme; 58 QString m_theme;
59}; 59};
60 60
61 61
62ThemeSettings::ThemeSettings ( QWidget* parent, const char *name, WFlags fl ) 62ThemeSettings::ThemeSettings ( QWidget* parent, const char *name, WFlags fl )
63 : QWidget ( parent, name, fl ) 63 : QWidget ( parent, name, fl )
64{ 64{
65 setCaption ( tr( "Theme Style" ) ); 65 setCaption ( tr( "Theme Style" ) );
66 66
67 Config config ( "qpe" ); 67 Config config ( "qpe" );
68 config. setGroup ( "Appearance" ); 68 config. setGroup ( "Appearance" );
69 69
70 QString active = config. readEntry ( "Theme", "default" ); 70 QString active = config. readEntry ( "Theme", "default" );
71 71
72 QVBoxLayout *vbox = new QVBoxLayout ( this ); 72 QVBoxLayout *vbox = new QVBoxLayout ( this );
73 vbox-> setSpacing ( 3 ); 73 vbox-> setSpacing ( 3 );
74 vbox-> setMargin ( 6 ); 74 vbox-> setMargin ( 6 );
75 75
76 vbox-> addWidget ( new QLabel ( tr( "Select the theme to be used" ), this )); 76 vbox-> addWidget ( new QLabel ( tr( "Select the theme to be used" ), this ));
77 77
78 m_list = new QListView ( this ); 78 m_list = new QListView ( this );
79 m_list-> addColumn ( tr( "Name" )); 79 m_list-> addColumn ( tr( "Name" ));
80 m_list-> addColumn ( tr( "Description" )); 80 m_list-> addColumn ( tr( "Description" ));
81 m_list-> setSelectionMode ( QListView::Single ); 81 m_list-> setSelectionMode ( QListView::Single );
82 m_list-> setAllColumnsShowFocus ( true ); 82 m_list-> setAllColumnsShowFocus ( true );
83 m_list-> setSorting ( -1 ); 83 m_list-> setSorting ( -1 );
84 vbox-> addWidget ( m_list, 10 ); 84 vbox-> addWidget ( m_list, 10 );
85 85
86 QListViewItem *item = new MyItem ( m_list, 0, tr( "[No theme]" ), "", "" ); 86 QListViewItem *item = new MyItem ( m_list, 0, tr( "[No theme]" ), "", "" );
87 m_list-> setSelected ( item, true ); 87 m_list-> setSelected ( item, true );
88 88
89 QString path = QPEApplication::qpeDir() + "/plugins/styles/themes"; 89 QString path = QPEApplication::qpeDir() + "plugins/styles/themes";
90 QStringList list = QDir ( path, "*.themerc" ). entryList ( ); 90 QStringList list = QDir ( path, "*.themerc" ). entryList ( );
91 91
92 for ( QStringList::Iterator it = list. begin(); it != list. end ( ); ++it ) { 92 for ( QStringList::Iterator it = list. begin(); it != list. end ( ); ++it ) {
93 MyConfig cfg ( path + "/" + *it, Config::File ); 93 MyConfig cfg ( path + "/" + *it, Config::File );
94 94
95 if ( cfg. hasGroup ( "Misc" )) { 95 if ( cfg. hasGroup ( "Misc" )) {
96 cfg. setGroup ( "Misc" ); 96 cfg. setGroup ( "Misc" );
97 97
98 QString name = cfg. readEntry ( "Name" ); 98 QString name = cfg. readEntry ( "Name" );
99 QString comm = cfg. readEntry ( "Comment" ); 99 QString comm = cfg. readEntry ( "Comment" );
100 100
101 if ( !name. isEmpty ( )) { 101 if ( !name. isEmpty ( )) {
102 QString fname = (*it). left ((*it). length ( ) - 8 ); 102 QString fname = (*it). left ((*it). length ( ) - 8 );
103 103
104 item = new MyItem ( m_list, item, name, comm, fname ); 104 item = new MyItem ( m_list, item, name, comm, fname );
105 if ( active == fname ) { 105 if ( active == fname ) {
106 m_list-> setSelected ( item, true ); 106 m_list-> setSelected ( item, true );
107 } 107 }
108 } 108 }
109 } 109 }
110 } 110 }
111} 111}
112 112
113bool ThemeSettings::writeConfig ( ) 113bool ThemeSettings::writeConfig ( )
114{ 114{
115 Config config ( "qpe" ); 115 Config config ( "qpe" );
116 config. setGroup ( "Appearance" ); 116 config. setGroup ( "Appearance" );
117 117
118 MyItem *it = (MyItem *) m_list-> selectedItem ( ); 118 MyItem *it = (MyItem *) m_list-> selectedItem ( );
119 config. writeEntry ( "Theme", it ? it-> m_theme : QString ( "" )); 119 config. writeEntry ( "Theme", it ? it-> m_theme : QString ( "" ));
120 config. write ( ); 120 config. write ( );
121 121
122 return true; 122 return true;
123} 123}
124 124
diff --git a/noncore/tools/calc2/calc.cpp b/noncore/tools/calc2/calc.cpp
index 3dcdf6e..c7656bf 100644
--- a/noncore/tools/calc2/calc.cpp
+++ b/noncore/tools/calc2/calc.cpp
@@ -1,104 +1,104 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include <qvaluelist.h> 21#include <qvaluelist.h>
22#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
23#include <qdir.h> 23#include <qdir.h>
24#include <qwidgetstack.h> 24#include <qwidgetstack.h>
25 25
26#include "calc.h" 26#include "calc.h"
27#include "plugininterface.h" 27#include "plugininterface.h"
28 28
29calc::calc (QWidget * p, const char *n):QWidget (p, n) 29calc::calc (QWidget * p, const char *n):QWidget (p, n)
30{ 30{
31 setCaption (tr ("Calculator")); 31 setCaption (tr ("Calculator"));
32 32
33// widgets 33// widgets
34 LCD = new QLCDNumber (this); 34 LCD = new QLCDNumber (this);
35 LCD->setMaximumSize (QSize (240, 30)); 35 LCD->setMaximumSize (QSize (240, 30));
36 LCD->setNumDigits(12); 36 LCD->setNumDigits(12);
37LCD->setSegmentStyle(QLCDNumber::Filled); 37LCD->setSegmentStyle(QLCDNumber::Filled);
38 pluginWidgetStack = new QWidgetStack (this); 38 pluginWidgetStack = new QWidgetStack (this);
39 39
40// layout widgets 40// layout widgets
41 calculatorLayout = new QVBoxLayout (this); 41 calculatorLayout = new QVBoxLayout (this);
42 calculatorLayout->addWidget (LCD); 42 calculatorLayout->addWidget (LCD);
43 calculatorLayout->addWidget (pluginWidgetStack); 43 calculatorLayout->addWidget (pluginWidgetStack);
44 44
45// no formatting of display for now 45// no formatting of display for now
46 connect (&engine, SIGNAL(display(double)), LCD, SLOT(display(double))); 46 connect (&engine, SIGNAL(display(double)), LCD, SLOT(display(double)));
47 connect (&engine, SIGNAL(display(const QString&)), LCD, SLOT(display(const QString&))); 47 connect (&engine, SIGNAL(display(const QString&)), LCD, SLOT(display(const QString&)));
48 connect (&engine, SIGNAL(setBinMode()), LCD, SLOT(setBinMode())); 48 connect (&engine, SIGNAL(setBinMode()), LCD, SLOT(setBinMode()));
49 connect (&engine, SIGNAL(setOctMode()), LCD, SLOT(setOctMode())); 49 connect (&engine, SIGNAL(setOctMode()), LCD, SLOT(setOctMode()));
50 connect (&engine, SIGNAL(setDecMode()), LCD, SLOT(setDecMode())); 50 connect (&engine, SIGNAL(setDecMode()), LCD, SLOT(setDecMode()));
51 connect (&engine, SIGNAL(setHexMode()), LCD, SLOT(setHexMode())); 51 connect (&engine, SIGNAL(setHexMode()), LCD, SLOT(setHexMode()));
52 52
53#ifndef NO_PLUGINS 53#ifndef NO_PLUGINS
54// load plugins 54// load plugins
55 QValueList < Plugin >::Iterator mit; 55 QValueList < Plugin >::Iterator mit;
56 for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) { 56 for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) {
57 (*mit).interface->release (); 57 (*mit).interface->release ();
58 (*mit).library->unload (); 58 (*mit).library->unload ();
59 delete (*mit).library; 59 delete (*mit).library;
60 } 60 }
61 pluginList.clear (); 61 pluginList.clear ();
62 62
63 QString path = QPEApplication::qpeDir() + "/plugins/calculator"; 63 QString path = QPEApplication::qpeDir() + "plugins/calculator";
64 QDir dir (path, "lib*.so"); 64 QDir dir (path, "lib*.so");
65 QStringList list = dir.entryList (); 65 QStringList list = dir.entryList ();
66 66
67 QStringList::Iterator it; 67 QStringList::Iterator it;
68 for (it = list.begin (); it != list.end (); ++it) { 68 for (it = list.begin (); it != list.end (); ++it) {
69 CalcInterface *iface = 0; 69 CalcInterface *iface = 0;
70 QLibrary *lib = new QLibrary (path + "/" + *it); 70 QLibrary *lib = new QLibrary (path + "/" + *it);
71 71
72 Plugin plugin; 72 Plugin plugin;
73 plugin.pluginWidget = 0; 73 plugin.pluginWidget = 0;
74 74
75 if (lib->queryInterface (IID_Calc, (QUnknownInterface **) & iface) == 75 if (lib->queryInterface (IID_Calc, (QUnknownInterface **) & iface) ==
76 QS_OK) { 76 QS_OK) {
77 plugin.library = lib; 77 plugin.library = lib;
78 plugin.interface = iface; 78 plugin.interface = iface;
79 plugin.pluginWidget = plugin.interface->getPlugin(&engine,pluginWidgetStack); 79 plugin.pluginWidget = plugin.interface->getPlugin(&engine,pluginWidgetStack);
80 if (plugin.pluginWidget) 80 if (plugin.pluginWidget)
81 pluginWidgetStack->addWidget (plugin.pluginWidget, pluginList.count()); 81 pluginWidgetStack->addWidget (plugin.pluginWidget, pluginList.count());
82 pluginList.append (plugin); 82 pluginList.append (plugin);
83 } else { 83 } else {
84 delete lib; 84 delete lib;
85 } 85 }
86 } 86 }
87 setMode (1); 87 setMode (1);
88#else 88#else
89// load simple interface 89// load simple interface
90#endif 90#endif
91} 91}
92 92
93calc::~calc () 93calc::~calc ()
94{ 94{
95#ifndef NO_PLUGINS 95#ifndef NO_PLUGINS
96 QValueList < Plugin >::Iterator mit; 96 QValueList < Plugin >::Iterator mit;
97 for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) { 97 for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) {
98 (*mit).interface->release (); 98 (*mit).interface->release ();
99 (*mit).library->unload (); 99 (*mit).library->unload ();
100 delete (*mit).library; 100 delete (*mit).library;
101 } 101 }
102#endif 102#endif
103} 103}
104 104
diff --git a/x11/libqpe-x11/qpe/qpeapplication.cpp b/x11/libqpe-x11/qpe/qpeapplication.cpp
index 3cb8faf..73e7ce4 100644
--- a/x11/libqpe-x11/qpe/qpeapplication.cpp
+++ b/x11/libqpe-x11/qpe/qpeapplication.cpp
@@ -1,796 +1,796 @@
1#define QTOPIA_INTERNAL_LANGLIST 1#define QTOPIA_INTERNAL_LANGLIST
2 2
3#include <stdio.h> 3#include <stdio.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <unistd.h> 5#include <unistd.h>
6#include <sys/file.h> 6#include <sys/file.h>
7 7
8 8
9#include <qdir.h> 9#include <qdir.h>
10#include <qdialog.h> 10#include <qdialog.h>
11#include <qdragobject.h> 11#include <qdragobject.h>
12#include <qevent.h> 12#include <qevent.h>
13#include <qlabel.h> 13#include <qlabel.h>
14#include <qlist.h> 14#include <qlist.h>
15#include <qtextstream.h> 15#include <qtextstream.h>
16#include <qtextcodec.h> 16#include <qtextcodec.h>
17#include <qpalette.h> 17#include <qpalette.h>
18#include <qptrdict.h> 18#include <qptrdict.h>
19#include <qregexp.h> 19#include <qregexp.h>
20#include <qtimer.h> 20#include <qtimer.h>
21 21
22#include <qpe/custom.h> 22#include <qpe/custom.h>
23#include <qpe/alarmserver.h> 23#include <qpe/alarmserver.h>
24#include <qpe/applnk.h> 24#include <qpe/applnk.h>
25#include <qpe/qpemenubar.h> 25#include <qpe/qpemenubar.h>
26#include <qpe/textcodecinterface.h> 26#include <qpe/textcodecinterface.h>
27#include <qpe/imagecodecinterface.h> 27#include <qpe/imagecodecinterface.h>
28#include <qpe/qlibrary.h> 28#include <qpe/qlibrary.h>
29#include <qpe/qpestyle.h> 29#include <qpe/qpestyle.h>
30#include <qpe/styleinterface.h> 30#include <qpe/styleinterface.h>
31#include <qpe/global.h> 31#include <qpe/global.h>
32#include <qpe/resource.h> 32#include <qpe/resource.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/network.h> 34#include <qpe/network.h>
35 35
36#include <qpe/qpeapplication.h> 36#include <qpe/qpeapplication.h>
37#include <qpe/timestring.h> 37#include <qpe/timestring.h>
38#include <qpe/qcopenvelope_qws.h> 38#include <qpe/qcopenvelope_qws.h>
39 39
40 40
41#include <X11/Xlib.h> 41#include <X11/Xlib.h>
42#include <X11/Xutil.h> 42#include <X11/Xutil.h>
43 43
44const int XKeyPress = KeyPress; 44const int XKeyPress = KeyPress;
45const int XKeyRelease = KeyRelease; 45const int XKeyRelease = KeyRelease;
46#undef KeyPress 46#undef KeyPress
47#undef KeyRelease 47#undef KeyRelease
48 48
49namespace { 49namespace {
50 struct QCopRec{ 50 struct QCopRec{
51 QCopRec( const QCString& ch, const QCString& msg, const QByteArray& ar ) 51 QCopRec( const QCString& ch, const QCString& msg, const QByteArray& ar )
52 : channel(ch), message(msg), data(ar) { 52 : channel(ch), message(msg), data(ar) {
53 53
54 } 54 }
55 QCString channel; 55 QCString channel;
56 QCString message; 56 QCString message;
57 QByteArray data; 57 QByteArray data;
58 }; 58 };
59}; 59};
60 60
61 61
62class QPEApplication::Private { 62class QPEApplication::Private {
63public: 63public:
64 Private(); 64 Private();
65 ~Private(); 65 ~Private();
66 void enqueueQCop( const QCString& ch, const QCString& msg, 66 void enqueueQCop( const QCString& ch, const QCString& msg,
67 const QByteArray& ); 67 const QByteArray& );
68 void sendQCopQ(); 68 void sendQCopQ();
69 static void show_mx(QWidget* mw, bool nomaximize ); 69 static void show_mx(QWidget* mw, bool nomaximize );
70 void show( QWidget* mw, bool nomax ); 70 void show( QWidget* mw, bool nomax );
71 void loadTextCodecs(); 71 void loadTextCodecs();
72 void loadImageCodecs(); 72 void loadImageCodecs();
73 73
74 int kbgrabber; 74 int kbgrabber;
75 int presstimer; 75 int presstimer;
76 76
77 bool rightpressed : 1; 77 bool rightpressed : 1;
78 bool kbregrab : 1; 78 bool kbregrab : 1;
79 bool notbusysent : 1; 79 bool notbusysent : 1;
80 bool preloaded : 1; 80 bool preloaded : 1;
81 bool forceshow : 1; 81 bool forceshow : 1;
82 bool nomaximize : 1; 82 bool nomaximize : 1;
83 bool keep_running : 1; 83 bool keep_running : 1;
84 84
85 QWidget* presswidget; 85 QWidget* presswidget;
86 QPoint presspos; 86 QPoint presspos;
87 QWidget* qpe_main_widget; 87 QWidget* qpe_main_widget;
88 QString appName; 88 QString appName;
89 QString styleName; 89 QString styleName;
90 QString decorationName; 90 QString decorationName;
91 Atom wm_delete_window; 91 Atom wm_delete_window;
92 Atom wm_take_focus; 92 Atom wm_take_focus;
93 Atom wm_context_help; 93 Atom wm_context_help;
94 Atom wm_context_accept; 94 Atom wm_context_accept;
95 Atom wm_protocols; 95 Atom wm_protocols;
96 96
97private: 97private:
98 QList<QCopRec> qcopq; 98 QList<QCopRec> qcopq;
99}; 99};
100QPEApplication::Private::~Private() { 100QPEApplication::Private::~Private() {
101} 101}
102QPEApplication::Private::Private() 102QPEApplication::Private::Private()
103 : kbgrabber(0 ), presstimer(0 ), rightpressed( FALSE ), kbregrab( FALSE ), notbusysent( FALSE ), 103 : kbgrabber(0 ), presstimer(0 ), rightpressed( FALSE ), kbregrab( FALSE ), notbusysent( FALSE ),
104 preloaded( FALSE ), forceshow( FALSE ), nomaximize( FALSE ), keep_running( TRUE ), 104 preloaded( FALSE ), forceshow( FALSE ), nomaximize( FALSE ), keep_running( TRUE ),
105 presswidget( 0 ), qpe_main_widget(0 ) { 105 presswidget( 0 ), qpe_main_widget(0 ) {
106 106
107 qcopq.setAutoDelete( TRUE ); 107 qcopq.setAutoDelete( TRUE );
108} 108}
109void QPEApplication::Private::enqueueQCop( const QCString& chan, const QCString& msg, 109void QPEApplication::Private::enqueueQCop( const QCString& chan, const QCString& msg,
110 const QByteArray& ar ) { 110 const QByteArray& ar ) {
111 qcopq.append( new QCopRec(chan, msg, ar ) ); 111 qcopq.append( new QCopRec(chan, msg, ar ) );
112} 112}
113void QPEApplication::Private::sendQCopQ() { 113void QPEApplication::Private::sendQCopQ() {
114 QCopRec* r; 114 QCopRec* r;
115 for ( r = qcopq.first(); r; r = qcopq.next() ) { 115 for ( r = qcopq.first(); r; r = qcopq.next() ) {
116 QCopChannel::sendLocally( r->channel, r->message, r->data ); 116 QCopChannel::sendLocally( r->channel, r->message, r->data );
117 } 117 }
118 qcopq.clear(); 118 qcopq.clear();
119} 119}
120void QPEApplication::Private::show_mx(QWidget* mw, bool nomaximize ) { 120void QPEApplication::Private::show_mx(QWidget* mw, bool nomaximize ) {
121 if (mw->layout() && mw->inherits("QDialog") ) { 121 if (mw->layout() && mw->inherits("QDialog") ) {
122 QPEApplication::showDialog( (QDialog*)mw, nomaximize ); 122 QPEApplication::showDialog( (QDialog*)mw, nomaximize );
123 }else { 123 }else {
124 if (!nomaximize ) 124 if (!nomaximize )
125 mw->showMaximized(); 125 mw->showMaximized();
126 else 126 else
127 mw->show(); 127 mw->show();
128 } 128 }
129} 129}
130void QPEApplication::Private::show( QWidget* mw, bool nomax ) { 130void QPEApplication::Private::show( QWidget* mw, bool nomax ) {
131 nomaximize = nomax; 131 nomaximize = nomax;
132 qpe_main_widget = mw; 132 qpe_main_widget = mw;
133 133
134 sendQCopQ(); 134 sendQCopQ();
135 135
136 if ( preloaded ) { 136 if ( preloaded ) {
137 if (forceshow ) 137 if (forceshow )
138 show_mx(mw, nomax ); 138 show_mx(mw, nomax );
139 }else if ( keep_running ) 139 }else if ( keep_running )
140 show_mx( mw, nomax ); 140 show_mx( mw, nomax );
141} 141}
142void QPEApplication::Private::loadTextCodecs() { 142void QPEApplication::Private::loadTextCodecs() {
143 QString path = QPEApplication::qpeDir() + "/plugins/textcodecs"; 143 QString path = QPEApplication::qpeDir() + "plugins/textcodecs";
144 QDir dir( path, "lib*.so" ); 144 QDir dir( path, "lib*.so" );
145 QStringList list = dir.entryList(); 145 QStringList list = dir.entryList();
146 QStringList::Iterator it; 146 QStringList::Iterator it;
147 for ( it = list.begin(); it != list.end(); ++it ) { 147 for ( it = list.begin(); it != list.end(); ++it ) {
148 TextCodecInterface *iface = 0; 148 TextCodecInterface *iface = 0;
149 QLibrary *lib = new QLibrary( path + "/" + *it ); 149 QLibrary *lib = new QLibrary( path + "/" + *it );
150 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 150 if ( lib->queryInterface( IID_QtopiaTextCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
151 QValueList<int> mibs = iface->mibEnums(); 151 QValueList<int> mibs = iface->mibEnums();
152 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) { 152 for (QValueList<int>::ConstIterator i = mibs.begin(); i != mibs.end(); ++i) {
153 (void)iface->createForMib(*i); 153 (void)iface->createForMib(*i);
154 // ### it exists now; need to remember if we can delete it 154 // ### it exists now; need to remember if we can delete it
155 } 155 }
156 } 156 }
157 else { 157 else {
158 lib->unload(); 158 lib->unload();
159 delete lib; 159 delete lib;
160 } 160 }
161 } 161 }
162} 162}
163void QPEApplication::Private::loadImageCodecs() { 163void QPEApplication::Private::loadImageCodecs() {
164 QString path = QPEApplication::qpeDir() + "/plugins/imagecodecs"; 164 QString path = QPEApplication::qpeDir() + "plugins/imagecodecs";
165 QDir dir( path, "lib*.so" ); 165 QDir dir( path, "lib*.so" );
166 QStringList list = dir.entryList(); 166 QStringList list = dir.entryList();
167 QStringList::Iterator it; 167 QStringList::Iterator it;
168 for ( it = list.begin(); it != list.end(); ++it ) { 168 for ( it = list.begin(); it != list.end(); ++it ) {
169 ImageCodecInterface *iface = 0; 169 ImageCodecInterface *iface = 0;
170 QLibrary *lib = new QLibrary( path + "/" + *it ); 170 QLibrary *lib = new QLibrary( path + "/" + *it );
171 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 171 if ( lib->queryInterface( IID_QtopiaImageCodec, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
172 QStringList formats = iface->keys(); 172 QStringList formats = iface->keys();
173 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) { 173 for (QStringList::ConstIterator i = formats.begin(); i != formats.end(); ++i) {
174 (void)iface->installIOHandler(*i); 174 (void)iface->installIOHandler(*i);
175 // ### it exists now; need to remember if we can delete it 175 // ### it exists now; need to remember if we can delete it
176 } 176 }
177 } 177 }
178 else { 178 else {
179 lib->unload(); 179 lib->unload();
180 delete lib; 180 delete lib;
181 } 181 }
182 } 182 }
183} 183}
184 184
185// The Help System hook 185// The Help System hook
186namespace { 186namespace {
187 class ResourceMimeFactory : public QMimeSourceFactory 187 class ResourceMimeFactory : public QMimeSourceFactory
188 { 188 {
189 public: 189 public:
190 ResourceMimeFactory(); 190 ResourceMimeFactory();
191 ~ResourceMimeFactory(); 191 ~ResourceMimeFactory();
192 const QMimeSource* data( const QString& abs_name )const; 192 const QMimeSource* data( const QString& abs_name )const;
193 }; 193 };
194 ResourceMimeFactory::ResourceMimeFactory() 194 ResourceMimeFactory::ResourceMimeFactory()
195 { 195 {
196 setFilePath( Global::helpPath() ); 196 setFilePath( Global::helpPath() );
197 setExtensionType( "html", "text/html;charset=UTF-8" ); 197 setExtensionType( "html", "text/html;charset=UTF-8" );
198 } 198 }
199 ResourceMimeFactory::~ResourceMimeFactory() { 199 ResourceMimeFactory::~ResourceMimeFactory() {
200 } 200 }
201 201
202 const QMimeSource* ResourceMimeFactory::data( const QString& abs_name ) const 202 const QMimeSource* ResourceMimeFactory::data( const QString& abs_name ) const
203 { 203 {
204 const QMimeSource * r = QMimeSourceFactory::data( abs_name ); 204 const QMimeSource * r = QMimeSourceFactory::data( abs_name );
205 if ( !r ) { 205 if ( !r ) {
206 int sl = abs_name.length(); 206 int sl = abs_name.length();
207 do { 207 do {
208 sl = abs_name.findRev( '/', sl - 1 ); 208 sl = abs_name.findRev( '/', sl - 1 );
209 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name; 209 QString name = sl >= 0 ? abs_name.mid( sl + 1 ) : abs_name;
210 int dot = name.findRev( '.' ); 210 int dot = name.findRev( '.' );
211 if ( dot >= 0 ) 211 if ( dot >= 0 )
212 name = name.left( dot ); 212 name = name.left( dot );
213 QImage img = Resource::loadImage( name ); 213 QImage img = Resource::loadImage( name );
214 if ( !img.isNull() ) 214 if ( !img.isNull() )
215 r = new QImageDrag( img ); 215 r = new QImageDrag( img );
216 } 216 }
217 while ( !r && sl > 0 ); 217 while ( !r && sl > 0 );
218 } 218 }
219 return r; 219 return r;
220 }; 220 };
221}; 221};
222// QPEApplication 222// QPEApplication
223QPEApplication::~QPEApplication() { 223QPEApplication::~QPEApplication() {
224 qWarning("~QPEApplication"); 224 qWarning("~QPEApplication");
225 ungrabKeyboard(); 225 ungrabKeyboard();
226 qWarning("UngrabKeyboard"); 226 qWarning("UngrabKeyboard");
227 227
228// delete m_sys; 228// delete m_sys;
229// delete m_pid; 229// delete m_pid;
230 230
231 delete d; 231 delete d;
232} 232}
233QPEApplication::QPEApplication(int &arg, char** argv, Type t) 233QPEApplication::QPEApplication(int &arg, char** argv, Type t)
234 : QApplication( arg, argv, t ) { 234 : QApplication( arg, argv, t ) {
235 d = new Private; 235 d = new Private;
236 d->loadTextCodecs(); 236 d->loadTextCodecs();
237 d->loadImageCodecs(); 237 d->loadImageCodecs();
238 238
239 // Init X-Atom 239 // Init X-Atom
240 Atom *atoms[5]; 240 Atom *atoms[5];
241 Atom atoms_re[5]; 241 Atom atoms_re[5];
242 char* names[5]; 242 char* names[5];
243 int n = 0; 243 int n = 0;
244 atoms[n] = &d->wm_delete_window; 244 atoms[n] = &d->wm_delete_window;
245 names[n++] = "WM_DELETE_WINDOW"; 245 names[n++] = "WM_DELETE_WINDOW";
246 246
247 atoms[n] = &d->wm_take_focus; 247 atoms[n] = &d->wm_take_focus;
248 names[n++] = "WM_TAKE_FOCUS"; 248 names[n++] = "WM_TAKE_FOCUS";
249 249
250 atoms[n] = &d->wm_context_help; 250 atoms[n] = &d->wm_context_help;
251 names[n++] = "_NET_WM_CONTEXT_HELP"; 251 names[n++] = "_NET_WM_CONTEXT_HELP";
252 252
253 atoms[n] = &d->wm_context_accept; 253 atoms[n] = &d->wm_context_accept;
254 names[n++] = "_NET_WM_CONTEXT_ACCEPT"; 254 names[n++] = "_NET_WM_CONTEXT_ACCEPT";
255 255
256 atoms[n] = &d->wm_protocols; 256 atoms[n] = &d->wm_protocols;
257 names[n++] = "WM_PROTOCOLS"; 257 names[n++] = "WM_PROTOCOLS";
258 258
259 XInternAtoms( qt_xdisplay(), names, n, FALSE, atoms_re); 259 XInternAtoms( qt_xdisplay(), names, n, FALSE, atoms_re);
260 // now copy the values over to the properties 260 // now copy the values over to the properties
261 for (int i = 0; i < n; i++ ) 261 for (int i = 0; i < n; i++ )
262 *atoms[i] = atoms_re[i]; 262 *atoms[i] = atoms_re[i];
263 // done with X11 Stuff 263 // done with X11 Stuff
264 264
265 int dw = desktop()->width(); 265 int dw = desktop()->width();
266 if ( dw < 200 ) { 266 if ( dw < 200 ) {
267 setFont( QFont( "helvetica", 8 ) ); 267 setFont( QFont( "helvetica", 8 ) );
268 AppLnk::setSmallIconSize( 10 ); 268 AppLnk::setSmallIconSize( 10 );
269 AppLnk::setBigIconSize( 28 ); 269 AppLnk::setBigIconSize( 28 );
270 }else if ( dw > 600 ) { 270 }else if ( dw > 600 ) {
271 setFont( QFont( "helvetica", 12 ) ); 271 setFont( QFont( "helvetica", 12 ) );
272 AppLnk::setSmallIconSize( 24 ); 272 AppLnk::setSmallIconSize( 24 );
273 AppLnk::setBigIconSize( 48 ); 273 AppLnk::setBigIconSize( 48 );
274 }else if ( dw > 200 ) { 274 }else if ( dw > 200 ) {
275 setFont( QFont( "helvetica", 10 ) ); 275 setFont( QFont( "helvetica", 10 ) );
276 AppLnk::setSmallIconSize( 16 ); 276 AppLnk::setSmallIconSize( 16 );
277 AppLnk::setBigIconSize( 32 ); 277 AppLnk::setBigIconSize( 32 );
278 } 278 }
279 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory ); 279 QMimeSourceFactory::setDefaultFactory( new ResourceMimeFactory );
280 280
281 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT(hideOrQuit() ) ); 281 connect( this, SIGNAL( lastWindowClosed() ), this, SLOT(hideOrQuit() ) );
282 282
283 QString qcopfn( "/tmp/qcop-msg-" ); 283 QString qcopfn( "/tmp/qcop-msg-" );
284 qcopfn += QString( argv[0] ); // append command name to the QCOP name 284 qcopfn += QString( argv[0] ); // append command name to the QCOP name
285 QFile file( qcopfn ); 285 QFile file( qcopfn );
286 if (file.open(IO_ReadOnly ) ) { 286 if (file.open(IO_ReadOnly ) ) {
287 flock( file.handle(), LOCK_EX ); 287 flock( file.handle(), LOCK_EX );
288 } 288 }
289 289
290 /* Hmmm damn we need to make the parent 0l otherwise it get's deleted 290 /* Hmmm damn we need to make the parent 0l otherwise it get's deleted
291 * past the QApplication 291 * past the QApplication
292 */ 292 */
293 m_sys = new QCopChannel( "QPE/System", 0l); 293 m_sys = new QCopChannel( "QPE/System", 0l);
294 connect(m_sys, SIGNAL( received(const QCString&,const QByteArray&) ), 294 connect(m_sys, SIGNAL( received(const QCString&,const QByteArray&) ),
295 this, SLOT(systemMessage(const QCString&,const QByteArray&) ) ); 295 this, SLOT(systemMessage(const QCString&,const QByteArray&) ) );
296 296
297 // private channel QPE/Application/appname 297 // private channel QPE/Application/appname
298 QCString channel = QCString( argv[0] ); 298 QCString channel = QCString( argv[0] );
299 channel.replace( QRegExp( ".*/"), "" ); 299 channel.replace( QRegExp( ".*/"), "" );
300 d->appName = channel; 300 d->appName = channel;
301 channel = "QPE/Application/"+ channel; 301 channel = "QPE/Application/"+ channel;
302 m_pid = new QCopChannel( channel, 0l ); 302 m_pid = new QCopChannel( channel, 0l );
303 connect(m_pid, SIGNAL( received(const QCString&,const QByteArray&) ), 303 connect(m_pid, SIGNAL( received(const QCString&,const QByteArray&) ),
304 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) ); 304 this, SLOT( pidMessage(const QCString&,const QByteArray&) ) );
305 305
306 // read the Pre QCOP Stuff from the file 306 // read the Pre QCOP Stuff from the file
307 if ( file.isOpen() ) { 307 if ( file.isOpen() ) {
308 d->keep_running = FALSE; 308 d->keep_running = FALSE;
309 QDataStream ds( &file ); 309 QDataStream ds( &file );
310 QCString chanel, message; 310 QCString chanel, message;
311 QByteArray data; 311 QByteArray data;
312 while (!ds.atEnd() ) { 312 while (!ds.atEnd() ) {
313 ds >> chanel >> message >> data; 313 ds >> chanel >> message >> data;
314 d->enqueueQCop( chanel, message, data ); 314 d->enqueueQCop( chanel, message, data );
315 } 315 }
316 flock( file.handle(), LOCK_UN ); 316 flock( file.handle(), LOCK_UN );
317 file.close(); 317 file.close();
318 file.remove(); 318 file.remove();
319 } 319 }
320 320
321 // read in some stuff from the command line 321 // read in some stuff from the command line
322 // we do not have setArgs so we need to take 322 // we do not have setArgs so we need to take
323 // care of that 323 // care of that
324 for ( int a = 0; a < arg; a++ ) { 324 for ( int a = 0; a < arg; a++ ) {
325 if ( qstrcmp( argv[a], "-preload" ) == 0 ) { 325 if ( qstrcmp( argv[a], "-preload" ) == 0 ) {
326 d->preloaded = TRUE; 326 d->preloaded = TRUE;
327 }else if ( qstrcmp( argv[a ] , "-preload-show" ) == 0 ) { 327 }else if ( qstrcmp( argv[a ] , "-preload-show" ) == 0 ) {
328 d->preloaded = TRUE; 328 d->preloaded = TRUE;
329 d->forceshow = TRUE; 329 d->forceshow = TRUE;
330 } 330 }
331 } 331 }
332 initTranslations(); 332 initTranslations();
333 applyStyle(); 333 applyStyle();
334 334
335 if ( type() == GuiServer ) 335 if ( type() == GuiServer )
336 ; 336 ;
337 337
338 installEventFilter( this ); 338 installEventFilter( this );
339 QPEMenuToolFocusManager::initialize(); 339 QPEMenuToolFocusManager::initialize();
340} 340}
341void QPEApplication::initTranslations() { 341void QPEApplication::initTranslations() {
342 // Translations add it 342 // Translations add it
343 QStringList langs = Global::languageList(); 343 QStringList langs = Global::languageList();
344 for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) { 344 for ( QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it ) {
345 QString lang = *it; 345 QString lang = *it;
346 346
347 QTranslator * trans; 347 QTranslator * trans;
348 QString tfn; 348 QString tfn;
349 349
350 trans = new QTranslator( this ); 350 trans = new QTranslator( this );
351 tfn = qpeDir() + "/i18n/" + lang + "/libqpe.qm"; 351 tfn = qpeDir() + "/i18n/" + lang + "/libqpe.qm";
352 if ( trans->load( tfn ) ) 352 if ( trans->load( tfn ) )
353 installTranslator( trans ); 353 installTranslator( trans );
354 else 354 else
355 delete trans; 355 delete trans;
356 356
357 trans = new QTranslator( this ); 357 trans = new QTranslator( this );
358 tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm"; 358 tfn = qpeDir() + "/i18n/" + lang + "/" + d->appName + ".qm";
359 if ( trans->load( tfn ) ) 359 if ( trans->load( tfn ) )
360 installTranslator( trans ); 360 installTranslator( trans );
361 else 361 else
362 delete trans; 362 delete trans;
363 } 363 }
364} 364}
365QString QPEApplication::qpeDir() { 365QString QPEApplication::qpeDir() {
366 const char * base = getenv( "OPIEDIR" ); 366 const char * base = getenv( "OPIEDIR" );
367 if ( base ) 367 if ( base )
368 return QString( base ) + "/"; 368 return QString( base ) + "/";
369 369
370 return QString( "../" ); 370 return QString( "../" );
371} 371}
372QString QPEApplication::documentDir() { 372QString QPEApplication::documentDir() {
373 const char* base = getenv( "HOME"); 373 const char* base = getenv( "HOME");
374 if ( base ) 374 if ( base )
375 return QString( base ) + "/Documents"; 375 return QString( base ) + "/Documents";
376 376
377 return QString( "../Documents" ); 377 return QString( "../Documents" );
378} 378}
379void QPEApplication::applyStyle() { 379void QPEApplication::applyStyle() {
380 Config config( "qpe" ); 380 Config config( "qpe" );
381 381
382 config.setGroup( "Appearance" ); 382 config.setGroup( "Appearance" );
383 383
384 // Widget style 384 // Widget style
385 QString style = config.readEntry( "Style", "Light" ); 385 QString style = config.readEntry( "Style", "Light" );
386 internalSetStyle( style ); 386 internalSetStyle( style );
387 387
388 // Colors 388 // Colors
389 QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) ); 389 QColor bgcolor( config.readEntry( "Background", "#E5E1D5" ) );
390 QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) ); 390 QColor btncolor( config.readEntry( "Button", "#D6CDBB" ) );
391 QPalette pal( btncolor, bgcolor ); 391 QPalette pal( btncolor, bgcolor );
392 QString color = config.readEntry( "Highlight", "#800000" ); 392 QString color = config.readEntry( "Highlight", "#800000" );
393 pal.setColor( QColorGroup::Highlight, QColor( color ) ); 393 pal.setColor( QColorGroup::Highlight, QColor( color ) );
394 color = config.readEntry( "HighlightedText", "#FFFFFF" ); 394 color = config.readEntry( "HighlightedText", "#FFFFFF" );
395 pal.setColor( QColorGroup::HighlightedText, QColor( color ) ); 395 pal.setColor( QColorGroup::HighlightedText, QColor( color ) );
396 color = config.readEntry( "Text", "#000000" ); 396 color = config.readEntry( "Text", "#000000" );
397 pal.setColor( QColorGroup::Text, QColor( color ) ); 397 pal.setColor( QColorGroup::Text, QColor( color ) );
398 color = config.readEntry( "ButtonText", "#000000" ); 398 color = config.readEntry( "ButtonText", "#000000" );
399 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) ); 399 pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor( color ) );
400 color = config.readEntry( "Base", "#FFFFFF" ); 400 color = config.readEntry( "Base", "#FFFFFF" );
401 pal.setColor( QColorGroup::Base, QColor( color ) ); 401 pal.setColor( QColorGroup::Base, QColor( color ) );
402 402
403 pal.setColor( QPalette::Disabled, QColorGroup::Text, 403 pal.setColor( QPalette::Disabled, QColorGroup::Text,
404 pal.color( QPalette::Active, QColorGroup::Background ).dark() ); 404 pal.color( QPalette::Active, QColorGroup::Background ).dark() );
405 405
406 setPalette( pal, TRUE ); 406 setPalette( pal, TRUE );
407 407
408 408
409 409
410 // Font 410 // Font
411 QString ff = config.readEntry( "FontFamily", font().family() ); 411 QString ff = config.readEntry( "FontFamily", font().family() );
412 int fs = config.readNumEntry( "FontSize", font().pointSize() ); 412 int fs = config.readNumEntry( "FontSize", font().pointSize() );
413 setFont( QFont(ff, fs) ); 413 setFont( QFont(ff, fs) );
414} 414}
415int QPEApplication::defaultRotation() { 415int QPEApplication::defaultRotation() {
416 return 0; 416 return 0;
417} 417}
418void QPEApplication::setDefaultRotation(int r ) { 418void QPEApplication::setDefaultRotation(int r ) {
419 419
420} 420}
421void QPEApplication::grabKeyboard() { 421void QPEApplication::grabKeyboard() {
422 QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d; 422 QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d;
423 if ( qApp->type() == QApplication::GuiServer ) 423 if ( qApp->type() == QApplication::GuiServer )
424 d->kbgrabber = 0; 424 d->kbgrabber = 0;
425 else { 425 else {
426 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" ); 426 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" );
427 e << d->appName; 427 e << d->appName;
428 428
429 d->kbgrabber = 2; // me 429 d->kbgrabber = 2; // me
430 } 430 }
431} 431}
432void QPEApplication::ungrabKeyboard() { 432void QPEApplication::ungrabKeyboard() {
433 QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d; 433 QPEApplication::Private * d = ( ( QPEApplication* ) qApp ) ->d;
434 if ( d->kbgrabber == 2 ) { 434 if ( d->kbgrabber == 2 ) {
435 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" ); 435 QCopEnvelope e( "QPE/System", "grabKeyboard(QString)" );
436 e << QString::null; 436 e << QString::null;
437 437
438 d->kbregrab = FALSE; 438 d->kbregrab = FALSE;
439 d->kbgrabber = 0; 439 d->kbgrabber = 0;
440 } 440 }
441} 441}
442void QPEApplication::showMainWidget( QWidget* wid, bool b) { 442void QPEApplication::showMainWidget( QWidget* wid, bool b) {
443 d->show(wid, b ); 443 d->show(wid, b );
444} 444}
445void QPEApplication::showMainDocumentWidget( QWidget* mw, bool m) { 445void QPEApplication::showMainDocumentWidget( QWidget* mw, bool m) {
446 if ( mw && argc() == 2 ) 446 if ( mw && argc() == 2 )
447 Global::setDocument( mw, QString::fromUtf8(argv()[1] ) ); 447 Global::setDocument( mw, QString::fromUtf8(argv()[1] ) );
448 448
449 d->show(mw, m ); 449 d->show(mw, m );
450} 450}
451void QPEApplication::showDialog( QDialog* d, bool nomax ) { 451void QPEApplication::showDialog( QDialog* d, bool nomax ) {
452 QSize sh = d->sizeHint(); 452 QSize sh = d->sizeHint();
453 int w = QMAX(sh.width(),d->width()); 453 int w = QMAX(sh.width(),d->width());
454 int h = QMAX(sh.height(),d->height()); 454 int h = QMAX(sh.height(),d->height());
455 if ( !nomax 455 if ( !nomax
456 && ( w > qApp->desktop()->width()*3/4 456 && ( w > qApp->desktop()->width()*3/4
457 || h > qApp->desktop()->height()*3/4 ) ) 457 || h > qApp->desktop()->height()*3/4 ) )
458 { 458 {
459 d->showMaximized(); 459 d->showMaximized();
460 } else { 460 } else {
461 d->resize(w,h); 461 d->resize(w,h);
462 d->show(); 462 d->show();
463 } 463 }
464} 464}
465int QPEApplication::execDialog( QDialog* d, bool nomax) { 465int QPEApplication::execDialog( QDialog* d, bool nomax) {
466 showDialog(d,nomax); 466 showDialog(d,nomax);
467 return d->exec(); 467 return d->exec();
468} 468}
469void QPEApplication::setKeepRunning() { 469void QPEApplication::setKeepRunning() {
470 if ( qApp && qApp->inherits( "QPEApplication" ) ) { 470 if ( qApp && qApp->inherits( "QPEApplication" ) ) {
471 QPEApplication * qpeApp = ( QPEApplication* ) qApp; 471 QPEApplication * qpeApp = ( QPEApplication* ) qApp;
472 qpeApp->d->keep_running = TRUE; 472 qpeApp->d->keep_running = TRUE;
473 } 473 }
474} 474}
475bool QPEApplication::keepRunning()const { 475bool QPEApplication::keepRunning()const {
476 return d->keep_running; 476 return d->keep_running;
477} 477}
478bool QPEApplication::keyboardGrabbed()const { 478bool QPEApplication::keyboardGrabbed()const {
479 return d->kbgrabber; 479 return d->kbgrabber;
480} 480}
481int QPEApplication::exec() { 481int QPEApplication::exec() {
482 /* now send the QCOP stuff gotten from the file */ 482 /* now send the QCOP stuff gotten from the file */
483 d->sendQCopQ(); 483 d->sendQCopQ();
484 484
485 if ( d->keep_running ) { 485 if ( d->keep_running ) {
486 qWarning("going to exec"); 486 qWarning("going to exec");
487 int a = QApplication::exec(); 487 int a = QApplication::exec();
488 qWarning("left"); 488 qWarning("left");
489 return a; 489 return a;
490 } 490 }
491 491
492 { 492 {
493 QCopEnvelope e( "QPE/System", "closing(QString)" ); 493 QCopEnvelope e( "QPE/System", "closing(QString)" );
494 e << d->appName; 494 e << d->appName;
495 } 495 }
496 qWarning("processing events!"); 496 qWarning("processing events!");
497 processEvents(); 497 processEvents();
498 return 0; 498 return 0;
499} 499}
500void QPEApplication::internalSetStyle( const QString& ) { 500void QPEApplication::internalSetStyle( const QString& ) {
501 501
502} 502}
503void QPEApplication::systemMessage( const QCString& chan, const QByteArray& ) { 503void QPEApplication::systemMessage( const QCString& chan, const QByteArray& ) {
504 qWarning("QPEApplication::systemMessage( %s )", chan.data() ); 504 qWarning("QPEApplication::systemMessage( %s )", chan.data() );
505} 505}
506void QPEApplication::pidMessage( const QCString& msg, const QByteArray& ) { 506void QPEApplication::pidMessage( const QCString& msg, const QByteArray& ) {
507 if ( msg == "flush()" ) { 507 if ( msg == "flush()" ) {
508 emit flush(); 508 emit flush();
509 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); 509 QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" );
510 e << d->appName; 510 e << d->appName;
511 }else if ( msg == "reload()" ) { 511 }else if ( msg == "reload()" ) {
512 emit reload(); 512 emit reload();
513 } 513 }
514 514
515} 515}
516void QPEApplication::timerEvent( QTimerEvent* e ) { 516void QPEApplication::timerEvent( QTimerEvent* e ) {
517 if ( e->timerId() == d->presstimer && d->presswidget ) { 517 if ( e->timerId() == d->presstimer && d->presswidget ) {
518 // Right pressed 518 // Right pressed
519 postEvent( d->presswidget, 519 postEvent( d->presswidget,
520 new QMouseEvent( QEvent::MouseButtonPress, d->presspos, 520 new QMouseEvent( QEvent::MouseButtonPress, d->presspos,
521 RightButton, LeftButton ) ); 521 RightButton, LeftButton ) );
522 killTimer( d->presstimer ); 522 killTimer( d->presstimer );
523 d->presstimer = 0; 523 d->presstimer = 0;
524 } 524 }
525} 525}
526 526
527// InputMethods Hints 527// InputMethods Hints
528namespace { 528namespace {
529 static QPtrDict<void>* inputMethodDict = 0; 529 static QPtrDict<void>* inputMethodDict = 0;
530 static void createInputMethodDict(){ 530 static void createInputMethodDict(){
531 if ( !inputMethodDict ) 531 if ( !inputMethodDict )
532 inputMethodDict = new QPtrDict<void>; 532 inputMethodDict = new QPtrDict<void>;
533 } 533 }
534 534
535 static QPtrDict<void>* stylusDict = 0; 535 static QPtrDict<void>* stylusDict = 0;
536 static void createDict() { 536 static void createDict() {
537 if ( !stylusDict ) 537 if ( !stylusDict )
538 stylusDict = new QPtrDict<void>; 538 stylusDict = new QPtrDict<void>;
539 } 539 }
540}; 540};
541 541
542void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode ) { 542void QPEApplication::setInputMethodHint( QWidget* w, InputMethodHint mode ) {
543 createInputMethodDict(); 543 createInputMethodDict();
544 if ( mode == Normal ) { 544 if ( mode == Normal ) {
545 inputMethodDict->remove 545 inputMethodDict->remove
546 ( w ); 546 ( w );
547 }else { 547 }else {
548 inputMethodDict->insert( w, ( void* ) mode ); 548 inputMethodDict->insert( w, ( void* ) mode );
549 } 549 }
550} 550}
551QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w) { 551QPEApplication::InputMethodHint QPEApplication::inputMethodHint( QWidget* w) {
552 if ( inputMethodDict && w ) 552 if ( inputMethodDict && w )
553 return ( InputMethodHint ) ( int ) inputMethodDict->find( w ); 553 return ( InputMethodHint ) ( int ) inputMethodDict->find( w );
554 return Normal; 554 return Normal;
555} 555}
556 556
557 557
558void QPEApplication::removeSenderFromStylusDict() { 558void QPEApplication::removeSenderFromStylusDict() {
559 stylusDict->remove( ( void* ) sender() ); 559 stylusDict->remove( ( void* ) sender() );
560 if ( d->presswidget == sender() ) 560 if ( d->presswidget == sender() )
561 d->presswidget = 0; 561 d->presswidget = 0;
562} 562}
563void QPEApplication::setStylusOperation( QWidget* w, StylusMode mode) { 563void QPEApplication::setStylusOperation( QWidget* w, StylusMode mode) {
564 createDict(); 564 createDict();
565 if ( mode == LeftOnly ) { 565 if ( mode == LeftOnly ) {
566 stylusDict->remove 566 stylusDict->remove
567 ( w ); 567 ( w );
568 w->removeEventFilter( qApp ); 568 w->removeEventFilter( qApp );
569 }else { 569 }else {
570 stylusDict->insert( w, ( void* ) mode ); 570 stylusDict->insert( w, ( void* ) mode );
571 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); 571 connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) );
572 w->installEventFilter( qApp ); 572 w->installEventFilter( qApp );
573 } 573 }
574} 574}
575QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w) { 575QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w) {
576 if ( stylusDict ) 576 if ( stylusDict )
577 return ( StylusMode ) ( int ) stylusDict->find( w ); 577 return ( StylusMode ) ( int ) stylusDict->find( w );
578 return LeftOnly; 578 return LeftOnly;
579} 579}
580 580
581// eventFilter...... 581// eventFilter......
582bool QPEApplication::eventFilter( QObject* o, QEvent* e ) { 582bool QPEApplication::eventFilter( QObject* o, QEvent* e ) {
583 /* 583 /*
584 * We want our WM to show Ok and a X button 584 * We want our WM to show Ok and a X button
585 * on dialogs 585 * on dialogs
586 * our part is to set the _NET_WM_CONTEXT_ACCEPT 586 * our part is to set the _NET_WM_CONTEXT_ACCEPT
587 * propery 587 * propery
588 * and then wait for a client message -zecke 588 * and then wait for a client message -zecke
589 * on show we will add the prop 589 * on show we will add the prop
590 */ 590 */
591 if (o->inherits("QDialog") && e->type() == QEvent::Show ) { 591 if (o->inherits("QDialog") && e->type() == QEvent::Show ) {
592 QDialog* dialog = (QDialog*)o; 592 QDialog* dialog = (QDialog*)o;
593 Atom wm_prot[45]; 593 Atom wm_prot[45];
594 int n = 0; 594 int n = 0;
595 wm_prot[n++] = d->wm_delete_window; 595 wm_prot[n++] = d->wm_delete_window;
596 wm_prot[n++] = d->wm_take_focus; 596 wm_prot[n++] = d->wm_take_focus;
597 wm_prot[n++] = d->wm_context_accept; 597 wm_prot[n++] = d->wm_context_accept;
598 if ( dialog->testWFlags( WStyle_ContextHelp ) ) 598 if ( dialog->testWFlags( WStyle_ContextHelp ) )
599 wm_prot[n++] = d->wm_context_help; 599 wm_prot[n++] = d->wm_context_help;
600 XSetWMProtocols( qt_xdisplay(), dialog->winId(), wm_prot, n ); 600 XSetWMProtocols( qt_xdisplay(), dialog->winId(), wm_prot, n );
601 return TRUE; // should be save 601 return TRUE; // should be save
602 } 602 }
603 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { 603 if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) {
604 QMouseEvent * me = ( QMouseEvent* ) e; 604 QMouseEvent * me = ( QMouseEvent* ) e;
605 StylusMode mode = (StylusMode)(int)stylusDict->find(o); 605 StylusMode mode = (StylusMode)(int)stylusDict->find(o);
606 switch (mode) { 606 switch (mode) {
607 case RightOnHold: 607 case RightOnHold:
608 switch ( me->type() ) { 608 switch ( me->type() ) {
609 case QEvent::MouseButtonPress: 609 case QEvent::MouseButtonPress:
610 if ( me->button() == LeftButton ) { 610 if ( me->button() == LeftButton ) {
611 d->presstimer = startTimer(500); // #### pref. 611 d->presstimer = startTimer(500); // #### pref.
612 d->presswidget = (QWidget*)o; 612 d->presswidget = (QWidget*)o;
613 d->presspos = me->pos(); 613 d->presspos = me->pos();
614 d->rightpressed = FALSE; 614 d->rightpressed = FALSE;
615 } 615 }
616 break; 616 break;
617 case QEvent::MouseMove: 617 case QEvent::MouseMove:
618 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { 618 if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) {
619 killTimer(d->presstimer); 619 killTimer(d->presstimer);
620 d->presstimer = 0; 620 d->presstimer = 0;
621 } 621 }
622 break; 622 break;
623 case QEvent::MouseButtonRelease: 623 case QEvent::MouseButtonRelease:
624 if ( me->button() == LeftButton ) { 624 if ( me->button() == LeftButton ) {
625 if ( d->presstimer ) { 625 if ( d->presstimer ) {
626 killTimer(d->presstimer); 626 killTimer(d->presstimer);
627 d->presstimer = 0; 627 d->presstimer = 0;
628 } 628 }
629 if ( d->rightpressed && d->presswidget ) { 629 if ( d->rightpressed && d->presswidget ) {
630 // Right released 630 // Right released
631 postEvent( d->presswidget, 631 postEvent( d->presswidget,
632 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), 632 new QMouseEvent( QEvent::MouseButtonRelease, me->pos(),
633 RightButton, LeftButton + RightButton ) ); 633 RightButton, LeftButton + RightButton ) );
634 // Left released, off-widget 634 // Left released, off-widget
635 postEvent( d->presswidget, 635 postEvent( d->presswidget,
636 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), 636 new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1),
637 LeftButton, LeftButton ) ); 637 LeftButton, LeftButton ) );
638 postEvent( d->presswidget, 638 postEvent( d->presswidget,
639 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), 639 new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1),
640 LeftButton, LeftButton ) ); 640 LeftButton, LeftButton ) );
641 d->rightpressed = FALSE; 641 d->rightpressed = FALSE;
642 return TRUE; // don't send the real Left release 642 return TRUE; // don't send the real Left release
643 } 643 }
644 } 644 }
645 break; 645 break;
646 default: 646 default:
647 break; 647 break;
648 } 648 }
649 break; 649 break;
650 default: 650 default:
651 ; 651 ;
652 } 652 }
653 } 653 }
654 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { 654 else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) {
655 QKeyEvent *ke = (QKeyEvent *)e; 655 QKeyEvent *ke = (QKeyEvent *)e;
656 if ( ke->key() == Key_Enter ) { 656 if ( ke->key() == Key_Enter ) {
657 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { 657 if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) {
658 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', 658 postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ',
659 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); 659 ke->state(), " ", ke->isAutoRepeat(), ke->count() ) );
660 return TRUE; 660 return TRUE;
661 } 661 }
662 } 662 }
663 } 663 }
664 return FALSE; 664 return FALSE;
665} 665}
666 666
667// Quit stuff 667// Quit stuff
668void QPEApplication::restart() { 668void QPEApplication::restart() {
669 669
670} 670}
671void QPEApplication::shutdown() { 671void QPEApplication::shutdown() {
672 672
673} 673}
674void QPEApplication::tryQuit() { 674void QPEApplication::tryQuit() {
675 qWarning("TryQuit!!"); 675 qWarning("TryQuit!!");
676 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 ) 676 if ( activeModalWidget() || strcmp( argv() [ 0 ], "embeddedkonsole" ) == 0 )
677 return ; // Inside modal loop or konsole. Too hard to save state. 677 return ; // Inside modal loop or konsole. Too hard to save state.
678 { 678 {
679 QCopEnvelope e( "QPE/System", "closing(QString)" ); 679 QCopEnvelope e( "QPE/System", "closing(QString)" );
680 e << d->appName; 680 e << d->appName;
681 } 681 }
682 processEvents(); 682 processEvents();
683 683
684 quit(); 684 quit();
685} 685}
686void QPEApplication::hideOrQuit() { 686void QPEApplication::hideOrQuit() {
687 qWarning("hide or close"); 687 qWarning("hide or close");
688 processEvents(); 688 processEvents();
689 qWarning("past processing"); 689 qWarning("past processing");
690 690
691 // If we are a preloaded application we don't actually quit, so emit 691 // If we are a preloaded application we don't actually quit, so emit
692 // a System message indicating we're quasi-closing. 692 // a System message indicating we're quasi-closing.
693 if ( d->preloaded && d->qpe_main_widget ) 693 if ( d->preloaded && d->qpe_main_widget )
694 694
695 { 695 {
696 qWarning("hiding"); 696 qWarning("hiding");
697 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" ); 697 QCopEnvelope e("QPE/System", "fastAppHiding(QString)" );
698 e << d->appName; 698 e << d->appName;
699 d->qpe_main_widget->hide(); 699 d->qpe_main_widget->hide();
700 } 700 }
701 else 701 else
702 quit(); 702 quit();
703} 703}
704 704
705/*! 705/*!
706 \internal 706 \internal
707*/ 707*/
708void QPEApplication::prepareForTermination( bool willrestart ) 708void QPEApplication::prepareForTermination( bool willrestart )
709{ 709{
710 if ( willrestart ) { 710 if ( willrestart ) {
711 // Draw a big wait icon, the image can be altered in later revisions 711 // Draw a big wait icon, the image can be altered in later revisions
712 // QWidget *d = QApplication::desktop(); 712 // QWidget *d = QApplication::desktop();
713 QImage img = Resource::loadImage( "launcher/new_wait" ); 713 QImage img = Resource::loadImage( "launcher/new_wait" );
714 QPixmap pix; 714 QPixmap pix;
715 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) ); 715 pix.convertFromImage( img.smoothScale( 1 * img.width(), 1 * img.height() ) );
716 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize | 716 QLabel *lblWait = new QLabel( 0, "wait hack!", QWidget::WStyle_Customize |
717 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); 717 QWidget::WStyle_NoBorder | QWidget::WStyle_Tool );
718 lblWait->setPixmap( pix ); 718 lblWait->setPixmap( pix );
719 lblWait->setAlignment( QWidget::AlignCenter ); 719 lblWait->setAlignment( QWidget::AlignCenter );
720 lblWait->show(); 720 lblWait->show();
721 lblWait->showMaximized(); 721 lblWait->showMaximized();
722 } 722 }
723#ifndef SINGLE_APP 723#ifndef SINGLE_APP
724 { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); 724 { QCopEnvelope envelope( "QPE/System", "forceQuit()" );
725 } 725 }
726 processEvents(); // ensure the message goes out. 726 processEvents(); // ensure the message goes out.
727 sleep( 1 ); // You have 1 second to comply. 727 sleep( 1 ); // You have 1 second to comply.
728#endif 728#endif
729} 729}
730int QPEApplication::x11ClientMessage(QWidget* w, XEvent* event, bool b ) { 730int QPEApplication::x11ClientMessage(QWidget* w, XEvent* event, bool b ) {
731 qWarning("X11 ClientMessage %d %d", event->type, ClientMessage); 731 qWarning("X11 ClientMessage %d %d", event->type, ClientMessage);
732 if ( event->type == ClientMessage ) { 732 if ( event->type == ClientMessage ) {
733 if ( (event->xclient.message_type == d->wm_protocols) && 733 if ( (event->xclient.message_type == d->wm_protocols) &&
734 (event->xclient.data.l[0] == d->wm_context_accept ) ) { 734 (event->xclient.data.l[0] == d->wm_context_accept ) ) {
735 qWarning("accepted!!!"); 735 qWarning("accepted!!!");
736 /* 736 /*
737 * I'm not sure if we should use activeWidget 737 * I'm not sure if we should use activeWidget
738 * or activeModalWidget 738 * or activeModalWidget
739 * a QDialog could be not modal too 739 * a QDialog could be not modal too
740 */ 740 */
741 if ( w->inherits("QDialog" ) ) { 741 if ( w->inherits("QDialog" ) ) {
742 qWarning("inherits QDialog!!!"); 742 qWarning("inherits QDialog!!!");
743 QDialog* dia = (QDialog*)w; 743 QDialog* dia = (QDialog*)w;
744 /* 744 /*
745 * call it directly or via QTimer::singleShot? 745 * call it directly or via QTimer::singleShot?
746 */ 746 */
747 QTimer::singleShot(0, dia, SLOT(accept() ) ); 747 QTimer::singleShot(0, dia, SLOT(accept() ) );
748 return 0; 748 return 0;
749 } 749 }
750 750
751 } 751 }
752 } 752 }
753 return QApplication::x11ClientMessage(w, event, b ); 753 return QApplication::x11ClientMessage(w, event, b );
754} 754}
755 755
756#define KeyPress XKeyPress 756#define KeyPress XKeyPress
757#define KeyRelease XKeyRelease 757#define KeyRelease XKeyRelease
758 758
759#if defined(OPIE_NEW_MALLOC) 759#if defined(OPIE_NEW_MALLOC)
760 760
761// The libraries with the skiff package (and possibly others) have 761// The libraries with the skiff package (and possibly others) have
762// completely useless implementations of builtin new and delete that 762// completely useless implementations of builtin new and delete that
763// use about 50% of your CPU. Here we revert to the simple libc 763// use about 50% of your CPU. Here we revert to the simple libc
764// functions. 764// functions.
765 765
766void* operator new[]( size_t size ) 766void* operator new[]( size_t size )
767{ 767{
768 return malloc( size ); 768 return malloc( size );
769} 769}
770 770
771void* operator new( size_t size ) 771void* operator new( size_t size )
772{ 772{
773 return malloc( size ); 773 return malloc( size );
774} 774}
775 775
776void operator delete[]( void* p ) 776void operator delete[]( void* p )
777{ 777{
778 free( p ); 778 free( p );
779} 779}
780 780
781void operator delete[]( void* p, size_t /*size*/ ) 781void operator delete[]( void* p, size_t /*size*/ )
782{ 782{
783 free( p ); 783 free( p );
784} 784}
785 785
786void operator delete( void* p ) 786void operator delete( void* p )
787{ 787{
788 free( p ); 788 free( p );
789} 789}
790 790
791void operator delete( void* p, size_t /*size*/ ) 791void operator delete( void* p, size_t /*size*/ )
792{ 792{
793 free( p ); 793 free( p );
794} 794}
795 795
796#endif 796#endif