57 files changed, 123 insertions, 123 deletions
diff --git a/core/apps/embeddedkonsole/commandeditdialog.cpp b/core/apps/embeddedkonsole/commandeditdialog.cpp index 97b0a9e..dd35466 100644 --- a/core/apps/embeddedkonsole/commandeditdialog.cpp +++ b/core/apps/embeddedkonsole/commandeditdialog.cpp | |||
@@ -1,199 +1,199 @@ | |||
1 | //comandeditdialog.cpp | 1 | //comandeditdialog.cpp |
2 | 2 | ||
3 | #include "commandeditdialog.h" | 3 | #include "commandeditdialog.h" |
4 | #include "playlistselection.h" | 4 | #include "playlistselection.h" |
5 | #include <qstring.h> | 5 | #include <qstring.h> |
6 | #include <qpe/config.h> | 6 | #include <qpe/config.h> |
7 | #include <qpe/qpetoolbar.h> | 7 | #include <qtoolbar.h> |
8 | #include <qwidget.h> | 8 | #include <qwidget.h> |
9 | #include <qmenubar.h> | 9 | #include <qmenubar.h> |
10 | #include <qpe/resource.h> | 10 | #include <qpe/resource.h> |
11 | #include <qlist.h> | 11 | #include <qlist.h> |
12 | #include <qtoolbutton.h> | 12 | #include <qtoolbutton.h> |
13 | #include <qvbox.h> | 13 | #include <qvbox.h> |
14 | #include <qlistview.h> | 14 | #include <qlistview.h> |
15 | #include <qlineedit.h> | 15 | #include <qlineedit.h> |
16 | #include <qheader.h> | 16 | #include <qheader.h> |
17 | #include <qlabel.h> | 17 | #include <qlabel.h> |
18 | #include <qmessagebox.h> | 18 | #include <qmessagebox.h> |
19 | #include "smallcommandeditdialogbase.h" | 19 | #include "smallcommandeditdialogbase.h" |
20 | 20 | ||
21 | CommandEditDialog::CommandEditDialog(QWidget *parent, const char* name, WFlags fl ) | 21 | CommandEditDialog::CommandEditDialog(QWidget *parent, const char* name, WFlags fl ) |
22 | : CommandEditDialogBase(parent, name, TRUE, fl) | 22 | : CommandEditDialogBase(parent, name, TRUE, fl) |
23 | 23 | ||
24 | { | 24 | { |
25 | m_SuggestedCommandList->addColumn( tr("Command Selection") ); | 25 | m_SuggestedCommandList->addColumn( tr("Command Selection") ); |
26 | m_SuggestedCommandList->header()->hide(); | 26 | m_SuggestedCommandList->header()->hide(); |
27 | m_SuggestedCommandList->setSorting(-1,FALSE); | 27 | m_SuggestedCommandList->setSorting(-1,FALSE); |
28 | m_SuggestedCommandList->clearSelection(); | 28 | m_SuggestedCommandList->clearSelection(); |
29 | m_SuggestedCommandList->setSorting(0,TRUE); | 29 | m_SuggestedCommandList->setSorting(0,TRUE); |
30 | QListViewItem *item; | 30 | QListViewItem *item; |
31 | item = new QListViewItem( m_SuggestedCommandList,"export "); | 31 | item = new QListViewItem( m_SuggestedCommandList,"export "); |
32 | item = new QListViewItem( m_SuggestedCommandList,"ifconfig "); | 32 | item = new QListViewItem( m_SuggestedCommandList,"ifconfig "); |
33 | item = new QListViewItem( m_SuggestedCommandList,"ipkg "); | 33 | item = new QListViewItem( m_SuggestedCommandList,"ipkg "); |
34 | item = new QListViewItem( m_SuggestedCommandList,"gzip "); | 34 | item = new QListViewItem( m_SuggestedCommandList,"gzip "); |
35 | item = new QListViewItem( m_SuggestedCommandList,"gunzip "); | 35 | item = new QListViewItem( m_SuggestedCommandList,"gunzip "); |
36 | item = new QListViewItem( m_SuggestedCommandList,"chgrp "); | 36 | item = new QListViewItem( m_SuggestedCommandList,"chgrp "); |
37 | item = new QListViewItem( m_SuggestedCommandList,"chown "); | 37 | item = new QListViewItem( m_SuggestedCommandList,"chown "); |
38 | item = new QListViewItem( m_SuggestedCommandList,"date "); | 38 | item = new QListViewItem( m_SuggestedCommandList,"date "); |
39 | item = new QListViewItem( m_SuggestedCommandList,"dd "); | 39 | item = new QListViewItem( m_SuggestedCommandList,"dd "); |
40 | item = new QListViewItem( m_SuggestedCommandList,"dmesg "); | 40 | item = new QListViewItem( m_SuggestedCommandList,"dmesg "); |
41 | item = new QListViewItem( m_SuggestedCommandList,"fuser "); | 41 | item = new QListViewItem( m_SuggestedCommandList,"fuser "); |
42 | item = new QListViewItem( m_SuggestedCommandList,"hostname "); | 42 | item = new QListViewItem( m_SuggestedCommandList,"hostname "); |
43 | item = new QListViewItem( m_SuggestedCommandList,"kill "); | 43 | item = new QListViewItem( m_SuggestedCommandList,"kill "); |
44 | item = new QListViewItem( m_SuggestedCommandList,"killall "); | 44 | item = new QListViewItem( m_SuggestedCommandList,"killall "); |
45 | item = new QListViewItem( m_SuggestedCommandList,"ln "); | 45 | item = new QListViewItem( m_SuggestedCommandList,"ln "); |
46 | item = new QListViewItem( m_SuggestedCommandList,"ln -s "); | 46 | item = new QListViewItem( m_SuggestedCommandList,"ln -s "); |
47 | item = new QListViewItem( m_SuggestedCommandList,"lsmod"); | 47 | item = new QListViewItem( m_SuggestedCommandList,"lsmod"); |
48 | item = new QListViewItem( m_SuggestedCommandList,"depmod -a"); | 48 | item = new QListViewItem( m_SuggestedCommandList,"depmod -a"); |
49 | item = new QListViewItem( m_SuggestedCommandList,"modprobe "); | 49 | item = new QListViewItem( m_SuggestedCommandList,"modprobe "); |
50 | item = new QListViewItem( m_SuggestedCommandList,"mount "); | 50 | item = new QListViewItem( m_SuggestedCommandList,"mount "); |
51 | item = new QListViewItem( m_SuggestedCommandList,"more "); | 51 | item = new QListViewItem( m_SuggestedCommandList,"more "); |
52 | item = new QListViewItem( m_SuggestedCommandList,"sort "); | 52 | item = new QListViewItem( m_SuggestedCommandList,"sort "); |
53 | item = new QListViewItem( m_SuggestedCommandList,"touch "); | 53 | item = new QListViewItem( m_SuggestedCommandList,"touch "); |
54 | item = new QListViewItem( m_SuggestedCommandList,"umount "); | 54 | item = new QListViewItem( m_SuggestedCommandList,"umount "); |
55 | item = new QListViewItem( m_SuggestedCommandList,"mknod "); | 55 | item = new QListViewItem( m_SuggestedCommandList,"mknod "); |
56 | item = new QListViewItem( m_SuggestedCommandList,"netstat "); | 56 | item = new QListViewItem( m_SuggestedCommandList,"netstat "); |
57 | item = new QListViewItem( m_SuggestedCommandList,"route "); | 57 | item = new QListViewItem( m_SuggestedCommandList,"route "); |
58 | item = new QListViewItem( m_SuggestedCommandList,"cardctl eject "); | 58 | item = new QListViewItem( m_SuggestedCommandList,"cardctl eject "); |
59 | m_SuggestedCommandList->setSelected(m_SuggestedCommandList->firstChild(),TRUE); | 59 | m_SuggestedCommandList->setSelected(m_SuggestedCommandList->firstChild(),TRUE); |
60 | m_SuggestedCommandList->sort(); | 60 | m_SuggestedCommandList->sort(); |
61 | 61 | ||
62 | connect( m_SuggestedCommandList, SIGNAL( clicked( QListViewItem * ) ), m_PlayListSelection, SLOT( addToSelection( QListViewItem *) ) ); | 62 | connect( m_SuggestedCommandList, SIGNAL( clicked( QListViewItem * ) ), m_PlayListSelection, SLOT( addToSelection( QListViewItem *) ) ); |
63 | 63 | ||
64 | 64 | ||
65 | 65 | ||
66 | ToolButton1->setTextLabel("new"); | 66 | ToolButton1->setTextLabel("new"); |
67 | ToolButton1->setPixmap(Resource::loadPixmap("new")); | 67 | ToolButton1->setPixmap(Resource::loadPixmap("new")); |
68 | ToolButton1->setAutoRaise(TRUE); | 68 | ToolButton1->setAutoRaise(TRUE); |
69 | ToolButton1->setFocusPolicy(QWidget::NoFocus); | 69 | ToolButton1->setFocusPolicy(QWidget::NoFocus); |
70 | connect(ToolButton1,SIGNAL(clicked()),this,SLOT(showAddDialog())); | 70 | connect(ToolButton1,SIGNAL(clicked()),this,SLOT(showAddDialog())); |
71 | 71 | ||
72 | ToolButton2->setTextLabel("edit"); | 72 | ToolButton2->setTextLabel("edit"); |
73 | ToolButton2->setPixmap(Resource::loadPixmap("edit")); | 73 | ToolButton2->setPixmap(Resource::loadPixmap("edit")); |
74 | ToolButton2->setAutoRaise(TRUE); | 74 | ToolButton2->setAutoRaise(TRUE); |
75 | ToolButton2->setFocusPolicy(QWidget::NoFocus); | 75 | ToolButton2->setFocusPolicy(QWidget::NoFocus); |
76 | connect(ToolButton2,SIGNAL(clicked()),this,SLOT(showEditDialog())); | 76 | connect(ToolButton2,SIGNAL(clicked()),this,SLOT(showEditDialog())); |
77 | 77 | ||
78 | ToolButton3->setTextLabel("delete"); | 78 | ToolButton3->setTextLabel("delete"); |
79 | ToolButton3->setPixmap(Resource::loadPixmap("editdelete")); | 79 | ToolButton3->setPixmap(Resource::loadPixmap("editdelete")); |
80 | ToolButton3->setAutoRaise(TRUE); | 80 | ToolButton3->setAutoRaise(TRUE); |
81 | ToolButton3->setFocusPolicy(QWidget::NoFocus); | 81 | ToolButton3->setFocusPolicy(QWidget::NoFocus); |
82 | connect(ToolButton3,SIGNAL(clicked()),m_PlayListSelection,SLOT(removeSelected())); | 82 | connect(ToolButton3,SIGNAL(clicked()),m_PlayListSelection,SLOT(removeSelected())); |
83 | 83 | ||
84 | ToolButton4->setTextLabel("up"); | 84 | ToolButton4->setTextLabel("up"); |
85 | ToolButton4->setPixmap(Resource::loadPixmap("up")); | 85 | ToolButton4->setPixmap(Resource::loadPixmap("up")); |
86 | ToolButton4->setAutoRaise(TRUE); | 86 | ToolButton4->setAutoRaise(TRUE); |
87 | ToolButton4->setFocusPolicy(QWidget::NoFocus); | 87 | ToolButton4->setFocusPolicy(QWidget::NoFocus); |
88 | connect(ToolButton4,SIGNAL(clicked()),m_PlayListSelection,SLOT(moveSelectedUp())); | 88 | connect(ToolButton4,SIGNAL(clicked()),m_PlayListSelection,SLOT(moveSelectedUp())); |
89 | 89 | ||
90 | ToolButton5->setTextLabel("down"); | 90 | ToolButton5->setTextLabel("down"); |
91 | ToolButton5->setPixmap(Resource::loadPixmap("down")); | 91 | ToolButton5->setPixmap(Resource::loadPixmap("down")); |
92 | ToolButton5->setAutoRaise(TRUE); | 92 | ToolButton5->setAutoRaise(TRUE); |
93 | ToolButton5->setFocusPolicy(QWidget::NoFocus); | 93 | ToolButton5->setFocusPolicy(QWidget::NoFocus); |
94 | 94 | ||
95 | connect(ToolButton5,SIGNAL(clicked()),m_PlayListSelection,SLOT(moveSelectedDown())); | 95 | connect(ToolButton5,SIGNAL(clicked()),m_PlayListSelection,SLOT(moveSelectedDown())); |
96 | 96 | ||
97 | 97 | ||
98 | 98 | ||
99 | 99 | ||
100 | QListViewItem *current = m_SuggestedCommandList->selectedItem(); | 100 | QListViewItem *current = m_SuggestedCommandList->selectedItem(); |
101 | if ( current ) | 101 | if ( current ) |
102 | item->moveItem( current ); | 102 | item->moveItem( current ); |
103 | m_SuggestedCommandList->setSelected( item, TRUE ); | 103 | m_SuggestedCommandList->setSelected( item, TRUE ); |
104 | m_SuggestedCommandList->ensureItemVisible( m_SuggestedCommandList->selectedItem() ); | 104 | m_SuggestedCommandList->ensureItemVisible( m_SuggestedCommandList->selectedItem() ); |
105 | Config cfg("Konsole"); | 105 | Config cfg("Konsole"); |
106 | cfg.setGroup("Commands"); | 106 | cfg.setGroup("Commands"); |
107 | if (cfg.readEntry("Commands Set","FALSE") == "TRUE") { | 107 | if (cfg.readEntry("Commands Set","FALSE") == "TRUE") { |
108 | for (int i = 0; i < 100; i++) { | 108 | for (int i = 0; i < 100; i++) { |
109 | QString tmp; | 109 | QString tmp; |
110 | tmp = cfg.readEntry( QString::number(i),""); | 110 | tmp = cfg.readEntry( QString::number(i),""); |
111 | if (!tmp.isEmpty()) | 111 | if (!tmp.isEmpty()) |
112 | m_PlayListSelection->addStringToSelection(tmp); | 112 | m_PlayListSelection->addStringToSelection(tmp); |
113 | } | 113 | } |
114 | } else { | 114 | } else { |
115 | 115 | ||
116 | m_PlayListSelection->addStringToSelection("ls "); | 116 | m_PlayListSelection->addStringToSelection("ls "); |
117 | m_PlayListSelection->addStringToSelection("cardctl eject"); | 117 | m_PlayListSelection->addStringToSelection("cardctl eject"); |
118 | m_PlayListSelection->addStringToSelection("cat "); | 118 | m_PlayListSelection->addStringToSelection("cat "); |
119 | m_PlayListSelection->addStringToSelection("cd "); | 119 | m_PlayListSelection->addStringToSelection("cd "); |
120 | m_PlayListSelection->addStringToSelection("chmod "); | 120 | m_PlayListSelection->addStringToSelection("chmod "); |
121 | m_PlayListSelection->addStringToSelection("cp "); | 121 | m_PlayListSelection->addStringToSelection("cp "); |
122 | m_PlayListSelection->addStringToSelection("dc "); | 122 | m_PlayListSelection->addStringToSelection("dc "); |
123 | m_PlayListSelection->addStringToSelection("df "); | 123 | m_PlayListSelection->addStringToSelection("df "); |
124 | m_PlayListSelection->addStringToSelection("dmesg"); | 124 | m_PlayListSelection->addStringToSelection("dmesg"); |
125 | m_PlayListSelection->addStringToSelection("echo "); | 125 | m_PlayListSelection->addStringToSelection("echo "); |
126 | m_PlayListSelection->addStringToSelection("env"); | 126 | m_PlayListSelection->addStringToSelection("env"); |
127 | m_PlayListSelection->addStringToSelection("find "); | 127 | m_PlayListSelection->addStringToSelection("find "); |
128 | m_PlayListSelection->addStringToSelection("free"); | 128 | m_PlayListSelection->addStringToSelection("free"); |
129 | m_PlayListSelection->addStringToSelection("grep "); | 129 | m_PlayListSelection->addStringToSelection("grep "); |
130 | m_PlayListSelection->addStringToSelection("ifconfig "); | 130 | m_PlayListSelection->addStringToSelection("ifconfig "); |
131 | m_PlayListSelection->addStringToSelection("ipkg "); | 131 | m_PlayListSelection->addStringToSelection("ipkg "); |
132 | m_PlayListSelection->addStringToSelection("mkdir "); | 132 | m_PlayListSelection->addStringToSelection("mkdir "); |
133 | m_PlayListSelection->addStringToSelection("mv "); | 133 | m_PlayListSelection->addStringToSelection("mv "); |
134 | m_PlayListSelection->addStringToSelection("nc localhost 7776"); | 134 | m_PlayListSelection->addStringToSelection("nc localhost 7776"); |
135 | m_PlayListSelection->addStringToSelection("nc localhost 7777"); | 135 | m_PlayListSelection->addStringToSelection("nc localhost 7777"); |
136 | m_PlayListSelection->addStringToSelection("nslookup "); | 136 | m_PlayListSelection->addStringToSelection("nslookup "); |
137 | m_PlayListSelection->addStringToSelection("ping "); | 137 | m_PlayListSelection->addStringToSelection("ping "); |
138 | m_PlayListSelection->addStringToSelection("ps aux"); | 138 | m_PlayListSelection->addStringToSelection("ps aux"); |
139 | m_PlayListSelection->addStringToSelection("pwd "); | 139 | m_PlayListSelection->addStringToSelection("pwd "); |
140 | m_PlayListSelection->addStringToSelection("rm "); | 140 | m_PlayListSelection->addStringToSelection("rm "); |
141 | m_PlayListSelection->addStringToSelection("rmdir "); | 141 | m_PlayListSelection->addStringToSelection("rmdir "); |
142 | m_PlayListSelection->addStringToSelection("route "); | 142 | m_PlayListSelection->addStringToSelection("route "); |
143 | m_PlayListSelection->addStringToSelection("set "); | 143 | m_PlayListSelection->addStringToSelection("set "); |
144 | m_PlayListSelection->addStringToSelection("traceroute"); | 144 | m_PlayListSelection->addStringToSelection("traceroute"); |
145 | 145 | ||
146 | } | 146 | } |
147 | } | 147 | } |
148 | CommandEditDialog::~CommandEditDialog() | 148 | CommandEditDialog::~CommandEditDialog() |
149 | { | 149 | { |
150 | } | 150 | } |
151 | 151 | ||
152 | void CommandEditDialog::accept() | 152 | void CommandEditDialog::accept() |
153 | { | 153 | { |
154 | int i = 0; | 154 | int i = 0; |
155 | Config *cfg = new Config("Konsole"); | 155 | Config *cfg = new Config("Konsole"); |
156 | cfg->setGroup("Commands"); | 156 | cfg->setGroup("Commands"); |
157 | cfg->clearGroup(); | 157 | cfg->clearGroup(); |
158 | 158 | ||
159 | QListViewItemIterator it( m_PlayListSelection ); | 159 | QListViewItemIterator it( m_PlayListSelection ); |
160 | 160 | ||
161 | for ( ; it.current(); ++it ) { | 161 | for ( ; it.current(); ++it ) { |
162 | // qDebug(it.current()->text(0)); | 162 | // qDebug(it.current()->text(0)); |
163 | cfg->writeEntry(QString::number(i),it.current()->text(0)); | 163 | cfg->writeEntry(QString::number(i),it.current()->text(0)); |
164 | i++; | 164 | i++; |
165 | 165 | ||
166 | } | 166 | } |
167 | cfg->writeEntry("Commands Set","TRUE"); | 167 | cfg->writeEntry("Commands Set","TRUE"); |
168 | // qDebug("CommandEditDialog::accept() - written"); | 168 | // qDebug("CommandEditDialog::accept() - written"); |
169 | delete cfg; | 169 | delete cfg; |
170 | emit commandsEdited(); | 170 | emit commandsEdited(); |
171 | close(); | 171 | close(); |
172 | 172 | ||
173 | 173 | ||
174 | 174 | ||
175 | 175 | ||
176 | 176 | ||
177 | } | 177 | } |
178 | 178 | ||
179 | void CommandEditDialog::showEditDialog() | 179 | void CommandEditDialog::showEditDialog() |
180 | { | 180 | { |
181 | editCommandBase *d = new editCommandBase(this,"smalleditdialog", TRUE); | 181 | editCommandBase *d = new editCommandBase(this,"smalleditdialog", TRUE); |
182 | d->setCaption("Edit command"); | 182 | d->setCaption("Edit command"); |
183 | d->TextLabel->setText("Edit command:"); | 183 | d->TextLabel->setText("Edit command:"); |
184 | d->commandEdit->setText(m_PlayListSelection->currentItem()->text(0)); | 184 | d->commandEdit->setText(m_PlayListSelection->currentItem()->text(0)); |
185 | int i = d->exec(); | 185 | int i = d->exec(); |
186 | if ((i==1) && (!(d->commandEdit->text()).isEmpty())) | 186 | if ((i==1) && (!(d->commandEdit->text()).isEmpty())) |
187 | m_PlayListSelection->currentItem()->setText(0,(d->commandEdit->text())); | 187 | m_PlayListSelection->currentItem()->setText(0,(d->commandEdit->text())); |
188 | } | 188 | } |
189 | 189 | ||
190 | void CommandEditDialog::showAddDialog() | 190 | void CommandEditDialog::showAddDialog() |
191 | { | 191 | { |
192 | 192 | ||
193 | editCommandBase *d = new editCommandBase(this,"smalleditdialog", TRUE); | 193 | editCommandBase *d = new editCommandBase(this,"smalleditdialog", TRUE); |
194 | int i = d->exec(); | 194 | int i = d->exec(); |
195 | if ((i==1) && (!(d->commandEdit->text()).isEmpty())) | 195 | if ((i==1) && (!(d->commandEdit->text()).isEmpty())) |
196 | m_PlayListSelection->addStringToSelection(d->commandEdit->text()); | 196 | m_PlayListSelection->addStringToSelection(d->commandEdit->text()); |
197 | 197 | ||
198 | } | 198 | } |
199 | 199 | ||
diff --git a/core/apps/embeddedkonsole/konsole.cpp b/core/apps/embeddedkonsole/konsole.cpp index d855d90..fff2f68 100644 --- a/core/apps/embeddedkonsole/konsole.cpp +++ b/core/apps/embeddedkonsole/konsole.cpp | |||
@@ -1,1102 +1,1102 @@ | |||
1 | /* ---------------------------------------------------------------------- */ | 1 | /* ---------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [main.C] Konsole */ | 3 | /* [main.C] Konsole */ |
4 | /* */ | 4 | /* */ |
5 | /* ---------------------------------------------------------------------- */ | 5 | /* ---------------------------------------------------------------------- */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole, an X terminal. */ | 9 | /* This file is part of Konsole, an X terminal. */ |
10 | /* */ | 10 | /* */ |
11 | /* The material contained in here more or less directly orginates from */ | 11 | /* The material contained in here more or less directly orginates from */ |
12 | /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ | 12 | /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ |
13 | /* */ | 13 | /* */ |
14 | /* ---------------------------------------------------------------------- */ | 14 | /* ---------------------------------------------------------------------- */ |
15 | /* */ | 15 | /* */ |
16 | /* Ported Konsole to Qt/Embedded */ | 16 | /* Ported Konsole to Qt/Embedded */ |
17 | /* */ | 17 | /* */ |
18 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 18 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
19 | /* */ | 19 | /* */ |
20 | /* -------------------------------------------------------------------------- */ | 20 | /* -------------------------------------------------------------------------- */ |
21 | // enhancements added by L.J. Potter <ljp@llornkcor.com> | 21 | // enhancements added by L.J. Potter <ljp@llornkcor.com> |
22 | #define QT_QWS_OPIE | 22 | #define QT_QWS_OPIE |
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | #include <qdir.h> | 26 | #include <qdir.h> |
27 | #include <qevent.h> | 27 | #include <qevent.h> |
28 | #include <qdragobject.h> | 28 | #include <qdragobject.h> |
29 | #include <qobjectlist.h> | 29 | #include <qobjectlist.h> |
30 | #include <qtoolbutton.h> | 30 | #include <qtoolbutton.h> |
31 | #include <qpe/qpetoolbar.h> | 31 | #include <qtoolbar.h> |
32 | #include <qpushbutton.h> | 32 | #include <qpushbutton.h> |
33 | #include <qfontdialog.h> | 33 | #include <qfontdialog.h> |
34 | #include <qglobal.h> | 34 | #include <qglobal.h> |
35 | #include <qpainter.h> | 35 | #include <qpainter.h> |
36 | #include <qmenubar.h> | 36 | #include <qmenubar.h> |
37 | #include <qmessagebox.h> | 37 | #include <qmessagebox.h> |
38 | #include <qaction.h> | 38 | #include <qaction.h> |
39 | #include <qapplication.h> | 39 | #include <qapplication.h> |
40 | #include <qfontmetrics.h> | 40 | #include <qfontmetrics.h> |
41 | #include <qcombobox.h> | 41 | #include <qcombobox.h> |
42 | #include <qevent.h> | 42 | #include <qevent.h> |
43 | #include <qtabwidget.h> | 43 | #include <qtabwidget.h> |
44 | #include <qtabbar.h> | 44 | #include <qtabbar.h> |
45 | #include <qpe/config.h> | 45 | #include <qpe/config.h> |
46 | #include <qstringlist.h> | 46 | #include <qstringlist.h> |
47 | #include <qpalette.h> | 47 | #include <qpalette.h> |
48 | 48 | ||
49 | #include <unistd.h> | 49 | #include <unistd.h> |
50 | #include <pwd.h> | 50 | #include <pwd.h> |
51 | #include <sys/types.h> | 51 | #include <sys/types.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 <assert.h> | 55 | #include <assert.h> |
56 | 56 | ||
57 | #include "konsole.h" | 57 | #include "konsole.h" |
58 | #include "keytrans.h" | 58 | #include "keytrans.h" |
59 | #include "commandeditdialog.h" | 59 | #include "commandeditdialog.h" |
60 | 60 | ||
61 | #ifdef QT_QWS_OPIE | 61 | #ifdef QT_QWS_OPIE |
62 | #include <opie/colorpopupmenu.h> | 62 | #include <opie/colorpopupmenu.h> |
63 | #endif | 63 | #endif |
64 | 64 | ||
65 | class EKNumTabBar : public QTabBar { | 65 | class EKNumTabBar : public QTabBar { |
66 | public: | 66 | public: |
67 | void numberTabs() | 67 | void numberTabs() |
68 | { | 68 | { |
69 | // Yes, it really is this messy. QTabWidget needs functions | 69 | // Yes, it really is this messy. QTabWidget needs functions |
70 | // that provide acces to tabs in a sequential way. | 70 | // that provide acces to tabs in a sequential way. |
71 | int m=INT_MIN; | 71 | int m=INT_MIN; |
72 | for (int i=0; i<count(); i++) { | 72 | for (int i=0; i<count(); i++) { |
73 | QTab* left=0; | 73 | QTab* left=0; |
74 | QListIterator<QTab> it(*tabList()); | 74 | QListIterator<QTab> it(*tabList()); |
75 | int x=INT_MAX; | 75 | int x=INT_MAX; |
76 | for( QTab* t; (t=it.current()); ++it ) { | 76 | for( QTab* t; (t=it.current()); ++it ) { |
77 | int tx = t->rect().x(); | 77 | int tx = t->rect().x(); |
78 | if ( tx<x && tx>m ) { | 78 | if ( tx<x && tx>m ) { |
79 | x = tx; | 79 | x = tx; |
80 | left = t; | 80 | left = t; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | if ( left ) { | 83 | if ( left ) { |
84 | left->setText(QString::number(i+1)); | 84 | left->setText(QString::number(i+1)); |
85 | m = left->rect().x(); | 85 | m = left->rect().x(); |
86 | } | 86 | } |
87 | } | 87 | } |
88 | } | 88 | } |
89 | }; | 89 | }; |
90 | 90 | ||
91 | class EKNumTabWidget : public QTabWidget { | 91 | class EKNumTabWidget : public QTabWidget { |
92 | public: | 92 | public: |
93 | EKNumTabWidget(QWidget* parent) : QTabWidget(parent) | 93 | EKNumTabWidget(QWidget* parent) : QTabWidget(parent) |
94 | { | 94 | { |
95 | } | 95 | } |
96 | 96 | ||
97 | void addTab(QWidget* w) | 97 | void addTab(QWidget* w) |
98 | { | 98 | { |
99 | QTab* t = new QTab(QString::number(tabBar()->count()+1)); | 99 | QTab* t = new QTab(QString::number(tabBar()->count()+1)); |
100 | QTabWidget::addTab(w,t); | 100 | QTabWidget::addTab(w,t); |
101 | } | 101 | } |
102 | 102 | ||
103 | void removeTab(QWidget* w) | 103 | void removeTab(QWidget* w) |
104 | { | 104 | { |
105 | removePage(w); | 105 | removePage(w); |
106 | ((EKNumTabBar*)tabBar())->numberTabs(); | 106 | ((EKNumTabBar*)tabBar())->numberTabs(); |
107 | } | 107 | } |
108 | }; | 108 | }; |
109 | 109 | ||
110 | // This could be configurable or dynamicly generated from the bash history | 110 | // This could be configurable or dynamicly generated from the bash history |
111 | // file of the user | 111 | // file of the user |
112 | static const char *commonCmds[] = | 112 | static const char *commonCmds[] = |
113 | { | 113 | { |
114 | "ls ", // I left this here, cause it looks better than the first alpha | 114 | "ls ", // I left this here, cause it looks better than the first alpha |
115 | "cardctl eject", | 115 | "cardctl eject", |
116 | "cat ", | 116 | "cat ", |
117 | "cd ", | 117 | "cd ", |
118 | "chmod ", | 118 | "chmod ", |
119 | "clear", | 119 | "clear", |
120 | "cp ", | 120 | "cp ", |
121 | "dc ", | 121 | "dc ", |
122 | "df ", | 122 | "df ", |
123 | "dmesg", | 123 | "dmesg", |
124 | "echo ", | 124 | "echo ", |
125 | "env", | 125 | "env", |
126 | "find ", | 126 | "find ", |
127 | "free", | 127 | "free", |
128 | "grep ", | 128 | "grep ", |
129 | "ifconfig ", | 129 | "ifconfig ", |
130 | "ipkg ", | 130 | "ipkg ", |
131 | "mkdir ", | 131 | "mkdir ", |
132 | "mv ", | 132 | "mv ", |
133 | "nc localhost 7776", | 133 | "nc localhost 7776", |
134 | "nc localhost 7777", | 134 | "nc localhost 7777", |
135 | "netstat ", | 135 | "netstat ", |
136 | "nslookup ", | 136 | "nslookup ", |
137 | "ping ", | 137 | "ping ", |
138 | "ps aux", | 138 | "ps aux", |
139 | "pwd ", | 139 | "pwd ", |
140 | "qcop QPE/System 'linkChanged(QString)' ''", | 140 | "qcop QPE/System 'linkChanged(QString)' ''", |
141 | "qcop QPE/System 'restart()'", | 141 | "qcop QPE/System 'restart()'", |
142 | "qcop QPE/System 'quit()'", | 142 | "qcop QPE/System 'quit()'", |
143 | "rm ", | 143 | "rm ", |
144 | "rmdir ", | 144 | "rmdir ", |
145 | "route ", | 145 | "route ", |
146 | "set ", | 146 | "set ", |
147 | "traceroute", | 147 | "traceroute", |
148 | 148 | ||
149 | /* | 149 | /* |
150 | "gzip", | 150 | "gzip", |
151 | "gunzip", | 151 | "gunzip", |
152 | "chgrp", | 152 | "chgrp", |
153 | "chown", | 153 | "chown", |
154 | "date", | 154 | "date", |
155 | "dd", | 155 | "dd", |
156 | "df", | 156 | "df", |
157 | "dmesg", | 157 | "dmesg", |
158 | "fuser", | 158 | "fuser", |
159 | "hostname", | 159 | "hostname", |
160 | "kill", | 160 | "kill", |
161 | "killall", | 161 | "killall", |
162 | "ln", | 162 | "ln", |
163 | "ping", | 163 | "ping", |
164 | "mount", | 164 | "mount", |
165 | "more", | 165 | "more", |
166 | "sort", | 166 | "sort", |
167 | "touch", | 167 | "touch", |
168 | "umount", | 168 | "umount", |
169 | "mknod", | 169 | "mknod", |
170 | "netstat", | 170 | "netstat", |
171 | */ | 171 | */ |
172 | 172 | ||
173 | "exit", | 173 | "exit", |
174 | NULL | 174 | NULL |
175 | }; | 175 | }; |
176 | 176 | ||
177 | static void konsoleInit(const char** shell) { | 177 | static void konsoleInit(const char** shell) { |
178 | if(setuid(getuid()) !=0) qDebug("setuid failed"); | 178 | if(setuid(getuid()) !=0) qDebug("setuid failed"); |
179 | if(setgid(getgid()) != 0) qDebug("setgid failed"); // drop privileges | 179 | if(setgid(getgid()) != 0) qDebug("setgid failed"); // drop privileges |
180 | 180 | ||
181 | 181 | ||
182 | // QPEApplication::grabKeyboard(); // for CTRL and ALT | 182 | // QPEApplication::grabKeyboard(); // for CTRL and ALT |
183 | 183 | ||
184 | qDebug("keyboard grabbed"); | 184 | qDebug("keyboard grabbed"); |
185 | #ifdef FAKE_CTRL_AND_ALT | 185 | #ifdef FAKE_CTRL_AND_ALT |
186 | qDebug("Fake Ctrl and Alt defined"); | 186 | qDebug("Fake Ctrl and Alt defined"); |
187 | QPEApplication::grabKeyboard(); // for CTRL and ALT | 187 | QPEApplication::grabKeyboard(); // for CTRL and ALT |
188 | #endif | 188 | #endif |
189 | 189 | ||
190 | *shell = getenv("SHELL"); | 190 | *shell = getenv("SHELL"); |
191 | qWarning("SHell initially is %s", *shell ); | 191 | qWarning("SHell initially is %s", *shell ); |
192 | 192 | ||
193 | if (shell == NULL || *shell == '\0') { | 193 | if (shell == NULL || *shell == '\0') { |
194 | struct passwd *ent = 0; | 194 | struct passwd *ent = 0; |
195 | uid_t me = getuid(); | 195 | uid_t me = getuid(); |
196 | *shell = "/bin/sh"; | 196 | *shell = "/bin/sh"; |
197 | 197 | ||
198 | while ( (ent = getpwent()) != 0 ) { | 198 | while ( (ent = getpwent()) != 0 ) { |
199 | if (ent->pw_uid == me) { | 199 | if (ent->pw_uid == me) { |
200 | if (ent->pw_shell != "") | 200 | if (ent->pw_shell != "") |
201 | *shell = ent->pw_shell; | 201 | *shell = ent->pw_shell; |
202 | break; | 202 | break; |
203 | } | 203 | } |
204 | } | 204 | } |
205 | endpwent(); | 205 | endpwent(); |
206 | } | 206 | } |
207 | 207 | ||
208 | qWarning("SHELL now is %s", *shell ); | 208 | qWarning("SHELL now is %s", *shell ); |
209 | 209 | ||
210 | if( putenv((char*)"COLORTERM=") !=0) | 210 | if( putenv((char*)"COLORTERM=") !=0) |
211 | qDebug("putenv failed"); // to trigger mc's color detection | 211 | qDebug("putenv failed"); // to trigger mc's color detection |
212 | } | 212 | } |
213 | 213 | ||
214 | Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : | 214 | Konsole::Konsole(QWidget* parent, const char* name, WFlags fl) : |
215 | QMainWindow(parent, name, fl) | 215 | QMainWindow(parent, name, fl) |
216 | { | 216 | { |
217 | QStrList tmp; const char* shell; | 217 | QStrList tmp; const char* shell; |
218 | 218 | ||
219 | setCaption( tr("Terminal") ); | 219 | setCaption( tr("Terminal") ); |
220 | 220 | ||
221 | konsoleInit( &shell); | 221 | konsoleInit( &shell); |
222 | qWarning("Using shell %s", shell); | 222 | qWarning("Using shell %s", shell); |
223 | init(shell,tmp); | 223 | init(shell,tmp); |
224 | } | 224 | } |
225 | 225 | ||
226 | 226 | ||
227 | 227 | ||
228 | void Konsole::initCommandList() | 228 | void Konsole::initCommandList() |
229 | { | 229 | { |
230 | // qDebug("Konsole::initCommandList"); | 230 | // qDebug("Konsole::initCommandList"); |
231 | Config cfg("Konsole"); | 231 | Config cfg("Konsole"); |
232 | cfg.setGroup("Commands"); | 232 | cfg.setGroup("Commands"); |
233 | commonCombo->setInsertionPolicy(QComboBox::AtCurrent); | 233 | commonCombo->setInsertionPolicy(QComboBox::AtCurrent); |
234 | commonCombo->clear(); | 234 | commonCombo->clear(); |
235 | if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { | 235 | if (cfg.readEntry("Commands Set","FALSE") == "FALSE") { |
236 | for (int i = 0; commonCmds[i] != NULL; i++) { | 236 | for (int i = 0; commonCmds[i] != NULL; i++) { |
237 | commonCombo->insertItem(commonCmds[i],i); | 237 | commonCombo->insertItem(commonCmds[i],i); |
238 | } | 238 | } |
239 | } else { | 239 | } else { |
240 | for (int i = 0; i < 100; i++) { | 240 | for (int i = 0; i < 100; i++) { |
241 | if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) | 241 | if (!(cfg.readEntry( QString::number(i),"")).isEmpty()) |
242 | commonCombo->insertItem((cfg.readEntry( QString::number(i),""))); | 242 | commonCombo->insertItem((cfg.readEntry( QString::number(i),""))); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | } | 246 | } |
247 | 247 | ||
248 | void Konsole::init(const char* _pgm, QStrList & _args) | 248 | void Konsole::init(const char* _pgm, QStrList & _args) |
249 | { | 249 | { |
250 | b_scroll = TRUE; // histon; | 250 | b_scroll = TRUE; // histon; |
251 | n_keytab = 0; | 251 | n_keytab = 0; |
252 | n_render = 0; | 252 | n_render = 0; |
253 | startUp=0; | 253 | startUp=0; |
254 | fromMenu = FALSE; | 254 | fromMenu = FALSE; |
255 | 255 | ||
256 | setCaption( tr("Terminal") ); | 256 | setCaption( tr("Terminal") ); |
257 | setIcon( Resource::loadPixmap( "konsole" ) ); | 257 | setIcon( Resource::loadPixmap( "konsole" ) ); |
258 | 258 | ||
259 | Config cfg("Konsole"); | 259 | Config cfg("Konsole"); |
260 | cfg.setGroup("Konsole"); | 260 | cfg.setGroup("Konsole"); |
261 | QString tmp; | 261 | QString tmp; |
262 | // initialize the list of allowed fonts /////////////////////////////////// | 262 | // initialize the list of allowed fonts /////////////////////////////////// |
263 | cfont = cfg.readNumEntry("FontID", 1); | 263 | cfont = cfg.readNumEntry("FontID", 1); |
264 | QFont f = QFont("Micro", 4, QFont::Normal); | 264 | QFont f = QFont("Micro", 4, QFont::Normal); |
265 | f.setFixedPitch(TRUE); | 265 | f.setFixedPitch(TRUE); |
266 | fonts.append(new VTFont(tr("Micro"), f)); | 266 | fonts.append(new VTFont(tr("Micro"), f)); |
267 | 267 | ||
268 | f = QFont("Fixed", 7, QFont::Normal); | 268 | f = QFont("Fixed", 7, QFont::Normal); |
269 | f.setFixedPitch(TRUE); | 269 | f.setFixedPitch(TRUE); |
270 | fonts.append(new VTFont(tr("Small Fixed"), f)); | 270 | fonts.append(new VTFont(tr("Small Fixed"), f)); |
271 | 271 | ||
272 | f = QFont("Fixed", 12, QFont::Normal); | 272 | f = QFont("Fixed", 12, QFont::Normal); |
273 | f.setFixedPitch(TRUE); | 273 | f.setFixedPitch(TRUE); |
274 | fonts.append(new VTFont(tr("Medium Fixed"), f)); | 274 | fonts.append(new VTFont(tr("Medium Fixed"), f)); |
275 | 275 | ||
276 | // create terminal emulation framework //////////////////////////////////// | 276 | // create terminal emulation framework //////////////////////////////////// |
277 | nsessions = 0; | 277 | nsessions = 0; |
278 | 278 | ||
279 | tab = new EKNumTabWidget(this); | 279 | tab = new EKNumTabWidget(this); |
280 | 280 | ||
281 | connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); | 281 | connect(tab, SIGNAL(currentChanged(QWidget*)), this, SLOT(switchSession(QWidget*))); |
282 | 282 | ||
283 | // create terminal toolbar //////////////////////////////////////////////// | 283 | // create terminal toolbar //////////////////////////////////////////////// |
284 | setToolBarsMovable( FALSE ); | 284 | setToolBarsMovable( FALSE ); |
285 | QPEToolBar *menuToolBar = new QPEToolBar( this ); | 285 | QToolBar *menuToolBar = new QToolBar( this ); |
286 | menuToolBar->setHorizontalStretchable( TRUE ); | 286 | menuToolBar->setHorizontalStretchable( TRUE ); |
287 | 287 | ||
288 | QMenuBar *menuBar = new QMenuBar( menuToolBar ); | 288 | QMenuBar *menuBar = new QMenuBar( menuToolBar ); |
289 | 289 | ||
290 | fontList = new QPopupMenu( this ); | 290 | fontList = new QPopupMenu( this ); |
291 | for(uint i = 0; i < fonts.count(); i++) { | 291 | for(uint i = 0; i < fonts.count(); i++) { |
292 | VTFont *fnt = fonts.at(i); | 292 | VTFont *fnt = fonts.at(i); |
293 | fontList->insertItem(fnt->getName(), i); | 293 | fontList->insertItem(fnt->getName(), i); |
294 | } | 294 | } |
295 | fontChanged(cfont); | 295 | fontChanged(cfont); |
296 | 296 | ||
297 | configMenu = new QPopupMenu( this); | 297 | configMenu = new QPopupMenu( this); |
298 | colorMenu = new QPopupMenu( this); | 298 | colorMenu = new QPopupMenu( this); |
299 | scrollMenu = new QPopupMenu( this); | 299 | scrollMenu = new QPopupMenu( this); |
300 | editCommandListMenu = new QPopupMenu( this); | 300 | editCommandListMenu = new QPopupMenu( this); |
301 | 301 | ||
302 | configMenu->insertItem(tr("Command List"), editCommandListMenu); | 302 | configMenu->insertItem(tr("Command List"), editCommandListMenu); |
303 | 303 | ||
304 | bool listHidden; | 304 | bool listHidden; |
305 | cfg.setGroup("Menubar"); | 305 | cfg.setGroup("Menubar"); |
306 | if( cfg.readEntry("Hidden","FALSE") == "TRUE") { | 306 | if( cfg.readEntry("Hidden","FALSE") == "TRUE") { |
307 | editCommandListMenu->insertItem( tr( "Show command list" )); | 307 | editCommandListMenu->insertItem( tr( "Show command list" )); |
308 | listHidden=TRUE; | 308 | listHidden=TRUE; |
309 | } else { | 309 | } else { |
310 | editCommandListMenu->insertItem( tr( "Hide command list" )); | 310 | editCommandListMenu->insertItem( tr( "Hide command list" )); |
311 | listHidden=FALSE; | 311 | listHidden=FALSE; |
312 | } | 312 | } |
313 | 313 | ||
314 | cfg.setGroup("Tabs"); | 314 | cfg.setGroup("Tabs"); |
315 | tmp=cfg.readEntry("Position","Bottom"); | 315 | tmp=cfg.readEntry("Position","Bottom"); |
316 | if(tmp=="Top") { | 316 | if(tmp=="Top") { |
317 | tab->setTabPosition(QTabWidget::Top); | 317 | tab->setTabPosition(QTabWidget::Top); |
318 | configMenu->insertItem( tr( "Tabs on Bottom" ) ); | 318 | configMenu->insertItem( tr( "Tabs on Bottom" ) ); |
319 | } else { | 319 | } else { |
320 | tab->setTabPosition(QTabWidget::Bottom); | 320 | tab->setTabPosition(QTabWidget::Bottom); |
321 | configMenu->insertItem(tr("Tabs on Top")); | 321 | configMenu->insertItem(tr("Tabs on Top")); |
322 | } | 322 | } |
323 | configMenu->insertSeparator(2); | 323 | configMenu->insertSeparator(2); |
324 | 324 | ||
325 | colorMenu->insertItem(tr( "Green on Black")); | 325 | colorMenu->insertItem(tr( "Green on Black")); |
326 | colorMenu->insertItem(tr( "Black on White")); | 326 | colorMenu->insertItem(tr( "Black on White")); |
327 | colorMenu->insertItem(tr( "White on Black")); | 327 | colorMenu->insertItem(tr( "White on Black")); |
328 | colorMenu->insertItem(tr( "Black on Transparent")); | 328 | colorMenu->insertItem(tr( "Black on Transparent")); |
329 | colorMenu->insertItem(tr( "Black on Red")); | 329 | colorMenu->insertItem(tr( "Black on Red")); |
330 | colorMenu->insertItem(tr( "Red on Black")); | 330 | colorMenu->insertItem(tr( "Red on Black")); |
331 | colorMenu->insertItem(tr( "Green on Yellow")); | 331 | colorMenu->insertItem(tr( "Green on Yellow")); |
332 | colorMenu->insertItem(tr( "Blue on Magenta")); | 332 | colorMenu->insertItem(tr( "Blue on Magenta")); |
333 | colorMenu->insertItem(tr( "Magenta on Blue")); | 333 | colorMenu->insertItem(tr( "Magenta on Blue")); |
334 | colorMenu->insertItem(tr( "Cyan on White")); | 334 | colorMenu->insertItem(tr( "Cyan on White")); |
335 | colorMenu->insertItem(tr( "White on Cyan")); | 335 | colorMenu->insertItem(tr( "White on Cyan")); |
336 | colorMenu->insertItem(tr( "Blue on Black")); | 336 | colorMenu->insertItem(tr( "Blue on Black")); |
337 | colorMenu->insertItem(tr( "Amber on Black")); | 337 | colorMenu->insertItem(tr( "Amber on Black")); |
338 | 338 | ||
339 | #ifdef QT_QWS_OPIE | 339 | #ifdef QT_QWS_OPIE |
340 | colorMenu->insertItem(tr( "Custom")); | 340 | colorMenu->insertItem(tr( "Custom")); |
341 | #endif | 341 | #endif |
342 | 342 | ||
343 | configMenu->insertItem( tr("Font"), fontList ); | 343 | configMenu->insertItem( tr("Font"), fontList ); |
344 | configMenu->insertItem(tr( "Colors") ,colorMenu); | 344 | configMenu->insertItem(tr( "Colors") ,colorMenu); |
345 | 345 | ||
346 | connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); | 346 | connect( fontList, SIGNAL( activated(int) ), this, SLOT( fontChanged(int) )); |
347 | connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); | 347 | connect( configMenu, SIGNAL( activated(int) ), this, SLOT( configMenuSelected(int) )); |
348 | connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) )); | 348 | connect( colorMenu, SIGNAL( activated(int) ), this, SLOT( colorMenuIsSelected(int) )); |
349 | connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int))); | 349 | connect( scrollMenu, SIGNAL(activated(int)),this,SLOT(scrollMenuSelected(int))); |
350 | connect(editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int))); | 350 | connect(editCommandListMenu,SIGNAL(activated(int)),this,SLOT(editCommandListMenuSelected(int))); |
351 | 351 | ||
352 | menuBar->insertItem( tr("Options"), configMenu ); | 352 | menuBar->insertItem( tr("Options"), configMenu ); |
353 | 353 | ||
354 | QPEToolBar *toolbar = new QPEToolBar( this ); | 354 | QToolBar *toolbar = new QToolBar( this ); |
355 | 355 | ||
356 | QAction *a; | 356 | QAction *a; |
357 | 357 | ||
358 | // Button Commands | 358 | // Button Commands |
359 | a = new QAction( tr("New"), Resource::loadPixmap( "konsole" ), QString::null, 0, this, 0 ); | 359 | a = new QAction( tr("New"), Resource::loadPixmap( "konsole" ), QString::null, 0, this, 0 ); |
360 | connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar ); | 360 | connect( a, SIGNAL( activated() ), this, SLOT( newSession() ) ); a->addTo( toolbar ); |
361 | a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 ); | 361 | a = new QAction( tr("Enter"), Resource::loadPixmap( "konsole/enter" ), QString::null, 0, this, 0 ); |
362 | connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar ); | 362 | connect( a, SIGNAL( activated() ), this, SLOT( hitEnter() ) ); a->addTo( toolbar ); |
363 | a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 ); | 363 | a = new QAction( tr("Space"), Resource::loadPixmap( "konsole/space" ), QString::null, 0, this, 0 ); |
364 | connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar ); | 364 | connect( a, SIGNAL( activated() ), this, SLOT( hitSpace() ) ); a->addTo( toolbar ); |
365 | a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 ); | 365 | a = new QAction( tr("Tab"), Resource::loadPixmap( "konsole/tab" ), QString::null, 0, this, 0 ); |
366 | connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar ); | 366 | connect( a, SIGNAL( activated() ), this, SLOT( hitTab() ) ); a->addTo( toolbar ); |
367 | a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 ); | 367 | a = new QAction( tr("Up"), Resource::loadPixmap( "konsole/up" ), QString::null, 0, this, 0 ); |
368 | connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); | 368 | connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); |
369 | a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 ); | 369 | a = new QAction( tr("Down"), Resource::loadPixmap( "konsole/down" ), QString::null, 0, this, 0 ); |
370 | connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); | 370 | connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); |
371 | a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 371 | a = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
372 | connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar ); | 372 | connect( a, SIGNAL( activated() ), this, SLOT( hitPaste() ) ); a->addTo( toolbar ); |
373 | /* | 373 | /* |
374 | a = new QAction( tr("Up"), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 ); | 374 | a = new QAction( tr("Up"), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 ); |
375 | connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); | 375 | connect( a, SIGNAL( activated() ), this, SLOT( hitUp() ) ); a->addTo( toolbar ); |
376 | a = new QAction( tr("Down"), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 ); | 376 | a = new QAction( tr("Down"), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 ); |
377 | connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); | 377 | connect( a, SIGNAL( activated() ), this, SLOT( hitDown() ) ); a->addTo( toolbar ); |
378 | */ | 378 | */ |
379 | 379 | ||
380 | secondToolBar = new QPEToolBar( this ); | 380 | secondToolBar = new QToolBar( this ); |
381 | secondToolBar->setHorizontalStretchable( TRUE ); | 381 | secondToolBar->setHorizontalStretchable( TRUE ); |
382 | 382 | ||
383 | commonCombo = new QComboBox( secondToolBar ); | 383 | commonCombo = new QComboBox( secondToolBar ); |
384 | commonCombo->setMaximumWidth(236); | 384 | commonCombo->setMaximumWidth(236); |
385 | 385 | ||
386 | editCommandListMenu->insertItem( tr( "Quick Edit" ) ); | 386 | editCommandListMenu->insertItem( tr( "Quick Edit" ) ); |
387 | if( listHidden) { | 387 | if( listHidden) { |
388 | secondToolBar->hide(); | 388 | secondToolBar->hide(); |
389 | editCommandListMenu->setItemEnabled(-23 ,FALSE); | 389 | editCommandListMenu->setItemEnabled(-23 ,FALSE); |
390 | } | 390 | } |
391 | editCommandListMenu->insertItem(tr( "Edit" ) ); | 391 | editCommandListMenu->insertItem(tr( "Edit" ) ); |
392 | 392 | ||
393 | cfg.setGroup("Commands"); | 393 | cfg.setGroup("Commands"); |
394 | commonCombo->setInsertionPolicy(QComboBox::AtCurrent); | 394 | commonCombo->setInsertionPolicy(QComboBox::AtCurrent); |
395 | 395 | ||
396 | initCommandList(); | 396 | initCommandList(); |
397 | // for (int i = 0; commonCmds[i] != NULL; i++) { | 397 | // for (int i = 0; commonCmds[i] != NULL; i++) { |
398 | // commonCombo->insertItem( commonCmds[i], i ); | 398 | // commonCombo->insertItem( commonCmds[i], i ); |
399 | // tmp = cfg.readEntry( QString::number(i),""); | 399 | // tmp = cfg.readEntry( QString::number(i),""); |
400 | // if(tmp != "") | 400 | // if(tmp != "") |
401 | // commonCombo->changeItem( tmp,i ); | 401 | // commonCombo->changeItem( tmp,i ); |
402 | // } | 402 | // } |
403 | 403 | ||
404 | connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); | 404 | connect( commonCombo, SIGNAL( activated(int) ), this, SLOT( enterCommand(int) )); |
405 | 405 | ||
406 | scrollMenu->insertItem(tr( "None" )); | 406 | scrollMenu->insertItem(tr( "None" )); |
407 | scrollMenu->insertItem(tr( "Left" )); | 407 | scrollMenu->insertItem(tr( "Left" )); |
408 | scrollMenu->insertItem(tr( "Right" )); | 408 | scrollMenu->insertItem(tr( "Right" )); |
409 | // scrollMenu->insertSeparator(4); | 409 | // scrollMenu->insertSeparator(4); |
410 | // scrollMenu->insertItem(tr( "Horizontal" )); | 410 | // scrollMenu->insertItem(tr( "Horizontal" )); |
411 | 411 | ||
412 | configMenu->insertItem(tr( "ScrollBar" ),scrollMenu); | 412 | configMenu->insertItem(tr( "ScrollBar" ),scrollMenu); |
413 | 413 | ||
414 | int jut = configMenu->insertItem(tr( "Wrap" )); | 414 | int jut = configMenu->insertItem(tr( "Wrap" )); |
415 | cfg.setGroup("ScrollBar"); | 415 | cfg.setGroup("ScrollBar"); |
416 | configMenu->setItemChecked(jut, cfg.readBoolEntry("HorzScroll",0)); | 416 | configMenu->setItemChecked(jut, cfg.readBoolEntry("HorzScroll",0)); |
417 | 417 | ||
418 | jut = configMenu->insertItem(tr( "Use Beep" )); | 418 | jut = configMenu->insertItem(tr( "Use Beep" )); |
419 | cfg.setGroup("Menubar"); | 419 | cfg.setGroup("Menubar"); |
420 | 420 | ||
421 | configMenu->setItemChecked(jut, cfg.readBoolEntry("useBeep",0)); | 421 | configMenu->setItemChecked(jut, cfg.readBoolEntry("useBeep",0)); |
422 | 422 | ||
423 | 423 | ||
424 | //scrollMenuSelected(-29); | 424 | //scrollMenuSelected(-29); |
425 | // cfg.setGroup("ScrollBar"); | 425 | // cfg.setGroup("ScrollBar"); |
426 | // if(cfg.readBoolEntry("HorzScroll",0)) { | 426 | // if(cfg.readBoolEntry("HorzScroll",0)) { |
427 | // if(cfg.readNumEntry("Position",2) == 0) | 427 | // if(cfg.readNumEntry("Position",2) == 0) |
428 | // te->setScrollbarLocation(1); | 428 | // te->setScrollbarLocation(1); |
429 | // else | 429 | // else |
430 | // te->setScrollbarLocation(0); | 430 | // te->setScrollbarLocation(0); |
431 | // te->setScrollbarLocation( cfg.readNumEntry("Position",2)); | 431 | // te->setScrollbarLocation( cfg.readNumEntry("Position",2)); |
432 | // te->setWrapAt(120); | 432 | // te->setWrapAt(120); |
433 | // } | 433 | // } |
434 | // create applications ///////////////////////////////////////////////////// | 434 | // create applications ///////////////////////////////////////////////////// |
435 | setCentralWidget(tab); | 435 | setCentralWidget(tab); |
436 | 436 | ||
437 | // load keymaps //////////////////////////////////////////////////////////// | 437 | // load keymaps //////////////////////////////////////////////////////////// |
438 | KeyTrans::loadAll(); | 438 | KeyTrans::loadAll(); |
439 | for (int i = 0; i < KeyTrans::count(); i++) | 439 | for (int i = 0; i < KeyTrans::count(); i++) |
440 | { KeyTrans* s = KeyTrans::find(i); | 440 | { KeyTrans* s = KeyTrans::find(i); |
441 | assert( s ); | 441 | assert( s ); |
442 | } | 442 | } |
443 | 443 | ||
444 | se_pgm = _pgm; | 444 | se_pgm = _pgm; |
445 | se_args = _args; | 445 | se_args = _args; |
446 | se_args.prepend("--login"); | 446 | se_args.prepend("--login"); |
447 | parseCommandLine(); | 447 | parseCommandLine(); |
448 | // read and apply default values /////////////////////////////////////////// | 448 | // read and apply default values /////////////////////////////////////////// |
449 | resize(321, 321); // Dummy. | 449 | resize(321, 321); // Dummy. |
450 | QSize currentSize = size(); | 450 | QSize currentSize = size(); |
451 | if (currentSize != size()) | 451 | if (currentSize != size()) |
452 | defaultSize = size(); | 452 | defaultSize = size(); |
453 | } | 453 | } |
454 | 454 | ||
455 | void Konsole::show() | 455 | void Konsole::show() |
456 | { | 456 | { |
457 | if ( !nsessions ) { | 457 | if ( !nsessions ) { |
458 | newSession(); | 458 | newSession(); |
459 | } | 459 | } |
460 | QMainWindow::show(); | 460 | QMainWindow::show(); |
461 | 461 | ||
462 | } | 462 | } |
463 | 463 | ||
464 | void Konsole::initSession(const char*, QStrList &) | 464 | void Konsole::initSession(const char*, QStrList &) |
465 | { | 465 | { |
466 | QMainWindow::show(); | 466 | QMainWindow::show(); |
467 | } | 467 | } |
468 | 468 | ||
469 | Konsole::~Konsole() | 469 | Konsole::~Konsole() |
470 | { | 470 | { |
471 | while (nsessions > 0) { | 471 | while (nsessions > 0) { |
472 | doneSession(getTe()->currentSession, 0); | 472 | doneSession(getTe()->currentSession, 0); |
473 | } | 473 | } |
474 | 474 | ||
475 | Config cfg("Konsole"); | 475 | Config cfg("Konsole"); |
476 | cfg.setGroup("Konsole"); | 476 | cfg.setGroup("Konsole"); |
477 | cfg.writeEntry("FontID", cfont); | 477 | cfg.writeEntry("FontID", cfont); |
478 | } | 478 | } |
479 | 479 | ||
480 | void Konsole::fontChanged(int f) | 480 | void Konsole::fontChanged(int f) |
481 | { | 481 | { |
482 | VTFont* font = fonts.at(f); | 482 | VTFont* font = fonts.at(f); |
483 | if (font != 0) { | 483 | if (font != 0) { |
484 | for(uint i = 0; i < fonts.count(); i++) { | 484 | for(uint i = 0; i < fonts.count(); i++) { |
485 | fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE); | 485 | fontList->setItemChecked(i, (i == (uint) f) ? TRUE : FALSE); |
486 | } | 486 | } |
487 | 487 | ||
488 | cfont = f; | 488 | cfont = f; |
489 | 489 | ||
490 | TEWidget* te = getTe(); | 490 | TEWidget* te = getTe(); |
491 | if (te != 0) { | 491 | if (te != 0) { |
492 | te->setVTFont(font->getFont()); | 492 | te->setVTFont(font->getFont()); |
493 | } | 493 | } |
494 | } | 494 | } |
495 | } | 495 | } |
496 | 496 | ||
497 | 497 | ||
498 | void Konsole::enterCommand(int c) | 498 | void Konsole::enterCommand(int c) |
499 | { | 499 | { |
500 | TEWidget* te = getTe(); | 500 | TEWidget* te = getTe(); |
501 | if (te != 0) { | 501 | if (te != 0) { |
502 | if(!commonCombo->editable()) { | 502 | if(!commonCombo->editable()) { |
503 | QString text = commonCombo->text(c); //commonCmds[c]; | 503 | QString text = commonCombo->text(c); //commonCmds[c]; |
504 | te->emitText(text); | 504 | te->emitText(text); |
505 | } else { | 505 | } else { |
506 | changeCommand( commonCombo->text(c), c); | 506 | changeCommand( commonCombo->text(c), c); |
507 | } | 507 | } |
508 | } | 508 | } |
509 | } | 509 | } |
510 | 510 | ||
511 | void Konsole::hitEnter() | 511 | void Konsole::hitEnter() |
512 | { | 512 | { |
513 | TEWidget* te = getTe(); | 513 | TEWidget* te = getTe(); |
514 | if (te != 0) { | 514 | if (te != 0) { |
515 | te->emitText(QString("\r")); | 515 | te->emitText(QString("\r")); |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | void Konsole::hitSpace() | 519 | void Konsole::hitSpace() |
520 | { | 520 | { |
521 | TEWidget* te = getTe(); | 521 | TEWidget* te = getTe(); |
522 | if (te != 0) { | 522 | if (te != 0) { |
523 | te->emitText(QString(" ")); | 523 | te->emitText(QString(" ")); |
524 | } | 524 | } |
525 | } | 525 | } |
526 | 526 | ||
527 | void Konsole::hitTab() | 527 | void Konsole::hitTab() |
528 | { | 528 | { |
529 | TEWidget* te = getTe(); | 529 | TEWidget* te = getTe(); |
530 | if (te != 0) { | 530 | if (te != 0) { |
531 | te->emitText(QString("\t")); | 531 | te->emitText(QString("\t")); |
532 | } | 532 | } |
533 | } | 533 | } |
534 | 534 | ||
535 | void Konsole::hitPaste() | 535 | void Konsole::hitPaste() |
536 | { | 536 | { |
537 | TEWidget* te = getTe(); | 537 | TEWidget* te = getTe(); |
538 | if (te != 0) { | 538 | if (te != 0) { |
539 | te->pasteClipboard(); | 539 | te->pasteClipboard(); |
540 | } | 540 | } |
541 | } | 541 | } |
542 | 542 | ||
543 | void Konsole::hitUp() | 543 | void Konsole::hitUp() |
544 | { | 544 | { |
545 | TEWidget* te = getTe(); | 545 | TEWidget* te = getTe(); |
546 | if (te != 0) { | 546 | if (te != 0) { |
547 | QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0); | 547 | QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Up, 0, 0); |
548 | QApplication::sendEvent( te, &ke ); | 548 | QApplication::sendEvent( te, &ke ); |
549 | } | 549 | } |
550 | } | 550 | } |
551 | 551 | ||
552 | void Konsole::hitDown() | 552 | void Konsole::hitDown() |
553 | { | 553 | { |
554 | TEWidget* te = getTe(); | 554 | TEWidget* te = getTe(); |
555 | if (te != 0) { | 555 | if (te != 0) { |
556 | QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0); | 556 | QKeyEvent ke( QKeyEvent::KeyPress, Qt::Key_Down, 0, 0); |
557 | QApplication::sendEvent( te, &ke ); | 557 | QApplication::sendEvent( te, &ke ); |
558 | } | 558 | } |
559 | } | 559 | } |
560 | 560 | ||
561 | /** | 561 | /** |
562 | This function calculates the size of the external widget | 562 | This function calculates the size of the external widget |
563 | needed for the internal widget to be | 563 | needed for the internal widget to be |
564 | */ | 564 | */ |
565 | QSize Konsole::calcSize(int columns, int lines) { | 565 | QSize Konsole::calcSize(int columns, int lines) { |
566 | TEWidget* te = getTe(); | 566 | TEWidget* te = getTe(); |
567 | if (te != 0) { | 567 | if (te != 0) { |
568 | QSize size = te->calcSize(columns, lines); | 568 | QSize size = te->calcSize(columns, lines); |
569 | return size; | 569 | return size; |
570 | } else { | 570 | } else { |
571 | QSize size; | 571 | QSize size; |
572 | return size; | 572 | return size; |
573 | } | 573 | } |
574 | } | 574 | } |
575 | 575 | ||
576 | /** | 576 | /** |
577 | sets application window to a size based on columns X lines of the te | 577 | sets application window to a size based on columns X lines of the te |
578 | guest widget. Call with (0,0) for setting default size. | 578 | guest widget. Call with (0,0) for setting default size. |
579 | */ | 579 | */ |
580 | 580 | ||
581 | void Konsole::setColLin(int columns, int lines) | 581 | void Konsole::setColLin(int columns, int lines) |
582 | { | 582 | { |
583 | qDebug("konsole::setColLin:: Columns %d", columns); | 583 | qDebug("konsole::setColLin:: Columns %d", columns); |
584 | 584 | ||
585 | if ((columns==0) || (lines==0)) | 585 | if ((columns==0) || (lines==0)) |
586 | { | 586 | { |
587 | if (defaultSize.isEmpty()) // not in config file : set default value | 587 | if (defaultSize.isEmpty()) // not in config file : set default value |
588 | { | 588 | { |
589 | defaultSize = calcSize(80,24); | 589 | defaultSize = calcSize(80,24); |
590 | // notifySize(24,80); // set menu items (strange arg order !) | 590 | // notifySize(24,80); // set menu items (strange arg order !) |
591 | } | 591 | } |
592 | resize(defaultSize); | 592 | resize(defaultSize); |
593 | } else { | 593 | } else { |
594 | resize(calcSize(columns, lines)); | 594 | resize(calcSize(columns, lines)); |
595 | // notifySize(lines,columns); // set menu items (strange arg order !) | 595 | // notifySize(lines,columns); // set menu items (strange arg order !) |
596 | } | 596 | } |
597 | } | 597 | } |
598 | 598 | ||
599 | /* | 599 | /* |
600 | void Konsole::setFont(int fontno) | 600 | void Konsole::setFont(int fontno) |
601 | { | 601 | { |
602 | QFont f; | 602 | QFont f; |
603 | if (fontno == 0) | 603 | if (fontno == 0) |
604 | f = defaultFont = QFont( "Helvetica", 12 ); | 604 | f = defaultFont = QFont( "Helvetica", 12 ); |
605 | else | 605 | else |
606 | if (fonts[fontno][0] == '-') | 606 | if (fonts[fontno][0] == '-') |
607 | f.setRawName( fonts[fontno] ); | 607 | f.setRawName( fonts[fontno] ); |
608 | else | 608 | else |
609 | { | 609 | { |
610 | f.setFamily(fonts[fontno]); | 610 | f.setFamily(fonts[fontno]); |
611 | f.setRawMode( TRUE ); | 611 | f.setRawMode( TRUE ); |
612 | } | 612 | } |
613 | if ( !f.exactMatch() && fontno != 0) | 613 | if ( !f.exactMatch() && fontno != 0) |
614 | { | 614 | { |
615 | QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]); | 615 | QString msg = i18n("Font `%1' not found.\nCheck README.linux.console for help.").arg(fonts[fontno]); |
616 | QMessageBox(this, msg); | 616 | QMessageBox(this, msg); |
617 | return; | 617 | return; |
618 | } | 618 | } |
619 | if (se) se->setFontNo(fontno); | 619 | if (se) se->setFontNo(fontno); |
620 | te->setVTFont(f); | 620 | te->setVTFont(f); |
621 | n_font = fontno; | 621 | n_font = fontno; |
622 | } | 622 | } |
623 | */ | 623 | */ |
624 | 624 | ||
625 | // --| color selection |------------------------------------------------------- | 625 | // --| color selection |------------------------------------------------------- |
626 | 626 | ||
627 | void Konsole::changeColumns(int columns) | 627 | void Konsole::changeColumns(int columns) |
628 | { //FIXME this seems to cause silliness when reset command is executed | 628 | { //FIXME this seems to cause silliness when reset command is executed |
629 | // qDebug("change columns"); | 629 | // qDebug("change columns"); |
630 | // TEWidget* te = getTe(); | 630 | // TEWidget* te = getTe(); |
631 | // if (te != 0) { | 631 | // if (te != 0) { |
632 | // setColLin(columns,te->Lines()); | 632 | // setColLin(columns,te->Lines()); |
633 | // te->update(); | 633 | // te->update(); |
634 | // } | 634 | // } |
635 | } | 635 | } |
636 | 636 | ||
637 | //FIXME: If a child dies during session swap, | 637 | //FIXME: If a child dies during session swap, |
638 | // this routine might be called before | 638 | // this routine might be called before |
639 | // session swap is completed. | 639 | // session swap is completed. |
640 | 640 | ||
641 | void Konsole::doneSession(TESession*, int ) | 641 | void Konsole::doneSession(TESession*, int ) |
642 | { | 642 | { |
643 | TEWidget *te = getTe(); | 643 | TEWidget *te = getTe(); |
644 | if (te != 0) { | 644 | if (te != 0) { |
645 | te->currentSession->setConnect(FALSE); | 645 | te->currentSession->setConnect(FALSE); |
646 | tab->removeTab(te); | 646 | tab->removeTab(te); |
647 | delete te->currentSession; | 647 | delete te->currentSession; |
648 | delete te; | 648 | delete te; |
649 | nsessions--; | 649 | nsessions--; |
650 | } | 650 | } |
651 | 651 | ||
652 | if (nsessions == 0) { | 652 | if (nsessions == 0) { |
653 | close(); | 653 | close(); |
654 | } | 654 | } |
655 | } | 655 | } |
656 | 656 | ||
657 | void Konsole::newSession() { | 657 | void Konsole::newSession() { |
658 | if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory? | 658 | if(nsessions < 15) { // seems to be something weird about 16 tabs on the Zaurus.... memory? |
659 | TEWidget* te = new TEWidget(tab); | 659 | TEWidget* te = new TEWidget(tab); |
660 | Config c("Konsole"); | 660 | Config c("Konsole"); |
661 | c.setGroup("Menubar"); | 661 | c.setGroup("Menubar"); |
662 | te->useBeep=c.readBoolEntry("useBeep",0); | 662 | te->useBeep=c.readBoolEntry("useBeep",0); |
663 | 663 | ||
664 | // te->setBackgroundMode(PaletteBase); //we want transparent!! | 664 | // te->setBackgroundMode(PaletteBase); //we want transparent!! |
665 | te->setVTFont(fonts.at(cfont)->getFont()); | 665 | te->setVTFont(fonts.at(cfont)->getFont()); |
666 | tab->addTab(te); | 666 | tab->addTab(te); |
667 | TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); | 667 | TESession* se = new TESession(this, te, se_pgm, se_args, "xterm"); |
668 | te->currentSession = se; | 668 | te->currentSession = se; |
669 | connect( se, SIGNAL(done(TESession*,int)), this, SLOT(doneSession(TESession*,int)) ); | 669 | connect( se, SIGNAL(done(TESession*,int)), this, SLOT(doneSession(TESession*,int)) ); |
670 | se->run(); | 670 | se->run(); |
671 | se->setConnect(TRUE); | 671 | se->setConnect(TRUE); |
672 | se->setHistory(b_scroll); | 672 | se->setHistory(b_scroll); |
673 | tab->setCurrentPage(nsessions); | 673 | tab->setCurrentPage(nsessions); |
674 | nsessions++; | 674 | nsessions++; |
675 | doWrap(); | 675 | doWrap(); |
676 | setColor(); | 676 | setColor(); |
677 | } | 677 | } |
678 | } | 678 | } |
679 | 679 | ||
680 | TEWidget* Konsole::getTe() { | 680 | TEWidget* Konsole::getTe() { |
681 | if (nsessions) { | 681 | if (nsessions) { |
682 | return (TEWidget *) tab->currentPage(); | 682 | return (TEWidget *) tab->currentPage(); |
683 | } else { | 683 | } else { |
684 | return 0; | 684 | return 0; |
685 | } | 685 | } |
686 | } | 686 | } |
687 | 687 | ||
688 | void Konsole::switchSession(QWidget* w) { | 688 | void Konsole::switchSession(QWidget* w) { |
689 | TEWidget* te = (TEWidget *) w; | 689 | TEWidget* te = (TEWidget *) w; |
690 | 690 | ||
691 | QFont teFnt = te->getVTFont(); | 691 | QFont teFnt = te->getVTFont(); |
692 | for(uint i = 0; i < fonts.count(); i++) { | 692 | for(uint i = 0; i < fonts.count(); i++) { |
693 | VTFont *fnt = fonts.at(i); | 693 | VTFont *fnt = fonts.at(i); |
694 | bool cf = fnt->getFont() == teFnt; | 694 | bool cf = fnt->getFont() == teFnt; |
695 | fontList->setItemChecked(i, cf); | 695 | fontList->setItemChecked(i, cf); |
696 | if (cf) { | 696 | if (cf) { |
697 | cfont = i; | 697 | cfont = i; |
698 | } | 698 | } |
699 | } | 699 | } |
700 | } | 700 | } |
701 | 701 | ||
702 | void Konsole::colorMenuIsSelected(int iD) { | 702 | void Konsole::colorMenuIsSelected(int iD) { |
703 | fromMenu = TRUE; | 703 | fromMenu = TRUE; |
704 | colorMenuSelected(iD); | 704 | colorMenuSelected(iD); |
705 | } | 705 | } |
706 | 706 | ||
707 | /// ------------------------------- some new stuff by L.J. Potter | 707 | /// ------------------------------- some new stuff by L.J. Potter |
708 | void Konsole::colorMenuSelected(int iD) | 708 | void Konsole::colorMenuSelected(int iD) |
709 | { // this is NOT pretty, elegant or anything else besides functional | 709 | { // this is NOT pretty, elegant or anything else besides functional |
710 | // QString temp; | 710 | // QString temp; |
711 | // qDebug( temp.sprintf("colormenu %d", iD)); | 711 | // qDebug( temp.sprintf("colormenu %d", iD)); |
712 | 712 | ||
713 | TEWidget* te = getTe(); | 713 | TEWidget* te = getTe(); |
714 | Config cfg("Konsole"); | 714 | Config cfg("Konsole"); |
715 | cfg.setGroup("Colors"); | 715 | cfg.setGroup("Colors"); |
716 | // QColor foreground; | 716 | // QColor foreground; |
717 | // QColor background; | 717 | // QColor background; |
718 | colorMenu->setItemChecked(lastSelectedMenu,FALSE); | 718 | colorMenu->setItemChecked(lastSelectedMenu,FALSE); |
719 | ColorEntry m_table[TABLE_COLORS]; | 719 | ColorEntry m_table[TABLE_COLORS]; |
720 | const ColorEntry * defaultCt=te->getdefaultColorTable(); | 720 | const ColorEntry * defaultCt=te->getdefaultColorTable(); |
721 | /////////// fore back | 721 | /////////// fore back |
722 | int i; | 722 | int i; |
723 | if(iD==-9) { // default default | 723 | if(iD==-9) { // default default |
724 | for (i = 0; i < TABLE_COLORS; i++) { | 724 | for (i = 0; i < TABLE_COLORS; i++) { |
725 | m_table[i].color = defaultCt[i].color; | 725 | m_table[i].color = defaultCt[i].color; |
726 | if(i==1 || i == 11) | 726 | if(i==1 || i == 11) |
727 | m_table[i].transparent=1; | 727 | m_table[i].transparent=1; |
728 | cfg.writeEntry("Schema","9"); | 728 | cfg.writeEntry("Schema","9"); |
729 | colorMenu->setItemChecked(-9,TRUE); | 729 | colorMenu->setItemChecked(-9,TRUE); |
730 | } | 730 | } |
731 | } else { | 731 | } else { |
732 | if(iD==-6) { // green black | 732 | if(iD==-6) { // green black |
733 | foreground.setRgb(0x18,255,0x18); | 733 | foreground.setRgb(0x18,255,0x18); |
734 | background.setRgb(0x00,0x00,0x00); | 734 | background.setRgb(0x00,0x00,0x00); |
735 | cfg.writeEntry("Schema","6"); | 735 | cfg.writeEntry("Schema","6"); |
736 | colorMenu->setItemChecked(-6,TRUE); | 736 | colorMenu->setItemChecked(-6,TRUE); |
737 | } | 737 | } |
738 | if(iD==-7) { // black white | 738 | if(iD==-7) { // black white |
739 | foreground.setRgb(0x00,0x00,0x00); | 739 | foreground.setRgb(0x00,0x00,0x00); |
740 | background.setRgb(0xFF,0xFF,0xFF); | 740 | background.setRgb(0xFF,0xFF,0xFF); |
741 | cfg.writeEntry("Schema","7"); | 741 | cfg.writeEntry("Schema","7"); |
742 | colorMenu->setItemChecked(-7,TRUE); | 742 | colorMenu->setItemChecked(-7,TRUE); |
743 | } | 743 | } |
744 | if(iD==-8) { // white black | 744 | if(iD==-8) { // white black |
745 | foreground.setRgb(0xFF,0xFF,0xFF); | 745 | foreground.setRgb(0xFF,0xFF,0xFF); |
746 | background.setRgb(0x00,0x00,0x00); | 746 | background.setRgb(0x00,0x00,0x00); |
747 | cfg.writeEntry("Schema","8"); | 747 | cfg.writeEntry("Schema","8"); |
748 | colorMenu->setItemChecked(-8,TRUE); | 748 | colorMenu->setItemChecked(-8,TRUE); |
749 | } | 749 | } |
750 | if(iD==-10) {// Black, Red | 750 | if(iD==-10) {// Black, Red |
751 | foreground.setRgb(0x00,0x00,0x00); | 751 | foreground.setRgb(0x00,0x00,0x00); |
752 | background.setRgb(0xB2,0x18,0x18); | 752 | background.setRgb(0xB2,0x18,0x18); |
753 | cfg.writeEntry("Schema","10"); | 753 | cfg.writeEntry("Schema","10"); |
754 | colorMenu->setItemChecked(-10,TRUE); | 754 | colorMenu->setItemChecked(-10,TRUE); |
755 | } | 755 | } |
756 | if(iD==-11) {// Red, Black | 756 | if(iD==-11) {// Red, Black |
757 | foreground.setRgb(230,31,31); //0xB2,0x18,0x18 | 757 | foreground.setRgb(230,31,31); //0xB2,0x18,0x18 |
758 | background.setRgb(0x00,0x00,0x00); | 758 | background.setRgb(0x00,0x00,0x00); |
759 | cfg.writeEntry("Schema","11"); | 759 | cfg.writeEntry("Schema","11"); |
760 | colorMenu->setItemChecked(-11,TRUE); | 760 | colorMenu->setItemChecked(-11,TRUE); |
761 | } | 761 | } |
762 | if(iD==-12) {// Green, Yellow - is ugly | 762 | if(iD==-12) {// Green, Yellow - is ugly |
763 | // foreground.setRgb(0x18,0xB2,0x18); | 763 | // foreground.setRgb(0x18,0xB2,0x18); |
764 | foreground.setRgb(36,139,10); | 764 | foreground.setRgb(36,139,10); |
765 | // background.setRgb(0xB2,0x68,0x18); | 765 | // background.setRgb(0xB2,0x68,0x18); |
766 | background.setRgb(255,255,0); | 766 | background.setRgb(255,255,0); |
767 | cfg.writeEntry("Schema","12"); | 767 | cfg.writeEntry("Schema","12"); |
768 | colorMenu->setItemChecked(-12,TRUE); | 768 | colorMenu->setItemChecked(-12,TRUE); |
769 | } | 769 | } |
770 | if(iD==-13) {// Blue, Magenta | 770 | if(iD==-13) {// Blue, Magenta |
771 | foreground.setRgb(0x18,0xB2,0xB2); | 771 | foreground.setRgb(0x18,0xB2,0xB2); |
772 | background.setRgb(0x18,0x18,0xB2); | 772 | background.setRgb(0x18,0x18,0xB2); |
773 | cfg.writeEntry("Schema","13"); | 773 | cfg.writeEntry("Schema","13"); |
774 | colorMenu->setItemChecked(-13,TRUE); | 774 | colorMenu->setItemChecked(-13,TRUE); |
775 | } | 775 | } |
776 | if(iD==-14) {// Magenta, Blue | 776 | if(iD==-14) {// Magenta, Blue |
777 | foreground.setRgb(0x18,0x18,0xB2); | 777 | foreground.setRgb(0x18,0x18,0xB2); |
778 | background.setRgb(0x18,0xB2,0xB2); | 778 | background.setRgb(0x18,0xB2,0xB2); |
779 | cfg.writeEntry("Schema","14"); | 779 | cfg.writeEntry("Schema","14"); |
780 | colorMenu->setItemChecked(-14,TRUE); | 780 | colorMenu->setItemChecked(-14,TRUE); |
781 | } | 781 | } |
782 | if(iD==-15) {// Cyan, White | 782 | if(iD==-15) {// Cyan, White |
783 | foreground.setRgb(0x18,0xB2,0xB2); | 783 | foreground.setRgb(0x18,0xB2,0xB2); |
784 | background.setRgb(0xFF,0xFF,0xFF); | 784 | background.setRgb(0xFF,0xFF,0xFF); |
785 | cfg.writeEntry("Schema","15"); | 785 | cfg.writeEntry("Schema","15"); |
786 | colorMenu->setItemChecked(-15,TRUE); | 786 | colorMenu->setItemChecked(-15,TRUE); |
787 | } | 787 | } |
788 | if(iD==-16) {// White, Cyan | 788 | if(iD==-16) {// White, Cyan |
789 | background.setRgb(0x18,0xB2,0xB2); | 789 | background.setRgb(0x18,0xB2,0xB2); |
790 | foreground.setRgb(0xFF,0xFF,0xFF); | 790 | foreground.setRgb(0xFF,0xFF,0xFF); |
791 | cfg.writeEntry("Schema","16"); | 791 | cfg.writeEntry("Schema","16"); |
792 | colorMenu->setItemChecked(-16,TRUE); | 792 | colorMenu->setItemChecked(-16,TRUE); |
793 | } | 793 | } |
794 | if(iD==-17) {// Black, Blue | 794 | if(iD==-17) {// Black, Blue |
795 | background.setRgb(0x00,0x00,0x00); | 795 | background.setRgb(0x00,0x00,0x00); |
796 | foreground.setRgb(0x18,0xB2,0xB2); | 796 | foreground.setRgb(0x18,0xB2,0xB2); |
797 | cfg.writeEntry("Schema","17"); | 797 | cfg.writeEntry("Schema","17"); |
798 | colorMenu->setItemChecked(-17,TRUE); | 798 | colorMenu->setItemChecked(-17,TRUE); |
799 | } | 799 | } |
800 | if(iD==-18) {// Black, Gold | 800 | if(iD==-18) {// Black, Gold |
801 | background.setRgb(0x00,0x00,0x00); | 801 | background.setRgb(0x00,0x00,0x00); |
802 | foreground.setRgb(255,215,0); | 802 | foreground.setRgb(255,215,0); |
803 | cfg.writeEntry("Schema","18"); | 803 | cfg.writeEntry("Schema","18"); |
804 | colorMenu->setItemChecked(-18,TRUE); | 804 | colorMenu->setItemChecked(-18,TRUE); |
805 | } | 805 | } |
806 | #ifdef QT_QWS_OPIE | 806 | #ifdef QT_QWS_OPIE |
807 | if(iD==-19) { | 807 | if(iD==-19) { |
808 | // Custom | 808 | // Custom |
809 | qDebug("do custom"); | 809 | qDebug("do custom"); |
810 | if(fromMenu) { | 810 | if(fromMenu) { |
811 | OColorPopupMenu* penColorPopupMenu = new OColorPopupMenu(Qt::black, this, "foreground color"); | 811 | OColorPopupMenu* penColorPopupMenu = new OColorPopupMenu(Qt::black, this, "foreground color"); |
812 | connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, | 812 | connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, |
813 | SLOT(changeForegroundColor(const QColor&))); | 813 | SLOT(changeForegroundColor(const QColor&))); |
814 | penColorPopupMenu->exec(); | 814 | penColorPopupMenu->exec(); |
815 | } | 815 | } |
816 | cfg.writeEntry("Schema","19"); | 816 | cfg.writeEntry("Schema","19"); |
817 | if(!fromMenu) { | 817 | if(!fromMenu) { |
818 | foreground.setNamedColor(cfg.readEntry("foreground","")); | 818 | foreground.setNamedColor(cfg.readEntry("foreground","")); |
819 | background.setNamedColor(cfg.readEntry("background","")); | 819 | background.setNamedColor(cfg.readEntry("background","")); |
820 | } | 820 | } |
821 | fromMenu=FALSE; | 821 | fromMenu=FALSE; |
822 | colorMenu->setItemChecked(-19,TRUE); | 822 | colorMenu->setItemChecked(-19,TRUE); |
823 | } | 823 | } |
824 | #endif | 824 | #endif |
825 | for (i = 0; i < TABLE_COLORS; i++) { | 825 | for (i = 0; i < TABLE_COLORS; i++) { |
826 | if(i==0 || i == 10) { | 826 | if(i==0 || i == 10) { |
827 | m_table[i].color = foreground; | 827 | m_table[i].color = foreground; |
828 | } | 828 | } |
829 | else if(i==1 || i == 11) { | 829 | else if(i==1 || i == 11) { |
830 | m_table[i].color = background; m_table[i].transparent=0; | 830 | m_table[i].color = background; m_table[i].transparent=0; |
831 | } | 831 | } |
832 | else | 832 | else |
833 | m_table[i].color = defaultCt[i].color; | 833 | m_table[i].color = defaultCt[i].color; |
834 | } | 834 | } |
835 | } | 835 | } |
836 | lastSelectedMenu = iD; | 836 | lastSelectedMenu = iD; |
837 | te->setColorTable(m_table); | 837 | te->setColorTable(m_table); |
838 | update(); | 838 | update(); |
839 | 839 | ||
840 | } | 840 | } |
841 | 841 | ||
842 | void Konsole::configMenuSelected(int iD) | 842 | void Konsole::configMenuSelected(int iD) |
843 | { | 843 | { |
844 | // QString temp; | 844 | // QString temp; |
845 | // qDebug( temp.sprintf("configmenu %d",iD)); | 845 | // qDebug( temp.sprintf("configmenu %d",iD)); |
846 | 846 | ||
847 | TEWidget* te = getTe(); | 847 | TEWidget* te = getTe(); |
848 | Config cfg("Konsole"); | 848 | Config cfg("Konsole"); |
849 | cfg.setGroup("Menubar"); | 849 | cfg.setGroup("Menubar"); |
850 | int i,j; | 850 | int i,j; |
851 | #ifdef QT_QWS_OPIE | 851 | #ifdef QT_QWS_OPIE |
852 | i=-29;j=-30; | 852 | i=-29;j=-30; |
853 | #else | 853 | #else |
854 | i=-28;j=-29; | 854 | i=-28;j=-29; |
855 | #endif | 855 | #endif |
856 | 856 | ||
857 | if(iD == -4) { | 857 | if(iD == -4) { |
858 | cfg.setGroup("Tabs"); | 858 | cfg.setGroup("Tabs"); |
859 | QString tmp=cfg.readEntry("Position","Bottom"); | 859 | QString tmp=cfg.readEntry("Position","Bottom"); |
860 | 860 | ||
861 | if(tmp=="Top") { | 861 | if(tmp=="Top") { |
862 | tab->setTabPosition(QTabWidget::Bottom); | 862 | tab->setTabPosition(QTabWidget::Bottom); |
863 | configMenu->changeItem( iD, tr("Tabs on Top")); | 863 | configMenu->changeItem( iD, tr("Tabs on Top")); |
864 | cfg.writeEntry("Position","Bottom"); | 864 | cfg.writeEntry("Position","Bottom"); |
865 | } else { | 865 | } else { |
866 | tab->setTabPosition(QTabWidget::Top); | 866 | tab->setTabPosition(QTabWidget::Top); |
867 | configMenu->changeItem( iD, tr("Tabs on Bottom")); | 867 | configMenu->changeItem( iD, tr("Tabs on Bottom")); |
868 | cfg.writeEntry("Position","Top"); | 868 | cfg.writeEntry("Position","Top"); |
869 | } | 869 | } |
870 | } | 870 | } |
871 | if(iD == i) { | 871 | if(iD == i) { |
872 | cfg.setGroup("ScrollBar"); | 872 | cfg.setGroup("ScrollBar"); |
873 | bool b=cfg.readBoolEntry("HorzScroll",0); | 873 | bool b=cfg.readBoolEntry("HorzScroll",0); |
874 | b=!b; | 874 | b=!b; |
875 | cfg.writeEntry("HorzScroll", b ); | 875 | cfg.writeEntry("HorzScroll", b ); |
876 | cfg.write(); | 876 | cfg.write(); |
877 | doWrap(); | 877 | doWrap(); |
878 | if(cfg.readNumEntry("Position",2) == 0) { | 878 | if(cfg.readNumEntry("Position",2) == 0) { |
879 | te->setScrollbarLocation(1); | 879 | te->setScrollbarLocation(1); |
880 | } else { | 880 | } else { |
881 | te->setScrollbarLocation(0); | 881 | te->setScrollbarLocation(0); |
882 | } | 882 | } |
883 | te->setScrollbarLocation( cfg.readNumEntry("Position",2)); | 883 | te->setScrollbarLocation( cfg.readNumEntry("Position",2)); |
884 | } | 884 | } |
885 | if(iD == j) { | 885 | if(iD == j) { |
886 | cfg.setGroup("Menubar"); | 886 | cfg.setGroup("Menubar"); |
887 | bool b=cfg.readBoolEntry("useBeep",0); | 887 | bool b=cfg.readBoolEntry("useBeep",0); |
888 | b=!b; | 888 | b=!b; |
889 | cfg.writeEntry("useBeep", b ); | 889 | cfg.writeEntry("useBeep", b ); |
890 | cfg.write(); | 890 | cfg.write(); |
891 | configMenu->setItemChecked(j,b); | 891 | configMenu->setItemChecked(j,b); |
892 | te->useBeep=b; | 892 | te->useBeep=b; |
893 | } | 893 | } |
894 | } | 894 | } |
895 | 895 | ||
896 | void Konsole::changeCommand(const QString &text, int c) | 896 | void Konsole::changeCommand(const QString &text, int c) |
897 | { | 897 | { |
898 | Config cfg("Konsole"); | 898 | Config cfg("Konsole"); |
899 | cfg.setGroup("Commands"); | 899 | cfg.setGroup("Commands"); |
900 | if(commonCmds[c] != text) { | 900 | if(commonCmds[c] != text) { |
901 | cfg.writeEntry(QString::number(c),text); | 901 | cfg.writeEntry(QString::number(c),text); |
902 | commonCombo->clearEdit(); | 902 | commonCombo->clearEdit(); |
903 | commonCombo->setCurrentItem(c); | 903 | commonCombo->setCurrentItem(c); |
904 | } | 904 | } |
905 | } | 905 | } |
906 | 906 | ||
907 | void Konsole::setColor() | 907 | void Konsole::setColor() |
908 | { | 908 | { |
909 | Config cfg("Konsole"); | 909 | Config cfg("Konsole"); |
910 | cfg.setGroup("Colors"); | 910 | cfg.setGroup("Colors"); |
911 | int scheme = cfg.readNumEntry("Schema",1); | 911 | int scheme = cfg.readNumEntry("Schema",1); |
912 | if(scheme != 1) colorMenuSelected( -scheme); | 912 | if(scheme != 1) colorMenuSelected( -scheme); |
913 | } | 913 | } |
914 | 914 | ||
915 | void Konsole::scrollMenuSelected(int index) | 915 | void Konsole::scrollMenuSelected(int index) |
916 | { | 916 | { |
917 | // qDebug( "scrollbar menu %d",index); | 917 | // qDebug( "scrollbar menu %d",index); |
918 | 918 | ||
919 | TEWidget* te = getTe(); | 919 | TEWidget* te = getTe(); |
920 | Config cfg("Konsole"); | 920 | Config cfg("Konsole"); |
921 | cfg.setGroup("ScrollBar"); | 921 | cfg.setGroup("ScrollBar"); |
922 | int i,j,k; | 922 | int i,j,k; |
923 | #ifdef QT_QWS_OPIE | 923 | #ifdef QT_QWS_OPIE |
924 | i=-25;j=-26;k=-27; | 924 | i=-25;j=-26;k=-27; |
925 | #else | 925 | #else |
926 | i=-24;j=-25;k=-26; | 926 | i=-24;j=-25;k=-26; |
927 | #endif | 927 | #endif |
928 | if(index == i) { | 928 | if(index == i) { |
929 | 929 | ||
930 | te->setScrollbarLocation(0); | 930 | te->setScrollbarLocation(0); |
931 | cfg.writeEntry("Position",0); | 931 | cfg.writeEntry("Position",0); |
932 | } else if(index == j) { | 932 | } else if(index == j) { |
933 | 933 | ||
934 | te->setScrollbarLocation(1); | 934 | te->setScrollbarLocation(1); |
935 | cfg.writeEntry("Position",1); | 935 | cfg.writeEntry("Position",1); |
936 | } else if(index == k) { | 936 | } else if(index == k) { |
937 | 937 | ||
938 | te->setScrollbarLocation(2); | 938 | te->setScrollbarLocation(2); |
939 | cfg.writeEntry("Position",2); | 939 | cfg.writeEntry("Position",2); |
940 | } | 940 | } |
941 | 941 | ||
942 | // case -29: { | 942 | // case -29: { |
943 | // bool b=cfg.readBoolEntry("HorzScroll",0); | 943 | // bool b=cfg.readBoolEntry("HorzScroll",0); |
944 | // cfg.writeEntry("HorzScroll", !b ); | 944 | // cfg.writeEntry("HorzScroll", !b ); |
945 | // cfg.write(); | 945 | // cfg.write(); |
946 | // if(cfg.readNumEntry("Position",2) == 0) { | 946 | // if(cfg.readNumEntry("Position",2) == 0) { |
947 | // te->setScrollbarLocation(1); | 947 | // te->setScrollbarLocation(1); |
948 | // te->setWrapAt(0); | 948 | // te->setWrapAt(0); |
949 | // } else { | 949 | // } else { |
950 | // te->setScrollbarLocation(0); | 950 | // te->setScrollbarLocation(0); |
951 | // te->setWrapAt(120); | 951 | // te->setWrapAt(120); |
952 | // } | 952 | // } |
953 | // te->setScrollbarLocation( cfg.readNumEntry("Position",2)); | 953 | // te->setScrollbarLocation( cfg.readNumEntry("Position",2)); |
954 | // } | 954 | // } |
955 | // break; | 955 | // break; |
956 | } | 956 | } |
957 | 957 | ||
958 | void Konsole::editCommandListMenuSelected(int iD) | 958 | void Konsole::editCommandListMenuSelected(int iD) |
959 | { | 959 | { |
960 | // QString temp; | 960 | // QString temp; |
961 | // qDebug( temp.sprintf("edit command list %d",iD)); | 961 | // qDebug( temp.sprintf("edit command list %d",iD)); |
962 | TEWidget* te = getTe(); | 962 | TEWidget* te = getTe(); |
963 | Config cfg("Konsole"); | 963 | Config cfg("Konsole"); |
964 | cfg.setGroup("Menubar"); | 964 | cfg.setGroup("Menubar"); |
965 | if( iD == -3) { | 965 | if( iD == -3) { |
966 | if(!secondToolBar->isHidden()) { | 966 | if(!secondToolBar->isHidden()) { |
967 | secondToolBar->hide(); | 967 | secondToolBar->hide(); |
968 | configMenu->changeItem( iD,tr( "Show Command List" )); | 968 | configMenu->changeItem( iD,tr( "Show Command List" )); |
969 | cfg.writeEntry("Hidden","TRUE"); | 969 | cfg.writeEntry("Hidden","TRUE"); |
970 | configMenu->setItemEnabled(-23 ,FALSE); | 970 | configMenu->setItemEnabled(-23 ,FALSE); |
971 | } else { | 971 | } else { |
972 | secondToolBar->show(); | 972 | secondToolBar->show(); |
973 | configMenu->changeItem( iD,tr( "Hide Command List" )); | 973 | configMenu->changeItem( iD,tr( "Hide Command List" )); |
974 | cfg.writeEntry("Hidden","FALSE"); | 974 | cfg.writeEntry("Hidden","FALSE"); |
975 | configMenu->setItemEnabled(-23 ,TRUE); | 975 | configMenu->setItemEnabled(-23 ,TRUE); |
976 | 976 | ||
977 | if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") { | 977 | if(cfg.readEntry("EditEnabled","FALSE")=="TRUE") { |
978 | configMenu->setItemChecked(-23,TRUE); | 978 | configMenu->setItemChecked(-23,TRUE); |
979 | commonCombo->setEditable( TRUE ); | 979 | commonCombo->setEditable( TRUE ); |
980 | } else { | 980 | } else { |
981 | configMenu->setItemChecked(-23,FALSE); | 981 | configMenu->setItemChecked(-23,FALSE); |
982 | commonCombo->setEditable( FALSE ); | 982 | commonCombo->setEditable( FALSE ); |
983 | } | 983 | } |
984 | } | 984 | } |
985 | } | 985 | } |
986 | if( iD == -23) { | 986 | if( iD == -23) { |
987 | cfg.setGroup("Commands"); | 987 | cfg.setGroup("Commands"); |
988 | // qDebug("enableCommandEdit"); | 988 | // qDebug("enableCommandEdit"); |
989 | if( !configMenu->isItemChecked(iD) ) { | 989 | if( !configMenu->isItemChecked(iD) ) { |
990 | commonCombo->setEditable( TRUE ); | 990 | commonCombo->setEditable( TRUE ); |
991 | configMenu->setItemChecked(iD,TRUE); | 991 | configMenu->setItemChecked(iD,TRUE); |
992 | commonCombo->setCurrentItem(0); | 992 | commonCombo->setCurrentItem(0); |
993 | cfg.writeEntry("EditEnabled","TRUE"); | 993 | cfg.writeEntry("EditEnabled","TRUE"); |
994 | } else { | 994 | } else { |
995 | commonCombo->setEditable( FALSE ); | 995 | commonCombo->setEditable( FALSE ); |
996 | configMenu->setItemChecked(iD,FALSE); | 996 | configMenu->setItemChecked(iD,FALSE); |
997 | cfg.writeEntry("EditEnabled","FALSE"); | 997 | cfg.writeEntry("EditEnabled","FALSE"); |
998 | commonCombo->setFocusPolicy(QWidget::NoFocus); | 998 | commonCombo->setFocusPolicy(QWidget::NoFocus); |
999 | te->setFocus(); | 999 | te->setFocus(); |
1000 | } | 1000 | } |
1001 | } | 1001 | } |
1002 | if(iD == -24) { | 1002 | if(iD == -24) { |
1003 | // "edit commands" | 1003 | // "edit commands" |
1004 | CommandEditDialog *m = new CommandEditDialog(this); | 1004 | CommandEditDialog *m = new CommandEditDialog(this); |
1005 | connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList())); | 1005 | connect(m,SIGNAL(commandsEdited()),this,SLOT(initCommandList())); |
1006 | m->showMaximized(); | 1006 | m->showMaximized(); |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | } | 1009 | } |
1010 | 1010 | ||
1011 | // $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V' | 1011 | // $QPEDIR/bin/qcop QPE/Application/embeddedkonsole 'setDocument(QString)' 'ssh -V' |
1012 | void Konsole::setDocument( const QString &cmd) { | 1012 | void Konsole::setDocument( const QString &cmd) { |
1013 | newSession(); | 1013 | newSession(); |
1014 | TEWidget* te = getTe(); | 1014 | TEWidget* te = getTe(); |
1015 | if(cmd.find("-e", 0, TRUE) != -1) { | 1015 | if(cmd.find("-e", 0, TRUE) != -1) { |
1016 | QString cmd2; | 1016 | QString cmd2; |
1017 | cmd2=cmd.right(cmd.length()-3)+" &"; | 1017 | cmd2=cmd.right(cmd.length()-3)+" &"; |
1018 | system(cmd2.latin1()); | 1018 | system(cmd2.latin1()); |
1019 | if(startUp <= 1 && nsessions < 2) { | 1019 | if(startUp <= 1 && nsessions < 2) { |
1020 | doneSession(getTe()->currentSession, 0); | 1020 | doneSession(getTe()->currentSession, 0); |
1021 | exit(0); | 1021 | exit(0); |
1022 | } else | 1022 | } else |
1023 | doneSession(getTe()->currentSession, 0); | 1023 | doneSession(getTe()->currentSession, 0); |
1024 | } else { | 1024 | } else { |
1025 | if (te != 0) { | 1025 | if (te != 0) { |
1026 | te->emitText(cmd+"\r"); | 1026 | te->emitText(cmd+"\r"); |
1027 | } | 1027 | } |
1028 | } | 1028 | } |
1029 | startUp++; | 1029 | startUp++; |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | void Konsole::parseCommandLine() { | 1032 | void Konsole::parseCommandLine() { |
1033 | QString cmd; | 1033 | QString cmd; |
1034 | // newSession(); | 1034 | // newSession(); |
1035 | for (int i=1;i< qApp->argc();i++) { | 1035 | for (int i=1;i< qApp->argc();i++) { |
1036 | if( QString(qApp->argv()[i]) == "-e") { | 1036 | if( QString(qApp->argv()[i]) == "-e") { |
1037 | i++; | 1037 | i++; |
1038 | for ( int j=i;j< qApp->argc();j++) { | 1038 | for ( int j=i;j< qApp->argc();j++) { |
1039 | cmd+=QString(qApp->argv()[j])+" "; | 1039 | cmd+=QString(qApp->argv()[j])+" "; |
1040 | } | 1040 | } |
1041 | cmd.stripWhiteSpace(); | 1041 | cmd.stripWhiteSpace(); |
1042 | system(cmd.latin1()); | 1042 | system(cmd.latin1()); |
1043 | exit(0);//close(); | 1043 | exit(0);//close(); |
1044 | } // end -e switch | 1044 | } // end -e switch |
1045 | } | 1045 | } |
1046 | startUp++; | 1046 | startUp++; |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | void Konsole::changeForegroundColor(const QColor &color) { | 1049 | void Konsole::changeForegroundColor(const QColor &color) { |
1050 | Config cfg("Konsole"); | 1050 | Config cfg("Konsole"); |
1051 | cfg.setGroup("Colors"); | 1051 | cfg.setGroup("Colors"); |
1052 | int r, g, b; | 1052 | int r, g, b; |
1053 | color.rgb(&r,&g,&b); | 1053 | color.rgb(&r,&g,&b); |
1054 | foreground.setRgb(r,g,b); | 1054 | foreground.setRgb(r,g,b); |
1055 | 1055 | ||
1056 | cfg.writeEntry("foreground",color.name()); | 1056 | cfg.writeEntry("foreground",color.name()); |
1057 | qDebug("foreground "+color.name()); | 1057 | qDebug("foreground "+color.name()); |
1058 | cfg.write(); | 1058 | cfg.write(); |
1059 | 1059 | ||
1060 | qDebug("do other dialog"); | 1060 | qDebug("do other dialog"); |
1061 | #ifdef QT_QWS_OPIE | 1061 | #ifdef QT_QWS_OPIE |
1062 | 1062 | ||
1063 | OColorPopupMenu* penColorPopupMenu2 = new OColorPopupMenu(Qt::black, this,"background color"); | 1063 | OColorPopupMenu* penColorPopupMenu2 = new OColorPopupMenu(Qt::black, this,"background color"); |
1064 | connect(penColorPopupMenu2, SIGNAL(colorSelected(const QColor&)), this, | 1064 | connect(penColorPopupMenu2, SIGNAL(colorSelected(const QColor&)), this, |
1065 | SLOT(changeBackgroundColor(const QColor&))); | 1065 | SLOT(changeBackgroundColor(const QColor&))); |
1066 | penColorPopupMenu2->exec(); | 1066 | penColorPopupMenu2->exec(); |
1067 | #endif | 1067 | #endif |
1068 | } | 1068 | } |
1069 | 1069 | ||
1070 | void Konsole::changeBackgroundColor(const QColor &color) { | 1070 | void Konsole::changeBackgroundColor(const QColor &color) { |
1071 | 1071 | ||
1072 | qDebug("Change background"); | 1072 | qDebug("Change background"); |
1073 | Config cfg("Konsole"); | 1073 | Config cfg("Konsole"); |
1074 | cfg.setGroup("Colors"); | 1074 | cfg.setGroup("Colors"); |
1075 | int r, g, b; | 1075 | int r, g, b; |
1076 | color.rgb(&r,&g,&b); | 1076 | color.rgb(&r,&g,&b); |
1077 | background.setRgb(r,g,b); | 1077 | background.setRgb(r,g,b); |
1078 | cfg.writeEntry("background",color.name()); | 1078 | cfg.writeEntry("background",color.name()); |
1079 | qDebug("background "+color.name()); | 1079 | qDebug("background "+color.name()); |
1080 | cfg.write(); | 1080 | cfg.write(); |
1081 | } | 1081 | } |
1082 | 1082 | ||
1083 | void Konsole::doWrap() { | 1083 | void Konsole::doWrap() { |
1084 | int i; | 1084 | int i; |
1085 | #ifdef QT_QWS_OPIE | 1085 | #ifdef QT_QWS_OPIE |
1086 | i=-29; | 1086 | i=-29; |
1087 | #else | 1087 | #else |
1088 | i=-28; | 1088 | i=-28; |
1089 | #endif | 1089 | #endif |
1090 | 1090 | ||
1091 | Config cfg("Konsole"); | 1091 | Config cfg("Konsole"); |
1092 | cfg.setGroup("ScrollBar"); | 1092 | cfg.setGroup("ScrollBar"); |
1093 | TEWidget* te = getTe(); | 1093 | TEWidget* te = getTe(); |
1094 | if( !cfg.readBoolEntry("HorzScroll",0)) { | 1094 | if( !cfg.readBoolEntry("HorzScroll",0)) { |
1095 | te->setWrapAt(0); | 1095 | te->setWrapAt(0); |
1096 | configMenu->setItemChecked( i,TRUE); | 1096 | configMenu->setItemChecked( i,TRUE); |
1097 | } else { | 1097 | } else { |
1098 | // te->setWrapAt(90); | 1098 | // te->setWrapAt(90); |
1099 | te->setWrapAt(120); | 1099 | te->setWrapAt(120); |
1100 | configMenu->setItemChecked( i,FALSE); | 1100 | configMenu->setItemChecked( i,FALSE); |
1101 | } | 1101 | } |
1102 | } | 1102 | } |
diff --git a/core/apps/embeddedkonsole/konsole.h b/core/apps/embeddedkonsole/konsole.h index e9d0e4b..7d5a908 100644 --- a/core/apps/embeddedkonsole/konsole.h +++ b/core/apps/embeddedkonsole/konsole.h | |||
@@ -1,144 +1,144 @@ | |||
1 | /* ----------------------------------------------------------------------- */ | 1 | /* ----------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [konsole.h] Konsole */ | 3 | /* [konsole.h] Konsole */ |
4 | /* */ | 4 | /* */ |
5 | /* -------------------------------------------------------------------------- */ | 5 | /* -------------------------------------------------------------------------- */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole, an X terminal. */ | 9 | /* This file is part of Konsole, an X terminal. */ |
10 | /* */ | 10 | /* */ |
11 | /* The material contained in here more or less directly orginates from */ | 11 | /* The material contained in here more or less directly orginates from */ |
12 | /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ | 12 | /* kvt, which is copyright (c) 1996 by Matthias Ettrich <ettrich@kde.org> */ |
13 | /* */ | 13 | /* */ |
14 | /* -------------------------------------------------------------------------- */ | 14 | /* -------------------------------------------------------------------------- */ |
15 | /* */ | 15 | /* */ |
16 | /* Ported Konsole to Qt/Embedded */ | 16 | /* Ported Konsole to Qt/Embedded */ |
17 | /* */ | 17 | /* */ |
18 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 18 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
19 | /* */ | 19 | /* */ |
20 | /* -------------------------------------------------------------------------- */ | 20 | /* -------------------------------------------------------------------------- */ |
21 | 21 | ||
22 | #ifndef KONSOLE_H | 22 | #ifndef KONSOLE_H |
23 | #define KONSOLE_H | 23 | #define KONSOLE_H |
24 | 24 | ||
25 | 25 | ||
26 | #include <qmainwindow.h> | 26 | #include <qmainwindow.h> |
27 | #include <qaction.h> | 27 | #include <qaction.h> |
28 | #include <qpopupmenu.h> | 28 | #include <qpopupmenu.h> |
29 | #include <qstrlist.h> | 29 | #include <qstrlist.h> |
30 | #include <qintdict.h> | 30 | #include <qintdict.h> |
31 | #include <qptrdict.h> | 31 | #include <qptrdict.h> |
32 | #include <qtabwidget.h> | 32 | #include <qtabwidget.h> |
33 | #include <qpe/qpetoolbar.h> | 33 | #include <qtoolbar.h> |
34 | #include <qcombobox.h> | 34 | #include <qcombobox.h> |
35 | #include <qcolor.h> | 35 | #include <qcolor.h> |
36 | 36 | ||
37 | #include "MyPty.h" | 37 | #include "MyPty.h" |
38 | #include "TEWidget.h" | 38 | #include "TEWidget.h" |
39 | #include "TEmuVt102.h" | 39 | #include "TEmuVt102.h" |
40 | #include "session.h" | 40 | #include "session.h" |
41 | 41 | ||
42 | class EKNumTabWidget; | 42 | class EKNumTabWidget; |
43 | 43 | ||
44 | class Konsole : public QMainWindow | 44 | class Konsole : public QMainWindow |
45 | { | 45 | { |
46 | Q_OBJECT | 46 | Q_OBJECT |
47 | 47 | ||
48 | public: | 48 | public: |
49 | static QString appName() { return QString::fromLatin1("embeddedkonsole"); } | 49 | static QString appName() { return QString::fromLatin1("embeddedkonsole"); } |
50 | 50 | ||
51 | Konsole(QWidget* parent = 0, const char* name = 0, WFlags fl = 0); | 51 | Konsole(QWidget* parent = 0, const char* name = 0, WFlags fl = 0); |
52 | ~Konsole(); | 52 | ~Konsole(); |
53 | void setColLin(int columns, int lines); | 53 | void setColLin(int columns, int lines); |
54 | QPEToolBar *secondToolBar; | 54 | QToolBar *secondToolBar; |
55 | void show(); | 55 | void show(); |
56 | void setColor(); | 56 | void setColor(); |
57 | int lastSelectedMenu; | 57 | int lastSelectedMenu; |
58 | int startUp; | 58 | int startUp; |
59 | private slots: | 59 | private slots: |
60 | void setDocument(const QString &); | 60 | void setDocument(const QString &); |
61 | void doneSession(TESession*,int); | 61 | void doneSession(TESession*,int); |
62 | void changeColumns(int); | 62 | void changeColumns(int); |
63 | void fontChanged(int); | 63 | void fontChanged(int); |
64 | void configMenuSelected(int ); | 64 | void configMenuSelected(int ); |
65 | void colorMenuSelected(int); | 65 | void colorMenuSelected(int); |
66 | void colorMenuIsSelected(int); | 66 | void colorMenuIsSelected(int); |
67 | void enterCommand(int); | 67 | void enterCommand(int); |
68 | void hitEnter(); | 68 | void hitEnter(); |
69 | void hitSpace(); | 69 | void hitSpace(); |
70 | void hitTab(); | 70 | void hitTab(); |
71 | void hitPaste(); | 71 | void hitPaste(); |
72 | void hitUp(); | 72 | void hitUp(); |
73 | void hitDown(); | 73 | void hitDown(); |
74 | void switchSession(QWidget *); | 74 | void switchSession(QWidget *); |
75 | void newSession(); | 75 | void newSession(); |
76 | void changeCommand(const QString &, int); | 76 | void changeCommand(const QString &, int); |
77 | void initCommandList(); | 77 | void initCommandList(); |
78 | void scrollMenuSelected(int); | 78 | void scrollMenuSelected(int); |
79 | void editCommandListMenuSelected(int); | 79 | void editCommandListMenuSelected(int); |
80 | void parseCommandLine(); | 80 | void parseCommandLine(); |
81 | void changeForegroundColor(const QColor &); | 81 | void changeForegroundColor(const QColor &); |
82 | void changeBackgroundColor(const QColor &); | 82 | void changeBackgroundColor(const QColor &); |
83 | private: | 83 | private: |
84 | void doWrap(); | 84 | void doWrap(); |
85 | void init(const char* _pgm, QStrList & _args); | 85 | void init(const char* _pgm, QStrList & _args); |
86 | void initSession(const char* _pgm, QStrList & _args); | 86 | void initSession(const char* _pgm, QStrList & _args); |
87 | void runSession(TESession* s); | 87 | void runSession(TESession* s); |
88 | void setColorPixmaps(); | 88 | void setColorPixmaps(); |
89 | void setHistory(bool); | 89 | void setHistory(bool); |
90 | QSize calcSize(int columns, int lines); | 90 | QSize calcSize(int columns, int lines); |
91 | TEWidget* getTe(); | 91 | TEWidget* getTe(); |
92 | QStringList commands; | 92 | QStringList commands; |
93 | QLabel * msgLabel; | 93 | QLabel * msgLabel; |
94 | QColor foreground, background; | 94 | QColor foreground, background; |
95 | bool fromMenu; | 95 | bool fromMenu; |
96 | private: | 96 | private: |
97 | class VTFont | 97 | class VTFont |
98 | { | 98 | { |
99 | public: | 99 | public: |
100 | VTFont(QString name, QFont& font) | 100 | VTFont(QString name, QFont& font) |
101 | { | 101 | { |
102 | this->name = name; | 102 | this->name = name; |
103 | this->font = font; | 103 | this->font = font; |
104 | } | 104 | } |
105 | 105 | ||
106 | QFont& getFont() | 106 | QFont& getFont() |
107 | { | 107 | { |
108 | return font; | 108 | return font; |
109 | } | 109 | } |
110 | 110 | ||
111 | QString getName() | 111 | QString getName() |
112 | { | 112 | { |
113 | return name; | 113 | return name; |
114 | } | 114 | } |
115 | 115 | ||
116 | private: | 116 | private: |
117 | QString name; | 117 | QString name; |
118 | QFont font; | 118 | QFont font; |
119 | }; | 119 | }; |
120 | 120 | ||
121 | EKNumTabWidget* tab; | 121 | EKNumTabWidget* tab; |
122 | int nsessions; | 122 | int nsessions; |
123 | QList<VTFont> fonts; | 123 | QList<VTFont> fonts; |
124 | int cfont; | 124 | int cfont; |
125 | QCString se_pgm; | 125 | QCString se_pgm; |
126 | QStrList se_args; | 126 | QStrList se_args; |
127 | 127 | ||
128 | QPopupMenu *fontList,*configMenu,*colorMenu,*scrollMenu,*editCommandListMenu; | 128 | QPopupMenu *fontList,*configMenu,*colorMenu,*scrollMenu,*editCommandListMenu; |
129 | QComboBox *commonCombo; | 129 | QComboBox *commonCombo; |
130 | // history scrolling I think | 130 | // history scrolling I think |
131 | bool b_scroll; | 131 | bool b_scroll; |
132 | 132 | ||
133 | int n_keytab; | 133 | int n_keytab; |
134 | int n_scroll; | 134 | int n_scroll; |
135 | int n_render; | 135 | int n_render; |
136 | QString pmPath; // pixmap path | 136 | QString pmPath; // pixmap path |
137 | QString dropText; | 137 | QString dropText; |
138 | QFont defaultFont; | 138 | QFont defaultFont; |
139 | QSize defaultSize; | 139 | QSize defaultSize; |
140 | 140 | ||
141 | }; | 141 | }; |
142 | 142 | ||
143 | #endif | 143 | #endif |
144 | 144 | ||
diff --git a/core/apps/helpbrowser/helpbrowser.cpp b/core/apps/helpbrowser/helpbrowser.cpp index ed1c165..6f84ae2 100644 --- a/core/apps/helpbrowser/helpbrowser.cpp +++ b/core/apps/helpbrowser/helpbrowser.cpp | |||
@@ -1,250 +1,250 @@ | |||
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 | 22 | ||
23 | #include "helpbrowser.h" | 23 | #include "helpbrowser.h" |
24 | 24 | ||
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/mimetype.h> | 27 | #include <qpe/mimetype.h> |
28 | #include <qpe/applnk.h> | 28 | #include <qpe/applnk.h> |
29 | #include <qpe/global.h> | 29 | #include <qpe/global.h> |
30 | 30 | ||
31 | #include <qstatusbar.h> | 31 | #include <qstatusbar.h> |
32 | #include <qdragobject.h> | 32 | #include <qdragobject.h> |
33 | #include <qpixmap.h> | 33 | #include <qpixmap.h> |
34 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
35 | #include <qmenubar.h> | 35 | #include <qmenubar.h> |
36 | #include <qpe/qpetoolbar.h> | 36 | #include <qtoolbar.h> |
37 | #include <qpe/qcopenvelope_qws.h> | 37 | #include <qpe/qcopenvelope_qws.h> |
38 | #include <qtoolbutton.h> | 38 | #include <qtoolbutton.h> |
39 | #include <qiconset.h> | 39 | #include <qiconset.h> |
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qstylesheet.h> | 42 | #include <qstylesheet.h> |
43 | #include <qmessagebox.h> | 43 | #include <qmessagebox.h> |
44 | #include <qfiledialog.h> | 44 | #include <qfiledialog.h> |
45 | #include <qevent.h> | 45 | #include <qevent.h> |
46 | #include <qlineedit.h> | 46 | #include <qlineedit.h> |
47 | #include <qobjectlist.h> | 47 | #include <qobjectlist.h> |
48 | #include <qfileinfo.h> | 48 | #include <qfileinfo.h> |
49 | #include <qfile.h> | 49 | #include <qfile.h> |
50 | #include <qdatastream.h> | 50 | #include <qdatastream.h> |
51 | #include <qprinter.h> | 51 | #include <qprinter.h> |
52 | #include <qsimplerichtext.h> | 52 | #include <qsimplerichtext.h> |
53 | #include <qpaintdevicemetrics.h> | 53 | #include <qpaintdevicemetrics.h> |
54 | #include <qaction.h> | 54 | #include <qaction.h> |
55 | 55 | ||
56 | #include <cctype> | 56 | #include <cctype> |
57 | 57 | ||
58 | #include "magictextbrowser.h" | 58 | #include "magictextbrowser.h" |
59 | 59 | ||
60 | HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f ) | 60 | HelpBrowser::HelpBrowser( QWidget* parent, const char *name, WFlags f ) |
61 | : QMainWindow( parent, name, f ), | 61 | : QMainWindow( parent, name, f ), |
62 | selectedURL() | 62 | selectedURL() |
63 | { | 63 | { |
64 | init( "index.html" ); | 64 | init( "index.html" ); |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | 68 | ||
69 | void HelpBrowser::init( const QString& _home ) | 69 | void HelpBrowser::init( const QString& _home ) |
70 | { | 70 | { |
71 | setIcon( Resource::loadPixmap( "HelpBrowser" ) ); | 71 | setIcon( Resource::loadPixmap( "HelpBrowser" ) ); |
72 | setBackgroundMode( PaletteButton ); | 72 | setBackgroundMode( PaletteButton ); |
73 | 73 | ||
74 | browser = new MagicTextBrowser( this ); | 74 | browser = new MagicTextBrowser( this ); |
75 | browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 75 | browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
76 | connect( browser, SIGNAL( textChanged() ), | 76 | connect( browser, SIGNAL( textChanged() ), |
77 | this, SLOT( textChanged() ) ); | 77 | this, SLOT( textChanged() ) ); |
78 | 78 | ||
79 | setCentralWidget( browser ); | 79 | setCentralWidget( browser ); |
80 | setToolBarsMovable( FALSE ); | 80 | setToolBarsMovable( FALSE ); |
81 | 81 | ||
82 | if ( !_home.isEmpty() ) | 82 | if ( !_home.isEmpty() ) |
83 | browser->setSource( _home ); | 83 | browser->setSource( _home ); |
84 | 84 | ||
85 | QPEToolBar* toolbar = new QPEToolBar( this ); | 85 | QToolBar* toolbar = new QToolBar( this ); |
86 | toolbar->setHorizontalStretchable( TRUE ); | 86 | toolbar->setHorizontalStretchable( TRUE ); |
87 | QMenuBar *menu = new QMenuBar( toolbar ); | 87 | QMenuBar *menu = new QMenuBar( toolbar ); |
88 | 88 | ||
89 | toolbar = new QPEToolBar( this ); | 89 | toolbar = new QToolBar( this ); |
90 | // addToolBar( toolbar, "Toolbar"); | 90 | // addToolBar( toolbar, "Toolbar"); |
91 | 91 | ||
92 | QPopupMenu* go = new QPopupMenu( this ); | 92 | QPopupMenu* go = new QPopupMenu( this ); |
93 | backAction = new QAction( tr( "Backward" ), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 ); | 93 | backAction = new QAction( tr( "Backward" ), Resource::loadIconSet( "back" ), QString::null, 0, this, 0 ); |
94 | connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) ); | 94 | connect( backAction, SIGNAL( activated() ), browser, SLOT( backward() ) ); |
95 | connect( browser, SIGNAL( backwardAvailable( bool ) ), | 95 | connect( browser, SIGNAL( backwardAvailable( bool ) ), |
96 | backAction, SLOT( setEnabled( bool ) ) ); | 96 | backAction, SLOT( setEnabled( bool ) ) ); |
97 | backAction->addTo( go ); | 97 | backAction->addTo( go ); |
98 | backAction->addTo( toolbar ); | 98 | backAction->addTo( toolbar ); |
99 | backAction->setEnabled( FALSE ); | 99 | backAction->setEnabled( FALSE ); |
100 | 100 | ||
101 | forwardAction = new QAction( tr( "Forward" ), Resource::loadIconSet( "forward" ), QString::null, 0, this, 0 ); | 101 | forwardAction = new QAction( tr( "Forward" ), Resource::loadIconSet( "forward" ), QString::null, 0, this, 0 ); |
102 | connect( forwardAction, SIGNAL( activated() ), browser, SLOT( forward() ) ); | 102 | connect( forwardAction, SIGNAL( activated() ), browser, SLOT( forward() ) ); |
103 | connect( browser, SIGNAL( forwardAvailable( bool ) ), | 103 | connect( browser, SIGNAL( forwardAvailable( bool ) ), |
104 | forwardAction, SLOT( setEnabled( bool ) ) ); | 104 | forwardAction, SLOT( setEnabled( bool ) ) ); |
105 | forwardAction->addTo( go ); | 105 | forwardAction->addTo( go ); |
106 | forwardAction->addTo( toolbar ); | 106 | forwardAction->addTo( toolbar ); |
107 | forwardAction->setEnabled( FALSE ); | 107 | forwardAction->setEnabled( FALSE ); |
108 | 108 | ||
109 | QAction *a = new QAction( tr( "Home" ), Resource::loadIconSet( "home" ), QString::null, 0, this, 0 ); | 109 | QAction *a = new QAction( tr( "Home" ), Resource::loadIconSet( "home" ), QString::null, 0, this, 0 ); |
110 | connect( a, SIGNAL( activated() ), browser, SLOT( home() ) ); | 110 | connect( a, SIGNAL( activated() ), browser, SLOT( home() ) ); |
111 | a->addTo( go ); | 111 | a->addTo( go ); |
112 | a->addTo( toolbar ); | 112 | a->addTo( toolbar ); |
113 | 113 | ||
114 | bookm = new QPopupMenu( this ); | 114 | bookm = new QPopupMenu( this ); |
115 | bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); | 115 | bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); |
116 | bookm->insertItem( tr( "Remove from Bookmarks" ), this, SLOT( removeBookmark() ) ); | 116 | bookm->insertItem( tr( "Remove from Bookmarks" ), this, SLOT( removeBookmark() ) ); |
117 | bookm->insertSeparator(); | 117 | bookm->insertSeparator(); |
118 | connect( bookm, SIGNAL( activated( int ) ), | 118 | connect( bookm, SIGNAL( activated( int ) ), |
119 | this, SLOT( bookmChosen( int ) ) ); | 119 | this, SLOT( bookmChosen( int ) ) ); |
120 | 120 | ||
121 | readBookmarks(); | 121 | readBookmarks(); |
122 | 122 | ||
123 | menu->insertItem( tr("Go"), go ); | 123 | menu->insertItem( tr("Go"), go ); |
124 | menu->insertItem( tr( "Bookmarks" ), bookm ); | 124 | menu->insertItem( tr( "Bookmarks" ), bookm ); |
125 | 125 | ||
126 | resize( 240, 300 ); | 126 | resize( 240, 300 ); |
127 | browser->setFocus(); | 127 | browser->setFocus(); |
128 | browser->setFrameStyle( QFrame::NoFrame ); | 128 | browser->setFrameStyle( QFrame::NoFrame ); |
129 | 129 | ||
130 | #if !defined(QT_NO_COP) | 130 | #if !defined(QT_NO_COP) |
131 | QCopChannel *addressChannel = new QCopChannel("QPE/HelpBrowser" , this ); | 131 | QCopChannel *addressChannel = new QCopChannel("QPE/HelpBrowser" , this ); |
132 | connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), | 132 | connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), |
133 | this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); | 133 | this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); |
134 | #endif | 134 | #endif |
135 | 135 | ||
136 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), | 136 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), |
137 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); | 137 | this, SLOT(appMessage(const QCString&, const QByteArray&)) ); |
138 | } | 138 | } |
139 | 139 | ||
140 | void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data) | 140 | void HelpBrowser::appMessage(const QCString& msg, const QByteArray& data) |
141 | { | 141 | { |
142 | qDebug("reached appMessage"); | 142 | qDebug("reached appMessage"); |
143 | if ( msg == "showFile(QString)" ) { | 143 | if ( msg == "showFile(QString)" ) { |
144 | QDataStream ds(data,IO_ReadOnly); | 144 | QDataStream ds(data,IO_ReadOnly); |
145 | QString fn; | 145 | QString fn; |
146 | ds >> fn; | 146 | ds >> fn; |
147 | setDocument( fn ); | 147 | setDocument( fn ); |
148 | 148 | ||
149 | QPEApplication::setKeepRunning(); | 149 | QPEApplication::setKeepRunning(); |
150 | 150 | ||
151 | showMaximized(); | 151 | showMaximized(); |
152 | setActiveWindow(); | 152 | setActiveWindow(); |
153 | raise(); | 153 | raise(); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | 156 | ||
157 | void HelpBrowser::setDocument( const QString &doc ) | 157 | void HelpBrowser::setDocument( const QString &doc ) |
158 | { | 158 | { |
159 | if ( !doc.isEmpty() ) | 159 | if ( !doc.isEmpty() ) |
160 | browser->setSource( doc ); | 160 | browser->setSource( doc ); |
161 | raise(); | 161 | raise(); |
162 | } | 162 | } |
163 | 163 | ||
164 | 164 | ||
165 | void HelpBrowser::textChanged() | 165 | void HelpBrowser::textChanged() |
166 | { | 166 | { |
167 | if ( browser->documentTitle().isNull() ) | 167 | if ( browser->documentTitle().isNull() ) |
168 | setCaption( tr("Help Browser") ); | 168 | setCaption( tr("Help Browser") ); |
169 | else | 169 | else |
170 | setCaption( browser->documentTitle() ) ; | 170 | setCaption( browser->documentTitle() ) ; |
171 | 171 | ||
172 | selectedURL = caption(); | 172 | selectedURL = caption(); |
173 | } | 173 | } |
174 | 174 | ||
175 | HelpBrowser::~HelpBrowser() | 175 | HelpBrowser::~HelpBrowser() |
176 | { | 176 | { |
177 | QStringList bookmarks; | 177 | QStringList bookmarks; |
178 | QMap<int, Bookmark>::Iterator it2 = mBookmarks.begin(); | 178 | QMap<int, Bookmark>::Iterator it2 = mBookmarks.begin(); |
179 | for ( ; it2 != mBookmarks.end(); ++it2 ) | 179 | for ( ; it2 != mBookmarks.end(); ++it2 ) |
180 | bookmarks.append( (*it2).name + "=" + (*it2).file ); | 180 | bookmarks.append( (*it2).name + "=" + (*it2).file ); |
181 | 181 | ||
182 | QFile f2( Global::applicationFileName("helpbrowser", "bookmarks") ); | 182 | QFile f2( Global::applicationFileName("helpbrowser", "bookmarks") ); |
183 | if ( f2.open( IO_WriteOnly ) ) { | 183 | if ( f2.open( IO_WriteOnly ) ) { |
184 | QDataStream s2( &f2 ); | 184 | QDataStream s2( &f2 ); |
185 | s2 << bookmarks; | 185 | s2 << bookmarks; |
186 | f2.close(); | 186 | f2.close(); |
187 | } | 187 | } |
188 | } | 188 | } |
189 | 189 | ||
190 | void HelpBrowser::pathSelected( const QString &_path ) | 190 | void HelpBrowser::pathSelected( const QString &_path ) |
191 | { | 191 | { |
192 | browser->setSource( _path ); | 192 | browser->setSource( _path ); |
193 | } | 193 | } |
194 | 194 | ||
195 | void HelpBrowser::readBookmarks() | 195 | void HelpBrowser::readBookmarks() |
196 | { | 196 | { |
197 | QString file = Global::applicationFileName("helpbrowser", "bookmarks"); | 197 | QString file = Global::applicationFileName("helpbrowser", "bookmarks"); |
198 | if ( QFile::exists( file ) ) { | 198 | if ( QFile::exists( file ) ) { |
199 | QStringList bookmarks; | 199 | QStringList bookmarks; |
200 | QFile f( file ); | 200 | QFile f( file ); |
201 | if ( f.open( IO_ReadOnly ) ) { | 201 | if ( f.open( IO_ReadOnly ) ) { |
202 | QDataStream s( &f ); | 202 | QDataStream s( &f ); |
203 | s >> bookmarks; | 203 | s >> bookmarks; |
204 | f.close(); | 204 | f.close(); |
205 | } | 205 | } |
206 | QStringList::Iterator it = bookmarks.begin(); | 206 | QStringList::Iterator it = bookmarks.begin(); |
207 | for ( ; it != bookmarks.end(); ++it ) { | 207 | for ( ; it != bookmarks.end(); ++it ) { |
208 | Bookmark b; | 208 | Bookmark b; |
209 | QString current = *it; | 209 | QString current = *it; |
210 | int equal = current.find( "=" ); | 210 | int equal = current.find( "=" ); |
211 | if ( equal < 1 || equal == (int)current.length() - 1 ) | 211 | if ( equal < 1 || equal == (int)current.length() - 1 ) |
212 | continue; | 212 | continue; |
213 | b.name = current.left( equal ); | 213 | b.name = current.left( equal ); |
214 | b.file = current.mid( equal + 1 ); | 214 | b.file = current.mid( equal + 1 ); |
215 | mBookmarks[ bookm->insertItem( b.name ) ] = b; | 215 | mBookmarks[ bookm->insertItem( b.name ) ] = b; |
216 | } | 216 | } |
217 | } | 217 | } |
218 | } | 218 | } |
219 | 219 | ||
220 | void HelpBrowser::bookmChosen( int i ) | 220 | void HelpBrowser::bookmChosen( int i ) |
221 | { | 221 | { |
222 | if ( mBookmarks.contains( i ) ) | 222 | if ( mBookmarks.contains( i ) ) |
223 | browser->setSource( mBookmarks[ i ].file ); | 223 | browser->setSource( mBookmarks[ i ].file ); |
224 | } | 224 | } |
225 | 225 | ||
226 | void HelpBrowser::addBookmark() | 226 | void HelpBrowser::addBookmark() |
227 | { | 227 | { |
228 | Bookmark b; | 228 | Bookmark b; |
229 | b.name = browser->documentTitle(); | 229 | b.name = browser->documentTitle(); |
230 | b.file = browser->source(); | 230 | b.file = browser->source(); |
231 | if (b.name.isEmpty() ) { | 231 | if (b.name.isEmpty() ) { |
232 | b.name = b.file.left( b.file.length() - 5 ); // remove .html | 232 | b.name = b.file.left( b.file.length() - 5 ); // remove .html |
233 | } | 233 | } |
234 | QMap<int, Bookmark>::Iterator it; | 234 | QMap<int, Bookmark>::Iterator it; |
235 | for( it = mBookmarks.begin(); it != mBookmarks.end(); ++it ) | 235 | for( it = mBookmarks.begin(); it != mBookmarks.end(); ++it ) |
236 | if ( (*it).file == b.file ) return; | 236 | if ( (*it).file == b.file ) return; |
237 | mBookmarks[ bookm->insertItem( b.name ) ] = b; | 237 | mBookmarks[ bookm->insertItem( b.name ) ] = b; |
238 | } | 238 | } |
239 | 239 | ||
240 | void HelpBrowser::removeBookmark() | 240 | void HelpBrowser::removeBookmark() |
241 | { | 241 | { |
242 | QString file = browser->source(); | 242 | QString file = browser->source(); |
243 | QMap<int, Bookmark>::Iterator it = mBookmarks.begin(); | 243 | QMap<int, Bookmark>::Iterator it = mBookmarks.begin(); |
244 | for( ; it != mBookmarks.end(); ++it ) | 244 | for( ; it != mBookmarks.end(); ++it ) |
245 | if ( (*it).file == file ) { | 245 | if ( (*it).file == file ) { |
246 | bookm->removeItem( it.key() ); | 246 | bookm->removeItem( it.key() ); |
247 | mBookmarks.remove( it ); | 247 | mBookmarks.remove( it ); |
248 | break; | 248 | break; |
249 | } | 249 | } |
250 | } | 250 | } |
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 0e3254f..be18140 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -1,1212 +1,1212 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | // textedit.cpp | 2 | // textedit.cpp |
3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
4 | ** | 4 | ** |
5 | ** This file is part of Opie Environment. | 5 | ** This file is part of Opie Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | **********************************************************************/ | 12 | **********************************************************************/ |
13 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 | 13 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 |
14 | #include "textedit.h" | 14 | #include "textedit.h" |
15 | #include "filePermissions.h" | 15 | #include "filePermissions.h" |
16 | 16 | ||
17 | 17 | ||
18 | #include <opie/ofileselector.h> | 18 | #include <opie/ofileselector.h> |
19 | #include <opie/ofiledialog.h> | 19 | #include <opie/ofiledialog.h> |
20 | #include <opie/ofontselector.h> | 20 | #include <opie/ofontselector.h> |
21 | 21 | ||
22 | #include <qpe/fontdatabase.h> | 22 | #include <qpe/fontdatabase.h> |
23 | #include <qpe/global.h> | 23 | #include <qpe/global.h> |
24 | #include <qpe/fileselector.h> | 24 | #include <qpe/fileselector.h> |
25 | #include <qpe/applnk.h> | 25 | #include <qpe/applnk.h> |
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
28 | #include <qpe/qpeapplication.h> | 28 | #include <qpe/qpeapplication.h> |
29 | #include <qmenubar.h> | 29 | #include <qmenubar.h> |
30 | #include <qpe/qpetoolbar.h> | 30 | #include <qtoolbar.h> |
31 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
32 | 32 | ||
33 | #include <qpoint.h> | 33 | #include <qpoint.h> |
34 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
35 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
36 | #include <qclipboard.h> | 36 | #include <qclipboard.h> |
37 | #include <qstringlist.h> | 37 | #include <qstringlist.h> |
38 | #include <qaction.h> | 38 | #include <qaction.h> |
39 | #include <qcolordialog.h> | 39 | #include <qcolordialog.h> |
40 | #include <qfileinfo.h> | 40 | #include <qfileinfo.h> |
41 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
42 | #include <qmessagebox.h> | 42 | #include <qmessagebox.h> |
43 | #include <qobjectlist.h> | 43 | #include <qobjectlist.h> |
44 | #include <qpopupmenu.h> | 44 | #include <qpopupmenu.h> |
45 | #include <qspinbox.h> | 45 | #include <qspinbox.h> |
46 | #include <qtoolbutton.h> | 46 | #include <qtoolbutton.h> |
47 | #include <qwidgetstack.h> | 47 | #include <qwidgetstack.h> |
48 | #include <qcheckbox.h> | 48 | #include <qcheckbox.h> |
49 | #include <qcombo.h> | 49 | #include <qcombo.h> |
50 | #include <qlayout.h> | 50 | #include <qlayout.h> |
51 | #include <qapplication.h> | 51 | #include <qapplication.h> |
52 | #include <qtimer.h> | 52 | #include <qtimer.h> |
53 | #include <qdir.h> | 53 | #include <qdir.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #include <sys/stat.h> | 55 | #include <sys/stat.h> |
56 | #include <stdlib.h> //getenv | 56 | #include <stdlib.h> //getenv |
57 | 57 | ||
58 | #if QT_VERSION < 300 | 58 | #if QT_VERSION < 300 |
59 | 59 | ||
60 | class QpeEditor : public QMultiLineEdit | 60 | class QpeEditor : public QMultiLineEdit |
61 | { | 61 | { |
62 | 62 | ||
63 | public: | 63 | public: |
64 | QpeEditor( QWidget *parent, const char * name = 0 ) | 64 | QpeEditor( QWidget *parent, const char * name = 0 ) |
65 | : QMultiLineEdit( parent, name ) { | 65 | : QMultiLineEdit( parent, name ) { |
66 | clearTableFlags(); | 66 | clearTableFlags(); |
67 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 67 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
68 | } | 68 | } |
69 | 69 | ||
70 | void find( const QString &txt, bool caseSensitive, | 70 | void find( const QString &txt, bool caseSensitive, |
71 | bool backwards ); | 71 | bool backwards ); |
72 | protected: | 72 | protected: |
73 | bool markIt; | 73 | bool markIt; |
74 | int line1, line2, col1, col2; | 74 | int line1, line2, col1, col2; |
75 | void mousePressEvent( QMouseEvent * ); | 75 | void mousePressEvent( QMouseEvent * ); |
76 | void mouseReleaseEvent( QMouseEvent * ); | 76 | void mouseReleaseEvent( QMouseEvent * ); |
77 | 77 | ||
78 | //public slots: | 78 | //public slots: |
79 | /* | 79 | /* |
80 | signals: | 80 | signals: |
81 | void notFound(); | 81 | void notFound(); |
82 | void searchWrapped(); | 82 | void searchWrapped(); |
83 | */ | 83 | */ |
84 | 84 | ||
85 | private: | 85 | private: |
86 | 86 | ||
87 | }; | 87 | }; |
88 | 88 | ||
89 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { | 89 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { |
90 | switch(e->button()) { | 90 | switch(e->button()) { |
91 | case RightButton: | 91 | case RightButton: |
92 | { //rediculous workaround for qt popup menu | 92 | { //rediculous workaround for qt popup menu |
93 | //and the hold right click mechanism | 93 | //and the hold right click mechanism |
94 | this->setSelection( line1, col1, line2, col2); | 94 | this->setSelection( line1, col1, line2, col2); |
95 | QMultiLineEdit::mousePressEvent( e ); | 95 | QMultiLineEdit::mousePressEvent( e ); |
96 | markIt = false; | 96 | markIt = false; |
97 | } | 97 | } |
98 | break; | 98 | break; |
99 | default: | 99 | default: |
100 | { | 100 | { |
101 | if(!markIt) { | 101 | if(!markIt) { |
102 | int line, col; | 102 | int line, col; |
103 | this->getCursorPosition(&line, &col); | 103 | this->getCursorPosition(&line, &col); |
104 | line1=line2=line; | 104 | line1=line2=line; |
105 | col1=col2=col; | 105 | col1=col2=col; |
106 | } | 106 | } |
107 | QMultiLineEdit::mousePressEvent( e ); | 107 | QMultiLineEdit::mousePressEvent( e ); |
108 | } | 108 | } |
109 | break; | 109 | break; |
110 | }; | 110 | }; |
111 | } | 111 | } |
112 | 112 | ||
113 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { | 113 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { |
114 | if(this->hasMarkedText()) { | 114 | if(this->hasMarkedText()) { |
115 | markIt = true; | 115 | markIt = true; |
116 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); | 116 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); |
117 | } else { | 117 | } else { |
118 | markIt = false; | 118 | markIt = false; |
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
122 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 122 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
123 | bool backwards ) | 123 | bool backwards ) |
124 | { | 124 | { |
125 | static bool wrap = false; | 125 | static bool wrap = false; |
126 | int line, col; | 126 | int line, col; |
127 | if ( wrap ) { | 127 | if ( wrap ) { |
128 | if ( !backwards ) | 128 | if ( !backwards ) |
129 | line = col = 0; | 129 | line = col = 0; |
130 | wrap = false; | 130 | wrap = false; |
131 | // emit searchWrapped(); | 131 | // emit searchWrapped(); |
132 | } else { | 132 | } else { |
133 | getCursorPosition( &line, &col ); | 133 | getCursorPosition( &line, &col ); |
134 | } | 134 | } |
135 | //ignore backwards for now.... | 135 | //ignore backwards for now.... |
136 | if ( !backwards ) { | 136 | if ( !backwards ) { |
137 | for ( ; ; ) { | 137 | for ( ; ; ) { |
138 | if ( line >= numLines() ) { | 138 | if ( line >= numLines() ) { |
139 | wrap = true; | 139 | wrap = true; |
140 | //emit notFound(); | 140 | //emit notFound(); |
141 | break; | 141 | break; |
142 | } | 142 | } |
143 | int findCol = getString( line )->find( txt, col, caseSensitive ); | 143 | int findCol = getString( line )->find( txt, col, caseSensitive ); |
144 | if ( findCol >= 0 ) { | 144 | if ( findCol >= 0 ) { |
145 | setCursorPosition( line, findCol, false ); | 145 | setCursorPosition( line, findCol, false ); |
146 | col = findCol + txt.length(); | 146 | col = findCol + txt.length(); |
147 | setCursorPosition( line, col, true ); | 147 | setCursorPosition( line, col, true ); |
148 | 148 | ||
149 | //found = true; | 149 | //found = true; |
150 | break; | 150 | break; |
151 | } | 151 | } |
152 | line++; | 152 | line++; |
153 | col = 0; | 153 | col = 0; |
154 | } | 154 | } |
155 | } | 155 | } |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | #else | 159 | #else |
160 | 160 | ||
161 | #error "Must make a QpeEditor that inherits QTextEdit" | 161 | #error "Must make a QpeEditor that inherits QTextEdit" |
162 | 162 | ||
163 | #endif | 163 | #endif |
164 | 164 | ||
165 | 165 | ||
166 | static const int nfontsizes = 6; | 166 | static const int nfontsizes = 6; |
167 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 167 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
168 | 168 | ||
169 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 169 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
170 | : QMainWindow( parent, name, f ), bFromDocView( false ) | 170 | : QMainWindow( parent, name, f ), bFromDocView( false ) |
171 | { | 171 | { |
172 | doc = 0; | 172 | doc = 0; |
173 | edited=false; | 173 | edited=false; |
174 | fromSetDocument=false; | 174 | fromSetDocument=false; |
175 | 175 | ||
176 | setToolBarsMovable( false ); | 176 | setToolBarsMovable( false ); |
177 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 177 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
178 | 178 | ||
179 | channel = new QCopChannel( "QPE/Application/textedit", this ); | 179 | channel = new QCopChannel( "QPE/Application/textedit", this ); |
180 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 180 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
181 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 181 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
182 | 182 | ||
183 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 183 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
184 | 184 | ||
185 | QPEToolBar *bar = new QPEToolBar( this ); | 185 | QToolBar *bar = new QToolBar( this ); |
186 | bar->setHorizontalStretchable( true ); | 186 | bar->setHorizontalStretchable( true ); |
187 | menu = bar; | 187 | menu = bar; |
188 | 188 | ||
189 | QMenuBar *mb = new QMenuBar( bar ); | 189 | QMenuBar *mb = new QMenuBar( bar ); |
190 | QPopupMenu *file = new QPopupMenu( this ); | 190 | QPopupMenu *file = new QPopupMenu( this ); |
191 | QPopupMenu *edit = new QPopupMenu( this ); | 191 | QPopupMenu *edit = new QPopupMenu( this ); |
192 | QPopupMenu *advancedMenu = new QPopupMenu(this); | 192 | QPopupMenu *advancedMenu = new QPopupMenu(this); |
193 | 193 | ||
194 | font = new QPopupMenu( this ); | 194 | font = new QPopupMenu( this ); |
195 | 195 | ||
196 | bar = new QPEToolBar( this ); | 196 | bar = new QToolBar( this ); |
197 | editBar = bar; | 197 | editBar = bar; |
198 | 198 | ||
199 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), | 199 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), |
200 | QString::null, 0, this, 0 ); | 200 | QString::null, 0, this, 0 ); |
201 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 201 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
202 | // a->addTo( bar ); | 202 | // a->addTo( bar ); |
203 | a->addTo( file ); | 203 | a->addTo( file ); |
204 | 204 | ||
205 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), | 205 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), |
206 | QString::null, 0, this, 0 ); | 206 | QString::null, 0, this, 0 ); |
207 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 207 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
208 | a->addTo( bar ); | 208 | a->addTo( bar ); |
209 | a->addTo( file ); | 209 | a->addTo( file ); |
210 | 210 | ||
211 | a = new QAction( tr( "Save" ), Resource::loadPixmap("save") , | 211 | a = new QAction( tr( "Save" ), Resource::loadPixmap("save") , |
212 | QString::null, 0, this, 0 ); | 212 | QString::null, 0, this, 0 ); |
213 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 213 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
214 | file->insertSeparator(); | 214 | file->insertSeparator(); |
215 | a->addTo( bar ); | 215 | a->addTo( bar ); |
216 | a->addTo( file ); | 216 | a->addTo( file ); |
217 | 217 | ||
218 | a = new QAction( tr( "Save As" ), Resource::loadPixmap("save") , | 218 | a = new QAction( tr( "Save As" ), Resource::loadPixmap("save") , |
219 | QString::null, 0, this, 0 ); | 219 | QString::null, 0, this, 0 ); |
220 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 220 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
221 | a->addTo( file ); | 221 | a->addTo( file ); |
222 | 222 | ||
223 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), | 223 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), |
224 | QString::null, 0, this, 0 ); | 224 | QString::null, 0, this, 0 ); |
225 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 225 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
226 | a->addTo( editBar ); | 226 | a->addTo( editBar ); |
227 | a->addTo( edit ); | 227 | a->addTo( edit ); |
228 | 228 | ||
229 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), | 229 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), |
230 | QString::null, 0, this, 0 ); | 230 | QString::null, 0, this, 0 ); |
231 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 231 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
232 | a->addTo( editBar ); | 232 | a->addTo( editBar ); |
233 | a->addTo( edit ); | 233 | a->addTo( edit ); |
234 | 234 | ||
235 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), | 235 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), |
236 | QString::null, 0, this, 0 ); | 236 | QString::null, 0, this, 0 ); |
237 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 237 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
238 | a->addTo( editBar ); | 238 | a->addTo( editBar ); |
239 | a->addTo( edit ); | 239 | a->addTo( edit ); |
240 | 240 | ||
241 | 241 | ||
242 | #ifndef QT_NO_CLIPBOARD | 242 | #ifndef QT_NO_CLIPBOARD |
243 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), | 243 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), |
244 | QString::null, 0, this, 0 ); | 244 | QString::null, 0, this, 0 ); |
245 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); | 245 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); |
246 | a->addTo( edit ); | 246 | a->addTo( edit ); |
247 | #endif | 247 | #endif |
248 | 248 | ||
249 | a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), | 249 | a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), |
250 | QString::null, 0, this, 0 ); | 250 | QString::null, 0, this, 0 ); |
251 | connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); | 251 | connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); |
252 | edit->insertSeparator(); | 252 | edit->insertSeparator(); |
253 | a->addTo( edit ); | 253 | a->addTo( edit ); |
254 | 254 | ||
255 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), | 255 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), |
256 | QString::null, 0, this, 0 ); | 256 | QString::null, 0, this, 0 ); |
257 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 257 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
258 | a->addTo( bar ); | 258 | a->addTo( bar ); |
259 | a->addTo( edit ); | 259 | a->addTo( edit ); |
260 | 260 | ||
261 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 261 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
262 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 262 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
263 | zin->addTo( font ); | 263 | zin->addTo( font ); |
264 | 264 | ||
265 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 265 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
266 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 266 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
267 | zout->addTo( font ); | 267 | zout->addTo( font ); |
268 | 268 | ||
269 | font->insertSeparator(); | 269 | font->insertSeparator(); |
270 | 270 | ||
271 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); | 271 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); |
272 | 272 | ||
273 | font->insertSeparator(); | 273 | font->insertSeparator(); |
274 | font->insertItem(tr("Advanced Features"), advancedMenu); | 274 | font->insertItem(tr("Advanced Features"), advancedMenu); |
275 | 275 | ||
276 | QAction *wa = new QAction( tr("Wrap lines"), | 276 | QAction *wa = new QAction( tr("Wrap lines"), |
277 | QString::null, 0, this, 0 ); | 277 | QString::null, 0, this, 0 ); |
278 | connect( wa, SIGNAL( toggled(bool) ), | 278 | connect( wa, SIGNAL( toggled(bool) ), |
279 | this, SLOT( setWordWrap(bool) ) ); | 279 | this, SLOT( setWordWrap(bool) ) ); |
280 | wa->setToggleAction(true); | 280 | wa->setToggleAction(true); |
281 | wa->addTo( advancedMenu); | 281 | wa->addTo( advancedMenu); |
282 | 282 | ||
283 | nStart = new QAction( tr("Start with new file"), | 283 | nStart = new QAction( tr("Start with new file"), |
284 | QString::null, 0, this, 0 ); | 284 | QString::null, 0, this, 0 ); |
285 | connect( nStart, SIGNAL( toggled(bool) ), | 285 | connect( nStart, SIGNAL( toggled(bool) ), |
286 | this, SLOT( changeStartConfig(bool) ) ); | 286 | this, SLOT( changeStartConfig(bool) ) ); |
287 | nStart->setToggleAction(true); | 287 | nStart->setToggleAction(true); |
288 | nStart->addTo( advancedMenu ); | 288 | nStart->addTo( advancedMenu ); |
289 | nStart->setEnabled(false); | 289 | nStart->setEnabled(false); |
290 | 290 | ||
291 | nAdvanced = new QAction( tr("Prompt on Exit"), | 291 | nAdvanced = new QAction( tr("Prompt on Exit"), |
292 | QString::null, 0, this, 0 ); | 292 | QString::null, 0, this, 0 ); |
293 | connect( nAdvanced, SIGNAL( toggled(bool) ), | 293 | connect( nAdvanced, SIGNAL( toggled(bool) ), |
294 | this, SLOT( doPrompt(bool) ) ); | 294 | this, SLOT( doPrompt(bool) ) ); |
295 | nAdvanced->setToggleAction(true); | 295 | nAdvanced->setToggleAction(true); |
296 | nAdvanced->addTo( advancedMenu ); | 296 | nAdvanced->addTo( advancedMenu ); |
297 | 297 | ||
298 | desktopAction = new QAction( tr("Always open linked file"), | 298 | desktopAction = new QAction( tr("Always open linked file"), |
299 | QString::null, 0, this, 0 ); | 299 | QString::null, 0, this, 0 ); |
300 | connect( desktopAction, SIGNAL( toggled(bool) ), | 300 | connect( desktopAction, SIGNAL( toggled(bool) ), |
301 | this, SLOT( doDesktop(bool) ) ); | 301 | this, SLOT( doDesktop(bool) ) ); |
302 | desktopAction->setToggleAction(true); | 302 | desktopAction->setToggleAction(true); |
303 | desktopAction->addTo( advancedMenu); | 303 | desktopAction->addTo( advancedMenu); |
304 | 304 | ||
305 | filePermAction = new QAction( tr("File Permissions"), | 305 | filePermAction = new QAction( tr("File Permissions"), |
306 | QString::null, 0, this, 0 ); | 306 | QString::null, 0, this, 0 ); |
307 | connect( filePermAction, SIGNAL( toggled(bool) ), | 307 | connect( filePermAction, SIGNAL( toggled(bool) ), |
308 | this, SLOT( doFilePerms(bool) ) ); | 308 | this, SLOT( doFilePerms(bool) ) ); |
309 | filePermAction->setToggleAction(true); | 309 | filePermAction->setToggleAction(true); |
310 | filePermAction->addTo( advancedMenu); | 310 | filePermAction->addTo( advancedMenu); |
311 | 311 | ||
312 | searchBarAction = new QAction( tr("Search Bar Open"), | 312 | searchBarAction = new QAction( tr("Search Bar Open"), |
313 | QString::null, 0, this, 0 ); | 313 | QString::null, 0, this, 0 ); |
314 | connect( searchBarAction, SIGNAL( toggled(bool) ), | 314 | connect( searchBarAction, SIGNAL( toggled(bool) ), |
315 | this, SLOT( setSearchBar(bool) ) ); | 315 | this, SLOT( setSearchBar(bool) ) ); |
316 | searchBarAction->setToggleAction(true); | 316 | searchBarAction->setToggleAction(true); |
317 | searchBarAction->addTo( advancedMenu); | 317 | searchBarAction->addTo( advancedMenu); |
318 | 318 | ||
319 | nAutoSave = new QAction( tr("Auto Save 5 min."), | 319 | nAutoSave = new QAction( tr("Auto Save 5 min."), |
320 | QString::null, 0, this, 0 ); | 320 | QString::null, 0, this, 0 ); |
321 | connect( nAutoSave, SIGNAL( toggled(bool) ), | 321 | connect( nAutoSave, SIGNAL( toggled(bool) ), |
322 | this, SLOT( doTimer(bool) ) ); | 322 | this, SLOT( doTimer(bool) ) ); |
323 | nAutoSave->setToggleAction(true); | 323 | nAutoSave->setToggleAction(true); |
324 | nAutoSave->addTo( advancedMenu); | 324 | nAutoSave->addTo( advancedMenu); |
325 | 325 | ||
326 | 326 | ||
327 | //font->insertSeparator(); | 327 | //font->insertSeparator(); |
328 | 328 | ||
329 | //font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 329 | //font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
330 | 330 | ||
331 | mb->insertItem( tr( "File" ), file ); | 331 | mb->insertItem( tr( "File" ), file ); |
332 | mb->insertItem( tr( "Edit" ), edit ); | 332 | mb->insertItem( tr( "Edit" ), edit ); |
333 | mb->insertItem( tr( "View" ), font ); | 333 | mb->insertItem( tr( "View" ), font ); |
334 | 334 | ||
335 | searchBar = new QPEToolBar(this); | 335 | searchBar = new QToolBar(this); |
336 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); | 336 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); |
337 | 337 | ||
338 | searchBar->setHorizontalStretchable( true ); | 338 | searchBar->setHorizontalStretchable( true ); |
339 | 339 | ||
340 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 340 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
341 | searchBar->setStretchableWidget( searchEdit ); | 341 | searchBar->setStretchableWidget( searchEdit ); |
342 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 342 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
343 | this, SLOT( search() ) ); | 343 | this, SLOT( search() ) ); |
344 | 344 | ||
345 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), | 345 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), |
346 | QString::null, 0, this, 0 ); | 346 | QString::null, 0, this, 0 ); |
347 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 347 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
348 | a->addTo( searchBar ); | 348 | a->addTo( searchBar ); |
349 | a->addTo( edit ); | 349 | a->addTo( edit ); |
350 | 350 | ||
351 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), | 351 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), |
352 | QString::null, 0, this, 0 ); | 352 | QString::null, 0, this, 0 ); |
353 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 353 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
354 | a->addTo( searchBar ); | 354 | a->addTo( searchBar ); |
355 | 355 | ||
356 | edit->insertSeparator(); | 356 | edit->insertSeparator(); |
357 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), | 357 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), |
358 | QString::null, 0, this, 0 ); | 358 | QString::null, 0, this, 0 ); |
359 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 359 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
360 | a->addTo( edit ); | 360 | a->addTo( edit ); |
361 | 361 | ||
362 | searchBar->hide(); | 362 | searchBar->hide(); |
363 | 363 | ||
364 | editor = new QpeEditor( this ); | 364 | editor = new QpeEditor( this ); |
365 | setCentralWidget( editor ); | 365 | setCentralWidget( editor ); |
366 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 366 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
367 | connect( editor, SIGNAL( textChanged() ), | 367 | connect( editor, SIGNAL( textChanged() ), |
368 | this, SLOT( editorChanged() ) ); | 368 | this, SLOT( editorChanged() ) ); |
369 | 369 | ||
370 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); | 370 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); |
371 | 371 | ||
372 | Config cfg("TextEdit"); | 372 | Config cfg("TextEdit"); |
373 | cfg. setGroup ( "Font" ); | 373 | cfg. setGroup ( "Font" ); |
374 | 374 | ||
375 | QFont defaultFont = editor-> font ( ); | 375 | QFont defaultFont = editor-> font ( ); |
376 | 376 | ||
377 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); | 377 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); |
378 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); | 378 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); |
379 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); | 379 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); |
380 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); | 380 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); |
381 | 381 | ||
382 | defaultFont = QFont ( family, size, weight, italic ); | 382 | defaultFont = QFont ( family, size, weight, italic ); |
383 | editor-> setFont ( defaultFont ); | 383 | editor-> setFont ( defaultFont ); |
384 | // updateCaption(); | 384 | // updateCaption(); |
385 | 385 | ||
386 | cfg.setGroup ( "View" ); | 386 | cfg.setGroup ( "View" ); |
387 | 387 | ||
388 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); | 388 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); |
389 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); | 389 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); |
390 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); | 390 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); |
391 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); | 391 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); |
392 | startWithNew = cfg.readBoolEntry ( "startNew", true); | 392 | startWithNew = cfg.readBoolEntry ( "startNew", true); |
393 | featureAutoSave = cfg.readBoolEntry( "autosave", false); | 393 | featureAutoSave = cfg.readBoolEntry( "autosave", false); |
394 | 394 | ||
395 | if(useSearchBar) searchBarAction->setOn(true); | 395 | if(useSearchBar) searchBarAction->setOn(true); |
396 | if(promptExit) nAdvanced->setOn( true ); | 396 | if(promptExit) nAdvanced->setOn( true ); |
397 | if(openDesktop) desktopAction->setOn( true ); | 397 | if(openDesktop) desktopAction->setOn( true ); |
398 | if(filePerms) filePermAction->setOn( true ); | 398 | if(filePerms) filePermAction->setOn( true ); |
399 | if(startWithNew) nStart->setOn( true ); | 399 | if(startWithNew) nStart->setOn( true ); |
400 | if(featureAutoSave) nAutoSave->setOn(true); | 400 | if(featureAutoSave) nAutoSave->setOn(true); |
401 | 401 | ||
402 | // { | 402 | // { |
403 | // doTimer(true); | 403 | // doTimer(true); |
404 | // } | 404 | // } |
405 | 405 | ||
406 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 406 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
407 | wa-> setOn ( wrap ); | 407 | wa-> setOn ( wrap ); |
408 | setWordWrap ( wrap ); | 408 | setWordWrap ( wrap ); |
409 | 409 | ||
410 | ///////////////// | 410 | ///////////////// |
411 | if( qApp->argc() > 1) { | 411 | if( qApp->argc() > 1) { |
412 | currentFileName=qApp->argv()[1]; | 412 | currentFileName=qApp->argv()[1]; |
413 | 413 | ||
414 | QFileInfo fi(currentFileName); | 414 | QFileInfo fi(currentFileName); |
415 | 415 | ||
416 | if(fi.baseName().left(1) == "") { | 416 | if(fi.baseName().left(1) == "") { |
417 | openDotFile(currentFileName); | 417 | openDotFile(currentFileName); |
418 | } else { | 418 | } else { |
419 | openFile(currentFileName); | 419 | openFile(currentFileName); |
420 | } | 420 | } |
421 | } else { | 421 | } else { |
422 | edited1=false; | 422 | edited1=false; |
423 | openDotFile(""); | 423 | openDotFile(""); |
424 | } | 424 | } |
425 | 425 | ||
426 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 426 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
427 | } | 427 | } |
428 | 428 | ||
429 | TextEdit::~TextEdit() { | 429 | TextEdit::~TextEdit() { |
430 | qWarning("textedit d'tor"); | 430 | qWarning("textedit d'tor"); |
431 | delete editor; | 431 | delete editor; |
432 | } | 432 | } |
433 | 433 | ||
434 | void TextEdit::closeEvent(QCloseEvent *) { | 434 | void TextEdit::closeEvent(QCloseEvent *) { |
435 | if( edited1 && promptExit) | 435 | if( edited1 && promptExit) |
436 | { | 436 | { |
437 | switch( savePrompt() ) | 437 | switch( savePrompt() ) |
438 | { | 438 | { |
439 | case 1: | 439 | case 1: |
440 | { | 440 | { |
441 | saveAs(); | 441 | saveAs(); |
442 | qApp->quit(); | 442 | qApp->quit(); |
443 | } | 443 | } |
444 | break; | 444 | break; |
445 | 445 | ||
446 | case 2: | 446 | case 2: |
447 | { | 447 | { |
448 | qApp->quit(); | 448 | qApp->quit(); |
449 | } | 449 | } |
450 | break; | 450 | break; |
451 | 451 | ||
452 | case -1: | 452 | case -1: |
453 | break; | 453 | break; |
454 | }; | 454 | }; |
455 | } | 455 | } |
456 | else | 456 | else |
457 | qApp->quit(); | 457 | qApp->quit(); |
458 | 458 | ||
459 | } | 459 | } |
460 | 460 | ||
461 | void TextEdit::cleanUp() { | 461 | void TextEdit::cleanUp() { |
462 | 462 | ||
463 | Config cfg ( "TextEdit" ); | 463 | Config cfg ( "TextEdit" ); |
464 | cfg. setGroup ( "Font" ); | 464 | cfg. setGroup ( "Font" ); |
465 | QFont f = editor->font(); | 465 | QFont f = editor->font(); |
466 | cfg.writeEntry ( "Family", f. family ( )); | 466 | cfg.writeEntry ( "Family", f. family ( )); |
467 | cfg.writeEntry ( "Size", f. pointSize ( )); | 467 | cfg.writeEntry ( "Size", f. pointSize ( )); |
468 | cfg.writeEntry ( "Weight", f. weight ( )); | 468 | cfg.writeEntry ( "Weight", f. weight ( )); |
469 | cfg.writeEntry ( "Italic", f. italic ( )); | 469 | cfg.writeEntry ( "Italic", f. italic ( )); |
470 | 470 | ||
471 | cfg.setGroup ( "View" ); | 471 | cfg.setGroup ( "View" ); |
472 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); | 472 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
473 | cfg.writeEntry ( "FileView", viewSelection ); | 473 | cfg.writeEntry ( "FileView", viewSelection ); |
474 | 474 | ||
475 | cfg.writeEntry ( "PromptExit", promptExit ); | 475 | cfg.writeEntry ( "PromptExit", promptExit ); |
476 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 476 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
477 | cfg.writeEntry ( "FilePermissions", filePerms ); | 477 | cfg.writeEntry ( "FilePermissions", filePerms ); |
478 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 478 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
479 | cfg.writeEntry ( "startNew", startWithNew ); | 479 | cfg.writeEntry ( "startNew", startWithNew ); |
480 | 480 | ||
481 | } | 481 | } |
482 | 482 | ||
483 | 483 | ||
484 | void TextEdit::accept() { | 484 | void TextEdit::accept() { |
485 | if( edited1) | 485 | if( edited1) |
486 | saveAs(); | 486 | saveAs(); |
487 | qApp->quit(); | 487 | qApp->quit(); |
488 | } | 488 | } |
489 | 489 | ||
490 | void TextEdit::zoomIn() { | 490 | void TextEdit::zoomIn() { |
491 | setFontSize(editor->font().pointSize()+1,false); | 491 | setFontSize(editor->font().pointSize()+1,false); |
492 | } | 492 | } |
493 | 493 | ||
494 | void TextEdit::zoomOut() { | 494 | void TextEdit::zoomOut() { |
495 | setFontSize(editor->font().pointSize()-1,true); | 495 | setFontSize(editor->font().pointSize()-1,true); |
496 | } | 496 | } |
497 | 497 | ||
498 | 498 | ||
499 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 499 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
500 | int s=10; | 500 | int s=10; |
501 | for (int i=0; i<nfontsizes; i++) { | 501 | for (int i=0; i<nfontsizes; i++) { |
502 | if ( fontsize[i] == sz ) { | 502 | if ( fontsize[i] == sz ) { |
503 | s = sz; | 503 | s = sz; |
504 | break; | 504 | break; |
505 | } else if ( round_down_not_up ) { | 505 | } else if ( round_down_not_up ) { |
506 | if ( fontsize[i] < sz ) | 506 | if ( fontsize[i] < sz ) |
507 | s = fontsize[i]; | 507 | s = fontsize[i]; |
508 | } else { | 508 | } else { |
509 | if ( fontsize[i] > sz ) { | 509 | if ( fontsize[i] > sz ) { |
510 | s = fontsize[i]; | 510 | s = fontsize[i]; |
511 | break; | 511 | break; |
512 | } | 512 | } |
513 | } | 513 | } |
514 | } | 514 | } |
515 | 515 | ||
516 | QFont f = editor->font(); | 516 | QFont f = editor->font(); |
517 | f.setPointSize(s); | 517 | f.setPointSize(s); |
518 | editor->setFont(f); | 518 | editor->setFont(f); |
519 | 519 | ||
520 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 520 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
521 | zout->setEnabled(s != fontsize[0]); | 521 | zout->setEnabled(s != fontsize[0]); |
522 | } | 522 | } |
523 | 523 | ||
524 | void TextEdit::setBold(bool y) { | 524 | void TextEdit::setBold(bool y) { |
525 | QFont f = editor->font(); | 525 | QFont f = editor->font(); |
526 | f.setBold(y); | 526 | f.setBold(y); |
527 | editor->setFont(f); | 527 | editor->setFont(f); |
528 | } | 528 | } |
529 | 529 | ||
530 | void TextEdit::setItalic(bool y) { | 530 | void TextEdit::setItalic(bool y) { |
531 | QFont f = editor->font(); | 531 | QFont f = editor->font(); |
532 | f.setItalic(y); | 532 | f.setItalic(y); |
533 | editor->setFont(f); | 533 | editor->setFont(f); |
534 | } | 534 | } |
535 | 535 | ||
536 | void TextEdit::setWordWrap(bool y) { | 536 | void TextEdit::setWordWrap(bool y) { |
537 | bool state = editor->edited(); | 537 | bool state = editor->edited(); |
538 | QString captionStr = caption(); | 538 | QString captionStr = caption(); |
539 | bool b1 = edited1; | 539 | bool b1 = edited1; |
540 | bool b2 = edited; | 540 | bool b2 = edited; |
541 | 541 | ||
542 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 542 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
543 | editor->setEdited( state ); | 543 | editor->setEdited( state ); |
544 | edited1=b1; | 544 | edited1=b1; |
545 | edited=b2; | 545 | edited=b2; |
546 | setCaption(captionStr); | 546 | setCaption(captionStr); |
547 | } | 547 | } |
548 | 548 | ||
549 | void TextEdit::setSearchBar(bool b) { | 549 | void TextEdit::setSearchBar(bool b) { |
550 | useSearchBar=b; | 550 | useSearchBar=b; |
551 | Config cfg("TextEdit"); | 551 | Config cfg("TextEdit"); |
552 | cfg.setGroup("View"); | 552 | cfg.setGroup("View"); |
553 | cfg.writeEntry ( "SearchBar", b ); | 553 | cfg.writeEntry ( "SearchBar", b ); |
554 | searchBarAction->setOn(b); | 554 | searchBarAction->setOn(b); |
555 | if(b) | 555 | if(b) |
556 | searchBar->show(); | 556 | searchBar->show(); |
557 | else | 557 | else |
558 | searchBar->hide(); | 558 | searchBar->hide(); |
559 | editor->setFocus(); | 559 | editor->setFocus(); |
560 | } | 560 | } |
561 | 561 | ||
562 | void TextEdit::fileNew() { | 562 | void TextEdit::fileNew() { |
563 | // if( !bFromDocView ) { | 563 | // if( !bFromDocView ) { |
564 | // saveAs(); | 564 | // saveAs(); |
565 | // } | 565 | // } |
566 | newFile(DocLnk()); | 566 | newFile(DocLnk()); |
567 | } | 567 | } |
568 | 568 | ||
569 | void TextEdit::fileOpen() { | 569 | void TextEdit::fileOpen() { |
570 | Config cfg("TextEdit"); | 570 | Config cfg("TextEdit"); |
571 | cfg. setGroup ( "View" ); | 571 | cfg. setGroup ( "View" ); |
572 | QMap<QString, QStringList> map; | 572 | QMap<QString, QStringList> map; |
573 | map.insert(tr("All"), QStringList() ); | 573 | map.insert(tr("All"), QStringList() ); |
574 | QStringList text; | 574 | QStringList text; |
575 | text << "text/*"; | 575 | text << "text/*"; |
576 | map.insert(tr("Text"), text ); | 576 | map.insert(tr("Text"), text ); |
577 | text << "*"; | 577 | text << "*"; |
578 | map.insert(tr("All"), text ); | 578 | map.insert(tr("All"), text ); |
579 | QString str = OFileDialog::getOpenFileName( 2, | 579 | QString str = OFileDialog::getOpenFileName( 2, |
580 | QString::null , | 580 | QString::null , |
581 | QString::null, map); | 581 | QString::null, map); |
582 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) | 582 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) |
583 | { | 583 | { |
584 | openFile( str ); | 584 | openFile( str ); |
585 | } | 585 | } |
586 | else | 586 | else |
587 | updateCaption(); | 587 | updateCaption(); |
588 | } | 588 | } |
589 | 589 | ||
590 | void TextEdit::doSearchBar() { | 590 | void TextEdit::doSearchBar() { |
591 | if(!useSearchBar) | 591 | if(!useSearchBar) |
592 | searchBar->hide(); | 592 | searchBar->hide(); |
593 | else | 593 | else |
594 | searchBar->show(); | 594 | searchBar->show(); |
595 | } | 595 | } |
596 | 596 | ||
597 | #if 0 | 597 | #if 0 |
598 | void TextEdit::slotFind() { | 598 | void TextEdit::slotFind() { |
599 | FindDialog frmFind( tr("Text Editor"), this ); | 599 | FindDialog frmFind( tr("Text Editor"), this ); |
600 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 600 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
601 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 601 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
602 | 602 | ||
603 | //case sensitive, backwards, [category] | 603 | //case sensitive, backwards, [category] |
604 | 604 | ||
605 | connect( editor, SIGNAL(notFound()), | 605 | connect( editor, SIGNAL(notFound()), |
606 | &frmFind, SLOT(slotNotFound()) ); | 606 | &frmFind, SLOT(slotNotFound()) ); |
607 | connect( editor, SIGNAL(searchWrapped()), | 607 | connect( editor, SIGNAL(searchWrapped()), |
608 | &frmFind, SLOT(slotWrapAround()) ); | 608 | &frmFind, SLOT(slotWrapAround()) ); |
609 | 609 | ||
610 | frmFind.exec(); | 610 | frmFind.exec(); |
611 | 611 | ||
612 | 612 | ||
613 | } | 613 | } |
614 | #endif | 614 | #endif |
615 | 615 | ||
616 | void TextEdit::fileRevert() { | 616 | void TextEdit::fileRevert() { |
617 | clear(); | 617 | clear(); |
618 | fileOpen(); | 618 | fileOpen(); |
619 | } | 619 | } |
620 | 620 | ||
621 | void TextEdit::editCut() { | 621 | void TextEdit::editCut() { |
622 | #ifndef QT_NO_CLIPBOARD | 622 | #ifndef QT_NO_CLIPBOARD |
623 | editor->cut(); | 623 | editor->cut(); |
624 | #endif | 624 | #endif |
625 | } | 625 | } |
626 | 626 | ||
627 | void TextEdit::editCopy() { | 627 | void TextEdit::editCopy() { |
628 | #ifndef QT_NO_CLIPBOARD | 628 | #ifndef QT_NO_CLIPBOARD |
629 | editor->copy(); | 629 | editor->copy(); |
630 | #endif | 630 | #endif |
631 | } | 631 | } |
632 | 632 | ||
633 | void TextEdit::editPaste() { | 633 | void TextEdit::editPaste() { |
634 | #ifndef QT_NO_CLIPBOARD | 634 | #ifndef QT_NO_CLIPBOARD |
635 | editor->paste(); | 635 | editor->paste(); |
636 | #endif | 636 | #endif |
637 | } | 637 | } |
638 | 638 | ||
639 | void TextEdit::editFind() { | 639 | void TextEdit::editFind() { |
640 | searchBar->show(); | 640 | searchBar->show(); |
641 | searchEdit->setFocus(); | 641 | searchEdit->setFocus(); |
642 | } | 642 | } |
643 | 643 | ||
644 | void TextEdit::findNext() { | 644 | void TextEdit::findNext() { |
645 | editor->find( searchEdit->text(), false, false ); | 645 | editor->find( searchEdit->text(), false, false ); |
646 | 646 | ||
647 | } | 647 | } |
648 | 648 | ||
649 | void TextEdit::findClose() { | 649 | void TextEdit::findClose() { |
650 | searchBar->hide(); | 650 | searchBar->hide(); |
651 | } | 651 | } |
652 | 652 | ||
653 | void TextEdit::search() { | 653 | void TextEdit::search() { |
654 | editor->find( searchEdit->text(), false, false ); | 654 | editor->find( searchEdit->text(), false, false ); |
655 | } | 655 | } |
656 | 656 | ||
657 | void TextEdit::newFile( const DocLnk &f ) { | 657 | void TextEdit::newFile( const DocLnk &f ) { |
658 | DocLnk nf = f; | 658 | DocLnk nf = f; |
659 | nf.setType("text/plain"); | 659 | nf.setType("text/plain"); |
660 | clear(); | 660 | clear(); |
661 | setWState (WState_Reserved1 ); | 661 | setWState (WState_Reserved1 ); |
662 | editor->setFocus(); | 662 | editor->setFocus(); |
663 | doc = new DocLnk(nf); | 663 | doc = new DocLnk(nf); |
664 | currentFileName = "Unnamed"; | 664 | currentFileName = "Unnamed"; |
665 | qDebug("newFile "+currentFileName); | 665 | qDebug("newFile "+currentFileName); |
666 | updateCaption( currentFileName); | 666 | updateCaption( currentFileName); |
667 | // editor->setEdited( false); | 667 | // editor->setEdited( false); |
668 | } | 668 | } |
669 | 669 | ||
670 | void TextEdit::openDotFile( const QString &f ) { | 670 | void TextEdit::openDotFile( const QString &f ) { |
671 | if(!currentFileName.isEmpty()) { | 671 | if(!currentFileName.isEmpty()) { |
672 | currentFileName=f; | 672 | currentFileName=f; |
673 | 673 | ||
674 | qDebug("openFile dotfile " + currentFileName); | 674 | qDebug("openFile dotfile " + currentFileName); |
675 | QString txt; | 675 | QString txt; |
676 | QFile file(f); | 676 | QFile file(f); |
677 | file.open(IO_ReadWrite); | 677 | file.open(IO_ReadWrite); |
678 | QTextStream t(&file); | 678 | QTextStream t(&file); |
679 | while ( !t.atEnd()) { | 679 | while ( !t.atEnd()) { |
680 | txt+=t.readLine()+"\n"; | 680 | txt+=t.readLine()+"\n"; |
681 | } | 681 | } |
682 | editor->setText(txt); | 682 | editor->setText(txt); |
683 | editor->setEdited( false); | 683 | editor->setEdited( false); |
684 | edited1=false; | 684 | edited1=false; |
685 | edited=false; | 685 | edited=false; |
686 | 686 | ||
687 | 687 | ||
688 | } | 688 | } |
689 | updateCaption( currentFileName); | 689 | updateCaption( currentFileName); |
690 | } | 690 | } |
691 | 691 | ||
692 | void TextEdit::openFile( const QString &f ) { | 692 | void TextEdit::openFile( const QString &f ) { |
693 | qDebug("filename is "+ f); | 693 | qDebug("filename is "+ f); |
694 | QString filer; | 694 | QString filer; |
695 | QFileInfo fi( f); | 695 | QFileInfo fi( f); |
696 | // bFromDocView = true; | 696 | // bFromDocView = true; |
697 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) | 697 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) |
698 | { | 698 | { |
699 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) | 699 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) |
700 | { | 700 | { |
701 | case 0: //desktop | 701 | case 0: //desktop |
702 | filer = f; | 702 | filer = f; |
703 | break; | 703 | break; |
704 | case 1: //linked | 704 | case 1: //linked |
705 | DocLnk sf(f); | 705 | DocLnk sf(f); |
706 | filer = sf.file(); | 706 | filer = sf.file(); |
707 | break; | 707 | break; |
708 | }; | 708 | }; |
709 | } | 709 | } |
710 | else if(fi.baseName().left(1) == "") | 710 | else if(fi.baseName().left(1) == "") |
711 | { | 711 | { |
712 | qDebug("opening dotfile"); | 712 | qDebug("opening dotfile"); |
713 | currentFileName=f; | 713 | currentFileName=f; |
714 | openDotFile(currentFileName); | 714 | openDotFile(currentFileName); |
715 | return; | 715 | return; |
716 | } | 716 | } |
717 | /* | 717 | /* |
718 | * The problem is a file where Config(f).isValid() and it does not | 718 | * The problem is a file where Config(f).isValid() and it does not |
719 | * end with .desktop will be treated as desktop file | 719 | * end with .desktop will be treated as desktop file |
720 | */ | 720 | */ |
721 | else if (f.find(".desktop",0,true) != -1 ) | 721 | else if (f.find(".desktop",0,true) != -1 ) |
722 | { | 722 | { |
723 | DocLnk sf(f); | 723 | DocLnk sf(f); |
724 | filer = sf.file(); | 724 | filer = sf.file(); |
725 | if(filer.right(1) == "/") | 725 | if(filer.right(1) == "/") |
726 | filer = f; | 726 | filer = f; |
727 | 727 | ||
728 | } | 728 | } |
729 | else | 729 | else |
730 | filer = f; | 730 | filer = f; |
731 | 731 | ||
732 | DocLnk nf; | 732 | DocLnk nf; |
733 | nf.setType("text/plain"); | 733 | nf.setType("text/plain"); |
734 | nf.setFile(filer); | 734 | nf.setFile(filer); |
735 | currentFileName=filer; | 735 | currentFileName=filer; |
736 | 736 | ||
737 | nf.setName(fi.baseName()); | 737 | nf.setName(fi.baseName()); |
738 | openFile(nf); | 738 | openFile(nf); |
739 | 739 | ||
740 | qDebug("openFile string "+currentFileName); | 740 | qDebug("openFile string "+currentFileName); |
741 | 741 | ||
742 | showEditTools(); | 742 | showEditTools(); |
743 | // Show filename in caption | 743 | // Show filename in caption |
744 | QString name = filer; | 744 | QString name = filer; |
745 | int sep = name.findRev( '/' ); | 745 | int sep = name.findRev( '/' ); |
746 | if ( sep > 0 ) | 746 | if ( sep > 0 ) |
747 | name = name.mid( sep+1 ); | 747 | name = name.mid( sep+1 ); |
748 | updateCaption( name ); | 748 | updateCaption( name ); |
749 | } | 749 | } |
750 | 750 | ||
751 | void TextEdit::openFile( const DocLnk &f ) { | 751 | void TextEdit::openFile( const DocLnk &f ) { |
752 | // clear(); | 752 | // clear(); |
753 | // bFromDocView = true; | 753 | // bFromDocView = true; |
754 | FileManager fm; | 754 | FileManager fm; |
755 | QString txt; | 755 | QString txt; |
756 | currentFileName=f.file(); | 756 | currentFileName=f.file(); |
757 | qDebug("openFile doclnk " + currentFileName); | 757 | qDebug("openFile doclnk " + currentFileName); |
758 | if ( !fm.loadFile( f, txt ) ) { | 758 | if ( !fm.loadFile( f, txt ) ) { |
759 | // ####### could be a new file | 759 | // ####### could be a new file |
760 | qDebug( "Cannot open file" ); | 760 | qDebug( "Cannot open file" ); |
761 | } | 761 | } |
762 | // fileNew(); | 762 | // fileNew(); |
763 | if ( doc ) | 763 | if ( doc ) |
764 | delete doc; | 764 | delete doc; |
765 | doc = new DocLnk(f); | 765 | doc = new DocLnk(f); |
766 | editor->setText(txt); | 766 | editor->setText(txt); |
767 | editor->setEdited( false); | 767 | editor->setEdited( false); |
768 | edited1=false; | 768 | edited1=false; |
769 | edited=false; | 769 | edited=false; |
770 | 770 | ||
771 | doc->setName(currentFileName); | 771 | doc->setName(currentFileName); |
772 | updateCaption(); | 772 | updateCaption(); |
773 | setTimer(); | 773 | setTimer(); |
774 | } | 774 | } |
775 | 775 | ||
776 | void TextEdit::showEditTools() { | 776 | void TextEdit::showEditTools() { |
777 | menu->show(); | 777 | menu->show(); |
778 | editBar->show(); | 778 | editBar->show(); |
779 | if(!useSearchBar) | 779 | if(!useSearchBar) |
780 | searchBar->hide(); | 780 | searchBar->hide(); |
781 | else | 781 | else |
782 | searchBar->show(); | 782 | searchBar->show(); |
783 | setWState (WState_Reserved1 ); | 783 | setWState (WState_Reserved1 ); |
784 | } | 784 | } |
785 | 785 | ||
786 | /*! | 786 | /*! |
787 | unprompted save */ | 787 | unprompted save */ |
788 | bool TextEdit::save() { | 788 | bool TextEdit::save() { |
789 | qDebug("saveAsFile " + currentFileName); | 789 | qDebug("saveAsFile " + currentFileName); |
790 | if(currentFileName.isEmpty()) { | 790 | if(currentFileName.isEmpty()) { |
791 | saveAs(); | 791 | saveAs(); |
792 | return false; | 792 | return false; |
793 | } | 793 | } |
794 | 794 | ||
795 | QString file = doc->file(); | 795 | QString file = doc->file(); |
796 | qDebug("saver file "+file); | 796 | qDebug("saver file "+file); |
797 | QString name= doc->name(); | 797 | QString name= doc->name(); |
798 | qDebug("File named "+name); | 798 | qDebug("File named "+name); |
799 | QString rt = editor->text(); | 799 | QString rt = editor->text(); |
800 | if( !rt.isEmpty() ) { | 800 | if( !rt.isEmpty() ) { |
801 | if(name.isEmpty()) { | 801 | if(name.isEmpty()) { |
802 | saveAs(); | 802 | saveAs(); |
803 | } else { | 803 | } else { |
804 | currentFileName= name ; | 804 | currentFileName= name ; |
805 | qDebug("saveFile "+currentFileName); | 805 | qDebug("saveFile "+currentFileName); |
806 | 806 | ||
807 | struct stat buf; | 807 | struct stat buf; |
808 | mode_t mode; | 808 | mode_t mode; |
809 | stat(file.latin1(), &buf); | 809 | stat(file.latin1(), &buf); |
810 | mode = buf.st_mode; | 810 | mode = buf.st_mode; |
811 | 811 | ||
812 | if(!fileIs) { | 812 | if(!fileIs) { |
813 | doc->setName( name); | 813 | doc->setName( name); |
814 | FileManager fm; | 814 | FileManager fm; |
815 | if ( !fm.saveFile( *doc, rt ) ) { | 815 | if ( !fm.saveFile( *doc, rt ) ) { |
816 | return false; | 816 | return false; |
817 | } | 817 | } |
818 | } else { | 818 | } else { |
819 | qDebug("regular save file"); | 819 | qDebug("regular save file"); |
820 | QFile f(file); | 820 | QFile f(file); |
821 | if( f.open(IO_WriteOnly)) { | 821 | if( f.open(IO_WriteOnly)) { |
822 | QCString crt = rt.utf8(); | 822 | QCString crt = rt.utf8(); |
823 | f.writeBlock(crt,crt.length()); | 823 | f.writeBlock(crt,crt.length()); |
824 | } else { | 824 | } else { |
825 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 825 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
826 | return false; | 826 | return false; |
827 | } | 827 | } |
828 | 828 | ||
829 | } | 829 | } |
830 | editor->setEdited( false); | 830 | editor->setEdited( false); |
831 | edited1=false; | 831 | edited1=false; |
832 | edited=false; | 832 | edited=false; |
833 | if(caption().left(1)=="*") | 833 | if(caption().left(1)=="*") |
834 | setCaption(caption().right(caption().length()-1)); | 834 | setCaption(caption().right(caption().length()-1)); |
835 | 835 | ||
836 | 836 | ||
837 | chmod( file.latin1(), mode); | 837 | chmod( file.latin1(), mode); |
838 | } | 838 | } |
839 | return true; | 839 | return true; |
840 | } | 840 | } |
841 | return false; | 841 | return false; |
842 | } | 842 | } |
843 | 843 | ||
844 | /*! | 844 | /*! |
845 | prompted save */ | 845 | prompted save */ |
846 | bool TextEdit::saveAs() { | 846 | bool TextEdit::saveAs() { |
847 | 847 | ||
848 | if(caption() == tr("Text Editor")) | 848 | if(caption() == tr("Text Editor")) |
849 | return false; | 849 | return false; |
850 | qDebug("saveAsFile " + currentFileName); | 850 | qDebug("saveAsFile " + currentFileName); |
851 | // case of nothing to save... | 851 | // case of nothing to save... |
852 | // if ( !doc && !currentFileName.isEmpty()) { | 852 | // if ( !doc && !currentFileName.isEmpty()) { |
853 | // //|| !bFromDocView) | 853 | // //|| !bFromDocView) |
854 | // qDebug("no doc"); | 854 | // qDebug("no doc"); |
855 | // return true; | 855 | // return true; |
856 | // } | 856 | // } |
857 | // if ( !editor->edited() ) { | 857 | // if ( !editor->edited() ) { |
858 | // delete doc; | 858 | // delete doc; |
859 | // doc = 0; | 859 | // doc = 0; |
860 | // return true; | 860 | // return true; |
861 | // } | 861 | // } |
862 | 862 | ||
863 | QString rt = editor->text(); | 863 | QString rt = editor->text(); |
864 | qDebug(currentFileName); | 864 | qDebug(currentFileName); |
865 | 865 | ||
866 | if( currentFileName.isEmpty() | 866 | if( currentFileName.isEmpty() |
867 | || currentFileName == tr("Unnamed") | 867 | || currentFileName == tr("Unnamed") |
868 | || currentFileName == tr("Text Editor")) { | 868 | || currentFileName == tr("Text Editor")) { |
869 | qDebug("do silly TT filename thing"); | 869 | qDebug("do silly TT filename thing"); |
870 | // if ( doc && doc->name().isEmpty() ) { | 870 | // if ( doc && doc->name().isEmpty() ) { |
871 | QString pt = rt.simplifyWhiteSpace(); | 871 | QString pt = rt.simplifyWhiteSpace(); |
872 | int i = pt.find( ' ' ); | 872 | int i = pt.find( ' ' ); |
873 | QString docname = pt; | 873 | QString docname = pt; |
874 | if ( i > 0 ) | 874 | if ( i > 0 ) |
875 | docname = pt.left( i ); | 875 | docname = pt.left( i ); |
876 | // remove "." at the beginning | 876 | // remove "." at the beginning |
877 | while( docname.startsWith( "." ) ) | 877 | while( docname.startsWith( "." ) ) |
878 | docname = docname.mid( 1 ); | 878 | docname = docname.mid( 1 ); |
879 | docname.replace( QRegExp("/"), "_" ); | 879 | docname.replace( QRegExp("/"), "_" ); |
880 | // cut the length. filenames longer than that | 880 | // cut the length. filenames longer than that |
881 | //don't make sense and something goes wrong when they get too long. | 881 | //don't make sense and something goes wrong when they get too long. |
882 | if ( docname.length() > 40 ) | 882 | if ( docname.length() > 40 ) |
883 | docname = docname.left(40); | 883 | docname = docname.left(40); |
884 | if ( docname.isEmpty() ) | 884 | if ( docname.isEmpty() ) |
885 | docname = tr("Unnamed"); | 885 | docname = tr("Unnamed"); |
886 | if(doc) doc->setName(docname); | 886 | if(doc) doc->setName(docname); |
887 | currentFileName=docname; | 887 | currentFileName=docname; |
888 | // } | 888 | // } |
889 | // else | 889 | // else |
890 | // qDebug("hmmmmmm"); | 890 | // qDebug("hmmmmmm"); |
891 | } | 891 | } |
892 | 892 | ||
893 | 893 | ||
894 | QMap<QString, QStringList> map; | 894 | QMap<QString, QStringList> map; |
895 | map.insert(tr("All"), QStringList() ); | 895 | map.insert(tr("All"), QStringList() ); |
896 | QStringList text; | 896 | QStringList text; |
897 | text << "text/*"; | 897 | text << "text/*"; |
898 | map.insert(tr("Text"), text ); | 898 | map.insert(tr("Text"), text ); |
899 | text << "*"; | 899 | text << "*"; |
900 | map.insert(tr("All"), text ); | 900 | map.insert(tr("All"), text ); |
901 | 901 | ||
902 | QFileInfo cuFi( currentFileName); | 902 | QFileInfo cuFi( currentFileName); |
903 | QString filee = cuFi.fileName(); | 903 | QString filee = cuFi.fileName(); |
904 | QString dire = cuFi.dirPath(); | 904 | QString dire = cuFi.dirPath(); |
905 | if(dire==".") | 905 | if(dire==".") |
906 | dire = QPEApplication::documentDir(); | 906 | dire = QPEApplication::documentDir(); |
907 | QString str; | 907 | QString str; |
908 | if( !featureAutoSave) | 908 | if( !featureAutoSave) |
909 | { | 909 | { |
910 | str = OFileDialog::getSaveFileName( 2, | 910 | str = OFileDialog::getSaveFileName( 2, |
911 | dire, | 911 | dire, |
912 | filee, map); | 912 | filee, map); |
913 | } | 913 | } |
914 | else | 914 | else |
915 | str=currentFileName; | 915 | str=currentFileName; |
916 | if(!str.isEmpty()) { | 916 | if(!str.isEmpty()) { |
917 | QString fileNm=str; | 917 | QString fileNm=str; |
918 | 918 | ||
919 | qDebug("saving filename "+fileNm); | 919 | qDebug("saving filename "+fileNm); |
920 | QFileInfo fi(fileNm); | 920 | QFileInfo fi(fileNm); |
921 | currentFileName=fi.fileName(); | 921 | currentFileName=fi.fileName(); |
922 | if(doc) | 922 | if(doc) |
923 | // QString file = doc->file(); | 923 | // QString file = doc->file(); |
924 | // doc->removeFiles(); | 924 | // doc->removeFiles(); |
925 | delete doc; | 925 | delete doc; |
926 | DocLnk nf; | 926 | DocLnk nf; |
927 | nf.setType("text/plain"); | 927 | nf.setType("text/plain"); |
928 | nf.setFile( fileNm); | 928 | nf.setFile( fileNm); |
929 | doc = new DocLnk(nf); | 929 | doc = new DocLnk(nf); |
930 | // editor->setText(rt); | 930 | // editor->setText(rt); |
931 | qDebug("Saving file as "+currentFileName); | 931 | qDebug("Saving file as "+currentFileName); |
932 | doc->setName( currentFileName); | 932 | doc->setName( currentFileName); |
933 | updateCaption( currentFileName); | 933 | updateCaption( currentFileName); |
934 | 934 | ||
935 | FileManager fm; | 935 | FileManager fm; |
936 | if ( !fm.saveFile( *doc, rt ) ) { | 936 | if ( !fm.saveFile( *doc, rt ) ) { |
937 | return false; | 937 | return false; |
938 | } | 938 | } |
939 | 939 | ||
940 | if( filePerms ) { | 940 | if( filePerms ) { |
941 | filePermissions *filePerm; | 941 | filePermissions *filePerm; |
942 | filePerm = new filePermissions(this, | 942 | filePerm = new filePermissions(this, |
943 | tr("Permissions"),true, | 943 | tr("Permissions"),true, |
944 | 0,(const QString &)fileNm); | 944 | 0,(const QString &)fileNm); |
945 | filePerm->showMaximized(); | 945 | filePerm->showMaximized(); |
946 | filePerm->exec(); | 946 | filePerm->exec(); |
947 | 947 | ||
948 | if( filePerm) | 948 | if( filePerm) |
949 | delete filePerm; | 949 | delete filePerm; |
950 | } | 950 | } |
951 | // } | 951 | // } |
952 | editor->setEdited( false); | 952 | editor->setEdited( false); |
953 | edited1 = false; | 953 | edited1 = false; |
954 | edited = false; | 954 | edited = false; |
955 | if(caption().left(1)=="*") | 955 | if(caption().left(1)=="*") |
956 | setCaption(caption().right(caption().length()-1)); | 956 | setCaption(caption().right(caption().length()-1)); |
957 | 957 | ||
958 | return true; | 958 | return true; |
959 | } | 959 | } |
960 | qDebug("returning false"); | 960 | qDebug("returning false"); |
961 | return false; | 961 | return false; |
962 | } //end saveAs | 962 | } //end saveAs |
963 | 963 | ||
964 | void TextEdit::clear() { | 964 | void TextEdit::clear() { |
965 | delete doc; | 965 | delete doc; |
966 | doc = 0; | 966 | doc = 0; |
967 | editor->clear(); | 967 | editor->clear(); |
968 | } | 968 | } |
969 | 969 | ||
970 | void TextEdit::updateCaption( const QString &name ) { | 970 | void TextEdit::updateCaption( const QString &name ) { |
971 | 971 | ||
972 | if ( name.isEmpty() ) | 972 | if ( name.isEmpty() ) |
973 | setCaption( tr("Text Editor") ); | 973 | setCaption( tr("Text Editor") ); |
974 | else { | 974 | else { |
975 | QString s = name; | 975 | QString s = name; |
976 | if ( s.isNull() ) | 976 | if ( s.isNull() ) |
977 | s = doc->name(); | 977 | s = doc->name(); |
978 | if ( s.isEmpty() ) { | 978 | if ( s.isEmpty() ) { |
979 | s = tr( "Unnamed" ); | 979 | s = tr( "Unnamed" ); |
980 | currentFileName=s; | 980 | currentFileName=s; |
981 | } | 981 | } |
982 | // if(s.left(1) == "/") | 982 | // if(s.left(1) == "/") |
983 | // s = s.right(s.length()-1); | 983 | // s = s.right(s.length()-1); |
984 | setCaption( tr("%1 - Text Editor").arg( s ) ); | 984 | setCaption( tr("%1 - Text Editor").arg( s ) ); |
985 | } | 985 | } |
986 | } | 986 | } |
987 | 987 | ||
988 | void TextEdit::setDocument(const QString& fileref) { | 988 | void TextEdit::setDocument(const QString& fileref) { |
989 | if(fileref != "Unnamed") { | 989 | if(fileref != "Unnamed") { |
990 | currentFileName=fileref; | 990 | currentFileName=fileref; |
991 | qDebug("setDocument"); | 991 | qDebug("setDocument"); |
992 | QFileInfo fi(currentFileName); | 992 | QFileInfo fi(currentFileName); |
993 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); | 993 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); |
994 | if( (fi.baseName().left(1)).isEmpty() ) { | 994 | if( (fi.baseName().left(1)).isEmpty() ) { |
995 | openDotFile(currentFileName); | 995 | openDotFile(currentFileName); |
996 | 996 | ||
997 | } else { | 997 | } else { |
998 | qDebug("setDoc open"); | 998 | qDebug("setDoc open"); |
999 | bFromDocView = true; | 999 | bFromDocView = true; |
1000 | openFile(fileref); | 1000 | openFile(fileref); |
1001 | editor->setEdited(true); | 1001 | editor->setEdited(true); |
1002 | edited1=false; | 1002 | edited1=false; |
1003 | edited=true; | 1003 | edited=true; |
1004 | // fromSetDocument=false; | 1004 | // fromSetDocument=false; |
1005 | // doSearchBar(); | 1005 | // doSearchBar(); |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | updateCaption( currentFileName); | 1008 | updateCaption( currentFileName); |
1009 | } | 1009 | } |
1010 | 1010 | ||
1011 | void TextEdit::changeFont() { | 1011 | void TextEdit::changeFont() { |
1012 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 1012 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
1013 | d-> setCaption ( tr( "Choose font" )); | 1013 | d-> setCaption ( tr( "Choose font" )); |
1014 | QBoxLayout *lay = new QVBoxLayout ( d ); | 1014 | QBoxLayout *lay = new QVBoxLayout ( d ); |
1015 | OFontSelector *ofs = new OFontSelector ( true, d ); | 1015 | OFontSelector *ofs = new OFontSelector ( true, d ); |
1016 | lay-> addWidget ( ofs ); | 1016 | lay-> addWidget ( ofs ); |
1017 | ofs-> setSelectedFont ( editor-> font ( )); | 1017 | ofs-> setSelectedFont ( editor-> font ( )); |
1018 | 1018 | ||
1019 | d-> showMaximized ( ); | 1019 | d-> showMaximized ( ); |
1020 | if ( d-> exec ( ) == QDialog::Accepted ) | 1020 | if ( d-> exec ( ) == QDialog::Accepted ) |
1021 | editor-> setFont ( ofs-> selectedFont ( )); | 1021 | editor-> setFont ( ofs-> selectedFont ( )); |
1022 | delete d; | 1022 | delete d; |
1023 | 1023 | ||
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | void TextEdit::editDelete() { | 1026 | void TextEdit::editDelete() { |
1027 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1027 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1028 | tr("Do you really want<BR>to <B>delete</B> " | 1028 | tr("Do you really want<BR>to <B>delete</B> " |
1029 | "the current file\nfrom the disk?<BR>This is " | 1029 | "the current file\nfrom the disk?<BR>This is " |
1030 | "<B>irreversable!</B>"), | 1030 | "<B>irreversable!</B>"), |
1031 | tr("Yes"),tr("No"),0,0,1) ) { | 1031 | tr("Yes"),tr("No"),0,0,1) ) { |
1032 | case 0: | 1032 | case 0: |
1033 | if(doc) { | 1033 | if(doc) { |
1034 | doc->removeFiles(); | 1034 | doc->removeFiles(); |
1035 | clear(); | 1035 | clear(); |
1036 | setCaption( tr("Text Editor") ); | 1036 | setCaption( tr("Text Editor") ); |
1037 | } | 1037 | } |
1038 | break; | 1038 | break; |
1039 | case 1: | 1039 | case 1: |
1040 | // exit | 1040 | // exit |
1041 | break; | 1041 | break; |
1042 | }; | 1042 | }; |
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | void TextEdit::changeStartConfig( bool b ) { | 1045 | void TextEdit::changeStartConfig( bool b ) { |
1046 | startWithNew=b; | 1046 | startWithNew=b; |
1047 | Config cfg("TextEdit"); | 1047 | Config cfg("TextEdit"); |
1048 | cfg.setGroup("View"); | 1048 | cfg.setGroup("View"); |
1049 | cfg.writeEntry("startNew",b); | 1049 | cfg.writeEntry("startNew",b); |
1050 | update(); | 1050 | update(); |
1051 | } | 1051 | } |
1052 | 1052 | ||
1053 | void TextEdit::editorChanged() { | 1053 | void TextEdit::editorChanged() { |
1054 | // qDebug("editor changed"); | 1054 | // qDebug("editor changed"); |
1055 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1055 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1056 | setCaption( "*"+caption()); | 1056 | setCaption( "*"+caption()); |
1057 | edited1=true; | 1057 | edited1=true; |
1058 | } | 1058 | } |
1059 | edited=true; | 1059 | edited=true; |
1060 | } | 1060 | } |
1061 | 1061 | ||
1062 | void TextEdit::receive(const QCString&msg, const QByteArray &) { | 1062 | void TextEdit::receive(const QCString&msg, const QByteArray &) { |
1063 | qDebug("QCop "+msg); | 1063 | qDebug("QCop "+msg); |
1064 | if ( msg == "setDocument(QString)" ) { | 1064 | if ( msg == "setDocument(QString)" ) { |
1065 | qDebug("bugger all"); | 1065 | qDebug("bugger all"); |
1066 | 1066 | ||
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | void TextEdit::doAbout() { | 1071 | void TextEdit::doAbout() { |
1072 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 1072 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
1073 | "2000 Trolltech AS, and<BR>" | 1073 | "2000 Trolltech AS, and<BR>" |
1074 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 1074 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
1075 | "and is licensed under the GPL")); | 1075 | "and is licensed under the GPL")); |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | void TextEdit::doPrompt(bool b) { | 1078 | void TextEdit::doPrompt(bool b) { |
1079 | promptExit=b; | 1079 | promptExit=b; |
1080 | Config cfg("TextEdit"); | 1080 | Config cfg("TextEdit"); |
1081 | cfg.setGroup ( "View" ); | 1081 | cfg.setGroup ( "View" ); |
1082 | cfg.writeEntry ( "PromptExit", b); | 1082 | cfg.writeEntry ( "PromptExit", b); |
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | void TextEdit::doDesktop(bool b) { | 1085 | void TextEdit::doDesktop(bool b) { |
1086 | openDesktop=b; | 1086 | openDesktop=b; |
1087 | Config cfg("TextEdit"); | 1087 | Config cfg("TextEdit"); |
1088 | cfg.setGroup ( "View" ); | 1088 | cfg.setGroup ( "View" ); |
1089 | cfg.writeEntry ( "OpenDesktop", b); | 1089 | cfg.writeEntry ( "OpenDesktop", b); |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | void TextEdit::doFilePerms(bool b) { | 1092 | void TextEdit::doFilePerms(bool b) { |
1093 | filePerms=b; | 1093 | filePerms=b; |
1094 | Config cfg("TextEdit"); | 1094 | Config cfg("TextEdit"); |
1095 | cfg.setGroup ( "View" ); | 1095 | cfg.setGroup ( "View" ); |
1096 | cfg.writeEntry ( "FilePermissions", b); | 1096 | cfg.writeEntry ( "FilePermissions", b); |
1097 | } | 1097 | } |
1098 | 1098 | ||
1099 | void TextEdit::editPasteTimeDate() { | 1099 | void TextEdit::editPasteTimeDate() { |
1100 | #ifndef QT_NO_CLIPBOARD | 1100 | #ifndef QT_NO_CLIPBOARD |
1101 | QClipboard *cb = QApplication::clipboard(); | 1101 | QClipboard *cb = QApplication::clipboard(); |
1102 | QDateTime dt = QDateTime::currentDateTime(); | 1102 | QDateTime dt = QDateTime::currentDateTime(); |
1103 | cb->setText( dt.toString()); | 1103 | cb->setText( dt.toString()); |
1104 | editor->paste(); | 1104 | editor->paste(); |
1105 | #endif | 1105 | #endif |
1106 | } | 1106 | } |
1107 | 1107 | ||
1108 | int TextEdit::savePrompt() | 1108 | int TextEdit::savePrompt() |
1109 | { | 1109 | { |
1110 | switch( QMessageBox::information( 0, (tr("Textedit")), | 1110 | switch( QMessageBox::information( 0, (tr("Textedit")), |
1111 | (tr("Textedit detected\n" | 1111 | (tr("Textedit detected\n" |
1112 | "you have unsaved changes\n" | 1112 | "you have unsaved changes\n" |
1113 | "Go ahead and save?\n")), | 1113 | "Go ahead and save?\n")), |
1114 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) | 1114 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) |
1115 | { | 1115 | { |
1116 | case 0: | 1116 | case 0: |
1117 | { | 1117 | { |
1118 | return 1; | 1118 | return 1; |
1119 | } | 1119 | } |
1120 | break; | 1120 | break; |
1121 | 1121 | ||
1122 | case 1: | 1122 | case 1: |
1123 | { | 1123 | { |
1124 | return 2; | 1124 | return 2; |
1125 | } | 1125 | } |
1126 | break; | 1126 | break; |
1127 | 1127 | ||
1128 | case 2: | 1128 | case 2: |
1129 | { | 1129 | { |
1130 | return -1; | 1130 | return -1; |
1131 | } | 1131 | } |
1132 | break; | 1132 | break; |
1133 | }; | 1133 | }; |
1134 | 1134 | ||
1135 | return 0; | 1135 | return 0; |
1136 | } | 1136 | } |
1137 | 1137 | ||
1138 | void TextEdit::timerCrank() | 1138 | void TextEdit::timerCrank() |
1139 | { | 1139 | { |
1140 | if(featureAutoSave && edited1) | 1140 | if(featureAutoSave && edited1) |
1141 | { | 1141 | { |
1142 | if(currentFileName.isEmpty()) | 1142 | if(currentFileName.isEmpty()) |
1143 | { | 1143 | { |
1144 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; | 1144 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; |
1145 | saveAs(); | 1145 | saveAs(); |
1146 | } | 1146 | } |
1147 | else | 1147 | else |
1148 | { | 1148 | { |
1149 | // qDebug("autosave"); | 1149 | // qDebug("autosave"); |
1150 | save(); | 1150 | save(); |
1151 | } | 1151 | } |
1152 | setTimer(); | 1152 | setTimer(); |
1153 | } | 1153 | } |
1154 | } | 1154 | } |
1155 | 1155 | ||
1156 | void TextEdit::doTimer(bool b) | 1156 | void TextEdit::doTimer(bool b) |
1157 | { | 1157 | { |
1158 | Config cfg("TextEdit"); | 1158 | Config cfg("TextEdit"); |
1159 | cfg.setGroup ( "View" ); | 1159 | cfg.setGroup ( "View" ); |
1160 | cfg.writeEntry ( "autosave", b); | 1160 | cfg.writeEntry ( "autosave", b); |
1161 | featureAutoSave = b; | 1161 | featureAutoSave = b; |
1162 | nAutoSave->setOn(b); | 1162 | nAutoSave->setOn(b); |
1163 | if(b) | 1163 | if(b) |
1164 | { | 1164 | { |
1165 | // qDebug("doTimer true"); | 1165 | // qDebug("doTimer true"); |
1166 | setTimer(); | 1166 | setTimer(); |
1167 | } | 1167 | } |
1168 | // else | 1168 | // else |
1169 | // qDebug("doTimer false"); | 1169 | // qDebug("doTimer false"); |
1170 | } | 1170 | } |
1171 | 1171 | ||
1172 | void TextEdit::setTimer() | 1172 | void TextEdit::setTimer() |
1173 | { | 1173 | { |
1174 | if(featureAutoSave) | 1174 | if(featureAutoSave) |
1175 | { | 1175 | { |
1176 | // qDebug("setting autosave"); | 1176 | // qDebug("setting autosave"); |
1177 | QTimer *timer = new QTimer(this ); | 1177 | QTimer *timer = new QTimer(this ); |
1178 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); | 1178 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); |
1179 | timer->start( 300000, true); //5 minutes | 1179 | timer->start( 300000, true); //5 minutes |
1180 | } | 1180 | } |
1181 | } | 1181 | } |
1182 | 1182 | ||
1183 | void TextEdit::gotoLine() { | 1183 | void TextEdit::gotoLine() { |
1184 | if( editor->length() < 1) | 1184 | if( editor->length() < 1) |
1185 | return; | 1185 | return; |
1186 | QWidget *d = QApplication::desktop(); | 1186 | QWidget *d = QApplication::desktop(); |
1187 | gotoEdit = new QLineEdit( 0, "Goto line"); | 1187 | gotoEdit = new QLineEdit( 0, "Goto line"); |
1188 | 1188 | ||
1189 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); | 1189 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); |
1190 | gotoEdit->setFrame(true); | 1190 | gotoEdit->setFrame(true); |
1191 | gotoEdit->show(); | 1191 | gotoEdit->show(); |
1192 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); | 1192 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); |
1193 | } | 1193 | } |
1194 | 1194 | ||
1195 | void TextEdit::doGoto() { | 1195 | void TextEdit::doGoto() { |
1196 | QString number = gotoEdit->text(); | 1196 | QString number = gotoEdit->text(); |
1197 | gotoEdit->hide(); | 1197 | gotoEdit->hide(); |
1198 | 1198 | ||
1199 | if(gotoEdit) { | 1199 | if(gotoEdit) { |
1200 | delete gotoEdit; | 1200 | delete gotoEdit; |
1201 | gotoEdit = 0; | 1201 | gotoEdit = 0; |
1202 | } | 1202 | } |
1203 | 1203 | ||
1204 | bool ok; | 1204 | bool ok; |
1205 | int lineNumber = number.toInt(&ok, 10); | 1205 | int lineNumber = number.toInt(&ok, 10); |
1206 | if( editor->numLines() < lineNumber) | 1206 | if( editor->numLines() < lineNumber) |
1207 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); | 1207 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); |
1208 | else | 1208 | else |
1209 | { | 1209 | { |
1210 | editor->setCursorPosition(lineNumber, 0, false); | 1210 | editor->setCursorPosition(lineNumber, 0, false); |
1211 | } | 1211 | } |
1212 | } | 1212 | } |
diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index cfcfd41..5ce53b8 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp | |||
@@ -1,1482 +1,1482 @@ | |||
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 | #include <qpe/qcopenvelope_qws.h> | 22 | #include <qpe/qcopenvelope_qws.h> |
23 | 23 | ||
24 | #include <qmenubar.h> | 24 | #include <qmenubar.h> |
25 | #include <qpe/qpetoolbar.h> | 25 | #include <qtoolbar.h> |
26 | #include <qpe/fileselector.h> | 26 | #include <qpe/fileselector.h> |
27 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
28 | #include <qpe/lnkproperties.h> | 28 | #include <qpe/lnkproperties.h> |
29 | #include <qpe/storage.h> | 29 | #include <qpe/storage.h> |
30 | 30 | ||
31 | #include <qpe/applnk.h> | 31 | #include <qpe/applnk.h> |
32 | #include <qpe/config.h> | 32 | #include <qpe/config.h> |
33 | #include <qpe/global.h> | 33 | #include <qpe/global.h> |
34 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qaction.h> | 35 | #include <qaction.h> |
36 | #include <qcursor.h> | 36 | #include <qcursor.h> |
37 | #include <qimage.h> | 37 | #include <qimage.h> |
38 | #include <qfile.h> | 38 | #include <qfile.h> |
39 | #include <qdir.h> | 39 | #include <qdir.h> |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qlabel.h> | 41 | #include <qlabel.h> |
42 | #include <qlist.h> | 42 | #include <qlist.h> |
43 | #include <qlistbox.h> | 43 | #include <qlistbox.h> |
44 | #include <qmainwindow.h> | 44 | #include <qmainwindow.h> |
45 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
46 | #include <qtoolbutton.h> | 46 | #include <qtoolbutton.h> |
47 | #include <qtabwidget.h> | 47 | #include <qtabwidget.h> |
48 | #include <qlistview.h> | 48 | #include <qlistview.h> |
49 | #include <qpoint.h> | 49 | #include <qpoint.h> |
50 | #include <qlineedit.h> | 50 | #include <qlineedit.h> |
51 | #include <qpushbutton.h> | 51 | #include <qpushbutton.h> |
52 | #include <qregexp.h> | 52 | #include <qregexp.h> |
53 | #include <qtextstream.h> | 53 | #include <qtextstream.h> |
54 | 54 | ||
55 | //#include <qtimer.h> | 55 | //#include <qtimer.h> |
56 | 56 | ||
57 | #include "playlistselection.h" | 57 | #include "playlistselection.h" |
58 | #include "playlistwidget.h" | 58 | #include "playlistwidget.h" |
59 | #include "mediaplayerstate.h" | 59 | #include "mediaplayerstate.h" |
60 | 60 | ||
61 | #include "inputDialog.h" | 61 | #include "inputDialog.h" |
62 | 62 | ||
63 | #include <stdlib.h> | 63 | #include <stdlib.h> |
64 | #include "audiowidget.h" | 64 | #include "audiowidget.h" |
65 | #include "videowidget.h" | 65 | #include "videowidget.h" |
66 | 66 | ||
67 | #include <unistd.h> | 67 | #include <unistd.h> |
68 | #include <sys/file.h> | 68 | #include <sys/file.h> |
69 | #include <sys/ioctl.h> | 69 | #include <sys/ioctl.h> |
70 | #include <sys/soundcard.h> | 70 | #include <sys/soundcard.h> |
71 | 71 | ||
72 | // for setBacklight() | 72 | // for setBacklight() |
73 | #include <linux/fb.h> | 73 | #include <linux/fb.h> |
74 | #include <sys/types.h> | 74 | #include <sys/types.h> |
75 | #include <sys/stat.h> | 75 | #include <sys/stat.h> |
76 | #include <stdlib.h> | 76 | #include <stdlib.h> |
77 | 77 | ||
78 | #define BUTTONS_ON_TOOLBAR | 78 | #define BUTTONS_ON_TOOLBAR |
79 | #define SIDE_BUTTONS | 79 | #define SIDE_BUTTONS |
80 | #define CAN_SAVE_LOAD_PLAYLISTS | 80 | #define CAN_SAVE_LOAD_PLAYLISTS |
81 | 81 | ||
82 | extern AudioWidget *audioUI; | 82 | extern AudioWidget *audioUI; |
83 | extern VideoWidget *videoUI; | 83 | extern VideoWidget *videoUI; |
84 | extern MediaPlayerState *mediaPlayerState; | 84 | extern MediaPlayerState *mediaPlayerState; |
85 | 85 | ||
86 | static inline QString fullBaseName ( const QFileInfo &fi ) | 86 | static inline QString fullBaseName ( const QFileInfo &fi ) |
87 | { | 87 | { |
88 | QString str = fi. fileName ( ); | 88 | QString str = fi. fileName ( ); |
89 | return str. left ( str. findRev ( '.' )); | 89 | return str. left ( str. findRev ( '.' )); |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | QString audioMimes ="audio/mpeg;audio/x-wav;application/ogg;audio/x-mod"; | 93 | QString audioMimes ="audio/mpeg;audio/x-wav;application/ogg;audio/x-mod"; |
94 | // class myFileSelector { | 94 | // class myFileSelector { |
95 | 95 | ||
96 | // }; | 96 | // }; |
97 | class PlayListWidgetPrivate { | 97 | class PlayListWidgetPrivate { |
98 | public: | 98 | public: |
99 | QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; | 99 | QToolButton *tbPlay, *tbFull, *tbLoop, *tbScale, *tbShuffle, *tbAddToList, *tbRemoveFromList, *tbMoveUp, *tbMoveDown, *tbRemove; |
100 | QFrame *playListFrame; | 100 | QFrame *playListFrame; |
101 | FileSelector *files; | 101 | FileSelector *files; |
102 | PlayListSelection *selectedFiles; | 102 | PlayListSelection *selectedFiles; |
103 | bool setDocumentUsed; | 103 | bool setDocumentUsed; |
104 | DocLnk *current; | 104 | DocLnk *current; |
105 | }; | 105 | }; |
106 | 106 | ||
107 | 107 | ||
108 | class ToolButton : public QToolButton { | 108 | class ToolButton : public QToolButton { |
109 | public: | 109 | public: |
110 | ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) | 110 | ToolButton( QWidget *parent, const char *name, const QString& icon, QObject *handler, const QString& slot, bool t = FALSE ) |
111 | : QToolButton( parent, name ) { | 111 | : QToolButton( parent, name ) { |
112 | setTextLabel( name ); | 112 | setTextLabel( name ); |
113 | setPixmap( Resource::loadPixmap( icon ) ); | 113 | setPixmap( Resource::loadPixmap( icon ) ); |
114 | setAutoRaise( TRUE ); | 114 | setAutoRaise( TRUE ); |
115 | setFocusPolicy( QWidget::NoFocus ); | 115 | setFocusPolicy( QWidget::NoFocus ); |
116 | setToggleButton( t ); | 116 | setToggleButton( t ); |
117 | connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); | 117 | connect( this, t ? SIGNAL( toggled(bool) ) : SIGNAL( clicked() ), handler, slot ); |
118 | QPEMenuToolFocusManager::manager()->addWidget( this ); | 118 | QPEMenuToolFocusManager::manager()->addWidget( this ); |
119 | } | 119 | } |
120 | }; | 120 | }; |
121 | 121 | ||
122 | 122 | ||
123 | class MenuItem : public QAction { | 123 | class MenuItem : public QAction { |
124 | public: | 124 | public: |
125 | MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) | 125 | MenuItem( QWidget *parent, const QString& text, QObject *handler, const QString& slot ) |
126 | : QAction( text, QString::null, 0, 0 ) { | 126 | : QAction( text, QString::null, 0, 0 ) { |
127 | connect( this, SIGNAL( activated() ), handler, slot ); | 127 | connect( this, SIGNAL( activated() ), handler, slot ); |
128 | addTo( parent ); | 128 | addTo( parent ); |
129 | } | 129 | } |
130 | }; | 130 | }; |
131 | 131 | ||
132 | 132 | ||
133 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) | 133 | PlayListWidget::PlayListWidget( QWidget* parent, const char* name, WFlags fl ) |
134 | : QMainWindow( parent, name, fl ) { | 134 | : QMainWindow( parent, name, fl ) { |
135 | 135 | ||
136 | d = new PlayListWidgetPrivate; | 136 | d = new PlayListWidgetPrivate; |
137 | d->setDocumentUsed = FALSE; | 137 | d->setDocumentUsed = FALSE; |
138 | d->current = NULL; | 138 | d->current = NULL; |
139 | fromSetDocument = FALSE; | 139 | fromSetDocument = FALSE; |
140 | insanityBool=FALSE; | 140 | insanityBool=FALSE; |
141 | audioScan = FALSE; | 141 | audioScan = FALSE; |
142 | videoScan = FALSE; | 142 | videoScan = FALSE; |
143 | // menuTimer = new QTimer( this ,"menu timer"), | 143 | // menuTimer = new QTimer( this ,"menu timer"), |
144 | // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); | 144 | // connect( menuTimer, SIGNAL( timeout() ), SLOT( addSelected() ) ); |
145 | channel = new QCopChannel( "QPE/Application/opieplayer", this ); | 145 | channel = new QCopChannel( "QPE/Application/opieplayer", this ); |
146 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 146 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
147 | this, SLOT( qcopReceive(const QCString&, const QByteArray&)) ); | 147 | this, SLOT( qcopReceive(const QCString&, const QByteArray&)) ); |
148 | 148 | ||
149 | setBackgroundMode( PaletteButton ); | 149 | setBackgroundMode( PaletteButton ); |
150 | 150 | ||
151 | setCaption( tr("OpiePlayer") ); | 151 | setCaption( tr("OpiePlayer") ); |
152 | setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); | 152 | setIcon( Resource::loadPixmap( "opieplayer/MPEGPlayer" ) ); |
153 | 153 | ||
154 | setToolBarsMovable( FALSE ); | 154 | setToolBarsMovable( FALSE ); |
155 | 155 | ||
156 | // Create Toolbar | 156 | // Create Toolbar |
157 | QPEToolBar *toolbar = new QPEToolBar( this ); | 157 | QToolBar *toolbar = new QToolBar( this ); |
158 | toolbar->setHorizontalStretchable( TRUE ); | 158 | toolbar->setHorizontalStretchable( TRUE ); |
159 | 159 | ||
160 | // Create Menubar | 160 | // Create Menubar |
161 | QMenuBar *menu = new QMenuBar( toolbar ); | 161 | QMenuBar *menu = new QMenuBar( toolbar ); |
162 | menu->setMargin( 0 ); | 162 | menu->setMargin( 0 ); |
163 | 163 | ||
164 | QPEToolBar *bar = new QPEToolBar( this ); | 164 | QToolBar *bar = new QToolBar( this ); |
165 | bar->setLabel( tr( "Play Operations" ) ); | 165 | bar->setLabel( tr( "Play Operations" ) ); |
166 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", | 166 | // d->tbPlayCurList = new ToolButton( bar, tr( "play List" ), "opieplayer/play_current_list", |
167 | // this , SLOT( addSelected()) ); | 167 | // this , SLOT( addSelected()) ); |
168 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); | 168 | tbDeletePlaylist = new QPushButton( Resource::loadIconSet("trash"),"",bar,"close"); |
169 | tbDeletePlaylist->setFlat(TRUE); | 169 | tbDeletePlaylist->setFlat(TRUE); |
170 | 170 | ||
171 | tbDeletePlaylist->setFixedSize(20,20); | 171 | tbDeletePlaylist->setFixedSize(20,20); |
172 | 172 | ||
173 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", | 173 | d->tbAddToList = new ToolButton( bar, tr( "Add to Playlist" ), "opieplayer/add_to_playlist", |
174 | this , SLOT(addSelected()) ); | 174 | this , SLOT(addSelected()) ); |
175 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", | 175 | d->tbRemoveFromList = new ToolButton( bar, tr( "Remove from Playlist" ), "opieplayer/remove_from_playlist", |
176 | this , SLOT(removeSelected()) ); | 176 | this , SLOT(removeSelected()) ); |
177 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); | 177 | // d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", /*this */mediaPlayerState , SLOT(setPlaying(bool) /* btnPlay() */), TRUE ); |
178 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", | 178 | d->tbPlay = new ToolButton( bar, tr( "Play" ), "opieplayer/play", |
179 | this , SLOT( btnPlay(bool) ), TRUE ); | 179 | this , SLOT( btnPlay(bool) ), TRUE ); |
180 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", | 180 | d->tbShuffle = new ToolButton( bar, tr( "Randomize" ),"opieplayer/shuffle", |
181 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); | 181 | mediaPlayerState, SLOT(setShuffled(bool)), TRUE ); |
182 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", | 182 | d->tbLoop = new ToolButton( bar, tr( "Loop" ),"opieplayer/loop", |
183 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); | 183 | mediaPlayerState, SLOT(setLooping(bool)), TRUE ); |
184 | tbDeletePlaylist->hide(); | 184 | tbDeletePlaylist->hide(); |
185 | 185 | ||
186 | QPopupMenu *pmPlayList = new QPopupMenu( this ); | 186 | QPopupMenu *pmPlayList = new QPopupMenu( this ); |
187 | menu->insertItem( tr( "File" ), pmPlayList ); | 187 | menu->insertItem( tr( "File" ), pmPlayList ); |
188 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); | 188 | new MenuItem( pmPlayList, tr( "Clear List" ), this, SLOT( clearList() ) ); |
189 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); | 189 | new MenuItem( pmPlayList, tr( "Add all audio files" ), this, SLOT( addAllMusicToList() ) ); |
190 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); | 190 | new MenuItem( pmPlayList, tr( "Add all video files" ), this, SLOT( addAllVideoToList() ) ); |
191 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); | 191 | new MenuItem( pmPlayList, tr( "Add all files" ), this, SLOT( addAllToList() ) ); |
192 | pmPlayList->insertSeparator(-1); | 192 | pmPlayList->insertSeparator(-1); |
193 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); | 193 | new MenuItem( pmPlayList, tr( "Save PlayList" ), this, SLOT( saveList() ) ); |
194 | new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); | 194 | new MenuItem( pmPlayList, tr( "Open File or URL" ), this,SLOT( openFile() ) ); |
195 | pmPlayList->insertSeparator(-1); | 195 | pmPlayList->insertSeparator(-1); |
196 | new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); | 196 | new MenuItem( pmPlayList, tr( "Rescan for Audio Files" ), this,SLOT( scanForAudio() ) ); |
197 | new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); | 197 | new MenuItem( pmPlayList, tr( "Rescan for Video Files" ), this,SLOT( scanForVideo() ) ); |
198 | 198 | ||
199 | QPopupMenu *pmView = new QPopupMenu( this ); | 199 | QPopupMenu *pmView = new QPopupMenu( this ); |
200 | menu->insertItem( tr( "View" ), pmView ); | 200 | menu->insertItem( tr( "View" ), pmView ); |
201 | 201 | ||
202 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); | 202 | fullScreenButton = new QAction(tr("Full Screen"), Resource::loadPixmap("fullscreen"), QString::null, 0, this, 0); |
203 | fullScreenButton->addTo(pmView); | 203 | fullScreenButton->addTo(pmView); |
204 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); | 204 | scaleButton = new QAction(tr("Scale"), Resource::loadPixmap("opieplayer/scale"), QString::null, 0, this, 0); |
205 | scaleButton->addTo(pmView); | 205 | scaleButton->addTo(pmView); |
206 | 206 | ||
207 | 207 | ||
208 | skinsMenu = new QPopupMenu( this ); | 208 | skinsMenu = new QPopupMenu( this ); |
209 | menu->insertItem( tr( "Skins" ), skinsMenu ); | 209 | menu->insertItem( tr( "Skins" ), skinsMenu ); |
210 | skinsMenu->isCheckable(); | 210 | skinsMenu->isCheckable(); |
211 | connect( skinsMenu, SIGNAL( activated( int ) ) , | 211 | connect( skinsMenu, SIGNAL( activated( int ) ) , |
212 | this, SLOT( skinsMenuActivated( int ) ) ); | 212 | this, SLOT( skinsMenuActivated( int ) ) ); |
213 | populateSkinsMenu(); | 213 | populateSkinsMenu(); |
214 | 214 | ||
215 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); | 215 | QVBox *vbox5 = new QVBox( this ); vbox5->setBackgroundMode( PaletteButton ); |
216 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); | 216 | QVBox *vbox4 = new QVBox( vbox5 ); vbox4->setBackgroundMode( PaletteButton ); |
217 | 217 | ||
218 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); | 218 | QHBox *hbox6 = new QHBox( vbox4 ); hbox6->setBackgroundMode( PaletteButton ); |
219 | 219 | ||
220 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); | 220 | tabWidget = new QTabWidget( hbox6, "tabWidget" ); |
221 | // tabWidget->setTabShape(QTabWidget::Triangular); | 221 | // tabWidget->setTabShape(QTabWidget::Triangular); |
222 | 222 | ||
223 | QWidget *pTab; | 223 | QWidget *pTab; |
224 | pTab = new QWidget( tabWidget, "pTab" ); | 224 | pTab = new QWidget( tabWidget, "pTab" ); |
225 | // playlistView = new QListView( pTab, "playlistview" ); | 225 | // playlistView = new QListView( pTab, "playlistview" ); |
226 | // playlistView->setMinimumSize(236,260); | 226 | // playlistView->setMinimumSize(236,260); |
227 | tabWidget->insertTab( pTab,"Playlist"); | 227 | tabWidget->insertTab( pTab,"Playlist"); |
228 | 228 | ||
229 | 229 | ||
230 | // Add the playlist area | 230 | // Add the playlist area |
231 | 231 | ||
232 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); | 232 | QVBox *vbox3 = new QVBox( pTab ); vbox3->setBackgroundMode( PaletteButton ); |
233 | d->playListFrame = vbox3; | 233 | d->playListFrame = vbox3; |
234 | 234 | ||
235 | QGridLayout *layoutF = new QGridLayout( pTab ); | 235 | QGridLayout *layoutF = new QGridLayout( pTab ); |
236 | layoutF->setSpacing( 2); | 236 | layoutF->setSpacing( 2); |
237 | layoutF->setMargin( 2); | 237 | layoutF->setMargin( 2); |
238 | layoutF->addMultiCellWidget( d->playListFrame , 0, 0, 0, 1 ); | 238 | layoutF->addMultiCellWidget( d->playListFrame , 0, 0, 0, 1 ); |
239 | 239 | ||
240 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); | 240 | QHBox *hbox2 = new QHBox( vbox3 ); hbox2->setBackgroundMode( PaletteButton ); |
241 | 241 | ||
242 | d->selectedFiles = new PlayListSelection( hbox2); | 242 | d->selectedFiles = new PlayListSelection( hbox2); |
243 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); | 243 | QVBox *vbox1 = new QVBox( hbox2 ); vbox1->setBackgroundMode( PaletteButton ); |
244 | 244 | ||
245 | QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); | 245 | QPEApplication::setStylusOperation( d->selectedFiles->viewport(),QPEApplication::RightOnHold); |
246 | 246 | ||
247 | 247 | ||
248 | 248 | ||
249 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch | 249 | QVBox *stretch1 = new QVBox( vbox1 ); stretch1->setBackgroundMode( PaletteButton ); // add stretch |
250 | new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); | 250 | new ToolButton( vbox1, tr( "Move Up" ), "opieplayer/up", d->selectedFiles, SLOT(moveSelectedUp()) ); |
251 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); | 251 | new ToolButton( vbox1, tr( "Remove" ), "opieplayer/cut", d->selectedFiles, SLOT(removeSelected()) ); |
252 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); | 252 | new ToolButton( vbox1, tr( "Move Down" ), "opieplayer/down", d->selectedFiles, SLOT(moveSelectedDown()) ); |
253 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch | 253 | QVBox *stretch2 = new QVBox( vbox1 ); stretch2->setBackgroundMode( PaletteButton ); // add stretch |
254 | 254 | ||
255 | QWidget *aTab; | 255 | QWidget *aTab; |
256 | aTab = new QWidget( tabWidget, "aTab" ); | 256 | aTab = new QWidget( tabWidget, "aTab" ); |
257 | audioView = new QListView( aTab, "Audioview" ); | 257 | audioView = new QListView( aTab, "Audioview" ); |
258 | 258 | ||
259 | QGridLayout *layoutA = new QGridLayout( aTab ); | 259 | QGridLayout *layoutA = new QGridLayout( aTab ); |
260 | layoutA->setSpacing( 2); | 260 | layoutA->setSpacing( 2); |
261 | layoutA->setMargin( 2); | 261 | layoutA->setMargin( 2); |
262 | layoutA->addMultiCellWidget( audioView, 0, 0, 0, 1 ); | 262 | layoutA->addMultiCellWidget( audioView, 0, 0, 0, 1 ); |
263 | 263 | ||
264 | audioView->addColumn( tr("Title"),-1); | 264 | audioView->addColumn( tr("Title"),-1); |
265 | audioView->addColumn(tr("Size"), -1); | 265 | audioView->addColumn(tr("Size"), -1); |
266 | audioView->addColumn(tr("Media"),-1); | 266 | audioView->addColumn(tr("Media"),-1); |
267 | audioView->addColumn( tr( "Path" ), -1 ); | 267 | audioView->addColumn( tr( "Path" ), -1 ); |
268 | 268 | ||
269 | audioView->setColumnAlignment(1, Qt::AlignRight); | 269 | audioView->setColumnAlignment(1, Qt::AlignRight); |
270 | audioView->setColumnAlignment(2, Qt::AlignRight); | 270 | audioView->setColumnAlignment(2, Qt::AlignRight); |
271 | audioView->setAllColumnsShowFocus(TRUE); | 271 | audioView->setAllColumnsShowFocus(TRUE); |
272 | 272 | ||
273 | audioView->setMultiSelection( TRUE ); | 273 | audioView->setMultiSelection( TRUE ); |
274 | audioView->setSelectionMode( QListView::Extended); | 274 | audioView->setSelectionMode( QListView::Extended); |
275 | audioView->setSorting( 3, TRUE ); | 275 | audioView->setSorting( 3, TRUE ); |
276 | 276 | ||
277 | tabWidget->insertTab(aTab,tr("Audio")); | 277 | tabWidget->insertTab(aTab,tr("Audio")); |
278 | 278 | ||
279 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); | 279 | QPEApplication::setStylusOperation( audioView->viewport(),QPEApplication::RightOnHold); |
280 | 280 | ||
281 | // audioView | 281 | // audioView |
282 | // populateAudioView(); | 282 | // populateAudioView(); |
283 | // videowidget | 283 | // videowidget |
284 | 284 | ||
285 | QWidget *vTab; | 285 | QWidget *vTab; |
286 | vTab = new QWidget( tabWidget, "vTab" ); | 286 | vTab = new QWidget( tabWidget, "vTab" ); |
287 | videoView = new QListView( vTab, "Videoview" ); | 287 | videoView = new QListView( vTab, "Videoview" ); |
288 | 288 | ||
289 | QGridLayout *layoutV = new QGridLayout( vTab ); | 289 | QGridLayout *layoutV = new QGridLayout( vTab ); |
290 | layoutV->setSpacing( 2); | 290 | layoutV->setSpacing( 2); |
291 | layoutV->setMargin( 2); | 291 | layoutV->setMargin( 2); |
292 | layoutV->addMultiCellWidget( videoView, 0, 0, 0, 1 ); | 292 | layoutV->addMultiCellWidget( videoView, 0, 0, 0, 1 ); |
293 | 293 | ||
294 | videoView->addColumn(tr("Title"),-1); | 294 | videoView->addColumn(tr("Title"),-1); |
295 | videoView->addColumn(tr("Size"),-1); | 295 | videoView->addColumn(tr("Size"),-1); |
296 | videoView->addColumn(tr("Media"),-1); | 296 | videoView->addColumn(tr("Media"),-1); |
297 | videoView->addColumn(tr( "Path" ), -1 ); | 297 | videoView->addColumn(tr( "Path" ), -1 ); |
298 | videoView->setColumnAlignment(1, Qt::AlignRight); | 298 | videoView->setColumnAlignment(1, Qt::AlignRight); |
299 | videoView->setColumnAlignment(2, Qt::AlignRight); | 299 | videoView->setColumnAlignment(2, Qt::AlignRight); |
300 | videoView->setAllColumnsShowFocus(TRUE); | 300 | videoView->setAllColumnsShowFocus(TRUE); |
301 | videoView->setMultiSelection( TRUE ); | 301 | videoView->setMultiSelection( TRUE ); |
302 | videoView->setSelectionMode( QListView::Extended); | 302 | videoView->setSelectionMode( QListView::Extended); |
303 | 303 | ||
304 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); | 304 | QPEApplication::setStylusOperation( videoView->viewport(),QPEApplication::RightOnHold); |
305 | 305 | ||
306 | tabWidget->insertTab( vTab,tr("Video")); | 306 | tabWidget->insertTab( vTab,tr("Video")); |
307 | 307 | ||
308 | QWidget *LTab; | 308 | QWidget *LTab; |
309 | LTab = new QWidget( tabWidget, "LTab" ); | 309 | LTab = new QWidget( tabWidget, "LTab" ); |
310 | playLists = new FileSelector( "playlist/plain;audio/x-mpegurl", LTab, "fileselector" , FALSE, FALSE); | 310 | playLists = new FileSelector( "playlist/plain;audio/x-mpegurl", LTab, "fileselector" , FALSE, FALSE); |
311 | 311 | ||
312 | QGridLayout *layoutL = new QGridLayout( LTab ); | 312 | QGridLayout *layoutL = new QGridLayout( LTab ); |
313 | layoutL->setSpacing( 2); | 313 | layoutL->setSpacing( 2); |
314 | layoutL->setMargin( 2); | 314 | layoutL->setMargin( 2); |
315 | layoutL->addMultiCellWidget( playLists, 0, 0, 0, 1 ); | 315 | layoutL->addMultiCellWidget( playLists, 0, 0, 0, 1 ); |
316 | 316 | ||
317 | tabWidget->insertTab(LTab,tr("Lists")); | 317 | tabWidget->insertTab(LTab,tr("Lists")); |
318 | 318 | ||
319 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); | 319 | connect(tbDeletePlaylist,(SIGNAL(released())),SLOT( deletePlaylist())); |
320 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); | 320 | connect( fullScreenButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleFullscreen()) ); |
321 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); | 321 | connect( scaleButton, SIGNAL(activated()), mediaPlayerState, SLOT(toggleScaled()) ); |
322 | 322 | ||
323 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 323 | connect( d->selectedFiles, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
324 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); | 324 | this,SLOT( playlistViewPressed(int, QListViewItem *, const QPoint&, int)) ); |
325 | 325 | ||
326 | 326 | ||
327 | ///audioView | 327 | ///audioView |
328 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 328 | connect( audioView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
329 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | 329 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); |
330 | 330 | ||
331 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), | 331 | connect( audioView, SIGNAL( returnPressed( QListViewItem *)), |
332 | this,SLOT( playIt( QListViewItem *)) ); | 332 | this,SLOT( playIt( QListViewItem *)) ); |
333 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 333 | connect( audioView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
334 | 334 | ||
335 | 335 | ||
336 | //videoView | 336 | //videoView |
337 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 337 | connect( videoView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
338 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); | 338 | this,SLOT( viewPressed(int, QListViewItem *, const QPoint&, int)) ); |
339 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), | 339 | connect( videoView, SIGNAL( returnPressed( QListViewItem *)), |
340 | this,SLOT( playIt( QListViewItem *)) ); | 340 | this,SLOT( playIt( QListViewItem *)) ); |
341 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); | 341 | connect( videoView, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( addToSelection( QListViewItem *) ) ); |
342 | 342 | ||
343 | //playlists | 343 | //playlists |
344 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); | 344 | connect( playLists, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( loadList( const DocLnk & ) ) ); |
345 | 345 | ||
346 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); | 346 | connect( tabWidget, SIGNAL (currentChanged(QWidget*)),this,SLOT(tabChanged(QWidget*))); |
347 | 347 | ||
348 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); | 348 | connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), d->tbPlay, SLOT( setOn( bool ) ) ); |
349 | 349 | ||
350 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); | 350 | connect( mediaPlayerState, SIGNAL( loopingToggled( bool ) ), d->tbLoop, SLOT( setOn( bool ) ) ); |
351 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); | 351 | connect( mediaPlayerState, SIGNAL( shuffledToggled( bool ) ), d->tbShuffle, SLOT( setOn( bool ) ) ); |
352 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); | 352 | connect( mediaPlayerState, SIGNAL( playlistToggled( bool ) ), this, SLOT( setPlaylist( bool ) ) ); |
353 | 353 | ||
354 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); | 354 | connect( d->selectedFiles, SIGNAL( doubleClicked( QListViewItem *) ), this, SLOT( playIt( QListViewItem *) ) ); |
355 | 355 | ||
356 | setCentralWidget( vbox5 ); | 356 | setCentralWidget( vbox5 ); |
357 | 357 | ||
358 | Config cfg( "OpiePlayer" ); | 358 | Config cfg( "OpiePlayer" ); |
359 | readConfig( cfg ); | 359 | readConfig( cfg ); |
360 | 360 | ||
361 | currentPlayList = cfg.readEntry("CurrentPlaylist","default"); | 361 | currentPlayList = cfg.readEntry("CurrentPlaylist","default"); |
362 | loadList(DocLnk( currentPlayList)); | 362 | loadList(DocLnk( currentPlayList)); |
363 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlayList))); | 363 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(currentPlayList))); |
364 | 364 | ||
365 | initializeStates(); | 365 | initializeStates(); |
366 | } | 366 | } |
367 | 367 | ||
368 | 368 | ||
369 | PlayListWidget::~PlayListWidget() { | 369 | PlayListWidget::~PlayListWidget() { |
370 | Config cfg( "OpiePlayer" ); | 370 | Config cfg( "OpiePlayer" ); |
371 | writeConfig( cfg ); | 371 | writeConfig( cfg ); |
372 | 372 | ||
373 | if ( d->current ) | 373 | if ( d->current ) |
374 | delete d->current; | 374 | delete d->current; |
375 | if(d) delete d; | 375 | if(d) delete d; |
376 | } | 376 | } |
377 | 377 | ||
378 | 378 | ||
379 | void PlayListWidget::initializeStates() { | 379 | void PlayListWidget::initializeStates() { |
380 | 380 | ||
381 | d->tbPlay->setOn( mediaPlayerState->playing() ); | 381 | d->tbPlay->setOn( mediaPlayerState->playing() ); |
382 | d->tbLoop->setOn( mediaPlayerState->looping() ); | 382 | d->tbLoop->setOn( mediaPlayerState->looping() ); |
383 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); | 383 | d->tbShuffle->setOn( mediaPlayerState->shuffled() ); |
384 | setPlaylist( true); | 384 | setPlaylist( true); |
385 | } | 385 | } |
386 | 386 | ||
387 | 387 | ||
388 | void PlayListWidget::readConfig( Config& cfg ) { | 388 | void PlayListWidget::readConfig( Config& cfg ) { |
389 | cfg.setGroup("PlayList"); | 389 | cfg.setGroup("PlayList"); |
390 | QString currentString = cfg.readEntry("current", "" ); | 390 | QString currentString = cfg.readEntry("current", "" ); |
391 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 391 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
392 | for ( int i = 0; i < noOfFiles; i++ ) { | 392 | for ( int i = 0; i < noOfFiles; i++ ) { |
393 | QString entryName; | 393 | QString entryName; |
394 | entryName.sprintf( "File%i", i + 1 ); | 394 | entryName.sprintf( "File%i", i + 1 ); |
395 | QString linkFile = cfg.readEntry( entryName ); | 395 | QString linkFile = cfg.readEntry( entryName ); |
396 | DocLnk lnk( linkFile ); | 396 | DocLnk lnk( linkFile ); |
397 | if ( lnk.isValid() ) { | 397 | if ( lnk.isValid() ) { |
398 | d->selectedFiles->addToSelection( lnk ); | 398 | d->selectedFiles->addToSelection( lnk ); |
399 | } | 399 | } |
400 | } | 400 | } |
401 | d->selectedFiles->setSelectedItem( currentString); | 401 | d->selectedFiles->setSelectedItem( currentString); |
402 | } | 402 | } |
403 | 403 | ||
404 | 404 | ||
405 | void PlayListWidget::writeConfig( Config& cfg ) const { | 405 | void PlayListWidget::writeConfig( Config& cfg ) const { |
406 | 406 | ||
407 | d->selectedFiles->writeCurrent( cfg); | 407 | d->selectedFiles->writeCurrent( cfg); |
408 | cfg.setGroup("PlayList"); | 408 | cfg.setGroup("PlayList"); |
409 | int noOfFiles = 0; | 409 | int noOfFiles = 0; |
410 | d->selectedFiles->first(); | 410 | d->selectedFiles->first(); |
411 | do { | 411 | do { |
412 | const DocLnk *lnk = d->selectedFiles->current(); | 412 | const DocLnk *lnk = d->selectedFiles->current(); |
413 | if ( lnk ) { | 413 | if ( lnk ) { |
414 | QString entryName; | 414 | QString entryName; |
415 | entryName.sprintf( "File%i", noOfFiles + 1 ); | 415 | entryName.sprintf( "File%i", noOfFiles + 1 ); |
416 | // qDebug(entryName); | 416 | // qDebug(entryName); |
417 | cfg.writeEntry( entryName, lnk->linkFile() ); | 417 | cfg.writeEntry( entryName, lnk->linkFile() ); |
418 | // if this link does exist, add it so we have the file | 418 | // if this link does exist, add it so we have the file |
419 | // next time... | 419 | // next time... |
420 | if ( !QFile::exists( lnk->linkFile() ) ) { | 420 | if ( !QFile::exists( lnk->linkFile() ) ) { |
421 | // the way writing lnks doesn't really check for out | 421 | // the way writing lnks doesn't really check for out |
422 | // of disk space, but check it anyway. | 422 | // of disk space, but check it anyway. |
423 | // if ( !lnk->writeLink() ) { | 423 | // if ( !lnk->writeLink() ) { |
424 | // QMessageBox::critical( 0, tr("Out of space"), | 424 | // QMessageBox::critical( 0, tr("Out of space"), |
425 | // tr( "There was a problem saving " | 425 | // tr( "There was a problem saving " |
426 | // "the playlist.\n" | 426 | // "the playlist.\n" |
427 | // "Your playlist " | 427 | // "Your playlist " |
428 | // "may be missing some entries\n" | 428 | // "may be missing some entries\n" |
429 | // "the next time you start it." ) | 429 | // "the next time you start it." ) |
430 | // ); | 430 | // ); |
431 | // } | 431 | // } |
432 | 432 | ||
433 | } | 433 | } |
434 | noOfFiles++; | 434 | noOfFiles++; |
435 | } | 435 | } |
436 | } | 436 | } |
437 | while ( d->selectedFiles->next() ); | 437 | while ( d->selectedFiles->next() ); |
438 | cfg.writeEntry("NumberOfFiles", noOfFiles ); | 438 | cfg.writeEntry("NumberOfFiles", noOfFiles ); |
439 | } | 439 | } |
440 | 440 | ||
441 | 441 | ||
442 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { | 442 | void PlayListWidget::addToSelection( const DocLnk& lnk ) { |
443 | d->setDocumentUsed = false; | 443 | d->setDocumentUsed = false; |
444 | if ( mediaPlayerState->playlist() ) { | 444 | if ( mediaPlayerState->playlist() ) { |
445 | if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) | 445 | if(QFileInfo(lnk.file()).exists() || lnk.file().left(4) == "http" ) |
446 | d->selectedFiles->addToSelection( lnk ); | 446 | d->selectedFiles->addToSelection( lnk ); |
447 | } | 447 | } |
448 | else | 448 | else |
449 | mediaPlayerState->setPlaying( true); | 449 | mediaPlayerState->setPlaying( true); |
450 | 450 | ||
451 | } | 451 | } |
452 | 452 | ||
453 | 453 | ||
454 | void PlayListWidget::clearList() { | 454 | void PlayListWidget::clearList() { |
455 | while ( first() ) | 455 | while ( first() ) |
456 | d->selectedFiles->removeSelected(); | 456 | d->selectedFiles->removeSelected(); |
457 | Config cfg( "OpiePlayer" ); | 457 | Config cfg( "OpiePlayer" ); |
458 | cfg.setGroup("PlayList"); | 458 | cfg.setGroup("PlayList"); |
459 | cfg.writeEntry("CurrentPlaylist",""); | 459 | cfg.writeEntry("CurrentPlaylist",""); |
460 | currentPlayList=""; | 460 | currentPlayList=""; |
461 | 461 | ||
462 | } | 462 | } |
463 | 463 | ||
464 | 464 | ||
465 | void PlayListWidget::addAllToList() { | 465 | void PlayListWidget::addAllToList() { |
466 | DocLnkSet filesAll; | 466 | DocLnkSet filesAll; |
467 | Global::findDocuments(&filesAll, "video/*;audio/*"); | 467 | Global::findDocuments(&filesAll, "video/*;audio/*"); |
468 | QListIterator<DocLnk> Adit( filesAll.children() ); | 468 | QListIterator<DocLnk> Adit( filesAll.children() ); |
469 | for ( ; Adit.current(); ++Adit ) | 469 | for ( ; Adit.current(); ++Adit ) |
470 | if(QFileInfo(Adit.current()->file()).exists()) | 470 | if(QFileInfo(Adit.current()->file()).exists()) |
471 | d->selectedFiles->addToSelection( **Adit ); | 471 | d->selectedFiles->addToSelection( **Adit ); |
472 | tabWidget->setCurrentPage(0); | 472 | tabWidget->setCurrentPage(0); |
473 | 473 | ||
474 | writeCurrentM3u(); | 474 | writeCurrentM3u(); |
475 | d->selectedFiles->first(); | 475 | d->selectedFiles->first(); |
476 | } | 476 | } |
477 | 477 | ||
478 | 478 | ||
479 | void PlayListWidget::addAllMusicToList() { | 479 | void PlayListWidget::addAllMusicToList() { |
480 | QListIterator<DocLnk> dit( files.children() ); | 480 | QListIterator<DocLnk> dit( files.children() ); |
481 | for ( ; dit.current(); ++dit ) | 481 | for ( ; dit.current(); ++dit ) |
482 | if(QFileInfo(dit.current()->file()).exists()) | 482 | if(QFileInfo(dit.current()->file()).exists()) |
483 | d->selectedFiles->addToSelection( **dit ); | 483 | d->selectedFiles->addToSelection( **dit ); |
484 | tabWidget->setCurrentPage(0); | 484 | tabWidget->setCurrentPage(0); |
485 | 485 | ||
486 | writeCurrentM3u(); | 486 | writeCurrentM3u(); |
487 | d->selectedFiles->first(); | 487 | d->selectedFiles->first(); |
488 | } | 488 | } |
489 | 489 | ||
490 | 490 | ||
491 | void PlayListWidget::addAllVideoToList() { | 491 | void PlayListWidget::addAllVideoToList() { |
492 | QListIterator<DocLnk> dit( vFiles.children() ); | 492 | QListIterator<DocLnk> dit( vFiles.children() ); |
493 | for ( ; dit.current(); ++dit ) | 493 | for ( ; dit.current(); ++dit ) |
494 | if(QFileInfo( dit.current()->file()).exists()) | 494 | if(QFileInfo( dit.current()->file()).exists()) |
495 | d->selectedFiles->addToSelection( **dit ); | 495 | d->selectedFiles->addToSelection( **dit ); |
496 | tabWidget->setCurrentPage(0); | 496 | tabWidget->setCurrentPage(0); |
497 | 497 | ||
498 | writeCurrentM3u(); | 498 | writeCurrentM3u(); |
499 | d->selectedFiles->first(); | 499 | d->selectedFiles->first(); |
500 | } | 500 | } |
501 | 501 | ||
502 | 502 | ||
503 | void PlayListWidget::setDocument(const QString& fileref) { | 503 | void PlayListWidget::setDocument(const QString& fileref) { |
504 | fromSetDocument = true; | 504 | fromSetDocument = true; |
505 | d->setDocumentUsed = TRUE; | 505 | d->setDocumentUsed = TRUE; |
506 | setDocumentEx(fileref); | 506 | setDocumentEx(fileref); |
507 | } | 507 | } |
508 | 508 | ||
509 | void PlayListWidget::setDocumentEx(const QString& fileref) { | 509 | void PlayListWidget::setDocumentEx(const QString& fileref) { |
510 | qDebug("opieplayer receive "+fileref); | 510 | qDebug("opieplayer receive "+fileref); |
511 | clearList(); | 511 | clearList(); |
512 | DocLnk lnk; | 512 | DocLnk lnk; |
513 | QFileInfo fileInfo(fileref); | 513 | QFileInfo fileInfo(fileref); |
514 | if ( !fileInfo.exists() ) { | 514 | if ( !fileInfo.exists() ) { |
515 | QMessageBox::critical( 0, tr( "Invalid File" ), | 515 | QMessageBox::critical( 0, tr( "Invalid File" ), |
516 | tr( "There was a problem in getting the file." ) ); | 516 | tr( "There was a problem in getting the file." ) ); |
517 | return; | 517 | return; |
518 | } | 518 | } |
519 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<setDocument "+fileref); | 519 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<setDocument "+fileref); |
520 | QString extension = fileInfo.extension(false); | 520 | QString extension = fileInfo.extension(false); |
521 | if( extension.find( "m3u", 0, false) != -1) { //is m3u | 521 | if( extension.find( "m3u", 0, false) != -1) { //is m3u |
522 | readm3u( fileref); | 522 | readm3u( fileref); |
523 | } | 523 | } |
524 | else if( extension.find( "pls", 0, false) != -1 ) { //is pls | 524 | else if( extension.find( "pls", 0, false) != -1 ) { //is pls |
525 | readPls( fileref); | 525 | readPls( fileref); |
526 | } | 526 | } |
527 | else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist | 527 | else if( fileref.find("playlist",0,TRUE) != -1) {//is playlist |
528 | clearList(); | 528 | clearList(); |
529 | lnk.setName( fileInfo.baseName() ); //sets name | 529 | lnk.setName( fileInfo.baseName() ); //sets name |
530 | lnk.setFile( fileref ); //sets file name | 530 | lnk.setFile( fileref ); //sets file name |
531 | lnk.setIcon("Sound"); | 531 | lnk.setIcon("Sound"); |
532 | //addToSelection( lnk ); | 532 | //addToSelection( lnk ); |
533 | 533 | ||
534 | loadList( lnk); | 534 | loadList( lnk); |
535 | d->selectedFiles->first(); | 535 | d->selectedFiles->first(); |
536 | } else { | 536 | } else { |
537 | if( fileref.find(".desktop",0,TRUE) != -1) { | 537 | if( fileref.find(".desktop",0,TRUE) != -1) { |
538 | lnk = DocLnk(fileref); | 538 | lnk = DocLnk(fileref); |
539 | } else { | 539 | } else { |
540 | lnk.setName( fileInfo.baseName() ); //sets name | 540 | lnk.setName( fileInfo.baseName() ); //sets name |
541 | lnk.setFile( fileref ); //sets file name | 541 | lnk.setFile( fileref ); //sets file name |
542 | lnk.setIcon("Sound"); | 542 | lnk.setIcon("Sound"); |
543 | } | 543 | } |
544 | 544 | ||
545 | addToSelection( lnk ); | 545 | addToSelection( lnk ); |
546 | // addToSelection( DocLnk( fileref ) ); | 546 | // addToSelection( DocLnk( fileref ) ); |
547 | lnk.removeLinkFile(); | 547 | lnk.removeLinkFile(); |
548 | // qApp->processEvents(); | 548 | // qApp->processEvents(); |
549 | } | 549 | } |
550 | setCaption(tr("OpiePlayer")); | 550 | setCaption(tr("OpiePlayer")); |
551 | d->setDocumentUsed = TRUE; | 551 | d->setDocumentUsed = TRUE; |
552 | d->selectedFiles->setSelected(d->selectedFiles->firstChild(),true ); | 552 | d->selectedFiles->setSelected(d->selectedFiles->firstChild(),true ); |
553 | mediaPlayerState->setPlaying( FALSE ); | 553 | mediaPlayerState->setPlaying( FALSE ); |
554 | qApp->processEvents(); | 554 | qApp->processEvents(); |
555 | mediaPlayerState->setPlaying( TRUE ); | 555 | mediaPlayerState->setPlaying( TRUE ); |
556 | 556 | ||
557 | } | 557 | } |
558 | 558 | ||
559 | 559 | ||
560 | void PlayListWidget::setActiveWindow() { | 560 | void PlayListWidget::setActiveWindow() { |
561 | // qDebug("SETTING active window"); | 561 | // qDebug("SETTING active window"); |
562 | // When we get raised we need to ensure that it switches views | 562 | // When we get raised we need to ensure that it switches views |
563 | char origView = mediaPlayerState->view(); | 563 | char origView = mediaPlayerState->view(); |
564 | mediaPlayerState->setView( 'l' ); // invalidate | 564 | mediaPlayerState->setView( 'l' ); // invalidate |
565 | mediaPlayerState->setView( origView ); // now switch back | 565 | mediaPlayerState->setView( origView ); // now switch back |
566 | } | 566 | } |
567 | 567 | ||
568 | 568 | ||
569 | void PlayListWidget::useSelectedDocument() { | 569 | void PlayListWidget::useSelectedDocument() { |
570 | d->setDocumentUsed = FALSE; | 570 | d->setDocumentUsed = FALSE; |
571 | } | 571 | } |
572 | 572 | ||
573 | 573 | ||
574 | const DocLnk *PlayListWidget::current() { // this is fugly | 574 | const DocLnk *PlayListWidget::current() { // this is fugly |
575 | switch (tabWidget->currentPageIndex()) { | 575 | switch (tabWidget->currentPageIndex()) { |
576 | case 0: //playlist | 576 | case 0: //playlist |
577 | { | 577 | { |
578 | // qDebug("playlist"); | 578 | // qDebug("playlist"); |
579 | if ( mediaPlayerState->playlist() ) { | 579 | if ( mediaPlayerState->playlist() ) { |
580 | return d->selectedFiles->current(); | 580 | return d->selectedFiles->current(); |
581 | } | 581 | } |
582 | else if ( d->setDocumentUsed && d->current ) { | 582 | else if ( d->setDocumentUsed && d->current ) { |
583 | return d->current; | 583 | return d->current; |
584 | } else { | 584 | } else { |
585 | return &(d->files->selectedDocument()); | 585 | return &(d->files->selectedDocument()); |
586 | } | 586 | } |
587 | } | 587 | } |
588 | break; | 588 | break; |
589 | case 1://audio | 589 | case 1://audio |
590 | { | 590 | { |
591 | // qDebug("audioView"); | 591 | // qDebug("audioView"); |
592 | QListIterator<DocLnk> dit( files.children() ); | 592 | QListIterator<DocLnk> dit( files.children() ); |
593 | for ( ; dit.current(); ++dit ) { | 593 | for ( ; dit.current(); ++dit ) { |
594 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { | 594 | if( dit.current()->name() == audioView->currentItem()->text(0) && !insanityBool) { |
595 | insanityBool=TRUE; | 595 | insanityBool=TRUE; |
596 | return dit; | 596 | return dit; |
597 | } | 597 | } |
598 | } | 598 | } |
599 | } | 599 | } |
600 | break; | 600 | break; |
601 | case 2: // video | 601 | case 2: // video |
602 | { | 602 | { |
603 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 603 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
604 | for ( ; Vdit.current(); ++Vdit ) { | 604 | for ( ; Vdit.current(); ++Vdit ) { |
605 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { | 605 | if( Vdit.current()->name() == videoView->currentItem()->text(0) && !insanityBool) { |
606 | insanityBool=TRUE; | 606 | insanityBool=TRUE; |
607 | return Vdit; | 607 | return Vdit; |
608 | } | 608 | } |
609 | } | 609 | } |
610 | } | 610 | } |
611 | break; | 611 | break; |
612 | }; | 612 | }; |
613 | return 0; | 613 | return 0; |
614 | } | 614 | } |
615 | 615 | ||
616 | bool PlayListWidget::prev() { | 616 | bool PlayListWidget::prev() { |
617 | if ( mediaPlayerState->playlist() ) { | 617 | if ( mediaPlayerState->playlist() ) { |
618 | if ( mediaPlayerState->shuffled() ) { | 618 | if ( mediaPlayerState->shuffled() ) { |
619 | const DocLnk *cur = current(); | 619 | const DocLnk *cur = current(); |
620 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); | 620 | int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); |
621 | for ( int i = 0; i < j; i++ ) { | 621 | for ( int i = 0; i < j; i++ ) { |
622 | if ( !d->selectedFiles->next() ) | 622 | if ( !d->selectedFiles->next() ) |
623 | d->selectedFiles->first(); | 623 | d->selectedFiles->first(); |
624 | } | 624 | } |
625 | if ( cur == current() ) | 625 | if ( cur == current() ) |
626 | if ( !d->selectedFiles->next() ) | 626 | if ( !d->selectedFiles->next() ) |
627 | d->selectedFiles->first(); | 627 | d->selectedFiles->first(); |
628 | return TRUE; | 628 | return TRUE; |
629 | } else { | 629 | } else { |
630 | if ( !d->selectedFiles->prev() ) { | 630 | if ( !d->selectedFiles->prev() ) { |
631 | if ( mediaPlayerState->looping() ) { | 631 | if ( mediaPlayerState->looping() ) { |
632 | return d->selectedFiles->last(); | 632 | return d->selectedFiles->last(); |
633 | } else { | 633 | } else { |
634 | return FALSE; | 634 | return FALSE; |
635 | } | 635 | } |
636 | } | 636 | } |
637 | return TRUE; | 637 | return TRUE; |
638 | } | 638 | } |
639 | } else { | 639 | } else { |
640 | return mediaPlayerState->looping(); | 640 | return mediaPlayerState->looping(); |
641 | } | 641 | } |
642 | } | 642 | } |
643 | 643 | ||
644 | 644 | ||
645 | bool PlayListWidget::next() { | 645 | bool PlayListWidget::next() { |
646 | if ( mediaPlayerState->playlist() ) { | 646 | if ( mediaPlayerState->playlist() ) { |
647 | if ( mediaPlayerState->shuffled() ) { | 647 | if ( mediaPlayerState->shuffled() ) { |
648 | return prev(); | 648 | return prev(); |
649 | } else { | 649 | } else { |
650 | if ( !d->selectedFiles->next() ) { | 650 | if ( !d->selectedFiles->next() ) { |
651 | if ( mediaPlayerState->looping() ) { | 651 | if ( mediaPlayerState->looping() ) { |
652 | return d->selectedFiles->first(); | 652 | return d->selectedFiles->first(); |
653 | } else { | 653 | } else { |
654 | return FALSE; | 654 | return FALSE; |
655 | } | 655 | } |
656 | } | 656 | } |
657 | return TRUE; | 657 | return TRUE; |
658 | } | 658 | } |
659 | } else { | 659 | } else { |
660 | return mediaPlayerState->looping(); | 660 | return mediaPlayerState->looping(); |
661 | } | 661 | } |
662 | } | 662 | } |
663 | 663 | ||
664 | 664 | ||
665 | bool PlayListWidget::first() { | 665 | bool PlayListWidget::first() { |
666 | if ( mediaPlayerState->playlist() ) | 666 | if ( mediaPlayerState->playlist() ) |
667 | return d->selectedFiles->first(); | 667 | return d->selectedFiles->first(); |
668 | else | 668 | else |
669 | return mediaPlayerState->looping(); | 669 | return mediaPlayerState->looping(); |
670 | } | 670 | } |
671 | 671 | ||
672 | 672 | ||
673 | bool PlayListWidget::last() { | 673 | bool PlayListWidget::last() { |
674 | if ( mediaPlayerState->playlist() ) | 674 | if ( mediaPlayerState->playlist() ) |
675 | return d->selectedFiles->last(); | 675 | return d->selectedFiles->last(); |
676 | else | 676 | else |
677 | return mediaPlayerState->looping(); | 677 | return mediaPlayerState->looping(); |
678 | } | 678 | } |
679 | 679 | ||
680 | 680 | ||
681 | void PlayListWidget::saveList() { | 681 | void PlayListWidget::saveList() { |
682 | writem3u(); | 682 | writem3u(); |
683 | } | 683 | } |
684 | 684 | ||
685 | void PlayListWidget::loadList( const DocLnk & lnk) { | 685 | void PlayListWidget::loadList( const DocLnk & lnk) { |
686 | QString name = lnk.name(); | 686 | QString name = lnk.name(); |
687 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); | 687 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<<currentList is "+name); |
688 | 688 | ||
689 | if( name.length()>0) { | 689 | if( name.length()>0) { |
690 | setCaption("OpiePlayer: "+name); | 690 | setCaption("OpiePlayer: "+name); |
691 | // qDebug("<<<<<<<<<<<<load list "+ lnk.file()); | 691 | // qDebug("<<<<<<<<<<<<load list "+ lnk.file()); |
692 | clearList(); | 692 | clearList(); |
693 | readm3u(lnk.file()); | 693 | readm3u(lnk.file()); |
694 | tabWidget->setCurrentPage(0); | 694 | tabWidget->setCurrentPage(0); |
695 | } | 695 | } |
696 | } | 696 | } |
697 | 697 | ||
698 | void PlayListWidget::setPlaylist( bool shown ) { | 698 | void PlayListWidget::setPlaylist( bool shown ) { |
699 | if ( shown ) | 699 | if ( shown ) |
700 | d->playListFrame->show(); | 700 | d->playListFrame->show(); |
701 | else | 701 | else |
702 | d->playListFrame->hide(); | 702 | d->playListFrame->hide(); |
703 | } | 703 | } |
704 | 704 | ||
705 | void PlayListWidget::setView( char view ) { | 705 | void PlayListWidget::setView( char view ) { |
706 | if ( view == 'l' ) | 706 | if ( view == 'l' ) |
707 | showMaximized(); | 707 | showMaximized(); |
708 | else | 708 | else |
709 | hide(); | 709 | hide(); |
710 | } | 710 | } |
711 | 711 | ||
712 | void PlayListWidget::addSelected() { | 712 | void PlayListWidget::addSelected() { |
713 | DocLnk lnk; | 713 | DocLnk lnk; |
714 | QString filename; | 714 | QString filename; |
715 | switch (tabWidget->currentPageIndex()) { | 715 | switch (tabWidget->currentPageIndex()) { |
716 | 716 | ||
717 | case 0: //playlist | 717 | case 0: //playlist |
718 | return; | 718 | return; |
719 | break; | 719 | break; |
720 | case 1: { //audio | 720 | case 1: { //audio |
721 | QListViewItemIterator it( audioView ); | 721 | QListViewItemIterator it( audioView ); |
722 | for ( ; it.current(); ++it ) { | 722 | for ( ; it.current(); ++it ) { |
723 | if ( it.current()->isSelected() ) { | 723 | if ( it.current()->isSelected() ) { |
724 | filename = it.current()->text(3); | 724 | filename = it.current()->text(3); |
725 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 725 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
726 | lnk.setFile( filename ); //sets file name | 726 | lnk.setFile( filename ); //sets file name |
727 | d->selectedFiles->addToSelection( lnk); | 727 | d->selectedFiles->addToSelection( lnk); |
728 | } | 728 | } |
729 | } | 729 | } |
730 | audioView->clearSelection(); | 730 | audioView->clearSelection(); |
731 | // d->selectedFiles->next(); | 731 | // d->selectedFiles->next(); |
732 | } | 732 | } |
733 | break; | 733 | break; |
734 | 734 | ||
735 | case 2: { // video | 735 | case 2: { // video |
736 | QListViewItemIterator it( videoView ); | 736 | QListViewItemIterator it( videoView ); |
737 | for ( ; it.current(); ++it ) { | 737 | for ( ; it.current(); ++it ) { |
738 | if ( it.current()->isSelected() ) { | 738 | if ( it.current()->isSelected() ) { |
739 | 739 | ||
740 | filename = it.current()->text(3); | 740 | filename = it.current()->text(3); |
741 | lnk.setName( QFileInfo(filename).baseName() ); //sets name | 741 | lnk.setName( QFileInfo(filename).baseName() ); //sets name |
742 | lnk.setFile( filename ); //sets file name | 742 | lnk.setFile( filename ); //sets file name |
743 | d->selectedFiles->addToSelection( lnk); | 743 | d->selectedFiles->addToSelection( lnk); |
744 | } | 744 | } |
745 | } | 745 | } |
746 | videoView->clearSelection(); | 746 | videoView->clearSelection(); |
747 | } | 747 | } |
748 | break; | 748 | break; |
749 | }; | 749 | }; |
750 | // tabWidget->setCurrentPage(0); | 750 | // tabWidget->setCurrentPage(0); |
751 | writeCurrentM3u(); | 751 | writeCurrentM3u(); |
752 | 752 | ||
753 | } | 753 | } |
754 | 754 | ||
755 | void PlayListWidget::removeSelected() { | 755 | void PlayListWidget::removeSelected() { |
756 | d->selectedFiles->removeSelected( ); | 756 | d->selectedFiles->removeSelected( ); |
757 | } | 757 | } |
758 | 758 | ||
759 | void PlayListWidget::playIt( QListViewItem *) { | 759 | void PlayListWidget::playIt( QListViewItem *) { |
760 | // d->setDocumentUsed = FALSE; | 760 | // d->setDocumentUsed = FALSE; |
761 | // mediaPlayerState->curPosition =0; | 761 | // mediaPlayerState->curPosition =0; |
762 | // mediaPlayerState->setPlaying(FALSE); | 762 | // mediaPlayerState->setPlaying(FALSE); |
763 | mediaPlayerState->setPlaying(TRUE); | 763 | mediaPlayerState->setPlaying(TRUE); |
764 | d->selectedFiles->unSelect(); | 764 | d->selectedFiles->unSelect(); |
765 | } | 765 | } |
766 | 766 | ||
767 | void PlayListWidget::addToSelection( QListViewItem *it) { | 767 | void PlayListWidget::addToSelection( QListViewItem *it) { |
768 | d->setDocumentUsed = FALSE; | 768 | d->setDocumentUsed = FALSE; |
769 | 769 | ||
770 | if(it) { | 770 | if(it) { |
771 | switch ( tabWidget->currentPageIndex()) { | 771 | switch ( tabWidget->currentPageIndex()) { |
772 | case 0: //playlist | 772 | case 0: //playlist |
773 | return; | 773 | return; |
774 | break; | 774 | break; |
775 | }; | 775 | }; |
776 | // case 1: { | 776 | // case 1: { |
777 | DocLnk lnk; | 777 | DocLnk lnk; |
778 | QString filename; | 778 | QString filename; |
779 | 779 | ||
780 | filename=it->text(3); | 780 | filename=it->text(3); |
781 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name | 781 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name |
782 | lnk.setFile( filename ); //sets file name | 782 | lnk.setFile( filename ); //sets file name |
783 | d->selectedFiles->addToSelection( lnk); | 783 | d->selectedFiles->addToSelection( lnk); |
784 | 784 | ||
785 | if(tabWidget->currentPageIndex() == 0) | 785 | if(tabWidget->currentPageIndex() == 0) |
786 | writeCurrentM3u(); | 786 | writeCurrentM3u(); |
787 | // tabWidget->setCurrentPage(0); | 787 | // tabWidget->setCurrentPage(0); |
788 | 788 | ||
789 | } | 789 | } |
790 | } | 790 | } |
791 | 791 | ||
792 | void PlayListWidget::tabChanged(QWidget *) { | 792 | void PlayListWidget::tabChanged(QWidget *) { |
793 | 793 | ||
794 | switch ( tabWidget->currentPageIndex()) { | 794 | switch ( tabWidget->currentPageIndex()) { |
795 | case 0: | 795 | case 0: |
796 | { | 796 | { |
797 | if( !tbDeletePlaylist->isHidden()) | 797 | if( !tbDeletePlaylist->isHidden()) |
798 | tbDeletePlaylist->hide(); | 798 | tbDeletePlaylist->hide(); |
799 | d->tbRemoveFromList->setEnabled(TRUE); | 799 | d->tbRemoveFromList->setEnabled(TRUE); |
800 | d->tbAddToList->setEnabled(FALSE); | 800 | d->tbAddToList->setEnabled(FALSE); |
801 | } | 801 | } |
802 | break; | 802 | break; |
803 | case 1: | 803 | case 1: |
804 | { | 804 | { |
805 | audioView->clear(); | 805 | audioView->clear(); |
806 | populateAudioView(); | 806 | populateAudioView(); |
807 | 807 | ||
808 | if( !tbDeletePlaylist->isHidden()) | 808 | if( !tbDeletePlaylist->isHidden()) |
809 | tbDeletePlaylist->hide(); | 809 | tbDeletePlaylist->hide(); |
810 | d->tbRemoveFromList->setEnabled(FALSE); | 810 | d->tbRemoveFromList->setEnabled(FALSE); |
811 | d->tbAddToList->setEnabled(TRUE); | 811 | d->tbAddToList->setEnabled(TRUE); |
812 | } | 812 | } |
813 | break; | 813 | break; |
814 | case 2: | 814 | case 2: |
815 | { | 815 | { |
816 | videoView->clear(); | 816 | videoView->clear(); |
817 | populateVideoView(); | 817 | populateVideoView(); |
818 | if( !tbDeletePlaylist->isHidden()) | 818 | if( !tbDeletePlaylist->isHidden()) |
819 | tbDeletePlaylist->hide(); | 819 | tbDeletePlaylist->hide(); |
820 | d->tbRemoveFromList->setEnabled(FALSE); | 820 | d->tbRemoveFromList->setEnabled(FALSE); |
821 | d->tbAddToList->setEnabled(TRUE); | 821 | d->tbAddToList->setEnabled(TRUE); |
822 | } | 822 | } |
823 | break; | 823 | break; |
824 | case 3: | 824 | case 3: |
825 | { | 825 | { |
826 | if( tbDeletePlaylist->isHidden()) | 826 | if( tbDeletePlaylist->isHidden()) |
827 | tbDeletePlaylist->show(); | 827 | tbDeletePlaylist->show(); |
828 | playLists->reread(); | 828 | playLists->reread(); |
829 | } | 829 | } |
830 | break; | 830 | break; |
831 | }; | 831 | }; |
832 | } | 832 | } |
833 | 833 | ||
834 | void PlayListWidget::btnPlay(bool b) { | 834 | void PlayListWidget::btnPlay(bool b) { |
835 | // mediaPlayerState->setPlaying(b); | 835 | // mediaPlayerState->setPlaying(b); |
836 | switch ( tabWidget->currentPageIndex()) { | 836 | switch ( tabWidget->currentPageIndex()) { |
837 | case 0: | 837 | case 0: |
838 | { | 838 | { |
839 | // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 | 839 | // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 |
840 | // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { | 840 | // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { |
841 | // QMessageBox::message("Note","You are trying to play\na malformed url."); | 841 | // QMessageBox::message("Note","You are trying to play\na malformed url."); |
842 | // } else { | 842 | // } else { |
843 | mediaPlayerState->setPlaying(b); | 843 | mediaPlayerState->setPlaying(b); |
844 | insanityBool=FALSE; | 844 | insanityBool=FALSE; |
845 | qDebug("insanity"); | 845 | qDebug("insanity"); |
846 | // } | 846 | // } |
847 | } | 847 | } |
848 | break; | 848 | break; |
849 | case 1: | 849 | case 1: |
850 | { | 850 | { |
851 | // d->selectedFiles->unSelect(); | 851 | // d->selectedFiles->unSelect(); |
852 | addToSelection( audioView->currentItem() ); | 852 | addToSelection( audioView->currentItem() ); |
853 | mediaPlayerState->setPlaying( b); | 853 | mediaPlayerState->setPlaying( b); |
854 | d->selectedFiles->removeSelected( ); | 854 | d->selectedFiles->removeSelected( ); |
855 | d->selectedFiles->unSelect(); | 855 | d->selectedFiles->unSelect(); |
856 | tabWidget->setCurrentPage(1); | 856 | tabWidget->setCurrentPage(1); |
857 | insanityBool=FALSE; | 857 | insanityBool=FALSE; |
858 | }// audioView->clearSelection(); | 858 | }// audioView->clearSelection(); |
859 | break; | 859 | break; |
860 | case 2: | 860 | case 2: |
861 | { | 861 | { |
862 | 862 | ||
863 | addToSelection( videoView->currentItem() ); | 863 | addToSelection( videoView->currentItem() ); |
864 | mediaPlayerState->setPlaying( b); | 864 | mediaPlayerState->setPlaying( b); |
865 | // qApp->processEvents(); | 865 | // qApp->processEvents(); |
866 | d->selectedFiles->removeSelected( ); | 866 | d->selectedFiles->removeSelected( ); |
867 | d->selectedFiles->unSelect(); | 867 | d->selectedFiles->unSelect(); |
868 | tabWidget->setCurrentPage(2); | 868 | tabWidget->setCurrentPage(2); |
869 | insanityBool=FALSE; | 869 | insanityBool=FALSE; |
870 | }// videoView->clearSelection(); | 870 | }// videoView->clearSelection(); |
871 | break; | 871 | break; |
872 | }; | 872 | }; |
873 | 873 | ||
874 | } | 874 | } |
875 | 875 | ||
876 | void PlayListWidget::deletePlaylist() { | 876 | void PlayListWidget::deletePlaylist() { |
877 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), | 877 | switch( QMessageBox::information( this, (tr("Remove Playlist?")), |
878 | (tr("You really want to delete\nthis playlist?")), | 878 | (tr("You really want to delete\nthis playlist?")), |
879 | (tr("Yes")), (tr("No")), 0 )){ | 879 | (tr("Yes")), (tr("No")), 0 )){ |
880 | case 0: // Yes clicked, | 880 | case 0: // Yes clicked, |
881 | QFile().remove(playLists->selectedDocument().file()); | 881 | QFile().remove(playLists->selectedDocument().file()); |
882 | QFile().remove(playLists->selectedDocument().linkFile()); | 882 | QFile().remove(playLists->selectedDocument().linkFile()); |
883 | playLists->reread(); | 883 | playLists->reread(); |
884 | break; | 884 | break; |
885 | case 1: // Cancel | 885 | case 1: // Cancel |
886 | break; | 886 | break; |
887 | }; | 887 | }; |
888 | } | 888 | } |
889 | 889 | ||
890 | void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint&, int ) | 890 | void PlayListWidget::viewPressed( int mouse, QListViewItem *, const QPoint&, int ) |
891 | { | 891 | { |
892 | switch (mouse) { | 892 | switch (mouse) { |
893 | case 1: | 893 | case 1: |
894 | break; | 894 | break; |
895 | case 2:{ | 895 | case 2:{ |
896 | 896 | ||
897 | QPopupMenu m; | 897 | QPopupMenu m; |
898 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); | 898 | m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); |
899 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); | 899 | m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); |
900 | m.insertSeparator(); | 900 | m.insertSeparator(); |
901 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) | 901 | if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) |
902 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | 902 | m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); |
903 | 903 | ||
904 | m.exec( QCursor::pos() ); | 904 | m.exec( QCursor::pos() ); |
905 | } | 905 | } |
906 | break; | 906 | break; |
907 | }; | 907 | }; |
908 | } | 908 | } |
909 | 909 | ||
910 | void PlayListWidget::playSelected() | 910 | void PlayListWidget::playSelected() |
911 | { | 911 | { |
912 | btnPlay( true); | 912 | btnPlay( true); |
913 | // d->selectedFiles->unSelect(); | 913 | // d->selectedFiles->unSelect(); |
914 | } | 914 | } |
915 | 915 | ||
916 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint&, int) | 916 | void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *, const QPoint&, int) |
917 | { | 917 | { |
918 | switch (mouse) { | 918 | switch (mouse) { |
919 | case 1: | 919 | case 1: |
920 | 920 | ||
921 | break; | 921 | break; |
922 | case 2:{ | 922 | case 2:{ |
923 | QPopupMenu m; | 923 | QPopupMenu m; |
924 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); | 924 | m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); |
925 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); | 925 | m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); |
926 | // m.insertSeparator(); | 926 | // m.insertSeparator(); |
927 | // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); | 927 | // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); |
928 | m.exec( QCursor::pos() ); | 928 | m.exec( QCursor::pos() ); |
929 | } | 929 | } |
930 | break; | 930 | break; |
931 | }; | 931 | }; |
932 | 932 | ||
933 | } | 933 | } |
934 | 934 | ||
935 | void PlayListWidget::listDelete() { | 935 | void PlayListWidget::listDelete() { |
936 | Config cfg( "OpiePlayer" ); | 936 | Config cfg( "OpiePlayer" ); |
937 | cfg.setGroup("PlayList"); | 937 | cfg.setGroup("PlayList"); |
938 | currentPlayList = cfg.readEntry("CurrentPlaylist",""); | 938 | currentPlayList = cfg.readEntry("CurrentPlaylist",""); |
939 | QString file; | 939 | QString file; |
940 | // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 940 | // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
941 | switch ( tabWidget->currentPageIndex()) { | 941 | switch ( tabWidget->currentPageIndex()) { |
942 | case 0: | 942 | case 0: |
943 | break; | 943 | break; |
944 | case 1: | 944 | case 1: |
945 | { | 945 | { |
946 | file = audioView->currentItem()->text(0); | 946 | file = audioView->currentItem()->text(0); |
947 | QListIterator<DocLnk> Pdit( files.children() ); | 947 | QListIterator<DocLnk> Pdit( files.children() ); |
948 | for ( ; Pdit.current(); ++Pdit ) { | 948 | for ( ; Pdit.current(); ++Pdit ) { |
949 | if( Pdit.current()->name() == file) { | 949 | if( Pdit.current()->name() == file) { |
950 | LnkProperties prop( Pdit.current() ); | 950 | LnkProperties prop( Pdit.current() ); |
951 | prop.showMaximized(); | 951 | prop.showMaximized(); |
952 | prop.exec(); | 952 | prop.exec(); |
953 | } | 953 | } |
954 | } | 954 | } |
955 | populateAudioView(); | 955 | populateAudioView(); |
956 | } | 956 | } |
957 | break; | 957 | break; |
958 | case 2: | 958 | case 2: |
959 | { | 959 | { |
960 | // file = videoView->selectedItem()->text(0); | 960 | // file = videoView->selectedItem()->text(0); |
961 | // for ( int i = 0; i < noOfFiles; i++ ) { | 961 | // for ( int i = 0; i < noOfFiles; i++ ) { |
962 | // QString entryName; | 962 | // QString entryName; |
963 | // entryName.sprintf( "File%i", i + 1 ); | 963 | // entryName.sprintf( "File%i", i + 1 ); |
964 | // QString linkFile = cfg.readEntry( entryName ); | 964 | // QString linkFile = cfg.readEntry( entryName ); |
965 | // AppLnk lnk( AppLnk(linkFile)); | 965 | // AppLnk lnk( AppLnk(linkFile)); |
966 | // if( lnk.name() == file ) { | 966 | // if( lnk.name() == file ) { |
967 | // LnkProperties prop( &lnk); | 967 | // LnkProperties prop( &lnk); |
968 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); | 968 | // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); |
969 | // prop.showMaximized(); | 969 | // prop.showMaximized(); |
970 | // prop.exec(); | 970 | // prop.exec(); |
971 | // } | 971 | // } |
972 | // } | 972 | // } |
973 | } | 973 | } |
974 | break; | 974 | break; |
975 | }; | 975 | }; |
976 | } | 976 | } |
977 | 977 | ||
978 | void PlayListWidget::scanForAudio() { | 978 | void PlayListWidget::scanForAudio() { |
979 | // qDebug("scan for audio"); | 979 | // qDebug("scan for audio"); |
980 | files.detachChildren(); | 980 | files.detachChildren(); |
981 | QListIterator<DocLnk> sdit( files.children() ); | 981 | QListIterator<DocLnk> sdit( files.children() ); |
982 | for ( ; sdit.current(); ++sdit ) { | 982 | for ( ; sdit.current(); ++sdit ) { |
983 | delete sdit.current(); | 983 | delete sdit.current(); |
984 | } | 984 | } |
985 | Global::findDocuments( &files, audioMimes); | 985 | Global::findDocuments( &files, audioMimes); |
986 | audioScan = true; | 986 | audioScan = true; |
987 | } | 987 | } |
988 | void PlayListWidget::scanForVideo() { | 988 | void PlayListWidget::scanForVideo() { |
989 | // qDebug("scan for video"); | 989 | // qDebug("scan for video"); |
990 | vFiles.detachChildren(); | 990 | vFiles.detachChildren(); |
991 | QListIterator<DocLnk> sdit( vFiles.children() ); | 991 | QListIterator<DocLnk> sdit( vFiles.children() ); |
992 | for ( ; sdit.current(); ++sdit ) { | 992 | for ( ; sdit.current(); ++sdit ) { |
993 | delete sdit.current(); | 993 | delete sdit.current(); |
994 | } | 994 | } |
995 | Global::findDocuments(&vFiles, "video/*"); | 995 | Global::findDocuments(&vFiles, "video/*"); |
996 | videoScan = true; | 996 | videoScan = true; |
997 | } | 997 | } |
998 | 998 | ||
999 | void PlayListWidget::populateAudioView() { | 999 | void PlayListWidget::populateAudioView() { |
1000 | 1000 | ||
1001 | audioView->clear(); | 1001 | audioView->clear(); |
1002 | StorageInfo storageInfo; | 1002 | StorageInfo storageInfo; |
1003 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1003 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1004 | if(!audioScan) scanForAudio(); | 1004 | if(!audioScan) scanForAudio(); |
1005 | 1005 | ||
1006 | QListIterator<DocLnk> dit( files.children() ); | 1006 | QListIterator<DocLnk> dit( files.children() ); |
1007 | QListIterator<FileSystem> it ( fs ); | 1007 | QListIterator<FileSystem> it ( fs ); |
1008 | 1008 | ||
1009 | QString storage; | 1009 | QString storage; |
1010 | for ( ; dit.current(); ++dit ) { | 1010 | for ( ; dit.current(); ++dit ) { |
1011 | for( ; it.current(); ++it ){ | 1011 | for( ; it.current(); ++it ){ |
1012 | const QString name = (*it)->name(); | 1012 | const QString name = (*it)->name(); |
1013 | const QString path = (*it)->path(); | 1013 | const QString path = (*it)->path(); |
1014 | if(dit.current()->file().find(path) != -1 ) storage=name; | 1014 | if(dit.current()->file().find(path) != -1 ) storage=name; |
1015 | } | 1015 | } |
1016 | 1016 | ||
1017 | QListViewItem * newItem; | 1017 | QListViewItem * newItem; |
1018 | if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { | 1018 | if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { |
1019 | long size; | 1019 | long size; |
1020 | if( dit.current()->file().left(4) == "http" ) | 1020 | if( dit.current()->file().left(4) == "http" ) |
1021 | size=0; | 1021 | size=0; |
1022 | else | 1022 | else |
1023 | size = QFile( dit.current()->file() ).size(); | 1023 | size = QFile( dit.current()->file() ).size(); |
1024 | // qDebug(dit.current()->name()); | 1024 | // qDebug(dit.current()->name()); |
1025 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), | 1025 | newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), |
1026 | QString::number(size ), storage, dit.current()->file()); | 1026 | QString::number(size ), storage, dit.current()->file()); |
1027 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); | 1027 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); |
1028 | } | 1028 | } |
1029 | } | 1029 | } |
1030 | 1030 | ||
1031 | } | 1031 | } |
1032 | 1032 | ||
1033 | void PlayListWidget::populateVideoView() { | 1033 | void PlayListWidget::populateVideoView() { |
1034 | videoView->clear(); | 1034 | videoView->clear(); |
1035 | StorageInfo storageInfo; | 1035 | StorageInfo storageInfo; |
1036 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 1036 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
1037 | 1037 | ||
1038 | if(!videoScan ) scanForVideo(); | 1038 | if(!videoScan ) scanForVideo(); |
1039 | 1039 | ||
1040 | QListIterator<DocLnk> Vdit( vFiles.children() ); | 1040 | QListIterator<DocLnk> Vdit( vFiles.children() ); |
1041 | QListIterator<FileSystem> it ( fs ); | 1041 | QListIterator<FileSystem> it ( fs ); |
1042 | videoView->clear(); | 1042 | videoView->clear(); |
1043 | QString storage; | 1043 | QString storage; |
1044 | for ( ; Vdit.current(); ++Vdit ) { | 1044 | for ( ; Vdit.current(); ++Vdit ) { |
1045 | for( ; it.current(); ++it ){ | 1045 | for( ; it.current(); ++it ){ |
1046 | const QString name = (*it)->name(); | 1046 | const QString name = (*it)->name(); |
1047 | const QString path = (*it)->path(); | 1047 | const QString path = (*it)->path(); |
1048 | if( Vdit.current()->file().find(path) != -1 ) storage=name; | 1048 | if( Vdit.current()->file().find(path) != -1 ) storage=name; |
1049 | } | 1049 | } |
1050 | 1050 | ||
1051 | QListViewItem * newItem; | 1051 | QListViewItem * newItem; |
1052 | if ( QFile( Vdit.current()->file()).exists() ) { | 1052 | if ( QFile( Vdit.current()->file()).exists() ) { |
1053 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), | 1053 | newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), |
1054 | QString::number( QFile( Vdit.current()->file() ).size() ), | 1054 | QString::number( QFile( Vdit.current()->file() ).size() ), |
1055 | storage, Vdit.current()->file()); | 1055 | storage, Vdit.current()->file()); |
1056 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); | 1056 | newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); |
1057 | } | 1057 | } |
1058 | } | 1058 | } |
1059 | } | 1059 | } |
1060 | 1060 | ||
1061 | void PlayListWidget::openFile() { | 1061 | void PlayListWidget::openFile() { |
1062 | QString filename, name; | 1062 | QString filename, name; |
1063 | InputDialog *fileDlg; | 1063 | InputDialog *fileDlg; |
1064 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); | 1064 | fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); |
1065 | fileDlg->exec(); | 1065 | fileDlg->exec(); |
1066 | if( fileDlg->result() == 1 ) { | 1066 | if( fileDlg->result() == 1 ) { |
1067 | filename = fileDlg->text(); | 1067 | filename = fileDlg->text(); |
1068 | // qDebug( "Selected filename is " + filename ); | 1068 | // qDebug( "Selected filename is " + filename ); |
1069 | DocLnk lnk; | 1069 | DocLnk lnk; |
1070 | Config cfg( "OpiePlayer" ); | 1070 | Config cfg( "OpiePlayer" ); |
1071 | cfg.setGroup("PlayList"); | 1071 | cfg.setGroup("PlayList"); |
1072 | 1072 | ||
1073 | QString m3uFile; | 1073 | QString m3uFile; |
1074 | m3uFile = filename; | 1074 | m3uFile = filename; |
1075 | if(filename.left(4) == "http") { | 1075 | if(filename.left(4) == "http") { |
1076 | if(filename.find(":",8,TRUE) != -1) { //found a port | 1076 | if(filename.find(":",8,TRUE) != -1) { //found a port |
1077 | 1077 | ||
1078 | m3uFile = filename; | 1078 | m3uFile = filename; |
1079 | if( m3uFile.right( 1 ).find( '/' ) == -1) { | 1079 | if( m3uFile.right( 1 ).find( '/' ) == -1) { |
1080 | m3uFile += "/"; | 1080 | m3uFile += "/"; |
1081 | } | 1081 | } |
1082 | filename = m3uFile; | 1082 | filename = m3uFile; |
1083 | } | 1083 | } |
1084 | lnk.setName( m3uFile ); //sets name | 1084 | lnk.setName( m3uFile ); //sets name |
1085 | lnk.setFile( filename ); //sets file name | 1085 | lnk.setFile( filename ); //sets file name |
1086 | lnk.setIcon("opieplayer2/musicfile"); | 1086 | lnk.setIcon("opieplayer2/musicfile"); |
1087 | d->selectedFiles->addToSelection( lnk ); | 1087 | d->selectedFiles->addToSelection( lnk ); |
1088 | writeCurrentM3u(); | 1088 | writeCurrentM3u(); |
1089 | } | 1089 | } |
1090 | else if( filename.right( 3) == "m3u" ) { | 1090 | else if( filename.right( 3) == "m3u" ) { |
1091 | readm3u( filename ); | 1091 | readm3u( filename ); |
1092 | 1092 | ||
1093 | } else if( filename.right(3) == "pls" ) { | 1093 | } else if( filename.right(3) == "pls" ) { |
1094 | readPls( filename ); | 1094 | readPls( filename ); |
1095 | } else { | 1095 | } else { |
1096 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name | 1096 | lnk.setName( fullBaseName ( QFileInfo(filename)) ); //sets name |
1097 | lnk.setFile( filename ); //sets file name | 1097 | lnk.setFile( filename ); //sets file name |
1098 | d->selectedFiles->addToSelection( lnk); | 1098 | d->selectedFiles->addToSelection( lnk); |
1099 | lnk.removeLinkFile(); | 1099 | lnk.removeLinkFile(); |
1100 | writeCurrentM3u(); | 1100 | writeCurrentM3u(); |
1101 | } | 1101 | } |
1102 | } | 1102 | } |
1103 | 1103 | ||
1104 | if( fileDlg ) { | 1104 | if( fileDlg ) { |
1105 | delete fileDlg; | 1105 | delete fileDlg; |
1106 | } | 1106 | } |
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | 1109 | ||
1110 | /* | 1110 | /* |
1111 | reads m3u and shows files/urls to playlist widget */ | 1111 | reads m3u and shows files/urls to playlist widget */ |
1112 | void PlayListWidget::readm3u( const QString &filename ) { | 1112 | void PlayListWidget::readm3u( const QString &filename ) { |
1113 | // qDebug( "read m3u filename " + filename ); | 1113 | // qDebug( "read m3u filename " + filename ); |
1114 | 1114 | ||
1115 | Om3u *m3uList; | 1115 | Om3u *m3uList; |
1116 | QString s, name; | 1116 | QString s, name; |
1117 | m3uList = new Om3u( filename, IO_ReadOnly ); | 1117 | m3uList = new Om3u( filename, IO_ReadOnly ); |
1118 | m3uList->readM3u(); | 1118 | m3uList->readM3u(); |
1119 | DocLnk lnk; | 1119 | DocLnk lnk; |
1120 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 1120 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
1121 | s = *it; | 1121 | s = *it; |
1122 | // qDebug("reading "+ s); | 1122 | // qDebug("reading "+ s); |
1123 | if(s.left(4)=="http") { | 1123 | if(s.left(4)=="http") { |
1124 | lnk.setName( s ); //sets file name | 1124 | lnk.setName( s ); //sets file name |
1125 | lnk.setIcon("opieplayer2/musicfile"); | 1125 | lnk.setIcon("opieplayer2/musicfile"); |
1126 | 1126 | ||
1127 | // if(s.right(4) != '.' || s.right(5) != '.') | 1127 | // if(s.right(4) != '.' || s.right(5) != '.') |
1128 | if(s.right(4) != '.' || s.right(5) != '.' ) | 1128 | if(s.right(4) != '.' || s.right(5) != '.' ) |
1129 | if( s.right(1) != "/") | 1129 | if( s.right(1) != "/") |
1130 | lnk.setFile( s+"/"); //if url with no extension | 1130 | lnk.setFile( s+"/"); //if url with no extension |
1131 | else | 1131 | else |
1132 | lnk.setFile( s ); //sets file name | 1132 | lnk.setFile( s ); //sets file name |
1133 | 1133 | ||
1134 | } else { | 1134 | } else { |
1135 | // if( QFileInfo( s ).exists() ) { | 1135 | // if( QFileInfo( s ).exists() ) { |
1136 | lnk.setName( fullBaseName ( QFileInfo(s))); | 1136 | lnk.setName( fullBaseName ( QFileInfo(s))); |
1137 | // if(s.right(4) == '.') {//if regular file | 1137 | // if(s.right(4) == '.') {//if regular file |
1138 | if(s.left(1) != "/") { | 1138 | if(s.left(1) != "/") { |
1139 | // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); | 1139 | // qDebug("set link "+QFileInfo(filename).dirPath()+"/"+s); |
1140 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); | 1140 | lnk.setFile( QFileInfo(filename).dirPath()+"/"+s); |
1141 | lnk.setIcon("SoundPlayer"); | 1141 | lnk.setIcon("SoundPlayer"); |
1142 | } else { | 1142 | } else { |
1143 | // qDebug("set link2 "+s); | 1143 | // qDebug("set link2 "+s); |
1144 | lnk.setFile( s); | 1144 | lnk.setFile( s); |
1145 | lnk.setIcon("SoundPlayer"); | 1145 | lnk.setIcon("SoundPlayer"); |
1146 | } | 1146 | } |
1147 | } | 1147 | } |
1148 | d->selectedFiles->addToSelection( lnk ); | 1148 | d->selectedFiles->addToSelection( lnk ); |
1149 | } | 1149 | } |
1150 | Config config( "OpiePlayer" ); | 1150 | Config config( "OpiePlayer" ); |
1151 | config.setGroup( "PlayList" ); | 1151 | config.setGroup( "PlayList" ); |
1152 | 1152 | ||
1153 | config.writeEntry("CurrentPlaylist",filename); | 1153 | config.writeEntry("CurrentPlaylist",filename); |
1154 | config.write(); | 1154 | config.write(); |
1155 | currentPlayList=filename; | 1155 | currentPlayList=filename; |
1156 | 1156 | ||
1157 | // m3uList->write(); | 1157 | // m3uList->write(); |
1158 | m3uList->close(); | 1158 | m3uList->close(); |
1159 | if(m3uList) delete m3uList; | 1159 | if(m3uList) delete m3uList; |
1160 | 1160 | ||
1161 | d->selectedFiles->setSelectedItem( s); | 1161 | d->selectedFiles->setSelectedItem( s); |
1162 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); | 1162 | setCaption(tr("OpiePlayer: ")+ fullBaseName ( QFileInfo(filename))); |
1163 | 1163 | ||
1164 | } | 1164 | } |
1165 | 1165 | ||
1166 | /* | 1166 | /* |
1167 | reads pls and adds files/urls to playlist */ | 1167 | reads pls and adds files/urls to playlist */ |
1168 | void PlayListWidget::readPls( const QString &filename ) { | 1168 | void PlayListWidget::readPls( const QString &filename ) { |
1169 | 1169 | ||
1170 | // qDebug( "pls filename is " + filename ); | 1170 | // qDebug( "pls filename is " + filename ); |
1171 | Om3u *m3uList; | 1171 | Om3u *m3uList; |
1172 | QString s, name; | 1172 | QString s, name; |
1173 | m3uList = new Om3u( filename, IO_ReadOnly ); | 1173 | m3uList = new Om3u( filename, IO_ReadOnly ); |
1174 | m3uList->readPls(); | 1174 | m3uList->readPls(); |
1175 | 1175 | ||
1176 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { | 1176 | for ( QStringList::ConstIterator it = m3uList->begin(); it != m3uList->end(); ++it ) { |
1177 | s = *it; | 1177 | s = *it; |
1178 | // s.replace( QRegExp( "%20" )," " ); | 1178 | // s.replace( QRegExp( "%20" )," " ); |
1179 | DocLnk lnk( s ); | 1179 | DocLnk lnk( s ); |
1180 | QFileInfo f( s ); | 1180 | QFileInfo f( s ); |
1181 | QString name = fullBaseName ( f); | 1181 | QString name = fullBaseName ( f); |
1182 | 1182 | ||
1183 | if( name.left( 4 ) == "http" ) { | 1183 | if( name.left( 4 ) == "http" ) { |
1184 | name = s.right( s.length() - 7); | 1184 | name = s.right( s.length() - 7); |
1185 | } else { | 1185 | } else { |
1186 | name = s; | 1186 | name = s; |
1187 | } | 1187 | } |
1188 | 1188 | ||
1189 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); | 1189 | name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); |
1190 | 1190 | ||
1191 | lnk.setName( name ); | 1191 | lnk.setName( name ); |
1192 | if( s.at( s.length() - 4) == '.') {// if this is probably a file | 1192 | if( s.at( s.length() - 4) == '.') {// if this is probably a file |
1193 | lnk.setFile( s ); | 1193 | lnk.setFile( s ); |
1194 | } else { //if its a url | 1194 | } else { //if its a url |
1195 | if( name.right( 1 ).find( '/' ) == -1) { | 1195 | if( name.right( 1 ).find( '/' ) == -1) { |
1196 | s += "/"; | 1196 | s += "/"; |
1197 | } | 1197 | } |
1198 | lnk.setFile( s ); | 1198 | lnk.setFile( s ); |
1199 | } | 1199 | } |
1200 | lnk.setType( "audio/x-mpegurl" ); | 1200 | lnk.setType( "audio/x-mpegurl" ); |
1201 | 1201 | ||
1202 | lnk.writeLink(); | 1202 | lnk.writeLink(); |
1203 | d->selectedFiles->addToSelection( lnk ); | 1203 | d->selectedFiles->addToSelection( lnk ); |
1204 | } | 1204 | } |
1205 | 1205 | ||
1206 | m3uList->close(); | 1206 | m3uList->close(); |
1207 | if(m3uList) delete m3uList; | 1207 | if(m3uList) delete m3uList; |
1208 | } | 1208 | } |
1209 | 1209 | ||
1210 | /* | 1210 | /* |
1211 | writes current playlist to current m3u file */ | 1211 | writes current playlist to current m3u file */ |
1212 | void PlayListWidget::writeCurrentM3u() { | 1212 | void PlayListWidget::writeCurrentM3u() { |
1213 | // qDebug("writing to current m3u"); | 1213 | // qDebug("writing to current m3u"); |
1214 | Config cfg( "OpiePlayer" ); | 1214 | Config cfg( "OpiePlayer" ); |
1215 | cfg.setGroup("PlayList"); | 1215 | cfg.setGroup("PlayList"); |
1216 | currentPlayList = cfg.readEntry("CurrentPlaylist",""); | 1216 | currentPlayList = cfg.readEntry("CurrentPlaylist",""); |
1217 | Om3u *m3uList; | 1217 | Om3u *m3uList; |
1218 | m3uList = new Om3u( currentPlayList, IO_ReadWrite | IO_Truncate ); | 1218 | m3uList = new Om3u( currentPlayList, IO_ReadWrite | IO_Truncate ); |
1219 | 1219 | ||
1220 | if( d->selectedFiles->first()) { | 1220 | if( d->selectedFiles->first()) { |
1221 | do { | 1221 | do { |
1222 | // qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file()); | 1222 | // qDebug( "writeCurrentM3u " +d->selectedFiles->current()->file()); |
1223 | m3uList->add( d->selectedFiles->current()->file() ); | 1223 | m3uList->add( d->selectedFiles->current()->file() ); |
1224 | } | 1224 | } |
1225 | while ( d->selectedFiles->next() ); | 1225 | while ( d->selectedFiles->next() ); |
1226 | // qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); | 1226 | // qDebug( "<<<<<<<<<<<<>>>>>>>>>>>>>>>>>" ); |
1227 | m3uList->write(); | 1227 | m3uList->write(); |
1228 | m3uList->close(); | 1228 | m3uList->close(); |
1229 | 1229 | ||
1230 | if(m3uList) delete m3uList; | 1230 | if(m3uList) delete m3uList; |
1231 | } | 1231 | } |
1232 | } | 1232 | } |
1233 | 1233 | ||
1234 | /* | 1234 | /* |
1235 | writes current playlist to m3u file */ | 1235 | writes current playlist to m3u file */ |
1236 | void PlayListWidget::writem3u() { | 1236 | void PlayListWidget::writem3u() { |
1237 | InputDialog *fileDlg; | 1237 | InputDialog *fileDlg; |
1238 | fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); | 1238 | fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); |
1239 | fileDlg->exec(); | 1239 | fileDlg->exec(); |
1240 | QString name, filename, list; | 1240 | QString name, filename, list; |
1241 | Om3u *m3uList; | 1241 | Om3u *m3uList; |
1242 | 1242 | ||
1243 | if( fileDlg->result() == 1 ) { | 1243 | if( fileDlg->result() == 1 ) { |
1244 | name = fileDlg->text(); | 1244 | name = fileDlg->text(); |
1245 | // qDebug( filename ); | 1245 | // qDebug( filename ); |
1246 | if( name.find("/",0,true) != -1) {// assume they specify a file path | 1246 | if( name.find("/",0,true) != -1) {// assume they specify a file path |
1247 | filename = name; | 1247 | filename = name; |
1248 | name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); | 1248 | name = name.right(name.length()- name.findRev("/",-1,true) - 1 ); |
1249 | } | 1249 | } |
1250 | else //otherwise dump it somewhere noticable | 1250 | else //otherwise dump it somewhere noticable |
1251 | filename = QPEApplication::documentDir() + "/" + name; | 1251 | filename = QPEApplication::documentDir() + "/" + name; |
1252 | 1252 | ||
1253 | if( filename.right( 3 ) != "m3u" ) //needs filename extension | 1253 | if( filename.right( 3 ) != "m3u" ) //needs filename extension |
1254 | filename += ".m3u"; | 1254 | filename += ".m3u"; |
1255 | 1255 | ||
1256 | if( d->selectedFiles->first()) { | 1256 | if( d->selectedFiles->first()) { |
1257 | m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); | 1257 | m3uList = new Om3u(filename, IO_ReadWrite | IO_Truncate); |
1258 | 1258 | ||
1259 | do { | 1259 | do { |
1260 | m3uList->add( d->selectedFiles->current()->file()); | 1260 | m3uList->add( d->selectedFiles->current()->file()); |
1261 | } | 1261 | } |
1262 | while ( d->selectedFiles->next() ); | 1262 | while ( d->selectedFiles->next() ); |
1263 | // qDebug( list ); | 1263 | // qDebug( list ); |
1264 | m3uList->write(); | 1264 | m3uList->write(); |
1265 | m3uList->close(); | 1265 | m3uList->close(); |
1266 | if(m3uList) delete m3uList; | 1266 | if(m3uList) delete m3uList; |
1267 | 1267 | ||
1268 | if(fileDlg) delete fileDlg; | 1268 | if(fileDlg) delete fileDlg; |
1269 | 1269 | ||
1270 | DocLnk lnk; | 1270 | DocLnk lnk; |
1271 | lnk.setFile( filename); | 1271 | lnk.setFile( filename); |
1272 | lnk.setIcon("opieplayer2/playlist2"); | 1272 | lnk.setIcon("opieplayer2/playlist2"); |
1273 | lnk.setName( name); //sets file name | 1273 | lnk.setName( name); //sets file name |
1274 | 1274 | ||
1275 | // qDebug(filename); | 1275 | // qDebug(filename); |
1276 | Config config( "OpiePlayer" ); | 1276 | Config config( "OpiePlayer" ); |
1277 | config.setGroup( "PlayList" ); | 1277 | config.setGroup( "PlayList" ); |
1278 | 1278 | ||
1279 | config.writeEntry("CurrentPlaylist",filename); | 1279 | config.writeEntry("CurrentPlaylist",filename); |
1280 | currentPlayList=filename; | 1280 | currentPlayList=filename; |
1281 | 1281 | ||
1282 | if(!lnk.writeLink()) { | 1282 | if(!lnk.writeLink()) { |
1283 | // qDebug("Writing doclink did not work"); | 1283 | // qDebug("Writing doclink did not work"); |
1284 | } | 1284 | } |
1285 | 1285 | ||
1286 | setCaption(tr("OpiePlayer: ") + name); | 1286 | setCaption(tr("OpiePlayer: ") + name); |
1287 | } | 1287 | } |
1288 | } | 1288 | } |
1289 | } | 1289 | } |
1290 | 1290 | ||
1291 | 1291 | ||
1292 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e) | 1292 | void PlayListWidget::keyReleaseEvent( QKeyEvent *e) |
1293 | { | 1293 | { |
1294 | switch ( e->key() ) { | 1294 | switch ( e->key() ) { |
1295 | ////////////////////////////// Zaurus keys | 1295 | ////////////////////////////// Zaurus keys |
1296 | case Key_F9: //activity | 1296 | case Key_F9: //activity |
1297 | // if(audioUI->isHidden()) | 1297 | // if(audioUI->isHidden()) |
1298 | // audioUI->showMaximized(); | 1298 | // audioUI->showMaximized(); |
1299 | break; | 1299 | break; |
1300 | case Key_F10: //contacts | 1300 | case Key_F10: //contacts |
1301 | // if( videoUI->isHidden()) | 1301 | // if( videoUI->isHidden()) |
1302 | // videoUI->showMaximized(); | 1302 | // videoUI->showMaximized(); |
1303 | break; | 1303 | break; |
1304 | case Key_F11: //menu | 1304 | case Key_F11: //menu |
1305 | break; | 1305 | break; |
1306 | case Key_F12: //home | 1306 | case Key_F12: //home |
1307 | // doBlank(); | 1307 | // doBlank(); |
1308 | break; | 1308 | break; |
1309 | case Key_F13: //mail | 1309 | case Key_F13: //mail |
1310 | // doUnblank(); | 1310 | // doUnblank(); |
1311 | break; | 1311 | break; |
1312 | case Key_Q: //add to playlist | 1312 | case Key_Q: //add to playlist |
1313 | addSelected(); | 1313 | addSelected(); |
1314 | break; | 1314 | break; |
1315 | case Key_R: //remove from playlist | 1315 | case Key_R: //remove from playlist |
1316 | removeSelected(); | 1316 | removeSelected(); |
1317 | break; | 1317 | break; |
1318 | // case Key_P: //play | 1318 | // case Key_P: //play |
1319 | // qDebug("Play"); | 1319 | // qDebug("Play"); |
1320 | // playSelected(); | 1320 | // playSelected(); |
1321 | // break; | 1321 | // break; |
1322 | case Key_Space: | 1322 | case Key_Space: |
1323 | // playSelected(); puh | 1323 | // playSelected(); puh |
1324 | break; | 1324 | break; |
1325 | case Key_1: | 1325 | case Key_1: |
1326 | tabWidget->setCurrentPage(0); | 1326 | tabWidget->setCurrentPage(0); |
1327 | break; | 1327 | break; |
1328 | case Key_2: | 1328 | case Key_2: |
1329 | tabWidget->setCurrentPage(1); | 1329 | tabWidget->setCurrentPage(1); |
1330 | break; | 1330 | break; |
1331 | case Key_3: | 1331 | case Key_3: |
1332 | tabWidget->setCurrentPage(2); | 1332 | tabWidget->setCurrentPage(2); |
1333 | break; | 1333 | break; |
1334 | case Key_4: | 1334 | case Key_4: |
1335 | tabWidget->setCurrentPage(3); | 1335 | tabWidget->setCurrentPage(3); |
1336 | break; | 1336 | break; |
1337 | case Key_Down: | 1337 | case Key_Down: |
1338 | if ( !d->selectedFiles->next() ) | 1338 | if ( !d->selectedFiles->next() ) |
1339 | d->selectedFiles->first(); | 1339 | d->selectedFiles->first(); |
1340 | 1340 | ||
1341 | break; | 1341 | break; |
1342 | case Key_Up: | 1342 | case Key_Up: |
1343 | if ( !d->selectedFiles->prev() ) | 1343 | if ( !d->selectedFiles->prev() ) |
1344 | // d->selectedFiles->last(); | 1344 | // d->selectedFiles->last(); |
1345 | 1345 | ||
1346 | break; | 1346 | break; |
1347 | 1347 | ||
1348 | } | 1348 | } |
1349 | } | 1349 | } |
1350 | 1350 | ||
1351 | void PlayListWidget::keyPressEvent( QKeyEvent *) | 1351 | void PlayListWidget::keyPressEvent( QKeyEvent *) |
1352 | { | 1352 | { |
1353 | // qDebug("Key press"); | 1353 | // qDebug("Key press"); |
1354 | // switch ( e->key() ) { | 1354 | // switch ( e->key() ) { |
1355 | // ////////////////////////////// Zaurus keys | 1355 | // ////////////////////////////// Zaurus keys |
1356 | // case Key_A: //add to playlist | 1356 | // case Key_A: //add to playlist |
1357 | // qDebug("Add"); | 1357 | // qDebug("Add"); |
1358 | // addSelected(); | 1358 | // addSelected(); |
1359 | // break; | 1359 | // break; |
1360 | // case Key_R: //remove from playlist | 1360 | // case Key_R: //remove from playlist |
1361 | // removeSelected(); | 1361 | // removeSelected(); |
1362 | // break; | 1362 | // break; |
1363 | // case Key_P: //play | 1363 | // case Key_P: //play |
1364 | // qDebug("Play"); | 1364 | // qDebug("Play"); |
1365 | // playSelected(); | 1365 | // playSelected(); |
1366 | // break; | 1366 | // break; |
1367 | // case Key_Space: | 1367 | // case Key_Space: |
1368 | // qDebug("Play"); | 1368 | // qDebug("Play"); |
1369 | // playSelected(); | 1369 | // playSelected(); |
1370 | // break; | 1370 | // break; |
1371 | // } | 1371 | // } |
1372 | } | 1372 | } |
1373 | 1373 | ||
1374 | void PlayListWidget::doBlank() { | 1374 | void PlayListWidget::doBlank() { |
1375 | // qDebug("do blanking"); | 1375 | // qDebug("do blanking"); |
1376 | #ifdef QT_QWS_DEVFS | 1376 | #ifdef QT_QWS_DEVFS |
1377 | fd=open("/dev/fb/0",O_RDWR); | 1377 | fd=open("/dev/fb/0",O_RDWR); |
1378 | #else | 1378 | #else |
1379 | fd=open("/dev/fb0",O_RDWR); | 1379 | fd=open("/dev/fb0",O_RDWR); |
1380 | #endif | 1380 | #endif |
1381 | if (fd != -1) { | 1381 | if (fd != -1) { |
1382 | ioctl(fd,FBIOBLANK,1); | 1382 | ioctl(fd,FBIOBLANK,1); |
1383 | // close(fd); | 1383 | // close(fd); |
1384 | } | 1384 | } |
1385 | } | 1385 | } |
1386 | 1386 | ||
1387 | void PlayListWidget::doUnblank() { | 1387 | void PlayListWidget::doUnblank() { |
1388 | // this crashes opieplayer with a segfault | 1388 | // this crashes opieplayer with a segfault |
1389 | // int fd; | 1389 | // int fd; |
1390 | // fd=open("/dev/fb0",O_RDWR); | 1390 | // fd=open("/dev/fb0",O_RDWR); |
1391 | // qDebug("do unblanking"); | 1391 | // qDebug("do unblanking"); |
1392 | if (fd != -1) { | 1392 | if (fd != -1) { |
1393 | ioctl(fd,FBIOBLANK,0); | 1393 | ioctl(fd,FBIOBLANK,0); |
1394 | close(fd); | 1394 | close(fd); |
1395 | } | 1395 | } |
1396 | QCopEnvelope h("QPE/System", "setBacklight(int)"); | 1396 | QCopEnvelope h("QPE/System", "setBacklight(int)"); |
1397 | h <<-3;// v[1]; // -3 Force on | 1397 | h <<-3;// v[1]; // -3 Force on |
1398 | } | 1398 | } |
1399 | 1399 | ||
1400 | void PlayListWidget::populateSkinsMenu() { | 1400 | void PlayListWidget::populateSkinsMenu() { |
1401 | int item = 0; | 1401 | int item = 0; |
1402 | defaultSkinIndex = 0; | 1402 | defaultSkinIndex = 0; |
1403 | QString skinName; | 1403 | QString skinName; |
1404 | Config cfg( "OpiePlayer" ); | 1404 | Config cfg( "OpiePlayer" ); |
1405 | cfg.setGroup("Options" ); | 1405 | cfg.setGroup("Options" ); |
1406 | QString skin = cfg.readEntry( "Skin", "default" ); | 1406 | QString skin = cfg.readEntry( "Skin", "default" ); |
1407 | 1407 | ||
1408 | QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); | 1408 | QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); |
1409 | skinsDir.setFilter( QDir::Dirs ); | 1409 | skinsDir.setFilter( QDir::Dirs ); |
1410 | skinsDir.setSorting(QDir::Name ); | 1410 | skinsDir.setSorting(QDir::Name ); |
1411 | const QFileInfoList *skinslist = skinsDir.entryInfoList(); | 1411 | const QFileInfoList *skinslist = skinsDir.entryInfoList(); |
1412 | QFileInfoListIterator it( *skinslist ); | 1412 | QFileInfoListIterator it( *skinslist ); |
1413 | QFileInfo *fi; | 1413 | QFileInfo *fi; |
1414 | while ( ( fi = it.current() ) ) { | 1414 | while ( ( fi = it.current() ) ) { |
1415 | skinName = fi->fileName(); | 1415 | skinName = fi->fileName(); |
1416 | // qDebug( fi->fileName() ); | 1416 | // qDebug( fi->fileName() ); |
1417 | if( skinName != "." && skinName != ".." && skinName !="CVS" ) { | 1417 | if( skinName != "." && skinName != ".." && skinName !="CVS" ) { |
1418 | item = skinsMenu->insertItem( fi->fileName() ) ; | 1418 | item = skinsMenu->insertItem( fi->fileName() ) ; |
1419 | } | 1419 | } |
1420 | if( skinName == "default" ) { | 1420 | if( skinName == "default" ) { |
1421 | defaultSkinIndex = item; | 1421 | defaultSkinIndex = item; |
1422 | } | 1422 | } |
1423 | if( skinName == skin ) { | 1423 | if( skinName == skin ) { |
1424 | skinsMenu->setItemChecked( item, TRUE ); | 1424 | skinsMenu->setItemChecked( item, TRUE ); |
1425 | } | 1425 | } |
1426 | ++it; | 1426 | ++it; |
1427 | } | 1427 | } |
1428 | } | 1428 | } |
1429 | 1429 | ||
1430 | void PlayListWidget::skinsMenuActivated( int item ) { | 1430 | void PlayListWidget::skinsMenuActivated( int item ) { |
1431 | for( int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { | 1431 | for( int i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { |
1432 | skinsMenu->setItemChecked( i, FALSE ); | 1432 | skinsMenu->setItemChecked( i, FALSE ); |
1433 | } | 1433 | } |
1434 | skinsMenu->setItemChecked( item, TRUE ); | 1434 | skinsMenu->setItemChecked( item, TRUE ); |
1435 | 1435 | ||
1436 | Config cfg( "OpiePlayer" ); | 1436 | Config cfg( "OpiePlayer" ); |
1437 | cfg.setGroup("Options"); | 1437 | cfg.setGroup("Options"); |
1438 | cfg.writeEntry("Skin", skinsMenu->text( item ) ); | 1438 | cfg.writeEntry("Skin", skinsMenu->text( item ) ); |
1439 | } | 1439 | } |
1440 | 1440 | ||
1441 | void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { | 1441 | void PlayListWidget::qcopReceive(const QCString &msg, const QByteArray &data) { |
1442 | // qDebug("qcop message "+msg ); | 1442 | // qDebug("qcop message "+msg ); |
1443 | QDataStream stream ( data, IO_ReadOnly ); | 1443 | QDataStream stream ( data, IO_ReadOnly ); |
1444 | if ( msg == "play()" ) { //plays current selection | 1444 | if ( msg == "play()" ) { //plays current selection |
1445 | btnPlay( true); | 1445 | btnPlay( true); |
1446 | } else if ( msg == "stop()" ) { | 1446 | } else if ( msg == "stop()" ) { |
1447 | mediaPlayerState->setPlaying( false); | 1447 | mediaPlayerState->setPlaying( false); |
1448 | } else if ( msg == "togglePause()" ) { | 1448 | } else if ( msg == "togglePause()" ) { |
1449 | mediaPlayerState->togglePaused(); | 1449 | mediaPlayerState->togglePaused(); |
1450 | } else if ( msg == "next()" ) { //select next in lis | 1450 | } else if ( msg == "next()" ) { //select next in lis |
1451 | mediaPlayerState->setNext(); | 1451 | mediaPlayerState->setNext(); |
1452 | } else if ( msg == "prev()" ) { //select previous in list | 1452 | } else if ( msg == "prev()" ) { //select previous in list |
1453 | mediaPlayerState->setPrev(); | 1453 | mediaPlayerState->setPrev(); |
1454 | } else if ( msg == "toggleLooping()" ) { //loop or not loop | 1454 | } else if ( msg == "toggleLooping()" ) { //loop or not loop |
1455 | mediaPlayerState->toggleLooping(); | 1455 | mediaPlayerState->toggleLooping(); |
1456 | } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled | 1456 | } else if ( msg == "toggleShuffled()" ) { //shuffled or not shuffled |
1457 | mediaPlayerState->toggleShuffled(); | 1457 | mediaPlayerState->toggleShuffled(); |
1458 | } else if ( msg == "volUp()" ) { //volume more | 1458 | } else if ( msg == "volUp()" ) { //volume more |
1459 | // emit moreClicked(); | 1459 | // emit moreClicked(); |
1460 | // emit moreReleased(); | 1460 | // emit moreReleased(); |
1461 | } else if ( msg == "volDown()" ) { //volume less | 1461 | } else if ( msg == "volDown()" ) { //volume less |
1462 | // emit lessClicked(); | 1462 | // emit lessClicked(); |
1463 | // emit lessReleased(); | 1463 | // emit lessReleased(); |
1464 | } else if ( msg == "play(QString)" ) { //play this now | 1464 | } else if ( msg == "play(QString)" ) { //play this now |
1465 | QString file; | 1465 | QString file; |
1466 | stream >> file; | 1466 | stream >> file; |
1467 | setDocumentEx( (const QString &) file); | 1467 | setDocumentEx( (const QString &) file); |
1468 | } else if ( msg == "add(QString)" ) { //add to playlist | 1468 | } else if ( msg == "add(QString)" ) { //add to playlist |
1469 | QString file; | 1469 | QString file; |
1470 | stream >> file; | 1470 | stream >> file; |
1471 | QFileInfo fileInfo(file); | 1471 | QFileInfo fileInfo(file); |
1472 | DocLnk lnk; | 1472 | DocLnk lnk; |
1473 | lnk.setName( fileInfo.baseName() ); //sets name | 1473 | lnk.setName( fileInfo.baseName() ); //sets name |
1474 | lnk.setFile( file ); //sets file name | 1474 | lnk.setFile( file ); //sets file name |
1475 | addToSelection( lnk ); | 1475 | addToSelection( lnk ); |
1476 | } else if ( msg == "rem(QString)" ) { //remove from playlist | 1476 | } else if ( msg == "rem(QString)" ) { //remove from playlist |
1477 | QString file; | 1477 | QString file; |
1478 | stream >> file; | 1478 | stream >> file; |
1479 | } else if ( msg == "setDocument(QString)" ) { //loop or not loop | 1479 | } else if ( msg == "setDocument(QString)" ) { //loop or not loop |
1480 | QCopEnvelope h("QPE/Application/opieplayer", "raise()"); | 1480 | QCopEnvelope h("QPE/Application/opieplayer", "raise()"); |
1481 | } | 1481 | } |
1482 | } | 1482 | } |
diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index 406ced6..9f668f4 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp | |||
@@ -1,1061 +1,1061 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** Copyright (C) 2003 Stefan Eilers (eilers.stefan@epost.de) | 3 | ** Copyright (C) 2003 Stefan Eilers (eilers.stefan@epost.de) |
4 | ** | 4 | ** |
5 | ** This file is part of the Open Palmtop Environment (see www.opie.info). | 5 | ** This file is part of the Open Palmtop Environment (see www.opie.info). |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
14 | ** | 14 | ** |
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
16 | ** | 16 | ** |
17 | ** | 17 | ** |
18 | **********************************************************************/ | 18 | **********************************************************************/ |
19 | 19 | ||
20 | #define QTOPIA_INTERNAL_FD | 20 | #define QTOPIA_INTERNAL_FD |
21 | 21 | ||
22 | #include "contacteditor.h" | 22 | #include "contacteditor.h" |
23 | #include "ablabel.h" | 23 | #include "ablabel.h" |
24 | #include "abview.h" | 24 | #include "abview.h" |
25 | #include "abtable.h" | 25 | #include "abtable.h" |
26 | // #include "addresssettings.h" | 26 | // #include "addresssettings.h" |
27 | #include "addressbook.h" | 27 | #include "addressbook.h" |
28 | 28 | ||
29 | 29 | ||
30 | #include <opie/ofileselector.h> | 30 | #include <opie/ofileselector.h> |
31 | #include <opie/ofiledialog.h> | 31 | #include <opie/ofiledialog.h> |
32 | #include <opie/ocontact.h> | 32 | #include <opie/ocontact.h> |
33 | #include <opie/ocontactaccessbackend_vcard.h> | 33 | #include <opie/ocontactaccessbackend_vcard.h> |
34 | 34 | ||
35 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
36 | #include <qpe/ir.h> | 36 | #include <qpe/ir.h> |
37 | #include <qpe/qpemessagebox.h> | 37 | #include <qpe/qpemessagebox.h> |
38 | #include <qpe/qcopenvelope_qws.h> | 38 | #include <qpe/qcopenvelope_qws.h> |
39 | #include <qpe/qpetoolbar.h> | 39 | #include <qtoolbar.h> |
40 | #include <qmenubar.h> | 40 | #include <qmenubar.h> |
41 | // #include <qtoolbar.h> | 41 | // #include <qtoolbar.h> |
42 | // #include <qmenubar.h> | 42 | // #include <qmenubar.h> |
43 | #include <qpe/qpeapplication.h> | 43 | #include <qpe/qpeapplication.h> |
44 | #include <qpe/config.h> | 44 | #include <qpe/config.h> |
45 | 45 | ||
46 | #include <qaction.h> | 46 | #include <qaction.h> |
47 | #include <qdialog.h> | 47 | #include <qdialog.h> |
48 | #include <qdir.h> | 48 | #include <qdir.h> |
49 | #include <qfile.h> | 49 | #include <qfile.h> |
50 | #include <qimage.h> | 50 | #include <qimage.h> |
51 | #include <qlayout.h> | 51 | #include <qlayout.h> |
52 | #include <qmessagebox.h> | 52 | #include <qmessagebox.h> |
53 | #include <qpixmap.h> | 53 | #include <qpixmap.h> |
54 | #include <qpopupmenu.h> | 54 | #include <qpopupmenu.h> |
55 | #include <qstringlist.h> | 55 | #include <qstringlist.h> |
56 | #include <qtoolbutton.h> | 56 | #include <qtoolbutton.h> |
57 | #include <qwhatsthis.h> | 57 | #include <qwhatsthis.h> |
58 | #include <qdatetime.h> | 58 | #include <qdatetime.h> |
59 | 59 | ||
60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
61 | #include <sys/stat.h> | 61 | #include <sys/stat.h> |
62 | #include <sys/types.h> | 62 | #include <sys/types.h> |
63 | #include <fcntl.h> | 63 | #include <fcntl.h> |
64 | #include <unistd.h> | 64 | #include <unistd.h> |
65 | 65 | ||
66 | 66 | ||
67 | #include "picker.h" | 67 | #include "picker.h" |
68 | #include "configdlg.h" | 68 | #include "configdlg.h" |
69 | 69 | ||
70 | extern QString addressbookPersonalVCardName(); | 70 | extern QString addressbookPersonalVCardName(); |
71 | 71 | ||
72 | AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, | 72 | AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, |
73 | WFlags f ) | 73 | WFlags f ) |
74 | : QMainWindow( parent, name, f ), | 74 | : QMainWindow( parent, name, f ), |
75 | catMenu (0l), | 75 | catMenu (0l), |
76 | abEditor(0l), | 76 | abEditor(0l), |
77 | syncing(FALSE), | 77 | syncing(FALSE), |
78 | m_tableViewButton(0l), | 78 | m_tableViewButton(0l), |
79 | m_cardViewButton(0l) | 79 | m_cardViewButton(0l) |
80 | { | 80 | { |
81 | isLoading = true; | 81 | isLoading = true; |
82 | 82 | ||
83 | m_config.load(); | 83 | m_config.load(); |
84 | 84 | ||
85 | setCaption( tr("Contacts") ); | 85 | setCaption( tr("Contacts") ); |
86 | setIcon( Resource::loadPixmap( "AddressBook" ) ); | 86 | setIcon( Resource::loadPixmap( "AddressBook" ) ); |
87 | 87 | ||
88 | // Settings for Main Menu | 88 | // Settings for Main Menu |
89 | // setToolBarsMovable( false ); | 89 | // setToolBarsMovable( false ); |
90 | setToolBarsMovable( !m_config.fixedBars() ); | 90 | setToolBarsMovable( !m_config.fixedBars() ); |
91 | setRightJustification( true ); | 91 | setRightJustification( true ); |
92 | 92 | ||
93 | QPEToolBar *bar = new QPEToolBar( this ); | 93 | QToolBar *bar = new QToolBar( this ); |
94 | bar->setHorizontalStretchable( TRUE ); | 94 | bar->setHorizontalStretchable( TRUE ); |
95 | 95 | ||
96 | QMenuBar *mbList = new QMenuBar( bar ); | 96 | QMenuBar *mbList = new QMenuBar( bar ); |
97 | mbList->setMargin( 0 ); | 97 | mbList->setMargin( 0 ); |
98 | 98 | ||
99 | QPopupMenu *edit = new QPopupMenu( mbList ); | 99 | QPopupMenu *edit = new QPopupMenu( mbList ); |
100 | mbList->insertItem( tr( "Contact" ), edit ); | 100 | mbList->insertItem( tr( "Contact" ), edit ); |
101 | 101 | ||
102 | // Category Menu | 102 | // Category Menu |
103 | catMenu = new QPopupMenu( this ); | 103 | catMenu = new QPopupMenu( this ); |
104 | catMenu->setCheckable( TRUE ); | 104 | catMenu->setCheckable( TRUE ); |
105 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); | 105 | connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); |
106 | mbList->insertItem( tr("View"), catMenu ); | 106 | mbList->insertItem( tr("View"), catMenu ); |
107 | 107 | ||
108 | // Create Toolbar | 108 | // Create Toolbar |
109 | listTools = new QPEToolBar( this, "list operations" ); | 109 | listTools = new QToolBar( this, "list operations" ); |
110 | listTools->setHorizontalStretchable( true ); | 110 | listTools->setHorizontalStretchable( true ); |
111 | addToolBar( listTools ); | 111 | addToolBar( listTools ); |
112 | moveToolBar( listTools, m_config.getToolBarPos() ); | 112 | moveToolBar( listTools, m_config.getToolBarPos() ); |
113 | 113 | ||
114 | // View Icons | 114 | // View Icons |
115 | m_tableViewButton = new QAction( tr( "List" ), Resource::loadPixmap( "addressbook/listview" ), | 115 | m_tableViewButton = new QAction( tr( "List" ), Resource::loadPixmap( "addressbook/listview" ), |
116 | QString::null, 0, this, 0 ); | 116 | QString::null, 0, this, 0 ); |
117 | connect( m_tableViewButton, SIGNAL( activated() ), this, SLOT( slotListView() ) ); | 117 | connect( m_tableViewButton, SIGNAL( activated() ), this, SLOT( slotListView() ) ); |
118 | m_tableViewButton->setToggleAction( true ); | 118 | m_tableViewButton->setToggleAction( true ); |
119 | m_tableViewButton->addTo( listTools ); | 119 | m_tableViewButton->addTo( listTools ); |
120 | m_cardViewButton = new QAction( tr( "Card" ), Resource::loadPixmap( "addressbook/cardview" ), QString::null, 0, this, 0 ); | 120 | m_cardViewButton = new QAction( tr( "Card" ), Resource::loadPixmap( "addressbook/cardview" ), QString::null, 0, this, 0 ); |
121 | connect( m_cardViewButton, SIGNAL( activated() ), this, SLOT( slotCardView() ) ); | 121 | connect( m_cardViewButton, SIGNAL( activated() ), this, SLOT( slotCardView() ) ); |
122 | m_cardViewButton->setToggleAction( true ); | 122 | m_cardViewButton->setToggleAction( true ); |
123 | m_cardViewButton->addTo( listTools ); | 123 | m_cardViewButton->addTo( listTools ); |
124 | 124 | ||
125 | listTools->addSeparator(); | 125 | listTools->addSeparator(); |
126 | 126 | ||
127 | // Other Buttons | 127 | // Other Buttons |
128 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, | 128 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, |
129 | 0, this, 0 ); | 129 | 0, this, 0 ); |
130 | actionNew = a; | 130 | actionNew = a; |
131 | connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); | 131 | connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); |
132 | a->addTo( edit ); | 132 | a->addTo( edit ); |
133 | a->addTo( listTools ); | 133 | a->addTo( listTools ); |
134 | 134 | ||
135 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, | 135 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, |
136 | 0, this, 0 ); | 136 | 0, this, 0 ); |
137 | actionEdit = a; | 137 | actionEdit = a; |
138 | connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); | 138 | connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); |
139 | a->addTo( edit ); | 139 | a->addTo( edit ); |
140 | a->addTo( listTools ); | 140 | a->addTo( listTools ); |
141 | 141 | ||
142 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, | 142 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, |
143 | 0, this, 0 ); | 143 | 0, this, 0 ); |
144 | actionTrash = a; | 144 | actionTrash = a; |
145 | connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); | 145 | connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); |
146 | a->addTo( edit ); | 146 | a->addTo( edit ); |
147 | a->addTo( listTools ); | 147 | a->addTo( listTools ); |
148 | 148 | ||
149 | 149 | ||
150 | // make it possible to go directly to businesscard via qcop call | 150 | // make it possible to go directly to businesscard via qcop call |
151 | //#if defined(Q_WS_QWS) // Why this ? (se) | 151 | //#if defined(Q_WS_QWS) // Why this ? (se) |
152 | #if !defined(QT_NO_COP) | 152 | #if !defined(QT_NO_COP) |
153 | QCopChannel *addressChannel = new QCopChannel("QPE/Addressbook" , this ); | 153 | QCopChannel *addressChannel = new QCopChannel("QPE/Addressbook" , this ); |
154 | connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), | 154 | connect (addressChannel, SIGNAL( received(const QCString &, const QByteArray &)), |
155 | this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); | 155 | this, SLOT ( appMessage(const QCString &, const QByteArray &) ) ); |
156 | #endif | 156 | #endif |
157 | // #endif | 157 | // #endif |
158 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), | 158 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), |
159 | QString::null, 0, this, 0 ); | 159 | QString::null, 0, this, 0 ); |
160 | actionFind = a; | 160 | actionFind = a; |
161 | connect( a, SIGNAL(activated()), this, SLOT( slotFindOpen()) ); | 161 | connect( a, SIGNAL(activated()), this, SLOT( slotFindOpen()) ); |
162 | a->addTo( edit ); | 162 | a->addTo( edit ); |
163 | a->addTo( listTools ); | 163 | a->addTo( listTools ); |
164 | 164 | ||
165 | // Much better search widget, taken from QTReader.. (se) | 165 | // Much better search widget, taken from QTReader.. (se) |
166 | searchBar = new OFloatBar( "Search", this, QMainWindow::Top, TRUE ); | 166 | searchBar = new OFloatBar( "Search", this, QMainWindow::Top, TRUE ); |
167 | searchBar->setHorizontalStretchable( TRUE ); | 167 | searchBar->setHorizontalStretchable( TRUE ); |
168 | searchBar->hide(); | 168 | searchBar->hide(); |
169 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 169 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
170 | 170 | ||
171 | // QFont f("unifont", 16 /*, QFont::Bold*/); | 171 | // QFont f("unifont", 16 /*, QFont::Bold*/); |
172 | // searchEdit->setFont( f ); | 172 | // searchEdit->setFont( f ); |
173 | 173 | ||
174 | searchBar->setStretchableWidget( searchEdit ); | 174 | searchBar->setStretchableWidget( searchEdit ); |
175 | connect( searchEdit, SIGNAL( returnPressed( ) ), | 175 | connect( searchEdit, SIGNAL( returnPressed( ) ), |
176 | this, SLOT( slotFind( ) ) ); | 176 | this, SLOT( slotFind( ) ) ); |
177 | 177 | ||
178 | a = new QAction( tr( "Start Search" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 ); | 178 | a = new QAction( tr( "Start Search" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 ); |
179 | connect( a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); | 179 | connect( a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); |
180 | a->addTo( searchBar ); | 180 | a->addTo( searchBar ); |
181 | 181 | ||
182 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 182 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
183 | connect( a, SIGNAL( activated() ), this, SLOT( slotFindClose() ) ); | 183 | connect( a, SIGNAL( activated() ), this, SLOT( slotFindClose() ) ); |
184 | a->addTo( searchBar ); | 184 | a->addTo( searchBar ); |
185 | 185 | ||
186 | a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "addressbook/sendmail" ), | 186 | a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "addressbook/sendmail" ), |
187 | QString::null, 0, this, 0 ); | 187 | QString::null, 0, this, 0 ); |
188 | //a->setEnabled( FALSE ); we got support for it now :) zecke | 188 | //a->setEnabled( FALSE ); we got support for it now :) zecke |
189 | actionMail = a; | 189 | actionMail = a; |
190 | connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); | 190 | connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); |
191 | a->addTo( edit ); | 191 | a->addTo( edit ); |
192 | a->addTo( listTools ); | 192 | a->addTo( listTools ); |
193 | 193 | ||
194 | if ( Ir::supported() ) { | 194 | if ( Ir::supported() ) { |
195 | a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, | 195 | a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, |
196 | 0, this, 0 ); | 196 | 0, this, 0 ); |
197 | actionBeam = a; | 197 | actionBeam = a; |
198 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); | 198 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); |
199 | a->addTo( edit ); | 199 | a->addTo( edit ); |
200 | a->addTo( listTools ); | 200 | a->addTo( listTools ); |
201 | } | 201 | } |
202 | 202 | ||
203 | edit->insertSeparator(); | 203 | edit->insertSeparator(); |
204 | 204 | ||
205 | a = new QAction( tr("Import vCard"), Resource::loadPixmap( "addressbook/fileimport"), QString::null, | 205 | a = new QAction( tr("Import vCard"), Resource::loadPixmap( "addressbook/fileimport"), QString::null, |
206 | 0, this, 0); | 206 | 0, this, 0); |
207 | actionPersonal = a; | 207 | actionPersonal = a; |
208 | connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); | 208 | connect( a, SIGNAL( activated() ), this, SLOT( importvCard() ) ); |
209 | a->addTo( edit ); | 209 | a->addTo( edit ); |
210 | 210 | ||
211 | a = new QAction( tr("Export vCard"), Resource::loadPixmap( "addressbook/fileexport"), QString::null, | 211 | a = new QAction( tr("Export vCard"), Resource::loadPixmap( "addressbook/fileexport"), QString::null, |
212 | 0, this, 0); | 212 | 0, this, 0); |
213 | actionPersonal = a; | 213 | actionPersonal = a; |
214 | connect( a, SIGNAL( activated() ), this, SLOT( exportvCard() ) ); | 214 | connect( a, SIGNAL( activated() ), this, SLOT( exportvCard() ) ); |
215 | a->addTo( edit ); | 215 | a->addTo( edit ); |
216 | 216 | ||
217 | edit->insertSeparator(); | 217 | edit->insertSeparator(); |
218 | 218 | ||
219 | a = new QAction( tr("My Personal Details"), Resource::loadPixmap( "addressbook/identity" ), | 219 | a = new QAction( tr("My Personal Details"), Resource::loadPixmap( "addressbook/identity" ), |
220 | QString::null, 0, this, 0 , TRUE ); | 220 | QString::null, 0, this, 0 , TRUE ); |
221 | actionPersonal = a; | 221 | actionPersonal = a; |
222 | connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); | 222 | connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); |
223 | a->addTo( edit ); | 223 | a->addTo( edit ); |
224 | 224 | ||
225 | 225 | ||
226 | #ifdef __DEBUG_RELEASE | 226 | #ifdef __DEBUG_RELEASE |
227 | // Remove this function for public Release ! This is only | 227 | // Remove this function for public Release ! This is only |
228 | // for debug purposes .. | 228 | // for debug purposes .. |
229 | a = new QAction( tr( "Save all Data"), QString::null, 0, 0 ); | 229 | a = new QAction( tr( "Save all Data"), QString::null, 0, 0 ); |
230 | connect( a, SIGNAL( activated() ), this , SLOT( slotSave() ) ); | 230 | connect( a, SIGNAL( activated() ), this , SLOT( slotSave() ) ); |
231 | a->addTo( edit ); | 231 | a->addTo( edit ); |
232 | #endif | 232 | #endif |
233 | a = new QAction( tr( "Config" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, | 233 | a = new QAction( tr( "Config" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, |
234 | 0, this, 0 ); | 234 | 0, this, 0 ); |
235 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfig() ) ); | 235 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfig() ) ); |
236 | a->addTo( edit ); | 236 | a->addTo( edit ); |
237 | 237 | ||
238 | // Create Views | 238 | // Create Views |
239 | listContainer = new QWidget( this ); | 239 | listContainer = new QWidget( this ); |
240 | QVBoxLayout *vb = new QVBoxLayout( listContainer ); | 240 | QVBoxLayout *vb = new QVBoxLayout( listContainer ); |
241 | 241 | ||
242 | m_abView = new AbView( listContainer, m_config.orderList() ); | 242 | m_abView = new AbView( listContainer, m_config.orderList() ); |
243 | vb->addWidget( m_abView ); | 243 | vb->addWidget( m_abView ); |
244 | // abList->setHScrollBarMode( QScrollView::AlwaysOff ); | 244 | // abList->setHScrollBarMode( QScrollView::AlwaysOff ); |
245 | connect( m_abView, SIGNAL( signalViewSwitched ( int ) ), | 245 | connect( m_abView, SIGNAL( signalViewSwitched ( int ) ), |
246 | this, SLOT( slotViewSwitched( int ) ) ); | 246 | this, SLOT( slotViewSwitched( int ) ) ); |
247 | 247 | ||
248 | 248 | ||
249 | QObject::connect( m_abView, SIGNAL(signalNotFound()), this, SLOT(slotNotFound()) ); | 249 | QObject::connect( m_abView, SIGNAL(signalNotFound()), this, SLOT(slotNotFound()) ); |
250 | 250 | ||
251 | // m_abView->load(); // Already done by c'tor . | 251 | // m_abView->load(); // Already done by c'tor . |
252 | 252 | ||
253 | // Letter Picker | 253 | // Letter Picker |
254 | pLabel = new LetterPicker( listContainer ); | 254 | pLabel = new LetterPicker( listContainer ); |
255 | connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); | 255 | connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); |
256 | connect(m_abView, SIGNAL( signalClearLetterPicker() ), pLabel, SLOT( clear() ) ); | 256 | connect(m_abView, SIGNAL( signalClearLetterPicker() ), pLabel, SLOT( clear() ) ); |
257 | 257 | ||
258 | vb->addWidget( pLabel ); | 258 | vb->addWidget( pLabel ); |
259 | 259 | ||
260 | // All Categories into view-menu.. | 260 | // All Categories into view-menu.. |
261 | populateCategories(); | 261 | populateCategories(); |
262 | 262 | ||
263 | // Fontsize | 263 | // Fontsize |
264 | defaultFont = new QFont( m_abView->font() ); | 264 | defaultFont = new QFont( m_abView->font() ); |
265 | slotSetFont(m_config.fontSize()); | 265 | slotSetFont(m_config.fontSize()); |
266 | m_curFontSize = m_config.fontSize(); | 266 | m_curFontSize = m_config.fontSize(); |
267 | 267 | ||
268 | setCentralWidget(listContainer); | 268 | setCentralWidget(listContainer); |
269 | 269 | ||
270 | // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); | 270 | // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); |
271 | connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); | 271 | connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); |
272 | connect( qApp, SIGNAL( reload() ), this, SLOT( reload() ) ); | 272 | connect( qApp, SIGNAL( reload() ), this, SLOT( reload() ) ); |
273 | connect( qApp, SIGNAL( appMessage(const QCString &, const QByteArray &) ), | 273 | connect( qApp, SIGNAL( appMessage(const QCString &, const QByteArray &) ), |
274 | this, SLOT( appMessage(const QCString &, const QByteArray &) ) ); | 274 | this, SLOT( appMessage(const QCString &, const QByteArray &) ) ); |
275 | 275 | ||
276 | 276 | ||
277 | isLoading = false; | 277 | isLoading = false; |
278 | } | 278 | } |
279 | 279 | ||
280 | 280 | ||
281 | void AddressbookWindow::slotConfig() | 281 | void AddressbookWindow::slotConfig() |
282 | { | 282 | { |
283 | ConfigDlg* dlg = new ConfigDlg( this, "Config" ); | 283 | ConfigDlg* dlg = new ConfigDlg( this, "Config" ); |
284 | dlg -> setConfig( m_config ); | 284 | dlg -> setConfig( m_config ); |
285 | dlg -> showMaximized(); | 285 | dlg -> showMaximized(); |
286 | if ( dlg -> exec() ) { | 286 | if ( dlg -> exec() ) { |
287 | qWarning ("Config Dialog accepted!"); | 287 | qWarning ("Config Dialog accepted!"); |
288 | m_config = dlg -> getConfig(); | 288 | m_config = dlg -> getConfig(); |
289 | if ( m_curFontSize != m_config.fontSize() ){ | 289 | if ( m_curFontSize != m_config.fontSize() ){ |
290 | qWarning("Font was changed!"); | 290 | qWarning("Font was changed!"); |
291 | m_curFontSize = m_config.fontSize(); | 291 | m_curFontSize = m_config.fontSize(); |
292 | emit slotSetFont( m_curFontSize ); | 292 | emit slotSetFont( m_curFontSize ); |
293 | } | 293 | } |
294 | m_abView -> setListOrder( m_config.orderList() ); | 294 | m_abView -> setListOrder( m_config.orderList() ); |
295 | } | 295 | } |
296 | 296 | ||
297 | delete dlg; | 297 | delete dlg; |
298 | } | 298 | } |
299 | 299 | ||
300 | 300 | ||
301 | void AddressbookWindow::slotSetFont( int size ) | 301 | void AddressbookWindow::slotSetFont( int size ) |
302 | { | 302 | { |
303 | qWarning("void AddressbookWindow::slotSetFont( %d )", size); | 303 | qWarning("void AddressbookWindow::slotSetFont( %d )", size); |
304 | 304 | ||
305 | if (size > 2 || size < 0) | 305 | if (size > 2 || size < 0) |
306 | size = 1; | 306 | size = 1; |
307 | 307 | ||
308 | m_config.setFontSize( size ); | 308 | m_config.setFontSize( size ); |
309 | 309 | ||
310 | QFont *currentFont; | 310 | QFont *currentFont; |
311 | 311 | ||
312 | switch (size) { | 312 | switch (size) { |
313 | case 0: | 313 | case 0: |
314 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); | 314 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); |
315 | currentFont = new QFont (m_abView->font()); | 315 | currentFont = new QFont (m_abView->font()); |
316 | // abList->resizeRows(currentFont->pixelSize() + 7); :SX | 316 | // abList->resizeRows(currentFont->pixelSize() + 7); :SX |
317 | // abList->resizeRows(); | 317 | // abList->resizeRows(); |
318 | break; | 318 | break; |
319 | case 1: | 319 | case 1: |
320 | m_abView->setFont( *defaultFont ); | 320 | m_abView->setFont( *defaultFont ); |
321 | currentFont = new QFont (m_abView->font()); | 321 | currentFont = new QFont (m_abView->font()); |
322 | // // abList->resizeRows(currentFont->pixelSize() + 7); | 322 | // // abList->resizeRows(currentFont->pixelSize() + 7); |
323 | // abList->resizeRows(); | 323 | // abList->resizeRows(); |
324 | break; | 324 | break; |
325 | case 2: | 325 | case 2: |
326 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); | 326 | m_abView->setFont( QFont( defaultFont->family(), defaultFont->pointSize() + 2 ) ); |
327 | currentFont = new QFont (m_abView->font()); | 327 | currentFont = new QFont (m_abView->font()); |
328 | // //abList->resizeRows(currentFont->pixelSize() + 7); | 328 | // //abList->resizeRows(currentFont->pixelSize() + 7); |
329 | // abList->resizeRows(); | 329 | // abList->resizeRows(); |
330 | break; | 330 | break; |
331 | } | 331 | } |
332 | } | 332 | } |
333 | 333 | ||
334 | 334 | ||
335 | 335 | ||
336 | void AddressbookWindow::importvCard() { | 336 | void AddressbookWindow::importvCard() { |
337 | QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); | 337 | QString str = OFileDialog::getOpenFileName( 1,"/");//,"", "*", this ); |
338 | if(!str.isEmpty() ){ | 338 | if(!str.isEmpty() ){ |
339 | setDocument((const QString&) str ); | 339 | setDocument((const QString&) str ); |
340 | } | 340 | } |
341 | 341 | ||
342 | } | 342 | } |
343 | void AddressbookWindow::exportvCard() | 343 | void AddressbookWindow::exportvCard() |
344 | { | 344 | { |
345 | qWarning(" void AddressbookWindow::exportvCard()"); | 345 | qWarning(" void AddressbookWindow::exportvCard()"); |
346 | QString filename = OFileDialog::getSaveFileName( 1,"/home/"); //,"", "*", this ); | 346 | QString filename = OFileDialog::getSaveFileName( 1,"/home/"); //,"", "*", this ); |
347 | if( !filename.isEmpty() && ( filename[filename.length()-1] != '/' ) ){ | 347 | if( !filename.isEmpty() && ( filename[filename.length()-1] != '/' ) ){ |
348 | qWarning(" Save to file %s, (%d)", filename.latin1(), filename.length()-1 ); | 348 | qWarning(" Save to file %s, (%d)", filename.latin1(), filename.length()-1 ); |
349 | OContact curCont = m_abView->currentEntry(); | 349 | OContact curCont = m_abView->currentEntry(); |
350 | if ( !curCont.isEmpty() ){ | 350 | if ( !curCont.isEmpty() ){ |
351 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 351 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
352 | filename ); | 352 | filename ); |
353 | OContactAccess* access = new OContactAccess ( "addressbook_exp", QString::null , vcard_backend, true ); | 353 | OContactAccess* access = new OContactAccess ( "addressbook_exp", QString::null , vcard_backend, true ); |
354 | if ( access ){ | 354 | if ( access ){ |
355 | access->add( curCont ); | 355 | access->add( curCont ); |
356 | access->save(); | 356 | access->save(); |
357 | } | 357 | } |
358 | delete access; | 358 | delete access; |
359 | }else | 359 | }else |
360 | QMessageBox::critical( 0, "Export VCard", | 360 | QMessageBox::critical( 0, "Export VCard", |
361 | QString( tr( "You have to select a contact !") ) ); | 361 | QString( tr( "You have to select a contact !") ) ); |
362 | 362 | ||
363 | }else | 363 | }else |
364 | QMessageBox::critical( 0, "Export VCard", | 364 | QMessageBox::critical( 0, "Export VCard", |
365 | QString( tr( "You have to set a filename !") ) ); | 365 | QString( tr( "You have to set a filename !") ) ); |
366 | } | 366 | } |
367 | 367 | ||
368 | void AddressbookWindow::setDocument( const QString &filename ) | 368 | void AddressbookWindow::setDocument( const QString &filename ) |
369 | { | 369 | { |
370 | qWarning( "void AddressbookWindow::setDocument( %s )", filename.latin1() ); | 370 | qWarning( "void AddressbookWindow::setDocument( %s )", filename.latin1() ); |
371 | 371 | ||
372 | if ( filename.find(".vcf") != int(filename.length()) - 4 ){ | 372 | if ( filename.find(".vcf") != int(filename.length()) - 4 ){ |
373 | 373 | ||
374 | 374 | ||
375 | 375 | ||
376 | switch( QMessageBox::information( this, tr ( "Right file type ?" ), | 376 | switch( QMessageBox::information( this, tr ( "Right file type ?" ), |
377 | tr( "The selected file \n does not end with \".vcf\".\n Do you really want to open it?" ), | 377 | tr( "The selected file \n does not end with \".vcf\".\n Do you really want to open it?" ), |
378 | tr( "&Yes" ), tr( "&No" ), QString::null, | 378 | tr( "&Yes" ), tr( "&No" ), QString::null, |
379 | 0, // Enter == button 0 | 379 | 0, // Enter == button 0 |
380 | 2 ) ) { // Escape == button 2 | 380 | 2 ) ) { // Escape == button 2 |
381 | case 0: | 381 | case 0: |
382 | qWarning("YES clicked"); | 382 | qWarning("YES clicked"); |
383 | break; | 383 | break; |
384 | case 1: | 384 | case 1: |
385 | qWarning("NO clicked"); | 385 | qWarning("NO clicked"); |
386 | return; | 386 | return; |
387 | break; | 387 | break; |
388 | } | 388 | } |
389 | } | 389 | } |
390 | 390 | ||
391 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 391 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
392 | filename ); | 392 | filename ); |
393 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 393 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
394 | OContactAccess::List allList = access->allRecords(); | 394 | OContactAccess::List allList = access->allRecords(); |
395 | qWarning( "Found number of contacts in File: %d", allList.count() ); | 395 | qWarning( "Found number of contacts in File: %d", allList.count() ); |
396 | 396 | ||
397 | if ( !allList.count() ) { | 397 | if ( !allList.count() ) { |
398 | QMessageBox::information( this, "Import VCard", | 398 | QMessageBox::information( this, "Import VCard", |
399 | "It was impossible to import\nthe VCard.\n" | 399 | "It was impossible to import\nthe VCard.\n" |
400 | "The VCard may be corrupted!" ); | 400 | "The VCard may be corrupted!" ); |
401 | } | 401 | } |
402 | 402 | ||
403 | bool doAsk = true; | 403 | bool doAsk = true; |
404 | OContactAccess::List::Iterator it; | 404 | OContactAccess::List::Iterator it; |
405 | for ( it = allList.begin(); it != allList.end(); ++it ){ | 405 | for ( it = allList.begin(); it != allList.end(); ++it ){ |
406 | qWarning("Adding Contact from: %s", (*it).fullName().latin1() ); | 406 | qWarning("Adding Contact from: %s", (*it).fullName().latin1() ); |
407 | if ( doAsk ){ | 407 | if ( doAsk ){ |
408 | switch( QMessageBox::information( this, tr ( "Add Contact?" ), | 408 | switch( QMessageBox::information( this, tr ( "Add Contact?" ), |
409 | tr( "Do you really want add contact for \n%1?" ) | 409 | tr( "Do you really want add contact for \n%1?" ) |
410 | .arg( (*it).fullName().latin1() ), | 410 | .arg( (*it).fullName().latin1() ), |
411 | tr( "&Yes" ), tr( "&No" ), tr( "&All Yes"), | 411 | tr( "&Yes" ), tr( "&No" ), tr( "&All Yes"), |
412 | 0, // Enter == button 0 | 412 | 0, // Enter == button 0 |
413 | 2 ) ) { // Escape == button 2 | 413 | 2 ) ) { // Escape == button 2 |
414 | case 0: | 414 | case 0: |
415 | qWarning("YES clicked"); | 415 | qWarning("YES clicked"); |
416 | m_abView->addEntry( *it ); | 416 | m_abView->addEntry( *it ); |
417 | break; | 417 | break; |
418 | case 1: | 418 | case 1: |
419 | qWarning("NO clicked"); | 419 | qWarning("NO clicked"); |
420 | break; | 420 | break; |
421 | case 2: | 421 | case 2: |
422 | qWarning("YesAll clicked"); | 422 | qWarning("YesAll clicked"); |
423 | doAsk = false; | 423 | doAsk = false; |
424 | break; | 424 | break; |
425 | } | 425 | } |
426 | }else | 426 | }else |
427 | m_abView->addEntry( *it ); | 427 | m_abView->addEntry( *it ); |
428 | 428 | ||
429 | } | 429 | } |
430 | 430 | ||
431 | delete access; | 431 | delete access; |
432 | } | 432 | } |
433 | 433 | ||
434 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) | 434 | void AddressbookWindow::resizeEvent( QResizeEvent *e ) |
435 | { | 435 | { |
436 | QMainWindow::resizeEvent( e ); | 436 | QMainWindow::resizeEvent( e ); |
437 | 437 | ||
438 | 438 | ||
439 | } | 439 | } |
440 | 440 | ||
441 | AddressbookWindow::~AddressbookWindow() | 441 | AddressbookWindow::~AddressbookWindow() |
442 | { | 442 | { |
443 | ToolBarDock dock; | 443 | ToolBarDock dock; |
444 | int dummy; | 444 | int dummy; |
445 | bool bDummy; | 445 | bool bDummy; |
446 | getLocation ( listTools, dock, dummy, bDummy, dummy ); | 446 | getLocation ( listTools, dock, dummy, bDummy, dummy ); |
447 | m_config.setToolBarDock( dock ); | 447 | m_config.setToolBarDock( dock ); |
448 | m_config.save(); | 448 | m_config.save(); |
449 | } | 449 | } |
450 | 450 | ||
451 | void AddressbookWindow::slotUpdateToolbar() | 451 | void AddressbookWindow::slotUpdateToolbar() |
452 | { | 452 | { |
453 | OContact ce = m_abView->currentEntry(); | 453 | OContact ce = m_abView->currentEntry(); |
454 | actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); | 454 | actionMail->setEnabled( !ce.defaultEmail().isEmpty() ); |
455 | } | 455 | } |
456 | 456 | ||
457 | void AddressbookWindow::slotListNew() | 457 | void AddressbookWindow::slotListNew() |
458 | { | 458 | { |
459 | OContact cnt; | 459 | OContact cnt; |
460 | if( !syncing ) { | 460 | if( !syncing ) { |
461 | editEntry( NewEntry ); | 461 | editEntry( NewEntry ); |
462 | } else { | 462 | } else { |
463 | QMessageBox::warning(this, tr("Contacts"), | 463 | QMessageBox::warning(this, tr("Contacts"), |
464 | tr("Can not edit data, currently syncing")); | 464 | tr("Can not edit data, currently syncing")); |
465 | } | 465 | } |
466 | } | 466 | } |
467 | 467 | ||
468 | // void AddressbookWindow::slotListView() | 468 | // void AddressbookWindow::slotListView() |
469 | // { | 469 | // { |
470 | // m_abView -> init( abList->currentEntry() ); | 470 | // m_abView -> init( abList->currentEntry() ); |
471 | // // :SX mView->sync(); | 471 | // // :SX mView->sync(); |
472 | // //:SXshowView(); | 472 | // //:SXshowView(); |
473 | // } | 473 | // } |
474 | 474 | ||
475 | void AddressbookWindow::slotListDelete() | 475 | void AddressbookWindow::slotListDelete() |
476 | { | 476 | { |
477 | if(!syncing) { | 477 | if(!syncing) { |
478 | OContact tmpEntry = m_abView ->currentEntry(); | 478 | OContact tmpEntry = m_abView ->currentEntry(); |
479 | 479 | ||
480 | // get a name, do the best we can... | 480 | // get a name, do the best we can... |
481 | QString strName = tmpEntry.fullName(); | 481 | QString strName = tmpEntry.fullName(); |
482 | if ( strName.isEmpty() ) { | 482 | if ( strName.isEmpty() ) { |
483 | strName = tmpEntry.company(); | 483 | strName = tmpEntry.company(); |
484 | if ( strName.isEmpty() ) | 484 | if ( strName.isEmpty() ) |
485 | strName = "No Name"; | 485 | strName = "No Name"; |
486 | } | 486 | } |
487 | 487 | ||
488 | 488 | ||
489 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), | 489 | if ( QPEMessageBox::confirmDelete( this, tr( "Contacts" ), |
490 | strName ) ) { | 490 | strName ) ) { |
491 | m_abView->removeEntry( tmpEntry.uid() ); | 491 | m_abView->removeEntry( tmpEntry.uid() ); |
492 | } | 492 | } |
493 | } else { | 493 | } else { |
494 | QMessageBox::warning( this, tr("Contacts"), | 494 | QMessageBox::warning( this, tr("Contacts"), |
495 | tr("Can not edit data, currently syncing") ); | 495 | tr("Can not edit data, currently syncing") ); |
496 | } | 496 | } |
497 | } | 497 | } |
498 | 498 | ||
499 | void AddressbookWindow::slotFindOpen() | 499 | void AddressbookWindow::slotFindOpen() |
500 | { | 500 | { |
501 | searchBar->show(); | 501 | searchBar->show(); |
502 | m_abView -> inSearch(); | 502 | m_abView -> inSearch(); |
503 | searchEdit->setFocus(); | 503 | searchEdit->setFocus(); |
504 | } | 504 | } |
505 | void AddressbookWindow::slotFindClose() | 505 | void AddressbookWindow::slotFindClose() |
506 | { | 506 | { |
507 | searchBar->hide(); | 507 | searchBar->hide(); |
508 | m_abView -> offSearch(); | 508 | m_abView -> offSearch(); |
509 | // m_abView->setFocus(); | 509 | // m_abView->setFocus(); |
510 | } | 510 | } |
511 | 511 | ||
512 | 512 | ||
513 | void AddressbookWindow::slotFind() | 513 | void AddressbookWindow::slotFind() |
514 | { | 514 | { |
515 | m_abView->slotDoFind( searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); | 515 | m_abView->slotDoFind( searchEdit->text(), m_config.beCaseSensitive(), m_config.useRegExp(), false); |
516 | 516 | ||
517 | searchEdit->clearFocus(); | 517 | searchEdit->clearFocus(); |
518 | // m_abView->setFocus(); | 518 | // m_abView->setFocus(); |
519 | 519 | ||
520 | } | 520 | } |
521 | 521 | ||
522 | void AddressbookWindow::slotViewBack() | 522 | void AddressbookWindow::slotViewBack() |
523 | { | 523 | { |
524 | // :SX showList(); | 524 | // :SX showList(); |
525 | } | 525 | } |
526 | 526 | ||
527 | void AddressbookWindow::slotViewEdit() | 527 | void AddressbookWindow::slotViewEdit() |
528 | { | 528 | { |
529 | if(!syncing) { | 529 | if(!syncing) { |
530 | if (actionPersonal->isOn()) { | 530 | if (actionPersonal->isOn()) { |
531 | editPersonal(); | 531 | editPersonal(); |
532 | } else { | 532 | } else { |
533 | editEntry( EditEntry ); | 533 | editEntry( EditEntry ); |
534 | } | 534 | } |
535 | } else { | 535 | } else { |
536 | QMessageBox::warning( this, tr("Contacts"), | 536 | QMessageBox::warning( this, tr("Contacts"), |
537 | tr("Can not edit data, currently syncing") ); | 537 | tr("Can not edit data, currently syncing") ); |
538 | } | 538 | } |
539 | } | 539 | } |
540 | 540 | ||
541 | 541 | ||
542 | 542 | ||
543 | void AddressbookWindow::writeMail() | 543 | void AddressbookWindow::writeMail() |
544 | { | 544 | { |
545 | OContact c = m_abView -> currentEntry(); | 545 | OContact c = m_abView -> currentEntry(); |
546 | QString name = c.fileAs(); | 546 | QString name = c.fileAs(); |
547 | QString email = c.defaultEmail(); | 547 | QString email = c.defaultEmail(); |
548 | 548 | ||
549 | // I prefer the OPIE-Environment variable before the | 549 | // I prefer the OPIE-Environment variable before the |
550 | // QPE-one.. | 550 | // QPE-one.. |
551 | QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); | 551 | QString basepath = QString::fromLatin1( getenv("OPIEDIR") ); |
552 | if ( basepath.isEmpty() ) | 552 | if ( basepath.isEmpty() ) |
553 | basepath = QString::fromLatin1( getenv("QPEDIR") ); | 553 | basepath = QString::fromLatin1( getenv("QPEDIR") ); |
554 | 554 | ||
555 | // Try to access the preferred. If not possible, try to | 555 | // Try to access the preferred. If not possible, try to |
556 | // switch to the other one.. | 556 | // switch to the other one.. |
557 | if ( m_config.useQtMail() ){ | 557 | if ( m_config.useQtMail() ){ |
558 | qWarning ("Accessing: %s", (basepath + "/bin/qtmail").latin1()); | 558 | qWarning ("Accessing: %s", (basepath + "/bin/qtmail").latin1()); |
559 | if ( QFile::exists( basepath + "/bin/qtmail" ) ){ | 559 | if ( QFile::exists( basepath + "/bin/qtmail" ) ){ |
560 | qWarning ("QCop"); | 560 | qWarning ("QCop"); |
561 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); | 561 | QCopEnvelope e("QPE/Application/qtmail", "writeMail(QString,QString)"); |
562 | e << name << email; | 562 | e << name << email; |
563 | return; | 563 | return; |
564 | } else | 564 | } else |
565 | m_config.setUseOpieMail( true ); | 565 | m_config.setUseOpieMail( true ); |
566 | } | 566 | } |
567 | if ( m_config.useOpieMail() ){ | 567 | if ( m_config.useOpieMail() ){ |
568 | qWarning ("Accessing: %s", (basepath + "/bin/mail").latin1()); | 568 | qWarning ("Accessing: %s", (basepath + "/bin/mail").latin1()); |
569 | if ( QFile::exists( basepath + "/bin/mail" ) ){ | 569 | if ( QFile::exists( basepath + "/bin/mail" ) ){ |
570 | qWarning ("QCop"); | 570 | qWarning ("QCop"); |
571 | QCopEnvelope e("QPE/Application/mail", "writeMail(QString,QString)"); | 571 | QCopEnvelope e("QPE/Application/mail", "writeMail(QString,QString)"); |
572 | e << name << email; | 572 | e << name << email; |
573 | return; | 573 | return; |
574 | } else | 574 | } else |
575 | m_config.setUseQtMail( true ); | 575 | m_config.setUseQtMail( true ); |
576 | } | 576 | } |
577 | 577 | ||
578 | } | 578 | } |
579 | 579 | ||
580 | static const char * beamfile = "/tmp/obex/contact.vcf"; | 580 | static const char * beamfile = "/tmp/obex/contact.vcf"; |
581 | 581 | ||
582 | void AddressbookWindow::slotBeam() | 582 | void AddressbookWindow::slotBeam() |
583 | { | 583 | { |
584 | QString beamFilename; | 584 | QString beamFilename; |
585 | OContact c; | 585 | OContact c; |
586 | if ( actionPersonal->isOn() ) { | 586 | if ( actionPersonal->isOn() ) { |
587 | beamFilename = addressbookPersonalVCardName(); | 587 | beamFilename = addressbookPersonalVCardName(); |
588 | if ( !QFile::exists( beamFilename ) ) | 588 | if ( !QFile::exists( beamFilename ) ) |
589 | return; // can't beam a non-existent file | 589 | return; // can't beam a non-existent file |
590 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 590 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
591 | beamFilename ); | 591 | beamFilename ); |
592 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 592 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
593 | OContactAccess::List allList = access->allRecords(); | 593 | OContactAccess::List allList = access->allRecords(); |
594 | OContactAccess::List::Iterator it = allList.begin(); // Just take first | 594 | OContactAccess::List::Iterator it = allList.begin(); // Just take first |
595 | c = *it; | 595 | c = *it; |
596 | 596 | ||
597 | delete access; | 597 | delete access; |
598 | } else { | 598 | } else { |
599 | unlink( beamfile ); // delete if exists | 599 | unlink( beamfile ); // delete if exists |
600 | mkdir("/tmp/obex/", 0755); | 600 | mkdir("/tmp/obex/", 0755); |
601 | c = m_abView -> currentEntry(); | 601 | c = m_abView -> currentEntry(); |
602 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, | 602 | OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, |
603 | beamfile ); | 603 | beamfile ); |
604 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); | 604 | OContactAccess* access = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); |
605 | access->add( c ); | 605 | access->add( c ); |
606 | access->save(); | 606 | access->save(); |
607 | delete access; | 607 | delete access; |
608 | 608 | ||
609 | beamFilename = beamfile; | 609 | beamFilename = beamfile; |
610 | } | 610 | } |
611 | 611 | ||
612 | qWarning("Beaming: %s", beamFilename.latin1() ); | 612 | qWarning("Beaming: %s", beamFilename.latin1() ); |
613 | 613 | ||
614 | Ir *ir = new Ir( this ); | 614 | Ir *ir = new Ir( this ); |
615 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 615 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
616 | QString description = c.fullName(); | 616 | QString description = c.fullName(); |
617 | ir->send( beamFilename, description, "text/x-vCard" ); | 617 | ir->send( beamFilename, description, "text/x-vCard" ); |
618 | } | 618 | } |
619 | 619 | ||
620 | void AddressbookWindow::beamDone( Ir *ir ) | 620 | void AddressbookWindow::beamDone( Ir *ir ) |
621 | { | 621 | { |
622 | 622 | ||
623 | delete ir; | 623 | delete ir; |
624 | unlink( beamfile ); | 624 | unlink( beamfile ); |
625 | } | 625 | } |
626 | 626 | ||
627 | 627 | ||
628 | static void parseName( const QString& name, QString *first, QString *middle, | 628 | static void parseName( const QString& name, QString *first, QString *middle, |
629 | QString * last ) | 629 | QString * last ) |
630 | { | 630 | { |
631 | 631 | ||
632 | int comma = name.find ( "," ); | 632 | int comma = name.find ( "," ); |
633 | QString rest; | 633 | QString rest; |
634 | if ( comma > 0 ) { | 634 | if ( comma > 0 ) { |
635 | *last = name.left( comma ); | 635 | *last = name.left( comma ); |
636 | comma++; | 636 | comma++; |
637 | while ( comma < int(name.length()) && name[comma] == ' ' ) | 637 | while ( comma < int(name.length()) && name[comma] == ' ' ) |
638 | comma++; | 638 | comma++; |
639 | rest = name.mid( comma ); | 639 | rest = name.mid( comma ); |
640 | } else { | 640 | } else { |
641 | int space = name.findRev( ' ' ); | 641 | int space = name.findRev( ' ' ); |
642 | *last = name.mid( space+1 ); | 642 | *last = name.mid( space+1 ); |
643 | rest = name.left( space ); | 643 | rest = name.left( space ); |
644 | } | 644 | } |
645 | int space = rest.find( ' ' ); | 645 | int space = rest.find( ' ' ); |
646 | if ( space <= 0 ) { | 646 | if ( space <= 0 ) { |
647 | *first = rest; | 647 | *first = rest; |
648 | } else { | 648 | } else { |
649 | *first = rest.left( space ); | 649 | *first = rest.left( space ); |
650 | *middle = rest.mid( space+1 ); | 650 | *middle = rest.mid( space+1 ); |
651 | } | 651 | } |
652 | 652 | ||
653 | } | 653 | } |
654 | 654 | ||
655 | 655 | ||
656 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) | 656 | void AddressbookWindow::appMessage(const QCString &msg, const QByteArray &data) |
657 | { | 657 | { |
658 | bool needShow = FALSE; | 658 | bool needShow = FALSE; |
659 | qWarning("Receiving QCop-Call with message %s", QString( msg ).latin1() ); | 659 | qWarning("Receiving QCop-Call with message %s", QString( msg ).latin1() ); |
660 | 660 | ||
661 | 661 | ||
662 | if (msg == "editPersonal()") { | 662 | if (msg == "editPersonal()") { |
663 | editPersonal(); | 663 | editPersonal(); |
664 | } else if (msg == "editPersonalAndClose()") { | 664 | } else if (msg == "editPersonalAndClose()") { |
665 | editPersonal(); | 665 | editPersonal(); |
666 | close(); | 666 | close(); |
667 | } else if ( msg == "addContact(QString,QString)" ) { | 667 | } else if ( msg == "addContact(QString,QString)" ) { |
668 | QDataStream stream(data,IO_ReadOnly); | 668 | QDataStream stream(data,IO_ReadOnly); |
669 | QString name, email; | 669 | QString name, email; |
670 | stream >> name >> email; | 670 | stream >> name >> email; |
671 | 671 | ||
672 | OContact cnt; | 672 | OContact cnt; |
673 | QString fn, mn, ln; | 673 | QString fn, mn, ln; |
674 | parseName( name, &fn, &mn, &ln ); | 674 | parseName( name, &fn, &mn, &ln ); |
675 | // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); | 675 | // qDebug( " %s - %s - %s", fn.latin1(), mn.latin1(), ln.latin1() ); |
676 | cnt.setFirstName( fn ); | 676 | cnt.setFirstName( fn ); |
677 | cnt.setMiddleName( mn ); | 677 | cnt.setMiddleName( mn ); |
678 | cnt.setLastName( ln ); | 678 | cnt.setLastName( ln ); |
679 | cnt.insertEmails( email ); | 679 | cnt.insertEmails( email ); |
680 | cnt.setDefaultEmail( email ); | 680 | cnt.setDefaultEmail( email ); |
681 | cnt.setFileAs(); | 681 | cnt.setFileAs(); |
682 | 682 | ||
683 | m_abView -> addEntry( cnt ); | 683 | m_abView -> addEntry( cnt ); |
684 | 684 | ||
685 | // :SXm_abView()->init( cnt ); | 685 | // :SXm_abView()->init( cnt ); |
686 | editEntry( EditEntry ); | 686 | editEntry( EditEntry ); |
687 | } else if ( msg == "beamBusinessCard()" ) { | 687 | } else if ( msg == "beamBusinessCard()" ) { |
688 | QString beamFilename = addressbookPersonalVCardName(); | 688 | QString beamFilename = addressbookPersonalVCardName(); |
689 | if ( !QFile::exists( beamFilename ) ) | 689 | if ( !QFile::exists( beamFilename ) ) |
690 | return; // can't beam a non-existent file | 690 | return; // can't beam a non-existent file |
691 | 691 | ||
692 | Ir *ir = new Ir( this ); | 692 | Ir *ir = new Ir( this ); |
693 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 693 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
694 | QString description = "mycard.vcf"; | 694 | QString description = "mycard.vcf"; |
695 | ir->send( beamFilename, description, "text/x-vCard" ); | 695 | ir->send( beamFilename, description, "text/x-vCard" ); |
696 | } else if ( msg == "show(int)" ) { | 696 | } else if ( msg == "show(int)" ) { |
697 | raise(); | 697 | raise(); |
698 | QDataStream stream(data,IO_ReadOnly); | 698 | QDataStream stream(data,IO_ReadOnly); |
699 | int uid; | 699 | int uid; |
700 | stream >> uid; | 700 | stream >> uid; |
701 | 701 | ||
702 | qWarning( "Showing uid: %d" , uid ); | 702 | qWarning( "Showing uid: %d" , uid ); |
703 | 703 | ||
704 | // Deactivate Personal View.. | 704 | // Deactivate Personal View.. |
705 | if ( actionPersonal->isOn() ){ | 705 | if ( actionPersonal->isOn() ){ |
706 | actionPersonal->setOn( false ); | 706 | actionPersonal->setOn( false ); |
707 | slotPersonalView(); | 707 | slotPersonalView(); |
708 | } | 708 | } |
709 | 709 | ||
710 | // Reset category and show as card.. | 710 | // Reset category and show as card.. |
711 | m_abView -> setShowByCategory( QString::null ); | 711 | m_abView -> setShowByCategory( QString::null ); |
712 | m_abView -> setCurrentUid( uid ); | 712 | m_abView -> setCurrentUid( uid ); |
713 | slotViewSwitched ( AbView::CardView ); | 713 | slotViewSwitched ( AbView::CardView ); |
714 | 714 | ||
715 | needShow = true; | 715 | needShow = true; |
716 | 716 | ||
717 | 717 | ||
718 | } else if ( msg == "edit(int)" ) { | 718 | } else if ( msg == "edit(int)" ) { |
719 | QDataStream stream(data,IO_ReadOnly); | 719 | QDataStream stream(data,IO_ReadOnly); |
720 | int uid; | 720 | int uid; |
721 | stream >> uid; | 721 | stream >> uid; |
722 | 722 | ||
723 | // Deactivate Personal View.. | 723 | // Deactivate Personal View.. |
724 | if ( actionPersonal->isOn() ){ | 724 | if ( actionPersonal->isOn() ){ |
725 | actionPersonal->setOn( false ); | 725 | actionPersonal->setOn( false ); |
726 | slotPersonalView(); | 726 | slotPersonalView(); |
727 | } | 727 | } |
728 | 728 | ||
729 | // Reset category and edit.. | 729 | // Reset category and edit.. |
730 | m_abView -> setShowByCategory( QString::null ); | 730 | m_abView -> setShowByCategory( QString::null ); |
731 | m_abView -> setCurrentUid( uid ); | 731 | m_abView -> setCurrentUid( uid ); |
732 | slotViewEdit(); | 732 | slotViewEdit(); |
733 | } | 733 | } |
734 | 734 | ||
735 | if (needShow) | 735 | if (needShow) |
736 | QPEApplication::setKeepRunning(); | 736 | QPEApplication::setKeepRunning(); |
737 | 737 | ||
738 | } | 738 | } |
739 | 739 | ||
740 | void AddressbookWindow::editEntry( EntryMode entryMode ) | 740 | void AddressbookWindow::editEntry( EntryMode entryMode ) |
741 | { | 741 | { |
742 | OContact entry; | 742 | OContact entry; |
743 | if ( !abEditor ) { | 743 | if ( !abEditor ) { |
744 | abEditor = new ContactEditor( entry, this, "editor" ); | 744 | abEditor = new ContactEditor( entry, this, "editor" ); |
745 | } | 745 | } |
746 | if ( entryMode == EditEntry ) | 746 | if ( entryMode == EditEntry ) |
747 | abEditor->setEntry( m_abView -> currentEntry() ); | 747 | abEditor->setEntry( m_abView -> currentEntry() ); |
748 | else if ( entryMode == NewEntry ) | 748 | else if ( entryMode == NewEntry ) |
749 | abEditor->setEntry( entry ); | 749 | abEditor->setEntry( entry ); |
750 | // other things may change the caption. | 750 | // other things may change the caption. |
751 | abEditor->setCaption( tr("Edit Address") ); | 751 | abEditor->setCaption( tr("Edit Address") ); |
752 | 752 | ||
753 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 753 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
754 | abEditor->showMaximized(); | 754 | abEditor->showMaximized(); |
755 | #endif | 755 | #endif |
756 | // fix the foxus... | 756 | // fix the foxus... |
757 | abEditor->setNameFocus(); | 757 | abEditor->setNameFocus(); |
758 | if ( abEditor->exec() ) { | 758 | if ( abEditor->exec() ) { |
759 | setFocus(); | 759 | setFocus(); |
760 | if ( entryMode == NewEntry ) { | 760 | if ( entryMode == NewEntry ) { |
761 | OContact insertEntry = abEditor->entry(); | 761 | OContact insertEntry = abEditor->entry(); |
762 | insertEntry.assignUid(); | 762 | insertEntry.assignUid(); |
763 | m_abView -> addEntry( insertEntry ); | 763 | m_abView -> addEntry( insertEntry ); |
764 | m_abView -> setCurrentUid( insertEntry.uid() ); | 764 | m_abView -> setCurrentUid( insertEntry.uid() ); |
765 | } else { | 765 | } else { |
766 | OContact replEntry = abEditor->entry(); | 766 | OContact replEntry = abEditor->entry(); |
767 | 767 | ||
768 | if ( !replEntry.isValidUid() ) | 768 | if ( !replEntry.isValidUid() ) |
769 | replEntry.assignUid(); | 769 | replEntry.assignUid(); |
770 | 770 | ||
771 | m_abView -> replaceEntry( replEntry ); | 771 | m_abView -> replaceEntry( replEntry ); |
772 | } | 772 | } |
773 | } | 773 | } |
774 | // populateCategories(); | 774 | // populateCategories(); |
775 | 775 | ||
776 | } | 776 | } |
777 | 777 | ||
778 | void AddressbookWindow::editPersonal() | 778 | void AddressbookWindow::editPersonal() |
779 | { | 779 | { |
780 | OContact entry; | 780 | OContact entry; |
781 | 781 | ||
782 | // Switch to personal view if not selected | 782 | // Switch to personal view if not selected |
783 | // but take care of the menu, too | 783 | // but take care of the menu, too |
784 | if ( ! actionPersonal->isOn() ){ | 784 | if ( ! actionPersonal->isOn() ){ |
785 | qWarning("*** ++++"); | 785 | qWarning("*** ++++"); |
786 | actionPersonal->setOn( true ); | 786 | actionPersonal->setOn( true ); |
787 | slotPersonalView(); | 787 | slotPersonalView(); |
788 | } | 788 | } |
789 | 789 | ||
790 | if ( !abEditor ) { | 790 | if ( !abEditor ) { |
791 | abEditor = new ContactEditor( entry, this, "editor" ); | 791 | abEditor = new ContactEditor( entry, this, "editor" ); |
792 | } | 792 | } |
793 | 793 | ||
794 | abEditor->setCaption(tr("Edit My Personal Details")); | 794 | abEditor->setCaption(tr("Edit My Personal Details")); |
795 | abEditor->setPersonalView( true ); | 795 | abEditor->setPersonalView( true ); |
796 | editEntry( EditEntry ); | 796 | editEntry( EditEntry ); |
797 | abEditor->setPersonalView( false ); | 797 | abEditor->setPersonalView( false ); |
798 | 798 | ||
799 | } | 799 | } |
800 | 800 | ||
801 | 801 | ||
802 | void AddressbookWindow::slotPersonalView() | 802 | void AddressbookWindow::slotPersonalView() |
803 | { | 803 | { |
804 | qWarning("slotPersonalView()"); | 804 | qWarning("slotPersonalView()"); |
805 | if (!actionPersonal->isOn()) { | 805 | if (!actionPersonal->isOn()) { |
806 | // we just turned it off | 806 | // we just turned it off |
807 | qWarning("slotPersonalView()-> OFF"); | 807 | qWarning("slotPersonalView()-> OFF"); |
808 | setCaption( tr("Contacts") ); | 808 | setCaption( tr("Contacts") ); |
809 | actionNew->setEnabled(TRUE); | 809 | actionNew->setEnabled(TRUE); |
810 | actionTrash->setEnabled(TRUE); | 810 | actionTrash->setEnabled(TRUE); |
811 | actionFind->setEnabled(TRUE); | 811 | actionFind->setEnabled(TRUE); |
812 | actionMail->setEnabled(TRUE); | 812 | actionMail->setEnabled(TRUE); |
813 | // slotUpdateToolbar(); | 813 | // slotUpdateToolbar(); |
814 | 814 | ||
815 | m_abView->showPersonal( false ); | 815 | m_abView->showPersonal( false ); |
816 | 816 | ||
817 | return; | 817 | return; |
818 | } | 818 | } |
819 | 819 | ||
820 | qWarning("slotPersonalView()-> ON"); | 820 | qWarning("slotPersonalView()-> ON"); |
821 | // XXX need to disable some QActions. | 821 | // XXX need to disable some QActions. |
822 | actionNew->setEnabled(FALSE); | 822 | actionNew->setEnabled(FALSE); |
823 | actionTrash->setEnabled(FALSE); | 823 | actionTrash->setEnabled(FALSE); |
824 | actionFind->setEnabled(FALSE); | 824 | actionFind->setEnabled(FALSE); |
825 | actionMail->setEnabled(FALSE); | 825 | actionMail->setEnabled(FALSE); |
826 | 826 | ||
827 | setCaption( tr("Contacts - My Personal Details") ); | 827 | setCaption( tr("Contacts - My Personal Details") ); |
828 | 828 | ||
829 | m_abView->showPersonal( true ); | 829 | m_abView->showPersonal( true ); |
830 | 830 | ||
831 | } | 831 | } |
832 | 832 | ||
833 | 833 | ||
834 | void AddressbookWindow::listIsEmpty( bool empty ) | 834 | void AddressbookWindow::listIsEmpty( bool empty ) |
835 | { | 835 | { |
836 | if ( !empty ) { | 836 | if ( !empty ) { |
837 | deleteButton->setEnabled( TRUE ); | 837 | deleteButton->setEnabled( TRUE ); |
838 | } | 838 | } |
839 | } | 839 | } |
840 | 840 | ||
841 | void AddressbookWindow::reload() | 841 | void AddressbookWindow::reload() |
842 | { | 842 | { |
843 | syncing = FALSE; | 843 | syncing = FALSE; |
844 | m_abView->clear(); | 844 | m_abView->clear(); |
845 | m_abView->reload(); | 845 | m_abView->reload(); |
846 | } | 846 | } |
847 | 847 | ||
848 | void AddressbookWindow::flush() | 848 | void AddressbookWindow::flush() |
849 | { | 849 | { |
850 | syncing = TRUE; | 850 | syncing = TRUE; |
851 | m_abView->save(); | 851 | m_abView->save(); |
852 | } | 852 | } |
853 | 853 | ||
854 | 854 | ||
855 | void AddressbookWindow::closeEvent( QCloseEvent *e ) | 855 | void AddressbookWindow::closeEvent( QCloseEvent *e ) |
856 | { | 856 | { |
857 | if(active_view == AbView::CardView){ | 857 | if(active_view == AbView::CardView){ |
858 | slotViewSwitched( AbView::TableView ); | 858 | slotViewSwitched( AbView::TableView ); |
859 | e->ignore(); | 859 | e->ignore(); |
860 | return; | 860 | return; |
861 | } | 861 | } |
862 | if(syncing) { | 862 | if(syncing) { |
863 | /* shouldn't we save, I hear you say? well its already been set | 863 | /* shouldn't we save, I hear you say? well its already been set |
864 | so that an edit can not occur during a sync, and we flushed | 864 | so that an edit can not occur during a sync, and we flushed |
865 | at the start of the sync, so there is no need to save | 865 | at the start of the sync, so there is no need to save |
866 | Saving however itself would cause problems. */ | 866 | Saving however itself would cause problems. */ |
867 | e->accept(); | 867 | e->accept(); |
868 | return; | 868 | return; |
869 | } | 869 | } |
870 | //################## shouldn't always save | 870 | //################## shouldn't always save |
871 | // True, but the database handles this automatically ! (se) | 871 | // True, but the database handles this automatically ! (se) |
872 | if ( save() ) | 872 | if ( save() ) |
873 | e->accept(); | 873 | e->accept(); |
874 | else | 874 | else |
875 | e->ignore(); | 875 | e->ignore(); |
876 | } | 876 | } |
877 | 877 | ||
878 | /* | 878 | /* |
879 | Returns TRUE if it is OK to exit | 879 | Returns TRUE if it is OK to exit |
880 | */ | 880 | */ |
881 | 881 | ||
882 | bool AddressbookWindow::save() | 882 | bool AddressbookWindow::save() |
883 | { | 883 | { |
884 | if ( !m_abView->save() ) { | 884 | if ( !m_abView->save() ) { |
885 | if ( QMessageBox::critical( 0, tr( "Out of space" ), | 885 | if ( QMessageBox::critical( 0, tr( "Out of space" ), |
886 | tr("Unable to save information.\n" | 886 | tr("Unable to save information.\n" |
887 | "Free up some space\n" | 887 | "Free up some space\n" |
888 | "and try again.\n" | 888 | "and try again.\n" |
889 | "\nQuit anyway?"), | 889 | "\nQuit anyway?"), |
890 | QMessageBox::Yes|QMessageBox::Escape, | 890 | QMessageBox::Yes|QMessageBox::Escape, |
891 | QMessageBox::No|QMessageBox::Default ) | 891 | QMessageBox::No|QMessageBox::Default ) |
892 | != QMessageBox::No ) | 892 | != QMessageBox::No ) |
893 | return TRUE; | 893 | return TRUE; |
894 | else | 894 | else |
895 | return FALSE; | 895 | return FALSE; |
896 | } | 896 | } |
897 | return TRUE; | 897 | return TRUE; |
898 | } | 898 | } |
899 | 899 | ||
900 | #ifdef __DEBUG_RELEASE | 900 | #ifdef __DEBUG_RELEASE |
901 | void AddressbookWindow::slotSave() | 901 | void AddressbookWindow::slotSave() |
902 | { | 902 | { |
903 | save(); | 903 | save(); |
904 | } | 904 | } |
905 | #endif | 905 | #endif |
906 | 906 | ||
907 | 907 | ||
908 | void AddressbookWindow::slotNotFound() | 908 | void AddressbookWindow::slotNotFound() |
909 | { | 909 | { |
910 | qWarning("Got notfound signal!"); | 910 | qWarning("Got notfound signal!"); |
911 | QMessageBox::information( this, tr( "Not Found" ), | 911 | QMessageBox::information( this, tr( "Not Found" ), |
912 | "<qt>" + tr( "Unable to find a contact for this search pattern!" ) + "</qt>" ); | 912 | "<qt>" + tr( "Unable to find a contact for this search pattern!" ) + "</qt>" ); |
913 | 913 | ||
914 | 914 | ||
915 | } | 915 | } |
916 | void AddressbookWindow::slotWrapAround() | 916 | void AddressbookWindow::slotWrapAround() |
917 | { | 917 | { |
918 | qWarning("Got wrap signal!"); | 918 | qWarning("Got wrap signal!"); |
919 | // if ( doNotifyWrapAround ) | 919 | // if ( doNotifyWrapAround ) |
920 | // QMessageBox::information( this, tr( "End of list" ), | 920 | // QMessageBox::information( this, tr( "End of list" ), |
921 | // tr( "End of list. Wrap around now...!" ) + "\n" ); | 921 | // tr( "End of list. Wrap around now...!" ) + "\n" ); |
922 | 922 | ||
923 | } | 923 | } |
924 | 924 | ||
925 | void AddressbookWindow::slotSetCategory( int c ) | 925 | void AddressbookWindow::slotSetCategory( int c ) |
926 | { | 926 | { |
927 | qWarning( "void AddressbookWindow::slotSetCategory( %d ) from %d", c, catMenu->count() ); | 927 | qWarning( "void AddressbookWindow::slotSetCategory( %d ) from %d", c, catMenu->count() ); |
928 | 928 | ||
929 | QString cat, book; | 929 | QString cat, book; |
930 | AbView::Views view = AbView::TableView; | 930 | AbView::Views view = AbView::TableView; |
931 | 931 | ||
932 | if ( c <= 0 ) | 932 | if ( c <= 0 ) |
933 | return; | 933 | return; |
934 | 934 | ||
935 | // Switch view | 935 | // Switch view |
936 | if ( c < 3 ) | 936 | if ( c < 3 ) |
937 | for ( unsigned int i = 1; i < 3; i++ ){ | 937 | for ( unsigned int i = 1; i < 3; i++ ){ |
938 | if ( catMenu ) | 938 | if ( catMenu ) |
939 | catMenu->setItemChecked( i, c == (int)i ); | 939 | catMenu->setItemChecked( i, c == (int)i ); |
940 | } | 940 | } |
941 | else | 941 | else |
942 | // Checkmark Category Menu Item Selected | 942 | // Checkmark Category Menu Item Selected |
943 | for ( unsigned int i = 3; i < catMenu->count(); i++ ) | 943 | for ( unsigned int i = 3; i < catMenu->count(); i++ ) |
944 | catMenu->setItemChecked( i, c == (int)i ); | 944 | catMenu->setItemChecked( i, c == (int)i ); |
945 | 945 | ||
946 | // Now switch to the selected category | 946 | // Now switch to the selected category |
947 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) { | 947 | for ( unsigned int i = 1; i < catMenu->count(); i++ ) { |
948 | if (catMenu->isItemChecked( i )) { | 948 | if (catMenu->isItemChecked( i )) { |
949 | if ( i == 1 ){ // default List view | 949 | if ( i == 1 ){ // default List view |
950 | book = QString::null; | 950 | book = QString::null; |
951 | view = AbView::TableView; | 951 | view = AbView::TableView; |
952 | }else if ( i == 2 ){ | 952 | }else if ( i == 2 ){ |
953 | book = tr( "Cards" ); | 953 | book = tr( "Cards" ); |
954 | view = AbView::CardView; | 954 | view = AbView::CardView; |
955 | // }else if ( i == 3 ){ | 955 | // }else if ( i == 3 ){ |
956 | // book = tr( "Personal" ); | 956 | // book = tr( "Personal" ); |
957 | // view = AbView:: PersonalView; | 957 | // view = AbView:: PersonalView; |
958 | }else if ( i == 3 ){ // default All Categories | 958 | }else if ( i == 3 ){ // default All Categories |
959 | cat = QString::null; | 959 | cat = QString::null; |
960 | }else if ( i == (unsigned int)catMenu->count() - 1 ){ // last menu option (seperator is counted, too) will be Unfiled | 960 | }else if ( i == (unsigned int)catMenu->count() - 1 ){ // last menu option (seperator is counted, too) will be Unfiled |
961 | cat = "Unfiled"; | 961 | cat = "Unfiled"; |
962 | qWarning ("Unfiled selected!"); | 962 | qWarning ("Unfiled selected!"); |
963 | }else{ | 963 | }else{ |
964 | cat = m_abView->categories()[i - 4]; | 964 | cat = m_abView->categories()[i - 4]; |
965 | } | 965 | } |
966 | } | 966 | } |
967 | } | 967 | } |
968 | 968 | ||
969 | // Switch to the selected View | 969 | // Switch to the selected View |
970 | slotViewSwitched( view ); | 970 | slotViewSwitched( view ); |
971 | 971 | ||
972 | // Tell the view about the selected category | 972 | // Tell the view about the selected category |
973 | m_abView -> setShowByCategory( cat ); | 973 | m_abView -> setShowByCategory( cat ); |
974 | 974 | ||
975 | if ( book.isEmpty() ) | 975 | if ( book.isEmpty() ) |
976 | book = "List"; | 976 | book = "List"; |
977 | if ( cat.isEmpty() ) | 977 | if ( cat.isEmpty() ) |
978 | cat = "All"; | 978 | cat = "All"; |
979 | 979 | ||
980 | setCaption( tr( "Contacts" ) + " - " + book + " - " + tr( cat ) ); | 980 | setCaption( tr( "Contacts" ) + " - " + book + " - " + tr( cat ) ); |
981 | } | 981 | } |
982 | 982 | ||
983 | void AddressbookWindow::slotViewSwitched( int view ) | 983 | void AddressbookWindow::slotViewSwitched( int view ) |
984 | { | 984 | { |
985 | qWarning( "void AddressbookWindow::slotViewSwitched( %d )", view ); | 985 | qWarning( "void AddressbookWindow::slotViewSwitched( %d )", view ); |
986 | int menu = 0; | 986 | int menu = 0; |
987 | 987 | ||
988 | // Switch to selected view | 988 | // Switch to selected view |
989 | switch ( view ){ | 989 | switch ( view ){ |
990 | case AbView::TableView: | 990 | case AbView::TableView: |
991 | menu = 1; | 991 | menu = 1; |
992 | m_tableViewButton->setOn(true); | 992 | m_tableViewButton->setOn(true); |
993 | m_cardViewButton->setOn(false); | 993 | m_cardViewButton->setOn(false); |
994 | break; | 994 | break; |
995 | case AbView::CardView: | 995 | case AbView::CardView: |
996 | menu = 2; | 996 | menu = 2; |
997 | m_tableViewButton->setOn(false); | 997 | m_tableViewButton->setOn(false); |
998 | m_cardViewButton->setOn(true); | 998 | m_cardViewButton->setOn(true); |
999 | break; | 999 | break; |
1000 | } | 1000 | } |
1001 | for ( unsigned int i = 1; i < 3; i++ ){ | 1001 | for ( unsigned int i = 1; i < 3; i++ ){ |
1002 | if ( catMenu ) | 1002 | if ( catMenu ) |
1003 | catMenu->setItemChecked( i, menu == (int)i ); | 1003 | catMenu->setItemChecked( i, menu == (int)i ); |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | // Tell the view about the selected view | 1006 | // Tell the view about the selected view |
1007 | m_abView -> setShowToView ( (AbView::Views) view ); | 1007 | m_abView -> setShowToView ( (AbView::Views) view ); |
1008 | active_view = view; | 1008 | active_view = view; |
1009 | } | 1009 | } |
1010 | 1010 | ||
1011 | 1011 | ||
1012 | void AddressbookWindow::slotListView() | 1012 | void AddressbookWindow::slotListView() |
1013 | { | 1013 | { |
1014 | slotViewSwitched( AbView::TableView ); | 1014 | slotViewSwitched( AbView::TableView ); |
1015 | } | 1015 | } |
1016 | 1016 | ||
1017 | void AddressbookWindow::slotCardView() | 1017 | void AddressbookWindow::slotCardView() |
1018 | { | 1018 | { |
1019 | slotViewSwitched( AbView::CardView ); | 1019 | slotViewSwitched( AbView::CardView ); |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | void AddressbookWindow::slotSetLetter( char c ) { | 1022 | void AddressbookWindow::slotSetLetter( char c ) { |
1023 | 1023 | ||
1024 | m_abView->setShowByLetter( c, m_config.letterPickerSearch() ); | 1024 | m_abView->setShowByLetter( c, m_config.letterPickerSearch() ); |
1025 | 1025 | ||
1026 | } | 1026 | } |
1027 | 1027 | ||
1028 | 1028 | ||
1029 | void AddressbookWindow::populateCategories() | 1029 | void AddressbookWindow::populateCategories() |
1030 | { | 1030 | { |
1031 | catMenu->clear(); | 1031 | catMenu->clear(); |
1032 | 1032 | ||
1033 | int id, rememberId; | 1033 | int id, rememberId; |
1034 | id = 1; | 1034 | id = 1; |
1035 | rememberId = 0; | 1035 | rememberId = 0; |
1036 | 1036 | ||
1037 | catMenu->insertItem( Resource::loadPixmap( "addressbook/listview" ), tr( "List" ), id++ ); | 1037 | catMenu->insertItem( Resource::loadPixmap( "addressbook/listview" ), tr( "List" ), id++ ); |
1038 | catMenu->insertItem( Resource::loadPixmap( "addressbook/cardview" ), tr( "Cards" ), id++ ); | 1038 | catMenu->insertItem( Resource::loadPixmap( "addressbook/cardview" ), tr( "Cards" ), id++ ); |
1039 | // catMenu->insertItem( tr( "Personal" ), id++ ); | 1039 | // catMenu->insertItem( tr( "Personal" ), id++ ); |
1040 | catMenu->insertSeparator(); | 1040 | catMenu->insertSeparator(); |
1041 | 1041 | ||
1042 | catMenu->insertItem( tr( "All" ), id++ ); | 1042 | catMenu->insertItem( tr( "All" ), id++ ); |
1043 | QStringList categories = m_abView->categories(); | 1043 | QStringList categories = m_abView->categories(); |
1044 | categories.append( tr( "Unfiled" ) ); | 1044 | categories.append( tr( "Unfiled" ) ); |
1045 | for ( QStringList::Iterator it = categories.begin(); | 1045 | for ( QStringList::Iterator it = categories.begin(); |
1046 | it != categories.end(); ++it ) { | 1046 | it != categories.end(); ++it ) { |
1047 | catMenu->insertItem( *it, id ); | 1047 | catMenu->insertItem( *it, id ); |
1048 | if ( *it == m_abView -> showCategory() ) | 1048 | if ( *it == m_abView -> showCategory() ) |
1049 | rememberId = id; | 1049 | rememberId = id; |
1050 | ++id; | 1050 | ++id; |
1051 | } | 1051 | } |
1052 | 1052 | ||
1053 | 1053 | ||
1054 | if ( m_abView -> showCategory().isEmpty() ) { | 1054 | if ( m_abView -> showCategory().isEmpty() ) { |
1055 | slotSetCategory( 3 ); | 1055 | slotSetCategory( 3 ); |
1056 | } | 1056 | } |
1057 | else { | 1057 | else { |
1058 | slotSetCategory( rememberId ); | 1058 | slotSetCategory( rememberId ); |
1059 | } | 1059 | } |
1060 | } | 1060 | } |
1061 | 1061 | ||
diff --git a/core/pim/addressbook/addressbook.h b/core/pim/addressbook/addressbook.h index 34bcb2a..9217e95 100644 --- a/core/pim/addressbook/addressbook.h +++ b/core/pim/addressbook/addressbook.h | |||
@@ -1,137 +1,137 @@ | |||
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 Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop 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 | #ifndef Addressbook_H | 20 | #ifndef Addressbook_H |
21 | #define Addressbook_H | 21 | #define Addressbook_H |
22 | 22 | ||
23 | // Remove this for OPIE releae 1.0 ! | 23 | // Remove this for OPIE releae 1.0 ! |
24 | // #define __DEBUG_RELEASE | 24 | // #define __DEBUG_RELEASE |
25 | 25 | ||
26 | #include <qmainwindow.h> | 26 | #include <qmainwindow.h> |
27 | #include <qvaluelist.h> | 27 | #include <qvaluelist.h> |
28 | #include <qstringlist.h> | 28 | #include <qstringlist.h> |
29 | #include <qlineedit.h> | 29 | #include <qlineedit.h> |
30 | #include "ofloatbar.h" | 30 | #include "ofloatbar.h" |
31 | #include "abview.h" | 31 | #include "abview.h" |
32 | #include "abconfig.h" | 32 | #include "abconfig.h" |
33 | 33 | ||
34 | class ContactEditor; | 34 | class ContactEditor; |
35 | class AbLabel; | 35 | class AbLabel; |
36 | class AbTable; | 36 | class AbTable; |
37 | class QPEToolBar; | 37 | class QToolBar; |
38 | class QPopupMenu; | 38 | class QPopupMenu; |
39 | class QToolButton; | 39 | class QToolButton; |
40 | class QDialog; | 40 | class QDialog; |
41 | class Ir; | 41 | class Ir; |
42 | class QAction; | 42 | class QAction; |
43 | class LetterPicker; | 43 | class LetterPicker; |
44 | 44 | ||
45 | class AddressbookWindow: public QMainWindow | 45 | class AddressbookWindow: public QMainWindow |
46 | { | 46 | { |
47 | Q_OBJECT | 47 | Q_OBJECT |
48 | public: | 48 | public: |
49 | enum EntryMode { NewEntry=0, EditEntry }; | 49 | enum EntryMode { NewEntry=0, EditEntry }; |
50 | 50 | ||
51 | static QString appName() { return QString::fromLatin1("addressbook"); } | 51 | static QString appName() { return QString::fromLatin1("addressbook"); } |
52 | AddressbookWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 52 | AddressbookWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
53 | ~AddressbookWindow(); | 53 | ~AddressbookWindow(); |
54 | 54 | ||
55 | protected: | 55 | protected: |
56 | void resizeEvent( QResizeEvent * e ); | 56 | void resizeEvent( QResizeEvent * e ); |
57 | 57 | ||
58 | void editPersonal(); | 58 | void editPersonal(); |
59 | void editEntry( EntryMode ); | 59 | void editEntry( EntryMode ); |
60 | void closeEvent( QCloseEvent *e ); | 60 | void closeEvent( QCloseEvent *e ); |
61 | bool save(); | 61 | bool save(); |
62 | 62 | ||
63 | public slots: | 63 | public slots: |
64 | void flush(); | 64 | void flush(); |
65 | void reload(); | 65 | void reload(); |
66 | void appMessage(const QCString &, const QByteArray &); | 66 | void appMessage(const QCString &, const QByteArray &); |
67 | void setDocument( const QString & ); | 67 | void setDocument( const QString & ); |
68 | #ifdef __DEBUG_RELEASE | 68 | #ifdef __DEBUG_RELEASE |
69 | // void slotSave(); | 69 | // void slotSave(); |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | private slots: | 72 | private slots: |
73 | void importvCard(); | 73 | void importvCard(); |
74 | void exportvCard(); | 74 | void exportvCard(); |
75 | void slotListNew(); | 75 | void slotListNew(); |
76 | /* void slotListView(); */ | 76 | /* void slotListView(); */ |
77 | void slotListDelete(); | 77 | void slotListDelete(); |
78 | void slotViewBack(); | 78 | void slotViewBack(); |
79 | void slotViewEdit(); | 79 | void slotViewEdit(); |
80 | void slotPersonalView(); | 80 | void slotPersonalView(); |
81 | void listIsEmpty( bool ); | 81 | void listIsEmpty( bool ); |
82 | /* void slotSettings(); */ | 82 | /* void slotSettings(); */ |
83 | void writeMail(); | 83 | void writeMail(); |
84 | void slotBeam(); | 84 | void slotBeam(); |
85 | void beamDone( Ir * ); | 85 | void beamDone( Ir * ); |
86 | void slotSetCategory( int ); | 86 | void slotSetCategory( int ); |
87 | void slotSetLetter( char ); | 87 | void slotSetLetter( char ); |
88 | void slotUpdateToolbar(); | 88 | void slotUpdateToolbar(); |
89 | void slotSetFont(int); | 89 | void slotSetFont(int); |
90 | 90 | ||
91 | void slotFindOpen(); | 91 | void slotFindOpen(); |
92 | void slotFindClose(); | 92 | void slotFindClose(); |
93 | void slotFind(); | 93 | void slotFind(); |
94 | void slotNotFound(); | 94 | void slotNotFound(); |
95 | void slotWrapAround(); | 95 | void slotWrapAround(); |
96 | 96 | ||
97 | void slotViewSwitched( int ); | 97 | void slotViewSwitched( int ); |
98 | void slotListView(); | 98 | void slotListView(); |
99 | void slotCardView(); | 99 | void slotCardView(); |
100 | 100 | ||
101 | void slotConfig(); | 101 | void slotConfig(); |
102 | 102 | ||
103 | private: | 103 | private: |
104 | void populateCategories(); | 104 | void populateCategories(); |
105 | 105 | ||
106 | QPopupMenu *catMenu; | 106 | QPopupMenu *catMenu; |
107 | QPEToolBar *listTools; | 107 | QToolBar *listTools; |
108 | QToolButton *deleteButton; | 108 | QToolButton *deleteButton; |
109 | enum Panes { paneList=0, paneView, paneEdit }; | 109 | enum Panes { paneList=0, paneView, paneEdit }; |
110 | ContactEditor *abEditor; | 110 | ContactEditor *abEditor; |
111 | LetterPicker *pLabel; | 111 | LetterPicker *pLabel; |
112 | AbView* m_abView; | 112 | AbView* m_abView; |
113 | QWidget *listContainer; | 113 | QWidget *listContainer; |
114 | 114 | ||
115 | // Searching stuff | 115 | // Searching stuff |
116 | OFloatBar* searchBar; | 116 | OFloatBar* searchBar; |
117 | QLineEdit* searchEdit; | 117 | QLineEdit* searchEdit; |
118 | 118 | ||
119 | QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, *actionPersonal, *actionMail; | 119 | QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, *actionPersonal, *actionMail; |
120 | 120 | ||
121 | int viewMargin; | 121 | int viewMargin; |
122 | 122 | ||
123 | bool syncing; | 123 | bool syncing; |
124 | QFont *defaultFont; | 124 | QFont *defaultFont; |
125 | int m_curFontSize; | 125 | int m_curFontSize; |
126 | 126 | ||
127 | bool isLoading; | 127 | bool isLoading; |
128 | 128 | ||
129 | AbConfig m_config; | 129 | AbConfig m_config; |
130 | 130 | ||
131 | QAction* m_tableViewButton; | 131 | QAction* m_tableViewButton; |
132 | QAction* m_cardViewButton; | 132 | QAction* m_cardViewButton; |
133 | 133 | ||
134 | int active_view; | 134 | int active_view; |
135 | }; | 135 | }; |
136 | 136 | ||
137 | #endif | 137 | #endif |
diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index a040d7c..44f1515 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp | |||
@@ -1,1099 +1,1099 @@ | |||
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 | ** $Id$ | 19 | ** $Id$ |
20 | ** | 20 | ** |
21 | **********************************************************************/ | 21 | **********************************************************************/ |
22 | 22 | ||
23 | #define QTOPIA_INTERNAL_FD | 23 | #define QTOPIA_INTERNAL_FD |
24 | 24 | ||
25 | #include "datebook.h" | 25 | #include "datebook.h" |
26 | #include "datebookday.h" | 26 | #include "datebookday.h" |
27 | #include "datebooksettings.h" | 27 | #include "datebooksettings.h" |
28 | #include "datebookweek.h" | 28 | #include "datebookweek.h" |
29 | #include "datebookweeklst.h" | 29 | #include "datebookweeklst.h" |
30 | #include "dateentryimpl.h" | 30 | #include "dateentryimpl.h" |
31 | 31 | ||
32 | #include <qpe/datebookmonth.h> | 32 | #include <qpe/datebookmonth.h> |
33 | #include <qpe/qpeapplication.h> | 33 | #include <qpe/qpeapplication.h> |
34 | #include <qpe/config.h> | 34 | #include <qpe/config.h> |
35 | #include <qpe/qpedebug.h> | 35 | #include <qpe/qpedebug.h> |
36 | #include <qpe/event.h> | 36 | #include <qpe/event.h> |
37 | #include <qpe/finddialog.h> | 37 | #include <qpe/finddialog.h> |
38 | #include <qpe/ir.h> | 38 | #include <qpe/ir.h> |
39 | #include <qmenubar.h> | 39 | #include <qmenubar.h> |
40 | #include <qpe/qpemessagebox.h> | 40 | #include <qpe/qpemessagebox.h> |
41 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
42 | #include <qpe/sound.h> | 42 | #include <qpe/sound.h> |
43 | #include <qpe/timestring.h> | 43 | #include <qpe/timestring.h> |
44 | #include <qpe/qpetoolbar.h> | 44 | #include <qtoolbar.h> |
45 | #include <qpe/tzselect.h> | 45 | #include <qpe/tzselect.h> |
46 | #include <qpe/xmlreader.h> | 46 | #include <qpe/xmlreader.h> |
47 | 47 | ||
48 | #include <qaction.h> | 48 | #include <qaction.h> |
49 | #include <qcopchannel_qws.h> | 49 | #include <qcopchannel_qws.h> |
50 | #include <qdatetime.h> | 50 | #include <qdatetime.h> |
51 | #include <qdialog.h> | 51 | #include <qdialog.h> |
52 | #include <qfile.h> | 52 | #include <qfile.h> |
53 | #include <qlabel.h> | 53 | #include <qlabel.h> |
54 | #include <qlayout.h> | 54 | #include <qlayout.h> |
55 | #include <qmessagebox.h> | 55 | #include <qmessagebox.h> |
56 | #include <qpopupmenu.h> | 56 | #include <qpopupmenu.h> |
57 | #include <qpushbutton.h> | 57 | #include <qpushbutton.h> |
58 | #include <qregexp.h> | 58 | #include <qregexp.h> |
59 | #include <qtextcodec.h> | 59 | #include <qtextcodec.h> |
60 | #include <qtextstream.h> | 60 | #include <qtextstream.h> |
61 | #include <qtimer.h> | 61 | #include <qtimer.h> |
62 | #include <qtl.h> | 62 | #include <qtl.h> |
63 | #include <qwidgetstack.h> | 63 | #include <qwidgetstack.h> |
64 | #include <qwindowsystem_qws.h> | 64 | #include <qwindowsystem_qws.h> |
65 | 65 | ||
66 | #include <sys/stat.h> | 66 | #include <sys/stat.h> |
67 | #include <sys/types.h> | 67 | #include <sys/types.h> |
68 | #include <fcntl.h> | 68 | #include <fcntl.h> |
69 | #include <unistd.h> | 69 | #include <unistd.h> |
70 | 70 | ||
71 | #include <stdlib.h> | 71 | #include <stdlib.h> |
72 | 72 | ||
73 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) | 73 | DateBook::DateBook( QWidget *parent, const char *, WFlags f ) |
74 | : QMainWindow( parent, "datebook", f ), | 74 | : QMainWindow( parent, "datebook", f ), |
75 | aPreset( FALSE ), | 75 | aPreset( FALSE ), |
76 | presetTime( -1 ), | 76 | presetTime( -1 ), |
77 | startTime( 8 ), // an acceptable default | 77 | startTime( 8 ), // an acceptable default |
78 | rowStyle( 0 ), | 78 | rowStyle( 0 ), |
79 | bJumpToCurTime(FALSE), | 79 | bJumpToCurTime(FALSE), |
80 | syncing(FALSE), | 80 | syncing(FALSE), |
81 | inSearch(FALSE), | 81 | inSearch(FALSE), |
82 | alarmCounter(0) | 82 | alarmCounter(0) |
83 | { | 83 | { |
84 | bool needEvilHack= false; // if we need an Evil Hack | 84 | bool needEvilHack= false; // if we need an Evil Hack |
85 | QTime t; | 85 | QTime t; |
86 | t.start(); | 86 | t.start(); |
87 | db = new DateBookDBHack; | 87 | db = new DateBookDBHack; |
88 | qDebug("loading db t=%d", t.elapsed() ); | 88 | qDebug("loading db t=%d", t.elapsed() ); |
89 | loadSettings(); | 89 | loadSettings(); |
90 | setCaption( tr("Calendar") ); | 90 | setCaption( tr("Calendar") ); |
91 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); | 91 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); |
92 | 92 | ||
93 | setToolBarsMovable( FALSE ); | 93 | setToolBarsMovable( FALSE ); |
94 | 94 | ||
95 | views = new QWidgetStack( this ); | 95 | views = new QWidgetStack( this ); |
96 | setCentralWidget( views ); | 96 | setCentralWidget( views ); |
97 | 97 | ||
98 | dayView = 0; | 98 | dayView = 0; |
99 | weekView = 0; | 99 | weekView = 0; |
100 | weekLstView = 0; | 100 | weekLstView = 0; |
101 | monthView = 0; | 101 | monthView = 0; |
102 | 102 | ||
103 | // QPEToolBar *bar = new QPEToolBar( this ); | 103 | // QToolBar *bar = new QToolBar( this ); |
104 | // bar->setHorizontalStretchable( TRUE ); | 104 | // bar->setHorizontalStretchable( TRUE ); |
105 | 105 | ||
106 | // QMenuBar *mb = new QMenuBar( bar ); | 106 | // QMenuBar *mb = new QMenuBar( bar ); |
107 | // mb->setMargin( 0 ); | 107 | // mb->setMargin( 0 ); |
108 | 108 | ||
109 | // QPopupMenu *view = new QPopupMenu( this ); | 109 | // QPopupMenu *view = new QPopupMenu( this ); |
110 | // mb->insertItem( tr( "View" ), view ); | 110 | // mb->insertItem( tr( "View" ), view ); |
111 | 111 | ||
112 | QPEToolBar *sub_bar = new QPEToolBar(this); | 112 | QToolBar *sub_bar = new QToolBar(this); |
113 | sub_bar->setHorizontalStretchable(TRUE); | 113 | sub_bar->setHorizontalStretchable(TRUE); |
114 | 114 | ||
115 | QActionGroup *g = new QActionGroup( this ); | 115 | QActionGroup *g = new QActionGroup( this ); |
116 | g->setExclusive( TRUE ); | 116 | g->setExclusive( TRUE ); |
117 | 117 | ||
118 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 118 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
119 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 119 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
120 | a->addTo( sub_bar ); | 120 | a->addTo( sub_bar ); |
121 | 121 | ||
122 | sub_bar->addSeparator(); | 122 | sub_bar->addSeparator(); |
123 | 123 | ||
124 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); | 124 | a = new QAction( tr( "Today" ), Resource::loadPixmap( "datebook/to_day" ), QString::null, 0, g, 0 ); |
125 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); | 125 | connect( a, SIGNAL( activated() ), this, SLOT( slotToday() ) ); |
126 | a->addTo( sub_bar ); | 126 | a->addTo( sub_bar ); |
127 | //a->addTo( view ); | 127 | //a->addTo( view ); |
128 | 128 | ||
129 | sub_bar->addSeparator(); | 129 | sub_bar->addSeparator(); |
130 | 130 | ||
131 | a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); | 131 | a = new QAction( tr( "Day" ), Resource::loadPixmap( "day" ), QString::null, 0, g, 0 ); |
132 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); | 132 | connect( a, SIGNAL( activated() ), this, SLOT( viewDay() ) ); |
133 | a->addTo( sub_bar ); | 133 | a->addTo( sub_bar ); |
134 | // a->addTo( view ); | 134 | // a->addTo( view ); |
135 | a->setToggleAction( TRUE ); | 135 | a->setToggleAction( TRUE ); |
136 | a->setOn( TRUE ); | 136 | a->setOn( TRUE ); |
137 | dayAction = a; | 137 | dayAction = a; |
138 | 138 | ||
139 | a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); | 139 | a = new QAction( tr( "Week" ), Resource::loadPixmap( "week" ), QString::null, 0, g, 0 ); |
140 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); | 140 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeek() ) ); |
141 | a->addTo( sub_bar ); | 141 | a->addTo( sub_bar ); |
142 | // a->addTo( view ); | 142 | // a->addTo( view ); |
143 | a->setToggleAction( TRUE ); | 143 | a->setToggleAction( TRUE ); |
144 | weekAction = a; | 144 | weekAction = a; |
145 | 145 | ||
146 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); | 146 | a = new QAction( tr( "WeekLst" ), Resource::loadPixmap( "datebook/weeklst" ), QString::null, 0, g, 0 ); |
147 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); | 147 | connect( a, SIGNAL( activated() ), this, SLOT( viewWeekLst() ) ); |
148 | a->addTo( sub_bar ); | 148 | a->addTo( sub_bar ); |
149 | // a->addTo( view ); | 149 | // a->addTo( view ); |
150 | a->setToggleAction( TRUE ); | 150 | a->setToggleAction( TRUE ); |
151 | weekLstAction = a; | 151 | weekLstAction = a; |
152 | 152 | ||
153 | a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); | 153 | a = new QAction( tr( "Month" ), Resource::loadPixmap( "month" ), QString::null, 0, g, 0 ); |
154 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); | 154 | connect( a, SIGNAL( activated() ), this, SLOT( viewMonth() ) ); |
155 | a->addTo( sub_bar ); | 155 | a->addTo( sub_bar ); |
156 | // a->addTo( view ); | 156 | // a->addTo( view ); |
157 | a->setToggleAction( TRUE ); | 157 | a->setToggleAction( TRUE ); |
158 | monthAction = a; | 158 | monthAction = a; |
159 | 159 | ||
160 | sub_bar->addSeparator(); | 160 | sub_bar->addSeparator(); |
161 | 161 | ||
162 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); | 162 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); |
163 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); | 163 | connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); |
164 | a->addTo( sub_bar ); | 164 | a->addTo( sub_bar ); |
165 | 165 | ||
166 | a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); | 166 | a = new QAction( tr( "Edit..." ), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0 ); |
167 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); | 167 | connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); |
168 | a->addTo( sub_bar ); | 168 | a->addTo( sub_bar ); |
169 | 169 | ||
170 | if(defaultView==DAY) viewDay(); | 170 | if(defaultView==DAY) viewDay(); |
171 | if(defaultView==WEEK) needEvilHack=true;// viewWeek(); | 171 | if(defaultView==WEEK) needEvilHack=true;// viewWeek(); |
172 | if(defaultView==WEEKLST) viewWeekLst(); | 172 | if(defaultView==WEEKLST) viewWeekLst(); |
173 | if(defaultView==MONTH) viewMonth(); | 173 | if(defaultView==MONTH) viewMonth(); |
174 | 174 | ||
175 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); | 175 | connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); |
176 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); | 176 | connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(changeWeek(bool)) ); |
177 | 177 | ||
178 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 178 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
179 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); | 179 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), this, SLOT(appMessage(const QCString&, const QByteArray&)) ); |
180 | #endif | 180 | #endif |
181 | 181 | ||
182 | // listen on QPE/System | 182 | // listen on QPE/System |
183 | #if defined(Q_WS_QWS) | 183 | #if defined(Q_WS_QWS) |
184 | #if !defined(QT_NO_COP) | 184 | #if !defined(QT_NO_COP) |
185 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 185 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
186 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); | 186 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); |
187 | channel = new QCopChannel( "QPE/Datebook", this ); | 187 | channel = new QCopChannel( "QPE/Datebook", this ); |
188 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); | 188 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); |
189 | qDebug("olle\n"); | 189 | qDebug("olle\n"); |
190 | #endif | 190 | #endif |
191 | #endif | 191 | #endif |
192 | 192 | ||
193 | qDebug("done t=%d", t.elapsed() ); | 193 | qDebug("done t=%d", t.elapsed() ); |
194 | 194 | ||
195 | connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); | 195 | connect( qApp, SIGNAL( flush() ), this, SLOT( flush() ) ); |
196 | connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) ); | 196 | connect( qApp, SIGNAL( reload()), this, SLOT( reload() ) ); |
197 | /* | 197 | /* |
198 | * Here is a problem description: | 198 | * Here is a problem description: |
199 | * When Weekview is the default view | 199 | * When Weekview is the default view |
200 | * a DateBookWeekView get's created | 200 | * a DateBookWeekView get's created |
201 | * redraw() get's called. So what? | 201 | * redraw() get's called. So what? |
202 | * Remember that we're still in the c'tor | 202 | * Remember that we're still in the c'tor |
203 | * and no final layout has happened? Ok | 203 | * and no final layout has happened? Ok |
204 | * now all Events get arranged. Their x | 204 | * now all Events get arranged. Their x |
205 | * position get's determined by a QHeader | 205 | * position get's determined by a QHeader |
206 | * position. But the QHeader isn't layouted or | 206 | * position. But the QHeader isn't layouted or |
207 | * at the right position. redraw() is a slot | 207 | * at the right position. redraw() is a slot |
208 | * so we'll call it then via a singleShot | 208 | * so we'll call it then via a singleShot |
209 | * from view() | 209 | * from view() |
210 | */ | 210 | */ |
211 | if( needEvilHack ){ | 211 | if( needEvilHack ){ |
212 | QTimer::singleShot( 500, this, SLOT(viewWeek()) ); | 212 | QTimer::singleShot( 500, this, SLOT(viewWeek()) ); |
213 | } | 213 | } |
214 | } | 214 | } |
215 | 215 | ||
216 | void DateBook::receive( const QCString &msg, const QByteArray &data ) | 216 | void DateBook::receive( const QCString &msg, const QByteArray &data ) |
217 | { | 217 | { |
218 | QDataStream stream( data, IO_ReadOnly ); | 218 | QDataStream stream( data, IO_ReadOnly ); |
219 | if ( msg == "timeChange(QString)" ) { | 219 | if ( msg == "timeChange(QString)" ) { |
220 | // update active view! | 220 | // update active view! |
221 | if ( dayAction->isOn() ) | 221 | if ( dayAction->isOn() ) |
222 | viewDay(); | 222 | viewDay(); |
223 | else if ( weekAction->isOn() ) | 223 | else if ( weekAction->isOn() ) |
224 | viewWeek(); | 224 | viewWeek(); |
225 | else if ( monthAction->isOn() ) | 225 | else if ( monthAction->isOn() ) |
226 | viewMonth(); | 226 | viewMonth(); |
227 | } | 227 | } |
228 | else if (msg == "editEvent(int)") { | 228 | else if (msg == "editEvent(int)") { |
229 | int uid; | 229 | int uid; |
230 | stream >> uid; | 230 | stream >> uid; |
231 | Event e=db->eventByUID(uid); | 231 | Event e=db->eventByUID(uid); |
232 | editEvent(e); | 232 | editEvent(e); |
233 | }else if (msg == "viewDefault(QDate)"){ | 233 | }else if (msg == "viewDefault(QDate)"){ |
234 | QDate day; | 234 | QDate day; |
235 | stream >> day; | 235 | stream >> day; |
236 | viewDefault(day); | 236 | viewDefault(day); |
237 | } | 237 | } |
238 | } | 238 | } |
239 | 239 | ||
240 | DateBook::~DateBook() | 240 | DateBook::~DateBook() |
241 | { | 241 | { |
242 | } | 242 | } |
243 | 243 | ||
244 | void DateBook::slotSettings() | 244 | void DateBook::slotSettings() |
245 | { | 245 | { |
246 | DateBookSettings frmSettings( ampm, this ); | 246 | DateBookSettings frmSettings( ampm, this ); |
247 | frmSettings.setStartTime( startTime ); | 247 | frmSettings.setStartTime( startTime ); |
248 | frmSettings.setAlarmPreset( aPreset, presetTime ); | 248 | frmSettings.setAlarmPreset( aPreset, presetTime ); |
249 | frmSettings.setJumpToCurTime( bJumpToCurTime ); | 249 | frmSettings.setJumpToCurTime( bJumpToCurTime ); |
250 | frmSettings.setRowStyle( rowStyle ); | 250 | frmSettings.setRowStyle( rowStyle ); |
251 | frmSettings.comboDefaultView->setCurrentItem(defaultView-1); | 251 | frmSettings.comboDefaultView->setCurrentItem(defaultView-1); |
252 | frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); | 252 | frmSettings.comboWeekListView->setCurrentItem(weeklistviewconfig); |
253 | 253 | ||
254 | bool found=false; | 254 | bool found=false; |
255 | for (int i=0; i<(frmSettings.comboLocation->count()); i++) { | 255 | for (int i=0; i<(frmSettings.comboLocation->count()); i++) { |
256 | if ( frmSettings.comboLocation->text(i) == defaultLocation ) { | 256 | if ( frmSettings.comboLocation->text(i) == defaultLocation ) { |
257 | frmSettings.comboLocation->setCurrentItem(i); | 257 | frmSettings.comboLocation->setCurrentItem(i); |
258 | found=true; | 258 | found=true; |
259 | break; | 259 | break; |
260 | } | 260 | } |
261 | } | 261 | } |
262 | if(!found) { | 262 | if(!found) { |
263 | frmSettings.comboLocation->insertItem(defaultLocation); | 263 | frmSettings.comboLocation->insertItem(defaultLocation); |
264 | frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); | 264 | frmSettings.comboLocation->setCurrentItem(frmSettings.comboLocation->count()-1); |
265 | } | 265 | } |
266 | frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); | 266 | frmSettings.comboCategory->setCategories(defaultCategories,"Calendar", tr("Calendar")); |
267 | 267 | ||
268 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) | 268 | #if defined (Q_WS_QWS) || defined(_WS_QWS_) |
269 | frmSettings.showMaximized(); | 269 | frmSettings.showMaximized(); |
270 | #endif | 270 | #endif |
271 | 271 | ||
272 | if ( frmSettings.exec() ) { | 272 | if ( frmSettings.exec() ) { |
273 | 273 | ||
274 | aPreset = frmSettings.alarmPreset(); | 274 | aPreset = frmSettings.alarmPreset(); |
275 | presetTime = frmSettings.presetTime(); | 275 | presetTime = frmSettings.presetTime(); |
276 | startTime = frmSettings.startTime(); | 276 | startTime = frmSettings.startTime(); |
277 | bJumpToCurTime = frmSettings.jumpToCurTime(); | 277 | bJumpToCurTime = frmSettings.jumpToCurTime(); |
278 | rowStyle = frmSettings.rowStyle(); | 278 | rowStyle = frmSettings.rowStyle(); |
279 | defaultView=frmSettings.comboDefaultView->currentItem()+1; | 279 | defaultView=frmSettings.comboDefaultView->currentItem()+1; |
280 | weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); | 280 | weeklistviewconfig=frmSettings.comboWeekListView->currentItem(); |
281 | defaultLocation=frmSettings.comboLocation->currentText(); | 281 | defaultLocation=frmSettings.comboLocation->currentText(); |
282 | defaultCategories=frmSettings.comboCategory->currentCategories(); | 282 | defaultCategories=frmSettings.comboCategory->currentCategories(); |
283 | 283 | ||
284 | if ( dayView ) { | 284 | if ( dayView ) { |
285 | dayView->setStartViewTime( startTime ); | 285 | dayView->setStartViewTime( startTime ); |
286 | dayView->setJumpToCurTime( bJumpToCurTime ); | 286 | dayView->setJumpToCurTime( bJumpToCurTime ); |
287 | dayView->setRowStyle( rowStyle ); | 287 | dayView->setRowStyle( rowStyle ); |
288 | } | 288 | } |
289 | if ( weekView ) { | 289 | if ( weekView ) { |
290 | weekView->setStartViewTime( startTime ); | 290 | weekView->setStartViewTime( startTime ); |
291 | } | 291 | } |
292 | saveSettings(); | 292 | saveSettings(); |
293 | 293 | ||
294 | // make the change obvious | 294 | // make the change obvious |
295 | if ( views->visibleWidget() ) { | 295 | if ( views->visibleWidget() ) { |
296 | if ( views->visibleWidget() == dayView ) | 296 | if ( views->visibleWidget() == dayView ) |
297 | dayView->redraw(); | 297 | dayView->redraw(); |
298 | else if ( views->visibleWidget() == weekView ) | 298 | else if ( views->visibleWidget() == weekView ) |
299 | weekView->redraw(); | 299 | weekView->redraw(); |
300 | else if ( views->visibleWidget() == weekLstView ) | 300 | else if ( views->visibleWidget() == weekLstView ) |
301 | weekLstView->redraw(); | 301 | weekLstView->redraw(); |
302 | } | 302 | } |
303 | } | 303 | } |
304 | } | 304 | } |
305 | 305 | ||
306 | void DateBook::fileNew() | 306 | void DateBook::fileNew() |
307 | { | 307 | { |
308 | slotNewEventFromKey(""); | 308 | slotNewEventFromKey(""); |
309 | } | 309 | } |
310 | 310 | ||
311 | QString DateBook::checkEvent(const Event &e) | 311 | QString DateBook::checkEvent(const Event &e) |
312 | { | 312 | { |
313 | /* check if overlaps with itself */ | 313 | /* check if overlaps with itself */ |
314 | bool checkFailed = FALSE; | 314 | bool checkFailed = FALSE; |
315 | 315 | ||
316 | /* check the next 12 repeats. should catch most problems */ | 316 | /* check the next 12 repeats. should catch most problems */ |
317 | QDate current_date = e.start().date(); | 317 | QDate current_date = e.start().date(); |
318 | Event previous = e; | 318 | Event previous = e; |
319 | for(int i = 0; i < 12; i++) | 319 | for(int i = 0; i < 12; i++) |
320 | { | 320 | { |
321 | QDateTime next; | 321 | QDateTime next; |
322 | if (!nextOccurance(previous, current_date.addDays(1), next)) { | 322 | if (!nextOccurance(previous, current_date.addDays(1), next)) { |
323 | break; // no more repeats | 323 | break; // no more repeats |
324 | } | 324 | } |
325 | if(next < previous.end()) { | 325 | if(next < previous.end()) { |
326 | checkFailed = TRUE; | 326 | checkFailed = TRUE; |
327 | break; | 327 | break; |
328 | } | 328 | } |
329 | current_date = next.date(); | 329 | current_date = next.date(); |
330 | } | 330 | } |
331 | 331 | ||
332 | if(checkFailed) | 332 | if(checkFailed) |
333 | return tr("Event duration is potentially longer\n" | 333 | return tr("Event duration is potentially longer\n" |
334 | "than interval between repeats."); | 334 | "than interval between repeats."); |
335 | 335 | ||
336 | return QString::null; | 336 | return QString::null; |
337 | } | 337 | } |
338 | 338 | ||
339 | QDate DateBook::currentDate() | 339 | QDate DateBook::currentDate() |
340 | { | 340 | { |
341 | QDate d = QDate::currentDate(); | 341 | QDate d = QDate::currentDate(); |
342 | 342 | ||
343 | if ( dayView && views->visibleWidget() == dayView ) { | 343 | if ( dayView && views->visibleWidget() == dayView ) { |
344 | d = dayView->date(); | 344 | d = dayView->date(); |
345 | } else if ( weekView && views->visibleWidget() == weekView ) { | 345 | } else if ( weekView && views->visibleWidget() == weekView ) { |
346 | d = weekView->date(); | 346 | d = weekView->date(); |
347 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { | 347 | } else if ( weekLstView && views->visibleWidget() == weekLstView ) { |
348 | d = weekLstView->date(); | 348 | d = weekLstView->date(); |
349 | } else if ( monthView && views->visibleWidget() == monthView ) { | 349 | } else if ( monthView && views->visibleWidget() == monthView ) { |
350 | d = monthView->selectedDate(); | 350 | d = monthView->selectedDate(); |
351 | } | 351 | } |
352 | 352 | ||
353 | return d; | 353 | return d; |
354 | } | 354 | } |
355 | 355 | ||
356 | void DateBook::view(int v, const QDate &d) { | 356 | void DateBook::view(int v, const QDate &d) { |
357 | if (v==DAY) { | 357 | if (v==DAY) { |
358 | initDay(); | 358 | initDay(); |
359 | dayAction->setOn( TRUE ); | 359 | dayAction->setOn( TRUE ); |
360 | dayView->setDate( d ); | 360 | dayView->setDate( d ); |
361 | views->raiseWidget( dayView ); | 361 | views->raiseWidget( dayView ); |
362 | dayView->redraw(); | 362 | dayView->redraw(); |
363 | } else if (v==WEEK) { | 363 | } else if (v==WEEK) { |
364 | initWeek(); | 364 | initWeek(); |
365 | weekAction->setOn( TRUE ); | 365 | weekAction->setOn( TRUE ); |
366 | weekView->setDate( d ); | 366 | weekView->setDate( d ); |
367 | views->raiseWidget( weekView ); | 367 | views->raiseWidget( weekView ); |
368 | weekView->redraw(); | 368 | weekView->redraw(); |
369 | } else if (v==WEEKLST) { | 369 | } else if (v==WEEKLST) { |
370 | initWeekLst(); | 370 | initWeekLst(); |
371 | weekLstAction->setOn( TRUE ); | 371 | weekLstAction->setOn( TRUE ); |
372 | weekLstView->setDate(d); | 372 | weekLstView->setDate(d); |
373 | views->raiseWidget( weekLstView ); | 373 | views->raiseWidget( weekLstView ); |
374 | weekLstView->redraw(); | 374 | weekLstView->redraw(); |
375 | } else if (v==MONTH) { | 375 | } else if (v==MONTH) { |
376 | initMonth(); | 376 | initMonth(); |
377 | monthAction->setOn( TRUE ); | 377 | monthAction->setOn( TRUE ); |
378 | monthView->setDate( d.year(), d.month(), d.day() ); | 378 | monthView->setDate( d.year(), d.month(), d.day() ); |
379 | views->raiseWidget( monthView ); | 379 | views->raiseWidget( monthView ); |
380 | monthView->redraw(); | 380 | monthView->redraw(); |
381 | } | 381 | } |
382 | } | 382 | } |
383 | 383 | ||
384 | void DateBook::viewDefault(const QDate &d) { | 384 | void DateBook::viewDefault(const QDate &d) { |
385 | view(defaultView,d); | 385 | view(defaultView,d); |
386 | } | 386 | } |
387 | 387 | ||
388 | void DateBook::viewDay() { | 388 | void DateBook::viewDay() { |
389 | view(DAY,currentDate()); | 389 | view(DAY,currentDate()); |
390 | } | 390 | } |
391 | 391 | ||
392 | void DateBook::viewWeek() { | 392 | void DateBook::viewWeek() { |
393 | view(WEEK,currentDate()); | 393 | view(WEEK,currentDate()); |
394 | } | 394 | } |
395 | 395 | ||
396 | void DateBook::viewWeekLst() { | 396 | void DateBook::viewWeekLst() { |
397 | view(WEEKLST,currentDate()); | 397 | view(WEEKLST,currentDate()); |
398 | } | 398 | } |
399 | 399 | ||
400 | void DateBook::viewMonth() { | 400 | void DateBook::viewMonth() { |
401 | view(MONTH,currentDate()); | 401 | view(MONTH,currentDate()); |
402 | } | 402 | } |
403 | 403 | ||
404 | void DateBook::insertEvent( const Event &e ) | 404 | void DateBook::insertEvent( const Event &e ) |
405 | { | 405 | { |
406 | Event dupEvent=e; | 406 | Event dupEvent=e; |
407 | if(!dupEvent.isValidUid() ) // tkcRom seems to be different | 407 | if(!dupEvent.isValidUid() ) // tkcRom seems to be different |
408 | dupEvent.assignUid(); | 408 | dupEvent.assignUid(); |
409 | dupEvent.setLocation(defaultLocation); | 409 | dupEvent.setLocation(defaultLocation); |
410 | dupEvent.setCategories(defaultCategories); | 410 | dupEvent.setCategories(defaultCategories); |
411 | db->addEvent(dupEvent); | 411 | db->addEvent(dupEvent); |
412 | emit newEvent(); | 412 | emit newEvent(); |
413 | } | 413 | } |
414 | 414 | ||
415 | void DateBook::duplicateEvent( const Event &e ) | 415 | void DateBook::duplicateEvent( const Event &e ) |
416 | { | 416 | { |
417 | qWarning("Hmmm..."); | 417 | qWarning("Hmmm..."); |
418 | // Alot of code duplication, as this is almost like editEvent(); | 418 | // Alot of code duplication, as this is almost like editEvent(); |
419 | if (syncing) { | 419 | if (syncing) { |
420 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 420 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
421 | return; | 421 | return; |
422 | } | 422 | } |
423 | 423 | ||
424 | Event dupevent(e);// Make a duplicate. | 424 | Event dupevent(e);// Make a duplicate. |
425 | 425 | ||
426 | // workaround added for text input. | 426 | // workaround added for text input. |
427 | QDialog editDlg( this, 0, TRUE ); | 427 | QDialog editDlg( this, 0, TRUE ); |
428 | DateEntry *entry; | 428 | DateEntry *entry; |
429 | editDlg.setCaption( tr("Duplicate Event") ); | 429 | editDlg.setCaption( tr("Duplicate Event") ); |
430 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 430 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
431 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 431 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
432 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 432 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
433 | // KLUDGE!!! | 433 | // KLUDGE!!! |
434 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 434 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
435 | vb->addWidget( sv ); | 435 | vb->addWidget( sv ); |
436 | entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); | 436 | entry = new DateEntry( onMonday, dupevent, ampm, &editDlg, "editor" ); |
437 | entry->timezone->setEnabled( FALSE ); | 437 | entry->timezone->setEnabled( FALSE ); |
438 | sv->addChild( entry ); | 438 | sv->addChild( entry ); |
439 | 439 | ||
440 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 440 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
441 | editDlg.showMaximized(); | 441 | editDlg.showMaximized(); |
442 | #endif | 442 | #endif |
443 | while (editDlg.exec() ) { | 443 | while (editDlg.exec() ) { |
444 | Event newEv = entry->event(); | 444 | Event newEv = entry->event(); |
445 | QString error = checkEvent(newEv); | 445 | QString error = checkEvent(newEv); |
446 | if (!error.isNull()) { | 446 | if (!error.isNull()) { |
447 | if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) | 447 | if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) |
448 | continue; | 448 | continue; |
449 | } | 449 | } |
450 | /* | 450 | /* |
451 | * The problem: | 451 | * The problem: |
452 | * DateBookDB does remove repeating events not by uid but by the time | 452 | * DateBookDB does remove repeating events not by uid but by the time |
453 | * the recurrence was created | 453 | * the recurrence was created |
454 | * so we need to update that time as well | 454 | * so we need to update that time as well |
455 | */ | 455 | */ |
456 | Event::RepeatPattern rp = newEv.repeatPattern(); | 456 | Event::RepeatPattern rp = newEv.repeatPattern(); |
457 | rp.createTime = ::time( NULL ); | 457 | rp.createTime = ::time( NULL ); |
458 | newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern... | 458 | newEv.setRepeat( TRUE, rp ); // has repeat and repeatPattern... |
459 | if( newEv.uid() == e.uid() || !newEv.isValidUid() ) | 459 | if( newEv.uid() == e.uid() || !newEv.isValidUid() ) |
460 | newEv.assignUid(); | 460 | newEv.assignUid(); |
461 | 461 | ||
462 | db->addEvent(newEv); | 462 | db->addEvent(newEv); |
463 | emit newEvent(); | 463 | emit newEvent(); |
464 | break; | 464 | break; |
465 | } | 465 | } |
466 | } | 466 | } |
467 | 467 | ||
468 | void DateBook::editEvent( const Event &e ) | 468 | void DateBook::editEvent( const Event &e ) |
469 | { | 469 | { |
470 | if (syncing) { | 470 | if (syncing) { |
471 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 471 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
472 | return; | 472 | return; |
473 | } | 473 | } |
474 | 474 | ||
475 | // workaround added for text input. | 475 | // workaround added for text input. |
476 | QDialog editDlg( this, 0, TRUE ); | 476 | QDialog editDlg( this, 0, TRUE ); |
477 | DateEntry *entry; | 477 | DateEntry *entry; |
478 | editDlg.setCaption( tr("Edit Event") ); | 478 | editDlg.setCaption( tr("Edit Event") ); |
479 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); | 479 | QVBoxLayout *vb = new QVBoxLayout( &editDlg ); |
480 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); | 480 | QScrollView *sv = new QScrollView( &editDlg, "scrollview" ); |
481 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 481 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
482 | // KLUDGE!!! | 482 | // KLUDGE!!! |
483 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 483 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
484 | vb->addWidget( sv ); | 484 | vb->addWidget( sv ); |
485 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); | 485 | entry = new DateEntry( onMonday, e, ampm, &editDlg, "editor" ); |
486 | entry->timezone->setEnabled( FALSE ); | 486 | entry->timezone->setEnabled( FALSE ); |
487 | sv->addChild( entry ); | 487 | sv->addChild( entry ); |
488 | 488 | ||
489 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 489 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
490 | editDlg.showMaximized(); | 490 | editDlg.showMaximized(); |
491 | #endif | 491 | #endif |
492 | while (editDlg.exec() ) { | 492 | while (editDlg.exec() ) { |
493 | Event newEv = entry->event(); | 493 | Event newEv = entry->event(); |
494 | if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) | 494 | if(newEv.description().isEmpty() && newEv.notes().isEmpty() ) |
495 | break; | 495 | break; |
496 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid | 496 | newEv.setUid(e.uid()); // FIXME: Hack not to clear uid |
497 | QString error = checkEvent(newEv); | 497 | QString error = checkEvent(newEv); |
498 | if (!error.isNull()) { | 498 | if (!error.isNull()) { |
499 | if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; | 499 | if (QMessageBox::warning(this, tr("error box"), error, tr("Fix it"), tr("Continue"), 0, 0, 1) == 0) continue; |
500 | } | 500 | } |
501 | db->editEvent(e, newEv); | 501 | db->editEvent(e, newEv); |
502 | emit newEvent(); | 502 | emit newEvent(); |
503 | break; | 503 | break; |
504 | } | 504 | } |
505 | } | 505 | } |
506 | 506 | ||
507 | void DateBook::removeEvent( const Event &e ) | 507 | void DateBook::removeEvent( const Event &e ) |
508 | { | 508 | { |
509 | if (syncing) { | 509 | if (syncing) { |
510 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); | 510 | QMessageBox::warning( this, tr("Calendar"), tr( "Can not edit data, currently syncing") ); |
511 | return; | 511 | return; |
512 | } | 512 | } |
513 | 513 | ||
514 | QString strName = e.description(); | 514 | QString strName = e.description(); |
515 | 515 | ||
516 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) | 516 | if ( !QPEMessageBox::confirmDelete( this, tr( "Calendar" ),strName ) ) |
517 | return; | 517 | return; |
518 | 518 | ||
519 | db->removeEvent( e ); | 519 | db->removeEvent( e ); |
520 | if ( views->visibleWidget() == dayView && dayView ) | 520 | if ( views->visibleWidget() == dayView && dayView ) |
521 | dayView->redraw(); | 521 | dayView->redraw(); |
522 | } | 522 | } |
523 | 523 | ||
524 | void DateBook::addEvent( const Event &e ) | 524 | void DateBook::addEvent( const Event &e ) |
525 | { | 525 | { |
526 | QDate d = e.start().date(); | 526 | QDate d = e.start().date(); |
527 | initDay(); | 527 | initDay(); |
528 | dayView->setDate( d ); | 528 | dayView->setDate( d ); |
529 | } | 529 | } |
530 | 530 | ||
531 | void DateBook::showDay( int year, int month, int day ) | 531 | void DateBook::showDay( int year, int month, int day ) |
532 | { | 532 | { |
533 | QDate d(year, month, day); | 533 | QDate d(year, month, day); |
534 | view(DAY,d); | 534 | view(DAY,d); |
535 | } | 535 | } |
536 | 536 | ||
537 | void DateBook::initDay() | 537 | void DateBook::initDay() |
538 | { | 538 | { |
539 | if ( !dayView ) { | 539 | if ( !dayView ) { |
540 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); | 540 | dayView = new DateBookDay( ampm, onMonday, db, views, "day view" ); |
541 | views->addWidget( dayView, DAY ); | 541 | views->addWidget( dayView, DAY ); |
542 | dayView->setJumpToCurTime( bJumpToCurTime ); | 542 | dayView->setJumpToCurTime( bJumpToCurTime ); |
543 | dayView->setStartViewTime( startTime ); | 543 | dayView->setStartViewTime( startTime ); |
544 | dayView->setRowStyle( rowStyle ); | 544 | dayView->setRowStyle( rowStyle ); |
545 | connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); | 545 | connect( this, SIGNAL( newEvent() ), dayView, SLOT( redraw() ) ); |
546 | connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); | 546 | connect( dayView, SIGNAL( newEvent() ), this, SLOT( fileNew() ) ); |
547 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); | 547 | connect( dayView, SIGNAL( removeEvent( const Event & ) ), this, SLOT( removeEvent( const Event & ) ) ); |
548 | connect( dayView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); | 548 | connect( dayView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); |
549 | connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); | 549 | connect( dayView, SIGNAL( duplicateEvent( const Event & ) ), this, SLOT( duplicateEvent( const Event & ) ) ); |
550 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), this, SLOT( beamEvent( const Event & ) ) ); | 550 | connect( dayView, SIGNAL( beamEvent( const Event & ) ), this, SLOT( beamEvent( const Event & ) ) ); |
551 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), this, SLOT(slotNewEventFromKey(const QString &)) ); | 551 | connect( dayView, SIGNAL(sigNewEvent(const QString &)), this, SLOT(slotNewEventFromKey(const QString &)) ); |
552 | } | 552 | } |
553 | } | 553 | } |
554 | 554 | ||
555 | void DateBook::initWeek() | 555 | void DateBook::initWeek() |
556 | { | 556 | { |
557 | if ( !weekView ) { | 557 | if ( !weekView ) { |
558 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); | 558 | weekView = new DateBookWeek( ampm, onMonday, db, views, "week view" ); |
559 | weekView->setStartViewTime( startTime ); | 559 | weekView->setStartViewTime( startTime ); |
560 | views->addWidget( weekView, WEEK ); | 560 | views->addWidget( weekView, WEEK ); |
561 | connect( weekView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); | 561 | connect( weekView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); |
562 | connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); | 562 | connect( this, SIGNAL( newEvent() ), weekView, SLOT( redraw() ) ); |
563 | } | 563 | } |
564 | 564 | ||
565 | //But also get it right: the year that we display can be different | 565 | //But also get it right: the year that we display can be different |
566 | //from the year of the current date. So, first find the year | 566 | //from the year of the current date. So, first find the year |
567 | //number of the current week. | 567 | //number of the current week. |
568 | int yearNumber, totWeeks; | 568 | int yearNumber, totWeeks; |
569 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); | 569 | calcWeek( currentDate(), totWeeks, yearNumber, onMonday ); |
570 | 570 | ||
571 | QDate d = QDate( yearNumber, 12, 31 ); | 571 | QDate d = QDate( yearNumber, 12, 31 ); |
572 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 572 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
573 | 573 | ||
574 | while ( totWeeks == 1 ) { | 574 | while ( totWeeks == 1 ) { |
575 | d = d.addDays( -1 ); | 575 | d = d.addDays( -1 ); |
576 | calcWeek( d, totWeeks, yearNumber, onMonday ); | 576 | calcWeek( d, totWeeks, yearNumber, onMonday ); |
577 | } | 577 | } |
578 | } | 578 | } |
579 | 579 | ||
580 | void DateBook::initWeekLst() { | 580 | void DateBook::initWeekLst() { |
581 | if ( !weekLstView ) { | 581 | if ( !weekLstView ) { |
582 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); | 582 | weekLstView = new DateBookWeekLst( ampm, onMonday, db, views, "weeklst view" ); |
583 | views->addWidget( weekLstView, WEEKLST ); | 583 | views->addWidget( weekLstView, WEEKLST ); |
584 | 584 | ||
585 | //weekLstView->setStartViewTime( startTime ); | 585 | //weekLstView->setStartViewTime( startTime ); |
586 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); | 586 | connect( weekLstView, SIGNAL( showDate( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); |
587 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, const QDateTime &, const QString & , const QString &) ), | 587 | connect( weekLstView, SIGNAL( addEvent( const QDateTime &, const QDateTime &, const QString & , const QString &) ), |
588 | this, SLOT( slotNewEntry( const QDateTime &, const QDateTime &, const QString & , const QString &) ) ); | 588 | this, SLOT( slotNewEntry( const QDateTime &, const QDateTime &, const QString & , const QString &) ) ); |
589 | connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); | 589 | connect( this, SIGNAL( newEvent() ), weekLstView, SLOT( redraw() ) ); |
590 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); | 590 | connect( weekLstView, SIGNAL( editEvent( const Event & ) ), this, SLOT( editEvent( const Event & ) ) ); |
591 | } | 591 | } |
592 | } | 592 | } |
593 | 593 | ||
594 | 594 | ||
595 | void DateBook::initMonth() | 595 | void DateBook::initMonth() |
596 | { | 596 | { |
597 | if ( !monthView ) { | 597 | if ( !monthView ) { |
598 | monthView = new DateBookMonth( views, "month view", FALSE, db ); | 598 | monthView = new DateBookMonth( views, "month view", FALSE, db ); |
599 | views->addWidget( monthView, MONTH ); | 599 | views->addWidget( monthView, MONTH ); |
600 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); | 600 | connect( monthView, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( showDay( int, int, int ) ) ); |
601 | connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); | 601 | connect( this, SIGNAL( newEvent() ), monthView, SLOT( redraw() ) ); |
602 | qApp->processEvents(); | 602 | qApp->processEvents(); |
603 | } | 603 | } |
604 | } | 604 | } |
605 | 605 | ||
606 | void DateBook::loadSettings() | 606 | void DateBook::loadSettings() |
607 | { | 607 | { |
608 | Config qpeconfig( "qpe" ); | 608 | Config qpeconfig( "qpe" ); |
609 | qpeconfig.setGroup("Time"); | 609 | qpeconfig.setGroup("Time"); |
610 | ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); | 610 | ampm = qpeconfig.readBoolEntry( "AMPM", TRUE ); |
611 | onMonday = qpeconfig.readBoolEntry( "MONDAY" ); | 611 | onMonday = qpeconfig.readBoolEntry( "MONDAY" ); |
612 | 612 | ||
613 | Config config("DateBook"); | 613 | Config config("DateBook"); |
614 | config.setGroup("Main"); | 614 | config.setGroup("Main"); |
615 | startTime = config.readNumEntry("startviewtime", 8); | 615 | startTime = config.readNumEntry("startviewtime", 8); |
616 | aPreset = config.readBoolEntry("alarmpreset"); | 616 | aPreset = config.readBoolEntry("alarmpreset"); |
617 | presetTime = config.readNumEntry("presettime"); | 617 | presetTime = config.readNumEntry("presettime"); |
618 | bJumpToCurTime = config.readBoolEntry("jumptocurtime"); | 618 | bJumpToCurTime = config.readBoolEntry("jumptocurtime"); |
619 | rowStyle = config.readNumEntry("rowstyle"); | 619 | rowStyle = config.readNumEntry("rowstyle"); |
620 | defaultView = config.readNumEntry("defaultview",DAY); | 620 | defaultView = config.readNumEntry("defaultview",DAY); |
621 | weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); | 621 | weeklistviewconfig = config.readNumEntry("weeklistviewconfig",NORMAL); |
622 | 622 | ||
623 | defaultLocation=config.readEntry("defaultLocation"); | 623 | defaultLocation=config.readEntry("defaultLocation"); |
624 | QString tmpString=config.readEntry("defaultCategories"); | 624 | QString tmpString=config.readEntry("defaultCategories"); |
625 | QStringList tmpStringList=QStringList::split(",",tmpString); | 625 | QStringList tmpStringList=QStringList::split(",",tmpString); |
626 | defaultCategories.truncate(0); | 626 | defaultCategories.truncate(0); |
627 | 627 | ||
628 | for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { | 628 | for( QStringList::Iterator i=tmpStringList.begin(); i!=tmpStringList.end(); i++) { |
629 | defaultCategories.resize(defaultCategories.count()+1); | 629 | defaultCategories.resize(defaultCategories.count()+1); |
630 | defaultCategories[defaultCategories.count()-1]=(*i).toInt(); | 630 | defaultCategories[defaultCategories.count()-1]=(*i).toInt(); |
631 | } | 631 | } |
632 | } | 632 | } |
633 | 633 | ||
634 | void DateBook::saveSettings() | 634 | void DateBook::saveSettings() |
635 | { | 635 | { |
636 | Config config( "qpe" ); | 636 | Config config( "qpe" ); |
637 | Config configDB( "DateBook" ); | 637 | Config configDB( "DateBook" ); |
638 | configDB.setGroup( "Main" ); | 638 | configDB.setGroup( "Main" ); |
639 | configDB.writeEntry("startviewtime",startTime); | 639 | configDB.writeEntry("startviewtime",startTime); |
640 | configDB.writeEntry("alarmpreset",aPreset); | 640 | configDB.writeEntry("alarmpreset",aPreset); |
641 | configDB.writeEntry("presettime",presetTime); | 641 | configDB.writeEntry("presettime",presetTime); |
642 | configDB.writeEntry("jumptocurtime", bJumpToCurTime); | 642 | configDB.writeEntry("jumptocurtime", bJumpToCurTime); |
643 | configDB.writeEntry("rowstyle", rowStyle); | 643 | configDB.writeEntry("rowstyle", rowStyle); |
644 | configDB.writeEntry("defaultview",defaultView); | 644 | configDB.writeEntry("defaultview",defaultView); |
645 | configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); | 645 | configDB.writeEntry("weeklistviewconfig",weeklistviewconfig); |
646 | 646 | ||
647 | configDB.writeEntry("defaultLocation",defaultLocation); | 647 | configDB.writeEntry("defaultLocation",defaultLocation); |
648 | QStringList tmpStringList; | 648 | QStringList tmpStringList; |
649 | for( uint i=0; i<defaultCategories.count(); i++) { | 649 | for( uint i=0; i<defaultCategories.count(); i++) { |
650 | tmpStringList << QString::number(defaultCategories[i]); | 650 | tmpStringList << QString::number(defaultCategories[i]); |
651 | } | 651 | } |
652 | configDB.writeEntry("defaultCategories",tmpStringList.join(",")); | 652 | configDB.writeEntry("defaultCategories",tmpStringList.join(",")); |
653 | } | 653 | } |
654 | 654 | ||
655 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) | 655 | void DateBook::appMessage(const QCString& msg, const QByteArray& data) |
656 | { | 656 | { |
657 | bool needShow = FALSE; | 657 | bool needShow = FALSE; |
658 | if ( msg == "alarm(QDateTime,int)" ) { | 658 | if ( msg == "alarm(QDateTime,int)" ) { |
659 | QDataStream ds(data,IO_ReadOnly); | 659 | QDataStream ds(data,IO_ReadOnly); |
660 | QDateTime when; int warn; | 660 | QDateTime when; int warn; |
661 | ds >> when >> warn; | 661 | ds >> when >> warn; |
662 | 662 | ||
663 | // check to make it's okay to continue, | 663 | // check to make it's okay to continue, |
664 | // this is the case that the time was set ahead, and | 664 | // this is the case that the time was set ahead, and |
665 | // we are forced given a stale alarm... | 665 | // we are forced given a stale alarm... |
666 | QDateTime current = QDateTime::currentDateTime(); | 666 | QDateTime current = QDateTime::currentDateTime(); |
667 | if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) | 667 | if ( current.time().hour() != when.time().hour() && current.time().minute() != when.time().minute() ) |
668 | return; | 668 | return; |
669 | 669 | ||
670 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); | 670 | QValueList<EffectiveEvent> list = db->getEffectiveEvents(when.addSecs(warn*60)); |
671 | if ( list.count() > 0 ) { | 671 | if ( list.count() > 0 ) { |
672 | QString msg; | 672 | QString msg; |
673 | bool bSound = FALSE; | 673 | bool bSound = FALSE; |
674 | int stopTimer = 0; | 674 | int stopTimer = 0; |
675 | bool found = FALSE; | 675 | bool found = FALSE; |
676 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { | 676 | for ( QValueList<EffectiveEvent>::ConstIterator it=list.begin(); it!=list.end(); ++it ) { |
677 | if ( (*it).event().hasAlarm() ) { | 677 | if ( (*it).event().hasAlarm() ) { |
678 | found = TRUE; | 678 | found = TRUE; |
679 | msg += "<CENTER><B>" + (*it).description() + "</B>" | 679 | msg += "<CENTER><B>" + (*it).description() + "</B>" |
680 | + "<BR>" + (*it).location() + "<BR>" | 680 | + "<BR>" + (*it).location() + "<BR>" |
681 | + TimeString::dateString((*it).event().start(),ampm) | 681 | + TimeString::dateString((*it).event().start(),ampm) |
682 | + (warn | 682 | + (warn |
683 | ? tr(" (in " + QString::number(warn) | 683 | ? tr(" (in " + QString::number(warn) |
684 | + tr(" minutes)")) | 684 | + tr(" minutes)")) |
685 | : QString("")) | 685 | : QString("")) |
686 | + "<BR>" | 686 | + "<BR>" |
687 | + (*it).notes() + "</CENTER>"; | 687 | + (*it).notes() + "</CENTER>"; |
688 | if ( (*it).event().alarmSound() != Event::Silent ) { | 688 | if ( (*it).event().alarmSound() != Event::Silent ) { |
689 | bSound = TRUE; | 689 | bSound = TRUE; |
690 | } | 690 | } |
691 | } | 691 | } |
692 | } | 692 | } |
693 | if ( found ) { | 693 | if ( found ) { |
694 | if ( bSound ) { | 694 | if ( bSound ) { |
695 | Sound::soundAlarm(); | 695 | Sound::soundAlarm(); |
696 | alarmCounter = 0; | 696 | alarmCounter = 0; |
697 | stopTimer = startTimer( 5000 ); | 697 | stopTimer = startTimer( 5000 ); |
698 | } | 698 | } |
699 | QDialog dlg( this, 0, TRUE ); | 699 | QDialog dlg( this, 0, TRUE ); |
700 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); | 700 | QVBoxLayout *vb = new QVBoxLayout( &dlg ); |
701 | QScrollView *view = new QScrollView( &dlg, "scrollView"); | 701 | QScrollView *view = new QScrollView( &dlg, "scrollView"); |
702 | view->setResizePolicy( QScrollView::AutoOneFit ); | 702 | view->setResizePolicy( QScrollView::AutoOneFit ); |
703 | vb->addWidget( view ); | 703 | vb->addWidget( view ); |
704 | QLabel *lblMsg = new QLabel( msg, &dlg ); | 704 | QLabel *lblMsg = new QLabel( msg, &dlg ); |
705 | view->addChild( lblMsg ); | 705 | view->addChild( lblMsg ); |
706 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); | 706 | QPushButton *cmdOk = new QPushButton( tr("OK"), &dlg ); |
707 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); | 707 | connect( cmdOk, SIGNAL(clicked()), &dlg, SLOT(accept()) ); |
708 | vb->addWidget( cmdOk ); | 708 | vb->addWidget( cmdOk ); |
709 | 709 | ||
710 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 710 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
711 | dlg.showMaximized(); | 711 | dlg.showMaximized(); |
712 | #endif | 712 | #endif |
713 | needShow = dlg.exec(); | 713 | needShow = dlg.exec(); |
714 | 714 | ||
715 | if ( bSound ) | 715 | if ( bSound ) |
716 | killTimer( stopTimer ); | 716 | killTimer( stopTimer ); |
717 | } | 717 | } |
718 | } | 718 | } |
719 | } else if ( msg == "nextView()" ) { | 719 | } else if ( msg == "nextView()" ) { |
720 | needShow = true; | 720 | needShow = true; |
721 | if ( !qApp-> activeWindow ( )) { | 721 | if ( !qApp-> activeWindow ( )) { |
722 | needShow = TRUE; | 722 | needShow = TRUE; |
723 | } else { | 723 | } else { |
724 | QWidget* cur = views->visibleWidget(); | 724 | QWidget* cur = views->visibleWidget(); |
725 | if ( cur ) { | 725 | if ( cur ) { |
726 | if ( cur == dayView ) | 726 | if ( cur == dayView ) |
727 | viewWeek(); | 727 | viewWeek(); |
728 | else if ( cur == weekView ) | 728 | else if ( cur == weekView ) |
729 | viewWeekLst(); | 729 | viewWeekLst(); |
730 | else if ( cur == weekLstView ) | 730 | else if ( cur == weekLstView ) |
731 | viewMonth(); | 731 | viewMonth(); |
732 | else if ( cur == monthView ) | 732 | else if ( cur == monthView ) |
733 | viewDay(); | 733 | viewDay(); |
734 | needShow = TRUE; | 734 | needShow = TRUE; |
735 | } | 735 | } |
736 | } | 736 | } |
737 | } else if (msg == "editEvent(int)") { | 737 | } else if (msg == "editEvent(int)") { |
738 | /* simple copy from receive */ | 738 | /* simple copy from receive */ |
739 | QDataStream stream(data,IO_ReadOnly); | 739 | QDataStream stream(data,IO_ReadOnly); |
740 | int uid; | 740 | int uid; |
741 | stream >> uid; | 741 | stream >> uid; |
742 | Event e=db->eventByUID(uid); | 742 | Event e=db->eventByUID(uid); |
743 | editEvent(e); | 743 | editEvent(e); |
744 | } else if (msg == "viewDefault(QDate)"){ | 744 | } else if (msg == "viewDefault(QDate)"){ |
745 | /* simple copy from receive */ | 745 | /* simple copy from receive */ |
746 | QDataStream stream(data,IO_ReadOnly); | 746 | QDataStream stream(data,IO_ReadOnly); |
747 | QDate day; | 747 | QDate day; |
748 | stream >> day; | 748 | stream >> day; |
749 | viewDefault(day); | 749 | viewDefault(day); |
750 | needShow = true; | 750 | needShow = true; |
751 | } | 751 | } |
752 | 752 | ||
753 | if ( needShow ) { | 753 | if ( needShow ) { |
754 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 754 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
755 | // showMaximized(); | 755 | // showMaximized(); |
756 | #else | 756 | #else |
757 | // show(); | 757 | // show(); |
758 | #endif | 758 | #endif |
759 | // raise(); | 759 | // raise(); |
760 | QPEApplication::setKeepRunning(); | 760 | QPEApplication::setKeepRunning(); |
761 | // setActiveWindow(); | 761 | // setActiveWindow(); |
762 | } | 762 | } |
763 | } | 763 | } |
764 | 764 | ||
765 | void DateBook::reload() | 765 | void DateBook::reload() |
766 | { | 766 | { |
767 | db->reload(); | 767 | db->reload(); |
768 | if ( dayAction->isOn() ) viewDay(); | 768 | if ( dayAction->isOn() ) viewDay(); |
769 | else if ( weekAction->isOn() ) viewWeek(); | 769 | else if ( weekAction->isOn() ) viewWeek(); |
770 | else if ( monthAction->isOn() ) viewMonth(); | 770 | else if ( monthAction->isOn() ) viewMonth(); |
771 | syncing = FALSE; | 771 | syncing = FALSE; |
772 | } | 772 | } |
773 | 773 | ||
774 | void DateBook::flush() | 774 | void DateBook::flush() |
775 | { | 775 | { |
776 | syncing = TRUE; | 776 | syncing = TRUE; |
777 | db->save(); | 777 | db->save(); |
778 | } | 778 | } |
779 | 779 | ||
780 | void DateBook::timerEvent( QTimerEvent *e ) | 780 | void DateBook::timerEvent( QTimerEvent *e ) |
781 | { | 781 | { |
782 | if ( alarmCounter < 10 ) { | 782 | if ( alarmCounter < 10 ) { |
783 | alarmCounter++; | 783 | alarmCounter++; |
784 | Sound::soundAlarm(); | 784 | Sound::soundAlarm(); |
785 | } else { | 785 | } else { |
786 | killTimer( e->timerId() ); | 786 | killTimer( e->timerId() ); |
787 | } | 787 | } |
788 | } | 788 | } |
789 | 789 | ||
790 | void DateBook::changeClock( bool newClock ) | 790 | void DateBook::changeClock( bool newClock ) |
791 | { | 791 | { |
792 | ampm = newClock; | 792 | ampm = newClock; |
793 | // repaint the affected objects... | 793 | // repaint the affected objects... |
794 | if (dayView) dayView->redraw(); | 794 | if (dayView) dayView->redraw(); |
795 | if (weekView) weekView->redraw(); | 795 | if (weekView) weekView->redraw(); |
796 | if (weekLstView) weekLstView->redraw(); | 796 | if (weekLstView) weekLstView->redraw(); |
797 | } | 797 | } |
798 | 798 | ||
799 | void DateBook::changeWeek( bool m ) | 799 | void DateBook::changeWeek( bool m ) |
800 | { | 800 | { |
801 | /* no need to redraw, each widget catches. Do need to | 801 | /* no need to redraw, each widget catches. Do need to |
802 | store though for widgets we haven't made yet */ | 802 | store though for widgets we haven't made yet */ |
803 | onMonday = m; | 803 | onMonday = m; |
804 | } | 804 | } |
805 | 805 | ||
806 | void DateBook::slotToday() | 806 | void DateBook::slotToday() |
807 | { | 807 | { |
808 | // we need to view today using default view | 808 | // we need to view today using default view |
809 | view(defaultView,QDate::currentDate()); | 809 | view(defaultView,QDate::currentDate()); |
810 | } | 810 | } |
811 | 811 | ||
812 | void DateBook::closeEvent( QCloseEvent *e ) | 812 | void DateBook::closeEvent( QCloseEvent *e ) |
813 | { | 813 | { |
814 | if(syncing) { | 814 | if(syncing) { |
815 | /* no need to save, did that at flush */ | 815 | /* no need to save, did that at flush */ |
816 | e->accept(); | 816 | e->accept(); |
817 | return; | 817 | return; |
818 | } | 818 | } |
819 | 819 | ||
820 | // save settings will generate it's own error messages, no | 820 | // save settings will generate it's own error messages, no |
821 | // need to do checking ourselves. | 821 | // need to do checking ourselves. |
822 | saveSettings(); | 822 | saveSettings(); |
823 | if ( db->save() ) { | 823 | if ( db->save() ) { |
824 | e->accept(); | 824 | e->accept(); |
825 | } else { | 825 | } else { |
826 | if ( QMessageBox::critical( this, tr( "Out of space" ), | 826 | if ( QMessageBox::critical( this, tr( "Out of space" ), |
827 | tr("Calendar was unable to save\n" | 827 | tr("Calendar was unable to save\n" |
828 | "your changes.\n" | 828 | "your changes.\n" |
829 | "Free up some space and try again.\n" | 829 | "Free up some space and try again.\n" |
830 | "\nQuit anyway?"), | 830 | "\nQuit anyway?"), |
831 | QMessageBox::Yes|QMessageBox::Escape, | 831 | QMessageBox::Yes|QMessageBox::Escape, |
832 | QMessageBox::No|QMessageBox::Default ) | 832 | QMessageBox::No|QMessageBox::Default ) |
833 | != QMessageBox::No ) | 833 | != QMessageBox::No ) |
834 | e->accept(); | 834 | e->accept(); |
835 | else | 835 | else |
836 | e->ignore(); | 836 | e->ignore(); |
837 | } | 837 | } |
838 | } | 838 | } |
839 | 839 | ||
840 | // Entering directly from the "keyboard" | 840 | // Entering directly from the "keyboard" |
841 | void DateBook::slotNewEventFromKey( const QString &str ) | 841 | void DateBook::slotNewEventFromKey( const QString &str ) |
842 | { | 842 | { |
843 | if (syncing) { | 843 | if (syncing) { |
844 | QMessageBox::warning( this, tr("Calendar"), | 844 | QMessageBox::warning( this, tr("Calendar"), |
845 | tr( "Can not edit data, currently syncing") ); | 845 | tr( "Can not edit data, currently syncing") ); |
846 | return; | 846 | return; |
847 | } | 847 | } |
848 | 848 | ||
849 | // We get to here from a key pressed in the Day View | 849 | // We get to here from a key pressed in the Day View |
850 | // So we can assume some things. We want the string | 850 | // So we can assume some things. We want the string |
851 | // passed in to be part of the description. | 851 | // passed in to be part of the description. |
852 | QDateTime start, end; | 852 | QDateTime start, end; |
853 | if ( views->visibleWidget() == dayView ) { | 853 | if ( views->visibleWidget() == dayView ) { |
854 | dayView->selectedDates( start, end ); | 854 | dayView->selectedDates( start, end ); |
855 | } else if ( views->visibleWidget() == monthView ) { | 855 | } else if ( views->visibleWidget() == monthView ) { |
856 | QDate d = monthView->selectedDate(); | 856 | QDate d = monthView->selectedDate(); |
857 | start = end = d; | 857 | start = end = d; |
858 | start.setTime( QTime( 10, 0 ) ); | 858 | start.setTime( QTime( 10, 0 ) ); |
859 | end.setTime( QTime( 12, 0 ) ); | 859 | end.setTime( QTime( 12, 0 ) ); |
860 | } else if ( views->visibleWidget() == weekView ) { | 860 | } else if ( views->visibleWidget() == weekView ) { |
861 | QDate d = weekView->date(); | 861 | QDate d = weekView->date(); |
862 | start = end = d; | 862 | start = end = d; |
863 | start.setTime( QTime( 10, 0 ) ); | 863 | start.setTime( QTime( 10, 0 ) ); |
864 | end.setTime( QTime( 12, 0 ) ); | 864 | end.setTime( QTime( 12, 0 ) ); |
865 | } else if ( views->visibleWidget() == weekLstView ) { | 865 | } else if ( views->visibleWidget() == weekLstView ) { |
866 | QDate d = weekLstView->date(); | 866 | QDate d = weekLstView->date(); |
867 | start = end = d; | 867 | start = end = d; |
868 | start.setTime( QTime( 10, 0 ) ); | 868 | start.setTime( QTime( 10, 0 ) ); |
869 | end.setTime( QTime( 12, 0 ) ); | 869 | end.setTime( QTime( 12, 0 ) ); |
870 | } | 870 | } |
871 | slotNewEntry(start, end, str); | 871 | slotNewEntry(start, end, str); |
872 | } | 872 | } |
873 | void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { | 873 | void DateBook::slotNewEntry(const QDateTime &start, const QDateTime &end, const QString &str, const QString &location) { |
874 | // argh! This really needs to be encapsulated in a class | 874 | // argh! This really needs to be encapsulated in a class |
875 | // or function. | 875 | // or function. |
876 | QDialog newDlg( this, 0, TRUE ); | 876 | QDialog newDlg( this, 0, TRUE ); |
877 | newDlg.setCaption( DateEntryBase::tr("New Event") ); | 877 | newDlg.setCaption( DateEntryBase::tr("New Event") ); |
878 | DateEntry *e; | 878 | DateEntry *e; |
879 | QVBoxLayout *vb = new QVBoxLayout( &newDlg ); | 879 | QVBoxLayout *vb = new QVBoxLayout( &newDlg ); |
880 | QScrollView *sv = new QScrollView( &newDlg ); | 880 | QScrollView *sv = new QScrollView( &newDlg ); |
881 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 881 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
882 | sv->setFrameStyle( QFrame::NoFrame ); | 882 | sv->setFrameStyle( QFrame::NoFrame ); |
883 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); | 883 | sv->setHScrollBarMode( QScrollView::AlwaysOff ); |
884 | vb->addWidget( sv ); | 884 | vb->addWidget( sv ); |
885 | 885 | ||
886 | Event ev; | 886 | Event ev; |
887 | ev.setDescription( str ); | 887 | ev.setDescription( str ); |
888 | // When the new gui comes in, change this... | 888 | // When the new gui comes in, change this... |
889 | if(location==0) { | 889 | if(location==0) { |
890 | if(defaultLocation.isEmpty()) { | 890 | if(defaultLocation.isEmpty()) { |
891 | ev.setLocation(tr("(Unknown)")); | 891 | ev.setLocation(tr("(Unknown)")); |
892 | } else { | 892 | } else { |
893 | ev.setLocation( defaultLocation ); | 893 | ev.setLocation( defaultLocation ); |
894 | } | 894 | } |
895 | } else { | 895 | } else { |
896 | ev.setLocation(location); | 896 | ev.setLocation(location); |
897 | } | 897 | } |
898 | ev.setCategories(defaultCategories); | 898 | ev.setCategories(defaultCategories); |
899 | ev.setStart( start ); | 899 | ev.setStart( start ); |
900 | ev.setEnd( end ); | 900 | ev.setEnd( end ); |
901 | 901 | ||
902 | e = new DateEntry( onMonday, ev, ampm, &newDlg ); | 902 | e = new DateEntry( onMonday, ev, ampm, &newDlg ); |
903 | e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); | 903 | e->setAlarmEnabled( aPreset, presetTime, Event::Loud ); |
904 | sv->addChild( e ); | 904 | sv->addChild( e ); |
905 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 905 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
906 | newDlg.showMaximized(); | 906 | newDlg.showMaximized(); |
907 | #endif | 907 | #endif |
908 | while (newDlg.exec()) { | 908 | while (newDlg.exec()) { |
909 | ev = e->event(); | 909 | ev = e->event(); |
910 | ev.assignUid(); | 910 | ev.assignUid(); |
911 | QString error = checkEvent( ev ); | 911 | QString error = checkEvent( ev ); |
912 | if ( !error.isNull() ) { | 912 | if ( !error.isNull() ) { |
913 | if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) | 913 | if ( QMessageBox::warning( this, tr("Error!"), error, tr("Fix it"), tr("Continue"), 0, 0, 1 ) == 0 ) |
914 | continue; | 914 | continue; |
915 | } | 915 | } |
916 | db->addEvent( ev ); | 916 | db->addEvent( ev ); |
917 | emit newEvent(); | 917 | emit newEvent(); |
918 | break; | 918 | break; |
919 | } | 919 | } |
920 | } | 920 | } |
921 | 921 | ||
922 | void DateBook::setDocument( const QString &filename ) | 922 | void DateBook::setDocument( const QString &filename ) |
923 | { | 923 | { |
924 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; | 924 | if ( filename.find(".vcs") != int(filename.length()) - 4 ) return; |
925 | 925 | ||
926 | QValueList<Event> tl = Event::readVCalendar( filename ); | 926 | QValueList<Event> tl = Event::readVCalendar( filename ); |
927 | for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { | 927 | for( QValueList<Event>::Iterator it = tl.begin(); it != tl.end(); ++it ) { |
928 | db->addEvent( *it ); | 928 | db->addEvent( *it ); |
929 | } | 929 | } |
930 | } | 930 | } |
931 | 931 | ||
932 | static const char * beamfile = "/tmp/obex/event.vcs"; | 932 | static const char * beamfile = "/tmp/obex/event.vcs"; |
933 | 933 | ||
934 | void DateBook::beamEvent( const Event &e ) | 934 | void DateBook::beamEvent( const Event &e ) |
935 | { | 935 | { |
936 | qDebug("trying to beamn"); | 936 | qDebug("trying to beamn"); |
937 | unlink( beamfile ); // delete if exists | 937 | unlink( beamfile ); // delete if exists |
938 | mkdir("/tmp/obex/", 0755); | 938 | mkdir("/tmp/obex/", 0755); |
939 | Event::writeVCalendar( beamfile, e ); | 939 | Event::writeVCalendar( beamfile, e ); |
940 | Ir *ir = new Ir( this ); | 940 | Ir *ir = new Ir( this ); |
941 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); | 941 | connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); |
942 | QString description = e.description(); | 942 | QString description = e.description(); |
943 | ir->send( beamfile, description, "text/x-vCalendar" ); | 943 | ir->send( beamfile, description, "text/x-vCalendar" ); |
944 | } | 944 | } |
945 | 945 | ||
946 | void DateBook::beamDone( Ir *ir ) | 946 | void DateBook::beamDone( Ir *ir ) |
947 | { | 947 | { |
948 | delete ir; | 948 | delete ir; |
949 | unlink( beamfile ); | 949 | unlink( beamfile ); |
950 | } | 950 | } |
951 | 951 | ||
952 | void DateBook::slotFind() | 952 | void DateBook::slotFind() |
953 | { | 953 | { |
954 | // move it to the day view... | 954 | // move it to the day view... |
955 | viewDay(); | 955 | viewDay(); |
956 | FindDialog frmFind( "Calendar", this ); // no tr needed | 956 | FindDialog frmFind( "Calendar", this ); // no tr needed |
957 | frmFind.setUseDate( true ); | 957 | frmFind.setUseDate( true ); |
958 | frmFind.setDate( currentDate() ); | 958 | frmFind.setDate( currentDate() ); |
959 | QObject::connect( &frmFind, | 959 | QObject::connect( &frmFind, |
960 | SIGNAL(signalFindClicked(const QString&, const QDate&, | 960 | SIGNAL(signalFindClicked(const QString&, const QDate&, |
961 | bool, bool, int)), | 961 | bool, bool, int)), |
962 | this, | 962 | this, |
963 | SLOT(slotDoFind(const QString&, const QDate&, | 963 | SLOT(slotDoFind(const QString&, const QDate&, |
964 | bool, bool, int)) ); | 964 | bool, bool, int)) ); |
965 | QObject::connect( this, | 965 | QObject::connect( this, |
966 | SIGNAL(signalNotFound()), | 966 | SIGNAL(signalNotFound()), |
967 | &frmFind, | 967 | &frmFind, |
968 | SLOT(slotNotFound()) ); | 968 | SLOT(slotNotFound()) ); |
969 | QObject::connect( this, | 969 | QObject::connect( this, |
970 | SIGNAL(signalWrapAround()), | 970 | SIGNAL(signalWrapAround()), |
971 | &frmFind, | 971 | &frmFind, |
972 | SLOT(slotWrapAround()) ); | 972 | SLOT(slotWrapAround()) ); |
973 | frmFind.move(0,0); | 973 | frmFind.move(0,0); |
974 | frmFind.exec(); | 974 | frmFind.exec(); |
975 | inSearch = false; | 975 | inSearch = false; |
976 | } | 976 | } |
977 | 977 | ||
978 | bool catComp( QArray<int> cats, int category ) | 978 | bool catComp( QArray<int> cats, int category ) |
979 | { | 979 | { |
980 | bool returnMe; | 980 | bool returnMe; |
981 | int i, | 981 | int i, |
982 | count; | 982 | count; |
983 | 983 | ||
984 | count = int(cats.count()); | 984 | count = int(cats.count()); |
985 | returnMe = false; | 985 | returnMe = false; |
986 | if ( (category == -1 && count == 0) || category == -2 ) | 986 | if ( (category == -1 && count == 0) || category == -2 ) |
987 | returnMe = true; | 987 | returnMe = true; |
988 | else { | 988 | else { |
989 | for ( i = 0; i < count; i++ ) { | 989 | for ( i = 0; i < count; i++ ) { |
990 | if ( category == cats[i] ) { | 990 | if ( category == cats[i] ) { |
991 | returnMe = true; | 991 | returnMe = true; |
992 | break; | 992 | break; |
993 | } | 993 | } |
994 | } | 994 | } |
995 | } | 995 | } |
996 | return returnMe; | 996 | return returnMe; |
997 | } | 997 | } |
998 | 998 | ||
999 | 999 | ||
1000 | void DateBook::slotDoFind( const QString& txt, const QDate &dt, | 1000 | void DateBook::slotDoFind( const QString& txt, const QDate &dt, |
1001 | bool caseSensitive, bool /*backwards*/, | 1001 | bool caseSensitive, bool /*backwards*/, |
1002 | int category ) | 1002 | int category ) |
1003 | { | 1003 | { |
1004 | QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), | 1004 | QDateTime dtEnd( QDate(3001, 1, 1), QTime(0, 0, 0) ), |
1005 | next; | 1005 | next; |
1006 | 1006 | ||
1007 | QRegExp r( txt ); | 1007 | QRegExp r( txt ); |
1008 | r.setCaseSensitive( caseSensitive ); | 1008 | r.setCaseSensitive( caseSensitive ); |
1009 | 1009 | ||
1010 | 1010 | ||
1011 | static Event rev, | 1011 | static Event rev, |
1012 | nonrev; | 1012 | nonrev; |
1013 | if ( !inSearch ) { | 1013 | if ( !inSearch ) { |
1014 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); | 1014 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); |
1015 | nonrev.setStart( rev.start() ); | 1015 | nonrev.setStart( rev.start() ); |
1016 | inSearch = true; | 1016 | inSearch = true; |
1017 | } | 1017 | } |
1018 | static QDate searchDate = dt; | 1018 | static QDate searchDate = dt; |
1019 | static bool wrapAround = true; | 1019 | static bool wrapAround = true; |
1020 | bool candidtate; | 1020 | bool candidtate; |
1021 | candidtate = false; | 1021 | candidtate = false; |
1022 | 1022 | ||
1023 | QValueList<Event> repeats = db->getRawRepeats(); | 1023 | QValueList<Event> repeats = db->getRawRepeats(); |
1024 | 1024 | ||
1025 | // find the candidate for the first repeat that matches... | 1025 | // find the candidate for the first repeat that matches... |
1026 | QValueListConstIterator<Event> it; | 1026 | QValueListConstIterator<Event> it; |
1027 | QDate start = dt; | 1027 | QDate start = dt; |
1028 | for ( it = repeats.begin(); it != repeats.end(); ++it ) { | 1028 | for ( it = repeats.begin(); it != repeats.end(); ++it ) { |
1029 | if ( catComp( (*it).categories(), category ) ) { | 1029 | if ( catComp( (*it).categories(), category ) ) { |
1030 | while ( nextOccurance( *it, start, next ) ) { | 1030 | while ( nextOccurance( *it, start, next ) ) { |
1031 | if ( next < dtEnd ) { | 1031 | if ( next < dtEnd ) { |
1032 | if ( (*it).match( r ) && !(next <= rev.start()) ) { | 1032 | if ( (*it).match( r ) && !(next <= rev.start()) ) { |
1033 | rev = *it; | 1033 | rev = *it; |
1034 | dtEnd = next; | 1034 | dtEnd = next; |
1035 | rev.setStart( next ); | 1035 | rev.setStart( next ); |
1036 | candidtate = true; | 1036 | candidtate = true; |
1037 | wrapAround = true; | 1037 | wrapAround = true; |
1038 | start = dt; | 1038 | start = dt; |
1039 | break; | 1039 | break; |
1040 | } else | 1040 | } else |
1041 | start = next.date().addDays( 1 ); | 1041 | start = next.date().addDays( 1 ); |
1042 | } | 1042 | } |
1043 | } | 1043 | } |
1044 | } | 1044 | } |
1045 | } | 1045 | } |
1046 | 1046 | ||
1047 | // now the for first non repeat... | 1047 | // now the for first non repeat... |
1048 | QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); | 1048 | QValueList<Event> nonRepeats = db->getNonRepeatingEvents( dt, dtEnd.date() ); |
1049 | qHeapSort( nonRepeats.begin(), nonRepeats.end() ); | 1049 | qHeapSort( nonRepeats.begin(), nonRepeats.end() ); |
1050 | for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { | 1050 | for ( it = nonRepeats.begin(); it != nonRepeats.end(); ++it ) { |
1051 | if ( catComp( (*it).categories(), category ) ) { | 1051 | if ( catComp( (*it).categories(), category ) ) { |
1052 | if ( (*it).start() < dtEnd ) { | 1052 | if ( (*it).start() < dtEnd ) { |
1053 | if ( (*it).match( r ) && !(*it <= nonrev) ) { | 1053 | if ( (*it).match( r ) && !(*it <= nonrev) ) { |
1054 | nonrev = *it; | 1054 | nonrev = *it; |
1055 | dtEnd = nonrev.start(); | 1055 | dtEnd = nonrev.start(); |
1056 | candidtate = true; | 1056 | candidtate = true; |
1057 | wrapAround = true; | 1057 | wrapAround = true; |
1058 | break; | 1058 | break; |
1059 | } | 1059 | } |
1060 | } | 1060 | } |
1061 | } | 1061 | } |
1062 | } | 1062 | } |
1063 | if ( candidtate ) { | 1063 | if ( candidtate ) { |
1064 | dayView->setStartViewTime( dtEnd.time().hour() ); | 1064 | dayView->setStartViewTime( dtEnd.time().hour() ); |
1065 | dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), | 1065 | dayView->setDate( dtEnd.date().year(), dtEnd.date().month(), |
1066 | dtEnd.date().day() ); | 1066 | dtEnd.date().day() ); |
1067 | } else { | 1067 | } else { |
1068 | if ( wrapAround ) { | 1068 | if ( wrapAround ) { |
1069 | emit signalWrapAround(); | 1069 | emit signalWrapAround(); |
1070 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); | 1070 | rev.setStart( QDateTime(QDate(1960, 1, 1), QTime(0, 0, 0)) ); |
1071 | nonrev.setStart( rev.start() ); | 1071 | nonrev.setStart( rev.start() ); |
1072 | } else | 1072 | } else |
1073 | emit signalNotFound(); | 1073 | emit signalNotFound(); |
1074 | wrapAround = !wrapAround; | 1074 | wrapAround = !wrapAround; |
1075 | } | 1075 | } |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | Event DateBookDBHack::eventByUID(int uid) { | 1078 | Event DateBookDBHack::eventByUID(int uid) { |
1079 | 1079 | ||
1080 | // FIXME: Dirty Hacks to get hold of the private event lists | 1080 | // FIXME: Dirty Hacks to get hold of the private event lists |
1081 | QDate start; | 1081 | QDate start; |
1082 | QDate end=start.addDays(-1); | 1082 | QDate end=start.addDays(-1); |
1083 | QValueList<Event> myEventList=getNonRepeatingEvents(start,end); | 1083 | QValueList<Event> myEventList=getNonRepeatingEvents(start,end); |
1084 | QValueList<Event> myRepeatEvents=getRawRepeats(); | 1084 | QValueList<Event> myRepeatEvents=getRawRepeats(); |
1085 | 1085 | ||
1086 | QValueList<Event>::ConstIterator it; | 1086 | QValueList<Event>::ConstIterator it; |
1087 | 1087 | ||
1088 | for (it = myEventList.begin(); it != myEventList.end(); it++) { | 1088 | for (it = myEventList.begin(); it != myEventList.end(); it++) { |
1089 | if ((*it).uid() == uid) return *it; | 1089 | if ((*it).uid() == uid) return *it; |
1090 | } | 1090 | } |
1091 | for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { | 1091 | for (it = myRepeatEvents.begin(); it != myRepeatEvents.end(); it++) { |
1092 | if ((*it).uid() == uid) return *it; | 1092 | if ((*it).uid() == uid) return *it; |
1093 | } | 1093 | } |
1094 | 1094 | ||
1095 | qDebug("Event not found: uid=%d\n", uid); | 1095 | qDebug("Event not found: uid=%d\n", uid); |
1096 | Event ev; | 1096 | Event ev; |
1097 | return ev; // return at least | 1097 | return ev; // return at least |
1098 | } | 1098 | } |
1099 | 1099 | ||
diff --git a/core/pim/datebook2/mainwindow.cpp b/core/pim/datebook2/mainwindow.cpp index 7d436ae..be30415 100644 --- a/core/pim/datebook2/mainwindow.cpp +++ b/core/pim/datebook2/mainwindow.cpp | |||
@@ -1,305 +1,305 @@ | |||
1 | 1 | ||
2 | #include <qcopchannel_qws.h> | 2 | #include <qcopchannel_qws.h> |
3 | #include <qwidgetstack.h> | 3 | #include <qwidgetstack.h> |
4 | #include <qlabel.h> | 4 | #include <qlabel.h> |
5 | #include <qaction.h> | 5 | #include <qaction.h> |
6 | #include <qpopupmenu.h> | 6 | #include <qpopupmenu.h> |
7 | #include <qtimer.h> | 7 | #include <qtimer.h> |
8 | 8 | ||
9 | #include <qpe/qpeapplication.h> | 9 | #include <qpe/qpeapplication.h> |
10 | #include <qpe/ir.h> | 10 | #include <qpe/ir.h> |
11 | #include <qmenubar.h> | 11 | #include <qmenubar.h> |
12 | #include <qpe/qpetoolbar.h> | 12 | #include <qtoolbar.h> |
13 | #include <qpe/qpemessagebox.h> | 13 | #include <qpe/qpemessagebox.h> |
14 | #include <qpe/resource.h> | 14 | #include <qpe/resource.h> |
15 | 15 | ||
16 | #include "editor.h" | 16 | #include "editor.h" |
17 | #include "show.h" | 17 | #include "show.h" |
18 | #include "templatemanager.h" | 18 | #include "templatemanager.h" |
19 | #include "bookmanager.h" | 19 | #include "bookmanager.h" |
20 | #include "mainwindow.h" | 20 | #include "mainwindow.h" |
21 | 21 | ||
22 | 22 | ||
23 | using namespace Datebook; | 23 | using namespace Datebook; |
24 | 24 | ||
25 | MainWindow::MainWindow() | 25 | MainWindow::MainWindow() |
26 | : OPimMainWindow( "Datebook", 0, 0 ), m_descMan( "Descriptions" ), m_locMan( "Locations" ) | 26 | : OPimMainWindow( "Datebook", 0, 0 ), m_descMan( "Descriptions" ), m_locMan( "Locations" ) |
27 | { | 27 | { |
28 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); | 28 | setIcon( Resource::loadPixmap( "datebook_icon" ) ); |
29 | initUI(); | 29 | initUI(); |
30 | initManagers(); | 30 | initManagers(); |
31 | initView(); | 31 | initView(); |
32 | initConfig(); | 32 | initConfig(); |
33 | 33 | ||
34 | QTimer::singleShot(0, this, SLOT(populate() ) ); | 34 | QTimer::singleShot(0, this, SLOT(populate() ) ); |
35 | 35 | ||
36 | QCopChannel* chan = new QCopChannel( "QPE/System", this ); | 36 | QCopChannel* chan = new QCopChannel( "QPE/System", this ); |
37 | connect( chan, SIGNAL( received(const QCString&, const QByteArray& ) ), | 37 | connect( chan, SIGNAL( received(const QCString&, const QByteArray& ) ), |
38 | this, SLOT( slotReceive( const QCString&, const QByteArray& ) ) ); | 38 | this, SLOT( slotReceive( const QCString&, const QByteArray& ) ) ); |
39 | 39 | ||
40 | chan = new QCopChannel( "QPE/Datebook", this ); | 40 | chan = new QCopChannel( "QPE/Datebook", this ); |
41 | connect( chan, SIGNAL( received(const QCString&, const QByteArray& ) ), | 41 | connect( chan, SIGNAL( received(const QCString&, const QByteArray& ) ), |
42 | this, SLOT( slotReceive( const QCString&, const QByteArray& ) ) ); | 42 | this, SLOT( slotReceive( const QCString&, const QByteArray& ) ) ); |
43 | } | 43 | } |
44 | MainWindow::~MainWindow() { | 44 | MainWindow::~MainWindow() { |
45 | m_tempMan.save(); | 45 | m_tempMan.save(); |
46 | m_locMan.save(); | 46 | m_locMan.save(); |
47 | m_descMan.save(); | 47 | m_descMan.save(); |
48 | 48 | ||
49 | manager()->save(); | 49 | manager()->save(); |
50 | delete m_manager; | 50 | delete m_manager; |
51 | } | 51 | } |
52 | void MainWindow::doSetDocument( const QString& str ) { | 52 | void MainWindow::doSetDocument( const QString& str ) { |
53 | 53 | ||
54 | } | 54 | } |
55 | void MainWindow::flush() { | 55 | void MainWindow::flush() { |
56 | manager()->save(); | 56 | manager()->save(); |
57 | } | 57 | } |
58 | void MainWindow::reload() { | 58 | void MainWindow::reload() { |
59 | manager()->reload(); | 59 | manager()->reload(); |
60 | } | 60 | } |
61 | int MainWindow::create() { | 61 | int MainWindow::create() { |
62 | return 0; | 62 | return 0; |
63 | } | 63 | } |
64 | bool MainWindow::remove( int uid ) { | 64 | bool MainWindow::remove( int uid ) { |
65 | manager()->remove( uid ); | 65 | manager()->remove( uid ); |
66 | return true; | 66 | return true; |
67 | } | 67 | } |
68 | void MainWindow::beam( int uid ) { | 68 | void MainWindow::beam( int uid ) { |
69 | 69 | ||
70 | } | 70 | } |
71 | void MainWindow::show( int uid ) { | 71 | void MainWindow::show( int uid ) { |
72 | 72 | ||
73 | eventShow()->show( manager()->event( uid ) ); | 73 | eventShow()->show( manager()->event( uid ) ); |
74 | } | 74 | } |
75 | void MainWindow::add( const OPimRecord& ad) { | 75 | void MainWindow::add( const OPimRecord& ad) { |
76 | manager()->add( ad ); | 76 | manager()->add( ad ); |
77 | } | 77 | } |
78 | void MainWindow::edit() { | 78 | void MainWindow::edit() { |
79 | edit ( currentView()->currentItem() ); | 79 | edit ( currentView()->currentItem() ); |
80 | } | 80 | } |
81 | void MainWindow::edit( int uid ) { | 81 | void MainWindow::edit( int uid ) { |
82 | 82 | ||
83 | } | 83 | } |
84 | /* | 84 | /* |
85 | * init tool bars layout and so on | 85 | * init tool bars layout and so on |
86 | */ | 86 | */ |
87 | void MainWindow::initUI() { | 87 | void MainWindow::initUI() { |
88 | setToolBarsMovable( false ); | 88 | setToolBarsMovable( false ); |
89 | 89 | ||
90 | m_stack = new QWidgetStack( this ); | 90 | m_stack = new QWidgetStack( this ); |
91 | setCentralWidget( m_stack ); | 91 | setCentralWidget( m_stack ); |
92 | 92 | ||
93 | m_toolBar = new QPEToolBar( this ); | 93 | m_toolBar = new QToolBar( this ); |
94 | m_toolBar->setHorizontalStretchable( TRUE ); | 94 | m_toolBar->setHorizontalStretchable( TRUE ); |
95 | 95 | ||
96 | QMenuBar* mb = new QMenuBar( m_toolBar ); | 96 | QMenuBar* mb = new QMenuBar( m_toolBar ); |
97 | 97 | ||
98 | m_popView = new QPopupMenu( this ); | 98 | m_popView = new QPopupMenu( this ); |
99 | m_popSetting = new QPopupMenu( this ); | 99 | m_popSetting = new QPopupMenu( this ); |
100 | 100 | ||
101 | mb->insertItem( tr("View"), m_popView ); | 101 | mb->insertItem( tr("View"), m_popView ); |
102 | mb->insertItem( tr("Settings" ), m_popSetting ); | 102 | mb->insertItem( tr("Settings" ), m_popSetting ); |
103 | 103 | ||
104 | m_popTemplate = new QPopupMenu( this ); | 104 | m_popTemplate = new QPopupMenu( this ); |
105 | m_popTemplate->setCheckable( TRUE ); | 105 | m_popTemplate->setCheckable( TRUE ); |
106 | connect( m_popTemplate, SIGNAL(activated(int) ), | 106 | connect( m_popTemplate, SIGNAL(activated(int) ), |
107 | this, SLOT(slotNewFromTemplate(int) ) ); | 107 | this, SLOT(slotNewFromTemplate(int) ) ); |
108 | m_popView->insertItem(tr("New from template"), m_popTemplate, -1, 0); | 108 | m_popView->insertItem(tr("New from template"), m_popTemplate, -1, 0); |
109 | 109 | ||
110 | 110 | ||
111 | QAction* a = new QAction( tr("New Event"), Resource::loadPixmap("new"), | 111 | QAction* a = new QAction( tr("New Event"), Resource::loadPixmap("new"), |
112 | QString::null, 0, this, 0 ); | 112 | QString::null, 0, this, 0 ); |
113 | a->addTo( m_toolBar ); | 113 | a->addTo( m_toolBar ); |
114 | a->addTo( m_popView ); | 114 | a->addTo( m_popView ); |
115 | connect(a, SIGNAL( activated() ), this, SLOT( create() ) ); | 115 | connect(a, SIGNAL( activated() ), this, SLOT( create() ) ); |
116 | 116 | ||
117 | a = new QAction( tr("Edit Event"), Resource::loadPixmap("edit"), | 117 | a = new QAction( tr("Edit Event"), Resource::loadPixmap("edit"), |
118 | QString::null, 0, this, 0 ); | 118 | QString::null, 0, this, 0 ); |
119 | a->addTo( m_popView ); | 119 | a->addTo( m_popView ); |
120 | connect(a, SIGNAL( activated() ), this, SLOT( edit() ) ); | 120 | connect(a, SIGNAL( activated() ), this, SLOT( edit() ) ); |
121 | 121 | ||
122 | a = new QAction( tr("Today" ), Resource::loadPixmap( "datebook/to_day"), | 122 | a = new QAction( tr("Today" ), Resource::loadPixmap( "datebook/to_day"), |
123 | QString::null, 0, this, 0 ); | 123 | QString::null, 0, this, 0 ); |
124 | a->addTo( m_toolBar ); | 124 | a->addTo( m_toolBar ); |
125 | connect(a, SIGNAL( activated() ), this, SLOT( slotGoToNow() ) ); | 125 | connect(a, SIGNAL( activated() ), this, SLOT( slotGoToNow() ) ); |
126 | 126 | ||
127 | a = new QAction( tr("Find"), Resource::loadPixmap( "mag" ), | 127 | a = new QAction( tr("Find"), Resource::loadPixmap( "mag" ), |
128 | QString::null, 0, this, 0 ); | 128 | QString::null, 0, this, 0 ); |
129 | a->addTo( m_toolBar ); | 129 | a->addTo( m_toolBar ); |
130 | connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); | 130 | connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); |
131 | 131 | ||
132 | a = new QAction( tr("Configure"), QString::null, 0, 0 ); | 132 | a = new QAction( tr("Configure"), QString::null, 0, 0 ); |
133 | a->addTo( m_popSetting ); | 133 | a->addTo( m_popSetting ); |
134 | connect(a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); | 134 | connect(a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); |
135 | 135 | ||
136 | a = new QAction( tr("Configure Locations"), QString::null, 0, 0 ); | 136 | a = new QAction( tr("Configure Locations"), QString::null, 0, 0 ); |
137 | a->addTo( m_popSetting ); | 137 | a->addTo( m_popSetting ); |
138 | connect(a, SIGNAL( activated() ), this, SLOT( slotConfigureLocs() ) ); | 138 | connect(a, SIGNAL( activated() ), this, SLOT( slotConfigureLocs() ) ); |
139 | 139 | ||
140 | a = new QAction( tr("Configure Descriptions"), QString::null, 0, 0 ); | 140 | a = new QAction( tr("Configure Descriptions"), QString::null, 0, 0 ); |
141 | a->addTo( m_popSetting ); | 141 | a->addTo( m_popSetting ); |
142 | connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureDesc() ) ); | 142 | connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureDesc() ) ); |
143 | 143 | ||
144 | a = new QAction( tr("Configure Templates"), QString::null, 0, 0 ); | 144 | a = new QAction( tr("Configure Templates"), QString::null, 0, 0 ); |
145 | a->addTo( m_popSetting ); | 145 | a->addTo( m_popSetting ); |
146 | connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureTemp() ) ); | 146 | connect(a, SIGNAL( activated() ), this, SLOT(slotConfigureTemp() ) ); |
147 | 147 | ||
148 | connect( qApp, SIGNAL(clockChanged(bool) ), | 148 | connect( qApp, SIGNAL(clockChanged(bool) ), |
149 | this, SLOT(slotClockChanged(bool) ) ); | 149 | this, SLOT(slotClockChanged(bool) ) ); |
150 | connect( qApp, SIGNAL(weekChanged(bool) ), | 150 | connect( qApp, SIGNAL(weekChanged(bool) ), |
151 | this, SLOT(slotWeekChanged(bool) ) ); | 151 | this, SLOT(slotWeekChanged(bool) ) ); |
152 | 152 | ||
153 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), | 153 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray& ) ), |
154 | this, SLOT(slotAppMessage( const QCString&, const QByteArray& ) ) ); | 154 | this, SLOT(slotAppMessage( const QCString&, const QByteArray& ) ) ); |
155 | } | 155 | } |
156 | void MainWindow::initConfig() { | 156 | void MainWindow::initConfig() { |
157 | 157 | ||
158 | } | 158 | } |
159 | void MainWindow::initView() { | 159 | void MainWindow::initView() { |
160 | 160 | ||
161 | } | 161 | } |
162 | void MainWindow::initManagers() { | 162 | void MainWindow::initManagers() { |
163 | m_manager = new BookManager; | 163 | m_manager = new BookManager; |
164 | 164 | ||
165 | m_tempMan.load(); | 165 | m_tempMan.load(); |
166 | m_locMan.load(); | 166 | m_locMan.load(); |
167 | m_descMan.load(); | 167 | m_descMan.load(); |
168 | 168 | ||
169 | setTemplateMenu(); | 169 | setTemplateMenu(); |
170 | } | 170 | } |
171 | void MainWindow::raiseCurrentView() { | 171 | void MainWindow::raiseCurrentView() { |
172 | 172 | ||
173 | } | 173 | } |
174 | /* | 174 | /* |
175 | * populate the view | 175 | * populate the view |
176 | */ | 176 | */ |
177 | void MainWindow::populate() { | 177 | void MainWindow::populate() { |
178 | if (!manager()->isLoaded() ) | 178 | if (!manager()->isLoaded() ) |
179 | manager()->load(); | 179 | manager()->load(); |
180 | } | 180 | } |
181 | void MainWindow::slotGoToNow() { | 181 | void MainWindow::slotGoToNow() { |
182 | 182 | ||
183 | } | 183 | } |
184 | View* MainWindow::currentView() { | 184 | View* MainWindow::currentView() { |
185 | 185 | ||
186 | } | 186 | } |
187 | void MainWindow::slotFind() { | 187 | void MainWindow::slotFind() { |
188 | 188 | ||
189 | } | 189 | } |
190 | void MainWindow::slotConfigure() { | 190 | void MainWindow::slotConfigure() { |
191 | 191 | ||
192 | } | 192 | } |
193 | void MainWindow::slotClockChanged( bool ) { | 193 | void MainWindow::slotClockChanged( bool ) { |
194 | 194 | ||
195 | } | 195 | } |
196 | void MainWindow::slotWeekChanged(bool ) { | 196 | void MainWindow::slotWeekChanged(bool ) { |
197 | 197 | ||
198 | } | 198 | } |
199 | void MainWindow::slotAppMessage( const QCString&, const QByteArray& ) { | 199 | void MainWindow::slotAppMessage( const QCString&, const QByteArray& ) { |
200 | 200 | ||
201 | } | 201 | } |
202 | void MainWindow::slotReceive( const QCString&, const QByteArray& ) { | 202 | void MainWindow::slotReceive( const QCString&, const QByteArray& ) { |
203 | 203 | ||
204 | } | 204 | } |
205 | BookManager* MainWindow::manager() { | 205 | BookManager* MainWindow::manager() { |
206 | return m_manager; | 206 | return m_manager; |
207 | } | 207 | } |
208 | TemplateManager MainWindow::templateManager() { | 208 | TemplateManager MainWindow::templateManager() { |
209 | return m_tempMan; | 209 | return m_tempMan; |
210 | } | 210 | } |
211 | LocationManager MainWindow::locationManager() { | 211 | LocationManager MainWindow::locationManager() { |
212 | return m_locMan; | 212 | return m_locMan; |
213 | } | 213 | } |
214 | DescriptionManager MainWindow::descriptionManager() { | 214 | DescriptionManager MainWindow::descriptionManager() { |
215 | return m_descMan; | 215 | return m_descMan; |
216 | } | 216 | } |
217 | void MainWindow::setLocationManager( const LocationManager& loc) { | 217 | void MainWindow::setLocationManager( const LocationManager& loc) { |
218 | m_locMan = loc; | 218 | m_locMan = loc; |
219 | } | 219 | } |
220 | void MainWindow::setDescriptionManager( const DescriptionManager& dsc ) { | 220 | void MainWindow::setDescriptionManager( const DescriptionManager& dsc ) { |
221 | m_descMan = dsc; | 221 | m_descMan = dsc; |
222 | } | 222 | } |
223 | Show* MainWindow::eventShow() { | 223 | Show* MainWindow::eventShow() { |
224 | return m_show; | 224 | return m_show; |
225 | } | 225 | } |
226 | void MainWindow::slotAction( QAction* act ) { | 226 | void MainWindow::slotAction( QAction* act ) { |
227 | 227 | ||
228 | } | 228 | } |
229 | void MainWindow::slotConfigureLocs() { | 229 | void MainWindow::slotConfigureLocs() { |
230 | LocationManagerDialog dlg( locationManager() ); | 230 | LocationManagerDialog dlg( locationManager() ); |
231 | dlg.setCaption( tr("Configure Locations") ); | 231 | dlg.setCaption( tr("Configure Locations") ); |
232 | dlg.showMaximized(); | 232 | dlg.showMaximized(); |
233 | if (dlg.exec() == QDialog::Accepted ) { | 233 | if (dlg.exec() == QDialog::Accepted ) { |
234 | setLocationManager( dlg.manager() ); | 234 | setLocationManager( dlg.manager() ); |
235 | } | 235 | } |
236 | } | 236 | } |
237 | void MainWindow::slotConfigureDesc() { | 237 | void MainWindow::slotConfigureDesc() { |
238 | DescriptionManagerDialog dlg( descriptionManager() ); | 238 | DescriptionManagerDialog dlg( descriptionManager() ); |
239 | dlg.setCaption( tr("Configure Descriptions") ); | 239 | dlg.setCaption( tr("Configure Descriptions") ); |
240 | dlg.showMaximized(); | 240 | dlg.showMaximized(); |
241 | if (dlg.exec() == QDialog::Accepted ) { | 241 | if (dlg.exec() == QDialog::Accepted ) { |
242 | setDescriptionManager( dlg.manager() ); | 242 | setDescriptionManager( dlg.manager() ); |
243 | } | 243 | } |
244 | } | 244 | } |
245 | void MainWindow::slotConfigureTemp() { | 245 | void MainWindow::slotConfigureTemp() { |
246 | TemplateDialog dlg( templateManager(), editor() ); | 246 | TemplateDialog dlg( templateManager(), editor() ); |
247 | dlg.setCaption( tr("Configure Templates") ); | 247 | dlg.setCaption( tr("Configure Templates") ); |
248 | dlg.showMaximized(); | 248 | dlg.showMaximized(); |
249 | if ( dlg.exec() == QDialog::Accepted ) { | 249 | if ( dlg.exec() == QDialog::Accepted ) { |
250 | m_tempMan = dlg.manager(); | 250 | m_tempMan = dlg.manager(); |
251 | setTemplateMenu(); | 251 | setTemplateMenu(); |
252 | } | 252 | } |
253 | } | 253 | } |
254 | void MainWindow::hideShow() { | 254 | void MainWindow::hideShow() { |
255 | 255 | ||
256 | } | 256 | } |
257 | void MainWindow::viewPopup(int ) { | 257 | void MainWindow::viewPopup(int ) { |
258 | 258 | ||
259 | } | 259 | } |
260 | void MainWindow::viewAdd(const QDate& ) { | 260 | void MainWindow::viewAdd(const QDate& ) { |
261 | 261 | ||
262 | } | 262 | } |
263 | void MainWindow::viewAdd( const QDateTime&, const QDateTime& ) { | 263 | void MainWindow::viewAdd( const QDateTime&, const QDateTime& ) { |
264 | 264 | ||
265 | } | 265 | } |
266 | bool MainWindow::viewAP()const{ | 266 | bool MainWindow::viewAP()const{ |
267 | } | 267 | } |
268 | bool MainWindow::viewStartMonday()const { | 268 | bool MainWindow::viewStartMonday()const { |
269 | 269 | ||
270 | } | 270 | } |
271 | void MainWindow::setTemplateMenu() { | 271 | void MainWindow::setTemplateMenu() { |
272 | m_popTemplate->clear(); | 272 | m_popTemplate->clear(); |
273 | 273 | ||
274 | QStringList list = templateManager().names(); | 274 | QStringList list = templateManager().names(); |
275 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { | 275 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { |
276 | m_popTemplate->insertItem( (*it) ); | 276 | m_popTemplate->insertItem( (*it) ); |
277 | } | 277 | } |
278 | } | 278 | } |
279 | /* | 279 | /* |
280 | * get the name of the item with the id id | 280 | * get the name of the item with the id id |
281 | * then ask for an OEvent from the manager | 281 | * then ask for an OEvent from the manager |
282 | */ | 282 | */ |
283 | void MainWindow::slotNewFromTemplate(int id ) { | 283 | void MainWindow::slotNewFromTemplate(int id ) { |
284 | QString name = m_popTemplate->text( id ); | 284 | QString name = m_popTemplate->text( id ); |
285 | 285 | ||
286 | OEvent ev = templateManager().value( name ); | 286 | OEvent ev = templateManager().value( name ); |
287 | 287 | ||
288 | if ( editor()->edit( ev ) ) { | 288 | if ( editor()->edit( ev ) ) { |
289 | ev = editor()->event(); | 289 | ev = editor()->event(); |
290 | ev.setUid( -1 ); | 290 | ev.setUid( -1 ); |
291 | manager()->add( ev ); | 291 | manager()->add( ev ); |
292 | 292 | ||
293 | /* | 293 | /* |
294 | * no we'll find out if the current view | 294 | * no we'll find out if the current view |
295 | * should show the new event | 295 | * should show the new event |
296 | * and then we will ask it to refresh | 296 | * and then we will ask it to refresh |
297 | * FIXME for now we'll call a refresh | 297 | * FIXME for now we'll call a refresh |
298 | */ | 298 | */ |
299 | currentView()->reschedule(); | 299 | currentView()->reschedule(); |
300 | raiseCurrentView(); | 300 | raiseCurrentView(); |
301 | } | 301 | } |
302 | } | 302 | } |
303 | Editor* MainWindow::editor() { | 303 | Editor* MainWindow::editor() { |
304 | return m_edit; | 304 | return m_edit; |
305 | } | 305 | } |
diff --git a/core/pim/datebook2/mainwindow.h b/core/pim/datebook2/mainwindow.h index 3c22637..33ef864 100644 --- a/core/pim/datebook2/mainwindow.h +++ b/core/pim/datebook2/mainwindow.h | |||
@@ -1,107 +1,107 @@ | |||
1 | #ifndef DATE_BOOK_MAIN_WINDOW_H | 1 | #ifndef DATE_BOOK_MAIN_WINDOW_H |
2 | #define DATE_BOOK_MAIN_WINDOW_H | 2 | #define DATE_BOOK_MAIN_WINDOW_H |
3 | 3 | ||
4 | #include <qlist.h> | 4 | #include <qlist.h> |
5 | 5 | ||
6 | #include <opie/opimmainwindow.h> | 6 | #include <opie/opimmainwindow.h> |
7 | 7 | ||
8 | #include "descriptionmanager.h" | 8 | #include "descriptionmanager.h" |
9 | #include "locationmanager.h" | 9 | #include "locationmanager.h" |
10 | #include "templatemanager.h" | 10 | #include "templatemanager.h" |
11 | #include "view.h" | 11 | #include "view.h" |
12 | 12 | ||
13 | class QAction; | 13 | class QAction; |
14 | class QWidgetStack; | 14 | class QWidgetStack; |
15 | class QPopupMenu; | 15 | class QPopupMenu; |
16 | class QPEToolBar; | 16 | class QToolBar; |
17 | namespace Datebook { | 17 | namespace Datebook { |
18 | class BookManager; | 18 | class BookManager; |
19 | class Show; | 19 | class Show; |
20 | class Editor; | 20 | class Editor; |
21 | class MainWindow : public OPimMainWindow { | 21 | class MainWindow : public OPimMainWindow { |
22 | Q_OBJECT | 22 | Q_OBJECT |
23 | friend class Show; // to avoid QObject | 23 | friend class Show; // to avoid QObject |
24 | friend class View; // to avoid QObject | 24 | friend class View; // to avoid QObject |
25 | friend class Editor; | 25 | friend class Editor; |
26 | public: | 26 | public: |
27 | MainWindow(); | 27 | MainWindow(); |
28 | ~MainWindow(); | 28 | ~MainWindow(); |
29 | 29 | ||
30 | private slots: | 30 | private slots: |
31 | void initUI(); // init the UI | 31 | void initUI(); // init the UI |
32 | void initConfig(); // apply the config | 32 | void initConfig(); // apply the config |
33 | void initView(); // init the Views.. | 33 | void initView(); // init the Views.. |
34 | void initManagers(); // init the Managers including templates, location and description | 34 | void initManagers(); // init the Managers including templates, location and description |
35 | void raiseCurrentView(); // raise the current View | 35 | void raiseCurrentView(); // raise the current View |
36 | void slotGoToNow(); // will switch the currentView to the curren date time | 36 | void slotGoToNow(); // will switch the currentView to the curren date time |
37 | void slotFind(); // find!!! | 37 | void slotFind(); // find!!! |
38 | void slotConfigure(); // configure the app | 38 | void slotConfigure(); // configure the app |
39 | void slotClockChanged(bool); // clock changed | 39 | void slotClockChanged(bool); // clock changed |
40 | void slotWeekChanged( bool ); // week changed | 40 | void slotWeekChanged( bool ); // week changed |
41 | void slotAppMessage( const QCString&, const QByteArray& ); // qApp message QPE/Application/datebook | 41 | void slotAppMessage( const QCString&, const QByteArray& ); // qApp message QPE/Application/datebook |
42 | void slotReceive( const QCString&, const QByteArray& ); // QPE/System and QPE/Datebook | 42 | void slotReceive( const QCString&, const QByteArray& ); // QPE/System and QPE/Datebook |
43 | void slotAction( QAction* ); // View changed | 43 | void slotAction( QAction* ); // View changed |
44 | void slotConfigureLocs(); // Configure the Locations | 44 | void slotConfigureLocs(); // Configure the Locations |
45 | void slotConfigureDesc(); // Configure the Desc | 45 | void slotConfigureDesc(); // Configure the Desc |
46 | void slotConfigureTemp(); | 46 | void slotConfigureTemp(); |
47 | void slotNewFromTemplate(int ); // called when someone chooses the template menu | 47 | void slotNewFromTemplate(int ); // called when someone chooses the template menu |
48 | 48 | ||
49 | void setTemplateMenu(); // updates the templateMenu | 49 | void setTemplateMenu(); // updates the templateMenu |
50 | 50 | ||
51 | protected slots: | 51 | protected slots: |
52 | void populate(); | 52 | void populate(); |
53 | void doSetDocument( const QString& str ); | 53 | void doSetDocument( const QString& str ); |
54 | void flush(); | 54 | void flush(); |
55 | void reload(); | 55 | void reload(); |
56 | int create(); | 56 | int create(); |
57 | bool remove( int uid ); | 57 | bool remove( int uid ); |
58 | void beam( int uid ); | 58 | void beam( int uid ); |
59 | void show( int uid ); | 59 | void show( int uid ); |
60 | void edit( int uid ); | 60 | void edit( int uid ); |
61 | void edit(); | 61 | void edit(); |
62 | void add( const OPimRecord& ); | 62 | void add( const OPimRecord& ); |
63 | 63 | ||
64 | private: | 64 | private: |
65 | QPEToolBar* toolbar(); | 65 | QToolBar* toolbar(); |
66 | QPopupMenu* viewMenu(); | 66 | QPopupMenu* viewMenu(); |
67 | QPopupMenu* settingsMenu(); | 67 | QPopupMenu* settingsMenu(); |
68 | QPopupMenu* templateMenu(); | 68 | QPopupMenu* templateMenu(); |
69 | View* currentView(); | 69 | View* currentView(); |
70 | BookManager* manager(); | 70 | BookManager* manager(); |
71 | TemplateManager templateManager(); | 71 | TemplateManager templateManager(); |
72 | LocationManager locationManager(); | 72 | LocationManager locationManager(); |
73 | DescriptionManager descriptionManager(); | 73 | DescriptionManager descriptionManager(); |
74 | void setLocationManager( const LocationManager& ); | 74 | void setLocationManager( const LocationManager& ); |
75 | void setDescriptionManager( const DescriptionManager& ); | 75 | void setDescriptionManager( const DescriptionManager& ); |
76 | Show* eventShow(); | 76 | Show* eventShow(); |
77 | Editor* editor(); | 77 | Editor* editor(); |
78 | 78 | ||
79 | private: // friend functions for Show | 79 | private: // friend functions for Show |
80 | void hideShow(); // to hide the view | 80 | void hideShow(); // to hide the view |
81 | // off friend Show | 81 | // off friend Show |
82 | 82 | ||
83 | // friend of the view | 83 | // friend of the view |
84 | private: | 84 | private: |
85 | void viewPopup( int ); | 85 | void viewPopup( int ); |
86 | void viewAdd( const QDate& date ); | 86 | void viewAdd( const QDate& date ); |
87 | void viewAdd( const QDateTime&, const QDateTime& ); | 87 | void viewAdd( const QDateTime&, const QDateTime& ); |
88 | bool viewAP()const; | 88 | bool viewAP()const; |
89 | bool viewStartMonday()const; | 89 | bool viewStartMonday()const; |
90 | // off view show | 90 | // off view show |
91 | private: | 91 | private: |
92 | QList<View> m_view; // the Views.. not autoDelete | 92 | QList<View> m_view; // the Views.. not autoDelete |
93 | QWidgetStack* m_stack; | 93 | QWidgetStack* m_stack; |
94 | QPEToolBar *m_toolBar; | 94 | QToolBar *m_toolBar; |
95 | QPopupMenu* m_popView; | 95 | QPopupMenu* m_popView; |
96 | QPopupMenu* m_popSetting; | 96 | QPopupMenu* m_popSetting; |
97 | QPopupMenu* m_popTemplate; | 97 | QPopupMenu* m_popTemplate; |
98 | BookManager* m_manager; | 98 | BookManager* m_manager; |
99 | TemplateManager m_tempMan; | 99 | TemplateManager m_tempMan; |
100 | DescriptionManager m_descMan; | 100 | DescriptionManager m_descMan; |
101 | LocationManager m_locMan; | 101 | LocationManager m_locMan; |
102 | Show* m_show; | 102 | Show* m_show; |
103 | Editor* m_edit; | 103 | Editor* m_edit; |
104 | }; | 104 | }; |
105 | } | 105 | } |
106 | 106 | ||
107 | #endif | 107 | #endif |
diff --git a/core/pim/osearch/mainwindow.cpp b/core/pim/osearch/mainwindow.cpp index 80738df..07403a1 100644 --- a/core/pim/osearch/mainwindow.cpp +++ b/core/pim/osearch/mainwindow.cpp | |||
@@ -1,277 +1,277 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | 10 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> |
11 | 11 | ||
12 | 12 | ||
13 | 13 | ||
14 | #include <qaction.h> | 14 | #include <qaction.h> |
15 | #include <qmessagebox.h> | 15 | #include <qmessagebox.h> |
16 | #include <qpopupmenu.h> | 16 | #include <qpopupmenu.h> |
17 | #include <qtoolbutton.h> | 17 | #include <qtoolbutton.h> |
18 | #include <qstring.h> | 18 | #include <qstring.h> |
19 | #include <qlabel.h> | 19 | #include <qlabel.h> |
20 | #include <qfile.h> | 20 | #include <qfile.h> |
21 | #include <qhbuttongroup.h> | 21 | #include <qhbuttongroup.h> |
22 | #include <qhbox.h> | 22 | #include <qhbox.h> |
23 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
24 | #include <qintdict.h> | 24 | #include <qintdict.h> |
25 | #include <qlayout.h> | 25 | #include <qlayout.h> |
26 | #include <qlineedit.h> | 26 | #include <qlineedit.h> |
27 | #include <qsignalmapper.h> | 27 | #include <qsignalmapper.h> |
28 | #include <qtextbrowser.h> | 28 | #include <qtextbrowser.h> |
29 | #include <qregexp.h> | 29 | #include <qregexp.h> |
30 | #include <qwhatsthis.h> | 30 | #include <qwhatsthis.h> |
31 | #include <qmenubar.h> | 31 | #include <qmenubar.h> |
32 | #include <qpe/qpemessagebox.h> | 32 | #include <qpe/qpemessagebox.h> |
33 | #include <qpe/resource.h> | 33 | #include <qpe/resource.h> |
34 | #include <qpe/config.h> | 34 | #include <qpe/config.h> |
35 | #include <qpe/qpetoolbar.h> | 35 | #include <qtoolbar.h> |
36 | #include <qpe/qpeapplication.h> | 36 | #include <qpe/qpeapplication.h> |
37 | #include <qpe/config.h> | 37 | #include <qpe/config.h> |
38 | #include <qpe/global.h> | 38 | #include <qpe/global.h> |
39 | #include <opie/owait.h> | 39 | #include <opie/owait.h> |
40 | 40 | ||
41 | #include "olistview.h" | 41 | #include "olistview.h" |
42 | #include "olistviewitem.h" | 42 | #include "olistviewitem.h" |
43 | #include "resultitem.h" | 43 | #include "resultitem.h" |
44 | #include "adresssearch.h" | 44 | #include "adresssearch.h" |
45 | #include "todosearch.h" | 45 | #include "todosearch.h" |
46 | #include "datebooksearch.h" | 46 | #include "datebooksearch.h" |
47 | #include "applnksearch.h" | 47 | #include "applnksearch.h" |
48 | #include "doclnksearch.h" | 48 | #include "doclnksearch.h" |
49 | #include "mainwindow.h" | 49 | #include "mainwindow.h" |
50 | 50 | ||
51 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | 51 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : |
52 | QMainWindow( parent, name, f ), _currentItem(0) | 52 | QMainWindow( parent, name, f ), _currentItem(0) |
53 | { | 53 | { |
54 | setCaption( tr("OSearch") ); | 54 | setCaption( tr("OSearch") ); |
55 | 55 | ||
56 | setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); | 56 | setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); |
57 | 57 | ||
58 | QFrame *mainFrame = new QFrame( this, "mainFrame" ); | 58 | QFrame *mainFrame = new QFrame( this, "mainFrame" ); |
59 | mainFrame->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); | 59 | mainFrame->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); |
60 | 60 | ||
61 | mainLayout = new QVBoxLayout( mainFrame ); | 61 | mainLayout = new QVBoxLayout( mainFrame ); |
62 | mainLayout->setSpacing( 0 ); | 62 | mainLayout->setSpacing( 0 ); |
63 | mainLayout->setMargin( 0 ); | 63 | mainLayout->setMargin( 0 ); |
64 | 64 | ||
65 | resultsList = new OListView( mainFrame ); | 65 | resultsList = new OListView( mainFrame ); |
66 | resultsList->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); | 66 | resultsList->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); |
67 | mainLayout->addWidget( resultsList ); | 67 | mainLayout->addWidget( resultsList ); |
68 | 68 | ||
69 | detailsFrame = new QFrame( mainFrame, "detailsFrame" ); | 69 | detailsFrame = new QFrame( mainFrame, "detailsFrame" ); |
70 | QVBoxLayout *detailsLayout = new QVBoxLayout( detailsFrame ); | 70 | QVBoxLayout *detailsLayout = new QVBoxLayout( detailsFrame ); |
71 | richEdit = new QTextView( detailsFrame ); | 71 | richEdit = new QTextView( detailsFrame ); |
72 | QWhatsThis::add( richEdit, tr("The details of the current result") ); | 72 | QWhatsThis::add( richEdit, tr("The details of the current result") ); |
73 | richEdit->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); | 73 | richEdit->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); |
74 | detailsLayout->addWidget( richEdit ); | 74 | detailsLayout->addWidget( richEdit ); |
75 | 75 | ||
76 | buttonBox = new QHBox( mainFrame, "Button Box" ); | 76 | buttonBox = new QHBox( mainFrame, "Button Box" ); |
77 | 77 | ||
78 | _buttonCount = 0; | 78 | _buttonCount = 0; |
79 | 79 | ||
80 | mainLayout->addWidget( detailsFrame ); | 80 | mainLayout->addWidget( detailsFrame ); |
81 | mainLayout->addWidget( buttonBox ); | 81 | mainLayout->addWidget( buttonBox ); |
82 | detailsFrame->hide(); | 82 | detailsFrame->hide(); |
83 | buttonBox->hide(); | 83 | buttonBox->hide(); |
84 | 84 | ||
85 | searches.append( new AppLnkSearch( resultsList, tr("Applications") ) ); | 85 | searches.append( new AppLnkSearch( resultsList, tr("Applications") ) ); |
86 | searches.append( new DocLnkSearch( resultsList, tr("Documents") ) ); | 86 | searches.append( new DocLnkSearch( resultsList, tr("Documents") ) ); |
87 | searches.append( new TodoSearch( resultsList, tr("Todo List") ) ); | 87 | searches.append( new TodoSearch( resultsList, tr("Todo List") ) ); |
88 | searches.append( new DatebookSearch( resultsList, tr("Calendar") ) ); | 88 | searches.append( new DatebookSearch( resultsList, tr("Calendar") ) ); |
89 | searches.append( new AdressSearch( resultsList, tr("Contacts") ) ); | 89 | searches.append( new AdressSearch( resultsList, tr("Contacts") ) ); |
90 | 90 | ||
91 | setCentralWidget( mainFrame ); | 91 | setCentralWidget( mainFrame ); |
92 | 92 | ||
93 | popupTimer = new QTimer(); | 93 | popupTimer = new QTimer(); |
94 | searchTimer = new QTimer(); | 94 | searchTimer = new QTimer(); |
95 | 95 | ||
96 | connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup())); | 96 | connect(popupTimer, SIGNAL(timeout()), SLOT(showPopup())); |
97 | connect(searchTimer, SIGNAL(timeout()), SLOT(searchStringChanged())); | 97 | connect(searchTimer, SIGNAL(timeout()), SLOT(searchStringChanged())); |
98 | connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*))); | 98 | connect(resultsList, SIGNAL(pressed(QListViewItem*)), SLOT(setCurrent(QListViewItem*))); |
99 | connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*))); | 99 | connect(resultsList, SIGNAL(clicked(QListViewItem*)), SLOT(stopTimer(QListViewItem*))); |
100 | 100 | ||
101 | signalMapper = new QSignalMapper( this ); | 101 | signalMapper = new QSignalMapper( this ); |
102 | 102 | ||
103 | connect(signalMapper, SIGNAL(mapped(int)), SLOT( slotAction(int) ) ); | 103 | connect(signalMapper, SIGNAL(mapped(int)), SLOT( slotAction(int) ) ); |
104 | 104 | ||
105 | makeMenu(); | 105 | makeMenu(); |
106 | 106 | ||
107 | Config cfg( "osearch", Config::User ); | 107 | Config cfg( "osearch", Config::User ); |
108 | cfg.setGroup( "search_settings" ); | 108 | cfg.setGroup( "search_settings" ); |
109 | actionCaseSensitiv->setOn( cfg.readBoolEntry( "caseSensitiv", false ) ); | 109 | actionCaseSensitiv->setOn( cfg.readBoolEntry( "caseSensitiv", false ) ); |
110 | actionWildcards->setOn( cfg.readBoolEntry( "wildcards", false ) ); | 110 | actionWildcards->setOn( cfg.readBoolEntry( "wildcards", false ) ); |
111 | // actionWholeWordsOnly->setOn( cfg.readBoolEntry( "whole_words_only", false ) ); | 111 | // actionWholeWordsOnly->setOn( cfg.readBoolEntry( "whole_words_only", false ) ); |
112 | } | 112 | } |
113 | 113 | ||
114 | void MainWindow::makeMenu() | 114 | void MainWindow::makeMenu() |
115 | { | 115 | { |
116 | QPEToolBar *toolBar = new QPEToolBar( this ); | 116 | QToolBar *toolBar = new QToolBar( this ); |
117 | QPEToolBar *searchBar = new QPEToolBar(this); | 117 | QToolBar *searchBar = new QToolBar(this); |
118 | QMenuBar *menuBar = new QMenuBar( toolBar ); | 118 | QMenuBar *menuBar = new QMenuBar( toolBar ); |
119 | QPopupMenu *searchMenu = new QPopupMenu( menuBar ); | 119 | QPopupMenu *searchMenu = new QPopupMenu( menuBar ); |
120 | // QPopupMenu *viewMenu = new QPopupMenu( menuBar ); | 120 | // QPopupMenu *viewMenu = new QPopupMenu( menuBar ); |
121 | QPopupMenu *cfgMenu = new QPopupMenu( menuBar ); | 121 | QPopupMenu *cfgMenu = new QPopupMenu( menuBar ); |
122 | QPopupMenu *searchOptions = new QPopupMenu( cfgMenu ); | 122 | QPopupMenu *searchOptions = new QPopupMenu( cfgMenu ); |
123 | 123 | ||
124 | setToolBarsMovable( false ); | 124 | setToolBarsMovable( false ); |
125 | toolBar->setHorizontalStretchable( true ); | 125 | toolBar->setHorizontalStretchable( true ); |
126 | menuBar->insertItem( tr( "Search" ), searchMenu ); | 126 | menuBar->insertItem( tr( "Search" ), searchMenu ); |
127 | menuBar->insertItem( tr( "Settings" ), cfgMenu ); | 127 | menuBar->insertItem( tr( "Settings" ), cfgMenu ); |
128 | 128 | ||
129 | //SETTINGS MENU | 129 | //SETTINGS MENU |
130 | cfgMenu->insertItem( tr( "Search" ), searchOptions ); | 130 | cfgMenu->insertItem( tr( "Search" ), searchOptions ); |
131 | QPopupMenu *pop; | 131 | QPopupMenu *pop; |
132 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){ | 132 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){ |
133 | pop = s->popupMenu(); | 133 | pop = s->popupMenu(); |
134 | if (pop){ | 134 | if (pop){ |
135 | cfgMenu->insertItem( s->text(0), pop ); | 135 | cfgMenu->insertItem( s->text(0), pop ); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
139 | 139 | ||
140 | //SEARCH | 140 | //SEARCH |
141 | SearchAllAction = new QAction( tr("Search all"),QString::null, 0, this, 0 ); | 141 | SearchAllAction = new QAction( tr("Search all"),QString::null, 0, this, 0 ); |
142 | SearchAllAction->setIconSet( Resource::loadIconSet( "find" ) ); | 142 | SearchAllAction->setIconSet( Resource::loadIconSet( "find" ) ); |
143 | // QWhatsThis::add( SearchAllAction, tr("Search everything...") ); | 143 | // QWhatsThis::add( SearchAllAction, tr("Search everything...") ); |
144 | connect( SearchAllAction, SIGNAL(activated()), this, SLOT(searchAll()) ); | 144 | connect( SearchAllAction, SIGNAL(activated()), this, SLOT(searchAll()) ); |
145 | SearchAllAction->addTo( searchMenu ); | 145 | SearchAllAction->addTo( searchMenu ); |
146 | searchMenu->insertItem( tr( "Options" ), searchOptions ); | 146 | searchMenu->insertItem( tr( "Options" ), searchOptions ); |
147 | 147 | ||
148 | //SEARCH OPTIONS | 148 | //SEARCH OPTIONS |
149 | //actionWholeWordsOnly = new QAction( tr("Whole words only"),QString::null, 0, this, 0, true ); | 149 | //actionWholeWordsOnly = new QAction( tr("Whole words only"),QString::null, 0, this, 0, true ); |
150 | //actionWholeWordsOnly->addTo( searchOptions ); | 150 | //actionWholeWordsOnly->addTo( searchOptions ); |
151 | actionCaseSensitiv = new QAction( tr("Case sensitiv"),QString::null, 0, this, 0, true ); | 151 | actionCaseSensitiv = new QAction( tr("Case sensitiv"),QString::null, 0, this, 0, true ); |
152 | actionCaseSensitiv->addTo( searchOptions ); | 152 | actionCaseSensitiv->addTo( searchOptions ); |
153 | actionWildcards = new QAction( tr("Use wildcards"),QString::null, 0, this, 0, true ); | 153 | actionWildcards = new QAction( tr("Use wildcards"),QString::null, 0, this, 0, true ); |
154 | actionWildcards->addTo( searchOptions ); | 154 | actionWildcards->addTo( searchOptions ); |
155 | 155 | ||
156 | //SEARCH BAR | 156 | //SEARCH BAR |
157 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 157 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
158 | QLineEdit *searchEdit = new QLineEdit( searchBar, "seachEdit" ); | 158 | QLineEdit *searchEdit = new QLineEdit( searchBar, "seachEdit" ); |
159 | QWhatsThis::add( searchEdit, tr("Enter your search terms here") ); | 159 | QWhatsThis::add( searchEdit, tr("Enter your search terms here") ); |
160 | searchEdit->setFocus(); | 160 | searchEdit->setFocus(); |
161 | searchBar->setHorizontalStretchable( TRUE ); | 161 | searchBar->setHorizontalStretchable( TRUE ); |
162 | searchBar->setStretchableWidget( searchEdit ); | 162 | searchBar->setStretchableWidget( searchEdit ); |
163 | SearchAllAction->addTo( searchBar ); | 163 | SearchAllAction->addTo( searchBar ); |
164 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 164 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
165 | this, SLOT( setSearch( const QString & ) ) ); | 165 | this, SLOT( setSearch( const QString & ) ) ); |
166 | 166 | ||
167 | } | 167 | } |
168 | 168 | ||
169 | MainWindow::~MainWindow() | 169 | MainWindow::~MainWindow() |
170 | { | 170 | { |
171 | Config cfg( "osearch", Config::User ); | 171 | Config cfg( "osearch", Config::User ); |
172 | cfg.setGroup( "search_settings" ); | 172 | cfg.setGroup( "search_settings" ); |
173 | cfg.writeEntry( "caseSensitiv", actionCaseSensitiv->isOn() ); | 173 | cfg.writeEntry( "caseSensitiv", actionCaseSensitiv->isOn() ); |
174 | cfg.writeEntry( "wildcards", actionWildcards->isOn() ); | 174 | cfg.writeEntry( "wildcards", actionWildcards->isOn() ); |
175 | //cfg.writeEntry( "whole_words_only", actionWholeWordsOnly->isOn() ); | 175 | //cfg.writeEntry( "whole_words_only", actionWholeWordsOnly->isOn() ); |
176 | } | 176 | } |
177 | 177 | ||
178 | void MainWindow::setCurrent(QListViewItem *item) | 178 | void MainWindow::setCurrent(QListViewItem *item) |
179 | { | 179 | { |
180 | if (!item) return; | 180 | if (!item) return; |
181 | _currentItem = (OListViewItem*)item; | 181 | _currentItem = (OListViewItem*)item; |
182 | //_currentItem = dynamic_cast<OListViewItem*>(item); | 182 | //_currentItem = dynamic_cast<OListViewItem*>(item); |
183 | if (_currentItem->rtti() == OListViewItem::Result){ | 183 | if (_currentItem->rtti() == OListViewItem::Result){ |
184 | ResultItem *res = (ResultItem*)item; | 184 | ResultItem *res = (ResultItem*)item; |
185 | // ResultItem *res = dynamic_cast<ResultItem*>(item); | 185 | // ResultItem *res = dynamic_cast<ResultItem*>(item); |
186 | richEdit->setText( res->toRichText() ); | 186 | richEdit->setText( res->toRichText() ); |
187 | QIntDict<QString> acts = res->actions(); | 187 | QIntDict<QString> acts = res->actions(); |
188 | QButton *button; | 188 | QButton *button; |
189 | for (uint i = 0; i < acts.count(); i++){ | 189 | for (uint i = 0; i < acts.count(); i++){ |
190 | button = buttonMap[i]; | 190 | button = buttonMap[i]; |
191 | if (!button) { | 191 | if (!button) { |
192 | qWarning(" no button for %s", (*acts[i]).latin1() ); | 192 | qWarning(" no button for %s", (*acts[i]).latin1() ); |
193 | button = new QPushButton( buttonBox ); | 193 | button = new QPushButton( buttonBox ); |
194 | buttonMap.insert( i, button ); | 194 | buttonMap.insert( i, button ); |
195 | signalMapper->setMapping(button, i ); | 195 | signalMapper->setMapping(button, i ); |
196 | connect(button, SIGNAL(clicked() ), signalMapper, SLOT(map() ) ); | 196 | connect(button, SIGNAL(clicked() ), signalMapper, SLOT(map() ) ); |
197 | } | 197 | } |
198 | button->setText( *acts[i] ); | 198 | button->setText( *acts[i] ); |
199 | button->show(); | 199 | button->show(); |
200 | } | 200 | } |
201 | for (uint i = acts.count(); i < _buttonCount; i++){ | 201 | for (uint i = acts.count(); i < _buttonCount; i++){ |
202 | button = buttonMap[i]; | 202 | button = buttonMap[i]; |
203 | if (button) button->hide(); | 203 | if (button) button->hide(); |
204 | } | 204 | } |
205 | _buttonCount = acts.count(); | 205 | _buttonCount = acts.count(); |
206 | detailsFrame->show(); | 206 | detailsFrame->show(); |
207 | buttonBox->show(); | 207 | buttonBox->show(); |
208 | 208 | ||
209 | }else { | 209 | }else { |
210 | detailsFrame->hide(); | 210 | detailsFrame->hide(); |
211 | buttonBox->hide(); | 211 | buttonBox->hide(); |
212 | } | 212 | } |
213 | popupTimer->start( 300, true ); | 213 | popupTimer->start( 300, true ); |
214 | } | 214 | } |
215 | 215 | ||
216 | void MainWindow::stopTimer(QListViewItem*) | 216 | void MainWindow::stopTimer(QListViewItem*) |
217 | { | 217 | { |
218 | popupTimer->stop(); | 218 | popupTimer->stop(); |
219 | } | 219 | } |
220 | 220 | ||
221 | void MainWindow::showPopup() | 221 | void MainWindow::showPopup() |
222 | { | 222 | { |
223 | popupTimer->stop(); | 223 | popupTimer->stop(); |
224 | if (!_currentItem) return; | 224 | if (!_currentItem) return; |
225 | QPopupMenu *pop = _currentItem->popupMenu(); | 225 | QPopupMenu *pop = _currentItem->popupMenu(); |
226 | if (pop) pop->popup( QCursor::pos() ); | 226 | if (pop) pop->popup( QCursor::pos() ); |
227 | } | 227 | } |
228 | 228 | ||
229 | void MainWindow::setSearch( const QString &key ) | 229 | void MainWindow::setSearch( const QString &key ) |
230 | { | 230 | { |
231 | searchTimer->stop(); | 231 | searchTimer->stop(); |
232 | _searchString = key; | 232 | _searchString = key; |
233 | searchTimer->start( 300 ); | 233 | searchTimer->start( 300 ); |
234 | } | 234 | } |
235 | 235 | ||
236 | void MainWindow::searchStringChanged() | 236 | void MainWindow::searchStringChanged() |
237 | { | 237 | { |
238 | #ifdef NEW_OWAIT | 238 | #ifdef NEW_OWAIT |
239 | OWait("setting search string"); | 239 | OWait("setting search string"); |
240 | #endif | 240 | #endif |
241 | searchTimer->stop(); | 241 | searchTimer->stop(); |
242 | QString ss = _searchString; | 242 | QString ss = _searchString; |
243 | //ss = Global::stringQuote( _searchString ); | 243 | //ss = Global::stringQuote( _searchString ); |
244 | //if (actionWholeWordsOnly->isOn()) | 244 | //if (actionWholeWordsOnly->isOn()) |
245 | // ss = "\\s"+_searchString+"\\s"; | 245 | // ss = "\\s"+_searchString+"\\s"; |
246 | //qDebug(" set searchString >%s<",ss.latin1()); | 246 | //qDebug(" set searchString >%s<",ss.latin1()); |
247 | QRegExp re( ss ); | 247 | QRegExp re( ss ); |
248 | re.setCaseSensitive( actionCaseSensitiv->isOn() ); | 248 | re.setCaseSensitive( actionCaseSensitiv->isOn() ); |
249 | re.setWildcard( actionWildcards->isOn() ); | 249 | re.setWildcard( actionWildcards->isOn() ); |
250 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ) | 250 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ) |
251 | s->setSearch( re ); | 251 | s->setSearch( re ); |
252 | } | 252 | } |
253 | 253 | ||
254 | void MainWindow::searchAll() | 254 | void MainWindow::searchAll() |
255 | { | 255 | { |
256 | #ifdef NEW_OWAIT | 256 | #ifdef NEW_OWAIT |
257 | OWait("searching..."); | 257 | OWait("searching..."); |
258 | #endif | 258 | #endif |
259 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){ | 259 | for (SearchGroup *s = searches.first(); s != 0; s = searches.next() ){ |
260 | s->doSearch(); | 260 | s->doSearch(); |
261 | //resultsList->repaint(); | 261 | //resultsList->repaint(); |
262 | } | 262 | } |
263 | } | 263 | } |
264 | 264 | ||
265 | void MainWindow::slotAction( int act ) | 265 | void MainWindow::slotAction( int act ) |
266 | { | 266 | { |
267 | if ( _currentItem && _currentItem->rtti() == OListViewItem::Result){ | 267 | if ( _currentItem && _currentItem->rtti() == OListViewItem::Result){ |
268 | ResultItem *res = (ResultItem*)_currentItem; | 268 | ResultItem *res = (ResultItem*)_currentItem; |
269 | // ResultItem *res = dynamic_cast<ResultItem*>(item); | 269 | // ResultItem *res = dynamic_cast<ResultItem*>(item); |
270 | res->action(act); | 270 | res->action(act); |
271 | } | 271 | } |
272 | } | 272 | } |
273 | 273 | ||
274 | void MainWindow::optionChanged(int ) | 274 | void MainWindow::optionChanged(int ) |
275 | { | 275 | { |
276 | searchStringChanged(); | 276 | searchStringChanged(); |
277 | } | 277 | } |
diff --git a/core/pim/osearch/mainwindow.h b/core/pim/osearch/mainwindow.h index 75054f0..bdc6c5f 100644 --- a/core/pim/osearch/mainwindow.h +++ b/core/pim/osearch/mainwindow.h | |||
@@ -1,86 +1,86 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | // (c) 2002-2003 Patrick S. Vogt <tille@handhelds.org> | 10 | // (c) 2002-2003 Patrick S. Vogt <tille@handhelds.org> |
11 | 11 | ||
12 | #ifndef MAINWINDOW_H | 12 | #ifndef MAINWINDOW_H |
13 | #define MAINWINDOW_H | 13 | #define MAINWINDOW_H |
14 | 14 | ||
15 | #include <qmainwindow.h> | 15 | #include <qmainwindow.h> |
16 | #include <qdialog.h> | 16 | #include <qdialog.h> |
17 | #include <qaction.h> | 17 | #include <qaction.h> |
18 | #include <qlist.h> | 18 | #include <qlist.h> |
19 | 19 | ||
20 | #include <qmap.h> | 20 | #include <qmap.h> |
21 | #include <qtimer.h> | 21 | #include <qtimer.h> |
22 | #include <qpopupmenu.h> | 22 | #include <qpopupmenu.h> |
23 | 23 | ||
24 | class QAction; | 24 | class QAction; |
25 | class QPEToolBar; | 25 | class QToolBar; |
26 | class QHBox; | 26 | class QHBox; |
27 | class QVBoxLayout; | 27 | class QVBoxLayout; |
28 | class QTextView; | 28 | class QTextView; |
29 | class QFrame; | 29 | class QFrame; |
30 | class OListView; | 30 | class OListView; |
31 | class OListViewItem; | 31 | class OListViewItem; |
32 | class QListViewItem; | 32 | class QListViewItem; |
33 | class QPopupMenu; | 33 | class QPopupMenu; |
34 | class QTimer; | 34 | class QTimer; |
35 | 35 | ||
36 | class QSignalMapper; | 36 | class QSignalMapper; |
37 | class QButton; | 37 | class QButton; |
38 | 38 | ||
39 | class SearchGroup; | 39 | class SearchGroup; |
40 | 40 | ||
41 | class MainWindow : public QMainWindow | 41 | class MainWindow : public QMainWindow |
42 | { | 42 | { |
43 | Q_OBJECT | 43 | Q_OBJECT |
44 | 44 | ||
45 | 45 | ||
46 | public: | 46 | public: |
47 | MainWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 47 | MainWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
48 | ~MainWindow(); | 48 | ~MainWindow(); |
49 | static QString appName() { return QString::fromLatin1("osearch"); } | 49 | static QString appName() { return QString::fromLatin1("osearch"); } |
50 | 50 | ||
51 | public slots: | 51 | public slots: |
52 | void setCurrent(QListViewItem*); | 52 | void setCurrent(QListViewItem*); |
53 | void setSearch( const QString& ); | 53 | void setSearch( const QString& ); |
54 | void searchAll(); | 54 | void searchAll(); |
55 | 55 | ||
56 | protected slots: | 56 | protected slots: |
57 | void slotAction(int); | 57 | void slotAction(int); |
58 | void showPopup(); | 58 | void showPopup(); |
59 | void stopTimer( QListViewItem* ); | 59 | void stopTimer( QListViewItem* ); |
60 | void searchStringChanged(); | 60 | void searchStringChanged(); |
61 | void optionChanged(int); | 61 | void optionChanged(int); |
62 | 62 | ||
63 | private: | 63 | private: |
64 | QHBox *buttonBox; | 64 | QHBox *buttonBox; |
65 | QMap<int, QButton*> buttonMap; | 65 | QMap<int, QButton*> buttonMap; |
66 | QSignalMapper* signalMapper; | 66 | QSignalMapper* signalMapper; |
67 | OListView *resultsList; | 67 | OListView *resultsList; |
68 | QTextView *richEdit; | 68 | QTextView *richEdit; |
69 | OListViewItem *_currentItem; | 69 | OListViewItem *_currentItem; |
70 | QVBoxLayout *mainLayout; | 70 | QVBoxLayout *mainLayout; |
71 | QFrame *detailsFrame; | 71 | QFrame *detailsFrame; |
72 | QTimer *popupTimer; | 72 | QTimer *popupTimer; |
73 | QTimer *searchTimer; | 73 | QTimer *searchTimer; |
74 | 74 | ||
75 | QString _searchString; | 75 | QString _searchString; |
76 | QList<SearchGroup> searches; | 76 | QList<SearchGroup> searches; |
77 | QAction *SearchAllAction; | 77 | QAction *SearchAllAction; |
78 | QAction *actionCaseSensitiv; | 78 | QAction *actionCaseSensitiv; |
79 | QAction *actionWildcards; | 79 | QAction *actionWildcards; |
80 | //QAction *actionWholeWordsOnly; | 80 | //QAction *actionWholeWordsOnly; |
81 | uint _buttonCount; | 81 | uint _buttonCount; |
82 | void makeMenu(); | 82 | void makeMenu(); |
83 | }; | 83 | }; |
84 | 84 | ||
85 | #endif | 85 | #endif |
86 | 86 | ||
diff --git a/core/pim/todo/mainwindow.cpp b/core/pim/todo/mainwindow.cpp index 7f40645..d06a405 100644 --- a/core/pim/todo/mainwindow.cpp +++ b/core/pim/todo/mainwindow.cpp | |||
@@ -1,1045 +1,1045 @@ | |||
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 <> | 3 | .=l. Copyright (c) 2002 <> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This program is free software; you can | 5 | _;:, .> :=|. This program 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 program is distributed in the hope that | 12 | .i_,=:_. -<s. This program 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 | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 18 | ++= -. .` .: 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 | 21 | -_. . . )=. = General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 22 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 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 <unistd.h> | 29 | #include <unistd.h> |
30 | 30 | ||
31 | #include <qmenubar.h> | 31 | #include <qmenubar.h> |
32 | #include <qmessagebox.h> | 32 | #include <qmessagebox.h> |
33 | #include <qtoolbar.h> | 33 | #include <qtoolbar.h> |
34 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
35 | #include <qpushbutton.h> | 35 | #include <qpushbutton.h> |
36 | #include <qwidgetstack.h> | 36 | #include <qwidgetstack.h> |
37 | #include <qaction.h> | 37 | #include <qaction.h> |
38 | #include <qtimer.h> | 38 | #include <qtimer.h> |
39 | #include <qvbox.h> | 39 | #include <qvbox.h> |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
42 | #include <qwhatsthis.h> | 42 | #include <qwhatsthis.h> |
43 | 43 | ||
44 | #include <qpe/applnk.h> | 44 | #include <qpe/applnk.h> |
45 | #include <qpe/config.h> | 45 | #include <qpe/config.h> |
46 | #include <qpe/ir.h> | 46 | #include <qpe/ir.h> |
47 | #include <qpe/resource.h> | 47 | #include <qpe/resource.h> |
48 | #include <qpe/qpemessagebox.h> | 48 | #include <qpe/qpemessagebox.h> |
49 | #include <qpe/alarmserver.h> | 49 | #include <qpe/alarmserver.h> |
50 | #include <qpe/timestring.h> | 50 | #include <qpe/timestring.h> |
51 | #include <qpe/qpeapplication.h> | 51 | #include <qpe/qpeapplication.h> |
52 | 52 | ||
53 | #include <opie/orecur.h> | 53 | #include <opie/orecur.h> |
54 | #include <opie/opimnotifymanager.h> | 54 | #include <opie/opimnotifymanager.h> |
55 | #include <opie/otodoaccessvcal.h> | 55 | #include <opie/otodoaccessvcal.h> |
56 | #include <opie/owidgetstack.h> | 56 | #include <opie/owidgetstack.h> |
57 | 57 | ||
58 | #include <opie/oapplicationfactory.h> | 58 | #include <opie/oapplicationfactory.h> |
59 | 59 | ||
60 | #include "quickeditimpl.h" | 60 | #include "quickeditimpl.h" |
61 | #include "todotemplatemanager.h" | 61 | #include "todotemplatemanager.h" |
62 | #include "templateeditor.h" | 62 | #include "templateeditor.h" |
63 | #include "tableview.h" | 63 | #include "tableview.h" |
64 | 64 | ||
65 | #include "textviewshow.h" | 65 | #include "textviewshow.h" |
66 | #include "todoeditor.h" | 66 | #include "todoeditor.h" |
67 | #include "mainwindow.h" | 67 | #include "mainwindow.h" |
68 | 68 | ||
69 | OPIE_EXPORT_APP( OApplicationFactory<Todo::MainWindow> ) | 69 | OPIE_EXPORT_APP( OApplicationFactory<Todo::MainWindow> ) |
70 | 70 | ||
71 | using namespace Todo; | 71 | using namespace Todo; |
72 | 72 | ||
73 | MainWindow::MainWindow( QWidget* parent, | 73 | MainWindow::MainWindow( QWidget* parent, |
74 | const char* name, WFlags ) | 74 | const char* name, WFlags ) |
75 | : OPimMainWindow( "Todolist", parent, name, WType_TopLevel | WStyle_ContextHelp ) | 75 | : OPimMainWindow( "Todolist", parent, name, WType_TopLevel | WStyle_ContextHelp ) |
76 | { | 76 | { |
77 | if (!name) | 77 | if (!name) |
78 | setName("todo window"); | 78 | setName("todo window"); |
79 | 79 | ||
80 | m_syncing = false; | 80 | m_syncing = false; |
81 | m_showing = false; | 81 | m_showing = false; |
82 | m_counter = 0; | 82 | m_counter = 0; |
83 | m_tempManager = new TemplateManager(); | 83 | m_tempManager = new TemplateManager(); |
84 | m_tempManager->load(); | 84 | m_tempManager->load(); |
85 | 85 | ||
86 | initUI(); | 86 | initUI(); |
87 | initConfig(); | 87 | initConfig(); |
88 | initViews(); | 88 | initViews(); |
89 | initActions(); | 89 | initActions(); |
90 | initEditor(); | 90 | initEditor(); |
91 | initShow(); | 91 | initShow(); |
92 | initTemplate(); | 92 | initTemplate(); |
93 | 93 | ||
94 | populateTemplates(); | 94 | populateTemplates(); |
95 | raiseCurrentView(); | 95 | raiseCurrentView(); |
96 | QTimer::singleShot(0, this, SLOT(populateCategories() ) ); | 96 | QTimer::singleShot(0, this, SLOT(populateCategories() ) ); |
97 | } | 97 | } |
98 | void MainWindow::initTemplate() { | 98 | void MainWindow::initTemplate() { |
99 | m_curTempEd = new TemplateEditor( this, templateManager() ); | 99 | m_curTempEd = new TemplateEditor( this, templateManager() ); |
100 | } | 100 | } |
101 | void MainWindow::initActions() { | 101 | void MainWindow::initActions() { |
102 | 102 | ||
103 | // Data menu | 103 | // Data menu |
104 | m_edit->insertItem(QWidget::tr("New from template"), m_template, | 104 | m_edit->insertItem(QWidget::tr("New from template"), m_template, |
105 | -1, 0 ); | 105 | -1, 0 ); |
106 | 106 | ||
107 | QAction* a = new QAction( QWidget::tr("New Task" ), Resource::loadPixmap( "new" ), | 107 | QAction* a = new QAction( QWidget::tr("New Task" ), Resource::loadPixmap( "new" ), |
108 | QString::null, 0, this, 0 ); | 108 | QString::null, 0, this, 0 ); |
109 | connect(a, SIGNAL( activated() ), | 109 | connect(a, SIGNAL( activated() ), |
110 | this, SLOT( slotNew() ) ); | 110 | this, SLOT( slotNew() ) ); |
111 | a->setWhatsThis( QWidget::tr( "Click here to create a new task." ) ); | 111 | a->setWhatsThis( QWidget::tr( "Click here to create a new task." ) ); |
112 | a->addTo(m_tool ); | 112 | a->addTo(m_tool ); |
113 | a->addTo(m_edit ); | 113 | a->addTo(m_edit ); |
114 | 114 | ||
115 | a = new QAction( QWidget::tr("Edit Task"), Resource::loadIconSet( "edit" ), | 115 | a = new QAction( QWidget::tr("Edit Task"), Resource::loadIconSet( "edit" ), |
116 | QString::null, 0, this, 0 ); | 116 | QString::null, 0, this, 0 ); |
117 | connect(a, SIGNAL(activated() ), | 117 | connect(a, SIGNAL(activated() ), |
118 | this, SLOT( slotEdit() ) ); | 118 | this, SLOT( slotEdit() ) ); |
119 | a->setWhatsThis( QWidget::tr( "Click here to modify the current task." ) ); | 119 | a->setWhatsThis( QWidget::tr( "Click here to modify the current task." ) ); |
120 | a->addTo( m_tool ); | 120 | a->addTo( m_tool ); |
121 | a->addTo( m_edit ); | 121 | a->addTo( m_edit ); |
122 | m_editAction = a; | 122 | m_editAction = a; |
123 | 123 | ||
124 | a = new QAction( QString::null, QWidget::tr("View Task"), 0, this, 0 ); | 124 | a = new QAction( QString::null, QWidget::tr("View Task"), 0, this, 0 ); |
125 | connect(a, SIGNAL( activated() ), | 125 | connect(a, SIGNAL( activated() ), |
126 | this, SLOT( slotShowDetails() ) ); | 126 | this, SLOT( slotShowDetails() ) ); |
127 | a->addTo( m_edit ); | 127 | a->addTo( m_edit ); |
128 | 128 | ||
129 | m_edit->insertSeparator(); | 129 | m_edit->insertSeparator(); |
130 | 130 | ||
131 | a = new QAction( QWidget::tr("Delete..."), Resource::loadIconSet( "trash" ), | 131 | a = new QAction( QWidget::tr("Delete..."), Resource::loadIconSet( "trash" ), |
132 | QString::null, 0, this, 0 ); | 132 | QString::null, 0, this, 0 ); |
133 | connect(a, SIGNAL(activated() ), | 133 | connect(a, SIGNAL(activated() ), |
134 | this, SLOT(slotDelete() ) ); | 134 | this, SLOT(slotDelete() ) ); |
135 | a->setWhatsThis( QWidget::tr( "Click here to remove the current task." ) ); | 135 | a->setWhatsThis( QWidget::tr( "Click here to remove the current task." ) ); |
136 | a->addTo( m_tool ); | 136 | a->addTo( m_tool ); |
137 | a->addTo( m_edit ); | 137 | a->addTo( m_edit ); |
138 | m_deleteAction = a; | 138 | m_deleteAction = a; |
139 | 139 | ||
140 | a = new QAction( QString::null, QWidget::tr("Delete all..."), 0, this, 0 ); | 140 | a = new QAction( QString::null, QWidget::tr("Delete all..."), 0, this, 0 ); |
141 | connect(a, SIGNAL( activated() ), | 141 | connect(a, SIGNAL( activated() ), |
142 | this, SLOT( slotDeleteAll() ) ); | 142 | this, SLOT( slotDeleteAll() ) ); |
143 | a->addTo(m_edit ); | 143 | a->addTo(m_edit ); |
144 | m_deleteAllAction = a; | 144 | m_deleteAllAction = a; |
145 | 145 | ||
146 | a = new QAction( QString::null, QWidget::tr("Delete completed"), | 146 | a = new QAction( QString::null, QWidget::tr("Delete completed"), |
147 | 0, this, 0 ); | 147 | 0, this, 0 ); |
148 | connect(a, SIGNAL( activated() ), | 148 | connect(a, SIGNAL( activated() ), |
149 | this, SLOT( slotDeleteCompleted() ) ); | 149 | this, SLOT( slotDeleteCompleted() ) ); |
150 | a->addTo(m_edit ); | 150 | a->addTo(m_edit ); |
151 | a->setEnabled( TRUE ); | 151 | a->setEnabled( TRUE ); |
152 | m_deleteCompleteAction = a; | 152 | m_deleteCompleteAction = a; |
153 | 153 | ||
154 | m_edit->insertSeparator(); | 154 | m_edit->insertSeparator(); |
155 | 155 | ||
156 | a = new QAction( QString::null, QWidget::tr("Duplicate"), 0, this, 0 ); | 156 | a = new QAction( QString::null, QWidget::tr("Duplicate"), 0, this, 0 ); |
157 | connect(a, SIGNAL( activated() ), | 157 | connect(a, SIGNAL( activated() ), |
158 | this, SLOT( slotDuplicate() ) ); | 158 | this, SLOT( slotDuplicate() ) ); |
159 | a->addTo(m_edit ); | 159 | a->addTo(m_edit ); |
160 | m_duplicateAction = a; | 160 | m_duplicateAction = a; |
161 | 161 | ||
162 | m_edit->insertSeparator(); | 162 | m_edit->insertSeparator(); |
163 | 163 | ||
164 | if ( Ir::supported() ) { | 164 | if ( Ir::supported() ) { |
165 | a = new QAction( QWidget::tr( "Beam" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 ); | 165 | a = new QAction( QWidget::tr( "Beam" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 ); |
166 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); | 166 | connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); |
167 | a->setWhatsThis( QWidget::tr( "Click here to send the current task to another device." ) ); | 167 | a->setWhatsThis( QWidget::tr( "Click here to send the current task to another device." ) ); |
168 | a->addTo( m_edit ); | 168 | a->addTo( m_edit ); |
169 | a->addTo( m_tool ); | 169 | a->addTo( m_tool ); |
170 | } | 170 | } |
171 | 171 | ||
172 | #if 0 | 172 | #if 0 |
173 | // Options menu | 173 | // Options menu |
174 | a = new QAction( QWidget::tr("Find"), Resource::loadIconSet( "mag" ), | 174 | a = new QAction( QWidget::tr("Find"), Resource::loadIconSet( "mag" ), |
175 | QString::null, 0, this, 0 ); | 175 | QString::null, 0, this, 0 ); |
176 | connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); | 176 | connect(a, SIGNAL( activated() ), this, SLOT( slotFind() ) ); |
177 | a->addTo( m_options ); | 177 | a->addTo( m_options ); |
178 | m_findAction = a; | 178 | m_findAction = a; |
179 | 179 | ||
180 | 180 | ||
181 | m_options->insertSeparator(); | 181 | m_options->insertSeparator(); |
182 | #endif | 182 | #endif |
183 | 183 | ||
184 | m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"), | 184 | m_completedAction = new QAction( QString::null, QWidget::tr("Show completed tasks"), |
185 | 0, this, 0, TRUE ); | 185 | 0, this, 0, TRUE ); |
186 | m_completedAction->addTo( m_options ); | 186 | m_completedAction->addTo( m_options ); |
187 | m_completedAction->setOn( showCompleted() ); | 187 | m_completedAction->setOn( showCompleted() ); |
188 | connect(m_completedAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowCompleted(bool) ) ); | 188 | connect(m_completedAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowCompleted(bool) ) ); |
189 | 189 | ||
190 | a = new QAction( QString::null, QWidget::tr("Show only over-due tasks"), | 190 | a = new QAction( QString::null, QWidget::tr("Show only over-due tasks"), |
191 | 0, this, 0, TRUE ); | 191 | 0, this, 0, TRUE ); |
192 | a->addTo( m_options ); | 192 | a->addTo( m_options ); |
193 | a->setOn( showOverDue() ); | 193 | a->setOn( showOverDue() ); |
194 | connect(a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool) ) ); | 194 | connect(a, SIGNAL(toggled(bool)), this, SLOT(slotShowDue(bool) ) ); |
195 | 195 | ||
196 | m_showDeadLineAction = new QAction( QString::null, QWidget::tr("Show task deadlines"), | 196 | m_showDeadLineAction = new QAction( QString::null, QWidget::tr("Show task deadlines"), |
197 | 0, this, 0, TRUE ); | 197 | 0, this, 0, TRUE ); |
198 | m_showDeadLineAction->addTo( m_options ); | 198 | m_showDeadLineAction->addTo( m_options ); |
199 | m_showDeadLineAction->setOn( showDeadline() ); | 199 | m_showDeadLineAction->setOn( showDeadline() ); |
200 | connect(m_showDeadLineAction, SIGNAL(toggled(bool) ), this, SLOT( slotShowDeadLine( bool ) ) ); | 200 | connect(m_showDeadLineAction, SIGNAL(toggled(bool) ), this, SLOT( slotShowDeadLine( bool ) ) ); |
201 | 201 | ||
202 | m_showQuickTaskAction = new QAction( QString::null, QWidget::tr("Show quick task bar"), | 202 | m_showQuickTaskAction = new QAction( QString::null, QWidget::tr("Show quick task bar"), |
203 | 0, this, 0, TRUE ); | 203 | 0, this, 0, TRUE ); |
204 | m_showQuickTaskAction->addTo( m_options ); | 204 | m_showQuickTaskAction->addTo( m_options ); |
205 | m_showQuickTaskAction->setOn( showQuickTask() ); | 205 | m_showQuickTaskAction->setOn( showQuickTask() ); |
206 | connect(m_showQuickTaskAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowQuickTask(bool) ) ); | 206 | connect(m_showQuickTaskAction, SIGNAL( toggled(bool) ), this, SLOT(slotShowQuickTask(bool) ) ); |
207 | 207 | ||
208 | m_options->insertSeparator(); | 208 | m_options->insertSeparator(); |
209 | 209 | ||
210 | m_bar->insertItem( QWidget::tr("Data") ,m_edit ); | 210 | m_bar->insertItem( QWidget::tr("Data") ,m_edit ); |
211 | m_bar->insertItem( QWidget::tr("Category"), m_catMenu ); | 211 | m_bar->insertItem( QWidget::tr("Category"), m_catMenu ); |
212 | m_bar->insertItem( QWidget::tr("Options"), m_options ); | 212 | m_bar->insertItem( QWidget::tr("Options"), m_options ); |
213 | 213 | ||
214 | m_curQuick = new QuickEditImpl( this, m_quicktask ); | 214 | m_curQuick = new QuickEditImpl( this, m_quicktask ); |
215 | addToolBar( (QPEToolBar *)m_curQuick->widget(), QWidget::tr( "QuickEdit" ), QMainWindow::Top, TRUE ); | 215 | addToolBar( (QToolBar *)m_curQuick->widget(), QWidget::tr( "QuickEdit" ), QMainWindow::Top, TRUE ); |
216 | m_curQuick->signal()->connect( this, SLOT(slotQuickEntered() ) ); | 216 | m_curQuick->signal()->connect( this, SLOT(slotQuickEntered() ) ); |
217 | 217 | ||
218 | } | 218 | } |
219 | /* m_curCat from Config */ | 219 | /* m_curCat from Config */ |
220 | void MainWindow::initConfig() { | 220 | void MainWindow::initConfig() { |
221 | Config config( "todo" ); | 221 | Config config( "todo" ); |
222 | config.setGroup( "View" ); | 222 | config.setGroup( "View" ); |
223 | m_completed = config.readBoolEntry( "ShowComplete", TRUE ); | 223 | m_completed = config.readBoolEntry( "ShowComplete", TRUE ); |
224 | m_curCat = config.readEntry( "Category", QString::null ); | 224 | m_curCat = config.readEntry( "Category", QString::null ); |
225 | m_deadline = config.readBoolEntry( "ShowDeadLine", TRUE); | 225 | m_deadline = config.readBoolEntry( "ShowDeadLine", TRUE); |
226 | m_overdue = config.readBoolEntry("ShowOverDue", FALSE ); | 226 | m_overdue = config.readBoolEntry("ShowOverDue", FALSE ); |
227 | m_quicktask = config.readBoolEntry("ShowQuickTask", TRUE); | 227 | m_quicktask = config.readBoolEntry("ShowQuickTask", TRUE); |
228 | } | 228 | } |
229 | void MainWindow::initUI() { | 229 | void MainWindow::initUI() { |
230 | 230 | ||
231 | m_stack = new OWidgetStack(this, "main stack"); | 231 | m_stack = new OWidgetStack(this, "main stack"); |
232 | 232 | ||
233 | setCentralWidget( m_stack ); | 233 | setCentralWidget( m_stack ); |
234 | 234 | ||
235 | setToolBarsMovable( FALSE ); | 235 | setToolBarsMovable( FALSE ); |
236 | 236 | ||
237 | QToolBar *menubarholder = new QToolBar( this ); | 237 | QToolBar *menubarholder = new QToolBar( this ); |
238 | menubarholder->setHorizontalStretchable( TRUE ); | 238 | menubarholder->setHorizontalStretchable( TRUE ); |
239 | m_bar = new QMenuBar( menubarholder ); | 239 | m_bar = new QMenuBar( menubarholder ); |
240 | 240 | ||
241 | m_tool = new QToolBar( this ); | 241 | m_tool = new QToolBar( this ); |
242 | 242 | ||
243 | /** QPopupMenu */ | 243 | /** QPopupMenu */ |
244 | m_edit = new QPopupMenu( this ); | 244 | m_edit = new QPopupMenu( this ); |
245 | m_options = new QPopupMenu( this ); | 245 | m_options = new QPopupMenu( this ); |
246 | m_catMenu = new QPopupMenu( this ); | 246 | m_catMenu = new QPopupMenu( this ); |
247 | m_template = new QPopupMenu( this ); | 247 | m_template = new QPopupMenu( this ); |
248 | 248 | ||
249 | m_catMenu->setCheckable( TRUE ); | 249 | m_catMenu->setCheckable( TRUE ); |
250 | m_template->setCheckable( TRUE ); | 250 | m_template->setCheckable( TRUE ); |
251 | 251 | ||
252 | connect(m_catMenu, SIGNAL(activated(int) ), | 252 | connect(m_catMenu, SIGNAL(activated(int) ), |
253 | this, SLOT(setCategory(int) ) ); | 253 | this, SLOT(setCategory(int) ) ); |
254 | connect(m_template, SIGNAL(activated(int) ), | 254 | connect(m_template, SIGNAL(activated(int) ), |
255 | this, SLOT(slotNewFromTemplate(int) ) ); | 255 | this, SLOT(slotNewFromTemplate(int) ) ); |
256 | } | 256 | } |
257 | void MainWindow::initViews() { | 257 | void MainWindow::initViews() { |
258 | 258 | ||
259 | TableView* tableView = new TableView( this, m_stack ); | 259 | TableView* tableView = new TableView( this, m_stack ); |
260 | QWhatsThis::add( tableView, QWidget::tr( "This is a listing of all current tasks.\n\nThe list displays the following information:\n1. Completed - A green checkmark indicates task is completed. Click here to complete a task.\n2. Priority - a graphical representation of task priority. Double-click here to modify.\n3. Description - description of task. Click here to select the task.\n4. Deadline - shows when task is due. This column can be shown or hidden by selecting Options->'Show task deadlines' from the menu above." ) ); | 260 | QWhatsThis::add( tableView, QWidget::tr( "This is a listing of all current tasks.\n\nThe list displays the following information:\n1. Completed - A green checkmark indicates task is completed. Click here to complete a task.\n2. Priority - a graphical representation of task priority. Double-click here to modify.\n3. Description - description of task. Click here to select the task.\n4. Deadline - shows when task is due. This column can be shown or hidden by selecting Options->'Show task deadlines' from the menu above." ) ); |
261 | m_stack->addWidget( tableView, m_counter++ ); | 261 | m_stack->addWidget( tableView, m_counter++ ); |
262 | m_views.append( tableView ); | 262 | m_views.append( tableView ); |
263 | m_curView = tableView; | 263 | m_curView = tableView; |
264 | connectBase( tableView ); | 264 | connectBase( tableView ); |
265 | /* add QString type + QString configname to | 265 | /* add QString type + QString configname to |
266 | * the View menu | 266 | * the View menu |
267 | * and subdirs for multiple views | 267 | * and subdirs for multiple views |
268 | */ | 268 | */ |
269 | } | 269 | } |
270 | void MainWindow::initEditor() { | 270 | void MainWindow::initEditor() { |
271 | m_curEdit = new Editor(); | 271 | m_curEdit = new Editor(); |
272 | } | 272 | } |
273 | void MainWindow::initShow() { | 273 | void MainWindow::initShow() { |
274 | m_curShow = new TextViewShow(this, this); | 274 | m_curShow = new TextViewShow(this, this); |
275 | m_stack->addWidget( m_curShow->widget() , m_counter++ ); | 275 | m_stack->addWidget( m_curShow->widget() , m_counter++ ); |
276 | } | 276 | } |
277 | MainWindow::~MainWindow() { | 277 | MainWindow::~MainWindow() { |
278 | delete templateManager(); | 278 | delete templateManager(); |
279 | } | 279 | } |
280 | void MainWindow::connectBase( ViewBase* ) { | 280 | void MainWindow::connectBase( ViewBase* ) { |
281 | // once templates and signals mix we'll use it again | 281 | // once templates and signals mix we'll use it again |
282 | } | 282 | } |
283 | QPopupMenu* MainWindow::contextMenu( int , bool recur ) { | 283 | QPopupMenu* MainWindow::contextMenu( int , bool recur ) { |
284 | QPopupMenu* menu = new QPopupMenu(); | 284 | QPopupMenu* menu = new QPopupMenu(); |
285 | 285 | ||
286 | m_editAction->addTo( menu ); | 286 | m_editAction->addTo( menu ); |
287 | m_deleteAction->addTo( menu ); | 287 | m_deleteAction->addTo( menu ); |
288 | m_duplicateAction->addTo( menu ); | 288 | m_duplicateAction->addTo( menu ); |
289 | 289 | ||
290 | menu->insertSeparator(); | 290 | menu->insertSeparator(); |
291 | 291 | ||
292 | /* | 292 | /* |
293 | * if this event recurs we allow | 293 | * if this event recurs we allow |
294 | * to detach it. | 294 | * to detach it. |
295 | * remove all | 295 | * remove all |
296 | */ | 296 | */ |
297 | if ( recur ) { | 297 | if ( recur ) { |
298 | ; // FIXME | 298 | ; // FIXME |
299 | } | 299 | } |
300 | 300 | ||
301 | return menu; | 301 | return menu; |
302 | } | 302 | } |
303 | QPopupMenu* MainWindow::options() { | 303 | QPopupMenu* MainWindow::options() { |
304 | qWarning("Options"); | 304 | qWarning("Options"); |
305 | return m_options; | 305 | return m_options; |
306 | } | 306 | } |
307 | QPopupMenu* MainWindow::edit() { | 307 | QPopupMenu* MainWindow::edit() { |
308 | return m_edit; | 308 | return m_edit; |
309 | } | 309 | } |
310 | QToolBar* MainWindow::toolbar() { | 310 | QToolBar* MainWindow::toolbar() { |
311 | return m_tool; | 311 | return m_tool; |
312 | } | 312 | } |
313 | OTodoAccess::List MainWindow::list()const { | 313 | OTodoAccess::List MainWindow::list()const { |
314 | return m_todoMgr.list(); | 314 | return m_todoMgr.list(); |
315 | } | 315 | } |
316 | OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { | 316 | OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder ) { |
317 | int cat = 0; | 317 | int cat = 0; |
318 | if ( m_curCat != QWidget::tr("All Categories") ) | 318 | if ( m_curCat != QWidget::tr("All Categories") ) |
319 | cat = currentCatId(); | 319 | cat = currentCatId(); |
320 | if ( m_curCat == QWidget::tr("Unfiled") ) | 320 | if ( m_curCat == QWidget::tr("Unfiled") ) |
321 | cat = -1; | 321 | cat = -1; |
322 | 322 | ||
323 | qWarning(" Category %d %s", cat, m_curCat.latin1() ); | 323 | qWarning(" Category %d %s", cat, m_curCat.latin1() ); |
324 | 324 | ||
325 | int filter = 1; | 325 | int filter = 1; |
326 | 326 | ||
327 | if (!m_completed ) | 327 | if (!m_completed ) |
328 | filter |= 4; | 328 | filter |= 4; |
329 | if (m_overdue) | 329 | if (m_overdue) |
330 | filter |= 2; | 330 | filter |= 2; |
331 | 331 | ||
332 | return m_todoMgr.sorted( asc, sortOrder, filter, cat ); | 332 | return m_todoMgr.sorted( asc, sortOrder, filter, cat ); |
333 | } | 333 | } |
334 | OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { | 334 | OTodoAccess::List MainWindow::sorted( bool asc, int sortOrder, int addFilter) { |
335 | int cat = 0; | 335 | int cat = 0; |
336 | if ( m_curCat != QWidget::tr("All Categories") ) | 336 | if ( m_curCat != QWidget::tr("All Categories") ) |
337 | cat = currentCatId(); | 337 | cat = currentCatId(); |
338 | 338 | ||
339 | if ( m_curCat == QWidget::tr("Unfiled") ) | 339 | if ( m_curCat == QWidget::tr("Unfiled") ) |
340 | cat = -1; | 340 | cat = -1; |
341 | 341 | ||
342 | return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); | 342 | return m_todoMgr.sorted(asc, sortOrder, addFilter, cat ); |
343 | } | 343 | } |
344 | OTodo MainWindow::event( int uid ) { | 344 | OTodo MainWindow::event( int uid ) { |
345 | return m_todoMgr.event( uid ); | 345 | return m_todoMgr.event( uid ); |
346 | } | 346 | } |
347 | bool MainWindow::isSyncing()const { | 347 | bool MainWindow::isSyncing()const { |
348 | return m_syncing; | 348 | return m_syncing; |
349 | } | 349 | } |
350 | TemplateManager* MainWindow::templateManager() { | 350 | TemplateManager* MainWindow::templateManager() { |
351 | return m_tempManager; | 351 | return m_tempManager; |
352 | } | 352 | } |
353 | Editor* MainWindow::currentEditor() { | 353 | Editor* MainWindow::currentEditor() { |
354 | return m_curEdit; | 354 | return m_curEdit; |
355 | } | 355 | } |
356 | TodoShow* MainWindow::currentShow() { | 356 | TodoShow* MainWindow::currentShow() { |
357 | return m_curShow; | 357 | return m_curShow; |
358 | } | 358 | } |
359 | void MainWindow::slotReload() { | 359 | void MainWindow::slotReload() { |
360 | m_syncing = FALSE; | 360 | m_syncing = FALSE; |
361 | m_todoMgr.reload(); | 361 | m_todoMgr.reload(); |
362 | currentView()->updateView( ); | 362 | currentView()->updateView( ); |
363 | raiseCurrentView(); | 363 | raiseCurrentView(); |
364 | } | 364 | } |
365 | void MainWindow::closeEvent( QCloseEvent* e ) { | 365 | void MainWindow::closeEvent( QCloseEvent* e ) { |
366 | if (m_stack->visibleWidget() == currentShow()->widget() ) { | 366 | if (m_stack->visibleWidget() == currentShow()->widget() ) { |
367 | m_showing = false; | 367 | m_showing = false; |
368 | raiseCurrentView(); | 368 | raiseCurrentView(); |
369 | e->ignore(); | 369 | e->ignore(); |
370 | return; | 370 | return; |
371 | } | 371 | } |
372 | /* | 372 | /* |
373 | * we should have flushed and now we're still saving | 373 | * we should have flushed and now we're still saving |
374 | * so there is no need to flush | 374 | * so there is no need to flush |
375 | */ | 375 | */ |
376 | if (m_syncing ) { | 376 | if (m_syncing ) { |
377 | e->accept(); | 377 | e->accept(); |
378 | return; | 378 | return; |
379 | } | 379 | } |
380 | bool quit = false; | 380 | bool quit = false; |
381 | if ( m_todoMgr.saveAll() ){ | 381 | if ( m_todoMgr.saveAll() ){ |
382 | qWarning("saved"); | 382 | qWarning("saved"); |
383 | quit = true; | 383 | quit = true; |
384 | }else { | 384 | }else { |
385 | if ( QMessageBox::critical( this, QWidget::tr("Out of space"), | 385 | if ( QMessageBox::critical( this, QWidget::tr("Out of space"), |
386 | QWidget::tr("Todo was unable\n" | 386 | QWidget::tr("Todo was unable\n" |
387 | "to save your changes.\n" | 387 | "to save your changes.\n" |
388 | "Free up some space\n" | 388 | "Free up some space\n" |
389 | "and try again.\n" | 389 | "and try again.\n" |
390 | "\nQuit Anyway?"), | 390 | "\nQuit Anyway?"), |
391 | QMessageBox::Yes|QMessageBox::Escape, | 391 | QMessageBox::Yes|QMessageBox::Escape, |
392 | QMessageBox::No|QMessageBox::Default) | 392 | QMessageBox::No|QMessageBox::Default) |
393 | != QMessageBox::No ) { | 393 | != QMessageBox::No ) { |
394 | e->accept(); | 394 | e->accept(); |
395 | quit = true; | 395 | quit = true; |
396 | }else | 396 | }else |
397 | e->ignore(); | 397 | e->ignore(); |
398 | 398 | ||
399 | } | 399 | } |
400 | 400 | ||
401 | if (quit ) { | 401 | if (quit ) { |
402 | Config config( "todo" ); | 402 | Config config( "todo" ); |
403 | config.setGroup( "View" ); | 403 | config.setGroup( "View" ); |
404 | config.writeEntry( "ShowComplete", showCompleted() ); | 404 | config.writeEntry( "ShowComplete", showCompleted() ); |
405 | config.writeEntry( "Category", currentCategory() ); | 405 | config.writeEntry( "Category", currentCategory() ); |
406 | config.writeEntry( "ShowDeadLine", showDeadline()); | 406 | config.writeEntry( "ShowDeadLine", showDeadline()); |
407 | config.writeEntry( "ShowOverDue", showOverDue() ); | 407 | config.writeEntry( "ShowOverDue", showOverDue() ); |
408 | config.writeEntry( "ShowQuickTask", showQuickTask() ); | 408 | config.writeEntry( "ShowQuickTask", showQuickTask() ); |
409 | /* save templates */ | 409 | /* save templates */ |
410 | templateManager()->save(); | 410 | templateManager()->save(); |
411 | e->accept(); | 411 | e->accept(); |
412 | QTimer::singleShot(0, qApp, SLOT(closeAllWindows()) ); | 412 | QTimer::singleShot(0, qApp, SLOT(closeAllWindows()) ); |
413 | } | 413 | } |
414 | } | 414 | } |
415 | void MainWindow::populateTemplates() { | 415 | void MainWindow::populateTemplates() { |
416 | m_template->clear(); | 416 | m_template->clear(); |
417 | QStringList list = templateManager()->templates(); | 417 | QStringList list = templateManager()->templates(); |
418 | QStringList::Iterator it; | 418 | QStringList::Iterator it; |
419 | for ( it = list.begin(); it != list.end(); ++it ) { | 419 | for ( it = list.begin(); it != list.end(); ++it ) { |
420 | m_template->insertItem( (*it) ); | 420 | m_template->insertItem( (*it) ); |
421 | } | 421 | } |
422 | } | 422 | } |
423 | /* | 423 | /* |
424 | * slotNewFromTemplate | 424 | * slotNewFromTemplate |
425 | * We use the edit widget to do | 425 | * We use the edit widget to do |
426 | * the config but we setUid(1) | 426 | * the config but we setUid(1) |
427 | * to get a new uid | 427 | * to get a new uid |
428 | */ | 428 | */ |
429 | /* | 429 | /* |
430 | * first we get the name of the template | 430 | * first we get the name of the template |
431 | * then we will use the TemplateManager | 431 | * then we will use the TemplateManager |
432 | */ | 432 | */ |
433 | void MainWindow::slotNewFromTemplate( int id ) { | 433 | void MainWindow::slotNewFromTemplate( int id ) { |
434 | QString name = m_template->text( id ); | 434 | QString name = m_template->text( id ); |
435 | 435 | ||
436 | OTodo event = templateManager()->templateEvent( name ); | 436 | OTodo event = templateManager()->templateEvent( name ); |
437 | event = currentEditor()->edit(this, | 437 | event = currentEditor()->edit(this, |
438 | event ); | 438 | event ); |
439 | 439 | ||
440 | if ( currentEditor()->accepted() ) { | 440 | if ( currentEditor()->accepted() ) { |
441 | /* assign new todo */ | 441 | /* assign new todo */ |
442 | event.setUid( 1 ); | 442 | event.setUid( 1 ); |
443 | handleAlarms( OTodo(), event ); | 443 | handleAlarms( OTodo(), event ); |
444 | m_todoMgr.add( event ); | 444 | m_todoMgr.add( event ); |
445 | currentView()->addEvent( event ); | 445 | currentView()->addEvent( event ); |
446 | 446 | ||
447 | populateCategories(); | 447 | populateCategories(); |
448 | } | 448 | } |
449 | raiseCurrentView(); | 449 | raiseCurrentView(); |
450 | } | 450 | } |
451 | void MainWindow::slotNew() { | 451 | void MainWindow::slotNew() { |
452 | create(); | 452 | create(); |
453 | } | 453 | } |
454 | void MainWindow::slotDuplicate() { | 454 | void MainWindow::slotDuplicate() { |
455 | if(m_syncing) { | 455 | if(m_syncing) { |
456 | QMessageBox::warning(this, QWidget::tr("Todo"), | 456 | QMessageBox::warning(this, QWidget::tr("Todo"), |
457 | QWidget::tr("Data can not be edited, currently syncing")); | 457 | QWidget::tr("Data can not be edited, currently syncing")); |
458 | return; | 458 | return; |
459 | } | 459 | } |
460 | OTodo ev = m_todoMgr.event( currentView()->current() ); | 460 | OTodo ev = m_todoMgr.event( currentView()->current() ); |
461 | /* let's generate a new uid */ | 461 | /* let's generate a new uid */ |
462 | ev.setUid(1); | 462 | ev.setUid(1); |
463 | m_todoMgr.add( ev ); | 463 | m_todoMgr.add( ev ); |
464 | 464 | ||
465 | currentView()->addEvent( ev ); | 465 | currentView()->addEvent( ev ); |
466 | raiseCurrentView(); | 466 | raiseCurrentView(); |
467 | } | 467 | } |
468 | void MainWindow::slotDelete() { | 468 | void MainWindow::slotDelete() { |
469 | if (!currentView()->current() ) | 469 | if (!currentView()->current() ) |
470 | return; | 470 | return; |
471 | 471 | ||
472 | if(m_syncing) { | 472 | if(m_syncing) { |
473 | QMessageBox::warning(this, QWidget::tr("Todo"), | 473 | QMessageBox::warning(this, QWidget::tr("Todo"), |
474 | QWidget::tr("Data can not be edited, currently syncing")); | 474 | QWidget::tr("Data can not be edited, currently syncing")); |
475 | return; | 475 | return; |
476 | } | 476 | } |
477 | QString strName = currentView()->currentRepresentation(); | 477 | QString strName = currentView()->currentRepresentation(); |
478 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) | 478 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), strName ) ) |
479 | return; | 479 | return; |
480 | 480 | ||
481 | handleAlarms( m_todoMgr.event( currentView()->current() ), OTodo() ); | 481 | handleAlarms( m_todoMgr.event( currentView()->current() ), OTodo() ); |
482 | m_todoMgr.remove( currentView()->current() ); | 482 | m_todoMgr.remove( currentView()->current() ); |
483 | currentView()->removeEvent( currentView()->current() ); | 483 | currentView()->removeEvent( currentView()->current() ); |
484 | raiseCurrentView(); | 484 | raiseCurrentView(); |
485 | } | 485 | } |
486 | void MainWindow::slotDelete(int uid ) { | 486 | void MainWindow::slotDelete(int uid ) { |
487 | if( uid == 0 ) return; | 487 | if( uid == 0 ) return; |
488 | if(m_syncing) { | 488 | if(m_syncing) { |
489 | QMessageBox::warning(this, QWidget::tr("Todo"), | 489 | QMessageBox::warning(this, QWidget::tr("Todo"), |
490 | QWidget::tr("Data can not be edited, currently syncing")); | 490 | QWidget::tr("Data can not be edited, currently syncing")); |
491 | return; | 491 | return; |
492 | } | 492 | } |
493 | OTodo to = m_todoMgr.event(uid); | 493 | OTodo to = m_todoMgr.event(uid); |
494 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), to.toShortText() ) ) | 494 | if (!QPEMessageBox::confirmDelete(this, QWidget::tr("Todo"), to.toShortText() ) ) |
495 | return; | 495 | return; |
496 | 496 | ||
497 | handleAlarms(to, OTodo() ); | 497 | handleAlarms(to, OTodo() ); |
498 | m_todoMgr.remove( to.uid() ); | 498 | m_todoMgr.remove( to.uid() ); |
499 | currentView()->removeEvent( to.uid() ); | 499 | currentView()->removeEvent( to.uid() ); |
500 | raiseCurrentView(); | 500 | raiseCurrentView(); |
501 | } | 501 | } |
502 | void MainWindow::slotDeleteAll() { | 502 | void MainWindow::slotDeleteAll() { |
503 | if(m_syncing) { | 503 | if(m_syncing) { |
504 | QMessageBox::warning(this, QWidget::tr("Todo"), | 504 | QMessageBox::warning(this, QWidget::tr("Todo"), |
505 | QWidget::tr("Data can not be edited, currently syncing")); | 505 | QWidget::tr("Data can not be edited, currently syncing")); |
506 | return; | 506 | return; |
507 | } | 507 | } |
508 | 508 | ||
509 | 509 | ||
510 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all tasks?") ) ) | 510 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all tasks?") ) ) |
511 | return; | 511 | return; |
512 | 512 | ||
513 | m_todoMgr.removeAll(); | 513 | m_todoMgr.removeAll(); |
514 | currentView()->clear(); | 514 | currentView()->clear(); |
515 | 515 | ||
516 | raiseCurrentView(); | 516 | raiseCurrentView(); |
517 | } | 517 | } |
518 | void MainWindow::slotDeleteCompleted() { | 518 | void MainWindow::slotDeleteCompleted() { |
519 | if(m_syncing) { | 519 | if(m_syncing) { |
520 | QMessageBox::warning(this, QWidget::tr("Todo"), | 520 | QMessageBox::warning(this, QWidget::tr("Todo"), |
521 | QWidget::tr("Data can not be edited, currently syncing")); | 521 | QWidget::tr("Data can not be edited, currently syncing")); |
522 | return; | 522 | return; |
523 | } | 523 | } |
524 | 524 | ||
525 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) ) | 525 | if ( !QPEMessageBox::confirmDelete( this, QWidget::tr( "Todo" ), QWidget::tr("all completed tasks?") ) ) |
526 | return; | 526 | return; |
527 | 527 | ||
528 | 528 | ||
529 | m_todoMgr.removeCompleted(); | 529 | m_todoMgr.removeCompleted(); |
530 | currentView()->updateView( ); | 530 | currentView()->updateView( ); |
531 | } | 531 | } |
532 | void MainWindow::slotFind() { | 532 | void MainWindow::slotFind() { |
533 | 533 | ||
534 | } | 534 | } |
535 | void MainWindow::slotEdit() { | 535 | void MainWindow::slotEdit() { |
536 | slotEdit( currentView()->current() ); | 536 | slotEdit( currentView()->current() ); |
537 | } | 537 | } |
538 | /* | 538 | /* |
539 | * set the category | 539 | * set the category |
540 | */ | 540 | */ |
541 | void MainWindow::setCategory( int c) { | 541 | void MainWindow::setCategory( int c) { |
542 | if ( c <= 0 ) return; | 542 | if ( c <= 0 ) return; |
543 | 543 | ||
544 | 544 | ||
545 | qWarning("Iterating over cats %d", c ); | 545 | qWarning("Iterating over cats %d", c ); |
546 | for ( unsigned int i = 1; i < m_catMenu->count(); i++ ) | 546 | for ( unsigned int i = 1; i < m_catMenu->count(); i++ ) |
547 | m_catMenu->setItemChecked(i, c == (int)i ); | 547 | m_catMenu->setItemChecked(i, c == (int)i ); |
548 | 548 | ||
549 | if (c == 1 ) { | 549 | if (c == 1 ) { |
550 | m_curCat = QString::null; | 550 | m_curCat = QString::null; |
551 | setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("All Categories" ) ); | 551 | setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("All Categories" ) ); |
552 | 552 | ||
553 | }else if ( c == (int)m_catMenu->count() - 1 ) { | 553 | }else if ( c == (int)m_catMenu->count() - 1 ) { |
554 | m_curCat = QWidget::tr("Unfiled"); | 554 | m_curCat = QWidget::tr("Unfiled"); |
555 | setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("Unfiled") ); | 555 | setCaption( QWidget::tr("Todo") + " - " + QWidget::tr("Unfiled") ); |
556 | }else { | 556 | }else { |
557 | m_curCat = m_todoMgr.categories()[c-2]; | 557 | m_curCat = m_todoMgr.categories()[c-2]; |
558 | setCaption( QWidget::tr("Todo") + " - " + m_curCat ); | 558 | setCaption( QWidget::tr("Todo") + " - " + m_curCat ); |
559 | } | 559 | } |
560 | m_catMenu->setItemChecked( c, true ); | 560 | m_catMenu->setItemChecked( c, true ); |
561 | 561 | ||
562 | currentView()->setShowCategory( m_curCat ); | 562 | currentView()->setShowCategory( m_curCat ); |
563 | raiseCurrentView(); | 563 | raiseCurrentView(); |
564 | } | 564 | } |
565 | void MainWindow::slotShowDeadLine( bool dead) { | 565 | void MainWindow::slotShowDeadLine( bool dead) { |
566 | m_deadline = dead; | 566 | m_deadline = dead; |
567 | currentView()->setShowDeadline( dead ); | 567 | currentView()->setShowDeadline( dead ); |
568 | } | 568 | } |
569 | void MainWindow::slotShowCompleted( bool show) { | 569 | void MainWindow::slotShowCompleted( bool show) { |
570 | m_completed = show; | 570 | m_completed = show; |
571 | currentView()->setShowCompleted( m_completed ); | 571 | currentView()->setShowCompleted( m_completed ); |
572 | } | 572 | } |
573 | void MainWindow::slotShowQuickTask( bool show ) { | 573 | void MainWindow::slotShowQuickTask( bool show ) { |
574 | m_quicktask = show; | 574 | m_quicktask = show; |
575 | if ( m_quicktask ) | 575 | if ( m_quicktask ) |
576 | m_curQuick->widget()->show(); | 576 | m_curQuick->widget()->show(); |
577 | else | 577 | else |
578 | m_curQuick->widget()->hide(); | 578 | m_curQuick->widget()->hide(); |
579 | } | 579 | } |
580 | bool MainWindow::showOverDue()const { | 580 | bool MainWindow::showOverDue()const { |
581 | return m_overdue; | 581 | return m_overdue; |
582 | } | 582 | } |
583 | void MainWindow::setDocument( const QString& fi) { | 583 | void MainWindow::setDocument( const QString& fi) { |
584 | DocLnk doc(fi); | 584 | DocLnk doc(fi); |
585 | if (doc.isValid() ) | 585 | if (doc.isValid() ) |
586 | receiveFile(doc.file() ); | 586 | receiveFile(doc.file() ); |
587 | else | 587 | else |
588 | receiveFile(fi ); | 588 | receiveFile(fi ); |
589 | } | 589 | } |
590 | 590 | ||
591 | static const char *beamfile = "/tmp/opie-todo.vcs"; | 591 | static const char *beamfile = "/tmp/opie-todo.vcs"; |
592 | void MainWindow::slotBeam() { | 592 | void MainWindow::slotBeam() { |
593 | beam( currentView()->current() ); | 593 | beam( currentView()->current() ); |
594 | } | 594 | } |
595 | void MainWindow::beamDone( Ir* ir) { | 595 | void MainWindow::beamDone( Ir* ir) { |
596 | delete ir; | 596 | delete ir; |
597 | ::unlink( beamfile ); | 597 | ::unlink( beamfile ); |
598 | } | 598 | } |
599 | void MainWindow::receiveFile( const QString& filename ) { | 599 | void MainWindow::receiveFile( const QString& filename ) { |
600 | OTodoAccessVCal* cal = new OTodoAccessVCal(filename ); | 600 | OTodoAccessVCal* cal = new OTodoAccessVCal(filename ); |
601 | 601 | ||
602 | OTodoAccess acc( cal ); | 602 | OTodoAccess acc( cal ); |
603 | acc.load(); | 603 | acc.load(); |
604 | OTodoAccess::List list = acc.allRecords(); | 604 | OTodoAccess::List list = acc.allRecords(); |
605 | 605 | ||
606 | if (list.count()){ | 606 | if (list.count()){ |
607 | 607 | ||
608 | QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); | 608 | QString message = QWidget::tr("<P>%1 new tasks arrived.<p>Would you like to add them to your Todolist?").arg(list.count() ); |
609 | 609 | ||
610 | if ( QMessageBox::information(this, QWidget::tr("New Tasks"), | 610 | if ( QMessageBox::information(this, QWidget::tr("New Tasks"), |
611 | message, QMessageBox::Ok, | 611 | message, QMessageBox::Ok, |
612 | QMessageBox::Cancel ) == QMessageBox::Ok ) { | 612 | QMessageBox::Cancel ) == QMessageBox::Ok ) { |
613 | OTodoAccess::List::Iterator it; | 613 | OTodoAccess::List::Iterator it; |
614 | for ( it = list.begin(); it != list.end(); ++it ) | 614 | for ( it = list.begin(); it != list.end(); ++it ) |
615 | m_todoMgr.add( (*it) ); | 615 | m_todoMgr.add( (*it) ); |
616 | 616 | ||
617 | currentView()->updateView(); | 617 | currentView()->updateView(); |
618 | } | 618 | } |
619 | } | 619 | } |
620 | } | 620 | } |
621 | 621 | ||
622 | void MainWindow::slotFlush() { | 622 | void MainWindow::slotFlush() { |
623 | m_syncing = TRUE; | 623 | m_syncing = TRUE; |
624 | m_todoMgr.save(); | 624 | m_todoMgr.save(); |
625 | } | 625 | } |
626 | void MainWindow::slotShowDetails() { | 626 | void MainWindow::slotShowDetails() { |
627 | slotShow( currentView()->current() ); | 627 | slotShow( currentView()->current() ); |
628 | } | 628 | } |
629 | /* | 629 | /* |
630 | * populate the Categories | 630 | * populate the Categories |
631 | * Menu | 631 | * Menu |
632 | */ | 632 | */ |
633 | void MainWindow::populateCategories() { | 633 | void MainWindow::populateCategories() { |
634 | m_todoMgr.load(); | 634 | m_todoMgr.load(); |
635 | 635 | ||
636 | m_catMenu->clear(); | 636 | m_catMenu->clear(); |
637 | int id, rememberId; | 637 | int id, rememberId; |
638 | id = 1; | 638 | id = 1; |
639 | rememberId = 1; | 639 | rememberId = 1; |
640 | 640 | ||
641 | m_catMenu->insertItem( QWidget::tr( "All Categories" ), id++ ); | 641 | m_catMenu->insertItem( QWidget::tr( "All Categories" ), id++ ); |
642 | m_catMenu->insertSeparator(); | 642 | m_catMenu->insertSeparator(); |
643 | QStringList categories = m_todoMgr.categories(); | 643 | QStringList categories = m_todoMgr.categories(); |
644 | categories.append( QWidget::tr( "Unfiled" ) ); | 644 | categories.append( QWidget::tr( "Unfiled" ) ); |
645 | for ( QStringList::Iterator it = categories.begin(); | 645 | for ( QStringList::Iterator it = categories.begin(); |
646 | it != categories.end(); ++it ) { | 646 | it != categories.end(); ++it ) { |
647 | m_catMenu->insertItem( *it, id ); | 647 | m_catMenu->insertItem( *it, id ); |
648 | if ( *it == currentCategory() ) | 648 | if ( *it == currentCategory() ) |
649 | rememberId = id; | 649 | rememberId = id; |
650 | ++id; | 650 | ++id; |
651 | } | 651 | } |
652 | setCategory( rememberId ); | 652 | setCategory( rememberId ); |
653 | } | 653 | } |
654 | bool MainWindow::showCompleted()const { | 654 | bool MainWindow::showCompleted()const { |
655 | return m_completed; | 655 | return m_completed; |
656 | } | 656 | } |
657 | bool MainWindow::showDeadline()const { | 657 | bool MainWindow::showDeadline()const { |
658 | return m_deadline; | 658 | return m_deadline; |
659 | } | 659 | } |
660 | bool MainWindow::showQuickTask()const { | 660 | bool MainWindow::showQuickTask()const { |
661 | return m_quicktask; | 661 | return m_quicktask; |
662 | } | 662 | } |
663 | QString MainWindow::currentCategory()const { | 663 | QString MainWindow::currentCategory()const { |
664 | return m_curCat; | 664 | return m_curCat; |
665 | } | 665 | } |
666 | int MainWindow::currentCatId() { | 666 | int MainWindow::currentCatId() { |
667 | return m_todoMgr.catId( m_curCat ); | 667 | return m_todoMgr.catId( m_curCat ); |
668 | } | 668 | } |
669 | ViewBase* MainWindow::currentView() { | 669 | ViewBase* MainWindow::currentView() { |
670 | return m_curView; | 670 | return m_curView; |
671 | } | 671 | } |
672 | void MainWindow::raiseCurrentView() { | 672 | void MainWindow::raiseCurrentView() { |
673 | // due QPE/Application/todolist show(int) | 673 | // due QPE/Application/todolist show(int) |
674 | // we might not have the populateCategories slot called once | 674 | // we might not have the populateCategories slot called once |
675 | // we would show the otodo but then imediately switch to the currentView | 675 | // we would show the otodo but then imediately switch to the currentView |
676 | // if we're initially showing we shouldn't raise the table | 676 | // if we're initially showing we shouldn't raise the table |
677 | // in returnFromView we fix up m_showing | 677 | // in returnFromView we fix up m_showing |
678 | if (m_showing ) return; | 678 | if (m_showing ) return; |
679 | 679 | ||
680 | m_stack->raiseWidget( m_curView->widget() ); | 680 | m_stack->raiseWidget( m_curView->widget() ); |
681 | } | 681 | } |
682 | void MainWindow::slotShowDue(bool ov) { | 682 | void MainWindow::slotShowDue(bool ov) { |
683 | m_overdue = ov; | 683 | m_overdue = ov; |
684 | currentView()->showOverDue( ov ); | 684 | currentView()->showOverDue( ov ); |
685 | raiseCurrentView(); | 685 | raiseCurrentView(); |
686 | } | 686 | } |
687 | void MainWindow::slotShow( int uid ) { | 687 | void MainWindow::slotShow( int uid ) { |
688 | if ( uid == 0 ) return; | 688 | if ( uid == 0 ) return; |
689 | qWarning("slotShow"); | 689 | qWarning("slotShow"); |
690 | currentShow()->slotShow( event( uid ) ); | 690 | currentShow()->slotShow( event( uid ) ); |
691 | m_stack->raiseWidget( currentShow()->widget() ); | 691 | m_stack->raiseWidget( currentShow()->widget() ); |
692 | } | 692 | } |
693 | void MainWindow::slotShowNext() { | 693 | void MainWindow::slotShowNext() { |
694 | int l = currentView()->next(); | 694 | int l = currentView()->next(); |
695 | if (l!=0) | 695 | if (l!=0) |
696 | slotShow(l); | 696 | slotShow(l); |
697 | } | 697 | } |
698 | void MainWindow::slotShowPrev() { | 698 | void MainWindow::slotShowPrev() { |
699 | int l = currentView()->prev(); | 699 | int l = currentView()->prev(); |
700 | if (l!=0) | 700 | if (l!=0) |
701 | slotShow(l); | 701 | slotShow(l); |
702 | } | 702 | } |
703 | void MainWindow::slotEdit( int uid ) { | 703 | void MainWindow::slotEdit( int uid ) { |
704 | if (uid == 0 ) return; | 704 | if (uid == 0 ) return; |
705 | if(m_syncing) { | 705 | if(m_syncing) { |
706 | QMessageBox::warning(this, QWidget::tr("Todo"), | 706 | QMessageBox::warning(this, QWidget::tr("Todo"), |
707 | QWidget::tr("Data can't be edited, currently syncing")); | 707 | QWidget::tr("Data can't be edited, currently syncing")); |
708 | return; | 708 | return; |
709 | } | 709 | } |
710 | 710 | ||
711 | OTodo old_todo = m_todoMgr.event( uid ); | 711 | OTodo old_todo = m_todoMgr.event( uid ); |
712 | 712 | ||
713 | OTodo todo = currentEditor()->edit(this, old_todo ); | 713 | OTodo todo = currentEditor()->edit(this, old_todo ); |
714 | 714 | ||
715 | /* if completed */ | 715 | /* if completed */ |
716 | if ( currentEditor()->accepted() ) { | 716 | if ( currentEditor()->accepted() ) { |
717 | handleAlarms( old_todo, todo ); | 717 | handleAlarms( old_todo, todo ); |
718 | m_todoMgr.update( todo.uid(), todo ); | 718 | m_todoMgr.update( todo.uid(), todo ); |
719 | currentView()->replaceEvent( todo ); | 719 | currentView()->replaceEvent( todo ); |
720 | /* a Category might have changed */ | 720 | /* a Category might have changed */ |
721 | populateCategories(); | 721 | populateCategories(); |
722 | } | 722 | } |
723 | 723 | ||
724 | raiseCurrentView(); | 724 | raiseCurrentView(); |
725 | } | 725 | } |
726 | /* | 726 | /* |
727 | void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) { | 727 | void MainWindow::slotUpdate1( int uid, const SmallTodo& ev) { |
728 | m_todoMgr.update( uid, ev ); | 728 | m_todoMgr.update( uid, ev ); |
729 | } | 729 | } |
730 | */ | 730 | */ |
731 | void MainWindow::updateTodo( const OTodo& ev) { | 731 | void MainWindow::updateTodo( const OTodo& ev) { |
732 | m_todoMgr.update( ev.uid() , ev ); | 732 | m_todoMgr.update( ev.uid() , ev ); |
733 | } | 733 | } |
734 | /* The view changed it's configuration | 734 | /* The view changed it's configuration |
735 | * update the view menu | 735 | * update the view menu |
736 | */ | 736 | */ |
737 | void MainWindow::slotUpdate3( QWidget* ) { | 737 | void MainWindow::slotUpdate3( QWidget* ) { |
738 | 738 | ||
739 | } | 739 | } |
740 | void MainWindow::updateList() { | 740 | void MainWindow::updateList() { |
741 | m_todoMgr.updateList(); | 741 | m_todoMgr.updateList(); |
742 | } | 742 | } |
743 | void MainWindow::setReadAhead( uint count ) { | 743 | void MainWindow::setReadAhead( uint count ) { |
744 | if (m_todoMgr.todoDB() ) | 744 | if (m_todoMgr.todoDB() ) |
745 | m_todoMgr.todoDB()->setReadAhead( count ); | 745 | m_todoMgr.todoDB()->setReadAhead( count ); |
746 | } | 746 | } |
747 | void MainWindow::slotQuickEntered() { | 747 | void MainWindow::slotQuickEntered() { |
748 | qWarning("entered"); | 748 | qWarning("entered"); |
749 | OTodo todo = quickEditor()->todo(); | 749 | OTodo todo = quickEditor()->todo(); |
750 | if (todo.isEmpty() ) | 750 | if (todo.isEmpty() ) |
751 | return; | 751 | return; |
752 | 752 | ||
753 | m_todoMgr.add( todo ); | 753 | m_todoMgr.add( todo ); |
754 | currentView()->addEvent( todo ); | 754 | currentView()->addEvent( todo ); |
755 | raiseCurrentView(); | 755 | raiseCurrentView(); |
756 | } | 756 | } |
757 | QuickEditBase* MainWindow::quickEditor() { | 757 | QuickEditBase* MainWindow::quickEditor() { |
758 | return m_curQuick; | 758 | return m_curQuick; |
759 | } | 759 | } |
760 | void MainWindow::slotComplete( int uid ) { | 760 | void MainWindow::slotComplete( int uid ) { |
761 | slotComplete( event(uid) ); | 761 | slotComplete( event(uid) ); |
762 | } | 762 | } |
763 | void MainWindow::slotComplete( const OTodo& todo ) { | 763 | void MainWindow::slotComplete( const OTodo& todo ) { |
764 | OTodo to = todo; | 764 | OTodo to = todo; |
765 | to.setCompleted( !to.isCompleted() ); | 765 | to.setCompleted( !to.isCompleted() ); |
766 | to.setCompletedDate( QDate::currentDate() ); | 766 | to.setCompletedDate( QDate::currentDate() ); |
767 | 767 | ||
768 | /* | 768 | /* |
769 | * if the item does recur | 769 | * if the item does recur |
770 | * we need to spin it off | 770 | * we need to spin it off |
771 | * and update the items duedate to the next | 771 | * and update the items duedate to the next |
772 | * possible recurrance of this item... | 772 | * possible recurrance of this item... |
773 | * the spinned off one will loose the | 773 | * the spinned off one will loose the |
774 | * recurrence. | 774 | * recurrence. |
775 | * We calculate the difference between the old due date and the | 775 | * We calculate the difference between the old due date and the |
776 | * new one and add this diff to start, completed and alarm dates | 776 | * new one and add this diff to start, completed and alarm dates |
777 | * -zecke | 777 | * -zecke |
778 | */ | 778 | */ |
779 | if ( to.hasRecurrence() && to.isCompleted() ) { | 779 | if ( to.hasRecurrence() && to.isCompleted() ) { |
780 | OTodo to2( to ); | 780 | OTodo to2( to ); |
781 | 781 | ||
782 | /* the spinned off one won't recur anymore */ | 782 | /* the spinned off one won't recur anymore */ |
783 | to.setRecurrence( ORecur() ); | 783 | to.setRecurrence( ORecur() ); |
784 | 784 | ||
785 | ORecur rec = to2.recurrence(); | 785 | ORecur rec = to2.recurrence(); |
786 | rec.setStart( to.dueDate() ); | 786 | rec.setStart( to.dueDate() ); |
787 | to2.setRecurrence( rec ); | 787 | to2.setRecurrence( rec ); |
788 | /* | 788 | /* |
789 | * if there is a next occurence | 789 | * if there is a next occurence |
790 | * from the duedate of the last recurrance | 790 | * from the duedate of the last recurrance |
791 | */ | 791 | */ |
792 | QDate date; | 792 | QDate date; |
793 | if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { | 793 | if ( to2.recurrence().nextOcurrence( to2.dueDate().addDays(1), date ) ) { |
794 | int dayDiff = to.dueDate().daysTo( date ); | 794 | int dayDiff = to.dueDate().daysTo( date ); |
795 | qWarning("day diff is %d", dayDiff ); | 795 | qWarning("day diff is %d", dayDiff ); |
796 | QDate inval; | 796 | QDate inval; |
797 | /* generate a new uid for the old record */ | 797 | /* generate a new uid for the old record */ |
798 | to.setUid( 1 ); | 798 | to.setUid( 1 ); |
799 | 799 | ||
800 | /* add the old one cause it has a new UID here cause it was spin off */ | 800 | /* add the old one cause it has a new UID here cause it was spin off */ |
801 | m_todoMgr.add( to ); | 801 | m_todoMgr.add( to ); |
802 | 802 | ||
803 | /* | 803 | /* |
804 | * update the due date | 804 | * update the due date |
805 | * start date | 805 | * start date |
806 | * and complete date | 806 | * and complete date |
807 | */ | 807 | */ |
808 | to2.setDueDate( date ); | 808 | to2.setDueDate( date ); |
809 | rec.setStart( date ); | 809 | rec.setStart( date ); |
810 | to2.setRecurrence( rec ); // could be Monday, TuesDay, Thursday every week | 810 | to2.setRecurrence( rec ); // could be Monday, TuesDay, Thursday every week |
811 | 811 | ||
812 | /* move start date */ | 812 | /* move start date */ |
813 | if (to2.hasStartDate() ) | 813 | if (to2.hasStartDate() ) |
814 | to2.setStartDate( to2.startDate().addDays( dayDiff ) ); | 814 | to2.setStartDate( to2.startDate().addDays( dayDiff ) ); |
815 | 815 | ||
816 | /* now the alarms */ | 816 | /* now the alarms */ |
817 | if (to2.hasNotifiers() ) { | 817 | if (to2.hasNotifiers() ) { |
818 | OPimNotifyManager::Alarms _als = to2.notifiers().alarms(); | 818 | OPimNotifyManager::Alarms _als = to2.notifiers().alarms(); |
819 | OPimNotifyManager::Alarms als; | 819 | OPimNotifyManager::Alarms als; |
820 | 820 | ||
821 | /* for every alarm move the day */ | 821 | /* for every alarm move the day */ |
822 | for ( OPimNotifyManager::Alarms::Iterator it = _als.begin(); it != _als.end(); ++it ) { | 822 | for ( OPimNotifyManager::Alarms::Iterator it = _als.begin(); it != _als.end(); ++it ) { |
823 | OPimAlarm al = (*it); | 823 | OPimAlarm al = (*it); |
824 | al.setDateTime( al.dateTime().addDays( dayDiff ) ); | 824 | al.setDateTime( al.dateTime().addDays( dayDiff ) ); |
825 | als.append( al ); | 825 | als.append( al ); |
826 | } | 826 | } |
827 | to2.notifiers().setAlarms( als ); | 827 | to2.notifiers().setAlarms( als ); |
828 | handleAlarms( OTodo(), todo ); | 828 | handleAlarms( OTodo(), todo ); |
829 | } | 829 | } |
830 | to2.setCompletedDate( inval ); | 830 | to2.setCompletedDate( inval ); |
831 | to2.setCompleted( false ); | 831 | to2.setCompleted( false ); |
832 | 832 | ||
833 | updateTodo( to2 ); | 833 | updateTodo( to2 ); |
834 | }else | 834 | }else |
835 | updateTodo( to ); | 835 | updateTodo( to ); |
836 | }else | 836 | }else |
837 | updateTodo( to ); | 837 | updateTodo( to ); |
838 | 838 | ||
839 | currentView()->updateView(); | 839 | currentView()->updateView(); |
840 | raiseCurrentView(); | 840 | raiseCurrentView(); |
841 | } | 841 | } |
842 | void MainWindow::flush() { | 842 | void MainWindow::flush() { |
843 | slotFlush(); | 843 | slotFlush(); |
844 | } | 844 | } |
845 | void MainWindow::reload() { | 845 | void MainWindow::reload() { |
846 | slotReload(); | 846 | slotReload(); |
847 | } | 847 | } |
848 | int MainWindow::create() { | 848 | int MainWindow::create() { |
849 | int uid = 0; | 849 | int uid = 0; |
850 | if(m_syncing) { | 850 | if(m_syncing) { |
851 | QMessageBox::warning(this, QWidget::tr("Todo"), | 851 | QMessageBox::warning(this, QWidget::tr("Todo"), |
852 | QWidget::tr("Data can not be edited, currently syncing")); | 852 | QWidget::tr("Data can not be edited, currently syncing")); |
853 | return uid; | 853 | return uid; |
854 | } | 854 | } |
855 | m_todoMgr.load(); | 855 | m_todoMgr.load(); |
856 | 856 | ||
857 | 857 | ||
858 | OTodo todo = currentEditor()->newTodo( currentCatId(), | 858 | OTodo todo = currentEditor()->newTodo( currentCatId(), |
859 | this ); | 859 | this ); |
860 | 860 | ||
861 | if ( currentEditor()->accepted() ) { | 861 | if ( currentEditor()->accepted() ) { |
862 | //todo.assignUid(); | 862 | //todo.assignUid(); |
863 | uid = todo.uid(); | 863 | uid = todo.uid(); |
864 | handleAlarms( OTodo(), todo ); | 864 | handleAlarms( OTodo(), todo ); |
865 | m_todoMgr.add( todo ); | 865 | m_todoMgr.add( todo ); |
866 | currentView()->addEvent( todo ); | 866 | currentView()->addEvent( todo ); |
867 | 867 | ||
868 | 868 | ||
869 | // I'm afraid we must call this every time now, otherwise | 869 | // I'm afraid we must call this every time now, otherwise |
870 | // spend expensive time comparing all these strings... | 870 | // spend expensive time comparing all these strings... |
871 | // but only call if we changed something -zecke | 871 | // but only call if we changed something -zecke |
872 | populateCategories(); | 872 | populateCategories(); |
873 | } | 873 | } |
874 | raiseCurrentView( ); | 874 | raiseCurrentView( ); |
875 | 875 | ||
876 | return uid; | 876 | return uid; |
877 | } | 877 | } |
878 | /* delete it silently... */ | 878 | /* delete it silently... */ |
879 | bool MainWindow::remove( int uid ) { | 879 | bool MainWindow::remove( int uid ) { |
880 | if (m_syncing) return false; | 880 | if (m_syncing) return false; |
881 | 881 | ||
882 | /* argh need to get the whole OEvent... to disable alarms -zecke */ | 882 | /* argh need to get the whole OEvent... to disable alarms -zecke */ |
883 | handleAlarms( OTodo(), m_todoMgr.event( uid ) ); | 883 | handleAlarms( OTodo(), m_todoMgr.event( uid ) ); |
884 | 884 | ||
885 | return m_todoMgr.remove( uid ); | 885 | return m_todoMgr.remove( uid ); |
886 | } | 886 | } |
887 | void MainWindow::beam( int uid) { | 887 | void MainWindow::beam( int uid) { |
888 | if( uid == 0 ) return; | 888 | if( uid == 0 ) return; |
889 | 889 | ||
890 | ::unlink( beamfile ); | 890 | ::unlink( beamfile ); |
891 | m_todoMgr.load(); | 891 | m_todoMgr.load(); |
892 | 892 | ||
893 | OTodo todo = event( uid ); | 893 | OTodo todo = event( uid ); |
894 | OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); | 894 | OTodoAccessVCal* cal = new OTodoAccessVCal(QString::fromLatin1(beamfile) ); |
895 | OTodoAccess acc( cal ); | 895 | OTodoAccess acc( cal ); |
896 | acc.load(); | 896 | acc.load(); |
897 | acc.add( todo ); | 897 | acc.add( todo ); |
898 | acc.save(); | 898 | acc.save(); |
899 | Ir* ir = new Ir(this ); | 899 | Ir* ir = new Ir(this ); |
900 | connect(ir, SIGNAL(done(Ir*) ), | 900 | connect(ir, SIGNAL(done(Ir*) ), |
901 | this, SLOT(beamDone(Ir*) ) ); | 901 | this, SLOT(beamDone(Ir*) ) ); |
902 | ir->send(beamfile, todo.summary(), "text/x-vCalendar" ); | 902 | ir->send(beamfile, todo.summary(), "text/x-vCalendar" ); |
903 | } | 903 | } |
904 | void MainWindow::show( int uid ) { | 904 | void MainWindow::show( int uid ) { |
905 | m_todoMgr.load(); // might not be loaded yet | 905 | m_todoMgr.load(); // might not be loaded yet |
906 | m_showing = true; | 906 | m_showing = true; |
907 | slotShow( uid ); | 907 | slotShow( uid ); |
908 | raise(); | 908 | raise(); |
909 | QPEApplication::setKeepRunning(); | 909 | QPEApplication::setKeepRunning(); |
910 | } | 910 | } |
911 | void MainWindow::edit( int uid ) { | 911 | void MainWindow::edit( int uid ) { |
912 | m_todoMgr.load(); | 912 | m_todoMgr.load(); |
913 | slotEdit( uid ); | 913 | slotEdit( uid ); |
914 | } | 914 | } |
915 | void MainWindow::add( const OPimRecord& rec) { | 915 | void MainWindow::add( const OPimRecord& rec) { |
916 | if ( rec.rtti() != OTodo::rtti() ) return; | 916 | if ( rec.rtti() != OTodo::rtti() ) return; |
917 | m_todoMgr.load(); // might not be loaded | 917 | m_todoMgr.load(); // might not be loaded |
918 | 918 | ||
919 | const OTodo& todo = static_cast<const OTodo&>(rec); | 919 | const OTodo& todo = static_cast<const OTodo&>(rec); |
920 | 920 | ||
921 | m_todoMgr.add(todo ); | 921 | m_todoMgr.add(todo ); |
922 | currentView()->addEvent( todo ); | 922 | currentView()->addEvent( todo ); |
923 | 923 | ||
924 | 924 | ||
925 | // I'm afraid we must call this every time now, otherwise | 925 | // I'm afraid we must call this every time now, otherwise |
926 | // spend expensive time comparing all these strings... | 926 | // spend expensive time comparing all these strings... |
927 | // but only call if we changed something -zecke | 927 | // but only call if we changed something -zecke |
928 | populateCategories(); | 928 | populateCategories(); |
929 | } | 929 | } |
930 | void MainWindow::slotReturnFromView() { | 930 | void MainWindow::slotReturnFromView() { |
931 | m_showing = false; | 931 | m_showing = false; |
932 | raiseCurrentView(); | 932 | raiseCurrentView(); |
933 | } | 933 | } |
934 | 934 | ||
935 | namespace { | 935 | namespace { |
936 | OPimNotifyManager::Alarms findNonMatching( const OPimNotifyManager::Alarms& oldAls, | 936 | OPimNotifyManager::Alarms findNonMatching( const OPimNotifyManager::Alarms& oldAls, |
937 | const OPimNotifyManager::Alarms& newAls ) { | 937 | const OPimNotifyManager::Alarms& newAls ) { |
938 | OPimNotifyManager::Alarms nonMatching; | 938 | OPimNotifyManager::Alarms nonMatching; |
939 | OPimNotifyManager::Alarms::ConstIterator oldIt = oldAls.begin(); | 939 | OPimNotifyManager::Alarms::ConstIterator oldIt = oldAls.begin(); |
940 | OPimNotifyManager::Alarms::ConstIterator newIt; | 940 | OPimNotifyManager::Alarms::ConstIterator newIt; |
941 | for ( ; oldIt != oldAls.end(); ++oldIt ) { | 941 | for ( ; oldIt != oldAls.end(); ++oldIt ) { |
942 | bool found = false; | 942 | bool found = false; |
943 | QDateTime oldDt = (*oldIt).dateTime(); | 943 | QDateTime oldDt = (*oldIt).dateTime(); |
944 | for (newIt= newAls.begin(); newIt != newAls.end(); ++newIt ) { | 944 | for (newIt= newAls.begin(); newIt != newAls.end(); ++newIt ) { |
945 | if ( oldDt == (*newIt).dateTime() ) { | 945 | if ( oldDt == (*newIt).dateTime() ) { |
946 | found = true; | 946 | found = true; |
947 | break; | 947 | break; |
948 | } | 948 | } |
949 | } | 949 | } |
950 | if (!found) | 950 | if (!found) |
951 | nonMatching.append( (*oldIt) ); | 951 | nonMatching.append( (*oldIt) ); |
952 | } | 952 | } |
953 | return nonMatching; | 953 | return nonMatching; |
954 | } | 954 | } |
955 | void addAlarms( const OPimNotifyManager::Alarms& als, int uid ) { | 955 | void addAlarms( const OPimNotifyManager::Alarms& als, int uid ) { |
956 | OPimNotifyManager::Alarms::ConstIterator it; | 956 | OPimNotifyManager::Alarms::ConstIterator it; |
957 | for ( it = als.begin(); it != als.end(); ++it ) { | 957 | for ( it = als.begin(); it != als.end(); ++it ) { |
958 | qWarning("Adding alarm for %s", (*it).dateTime().toString().latin1() ); | 958 | qWarning("Adding alarm for %s", (*it).dateTime().toString().latin1() ); |
959 | AlarmServer::addAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); | 959 | AlarmServer::addAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); |
960 | } | 960 | } |
961 | 961 | ||
962 | } | 962 | } |
963 | void removeAlarms( const OPimNotifyManager::Alarms& als, int uid ) { | 963 | void removeAlarms( const OPimNotifyManager::Alarms& als, int uid ) { |
964 | OPimNotifyManager::Alarms::ConstIterator it; | 964 | OPimNotifyManager::Alarms::ConstIterator it; |
965 | for ( it = als.begin(); it != als.end(); ++it ) { | 965 | for ( it = als.begin(); it != als.end(); ++it ) { |
966 | qWarning("Removinf alarm for %s", (*it).dateTime().toString().latin1() ); | 966 | qWarning("Removinf alarm for %s", (*it).dateTime().toString().latin1() ); |
967 | AlarmServer::deleteAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); | 967 | AlarmServer::deleteAlarm( (*it).dateTime(), "QPE/Application/todolist", "alarm(QDateTime,int)", uid ); |
968 | } | 968 | } |
969 | } | 969 | } |
970 | } | 970 | } |
971 | 971 | ||
972 | void MainWindow::handleAlarms( const OTodo& oldTodo, const OTodo& newTodo) { | 972 | void MainWindow::handleAlarms( const OTodo& oldTodo, const OTodo& newTodo) { |
973 | /* | 973 | /* |
974 | * if oldTodo is not empty and has notifiers we need to find the deleted ones | 974 | * if oldTodo is not empty and has notifiers we need to find the deleted ones |
975 | */ | 975 | */ |
976 | if(!oldTodo.isEmpty() && oldTodo.hasNotifiers() ) { | 976 | if(!oldTodo.isEmpty() && oldTodo.hasNotifiers() ) { |
977 | OPimNotifyManager::Alarms removed; | 977 | OPimNotifyManager::Alarms removed; |
978 | OPimNotifyManager::Alarms oldAls = oldTodo.notifiers().alarms(); | 978 | OPimNotifyManager::Alarms oldAls = oldTodo.notifiers().alarms(); |
979 | if (!newTodo.hasNotifiers() ) | 979 | if (!newTodo.hasNotifiers() ) |
980 | removed = oldAls; | 980 | removed = oldAls; |
981 | else | 981 | else |
982 | removed = findNonMatching( oldAls, newTodo.notifiers().alarms() ); | 982 | removed = findNonMatching( oldAls, newTodo.notifiers().alarms() ); |
983 | 983 | ||
984 | removeAlarms( removed, oldTodo.uid() ); | 984 | removeAlarms( removed, oldTodo.uid() ); |
985 | } | 985 | } |
986 | if ( newTodo.hasNotifiers() ) { | 986 | if ( newTodo.hasNotifiers() ) { |
987 | OPimNotifyManager::Alarms added; | 987 | OPimNotifyManager::Alarms added; |
988 | if ( oldTodo.isEmpty() || !oldTodo.hasNotifiers() ) | 988 | if ( oldTodo.isEmpty() || !oldTodo.hasNotifiers() ) |
989 | added = newTodo.notifiers().alarms(); | 989 | added = newTodo.notifiers().alarms(); |
990 | else | 990 | else |
991 | added = findNonMatching( newTodo.notifiers().alarms(), oldTodo.notifiers().alarms() ); | 991 | added = findNonMatching( newTodo.notifiers().alarms(), oldTodo.notifiers().alarms() ); |
992 | 992 | ||
993 | addAlarms( added, newTodo.uid() ); | 993 | addAlarms( added, newTodo.uid() ); |
994 | } | 994 | } |
995 | } | 995 | } |
996 | /* we might have not loaded the db */ | 996 | /* we might have not loaded the db */ |
997 | void MainWindow::doAlarm( const QDateTime& dt, int uid ) { | 997 | void MainWindow::doAlarm( const QDateTime& dt, int uid ) { |
998 | m_todoMgr.load(); | 998 | m_todoMgr.load(); |
999 | 999 | ||
1000 | OTodo todo = m_todoMgr.event( uid ); | 1000 | OTodo todo = m_todoMgr.event( uid ); |
1001 | if (!todo.hasNotifiers() ) return; | 1001 | if (!todo.hasNotifiers() ) return; |
1002 | 1002 | ||
1003 | /* | 1003 | /* |
1004 | * let's find the right alarm and find out if silent | 1004 | * let's find the right alarm and find out if silent |
1005 | * then show a richtext widget | 1005 | * then show a richtext widget |
1006 | */ | 1006 | */ |
1007 | bool loud = false; | 1007 | bool loud = false; |
1008 | OPimNotifyManager::Alarms als = todo.notifiers().alarms(); | 1008 | OPimNotifyManager::Alarms als = todo.notifiers().alarms(); |
1009 | OPimNotifyManager::Alarms::Iterator it; | 1009 | OPimNotifyManager::Alarms::Iterator it; |
1010 | for ( it = als.begin(); it != als.end(); ++it ) { | 1010 | for ( it = als.begin(); it != als.end(); ++it ) { |
1011 | if ( (*it).dateTime() == dt ) { | 1011 | if ( (*it).dateTime() == dt ) { |
1012 | loud = ( (*it).sound() == OPimAlarm::Loud ); | 1012 | loud = ( (*it).sound() == OPimAlarm::Loud ); |
1013 | break; | 1013 | break; |
1014 | } | 1014 | } |
1015 | } | 1015 | } |
1016 | if (loud) | 1016 | if (loud) |
1017 | startAlarm(); | 1017 | startAlarm(); |
1018 | 1018 | ||
1019 | QDialog dlg(this, 0, TRUE ); | 1019 | QDialog dlg(this, 0, TRUE ); |
1020 | QVBoxLayout* lay = new QVBoxLayout( &dlg ); | 1020 | QVBoxLayout* lay = new QVBoxLayout( &dlg ); |
1021 | QTextView* view = new QTextView( &dlg ); | 1021 | QTextView* view = new QTextView( &dlg ); |
1022 | lay->addWidget( view ); | 1022 | lay->addWidget( view ); |
1023 | QPushButton* btnOk = new QPushButton( tr("Ok"), &dlg ); | 1023 | QPushButton* btnOk = new QPushButton( tr("Ok"), &dlg ); |
1024 | connect( btnOk, SIGNAL(clicked() ), &dlg, SLOT(accept() ) ); | 1024 | connect( btnOk, SIGNAL(clicked() ), &dlg, SLOT(accept() ) ); |
1025 | lay->addWidget( btnOk ); | 1025 | lay->addWidget( btnOk ); |
1026 | 1026 | ||
1027 | QString text = tr("<h1>Alarm at %1</h1><br>").arg( TimeString::dateString( dt ) ); | 1027 | QString text = tr("<h1>Alarm at %1</h1><br>").arg( TimeString::dateString( dt ) ); |
1028 | text += todo.toRichText(); | 1028 | text += todo.toRichText(); |
1029 | view->setText( text ); | 1029 | view->setText( text ); |
1030 | 1030 | ||
1031 | dlg.showMaximized(); | 1031 | dlg.showMaximized(); |
1032 | bool needToStay = dlg.exec(); | 1032 | bool needToStay = dlg.exec(); |
1033 | 1033 | ||
1034 | if (loud) | 1034 | if (loud) |
1035 | killAlarm(); | 1035 | killAlarm(); |
1036 | 1036 | ||
1037 | if (needToStay) { | 1037 | if (needToStay) { |
1038 | // showMaximized(); | 1038 | // showMaximized(); |
1039 | // raise(); | 1039 | // raise(); |
1040 | QPEApplication::setKeepRunning(); | 1040 | QPEApplication::setKeepRunning(); |
1041 | // setActiveWindow(); | 1041 | // setActiveWindow(); |
1042 | } | 1042 | } |
1043 | 1043 | ||
1044 | } | 1044 | } |
1045 | 1045 | ||
diff --git a/core/pim/todo/quickeditimpl.cpp b/core/pim/todo/quickeditimpl.cpp index 70e0582..1863ef4 100644 --- a/core/pim/todo/quickeditimpl.cpp +++ b/core/pim/todo/quickeditimpl.cpp | |||
@@ -1,116 +1,116 @@ | |||
1 | #include <qaction.h> | 1 | #include <qaction.h> |
2 | #include <qlineedit.h> | 2 | #include <qlineedit.h> |
3 | #include <qwhatsthis.h> | 3 | #include <qwhatsthis.h> |
4 | 4 | ||
5 | #include <qpe/resource.h> | 5 | #include <qpe/resource.h> |
6 | 6 | ||
7 | #include <opie/oclickablelabel.h> | 7 | #include <opie/oclickablelabel.h> |
8 | 8 | ||
9 | #include "mainwindow.h" | 9 | #include "mainwindow.h" |
10 | #include "quickeditimpl.h" | 10 | #include "quickeditimpl.h" |
11 | 11 | ||
12 | 12 | ||
13 | QuickEditImpl::QuickEditImpl( QWidget* parent, bool visible ) | 13 | QuickEditImpl::QuickEditImpl( QWidget* parent, bool visible ) |
14 | : QPEToolBar( (QMainWindow *)parent ), Todo::QuickEdit( (Todo::MainWindow *)parent ) { | 14 | : QToolBar( (QMainWindow *)parent ), Todo::QuickEdit( (Todo::MainWindow *)parent ) { |
15 | setHorizontalStretchable( TRUE ); | 15 | setHorizontalStretchable( TRUE ); |
16 | 16 | ||
17 | // Load priority icons | 17 | // Load priority icons |
18 | // TODO - probably should be done globally somewhere else, | 18 | // TODO - probably should be done globally somewhere else, |
19 | // see also tableview.cpp/h, taskeditoroverview.cpp/h | 19 | // see also tableview.cpp/h, taskeditoroverview.cpp/h |
20 | priority1 = Resource::loadPixmap( "todo/priority1" ); | 20 | priority1 = Resource::loadPixmap( "todo/priority1" ); |
21 | priority3 = Resource::loadPixmap( "todo/priority3" ); | 21 | priority3 = Resource::loadPixmap( "todo/priority3" ); |
22 | priority5 = Resource::loadPixmap( "todo/priority5" ); | 22 | priority5 = Resource::loadPixmap( "todo/priority5" ); |
23 | 23 | ||
24 | m_lbl = new OClickableLabel( this ); | 24 | m_lbl = new OClickableLabel( this ); |
25 | m_lbl->setMinimumWidth( 15 ); | 25 | m_lbl->setMinimumWidth( 15 ); |
26 | m_lbl->setPixmap( priority3 ); | 26 | m_lbl->setPixmap( priority3 ); |
27 | connect(m_lbl, SIGNAL(clicked() ), this, SLOT(slotPrio()) ); | 27 | connect(m_lbl, SIGNAL(clicked() ), this, SLOT(slotPrio()) ); |
28 | QWhatsThis::add( m_lbl, QWidget::tr( "Click here to set the priority of new task.\n\nThis area is called the quick task bar.\n\nIt allows you to quickly add a new task to your list. This area can be shown or hidden by selecting Options->'Show quick task bar' from the menu above." ) ); | 28 | QWhatsThis::add( m_lbl, QWidget::tr( "Click here to set the priority of new task.\n\nThis area is called the quick task bar.\n\nIt allows you to quickly add a new task to your list. This area can be shown or hidden by selecting Options->'Show quick task bar' from the menu above." ) ); |
29 | 29 | ||
30 | m_edit = new QLineEdit( this ); | 30 | m_edit = new QLineEdit( this ); |
31 | setStretchableWidget( m_edit ); | 31 | setStretchableWidget( m_edit ); |
32 | QWhatsThis::add( m_edit, QWidget::tr( "Enter description of new task here.\n\nThis area is called the quick task bar.\n\nIt allows you to quickly add a new task to your list. This area can be shown or hidden by selecting Options->'Show quick task bar' from the menu above." ) ); | 32 | QWhatsThis::add( m_edit, QWidget::tr( "Enter description of new task here.\n\nThis area is called the quick task bar.\n\nIt allows you to quickly add a new task to your list. This area can be shown or hidden by selecting Options->'Show quick task bar' from the menu above." ) ); |
33 | 33 | ||
34 | /* | 34 | /* |
35 | * it's not implemented and won't be implemented for 1.0 | 35 | * it's not implemented and won't be implemented for 1.0 |
36 | */ | 36 | */ |
37 | #if 0 | 37 | #if 0 |
38 | QAction *a = new QAction( QWidget::tr( "More" ), Resource::loadPixmap( "todo/more" ), QString::null, 0, this, 0 ); | 38 | QAction *a = new QAction( QWidget::tr( "More" ), Resource::loadPixmap( "todo/more" ), QString::null, 0, this, 0 ); |
39 | connect( a, SIGNAL( activated() ), this, SLOT( slotMore() ) ); | 39 | connect( a, SIGNAL( activated() ), this, SLOT( slotMore() ) ); |
40 | a->addTo( this ); | 40 | a->addTo( this ); |
41 | a->setWhatsThis( QWidget::tr( "Click here to enter additional information for new task.\n\nThis area is called the quick task bar.\n\nIt allows you to quickly add a new task to your list. This area can be shown or hidden by selecting Options->'Show quick task bar' from the menu above." ) ); | 41 | a->setWhatsThis( QWidget::tr( "Click here to enter additional information for new task.\n\nThis area is called the quick task bar.\n\nIt allows you to quickly add a new task to your list. This area can be shown or hidden by selecting Options->'Show quick task bar' from the menu above." ) ); |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | QAction *a = new QAction( QWidget::tr( "Enter" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 ); | 44 | QAction *a = new QAction( QWidget::tr( "Enter" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 ); |
45 | connect( a, SIGNAL( activated() ), this, SLOT( slotEnter() ) ); | 45 | connect( a, SIGNAL( activated() ), this, SLOT( slotEnter() ) ); |
46 | a->addTo( this ); | 46 | a->addTo( this ); |
47 | a->setWhatsThis( QWidget::tr( "Click here to add new task.\n\nThis area is called the quick task bar.\n\nIt allows you to quickly add a new task to your list. This area can be shown or hidden by selecting Options->'Show quick task bar' from the menu above." ) ); | 47 | a->setWhatsThis( QWidget::tr( "Click here to add new task.\n\nThis area is called the quick task bar.\n\nIt allows you to quickly add a new task to your list. This area can be shown or hidden by selecting Options->'Show quick task bar' from the menu above." ) ); |
48 | 48 | ||
49 | a = new QAction( QWidget::tr( "Cancel" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 49 | a = new QAction( QWidget::tr( "Cancel" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
50 | connect( a, SIGNAL( activated() ), this, SLOT( slotCancel() ) ); | 50 | connect( a, SIGNAL( activated() ), this, SLOT( slotCancel() ) ); |
51 | a->addTo( this ); | 51 | a->addTo( this ); |
52 | a->setWhatsThis( QWidget::tr( "Click here to reset new task information.\n\nThis area is called the quick task bar.\n\nIt allows you to quickly add a new task to your list. This area can be shown or hidden by selecting Options->'Show quick task bar' from the menu above." ) ); | 52 | a->setWhatsThis( QWidget::tr( "Click here to reset new task information.\n\nThis area is called the quick task bar.\n\nIt allows you to quickly add a new task to your list. This area can be shown or hidden by selecting Options->'Show quick task bar' from the menu above." ) ); |
53 | 53 | ||
54 | m_visible = visible; | 54 | m_visible = visible; |
55 | if ( !m_visible ) { | 55 | if ( !m_visible ) { |
56 | hide(); | 56 | hide(); |
57 | } | 57 | } |
58 | 58 | ||
59 | m_menu = 0l; | 59 | m_menu = 0l; |
60 | reinit(); | 60 | reinit(); |
61 | } | 61 | } |
62 | QuickEditImpl::~QuickEditImpl() { | 62 | QuickEditImpl::~QuickEditImpl() { |
63 | 63 | ||
64 | } | 64 | } |
65 | OTodo QuickEditImpl::todo()const { | 65 | OTodo QuickEditImpl::todo()const { |
66 | return m_todo; | 66 | return m_todo; |
67 | } | 67 | } |
68 | QWidget* QuickEditImpl::widget() { | 68 | QWidget* QuickEditImpl::widget() { |
69 | return this; | 69 | return this; |
70 | } | 70 | } |
71 | void QuickEditImpl::slotEnter() { | 71 | void QuickEditImpl::slotEnter() { |
72 | OTodo todo; | 72 | OTodo todo; |
73 | 73 | ||
74 | 74 | ||
75 | if (!m_edit->text().isEmpty() ) { | 75 | if (!m_edit->text().isEmpty() ) { |
76 | todo.setUid(1 ); // new uid | 76 | todo.setUid(1 ); // new uid |
77 | todo.setPriority( m_state ); | 77 | todo.setPriority( m_state ); |
78 | todo.setSummary( m_edit->text() ); | 78 | todo.setSummary( m_edit->text() ); |
79 | if ( ((Todo::MainWindow *)parent())->currentCatId() != 0 ) | 79 | if ( ((Todo::MainWindow *)parent())->currentCatId() != 0 ) |
80 | todo.setCategories( ((Todo::MainWindow *)parent())->currentCatId() ); | 80 | todo.setCategories( ((Todo::MainWindow *)parent())->currentCatId() ); |
81 | 81 | ||
82 | m_todo = todo; | 82 | m_todo = todo; |
83 | commit(); | 83 | commit(); |
84 | } | 84 | } |
85 | m_todo = todo; | 85 | m_todo = todo; |
86 | reinit(); | 86 | reinit(); |
87 | } | 87 | } |
88 | void QuickEditImpl::slotPrio() { | 88 | void QuickEditImpl::slotPrio() { |
89 | m_state -= 2; | 89 | m_state -= 2; |
90 | if ( m_state < 1 ) | 90 | if ( m_state < 1 ) |
91 | m_state = 5; | 91 | m_state = 5; |
92 | 92 | ||
93 | switch( m_state ) { | 93 | switch( m_state ) { |
94 | case 1: | 94 | case 1: |
95 | m_lbl->setPixmap( priority1 ); | 95 | m_lbl->setPixmap( priority1 ); |
96 | break; | 96 | break; |
97 | case 5: | 97 | case 5: |
98 | m_lbl->setPixmap( priority5 ); | 98 | m_lbl->setPixmap( priority5 ); |
99 | break; | 99 | break; |
100 | case 3: | 100 | case 3: |
101 | default: | 101 | default: |
102 | m_lbl->setPixmap( priority3 ); | 102 | m_lbl->setPixmap( priority3 ); |
103 | break; | 103 | break; |
104 | } | 104 | } |
105 | } | 105 | } |
106 | void QuickEditImpl::slotMore() { | 106 | void QuickEditImpl::slotMore() { |
107 | // TODO - implement | 107 | // TODO - implement |
108 | } | 108 | } |
109 | void QuickEditImpl::slotCancel() { | 109 | void QuickEditImpl::slotCancel() { |
110 | reinit(); | 110 | reinit(); |
111 | } | 111 | } |
112 | void QuickEditImpl::reinit() { | 112 | void QuickEditImpl::reinit() { |
113 | m_state = 3; | 113 | m_state = 3; |
114 | m_lbl->setPixmap( priority3 ); | 114 | m_lbl->setPixmap( priority3 ); |
115 | m_edit->clear(); | 115 | m_edit->clear(); |
116 | } | 116 | } |
diff --git a/core/pim/todo/quickeditimpl.h b/core/pim/todo/quickeditimpl.h index 1253f3d..89b94f8 100644 --- a/core/pim/todo/quickeditimpl.h +++ b/core/pim/todo/quickeditimpl.h | |||
@@ -1,41 +1,41 @@ | |||
1 | #ifndef OPIE_QUICK_EDIT_IMPL_H | 1 | #ifndef OPIE_QUICK_EDIT_IMPL_H |
2 | #define OPIE_QUICK_EDIT_IMPL_H | 2 | #define OPIE_QUICK_EDIT_IMPL_H |
3 | 3 | ||
4 | #include <qpixmap.h> | 4 | #include <qpixmap.h> |
5 | 5 | ||
6 | #include <qpe/qpetoolbar.h> | 6 | #include <qtoolbar.h> |
7 | 7 | ||
8 | #include "quickedit.h" | 8 | #include "quickedit.h" |
9 | 9 | ||
10 | class QLineEdit; | 10 | class QLineEdit; |
11 | class QLabel; | 11 | class QLabel; |
12 | 12 | ||
13 | class QuickEditImpl : public QPEToolBar, public Todo::QuickEdit { | 13 | class QuickEditImpl : public QToolBar, public Todo::QuickEdit { |
14 | Q_OBJECT | 14 | Q_OBJECT |
15 | public: | 15 | public: |
16 | QuickEditImpl( QWidget* parent, bool visible); | 16 | QuickEditImpl( QWidget* parent, bool visible); |
17 | ~QuickEditImpl(); | 17 | ~QuickEditImpl(); |
18 | OTodo todo()const; | 18 | OTodo todo()const; |
19 | QWidget* widget(); | 19 | QWidget* widget(); |
20 | private slots: | 20 | private slots: |
21 | void slotEnter(); | 21 | void slotEnter(); |
22 | void slotPrio(); | 22 | void slotPrio(); |
23 | void slotMore(); | 23 | void slotMore(); |
24 | void slotCancel(); | 24 | void slotCancel(); |
25 | private: | 25 | private: |
26 | void reinit(); | 26 | void reinit(); |
27 | int m_state; | 27 | int m_state; |
28 | QLabel* m_lbl; | 28 | QLabel* m_lbl; |
29 | QLineEdit* m_edit; | 29 | QLineEdit* m_edit; |
30 | QLabel* m_enter; | 30 | QLabel* m_enter; |
31 | QLabel* m_more; | 31 | QLabel* m_more; |
32 | QPopupMenu* m_menu; | 32 | QPopupMenu* m_menu; |
33 | OTodo m_todo; | 33 | OTodo m_todo; |
34 | bool m_visible; | 34 | bool m_visible; |
35 | 35 | ||
36 | QPixmap priority1; | 36 | QPixmap priority1; |
37 | QPixmap priority3; | 37 | QPixmap priority3; |
38 | QPixmap priority5; | 38 | QPixmap priority5; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | #endif | 41 | #endif |
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp index 25f9910..9fc2125 100644 --- a/noncore/apps/checkbook/mainwindow.cpp +++ b/noncore/apps/checkbook/mainwindow.cpp | |||
@@ -1,365 +1,365 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | 4 | .=l. Copyright (c) 2002 Dan Williams <drw@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 "mainwindow.h" | 29 | #include "mainwindow.h" |
30 | #include "cbinfo.h" | 30 | #include "cbinfo.h" |
31 | #include "configuration.h" | 31 | #include "configuration.h" |
32 | #include "password.h" | 32 | #include "password.h" |
33 | #include "checkbook.h" | 33 | #include "checkbook.h" |
34 | #include "listedit.h" | 34 | #include "listedit.h" |
35 | 35 | ||
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | #include <qpe/global.h> | 37 | #include <qpe/global.h> |
38 | #include <qpe/qpeapplication.h> | 38 | #include <qpe/qpeapplication.h> |
39 | #include <qpe/qpemenubar.h> | 39 | #include <qmenubar.h> |
40 | #include <qpe/qpemessagebox.h> | 40 | #include <qpe/qpemessagebox.h> |
41 | #include <qpe/qpetoolbar.h> | 41 | #include <qpe/qpetoolbar.h> |
42 | #include <qpe/resource.h> | 42 | #include <qpe/resource.h> |
43 | 43 | ||
44 | #include <qaction.h> | 44 | #include <qaction.h> |
45 | #include <qcheckbox.h> | 45 | #include <qcheckbox.h> |
46 | #include <qdir.h> | 46 | #include <qdir.h> |
47 | #include <qlineedit.h> | 47 | #include <qlineedit.h> |
48 | #include <qwhatsthis.h> | 48 | #include <qwhatsthis.h> |
49 | 49 | ||
50 | 50 | ||
51 | MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) | 51 | MainWindow::MainWindow( QWidget* parent, const char* name, WFlags fl ) |
52 | : QMainWindow( parent, name, fl || WStyle_ContextHelp ) | 52 | : QMainWindow( parent, name, fl || WStyle_ContextHelp ) |
53 | { | 53 | { |
54 | setCaption( tr( "Checkbook" ) ); | 54 | setCaption( tr( "Checkbook" ) ); |
55 | 55 | ||
56 | cbDir = Global::applicationFileName( "checkbook", "" ); | 56 | cbDir = Global::applicationFileName( "checkbook", "" ); |
57 | lockIcon = Resource::loadPixmap( "locked" ); | 57 | lockIcon = Resource::loadPixmap( "locked" ); |
58 | 58 | ||
59 | // Load configuration options | 59 | // Load configuration options |
60 | Config config( "checkbook" ); | 60 | Config config( "checkbook" ); |
61 | _cfg.readConfig( config ); | 61 | _cfg.readConfig( config ); |
62 | 62 | ||
63 | 63 | ||
64 | // Build menu and tool bars | 64 | // Build menu and tool bars |
65 | setToolBarsMovable( FALSE ); | 65 | setToolBarsMovable( FALSE ); |
66 | 66 | ||
67 | QPEToolBar *bar = new QPEToolBar( this ); | 67 | QToolBar *bar = new QToolBar( this ); |
68 | bar->setHorizontalStretchable( TRUE ); | 68 | bar->setHorizontalStretchable( TRUE ); |
69 | QMenuBar *mb = new QMenuBar( bar ); | 69 | QMenuBar *mb = new QMenuBar( bar ); |
70 | mb->setMargin( 0 ); | 70 | mb->setMargin( 0 ); |
71 | QPopupMenu *popup = new QPopupMenu( this ); | 71 | QPopupMenu *popup = new QPopupMenu( this ); |
72 | 72 | ||
73 | bar = new QPEToolBar( this ); | 73 | bar = new QToolBar( this ); |
74 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 74 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
75 | a->setWhatsThis( tr( "Click here to create a new checkbook.\n\nYou also can select New from the Checkbook menu." ) ); | 75 | a->setWhatsThis( tr( "Click here to create a new checkbook.\n\nYou also can select New from the Checkbook menu." ) ); |
76 | connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) ); | 76 | connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) ); |
77 | a->addTo( popup ); | 77 | a->addTo( popup ); |
78 | a->addTo( bar ); | 78 | a->addTo( bar ); |
79 | 79 | ||
80 | actionOpen = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, | 80 | actionOpen = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, |
81 | 0, this, 0 ); | 81 | 0, this, 0 ); |
82 | actionOpen->setWhatsThis( tr( "Select a checkbook and then click here to edit it.\n\nYou also can select Edit from the Checkbook menu, or click and hold on a checkbook name." ) ); | 82 | actionOpen->setWhatsThis( tr( "Select a checkbook and then click here to edit it.\n\nYou also can select Edit from the Checkbook menu, or click and hold on a checkbook name." ) ); |
83 | connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotEdit() ) ); | 83 | connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotEdit() ) ); |
84 | actionOpen->addTo( popup ); | 84 | actionOpen->addTo( popup ); |
85 | actionOpen->addTo( bar ); | 85 | actionOpen->addTo( bar ); |
86 | 86 | ||
87 | actionDelete = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, | 87 | actionDelete = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, |
88 | 0, this, 0 ); | 88 | 0, this, 0 ); |
89 | actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) ); | 89 | actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) ); |
90 | connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) ); | 90 | connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) ); |
91 | actionDelete->addTo( popup ); | 91 | actionDelete->addTo( popup ); |
92 | actionDelete->addTo( bar ); | 92 | actionDelete->addTo( bar ); |
93 | 93 | ||
94 | popup->insertSeparator(); | 94 | popup->insertSeparator(); |
95 | 95 | ||
96 | a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 ); | 96 | a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 ); |
97 | a->setWhatsThis( tr( "Click here to configure this app." ) ); | 97 | a->setWhatsThis( tr( "Click here to configure this app." ) ); |
98 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); | 98 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); |
99 | a->addTo( popup ); | 99 | a->addTo( popup ); |
100 | a->addTo( bar ); | 100 | a->addTo( bar ); |
101 | 101 | ||
102 | mb->insertItem( tr( "Checkbook" ), popup ); | 102 | mb->insertItem( tr( "Checkbook" ), popup ); |
103 | 103 | ||
104 | // Load Checkbook selection list | 104 | // Load Checkbook selection list |
105 | checkbooks = new CBInfoList(); | 105 | checkbooks = new CBInfoList(); |
106 | 106 | ||
107 | QDir checkdir( cbDir ); | 107 | QDir checkdir( cbDir ); |
108 | if (checkdir.exists() == true) | 108 | if (checkdir.exists() == true) |
109 | { | 109 | { |
110 | QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable, | 110 | QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable, |
111 | QDir::Time ); | 111 | QDir::Time ); |
112 | CBInfo *cb = 0x0; | 112 | CBInfo *cb = 0x0; |
113 | QString filename; | 113 | QString filename; |
114 | 114 | ||
115 | for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ ) | 115 | for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ ) |
116 | { | 116 | { |
117 | filename = cbDir; | 117 | filename = cbDir; |
118 | filename.append( (*it) ); | 118 | filename.append( (*it) ); |
119 | 119 | ||
120 | cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename ); | 120 | cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename ); |
121 | checkbooks->inSort( cb ); | 121 | checkbooks->inSort( cb ); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
125 | // Build Checkbook selection list control | 125 | // Build Checkbook selection list control |
126 | cbList = 0x0; | 126 | cbList = 0x0; |
127 | buildList(); | 127 | buildList(); |
128 | 128 | ||
129 | // open last book? | 129 | // open last book? |
130 | if( _cfg.isOpenLastBook() ) { | 130 | if( _cfg.isOpenLastBook() ) { |
131 | this->show(); | 131 | this->show(); |
132 | this->showMaximized(); | 132 | this->showMaximized(); |
133 | QListViewItem *itm=cbList->firstChild(); | 133 | QListViewItem *itm=cbList->firstChild(); |
134 | while( itm ) { | 134 | while( itm ) { |
135 | if( itm->text(posName)==_cfg.getLastBook() ) { | 135 | if( itm->text(posName)==_cfg.getLastBook() ) { |
136 | openBook( itm ); | 136 | openBook( itm ); |
137 | break; | 137 | break; |
138 | } | 138 | } |
139 | itm=itm->nextSibling(); | 139 | itm=itm->nextSibling(); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | 144 | ||
145 | // --- ~MainWindow ------------------------------------------------------------ | 145 | // --- ~MainWindow ------------------------------------------------------------ |
146 | MainWindow::~MainWindow() | 146 | MainWindow::~MainWindow() |
147 | { | 147 | { |
148 | writeConfig(); | 148 | writeConfig(); |
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | // --- buildList -------------------------------------------------------------- | 152 | // --- buildList -------------------------------------------------------------- |
153 | void MainWindow::buildList() | 153 | void MainWindow::buildList() |
154 | { | 154 | { |
155 | if ( cbList ) | 155 | if ( cbList ) |
156 | delete cbList; | 156 | delete cbList; |
157 | 157 | ||
158 | cbList = new QListView( this ); | 158 | cbList = new QListView( this ); |
159 | QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); | 159 | QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); |
160 | 160 | ||
161 | if ( _cfg.getShowLocks() ) | 161 | if ( _cfg.getShowLocks() ) |
162 | { | 162 | { |
163 | cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 ); | 163 | cbList->addColumn( Resource::loadIconSet( "locked" ), "", 24 ); |
164 | posName = 1; | 164 | posName = 1; |
165 | } | 165 | } |
166 | else | 166 | else |
167 | { | 167 | { |
168 | posName = 0; | 168 | posName = 0; |
169 | } | 169 | } |
170 | cbList->addColumn( tr( "Checkbook Name" ) ); | 170 | cbList->addColumn( tr( "Checkbook Name" ) ); |
171 | if ( _cfg.getShowBalances() ) | 171 | if ( _cfg.getShowBalances() ) |
172 | { | 172 | { |
173 | int colnum = cbList->addColumn( tr( "Balance" ) ); | 173 | int colnum = cbList->addColumn( tr( "Balance" ) ); |
174 | cbList->setColumnAlignment( colnum, Qt::AlignRight ); | 174 | cbList->setColumnAlignment( colnum, Qt::AlignRight ); |
175 | } | 175 | } |
176 | cbList->setAllColumnsShowFocus( TRUE ); | 176 | cbList->setAllColumnsShowFocus( TRUE ); |
177 | cbList->setSorting( posName ); | 177 | cbList->setSorting( posName ); |
178 | QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); | 178 | QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); |
179 | connect( cbList, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), | 179 | connect( cbList, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), |
180 | this, SLOT( slotEdit() ) ); | 180 | this, SLOT( slotEdit() ) ); |
181 | setCentralWidget( cbList ); | 181 | setCentralWidget( cbList ); |
182 | 182 | ||
183 | for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() ) | 183 | for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() ) |
184 | { | 184 | { |
185 | addCheckbook( cb ); | 185 | addCheckbook( cb ); |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | void MainWindow::addCheckbook( CBInfo *cb ) | 189 | void MainWindow::addCheckbook( CBInfo *cb ) |
190 | { | 190 | { |
191 | QListViewItem *lvi = new QListViewItem( cbList ); | 191 | QListViewItem *lvi = new QListViewItem( cbList ); |
192 | if ( _cfg.getShowLocks() && !cb->password().isNull() ) | 192 | if ( _cfg.getShowLocks() && !cb->password().isNull() ) |
193 | { | 193 | { |
194 | lvi->setPixmap( 0, lockIcon ); | 194 | lvi->setPixmap( 0, lockIcon ); |
195 | } | 195 | } |
196 | lvi->setText( posName, cb->name() ); | 196 | lvi->setText( posName, cb->name() ); |
197 | if ( _cfg.getShowBalances() ) | 197 | if ( _cfg.getShowBalances() ) |
198 | { | 198 | { |
199 | QString balance; | 199 | QString balance; |
200 | balance.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); | 200 | balance.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); |
201 | lvi->setText( posName + 1, balance ); | 201 | lvi->setText( posName + 1, balance ); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | void MainWindow::buildFilename( const QString &name ) | 205 | void MainWindow::buildFilename( const QString &name ) |
206 | { | 206 | { |
207 | tempFilename = cbDir; | 207 | tempFilename = cbDir; |
208 | tempFilename.append( name ); | 208 | tempFilename.append( name ); |
209 | tempFilename.append( ".qcb" ); | 209 | tempFilename.append( ".qcb" ); |
210 | } | 210 | } |
211 | 211 | ||
212 | void MainWindow::slotNew() | 212 | void MainWindow::slotNew() |
213 | { | 213 | { |
214 | CBInfo *cb = new CBInfo(); | 214 | CBInfo *cb = new CBInfo(); |
215 | 215 | ||
216 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); | 216 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); |
217 | currcb->showMaximized(); | 217 | currcb->showMaximized(); |
218 | if ( currcb->exec() == QDialog::Accepted ) | 218 | if ( currcb->exec() == QDialog::Accepted ) |
219 | { | 219 | { |
220 | // Save new checkbook | 220 | // Save new checkbook |
221 | buildFilename( cb->name() ); | 221 | buildFilename( cb->name() ); |
222 | _cfg.setLastBook( cb->name() ); | 222 | _cfg.setLastBook( cb->name() ); |
223 | cb->setFilename( tempFilename ); | 223 | cb->setFilename( tempFilename ); |
224 | cb->write(); | 224 | cb->write(); |
225 | 225 | ||
226 | // Add to listbox | 226 | // Add to listbox |
227 | checkbooks->inSort( cb ); | 227 | checkbooks->inSort( cb ); |
228 | addCheckbook( cb ); | 228 | addCheckbook( cb ); |
229 | } | 229 | } |
230 | delete currcb; | 230 | delete currcb; |
231 | } | 231 | } |
232 | 232 | ||
233 | // --- slotEdit --------------------------------------------------------------- | 233 | // --- slotEdit --------------------------------------------------------------- |
234 | void MainWindow::slotEdit() | 234 | void MainWindow::slotEdit() |
235 | { | 235 | { |
236 | // get name and open it | 236 | // get name and open it |
237 | QListViewItem *curritem = cbList->currentItem(); | 237 | QListViewItem *curritem = cbList->currentItem(); |
238 | if ( !curritem ) | 238 | if ( !curritem ) |
239 | return; | 239 | return; |
240 | openBook( curritem ); | 240 | openBook( curritem ); |
241 | } | 241 | } |
242 | 242 | ||
243 | 243 | ||
244 | // --- openBook --------------------------------------------------------------- | 244 | // --- openBook --------------------------------------------------------------- |
245 | void MainWindow::openBook(QListViewItem *curritem) | 245 | void MainWindow::openBook(QListViewItem *curritem) |
246 | { | 246 | { |
247 | // find book in List | 247 | // find book in List |
248 | QString currname=curritem->text(posName); | 248 | QString currname=curritem->text(posName); |
249 | CBInfo *cb = checkbooks->first(); | 249 | CBInfo *cb = checkbooks->first(); |
250 | while ( cb ) { | 250 | while ( cb ) { |
251 | if ( cb->name() == currname ) | 251 | if ( cb->name() == currname ) |
252 | break; | 252 | break; |
253 | cb = checkbooks->next(); | 253 | cb = checkbooks->next(); |
254 | } | 254 | } |
255 | if ( !cb ) return; | 255 | if ( !cb ) return; |
256 | 256 | ||
257 | // | 257 | // |
258 | buildFilename( currname ); | 258 | buildFilename( currname ); |
259 | float currbalance = cb->balance(); | 259 | float currbalance = cb->balance(); |
260 | bool currlock = !cb->password().isNull(); | 260 | bool currlock = !cb->password().isNull(); |
261 | 261 | ||
262 | if ( currlock ) | 262 | if ( currlock ) |
263 | { | 263 | { |
264 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); | 264 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); |
265 | if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) | 265 | if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) |
266 | { | 266 | { |
267 | delete pw; | 267 | delete pw; |
268 | return; | 268 | return; |
269 | } | 269 | } |
270 | delete pw; | 270 | delete pw; |
271 | } | 271 | } |
272 | 272 | ||
273 | _cfg.setLastBook( currname ); | 273 | _cfg.setLastBook( currname ); |
274 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); | 274 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); |
275 | currcb->showMaximized(); | 275 | currcb->showMaximized(); |
276 | if ( currcb->exec() == QDialog::Accepted ) | 276 | if ( currcb->exec() == QDialog::Accepted ) |
277 | { | 277 | { |
278 | QString newname = cb->name(); | 278 | QString newname = cb->name(); |
279 | if ( currname != newname ) | 279 | if ( currname != newname ) |
280 | { | 280 | { |
281 | // Update name if changed | 281 | // Update name if changed |
282 | if( curritem ) { | 282 | if( curritem ) { |
283 | curritem->setText( posName, newname ); | 283 | curritem->setText( posName, newname ); |
284 | cbList->sort(); | 284 | cbList->sort(); |
285 | } | 285 | } |
286 | _cfg.setLastBook( newname ); | 286 | _cfg.setLastBook( newname ); |
287 | 287 | ||
288 | // Remove old file | 288 | // Remove old file |
289 | QFile f( tempFilename ); | 289 | QFile f( tempFilename ); |
290 | if ( f.exists() ) | 290 | if ( f.exists() ) |
291 | f.remove(); | 291 | f.remove(); |
292 | 292 | ||
293 | // Get new filename | 293 | // Get new filename |
294 | buildFilename( newname ); | 294 | buildFilename( newname ); |
295 | cb->setFilename( tempFilename ); | 295 | cb->setFilename( tempFilename ); |
296 | } | 296 | } |
297 | 297 | ||
298 | cb->write(); | 298 | cb->write(); |
299 | 299 | ||
300 | // Update lock if changed | 300 | // Update lock if changed |
301 | if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) | 301 | if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) |
302 | { | 302 | { |
303 | if ( !cb->password().isNull() ) | 303 | if ( !cb->password().isNull() ) |
304 | curritem->setPixmap( 0, lockIcon ); | 304 | curritem->setPixmap( 0, lockIcon ); |
305 | else | 305 | else |
306 | curritem->setPixmap( 0, nullIcon ); | 306 | curritem->setPixmap( 0, nullIcon ); |
307 | } | 307 | } |
308 | 308 | ||
309 | // Update balance if changed | 309 | // Update balance if changed |
310 | if ( _cfg.getShowBalances() && cb->balance() != currbalance ) | 310 | if ( _cfg.getShowBalances() && cb->balance() != currbalance ) |
311 | { | 311 | { |
312 | QString tempstr; | 312 | QString tempstr; |
313 | tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); | 313 | tempstr.sprintf( "%s%.2f", _cfg.getCurrencySymbol().latin1(), cb->balance() ); |
314 | curritem->setText( posName + 1, tempstr ); | 314 | curritem->setText( posName + 1, tempstr ); |
315 | } | 315 | } |
316 | 316 | ||
317 | // write config, if needed | 317 | // write config, if needed |
318 | if( _cfg.isDirty() ) { | 318 | if( _cfg.isDirty() ) { |
319 | Config config("checkbook"); | 319 | Config config("checkbook"); |
320 | _cfg.writeConfig( config ); | 320 | _cfg.writeConfig( config ); |
321 | } | 321 | } |
322 | } | 322 | } |
323 | delete currcb; | 323 | delete currcb; |
324 | } | 324 | } |
325 | 325 | ||
326 | // --- slotDelete ------------------------------------------------------------- | 326 | // --- slotDelete ------------------------------------------------------------- |
327 | void MainWindow::slotDelete() | 327 | void MainWindow::slotDelete() |
328 | { | 328 | { |
329 | QString currname = cbList->currentItem()->text( posName ); | 329 | QString currname = cbList->currentItem()->text( posName ); |
330 | 330 | ||
331 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) | 331 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) |
332 | { | 332 | { |
333 | buildFilename( currname ); | 333 | buildFilename( currname ); |
334 | QFile f( tempFilename ); | 334 | QFile f( tempFilename ); |
335 | if ( f.exists() ) | 335 | if ( f.exists() ) |
336 | { | 336 | { |
337 | f.remove(); | 337 | f.remove(); |
338 | } | 338 | } |
339 | 339 | ||
340 | delete cbList->currentItem(); | 340 | delete cbList->currentItem(); |
341 | } | 341 | } |
342 | } | 342 | } |
343 | 343 | ||
344 | // --- slotConfigure ---------------------------------------------------------- | 344 | // --- slotConfigure ---------------------------------------------------------- |
345 | void MainWindow::slotConfigure() | 345 | void MainWindow::slotConfigure() |
346 | { | 346 | { |
347 | Configuration *cfgdlg = new Configuration( this, _cfg ); | 347 | Configuration *cfgdlg = new Configuration( this, _cfg ); |
348 | cfgdlg->showMaximized(); | 348 | cfgdlg->showMaximized(); |
349 | if ( cfgdlg->exec() == QDialog::Accepted ) | 349 | if ( cfgdlg->exec() == QDialog::Accepted ) |
350 | { | 350 | { |
351 | // read data from config dialog & save it | 351 | // read data from config dialog & save it |
352 | cfgdlg->saveConfig( _cfg ); | 352 | cfgdlg->saveConfig( _cfg ); |
353 | writeConfig(); | 353 | writeConfig(); |
354 | buildList(); | 354 | buildList(); |
355 | } | 355 | } |
356 | delete cfgdlg; | 356 | delete cfgdlg; |
357 | } | 357 | } |
358 | 358 | ||
359 | 359 | ||
360 | // --- writeConfig -------------------------------------------------------------- | 360 | // --- writeConfig -------------------------------------------------------------- |
361 | void MainWindow::writeConfig() | 361 | void MainWindow::writeConfig() |
362 | { | 362 | { |
363 | Config config("checkbook"); | 363 | Config config("checkbook"); |
364 | _cfg.writeConfig( config ); | 364 | _cfg.writeConfig( config ); |
365 | } | 365 | } |
diff --git a/noncore/apps/confedit/mainwindow.h b/noncore/apps/confedit/mainwindow.h index 96331db..23aca52 100644 --- a/noncore/apps/confedit/mainwindow.h +++ b/noncore/apps/confedit/mainwindow.h | |||
@@ -1,68 +1,68 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | 10 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> |
11 | 11 | ||
12 | #ifndef MAINWINDOW_H | 12 | #ifndef MAINWINDOW_H |
13 | #define MAINWINDOW_H | 13 | #define MAINWINDOW_H |
14 | 14 | ||
15 | #include <qmainwindow.h> | 15 | #include <qmainwindow.h> |
16 | #include <qdialog.h> | 16 | #include <qdialog.h> |
17 | #include <qaction.h> | 17 | #include <qaction.h> |
18 | #include <qtimer.h> | 18 | #include <qtimer.h> |
19 | #include <qpopupmenu.h> | 19 | #include <qpopupmenu.h> |
20 | #include "editwidget.h" | 20 | #include "editwidget.h" |
21 | 21 | ||
22 | class QPEToolBar; | 22 | class QToolBar; |
23 | class ListViewItemConfFile; | 23 | class ListViewItemConfFile; |
24 | class ListViewConfDir; | 24 | class ListViewConfDir; |
25 | class ListViewItemConf; | 25 | class ListViewItemConf; |
26 | 26 | ||
27 | class MainWindow : public QMainWindow | 27 | class MainWindow : public QMainWindow |
28 | { | 28 | { |
29 | Q_OBJECT | 29 | Q_OBJECT |
30 | 30 | ||
31 | 31 | ||
32 | public: | 32 | public: |
33 | MainWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 33 | MainWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
34 | ~MainWindow(); | 34 | ~MainWindow(); |
35 | static QString appName() { return QString::fromLatin1("confedit"); } | 35 | static QString appName() { return QString::fromLatin1("confedit"); } |
36 | 36 | ||
37 | public slots: | 37 | public slots: |
38 | void setCurrent(QListViewItem*); | 38 | void setCurrent(QListViewItem*); |
39 | void groupChanged(const QString&); | 39 | void groupChanged(const QString&); |
40 | void keyChanged(const QString&); | 40 | void keyChanged(const QString&); |
41 | void valueChanged(const QString&); | 41 | void valueChanged(const QString&); |
42 | void showPopup(); | 42 | void showPopup(); |
43 | void stopTimer( QListViewItem* ); | 43 | void stopTimer( QListViewItem* ); |
44 | void saveConfFile(); | 44 | void saveConfFile(); |
45 | void revertConfFile(); | 45 | void revertConfFile(); |
46 | void removeConfFile(); | 46 | void removeConfFile(); |
47 | 47 | ||
48 | private: | 48 | private: |
49 | ListViewConfDir *settingList; | 49 | ListViewConfDir *settingList; |
50 | EditWidget *editor; | 50 | EditWidget *editor; |
51 | QVBoxLayout *mainLayout; | 51 | QVBoxLayout *mainLayout; |
52 | ListViewItemConf *_item; | 52 | ListViewItemConf *_item; |
53 | ListViewItemConfigEntry *_currentItem; | 53 | ListViewItemConfigEntry *_currentItem; |
54 | ListViewItemConfFile *_fileItem; | 54 | ListViewItemConfFile *_fileItem; |
55 | QTimer *popupTimer; | 55 | QTimer *popupTimer; |
56 | QPopupMenu *popupMenuFile; | 56 | QPopupMenu *popupMenuFile; |
57 | QPopupMenu *popupMenuEntry; | 57 | QPopupMenu *popupMenuEntry; |
58 | QAction *popupActionSave; | 58 | QAction *popupActionSave; |
59 | QAction *popupActionRevert; | 59 | QAction *popupActionRevert; |
60 | QAction *popupActionDelete; | 60 | QAction *popupActionDelete; |
61 | QAction *popupActionNew; | 61 | QAction *popupActionNew; |
62 | //QAction *popupAction; | 62 | //QAction *popupAction; |
63 | //QAction *popupAction; | 63 | //QAction *popupAction; |
64 | 64 | ||
65 | void makeMenu(); | 65 | void makeMenu(); |
66 | }; | 66 | }; |
67 | 67 | ||
68 | #endif | 68 | #endif |
diff --git a/noncore/apps/opie-bartender/bartender.cpp b/noncore/apps/opie-bartender/bartender.cpp index 3a0d8d1..8c4ee93 100644 --- a/noncore/apps/opie-bartender/bartender.cpp +++ b/noncore/apps/opie-bartender/bartender.cpp | |||
@@ -1,447 +1,447 @@ | |||
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 "newdrinks.h" | 14 | #include "newdrinks.h" |
15 | #include "showdrinks.h" | 15 | #include "showdrinks.h" |
16 | #include "inputDialog.h" | 16 | #include "inputDialog.h" |
17 | #include "searchresults.h" | 17 | #include "searchresults.h" |
18 | #include "bac.h" | 18 | #include "bac.h" |
19 | 19 | ||
20 | #include <qpe/qpetoolbar.h> | 20 | #include <qpe/qpetoolbar.h> |
21 | #include <qpe/qpemenubar.h> | 21 | #include <qmenubar.h> |
22 | #include <opie/colorpopupmenu.h> | 22 | #include <opie/colorpopupmenu.h> |
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | #include <qcstring.h> | 26 | #include <qcstring.h> |
27 | #include <qlineedit.h> | 27 | #include <qlineedit.h> |
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include <qpushbutton.h> | 29 | #include <qpushbutton.h> |
30 | #include <qlistbox.h> | 30 | #include <qlistbox.h> |
31 | #include <qstringlist.h> | 31 | #include <qstringlist.h> |
32 | #include <qmultilineedit.h> | 32 | #include <qmultilineedit.h> |
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qfile.h> | 36 | #include <qfile.h> |
37 | #include <qaction.h> | 37 | #include <qaction.h> |
38 | #include <qheader.h> | 38 | #include <qheader.h> |
39 | #include <qlistview.h> | 39 | #include <qlistview.h> |
40 | #include <qwidget.h> | 40 | #include <qwidget.h> |
41 | #include <qlayout.h> | 41 | #include <qlayout.h> |
42 | #include <qvariant.h> | 42 | #include <qvariant.h> |
43 | #include <qtooltip.h> | 43 | #include <qtooltip.h> |
44 | #include <qwhatsthis.h> | 44 | #include <qwhatsthis.h> |
45 | #include <qimage.h> | 45 | #include <qimage.h> |
46 | #include <qpixmap.h> | 46 | #include <qpixmap.h> |
47 | 47 | ||
48 | #include <fcntl.h> | 48 | #include <fcntl.h> |
49 | #include <unistd.h> | 49 | #include <unistd.h> |
50 | #include <stdlib.h> | 50 | #include <stdlib.h> |
51 | #include <stdio.h> | 51 | #include <stdio.h> |
52 | #include <errno.h> | 52 | #include <errno.h> |
53 | 53 | ||
54 | 54 | ||
55 | Bartender::Bartender( QWidget* parent, const char* name, WFlags fl ) | 55 | Bartender::Bartender( QWidget* parent, const char* name, WFlags fl ) |
56 | : QMainWindow( parent, name, fl ) { | 56 | : QMainWindow( parent, name, fl ) { |
57 | if ( !name ) | 57 | if ( !name ) |
58 | setName( "Bartender" ); | 58 | setName( "Bartender" ); |
59 | QGridLayout *layout = new QGridLayout( this ); | 59 | QGridLayout *layout = new QGridLayout( this ); |
60 | layout->setSpacing( 2); | 60 | layout->setSpacing( 2); |
61 | layout->setMargin( 2); | 61 | layout->setMargin( 2); |
62 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 62 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
63 | 63 | ||
64 | setCaption( tr( "Bartender" ) ); | 64 | setCaption( tr( "Bartender" ) ); |
65 | 65 | ||
66 | ToolBar1 = new QPEToolBar( this, "ToolBar1" ); | 66 | ToolBar1 = new QToolBar( this, "ToolBar1" ); |
67 | ToolBar1->setFixedHeight(22); | 67 | ToolBar1->setFixedHeight(22); |
68 | layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 ); | 68 | layout->addMultiCellWidget( ToolBar1, 0, 0, 0, 4 ); |
69 | 69 | ||
70 | QMenuBar *menuBar = new QMenuBar( ToolBar1 ); | 70 | QMenuBar *menuBar = new QMenuBar( ToolBar1 ); |
71 | QPopupMenu *fileMenu; | 71 | QPopupMenu *fileMenu; |
72 | fileMenu = new QPopupMenu( this); | 72 | fileMenu = new QPopupMenu( this); |
73 | menuBar->insertItem( tr("File"), fileMenu ); | 73 | menuBar->insertItem( tr("File"), fileMenu ); |
74 | 74 | ||
75 | fileMenu->insertItem(tr("New Drink")); | 75 | fileMenu->insertItem(tr("New Drink")); |
76 | fileMenu->insertItem(tr("Open Drink")); | 76 | fileMenu->insertItem(tr("Open Drink")); |
77 | fileMenu->insertItem(tr("Find by Drink Name")); | 77 | fileMenu->insertItem(tr("Find by Drink Name")); |
78 | fileMenu->insertItem(tr("Find by Alcohol")); | 78 | fileMenu->insertItem(tr("Find by Alcohol")); |
79 | 79 | ||
80 | QPopupMenu *editMenu; | 80 | QPopupMenu *editMenu; |
81 | editMenu = new QPopupMenu( this); | 81 | editMenu = new QPopupMenu( this); |
82 | menuBar->insertItem( tr("Edit"), editMenu ); | 82 | menuBar->insertItem( tr("Edit"), editMenu ); |
83 | editMenu->insertItem(tr("edit")); | 83 | editMenu->insertItem(tr("edit")); |
84 | 84 | ||
85 | connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) )); | 85 | connect( fileMenu, SIGNAL( activated(int) ), this, SLOT( fileMenuActivated(int) )); |
86 | connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) )); | 86 | connect( editMenu, SIGNAL( activated(int) ), this, SLOT( editMenuActivated(int) )); |
87 | 87 | ||
88 | 88 | ||
89 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 ); | 89 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), "New", 0, this, 0 ); |
90 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 90 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
91 | a->addTo( ToolBar1 ); | 91 | a->addTo( ToolBar1 ); |
92 | 92 | ||
93 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 ); | 93 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "bartender/bartender_sm" ), "open", 0, this, 0 ); |
94 | connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) ); | 94 | connect( a, SIGNAL( activated() ), this, SLOT( openCurrentDrink() ) ); |
95 | a->addTo( ToolBar1 ); | 95 | a->addTo( ToolBar1 ); |
96 | 96 | ||
97 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 ); | 97 | a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), "Find", 0, this, 0 ); |
98 | connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) ); | 98 | connect( a, SIGNAL( activated() ), this, SLOT( askSearch() ) ); |
99 | a->addTo( ToolBar1 ); | 99 | a->addTo( ToolBar1 ); |
100 | 100 | ||
101 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ),"Edit", 0, this, 0 ); | 101 | a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ),"Edit", 0, this, 0 ); |
102 | connect( a, SIGNAL( activated() ), this, SLOT( doEdit() ) ); | 102 | connect( a, SIGNAL( activated() ), this, SLOT( doEdit() ) ); |
103 | a->addTo( ToolBar1 ); | 103 | a->addTo( ToolBar1 ); |
104 | 104 | ||
105 | QPushButton *t; | 105 | QPushButton *t; |
106 | t= new QPushButton( "BAC", ToolBar1, "bacButtin"); | 106 | t= new QPushButton( "BAC", ToolBar1, "bacButtin"); |
107 | connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) ); | 107 | connect( t, SIGNAL( clicked() ), this, SLOT( doBac() ) ); |
108 | 108 | ||
109 | DrinkView = new QListView( this, "DrinkView" ); | 109 | DrinkView = new QListView( this, "DrinkView" ); |
110 | DrinkView->addColumn( tr( "Name of Drink" ) ); | 110 | DrinkView->addColumn( tr( "Name of Drink" ) ); |
111 | // DrinkView->setRootIsDecorated( TRUE ); | 111 | // DrinkView->setRootIsDecorated( TRUE ); |
112 | DrinkView->header()->hide(); | 112 | DrinkView->header()->hide(); |
113 | 113 | ||
114 | QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold); | 114 | QPEApplication::setStylusOperation( DrinkView->viewport(),QPEApplication::RightOnHold); |
115 | 115 | ||
116 | connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink( QListViewItem*))); | 116 | connect(DrinkView, SIGNAL( doubleClicked(QListViewItem*)),this,SLOT(showDrink( QListViewItem*))); |
117 | connect(DrinkView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 117 | connect(DrinkView, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
118 | this,SLOT( showDrink(int, QListViewItem *, const QPoint&, int))); | 118 | this,SLOT( showDrink(int, QListViewItem *, const QPoint&, int))); |
119 | 119 | ||
120 | layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 ); | 120 | layout->addMultiCellWidget( DrinkView, 1, 2, 0, 4 ); |
121 | if(QDir("db").exists()) { | 121 | if(QDir("db").exists()) { |
122 | dbFile.setName( "db/drinkdb.txt"); | 122 | dbFile.setName( "db/drinkdb.txt"); |
123 | } else | 123 | } else |
124 | dbFile.setName( QPEApplication::qpeDir()+"/etc/bartender/drinkdb.txt"); | 124 | dbFile.setName( QPEApplication::qpeDir()+"/etc/bartender/drinkdb.txt"); |
125 | initDrinkDb(); | 125 | initDrinkDb(); |
126 | } | 126 | } |
127 | 127 | ||
128 | Bartender::~Bartender() { | 128 | Bartender::~Bartender() { |
129 | } | 129 | } |
130 | 130 | ||
131 | /* | 131 | /* |
132 | this happens right before exit */ | 132 | this happens right before exit */ |
133 | void Bartender::cleanUp() { | 133 | void Bartender::cleanUp() { |
134 | dbFile.close(); | 134 | dbFile.close(); |
135 | 135 | ||
136 | } | 136 | } |
137 | 137 | ||
138 | void Bartender::initDrinkDb() { | 138 | void Bartender::initDrinkDb() { |
139 | 139 | ||
140 | if(!dbFile.isOpen()) | 140 | if(!dbFile.isOpen()) |
141 | if ( !dbFile.open( IO_ReadOnly)) { | 141 | if ( !dbFile.open( IO_ReadOnly)) { |
142 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); | 142 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); |
143 | return; | 143 | return; |
144 | } | 144 | } |
145 | fillList(); | 145 | fillList(); |
146 | } | 146 | } |
147 | 147 | ||
148 | void Bartender::fillList() { | 148 | void Bartender::fillList() { |
149 | dbFile.at(1); | 149 | dbFile.at(1); |
150 | DrinkView->clear(); | 150 | DrinkView->clear(); |
151 | int i=0; | 151 | int i=0; |
152 | QListViewItem * item ; | 152 | QListViewItem * item ; |
153 | QTextStream t( &dbFile); | 153 | QTextStream t( &dbFile); |
154 | QString s; | 154 | QString s; |
155 | while ( !t.eof()) { | 155 | while ( !t.eof()) { |
156 | s = t.readLine(); | 156 | s = t.readLine(); |
157 | if(s.find("#",0,TRUE) != -1) { | 157 | if(s.find("#",0,TRUE) != -1) { |
158 | // qDebug(s.right(s.length()-2)); | 158 | // qDebug(s.right(s.length()-2)); |
159 | item= new QListViewItem( DrinkView, 0 ); | 159 | item= new QListViewItem( DrinkView, 0 ); |
160 | item->setText( 0, s.right(s.length()-2)); | 160 | item->setText( 0, s.right(s.length()-2)); |
161 | i++; | 161 | i++; |
162 | } | 162 | } |
163 | } | 163 | } |
164 | qDebug("there are currently %d of drinks", i); | 164 | qDebug("there are currently %d of drinks", i); |
165 | } | 165 | } |
166 | 166 | ||
167 | void Bartender::fileNew() { | 167 | void Bartender::fileNew() { |
168 | 168 | ||
169 | New_Drink *newDrinks; | 169 | New_Drink *newDrinks; |
170 | newDrinks = new New_Drink(this,"New Drink....", TRUE); | 170 | newDrinks = new New_Drink(this,"New Drink....", TRUE); |
171 | QString newName, newIng; | 171 | QString newName, newIng; |
172 | newDrinks->showMaximized(); | 172 | newDrinks->showMaximized(); |
173 | newDrinks->exec(); | 173 | newDrinks->exec(); |
174 | newName = newDrinks->LineEdit1->text(); | 174 | newName = newDrinks->LineEdit1->text(); |
175 | newIng= newDrinks->MultiLineEdit1->text(); | 175 | newIng= newDrinks->MultiLineEdit1->text(); |
176 | 176 | ||
177 | if(dbFile.isOpen()) | 177 | if(dbFile.isOpen()) |
178 | dbFile.close(); | 178 | dbFile.close(); |
179 | if ( !dbFile.open( IO_WriteOnly| IO_Append)) { | 179 | if ( !dbFile.open( IO_WriteOnly| IO_Append)) { |
180 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); | 180 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); |
181 | return; | 181 | return; |
182 | } | 182 | } |
183 | if(newDrinks ->result() == 1 ) { | 183 | if(newDrinks ->result() == 1 ) { |
184 | QString newDrink="\n# "+newName+"\n"; | 184 | QString newDrink="\n# "+newName+"\n"; |
185 | newDrink.append(newIng+"\n"); | 185 | newDrink.append(newIng+"\n"); |
186 | qDebug("writing "+newDrink); | 186 | qDebug("writing "+newDrink); |
187 | dbFile.writeBlock( newDrink.latin1(), newDrink.length()); | 187 | dbFile.writeBlock( newDrink.latin1(), newDrink.length()); |
188 | clearList(); | 188 | clearList(); |
189 | dbFile.close(); | 189 | dbFile.close(); |
190 | 190 | ||
191 | initDrinkDb(); | 191 | initDrinkDb(); |
192 | } | 192 | } |
193 | delete newDrinks; | 193 | delete newDrinks; |
194 | } | 194 | } |
195 | 195 | ||
196 | void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) { | 196 | void Bartender::showDrink(int mouse, QListViewItem * item, const QPoint&, int) { |
197 | switch (mouse) { | 197 | switch (mouse) { |
198 | case 1: | 198 | case 1: |
199 | // showDrink(item); | 199 | // showDrink(item); |
200 | break; | 200 | break; |
201 | case 2: | 201 | case 2: |
202 | showDrink(item); | 202 | showDrink(item); |
203 | break; | 203 | break; |
204 | } | 204 | } |
205 | } | 205 | } |
206 | 206 | ||
207 | void Bartender::showDrink( QListViewItem *item) { | 207 | void Bartender::showDrink( QListViewItem *item) { |
208 | if(item==NULL) return; | 208 | if(item==NULL) return; |
209 | dbFile.at(0); | 209 | dbFile.at(0); |
210 | Show_Drink *showDrinks; | 210 | Show_Drink *showDrinks; |
211 | QString myDrink=item->text(0); | 211 | QString myDrink=item->text(0); |
212 | showDrinks = new Show_Drink(this, myDrink, TRUE); | 212 | showDrinks = new Show_Drink(this, myDrink, TRUE); |
213 | QTextStream t( &dbFile); | 213 | QTextStream t( &dbFile); |
214 | 214 | ||
215 | QString s, s2; | 215 | QString s, s2; |
216 | while ( !t.eof()) { | 216 | while ( !t.eof()) { |
217 | s = t.readLine(); | 217 | s = t.readLine(); |
218 | if(s.find( myDrink, 0, TRUE) != -1) { | 218 | if(s.find( myDrink, 0, TRUE) != -1) { |
219 | for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { | 219 | for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { |
220 | s2 = t.readLine(); | 220 | s2 = t.readLine(); |
221 | if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { | 221 | if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { |
222 | // qDebug(s2); | 222 | // qDebug(s2); |
223 | showDrinks->MultiLineEdit1->append(s2); | 223 | showDrinks->MultiLineEdit1->append(s2); |
224 | } | 224 | } |
225 | if( dbFile.atEnd() ) break; | 225 | if( dbFile.atEnd() ) break; |
226 | } | 226 | } |
227 | } | 227 | } |
228 | } | 228 | } |
229 | showDrinks->showMaximized(); | 229 | showDrinks->showMaximized(); |
230 | showDrinks->exec(); | 230 | showDrinks->exec(); |
231 | 231 | ||
232 | if(showDrinks ->result() ==0) { | 232 | if(showDrinks ->result() ==0) { |
233 | doEdit(); | 233 | doEdit(); |
234 | } | 234 | } |
235 | delete showDrinks; | 235 | delete showDrinks; |
236 | } | 236 | } |
237 | 237 | ||
238 | void Bartender::askSearch() { | 238 | void Bartender::askSearch() { |
239 | switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+ | 239 | switch ( QMessageBox::warning(this,tr("Find"),tr("Search by drink name\n")+ |
240 | "\nor alcohol ?" | 240 | "\nor alcohol ?" |
241 | ,tr("Drink Name"),tr("Alcohol"),0,0,1) ) { | 241 | ,tr("Drink Name"),tr("Alcohol"),0,0,1) ) { |
242 | case 0: | 242 | case 0: |
243 | doSearchByName(); | 243 | doSearchByName(); |
244 | break; | 244 | break; |
245 | case 1: | 245 | case 1: |
246 | doSearchByDrink(); | 246 | doSearchByDrink(); |
247 | break; | 247 | break; |
248 | }; | 248 | }; |
249 | } | 249 | } |
250 | 250 | ||
251 | /* search by name */ | 251 | /* search by name */ |
252 | void Bartender::doSearchByName() { | 252 | void Bartender::doSearchByName() { |
253 | // if( DrinkView->currentItem() == NULL) return; | 253 | // if( DrinkView->currentItem() == NULL) return; |
254 | QStringList searchList; | 254 | QStringList searchList; |
255 | QString searchForDrinkName; | 255 | QString searchForDrinkName; |
256 | InputDialog *fileDlg; | 256 | InputDialog *fileDlg; |
257 | fileDlg = new InputDialog(this,tr("Find by Drink Name"),TRUE, 0); | 257 | fileDlg = new InputDialog(this,tr("Find by Drink Name"),TRUE, 0); |
258 | fileDlg->exec(); | 258 | fileDlg->exec(); |
259 | if( fileDlg->result() == 1 ) { | 259 | if( fileDlg->result() == 1 ) { |
260 | searchForDrinkName = fileDlg->LineEdit1->text(); | 260 | searchForDrinkName = fileDlg->LineEdit1->text(); |
261 | QListViewItemIterator it( DrinkView ); | 261 | QListViewItemIterator it( DrinkView ); |
262 | for ( ; it.current(); ++it ) { | 262 | for ( ; it.current(); ++it ) { |
263 | if ( it.current()->text(0).find( searchForDrinkName, 0, TRUE) != -1 ) { | 263 | if ( it.current()->text(0).find( searchForDrinkName, 0, TRUE) != -1 ) { |
264 | // qDebug( it.current()->text(0)); | 264 | // qDebug( it.current()->text(0)); |
265 | searchList.append(it.current()->text(0)); | 265 | searchList.append(it.current()->text(0)); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | if(searchList.count() >0) | 268 | if(searchList.count() >0) |
269 | showSearchResult(searchList); | 269 | showSearchResult(searchList); |
270 | else | 270 | else |
271 | QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+searchForDrinkName); | 271 | QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+searchForDrinkName); |
272 | }//end Inputdialog | 272 | }//end Inputdialog |
273 | delete fileDlg; | 273 | delete fileDlg; |
274 | } | 274 | } |
275 | 275 | ||
276 | void Bartender::doSearchByDrink() { | 276 | void Bartender::doSearchByDrink() { |
277 | // if( DrinkView->currentItem() == NULL) return; | 277 | // if( DrinkView->currentItem() == NULL) return; |
278 | QStringList searchList; | 278 | QStringList searchList; |
279 | QString searchForDrinkName, lastDrinkName, tempName; | 279 | QString searchForDrinkName, lastDrinkName, tempName; |
280 | 280 | ||
281 | InputDialog *fileDlg; | 281 | InputDialog *fileDlg; |
282 | fileDlg = new InputDialog(this,tr("Find by Alcohol"),TRUE, 0); | 282 | fileDlg = new InputDialog(this,tr("Find by Alcohol"),TRUE, 0); |
283 | fileDlg->exec(); | 283 | fileDlg->exec(); |
284 | if( fileDlg->result() == 1 ) { | 284 | if( fileDlg->result() == 1 ) { |
285 | searchForDrinkName = fileDlg->LineEdit1->text(); | 285 | searchForDrinkName = fileDlg->LineEdit1->text(); |
286 | 286 | ||
287 | dbFile.at(0); | 287 | dbFile.at(0); |
288 | QTextStream t( &dbFile); | 288 | QTextStream t( &dbFile); |
289 | 289 | ||
290 | QString s, s2; | 290 | QString s, s2; |
291 | while ( !t.eof()) { | 291 | while ( !t.eof()) { |
292 | s = t.readLine(); | 292 | s = t.readLine(); |
293 | if(s.find("#",0,TRUE) != -1) { | 293 | if(s.find("#",0,TRUE) != -1) { |
294 | lastDrinkName=s.right(s.length()-2); | 294 | lastDrinkName=s.right(s.length()-2); |
295 | // qDebug("last drink name "+lastDrinkName); | 295 | // qDebug("last drink name "+lastDrinkName); |
296 | } | 296 | } |
297 | else if( s.find( searchForDrinkName ,0, FALSE) != -1 && lastDrinkName != tempName ) { | 297 | else if( s.find( searchForDrinkName ,0, FALSE) != -1 && lastDrinkName != tempName ) { |
298 | // qDebug("appending "+lastDrinkName); | 298 | // qDebug("appending "+lastDrinkName); |
299 | searchList.append( lastDrinkName); | 299 | searchList.append( lastDrinkName); |
300 | tempName=lastDrinkName; | 300 | tempName=lastDrinkName; |
301 | } | 301 | } |
302 | // if( dbFile.atEnd() ) break; | 302 | // if( dbFile.atEnd() ) break; |
303 | 303 | ||
304 | } //oef | 304 | } //oef |
305 | if(searchList.count() >0) | 305 | if(searchList.count() >0) |
306 | showSearchResult(searchList); | 306 | showSearchResult(searchList); |
307 | else | 307 | else |
308 | QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForDrinkName); | 308 | QMessageBox::message(tr("Search"),tr("Sorry no results for\n")+ searchForDrinkName); |
309 | } | 309 | } |
310 | delete fileDlg; | 310 | delete fileDlg; |
311 | } | 311 | } |
312 | 312 | ||
313 | void Bartender::showSearchResult(QStringList &searchList) { | 313 | void Bartender::showSearchResult(QStringList &searchList) { |
314 | QString result; | 314 | QString result; |
315 | Search_Results *searchDlg; | 315 | Search_Results *searchDlg; |
316 | 316 | ||
317 | searchList.sort(); | 317 | searchList.sort(); |
318 | 318 | ||
319 | searchDlg = new Search_Results(this, "Search Results", TRUE); | 319 | searchDlg = new Search_Results(this, "Search Results", TRUE); |
320 | searchDlg->showMaximized(); | 320 | searchDlg->showMaximized(); |
321 | searchDlg->ListBox1->insertStringList( searchList,-1); | 321 | searchDlg->ListBox1->insertStringList( searchList,-1); |
322 | searchDlg->exec(); | 322 | searchDlg->exec(); |
323 | 323 | ||
324 | if( searchDlg->result() == 1 ) { | 324 | if( searchDlg->result() == 1 ) { |
325 | result= searchDlg->ListBox1->currentText(); | 325 | result= searchDlg->ListBox1->currentText(); |
326 | } | 326 | } |
327 | QListViewItemIterator it2( DrinkView ); | 327 | QListViewItemIterator it2( DrinkView ); |
328 | for ( ; it2.current(); ++it2 ) { | 328 | for ( ; it2.current(); ++it2 ) { |
329 | if ( it2.current()->text(0)== result ) { | 329 | if ( it2.current()->text(0)== result ) { |
330 | // qDebug( it2.current()->text(0)); | 330 | // qDebug( it2.current()->text(0)); |
331 | showDrink(it2.current()); | 331 | showDrink(it2.current()); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | delete searchDlg; | 334 | delete searchDlg; |
335 | } | 335 | } |
336 | 336 | ||
337 | void Bartender::doEdit() { | 337 | void Bartender::doEdit() { |
338 | if(DrinkView->currentItem() == NULL) { | 338 | if(DrinkView->currentItem() == NULL) { |
339 | fileNew(); | 339 | fileNew(); |
340 | } | 340 | } |
341 | 341 | ||
342 | QString myDrink; | 342 | QString myDrink; |
343 | myDrink= DrinkView->currentItem()->text(0); | 343 | myDrink= DrinkView->currentItem()->text(0); |
344 | dbFile.at(0); | 344 | dbFile.at(0); |
345 | int foundAt=0; | 345 | int foundAt=0; |
346 | New_Drink *newDrinks; | 346 | New_Drink *newDrinks; |
347 | newDrinks = new New_Drink(this,"Edit Drink....", TRUE); | 347 | newDrinks = new New_Drink(this,"Edit Drink....", TRUE); |
348 | QString newName, newIng; | 348 | QString newName, newIng; |
349 | newDrinks->showMaximized(); | 349 | newDrinks->showMaximized(); |
350 | QTextStream t( &dbFile); | 350 | QTextStream t( &dbFile); |
351 | 351 | ||
352 | QString s, s2; | 352 | QString s, s2; |
353 | while ( !t.eof()) { | 353 | while ( !t.eof()) { |
354 | s = t.readLine(); | 354 | s = t.readLine(); |
355 | if(s.find( myDrink, 0, TRUE) != -1) { | 355 | if(s.find( myDrink, 0, TRUE) != -1) { |
356 | foundAt = dbFile.at() - (s.length()+1); | 356 | foundAt = dbFile.at() - (s.length()+1); |
357 | for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { | 357 | for(int i=0;s2.find( "#", 0, TRUE) == -1;i++) { |
358 | s2 = t.readLine(); | 358 | s2 = t.readLine(); |
359 | if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { | 359 | if(s2.find("#",0,TRUE) == -1 || dbFile.atEnd() ) { |
360 | // qDebug(s2); | 360 | // qDebug(s2); |
361 | newDrinks->MultiLineEdit1->append(s2); | 361 | newDrinks->MultiLineEdit1->append(s2); |
362 | newDrinks->LineEdit1->setText(myDrink); | 362 | newDrinks->LineEdit1->setText(myDrink); |
363 | } | 363 | } |
364 | if( dbFile.atEnd() ) break; | 364 | if( dbFile.atEnd() ) break; |
365 | } | 365 | } |
366 | } | 366 | } |
367 | } | 367 | } |
368 | newDrinks->exec(); | 368 | newDrinks->exec(); |
369 | newName = newDrinks->LineEdit1->text(); | 369 | newName = newDrinks->LineEdit1->text(); |
370 | newIng= newDrinks->MultiLineEdit1->text(); | 370 | newIng= newDrinks->MultiLineEdit1->text(); |
371 | 371 | ||
372 | if( newDrinks ->result() == 1 ) { | 372 | if( newDrinks ->result() == 1 ) { |
373 | if(dbFile.isOpen()) | 373 | if(dbFile.isOpen()) |
374 | dbFile.close(); | 374 | dbFile.close(); |
375 | if ( !dbFile.open( IO_ReadWrite )) { | 375 | if ( !dbFile.open( IO_ReadWrite )) { |
376 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); | 376 | QMessageBox::message( (tr("Note")), (tr("Drink database not opened sucessfully.\n")) ); |
377 | return; | 377 | return; |
378 | } | 378 | } |
379 | int fd = dbFile.handle(); | 379 | int fd = dbFile.handle(); |
380 | lseek( fd, foundAt, SEEK_SET); | 380 | lseek( fd, foundAt, SEEK_SET); |
381 | 381 | ||
382 | // dbFile.at( foundAt); | 382 | // dbFile.at( foundAt); |
383 | #warning FIXME problems with editing drinks db | 383 | #warning FIXME problems with editing drinks db |
384 | ////////// FIXME write to user file | 384 | ////////// FIXME write to user file |
385 | QString newDrink="# "+newName+"\n"; | 385 | QString newDrink="# "+newName+"\n"; |
386 | newDrink.append(newIng+"\n"); | 386 | newDrink.append(newIng+"\n"); |
387 | qDebug("writing "+newDrink); | 387 | qDebug("writing "+newDrink); |
388 | dbFile.writeBlock( newDrink.latin1(), newDrink.length()); | 388 | dbFile.writeBlock( newDrink.latin1(), newDrink.length()); |
389 | clearList(); | 389 | clearList(); |
390 | 390 | ||
391 | dbFile.flush(); | 391 | dbFile.flush(); |
392 | 392 | ||
393 | initDrinkDb(); | 393 | initDrinkDb(); |
394 | } | 394 | } |
395 | } | 395 | } |
396 | 396 | ||
397 | void Bartender::clearList() { | 397 | void Bartender::clearList() { |
398 | DrinkView->clear(); | 398 | DrinkView->clear(); |
399 | } | 399 | } |
400 | 400 | ||
401 | void Bartender::doBac() { | 401 | void Bartender::doBac() { |
402 | BacDialog *bacDlg; | 402 | BacDialog *bacDlg; |
403 | bacDlg = new BacDialog(this,"BAC",TRUE); | 403 | bacDlg = new BacDialog(this,"BAC",TRUE); |
404 | bacDlg->showMaximized(); | 404 | bacDlg->showMaximized(); |
405 | bacDlg->exec(); | 405 | bacDlg->exec(); |
406 | delete bacDlg; | 406 | delete bacDlg; |
407 | } | 407 | } |
408 | 408 | ||
409 | void Bartender::openCurrentDrink() { | 409 | void Bartender::openCurrentDrink() { |
410 | if(DrinkView->currentItem() == NULL) return; | 410 | if(DrinkView->currentItem() == NULL) return; |
411 | showDrink(DrinkView->currentItem()); | 411 | showDrink(DrinkView->currentItem()); |
412 | } | 412 | } |
413 | 413 | ||
414 | void Bartender::fileMenuActivated( int item) { | 414 | void Bartender::fileMenuActivated( int item) { |
415 | qDebug("Item %d", item); | 415 | qDebug("Item %d", item); |
416 | switch(item) { | 416 | switch(item) { |
417 | case -3: // new -3 | 417 | case -3: // new -3 |
418 | fileNew(); | 418 | fileNew(); |
419 | break; | 419 | break; |
420 | case -4:// open -4 | 420 | case -4:// open -4 |
421 | openCurrentDrink(); | 421 | openCurrentDrink(); |
422 | break; | 422 | break; |
423 | case -5:// drink -5 | 423 | case -5:// drink -5 |
424 | doSearchByName(); | 424 | doSearchByName(); |
425 | 425 | ||
426 | break; | 426 | break; |
427 | case -6:// alcohol -6 | 427 | case -6:// alcohol -6 |
428 | doSearchByDrink(); | 428 | doSearchByDrink(); |
429 | 429 | ||
430 | break; | 430 | break; |
431 | 431 | ||
432 | } | 432 | } |
433 | } | 433 | } |
434 | 434 | ||
435 | void Bartender::editMenuActivated(int item) { | 435 | void Bartender::editMenuActivated(int item) { |
436 | qDebug("Item %d", item); | 436 | qDebug("Item %d", item); |
437 | /* | 437 | /* |
438 | edit -8 | 438 | edit -8 |
439 | */ | 439 | */ |
440 | switch(item) { | 440 | switch(item) { |
441 | case -8: | 441 | case -8: |
442 | doEdit() ; | 442 | doEdit() ; |
443 | break; | 443 | break; |
444 | 444 | ||
445 | } | 445 | } |
446 | } | 446 | } |
447 | 447 | ||
diff --git a/noncore/apps/opie-bartender/bartender.h b/noncore/apps/opie-bartender/bartender.h index 69cfa82..df1af76 100644 --- a/noncore/apps/opie-bartender/bartender.h +++ b/noncore/apps/opie-bartender/bartender.h | |||
@@ -1,63 +1,63 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** Created: Sat Jul 20 08:10:31 2002 | 2 | ** Created: Sat Jul 20 08:10:31 2002 |
3 | ** by: L.J. Potter <ljp@llornkcor.com> | 3 | ** by: L.J. Potter <ljp@llornkcor.com> |
4 | ** copyright : (C) 2002 by ljp | 4 | ** copyright : (C) 2002 by ljp |
5 | email : ljp@llornkcor.com | 5 | email : ljp@llornkcor.com |
6 | * This program is free software; you can redistribute it and/or modify * | 6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * | 7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * | 8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * | 9 | * (at your option) any later version. * |
10 | ***************************************************************************/ | 10 | ***************************************************************************/ |
11 | #ifndef BARTENDER_H | 11 | #ifndef BARTENDER_H |
12 | #define BARTENDER_H | 12 | #define BARTENDER_H |
13 | #include "newdrinks.h" | 13 | #include "newdrinks.h" |
14 | 14 | ||
15 | #include <qvariant.h> | 15 | #include <qvariant.h> |
16 | #include <qwidget.h> | 16 | #include <qwidget.h> |
17 | #include <qmainwindow.h> | 17 | #include <qmainwindow.h> |
18 | #include <qfile.h> | 18 | #include <qfile.h> |
19 | 19 | ||
20 | class QVBoxLayout; | 20 | class QVBoxLayout; |
21 | class QHBoxLayout; | 21 | class QHBoxLayout; |
22 | class QGridLayout; | 22 | class QGridLayout; |
23 | class QListView; | 23 | class QListView; |
24 | class QListViewItem; | 24 | class QListViewItem; |
25 | class QPEToolBar; | 25 | class QToolBar; |
26 | 26 | ||
27 | class Bartender : public QMainWindow | 27 | class Bartender : public QMainWindow |
28 | { | 28 | { |
29 | Q_OBJECT | 29 | Q_OBJECT |
30 | 30 | ||
31 | public: | 31 | public: |
32 | Bartender( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 32 | Bartender( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
33 | ~Bartender(); | 33 | ~Bartender(); |
34 | 34 | ||
35 | QPEToolBar* ToolBar1; | 35 | QToolBar* ToolBar1; |
36 | QListView* DrinkView; | 36 | QListView* DrinkView; |
37 | QFile dbFile; | 37 | QFile dbFile; |
38 | public slots: | 38 | public slots: |
39 | void doEdit(); | 39 | void doEdit(); |
40 | 40 | ||
41 | protected: | 41 | protected: |
42 | 42 | ||
43 | protected slots: | 43 | protected slots: |
44 | void fileMenuActivated(int); | 44 | void fileMenuActivated(int); |
45 | void editMenuActivated(int); | 45 | void editMenuActivated(int); |
46 | void cleanUp(); | 46 | void cleanUp(); |
47 | void fileNew(); | 47 | void fileNew(); |
48 | void showDrink( QListViewItem *); | 48 | void showDrink( QListViewItem *); |
49 | void showDrink(int, QListViewItem *, const QPoint&, int); | 49 | void showDrink(int, QListViewItem *, const QPoint&, int); |
50 | void initDrinkDb(); | 50 | void initDrinkDb(); |
51 | void doSearchByName(); | 51 | void doSearchByName(); |
52 | void doSearchByDrink(); | 52 | void doSearchByDrink(); |
53 | void showSearchResult(QStringList &); | 53 | void showSearchResult(QStringList &); |
54 | void doBac(); | 54 | void doBac(); |
55 | void openCurrentDrink(); | 55 | void openCurrentDrink(); |
56 | void askSearch(); | 56 | void askSearch(); |
57 | private: | 57 | private: |
58 | void clearList(); | 58 | void clearList(); |
59 | void fillList(); | 59 | void fillList(); |
60 | 60 | ||
61 | }; | 61 | }; |
62 | 62 | ||
63 | #endif // BARTENDER_H | 63 | #endif // BARTENDER_H |
diff --git a/noncore/apps/opie-reader/QTReaderApp.cpp b/noncore/apps/opie-reader/QTReaderApp.cpp index 8c0d138..f10020a 100644 --- a/noncore/apps/opie-reader/QTReaderApp.cpp +++ b/noncore/apps/opie-reader/QTReaderApp.cpp | |||
@@ -1,4222 +1,4222 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. Allrights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. Allrights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop 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 | #include "useqpe.h" | 20 | #include "useqpe.h" |
21 | #include <qregexp.h> | 21 | #include <qregexp.h> |
22 | #include <qclipboard.h> | 22 | #include <qclipboard.h> |
23 | #include <qwidgetstack.h> | 23 | #include <qwidgetstack.h> |
24 | #ifdef USEQPE | 24 | #ifdef USEQPE |
25 | #include <qpe/qpemenubar.h> | 25 | #include <qmenubar.h> |
26 | #include <qpe/qpetoolbar.h> | 26 | #include <qpe/qpetoolbar.h> |
27 | #endif | 27 | #endif |
28 | #include <qmenubar.h> | 28 | #include <qmenubar.h> |
29 | #include <qtoolbar.h> | 29 | #include <qtoolbar.h> |
30 | #ifdef USEQPE | 30 | #ifdef USEQPE |
31 | #include <qpe/menubutton.h> | 31 | #include <qpe/menubutton.h> |
32 | #include <qpe/fontdatabase.h> | 32 | #include <qpe/fontdatabase.h> |
33 | #endif | 33 | #endif |
34 | #include <qcombobox.h> | 34 | #include <qcombobox.h> |
35 | #include <qpopupmenu.h> | 35 | #include <qpopupmenu.h> |
36 | #include <qaction.h> | 36 | #include <qaction.h> |
37 | #include <qapplication.h> | 37 | #include <qapplication.h> |
38 | #include <qlineedit.h> | 38 | #include <qlineedit.h> |
39 | #include <qtoolbutton.h> | 39 | #include <qtoolbutton.h> |
40 | #include <qspinbox.h> | 40 | #include <qspinbox.h> |
41 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
42 | #ifdef USEQPE | 42 | #ifdef USEQPE |
43 | #include <qpe/global.h> | 43 | #include <qpe/global.h> |
44 | #include <qpe/applnk.h> | 44 | #include <qpe/applnk.h> |
45 | #endif | 45 | #endif |
46 | #include <qfileinfo.h> | 46 | #include <qfileinfo.h> |
47 | #include <stdlib.h> //getenv | 47 | #include <stdlib.h> //getenv |
48 | #include <qprogressbar.h> | 48 | #include <qprogressbar.h> |
49 | #ifdef USEQPE | 49 | #ifdef USEQPE |
50 | #include <qpe/config.h> | 50 | #include <qpe/config.h> |
51 | #endif | 51 | #endif |
52 | #include <qbuttongroup.h> | 52 | #include <qbuttongroup.h> |
53 | #include <qradiobutton.h> | 53 | #include <qradiobutton.h> |
54 | #ifdef USEQPE | 54 | #ifdef USEQPE |
55 | #include <qpe/qcopenvelope_qws.h> | 55 | #include <qpe/qcopenvelope_qws.h> |
56 | #endif | 56 | #endif |
57 | #include "QTReader.h" | 57 | #include "QTReader.h" |
58 | #include "GraphicWin.h" | 58 | #include "GraphicWin.h" |
59 | #include "Bkmks.h" | 59 | #include "Bkmks.h" |
60 | #include "cbkmkselector.h" | 60 | #include "cbkmkselector.h" |
61 | #include "infowin.h" | 61 | #include "infowin.h" |
62 | #include "ToolbarPrefs.h" | 62 | #include "ToolbarPrefs.h" |
63 | #include "Prefs.h" | 63 | #include "Prefs.h" |
64 | #include "CAnnoEdit.h" | 64 | #include "CAnnoEdit.h" |
65 | #include "QFloatBar.h" | 65 | #include "QFloatBar.h" |
66 | #include "FixedFont.h" | 66 | #include "FixedFont.h" |
67 | #include "URLDialog.h" | 67 | #include "URLDialog.h" |
68 | //#include <qpe/fontdatabase.h> | 68 | //#include <qpe/fontdatabase.h> |
69 | 69 | ||
70 | #ifdef USEQPE | 70 | #ifdef USEQPE |
71 | #include <qpe/resource.h> | 71 | #include <qpe/resource.h> |
72 | #include <qpe/qpeapplication.h> | 72 | #include <qpe/qpeapplication.h> |
73 | #include "fileBrowser.h" | 73 | #include "fileBrowser.h" |
74 | #else | 74 | #else |
75 | #include "qfiledialog.h" | 75 | #include "qfiledialog.h" |
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | #include "QTReaderApp.h" | 78 | #include "QTReaderApp.h" |
79 | #include "CDrawBuffer.h" | 79 | #include "CDrawBuffer.h" |
80 | #include "Filedata.h" | 80 | #include "Filedata.h" |
81 | #include "opie.h" | 81 | #include "opie.h" |
82 | #include "useqpe.h" | 82 | #include "useqpe.h" |
83 | #include "names.h" | 83 | #include "names.h" |
84 | #include "CEncoding_tables.h" | 84 | #include "CEncoding_tables.h" |
85 | #include "CloseDialog.h" | 85 | #include "CloseDialog.h" |
86 | 86 | ||
87 | bool CheckVersion(int&, int&, char&); | 87 | bool CheckVersion(int&, int&, char&); |
88 | 88 | ||
89 | #ifdef _WINDOWS | 89 | #ifdef _WINDOWS |
90 | #define PICDIR "c:\\uqtreader\\pics\\" | 90 | #define PICDIR "c:\\uqtreader\\pics\\" |
91 | #else | 91 | #else |
92 | #ifdef USEQPE | 92 | #ifdef USEQPE |
93 | #define PICDIR "opie-reader/" | 93 | #define PICDIR "opie-reader/" |
94 | #else | 94 | #else |
95 | #define PICDIR "/home/tim/uqtreader/pics/" | 95 | #define PICDIR "/home/tim/uqtreader/pics/" |
96 | #endif | 96 | #endif |
97 | #endif | 97 | #endif |
98 | 98 | ||
99 | unsigned long QTReaderApp::m_uid = 0; | 99 | unsigned long QTReaderApp::m_uid = 0; |
100 | 100 | ||
101 | void QTReaderApp::setScrollState(bool _b) { m_scrollButton->setOn(_b); } | 101 | void QTReaderApp::setScrollState(bool _b) { m_scrollButton->setOn(_b); } |
102 | 102 | ||
103 | #ifdef USEQPE | 103 | #ifdef USEQPE |
104 | #define geticon(iconname) Resource::loadPixmap( iconname ) | 104 | #define geticon(iconname) Resource::loadPixmap( iconname ) |
105 | #define getmyicon(iconname) Resource::loadPixmap( PICDIR iconname ) | 105 | #define getmyicon(iconname) Resource::loadPixmap( PICDIR iconname ) |
106 | #else | 106 | #else |
107 | #define geticon(iconname) QPixmap(PICDIR iconname ".png") | 107 | #define geticon(iconname) QPixmap(PICDIR iconname ".png") |
108 | #define getmyicon(iconname) geticon(iconname) | 108 | #define getmyicon(iconname) geticon(iconname) |
109 | //#define geticon(iconname) QIconSet( QPixmap(PICDIR iconname) ) | 109 | //#define geticon(iconname) QIconSet( QPixmap(PICDIR iconname) ) |
110 | #endif | 110 | #endif |
111 | 111 | ||
112 | #ifndef _WINDOWS | 112 | #ifndef _WINDOWS |
113 | #include <unistd.h> | 113 | #include <unistd.h> |
114 | #endif | 114 | #endif |
115 | #include <stddef.h> | 115 | #include <stddef.h> |
116 | #ifndef _WINDOWS | 116 | #ifndef _WINDOWS |
117 | #include <dirent.h> | 117 | #include <dirent.h> |
118 | #endif | 118 | #endif |
119 | 119 | ||
120 | void QTReaderApp::listBkmkFiles() | 120 | void QTReaderApp::listBkmkFiles() |
121 | { | 121 | { |
122 | bkmkselector->clear(); | 122 | bkmkselector->clear(); |
123 | bkmkselector->setText("Cancel"); | 123 | bkmkselector->setText("Cancel"); |
124 | #ifndef USEQPE | 124 | #ifndef USEQPE |
125 | int cnt = 0; | 125 | int cnt = 0; |
126 | 126 | ||
127 | QDir d = QDir::home(); // "/" | 127 | QDir d = QDir::home(); // "/" |
128 | if ( !d.cd(APPDIR) ) { // "/tmp" | 128 | if ( !d.cd(APPDIR) ) { // "/tmp" |
129 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); | 129 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); |
130 | d = QDir::home(); | 130 | d = QDir::home(); |
131 | d.mkdir(APPDIR); | 131 | d.mkdir(APPDIR); |
132 | d.cd(APPDIR); | 132 | d.cd(APPDIR); |
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | 136 | ||
137 | 137 | ||
138 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 138 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
139 | // d.setSorting( QDir::Size | QDir::Reversed ); | 139 | // d.setSorting( QDir::Size | QDir::Reversed ); |
140 | 140 | ||
141 | const QFileInfoList *list = d.entryInfoList(); | 141 | const QFileInfoList *list = d.entryInfoList(); |
142 | QFileInfoListIterator it( *list ); // create list iterator | 142 | QFileInfoListIterator it( *list ); // create list iterator |
143 | QFileInfo *fi; // pointer for traversing | 143 | QFileInfo *fi; // pointer for traversing |
144 | 144 | ||
145 | while ( (fi=it.current()) ) { // for each file... | 145 | while ( (fi=it.current()) ) { // for each file... |
146 | 146 | ||
147 | bkmkselector->insertItem(fi->fileName()); | 147 | bkmkselector->insertItem(fi->fileName()); |
148 | cnt++; | 148 | cnt++; |
149 | 149 | ||
150 | //qDebug( "%10li %s", fi->size(), fi->fileName().data() ); | 150 | //qDebug( "%10li %s", fi->size(), fi->fileName().data() ); |
151 | ++it; // goto next list element | 151 | ++it; // goto next list element |
152 | } | 152 | } |
153 | 153 | ||
154 | #else /* USEQPE */ | 154 | #else /* USEQPE */ |
155 | int cnt = 0; | 155 | int cnt = 0; |
156 | DIR *d; | 156 | DIR *d; |
157 | d = opendir((const char *)Global::applicationFileName(APPDIR,"")); | 157 | d = opendir((const char *)Global::applicationFileName(APPDIR,"")); |
158 | 158 | ||
159 | while(1) | 159 | while(1) |
160 | { | 160 | { |
161 | struct dirent* de; | 161 | struct dirent* de; |
162 | struct stat buf; | 162 | struct stat buf; |
163 | de = readdir(d); | 163 | de = readdir(d); |
164 | if (de == NULL) break; | 164 | if (de == NULL) break; |
165 | 165 | ||
166 | if (lstat((const char *)Global::applicationFileName(APPDIR,de->d_name),&buf) == 0 && S_ISREG(buf.st_mode)) | 166 | if (lstat((const char *)Global::applicationFileName(APPDIR,de->d_name),&buf) == 0 && S_ISREG(buf.st_mode)) |
167 | { | 167 | { |
168 | bkmkselector->insertItem(de->d_name); | 168 | bkmkselector->insertItem(de->d_name); |
169 | cnt++; | 169 | cnt++; |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | closedir(d); | 173 | closedir(d); |
174 | #endif | 174 | #endif |
175 | if (cnt > 0) | 175 | if (cnt > 0) |
176 | { | 176 | { |
177 | //tjw menu->hide(); | 177 | //tjw menu->hide(); |
178 | editorStack->raiseWidget( bkmkselector ); | 178 | editorStack->raiseWidget( bkmkselector ); |
179 | hidetoolbars(); | 179 | hidetoolbars(); |
180 | m_nBkmkAction = cRmBkmkFile; | 180 | m_nBkmkAction = cRmBkmkFile; |
181 | } | 181 | } |
182 | else | 182 | else |
183 | QMessageBox::information(this, PROGNAME, "No bookmark files"); | 183 | QMessageBox::information(this, PROGNAME, "No bookmark files"); |
184 | } | 184 | } |
185 | 185 | ||
186 | void QTReaderApp::hidetoolbars() | 186 | void QTReaderApp::hidetoolbars() |
187 | { | 187 | { |
188 | menubar->hide(); | 188 | menubar->hide(); |
189 | if (fileBar != NULL) fileBar->hide(); | 189 | if (fileBar != NULL) fileBar->hide(); |
190 | if (viewBar != NULL) viewBar->hide(); | 190 | if (viewBar != NULL) viewBar->hide(); |
191 | if (navBar != NULL) navBar->hide(); | 191 | if (navBar != NULL) navBar->hide(); |
192 | if (markBar != NULL) markBar->hide(); | 192 | if (markBar != NULL) markBar->hide(); |
193 | if (m_fontVisible) m_fontBar->hide(); | 193 | if (m_fontVisible) m_fontBar->hide(); |
194 | if (regVisible) | 194 | if (regVisible) |
195 | { | 195 | { |
196 | #ifdef USEQPE | 196 | #ifdef USEQPE |
197 | Global::hideInputMethod(); | 197 | Global::hideInputMethod(); |
198 | #endif | 198 | #endif |
199 | regBar->hide(); | 199 | regBar->hide(); |
200 | } | 200 | } |
201 | if (searchVisible) | 201 | if (searchVisible) |
202 | { | 202 | { |
203 | #ifdef USEQPE | 203 | #ifdef USEQPE |
204 | Global::hideInputMethod(); | 204 | Global::hideInputMethod(); |
205 | #endif | 205 | #endif |
206 | searchBar->hide(); | 206 | searchBar->hide(); |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) | 210 | QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f ) |
211 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ), m_dontSave(false), | 211 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ), m_dontSave(false), |
212 | fileBar(NULL), navBar(NULL), viewBar(NULL), markBar(NULL) | 212 | fileBar(NULL), navBar(NULL), viewBar(NULL), markBar(NULL) |
213 | { | 213 | { |
214 | m_url_clipboard = false; | 214 | m_url_clipboard = false; |
215 | m_url_localfile = false; | 215 | m_url_localfile = false; |
216 | m_url_globalfile = false; | 216 | m_url_globalfile = false; |
217 | ftime(&m_lastkeytime); | 217 | ftime(&m_lastkeytime); |
218 | //// qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir()); | 218 | //// qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir()); |
219 | //// qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml")); | 219 | //// qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml")); |
220 | 220 | ||
221 | m_bcloseDisabled = true; | 221 | m_bcloseDisabled = true; |
222 | m_disableesckey = false; | 222 | m_disableesckey = false; |
223 | pBkmklist = NULL; | 223 | pBkmklist = NULL; |
224 | pOpenlist = NULL; | 224 | pOpenlist = NULL; |
225 | // doc = 0; | 225 | // doc = 0; |
226 | 226 | ||
227 | m_fBkmksChanged = false; | 227 | m_fBkmksChanged = false; |
228 | 228 | ||
229 | QString lang = getenv( "LANG" ); | 229 | QString lang = getenv( "LANG" ); |
230 | QString rot = getenv( "QWS_DISPLAY" ); | 230 | QString rot = getenv( "QWS_DISPLAY" ); |
231 | 231 | ||
232 | /* | 232 | /* |
233 | int m_rot = 0; | 233 | int m_rot = 0; |
234 | if (rot.contains("Rot90")) | 234 | if (rot.contains("Rot90")) |
235 | { | 235 | { |
236 | m_rot = 90; | 236 | m_rot = 90; |
237 | } | 237 | } |
238 | else if (rot.contains("Rot180")) | 238 | else if (rot.contains("Rot180")) |
239 | { | 239 | { |
240 | m_rot = 180; | 240 | m_rot = 180; |
241 | } | 241 | } |
242 | else if (rot.contains("Rot270")) | 242 | else if (rot.contains("Rot270")) |
243 | { | 243 | { |
244 | m_rot = 270; | 244 | m_rot = 270; |
245 | } | 245 | } |
246 | 246 | ||
247 | // qDebug("Initial Rotation(%d):%s", m_rot, (const char*)rot); | 247 | // qDebug("Initial Rotation(%d):%s", m_rot, (const char*)rot); |
248 | */ | 248 | */ |
249 | m_autogenstr = "^ *[A-Z].*[a-z] *$"; | 249 | m_autogenstr = "^ *[A-Z].*[a-z] *$"; |
250 | 250 | ||
251 | #ifdef USEQPE | 251 | #ifdef USEQPE |
252 | setIcon( Resource::loadPixmap( PICDIR "uqtreader") ); | 252 | setIcon( Resource::loadPixmap( PICDIR "uqtreader") ); |
253 | #else | 253 | #else |
254 | setIcon( QPixmap (PICDIR "uqtreader.png") ); | 254 | setIcon( QPixmap (PICDIR "uqtreader.png") ); |
255 | #endif /* USEQPE */ | 255 | #endif /* USEQPE */ |
256 | 256 | ||
257 | // QPEToolBar *bar = new QPEToolBar( this ); | 257 | // QToolBar *bar = new QToolBar( this ); |
258 | // menubar = new QPEToolBar( this ); | 258 | // menubar = new QToolBar( this ); |
259 | #ifdef USEQPE | 259 | #ifdef USEQPE |
260 | Config config( APPDIR ); | 260 | Config config( APPDIR ); |
261 | #else | 261 | #else |
262 | QDir d = QDir::home(); // "/" | 262 | QDir d = QDir::home(); // "/" |
263 | if ( !d.cd(APPDIR) ) { // "/tmp" | 263 | if ( !d.cd(APPDIR) ) { // "/tmp" |
264 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); | 264 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); |
265 | d = QDir::home(); | 265 | d = QDir::home(); |
266 | d.mkdir(APPDIR); | 266 | d.mkdir(APPDIR); |
267 | d.cd(APPDIR); | 267 | d.cd(APPDIR); |
268 | } | 268 | } |
269 | QFileInfo fi(d, INIFILE); | 269 | QFileInfo fi(d, INIFILE); |
270 | // qDebug("Path:%s", (const char*)fi.absFilePath()); | 270 | // qDebug("Path:%s", (const char*)fi.absFilePath()); |
271 | Config config(fi.absFilePath()); | 271 | Config config(fi.absFilePath()); |
272 | #endif | 272 | #endif |
273 | config.setGroup("Toolbar"); | 273 | config.setGroup("Toolbar"); |
274 | m_tbmovesave = m_tbmove = config.readBoolEntry("Movable", false); | 274 | m_tbmovesave = m_tbmove = config.readBoolEntry("Movable", false); |
275 | m_tbpolsave = m_tbpol = (ToolbarPolicy)config.readNumEntry("Policy", 1); | 275 | m_tbpolsave = m_tbpol = (ToolbarPolicy)config.readNumEntry("Policy", 1); |
276 | m_tbposition = (ToolBarDock)config.readNumEntry("Position", 2); | 276 | m_tbposition = (ToolBarDock)config.readNumEntry("Position", 2); |
277 | menubar = new QToolBar("Menus", this, m_tbposition); | 277 | menubar = new QToolBar("Menus", this, m_tbposition); |
278 | 278 | ||
279 | // fileBar = new QToolBar("File", this); | 279 | // fileBar = new QToolBar("File", this); |
280 | // QToolBar* viewBar = new QToolBar("File", this); | 280 | // QToolBar* viewBar = new QToolBar("File", this); |
281 | // QToolBar* navBar = new QToolBar("File", this); | 281 | // QToolBar* navBar = new QToolBar("File", this); |
282 | // QToolBar* markBar = new QToolBar("File", this); | 282 | // QToolBar* markBar = new QToolBar("File", this); |
283 | 283 | ||
284 | #ifdef USEQPE | 284 | #ifdef USEQPE |
285 | mb = new QMenuBar( menubar ); | 285 | mb = new QMenuBar( menubar ); |
286 | #else | 286 | #else |
287 | mb = new QMenuBar( menubar ); | 287 | mb = new QMenuBar( menubar ); |
288 | #endif | 288 | #endif |
289 | 289 | ||
290 | //#ifdef USEQPE | 290 | //#ifdef USEQPE |
291 | QPopupMenu* tmp = new QPopupMenu(mb); | 291 | QPopupMenu* tmp = new QPopupMenu(mb); |
292 | mb->insertItem( geticon( "AppsIcon" ), tmp ); | 292 | mb->insertItem( geticon( "AppsIcon" ), tmp ); |
293 | //#else | 293 | //#else |
294 | // QMenuBar* tmp = mb; | 294 | // QMenuBar* tmp = mb; |
295 | //#endif | 295 | //#endif |
296 | 296 | ||
297 | QPopupMenu *file = new QPopupMenu( mb ); | 297 | QPopupMenu *file = new QPopupMenu( mb ); |
298 | tmp->insertItem( tr( "File" ), file ); | 298 | tmp->insertItem( tr( "File" ), file ); |
299 | 299 | ||
300 | QPopupMenu *navigation = new QPopupMenu(mb); | 300 | QPopupMenu *navigation = new QPopupMenu(mb); |
301 | tmp->insertItem( tr( "Navigation" ), navigation ); | 301 | tmp->insertItem( tr( "Navigation" ), navigation ); |
302 | 302 | ||
303 | QPopupMenu *view = new QPopupMenu( mb ); | 303 | QPopupMenu *view = new QPopupMenu( mb ); |
304 | tmp->insertItem( tr( "View" ), view ); | 304 | tmp->insertItem( tr( "View" ), view ); |
305 | 305 | ||
306 | QPopupMenu *marks = new QPopupMenu( this ); | 306 | QPopupMenu *marks = new QPopupMenu( this ); |
307 | tmp->insertItem( tr( "Marks" ), marks ); | 307 | tmp->insertItem( tr( "Marks" ), marks ); |
308 | 308 | ||
309 | QPopupMenu *settings = new QPopupMenu( this ); | 309 | QPopupMenu *settings = new QPopupMenu( this ); |
310 | tmp->insertItem( tr( "Settings" ), settings ); | 310 | tmp->insertItem( tr( "Settings" ), settings ); |
311 | 311 | ||
312 | // addToolBar(menubar, "Menus",QMainWindow::Top); | 312 | // addToolBar(menubar, "Menus",QMainWindow::Top); |
313 | // addToolBar(fileBar, "Toolbar",QMainWindow::Top); | 313 | // addToolBar(fileBar, "Toolbar",QMainWindow::Top); |
314 | 314 | ||
315 | // QPopupMenu *edit = new QPopupMenu( this ); | 315 | // QPopupMenu *edit = new QPopupMenu( this ); |
316 | 316 | ||
317 | /* | 317 | /* |
318 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 318 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
319 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 319 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
320 | a->addTo( bar ); | 320 | a->addTo( bar ); |
321 | a->addTo( file ); | 321 | a->addTo( file ); |
322 | */ | 322 | */ |
323 | 323 | ||
324 | editorStack = new QWidgetStack( this ); | 324 | editorStack = new QWidgetStack( this ); |
325 | setCentralWidget( editorStack ); | 325 | setCentralWidget( editorStack ); |
326 | 326 | ||
327 | searchVisible = FALSE; | 327 | searchVisible = FALSE; |
328 | regVisible = FALSE; | 328 | regVisible = FALSE; |
329 | m_fontVisible = false; | 329 | m_fontVisible = false; |
330 | 330 | ||
331 | m_annoWin = new CAnnoEdit(editorStack); | 331 | m_annoWin = new CAnnoEdit(editorStack); |
332 | editorStack->addWidget(m_annoWin, get_unique_id()); | 332 | editorStack->addWidget(m_annoWin, get_unique_id()); |
333 | connect( m_annoWin, SIGNAL( finished(const QString&, const QString&) ), this, SLOT( addAnno(const QString&, const QString&) ) ); | 333 | connect( m_annoWin, SIGNAL( finished(const QString&, const QString&) ), this, SLOT( addAnno(const QString&, const QString&) ) ); |
334 | connect( m_annoWin, SIGNAL( cancelled() ), this, SLOT( infoClose() ) ); | 334 | connect( m_annoWin, SIGNAL( cancelled() ), this, SLOT( infoClose() ) ); |
335 | 335 | ||
336 | m_infoWin = new infowin(editorStack); | 336 | m_infoWin = new infowin(editorStack); |
337 | editorStack->addWidget(m_infoWin, get_unique_id()); | 337 | editorStack->addWidget(m_infoWin, get_unique_id()); |
338 | connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) ); | 338 | connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) ); |
339 | 339 | ||
340 | m_graphicwin = new GraphicWin(editorStack); | 340 | m_graphicwin = new GraphicWin(editorStack); |
341 | editorStack->addWidget(m_graphicwin, get_unique_id()); | 341 | editorStack->addWidget(m_graphicwin, get_unique_id()); |
342 | connect( m_graphicwin, SIGNAL( Closed() ), this, SLOT( infoClose() ) ); | 342 | connect( m_graphicwin, SIGNAL( Closed() ), this, SLOT( infoClose() ) ); |
343 | 343 | ||
344 | // bkmkselector = new QListBox(editorStack, "Bookmarks"); | 344 | // bkmkselector = new QListBox(editorStack, "Bookmarks"); |
345 | bkmkselector = new CBkmkSelector(editorStack, "Bookmarks"); | 345 | bkmkselector = new CBkmkSelector(editorStack, "Bookmarks"); |
346 | // connect(bkmkselector, SIGNAL( selected(const QString&) ), this, SLOT( gotobkmk(const QString&) ) ); | 346 | // connect(bkmkselector, SIGNAL( selected(const QString&) ), this, SLOT( gotobkmk(const QString&) ) ); |
347 | connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( gotobkmk(int) ) ); | 347 | connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( gotobkmk(int) ) ); |
348 | connect(bkmkselector, SIGNAL( cancelled() ), this, SLOT( cancelbkmk() ) ); | 348 | connect(bkmkselector, SIGNAL( cancelled() ), this, SLOT( cancelbkmk() ) ); |
349 | editorStack->addWidget( bkmkselector, get_unique_id() ); | 349 | editorStack->addWidget( bkmkselector, get_unique_id() ); |
350 | 350 | ||
351 | /* | 351 | /* |
352 | importSelector = new FileSelector( "*", editorStack, "importselector", false ); | 352 | importSelector = new FileSelector( "*", editorStack, "importselector", false ); |
353 | connect( importSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( importFile( const DocLnk & ) ) ); | 353 | connect( importSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( importFile( const DocLnk & ) ) ); |
354 | 354 | ||
355 | editorStack->addWidget( importSelector, get_unique_id() ); | 355 | editorStack->addWidget( importSelector, get_unique_id() ); |
356 | 356 | ||
357 | // don't need the close visible, it is redundant... | 357 | // don't need the close visible, it is redundant... |
358 | importSelector->setCloseVisible( FALSE ); | 358 | importSelector->setCloseVisible( FALSE ); |
359 | */ | 359 | */ |
360 | // qDebug("Reading file list"); | 360 | // qDebug("Reading file list"); |
361 | readfilelist(); | 361 | readfilelist(); |
362 | 362 | ||
363 | reader = new QTReader( editorStack ); | 363 | reader = new QTReader( editorStack ); |
364 | 364 | ||
365 | reader->bDoUpdates = false; | 365 | reader->bDoUpdates = false; |
366 | 366 | ||
367 | #ifdef USEQPE | 367 | #ifdef USEQPE |
368 | ((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold); | 368 | ((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold); |
369 | #endif | 369 | #endif |
370 | 370 | ||
371 | // qDebug("Reading config"); | 371 | // qDebug("Reading config"); |
372 | // Config config( APPDIR ); | 372 | // Config config( APPDIR ); |
373 | config.setGroup( "View" ); | 373 | config.setGroup( "View" ); |
374 | m_debounce = config.readNumEntry("Debounce", 0); | 374 | m_debounce = config.readNumEntry("Debounce", 0); |
375 | #ifdef USEQPE | 375 | #ifdef USEQPE |
376 | m_bFloatingDialog = config.readBoolEntry("FloatDialogs", false); | 376 | m_bFloatingDialog = config.readBoolEntry("FloatDialogs", false); |
377 | #else | 377 | #else |
378 | m_bFloatingDialog = config.readBoolEntry("FloatDialogs", true); | 378 | m_bFloatingDialog = config.readBoolEntry("FloatDialogs", true); |
379 | #endif | 379 | #endif |
380 | reader->bstripcr = config.readBoolEntry( "StripCr", true ); | 380 | reader->bstripcr = config.readBoolEntry( "StripCr", true ); |
381 | reader->bfulljust = config.readBoolEntry( "FullJust", false ); | 381 | reader->bfulljust = config.readBoolEntry( "FullJust", false ); |
382 | reader->setextraspace(config.readNumEntry( "ExtraSpace", 0 )); | 382 | reader->setextraspace(config.readNumEntry( "ExtraSpace", 0 )); |
383 | reader->setlead(config.readNumEntry( "ExtraLead", 0 )); | 383 | reader->setlead(config.readNumEntry( "ExtraLead", 0 )); |
384 | reader->btextfmt = config.readBoolEntry( "TextFmt", false ); | 384 | reader->btextfmt = config.readBoolEntry( "TextFmt", false ); |
385 | reader->bautofmt = config.readBoolEntry( "AutoFmt", true ); | 385 | reader->bautofmt = config.readBoolEntry( "AutoFmt", true ); |
386 | reader->bstriphtml = config.readBoolEntry( "StripHtml", false ); | 386 | reader->bstriphtml = config.readBoolEntry( "StripHtml", false ); |
387 | reader->bpeanut = config.readBoolEntry( "Peanut", false ); | 387 | reader->bpeanut = config.readBoolEntry( "Peanut", false ); |
388 | reader->bdehyphen = config.readBoolEntry( "Dehyphen", false ); | 388 | reader->bdehyphen = config.readBoolEntry( "Dehyphen", false ); |
389 | reader->bdepluck = config.readBoolEntry( "Depluck", false ); | 389 | reader->bdepluck = config.readBoolEntry( "Depluck", false ); |
390 | reader->bdejpluck = config.readBoolEntry( "Dejpluck", false ); | 390 | reader->bdejpluck = config.readBoolEntry( "Dejpluck", false ); |
391 | reader->bonespace = config.readBoolEntry( "OneSpace", false ); | 391 | reader->bonespace = config.readBoolEntry( "OneSpace", false ); |
392 | reader->bunindent = config.readBoolEntry( "Unindent", false ); | 392 | reader->bunindent = config.readBoolEntry( "Unindent", false ); |
393 | reader->brepara = config.readBoolEntry( "Repara", false ); | 393 | reader->brepara = config.readBoolEntry( "Repara", false ); |
394 | reader->bdblspce = config.readBoolEntry( "DoubleSpace", false ); | 394 | reader->bdblspce = config.readBoolEntry( "DoubleSpace", false ); |
395 | reader->bindenter = config.readNumEntry( "Indent", 0 ); | 395 | reader->bindenter = config.readNumEntry( "Indent", 0 ); |
396 | reader->m_textsize = config.readNumEntry( "FontSize", 12 ); | 396 | reader->m_textsize = config.readNumEntry( "FontSize", 12 ); |
397 | reader->m_delay = config.readNumEntry( "ScrollDelay", 5184); | 397 | reader->m_delay = config.readNumEntry( "ScrollDelay", 5184); |
398 | reader->m_lastfile = config.readEntry( "LastFile", QString::null ); | 398 | reader->m_lastfile = config.readEntry( "LastFile", QString::null ); |
399 | reader->m_lastposn = config.readNumEntry( "LastPosn", 0 ); | 399 | reader->m_lastposn = config.readNumEntry( "LastPosn", 0 ); |
400 | reader->m_bpagemode = config.readBoolEntry( "PageMode", true ); | 400 | reader->m_bpagemode = config.readBoolEntry( "PageMode", true ); |
401 | reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false); | 401 | reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false); |
402 | reader->m_swapmouse = config.readBoolEntry( "SwapMouse", false); | 402 | reader->m_swapmouse = config.readBoolEntry( "SwapMouse", false); |
403 | reader->m_fontname = config.readEntry( "Fontname", "helvetica" ); | 403 | reader->m_fontname = config.readEntry( "Fontname", "helvetica" ); |
404 | reader->m_encd = config.readNumEntry( "Encoding", 0 ); | 404 | reader->m_encd = config.readNumEntry( "Encoding", 0 ); |
405 | reader->m_charpc = config.readNumEntry( "CharSpacing", 100 ); | 405 | reader->m_charpc = config.readNumEntry( "CharSpacing", 100 ); |
406 | reader->m_overlap = config.readNumEntry( "Overlap", 0 ); | 406 | reader->m_overlap = config.readNumEntry( "Overlap", 0 ); |
407 | reader->m_border = config.readNumEntry( "Margin", 6 ); | 407 | reader->m_border = config.readNumEntry( "Margin", 6 ); |
408 | #ifdef REPALM | 408 | #ifdef REPALM |
409 | reader->brepalm = config.readBoolEntry( "Repalm", true ); | 409 | reader->brepalm = config.readBoolEntry( "Repalm", true ); |
410 | #endif | 410 | #endif |
411 | reader->bremap = config.readBoolEntry( "Remap", true ); | 411 | reader->bremap = config.readBoolEntry( "Remap", true ); |
412 | reader->bmakebold = config.readBoolEntry( "MakeBold", false ); | 412 | reader->bmakebold = config.readBoolEntry( "MakeBold", false ); |
413 | reader->setContinuous(config.readBoolEntry( "Continuous", true )); | 413 | reader->setContinuous(config.readBoolEntry( "Continuous", true )); |
414 | m_targetapp = config.readEntry( "TargetApp", QString::null ); | 414 | m_targetapp = config.readEntry( "TargetApp", QString::null ); |
415 | m_targetmsg = config.readEntry( "TargetMsg", QString::null ); | 415 | m_targetmsg = config.readEntry( "TargetMsg", QString::null ); |
416 | #ifdef _SCROLLPIPE | 416 | #ifdef _SCROLLPIPE |
417 | reader->m_pipetarget = config.readEntry( "PipeTarget", QString::null ); | 417 | reader->m_pipetarget = config.readEntry( "PipeTarget", QString::null ); |
418 | reader->m_pauseAfterEachPara = config.readBoolEntry( "PauseAfterPara", true ); | 418 | reader->m_pauseAfterEachPara = config.readBoolEntry( "PauseAfterPara", true ); |
419 | #endif | 419 | #endif |
420 | m_twoTouch = config.readBoolEntry( "TwoTouch", false); | 420 | m_twoTouch = config.readBoolEntry( "TwoTouch", false); |
421 | m_doAnnotation = config.readBoolEntry( "Annotation", false); | 421 | m_doAnnotation = config.readBoolEntry( "Annotation", false); |
422 | m_doDictionary = config.readBoolEntry( "Dictionary", false); | 422 | m_doDictionary = config.readBoolEntry( "Dictionary", false); |
423 | m_doClipboard = config.readBoolEntry( "Clipboard", false); | 423 | m_doClipboard = config.readBoolEntry( "Clipboard", false); |
424 | m_spaceTarget = (ActionTypes)config.readNumEntry("SpaceTarget", cesAutoScroll); | 424 | m_spaceTarget = (ActionTypes)config.readNumEntry("SpaceTarget", cesAutoScroll); |
425 | m_escapeTarget = (ActionTypes)config.readNumEntry("EscapeTarget", cesNone); | 425 | m_escapeTarget = (ActionTypes)config.readNumEntry("EscapeTarget", cesNone); |
426 | m_returnTarget = (ActionTypes)config.readNumEntry("ReturnTarget", cesFullScreen); | 426 | m_returnTarget = (ActionTypes)config.readNumEntry("ReturnTarget", cesFullScreen); |
427 | m_leftTarget = (ActionTypes)config.readNumEntry("LeftTarget", cesZoomOut); | 427 | m_leftTarget = (ActionTypes)config.readNumEntry("LeftTarget", cesZoomOut); |
428 | m_rightTarget = (ActionTypes)config.readNumEntry("RightTarget", cesZoomIn); | 428 | m_rightTarget = (ActionTypes)config.readNumEntry("RightTarget", cesZoomIn); |
429 | m_upTarget = (ActionTypes)config.readNumEntry("UpTarget", cesPageUp); | 429 | m_upTarget = (ActionTypes)config.readNumEntry("UpTarget", cesPageUp); |
430 | m_downTarget = (ActionTypes)config.readNumEntry("DownTarget", cesPageDown); | 430 | m_downTarget = (ActionTypes)config.readNumEntry("DownTarget", cesPageDown); |
431 | 431 | ||
432 | m_leftScroll = config.readBoolEntry("LeftScroll", false); | 432 | m_leftScroll = config.readBoolEntry("LeftScroll", false); |
433 | m_rightScroll = config.readBoolEntry("RightScroll", false); | 433 | m_rightScroll = config.readBoolEntry("RightScroll", false); |
434 | m_upScroll = config.readBoolEntry("UpScroll", true); | 434 | m_upScroll = config.readBoolEntry("UpScroll", true); |
435 | m_downScroll = config.readBoolEntry("DownScroll", true); | 435 | m_downScroll = config.readBoolEntry("DownScroll", true); |
436 | 436 | ||
437 | m_propogatefontchange = config.readBoolEntry( "RequestorFontChange", false); | 437 | m_propogatefontchange = config.readBoolEntry( "RequestorFontChange", false); |
438 | reader->setBaseSize(config.readNumEntry( "Basesize", 10 )); | 438 | reader->setBaseSize(config.readNumEntry( "Basesize", 10 )); |
439 | 439 | ||
440 | #ifndef USEQPE | 440 | #ifndef USEQPE |
441 | config.setGroup( "Geometry" ); | 441 | config.setGroup( "Geometry" ); |
442 | setGeometry(0,0, | 442 | setGeometry(0,0, |
443 | config.readNumEntry( "width", QApplication::desktop()->width()/2 ), | 443 | config.readNumEntry( "width", QApplication::desktop()->width()/2 ), |
444 | config.readNumEntry( "height", QApplication::desktop()->height()/2 )); | 444 | config.readNumEntry( "height", QApplication::desktop()->height()/2 )); |
445 | move( | 445 | move( |
446 | config.readNumEntry( "x", 20 ), | 446 | config.readNumEntry( "x", 20 ), |
447 | config.readNumEntry( "y", 20 )); | 447 | config.readNumEntry( "y", 20 )); |
448 | #endif | 448 | #endif |
449 | 449 | ||
450 | 450 | ||
451 | 451 | ||
452 | setTwoTouch(m_twoTouch); | 452 | setTwoTouch(m_twoTouch); |
453 | 453 | ||
454 | connect( reader, SIGNAL( OnShowPicture(QImage&) ), this, SLOT( showgraphic(QImage&) ) ); | 454 | connect( reader, SIGNAL( OnShowPicture(QImage&) ), this, SLOT( showgraphic(QImage&) ) ); |
455 | 455 | ||
456 | connect( reader, SIGNAL( OnRedraw() ), this, SLOT( OnRedraw() ) ); | 456 | connect( reader, SIGNAL( OnRedraw() ), this, SLOT( OnRedraw() ) ); |
457 | connect( reader, SIGNAL( OnWordSelected(const QString&, size_t, const QString&) ), this, SLOT( OnWordSelected(const QString&, size_t, const QString&) ) ); | 457 | connect( reader, SIGNAL( OnWordSelected(const QString&, size_t, const QString&) ), this, SLOT( OnWordSelected(const QString&, size_t, const QString&) ) ); |
458 | connect( reader, SIGNAL( OnURLSelected(const QString&) ), this, SLOT( OnURLSelected(const QString&) ) ); | 458 | connect( reader, SIGNAL( OnURLSelected(const QString&) ), this, SLOT( OnURLSelected(const QString&) ) ); |
459 | editorStack->addWidget( reader, get_unique_id() ); | 459 | editorStack->addWidget( reader, get_unique_id() ); |
460 | 460 | ||
461 | m_preferences_action = new QAction( tr( "Configuration" ), geticon( "SettingsIcon" ), QString::null, 0, this, NULL); | 461 | m_preferences_action = new QAction( tr( "Configuration" ), geticon( "SettingsIcon" ), QString::null, 0, this, NULL); |
462 | connect( m_preferences_action, SIGNAL( activated() ), this, SLOT( showprefs() ) ); | 462 | connect( m_preferences_action, SIGNAL( activated() ), this, SLOT( showprefs() ) ); |
463 | m_preferences_action->addTo( settings ); | 463 | m_preferences_action->addTo( settings ); |
464 | 464 | ||
465 | m_saveconfig_action = new QAction( tr( "Save Config" ), QString::null, 0, this, NULL); | 465 | m_saveconfig_action = new QAction( tr( "Save Config" ), QString::null, 0, this, NULL); |
466 | connect( m_saveconfig_action, SIGNAL( activated() ), this, SLOT( SaveConfig() ) ); | 466 | connect( m_saveconfig_action, SIGNAL( activated() ), this, SLOT( SaveConfig() ) ); |
467 | m_saveconfig_action->addTo( settings ); | 467 | m_saveconfig_action->addTo( settings ); |
468 | 468 | ||
469 | m_loadconfig_action = new QAction( tr( "Load Config" ), QString::null, 0, this, NULL); | 469 | m_loadconfig_action = new QAction( tr( "Load Config" ), QString::null, 0, this, NULL); |
470 | connect( m_loadconfig_action, SIGNAL( activated() ), this, SLOT( LoadConfig() ) ); | 470 | connect( m_loadconfig_action, SIGNAL( activated() ), this, SLOT( LoadConfig() ) ); |
471 | m_loadconfig_action->addTo( settings ); | 471 | m_loadconfig_action->addTo( settings ); |
472 | 472 | ||
473 | m_tidyconfig_action = new QAction( tr( "Delete Config" ), QString::null, 0, this, NULL); | 473 | m_tidyconfig_action = new QAction( tr( "Delete Config" ), QString::null, 0, this, NULL); |
474 | connect( m_tidyconfig_action, SIGNAL( activated() ), this, SLOT( TidyConfig() ) ); | 474 | connect( m_tidyconfig_action, SIGNAL( activated() ), this, SLOT( TidyConfig() ) ); |
475 | m_tidyconfig_action->addTo( settings ); | 475 | m_tidyconfig_action->addTo( settings ); |
476 | 476 | ||
477 | settings->insertSeparator(); | 477 | settings->insertSeparator(); |
478 | m_toolbarprefs_action = new QAction( tr( "Toolbars" ), QString::null, 0, this, NULL); | 478 | m_toolbarprefs_action = new QAction( tr( "Toolbars" ), QString::null, 0, this, NULL); |
479 | connect( m_toolbarprefs_action, SIGNAL( activated() ), this, SLOT( showtoolbarprefs() ) ); | 479 | connect( m_toolbarprefs_action, SIGNAL( activated() ), this, SLOT( showtoolbarprefs() ) ); |
480 | m_toolbarprefs_action->addTo( settings ); | 480 | m_toolbarprefs_action->addTo( settings ); |
481 | 481 | ||
482 | m_open_action = new QAction( tr( "Open" ), geticon( "fileopen" ), QString::null, 0, this, 0 ); | 482 | m_open_action = new QAction( tr( "Open" ), geticon( "fileopen" ), QString::null, 0, this, 0 ); |
483 | connect( m_open_action, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 483 | connect( m_open_action, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
484 | m_open_action->addTo( file ); | 484 | m_open_action->addTo( file ); |
485 | 485 | ||
486 | m_close_action = new QAction( tr( "Close" ), geticon( "close" ), QString::null, 0, this, 0 ); | 486 | m_close_action = new QAction( tr( "Close" ), geticon( "close" ), QString::null, 0, this, 0 ); |
487 | connect( m_close_action, SIGNAL( activated() ), this, SLOT( fileClose() ) ); | 487 | connect( m_close_action, SIGNAL( activated() ), this, SLOT( fileClose() ) ); |
488 | m_close_action->addTo( file ); | 488 | m_close_action->addTo( file ); |
489 | 489 | ||
490 | #ifdef _SCRIPT | 490 | #ifdef _SCRIPT |
491 | a = new QAction( tr( "Run Script" ), QString::null, 0, this, NULL); | 491 | a = new QAction( tr( "Run Script" ), QString::null, 0, this, NULL); |
492 | connect( a, SIGNAL( activated() ), this, SLOT( RunScript() ) ); | 492 | connect( a, SIGNAL( activated() ), this, SLOT( RunScript() ) ); |
493 | a->addTo( file ); | 493 | a->addTo( file ); |
494 | #endif | 494 | #endif |
495 | /* | 495 | /* |
496 | a = new QAction( tr( "Revert" ), geticon( "close" ), QString::null, 0, this, 0 ); | 496 | a = new QAction( tr( "Revert" ), geticon( "close" ), QString::null, 0, this, 0 ); |
497 | connect( a, SIGNAL( activated() ), this, SLOT( fileRevert() ) ); | 497 | connect( a, SIGNAL( activated() ), this, SLOT( fileRevert() ) ); |
498 | a->addTo( file ); | 498 | a->addTo( file ); |
499 | 499 | ||
500 | a = new QAction( tr( "Cut" ), geticon( "cut" ), QString::null, 0, this, 0 ); | 500 | a = new QAction( tr( "Cut" ), geticon( "cut" ), QString::null, 0, this, 0 ); |
501 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 501 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
502 | a->addTo( filebar() ); | 502 | a->addTo( filebar() ); |
503 | a->addTo( edit ); | 503 | a->addTo( edit ); |
504 | */ | 504 | */ |
505 | 505 | ||
506 | m_info_action = new QAction( tr( "Info" ), geticon( "UtilsIcon" ), QString::null, 0, this, NULL); | 506 | m_info_action = new QAction( tr( "Info" ), geticon( "UtilsIcon" ), QString::null, 0, this, NULL); |
507 | connect( m_info_action, SIGNAL( activated() ), this, SLOT( showinfo() ) ); | 507 | connect( m_info_action, SIGNAL( activated() ), this, SLOT( showinfo() ) ); |
508 | m_info_action->addTo( file ); | 508 | m_info_action->addTo( file ); |
509 | 509 | ||
510 | m_touch_action = new QAction( tr( "Two/One Touch" ), geticon( "1to1" ), QString::null, 0, this, NULL, true ); | 510 | m_touch_action = new QAction( tr( "Two/One Touch" ), geticon( "1to1" ), QString::null, 0, this, NULL, true ); |
511 | connect( m_touch_action, SIGNAL( toggled(bool) ), this, SLOT( setTwoTouch(bool) ) ); | 511 | connect( m_touch_action, SIGNAL( toggled(bool) ), this, SLOT( setTwoTouch(bool) ) ); |
512 | m_touch_action->setOn(m_twoTouch); | 512 | m_touch_action->setOn(m_twoTouch); |
513 | m_touch_action->addTo( file ); | 513 | m_touch_action->addTo( file ); |
514 | 514 | ||
515 | m_find_action = new QAction( tr( "Find..." ), geticon( "find" ), QString::null, 0, this, NULL); | 515 | m_find_action = new QAction( tr( "Find..." ), geticon( "find" ), QString::null, 0, this, NULL); |
516 | connect( m_find_action, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 516 | connect( m_find_action, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
517 | file->insertSeparator(); | 517 | file->insertSeparator(); |
518 | // a->addTo( bar ); | 518 | // a->addTo( bar ); |
519 | m_find_action->addTo( file ); | 519 | m_find_action->addTo( file ); |
520 | 520 | ||
521 | m_exportlinks_action = new QAction( tr( "Export Links" ), QString::null, 0, this, NULL); | 521 | m_exportlinks_action = new QAction( tr( "Export Links" ), QString::null, 0, this, NULL); |
522 | connect( m_exportlinks_action, SIGNAL( activated() ), this, SLOT( ExportLinks() ) ); | 522 | connect( m_exportlinks_action, SIGNAL( activated() ), this, SLOT( ExportLinks() ) ); |
523 | m_exportlinks_action->addTo( file ); | 523 | m_exportlinks_action->addTo( file ); |
524 | 524 | ||
525 | m_scrollButton = new QAction( tr( "Scroll" ), getmyicon( "panel-arrow-down" ), QString::null, 0, this, 0, true ); | 525 | m_scrollButton = new QAction( tr( "Scroll" ), getmyicon( "panel-arrow-down" ), QString::null, 0, this, 0, true ); |
526 | connect( m_scrollButton, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) ); | 526 | connect( m_scrollButton, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) ); |
527 | m_scrollButton->addTo(navigation); | 527 | m_scrollButton->addTo(navigation); |
528 | m_scrollButton->setOn(false); | 528 | m_scrollButton->setOn(false); |
529 | 529 | ||
530 | m_start_action = new QAction( tr( "Goto Start" ), geticon( "start" ), QString::null, 0, this, NULL); | 530 | m_start_action = new QAction( tr( "Goto Start" ), geticon( "start" ), QString::null, 0, this, NULL); |
531 | connect( m_start_action, SIGNAL( activated() ), this, SLOT( gotoStart() ) ); | 531 | connect( m_start_action, SIGNAL( activated() ), this, SLOT( gotoStart() ) ); |
532 | m_start_action->addTo(navigation); | 532 | m_start_action->addTo(navigation); |
533 | 533 | ||
534 | m_end_action = new QAction( tr( "Goto End" ), geticon( "finish" ), QString::null, 0, this, NULL); | 534 | m_end_action = new QAction( tr( "Goto End" ), geticon( "finish" ), QString::null, 0, this, NULL); |
535 | connect( m_end_action, SIGNAL( activated() ), this, SLOT( gotoEnd() ) ); | 535 | connect( m_end_action, SIGNAL( activated() ), this, SLOT( gotoEnd() ) ); |
536 | m_end_action->addTo(navigation); | 536 | m_end_action->addTo(navigation); |
537 | 537 | ||
538 | m_jump_action = new QAction( tr( "Jump" ), geticon( "rotate" ), QString::null, 0, this, NULL); | 538 | m_jump_action = new QAction( tr( "Jump" ), geticon( "rotate" ), QString::null, 0, this, NULL); |
539 | connect( m_jump_action, SIGNAL( activated() ), this, SLOT( jump() ) ); | 539 | connect( m_jump_action, SIGNAL( activated() ), this, SLOT( jump() ) ); |
540 | m_jump_action->addTo(navigation); | 540 | m_jump_action->addTo(navigation); |
541 | 541 | ||
542 | m_pageline_action = new QAction( tr( "Page/Line Scroll" ), geticon( "pass" ), QString::null, 0, this, NULL, true ); | 542 | m_pageline_action = new QAction( tr( "Page/Line Scroll" ), geticon( "pass" ), QString::null, 0, this, NULL, true ); |
543 | connect( m_pageline_action, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) ); | 543 | connect( m_pageline_action, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) ); |
544 | m_pageline_action->addTo(navigation); | 544 | m_pageline_action->addTo(navigation); |
545 | m_pageline_action->setOn(reader->m_bpagemode); | 545 | m_pageline_action->setOn(reader->m_bpagemode); |
546 | 546 | ||
547 | m_pageup_action = new QAction( tr( "Up" ), geticon( "up" ), QString::null, 0, this, 0 ); | 547 | m_pageup_action = new QAction( tr( "Up" ), geticon( "up" ), QString::null, 0, this, 0 ); |
548 | connect( m_pageup_action, SIGNAL( activated() ), this, SLOT( pageup() ) ); | 548 | connect( m_pageup_action, SIGNAL( activated() ), this, SLOT( pageup() ) ); |
549 | m_pageup_action->addTo( navigation ); | 549 | m_pageup_action->addTo( navigation ); |
550 | 550 | ||
551 | m_pagedn_action = new QAction( tr( "Down" ), geticon( "down" ), QString::null, 0, this, 0 ); | 551 | m_pagedn_action = new QAction( tr( "Down" ), geticon( "down" ), QString::null, 0, this, 0 ); |
552 | connect( m_pagedn_action, SIGNAL( activated() ), this, SLOT( pagedn() ) ); | 552 | connect( m_pagedn_action, SIGNAL( activated() ), this, SLOT( pagedn() ) ); |
553 | m_pagedn_action->addTo( navigation ); | 553 | m_pagedn_action->addTo( navigation ); |
554 | 554 | ||
555 | m_back_action = new QAction( tr( "Back" ), geticon( "back" ), QString::null, 0, this, 0 ); | 555 | m_back_action = new QAction( tr( "Back" ), geticon( "back" ), QString::null, 0, this, 0 ); |
556 | connect( m_back_action, SIGNAL( activated() ), reader, SLOT( goBack() ) ); | 556 | connect( m_back_action, SIGNAL( activated() ), reader, SLOT( goBack() ) ); |
557 | m_back_action->addTo( navigation ); | 557 | m_back_action->addTo( navigation ); |
558 | 558 | ||
559 | m_home_action = new QAction( tr( "Home" ), geticon( "home" ), QString::null, 0, this, 0 ); | 559 | m_home_action = new QAction( tr( "Home" ), geticon( "home" ), QString::null, 0, this, 0 ); |
560 | connect( m_home_action, SIGNAL( activated() ), reader, SLOT( goHome() ) ); | 560 | connect( m_home_action, SIGNAL( activated() ), reader, SLOT( goHome() ) ); |
561 | m_home_action->addTo( navigation ); | 561 | m_home_action->addTo( navigation ); |
562 | 562 | ||
563 | m_forward_action = new QAction( tr( "Forward" ), geticon( "forward" ), QString::null, 0, this, 0 ); | 563 | m_forward_action = new QAction( tr( "Forward" ), geticon( "forward" ), QString::null, 0, this, 0 ); |
564 | connect( m_forward_action, SIGNAL( activated() ), reader, SLOT( goForward() ) ); | 564 | connect( m_forward_action, SIGNAL( activated() ), reader, SLOT( goForward() ) ); |
565 | m_forward_action->addTo( navigation ); | 565 | m_forward_action->addTo( navigation ); |
566 | 566 | ||
567 | /* | 567 | /* |
568 | a = new QAction( tr( "Find" ), QString::null, 0, this, NULL, true ); | 568 | a = new QAction( tr( "Find" ), QString::null, 0, this, NULL, true ); |
569 | // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) ); | 569 | // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) ); |
570 | a->addTo( file ); | 570 | a->addTo( file ); |
571 | 571 | ||
572 | a = new QAction( tr( "Find Again" ), QString::null, 0, this, NULL, true ); | 572 | a = new QAction( tr( "Find Again" ), QString::null, 0, this, NULL, true ); |
573 | // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) ); | 573 | // connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) ); |
574 | a->addTo( file ); | 574 | a->addTo( file ); |
575 | */ | 575 | */ |
576 | 576 | ||
577 | // file->insertSeparator(); | 577 | // file->insertSeparator(); |
578 | 578 | ||
579 | #ifdef _SCROLLPIPE | 579 | #ifdef _SCROLLPIPE |
580 | 580 | ||
581 | QActionGroup* ag = new QActionGroup(this); | 581 | QActionGroup* ag = new QActionGroup(this); |
582 | ag->setExclusive(false); | 582 | ag->setExclusive(false); |
583 | spacemenu = new QPopupMenu(this); | 583 | spacemenu = new QPopupMenu(this); |
584 | file->insertItem( tr( "Scrolling" ), spacemenu ); | 584 | file->insertItem( tr( "Scrolling" ), spacemenu ); |
585 | 585 | ||
586 | a = new QAction( tr( "Set Target" ), QString::null, 0, ag, NULL); | 586 | a = new QAction( tr( "Set Target" ), QString::null, 0, ag, NULL); |
587 | connect( a, SIGNAL( activated() ), this, SLOT( setpipetarget() ) ); | 587 | connect( a, SIGNAL( activated() ), this, SLOT( setpipetarget() ) ); |
588 | 588 | ||
589 | a = new QAction( tr( "Pause Paras" ), QString::null, 0, ag, NULL, true ); | 589 | a = new QAction( tr( "Pause Paras" ), QString::null, 0, ag, NULL, true ); |
590 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( setpause(bool) ) ); | 590 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( setpause(bool) ) ); |
591 | a->setOn(reader->m_pauseAfterEachPara); | 591 | a->setOn(reader->m_pauseAfterEachPara); |
592 | 592 | ||
593 | ag->addTo(spacemenu); | 593 | ag->addTo(spacemenu); |
594 | // file->insertSeparator(); | 594 | // file->insertSeparator(); |
595 | 595 | ||
596 | #endif | 596 | #endif |
597 | 597 | ||
598 | /* | 598 | /* |
599 | a = new QAction( tr( "Import" ), QString::null, 0, this, NULL ); | 599 | a = new QAction( tr( "Import" ), QString::null, 0, this, NULL ); |
600 | connect( a, SIGNAL( activated() ), this, SLOT( importFiles() ) ); | 600 | connect( a, SIGNAL( activated() ), this, SLOT( importFiles() ) ); |
601 | a->addTo( file ); | 601 | a->addTo( file ); |
602 | */ | 602 | */ |
603 | 603 | ||
604 | /* | 604 | /* |
605 | a = new QAction( tr( "Paste" ), geticon( "paste" ), QString::null, 0, this, 0 ); | 605 | a = new QAction( tr( "Paste" ), geticon( "paste" ), QString::null, 0, this, 0 ); |
606 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 606 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
607 | a->addTo( fileBar ); | 607 | a->addTo( fileBar ); |
608 | a->addTo( edit ); | 608 | a->addTo( edit ); |
609 | */ | 609 | */ |
610 | 610 | ||
611 | // a = new QAction( tr( "Find..." ), geticon( "find" ), QString::null, 0, this, 0 ); | 611 | // a = new QAction( tr( "Find..." ), geticon( "find" ), QString::null, 0, this, 0 ); |
612 | 612 | ||
613 | m_fullscreen = false; | 613 | m_fullscreen = false; |
614 | m_actFullscreen = new QAction( tr( "Fullscreen" ), geticon( "fullscreen" ), QString::null, 0, this, NULL, true ); | 614 | m_actFullscreen = new QAction( tr( "Fullscreen" ), geticon( "fullscreen" ), QString::null, 0, this, NULL, true ); |
615 | connect( m_actFullscreen, SIGNAL( toggled(bool) ), this, SLOT( setfullscreen(bool) ) ); | 615 | connect( m_actFullscreen, SIGNAL( toggled(bool) ), this, SLOT( setfullscreen(bool) ) ); |
616 | m_actFullscreen->setOn(m_fullscreen); | 616 | m_actFullscreen->setOn(m_fullscreen); |
617 | m_actFullscreen->addTo( view ); | 617 | m_actFullscreen->addTo( view ); |
618 | 618 | ||
619 | view->insertSeparator(); | 619 | view->insertSeparator(); |
620 | 620 | ||
621 | m_zoomin_action = new QAction( tr( "Zoom In" ), geticon( "zoom" ), QString::null, 0, this); | 621 | m_zoomin_action = new QAction( tr( "Zoom In" ), geticon( "zoom" ), QString::null, 0, this); |
622 | connect( m_zoomin_action, SIGNAL( activated() ), this, SLOT( zoomin() ) ); | 622 | connect( m_zoomin_action, SIGNAL( activated() ), this, SLOT( zoomin() ) ); |
623 | m_zoomin_action->addTo( view ); | 623 | m_zoomin_action->addTo( view ); |
624 | 624 | ||
625 | m_zoomout_action = new QAction( tr( "Zoom Out" ), geticon( "mag" ), QString::null, 0, this); | 625 | m_zoomout_action = new QAction( tr( "Zoom Out" ), geticon( "mag" ), QString::null, 0, this); |
626 | connect( m_zoomout_action, SIGNAL( activated() ), this, SLOT( zoomout() ) ); | 626 | connect( m_zoomout_action, SIGNAL( activated() ), this, SLOT( zoomout() ) ); |
627 | m_zoomout_action->addTo( view ); | 627 | m_zoomout_action->addTo( view ); |
628 | 628 | ||
629 | view->insertSeparator(); | 629 | view->insertSeparator(); |
630 | m_setfont_action = new QAction( tr( "Set Font" ), getmyicon( "font" ), QString::null, 0, this); | 630 | m_setfont_action = new QAction( tr( "Set Font" ), getmyicon( "font" ), QString::null, 0, this); |
631 | connect( m_setfont_action, SIGNAL( activated() ), this, SLOT( setfont() ) ); | 631 | connect( m_setfont_action, SIGNAL( activated() ), this, SLOT( setfont() ) ); |
632 | m_setfont_action->addTo( view ); | 632 | m_setfont_action->addTo( view ); |
633 | 633 | ||
634 | view->insertSeparator(); | 634 | view->insertSeparator(); |
635 | m_setenc_action = new QAction( tr( "Set Encoding" ), getmyicon( "charset" ), QString::null, 0, this); | 635 | m_setenc_action = new QAction( tr( "Set Encoding" ), getmyicon( "charset" ), QString::null, 0, this); |
636 | connect( m_setenc_action, SIGNAL( activated() ), this, SLOT( chooseencoding() ) ); | 636 | connect( m_setenc_action, SIGNAL( activated() ), this, SLOT( chooseencoding() ) ); |
637 | m_setenc_action->addTo( view ); | 637 | m_setenc_action->addTo( view ); |
638 | 638 | ||
639 | m_setmono_action = new QAction( tr( "Ideogram" ), getmyicon( "ideogram" ), QString::null, 0, this, NULL, true); | 639 | m_setmono_action = new QAction( tr( "Ideogram" ), getmyicon( "ideogram" ), QString::null, 0, this, NULL, true); |
640 | connect( m_setmono_action, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) ); | 640 | connect( m_setmono_action, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) ); |
641 | m_setmono_action->addTo( view ); | 641 | m_setmono_action->addTo( view ); |
642 | m_setmono_action->setOn(reader->m_bMonoSpaced); | 642 | m_setmono_action->setOn(reader->m_bMonoSpaced); |
643 | 643 | ||
644 | 644 | ||
645 | // a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true ); | 645 | // a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true ); |
646 | // a = new QAction( tr( "Zoom" ), geticon( "mag" ), QString::null, 0, this, 0 ); | 646 | // a = new QAction( tr( "Zoom" ), geticon( "mag" ), QString::null, 0, this, 0 ); |
647 | 647 | ||
648 | 648 | ||
649 | 649 | ||
650 | // a->addTo( filebar() ); | 650 | // a->addTo( filebar() ); |
651 | // view->insertSeparator(); | 651 | // view->insertSeparator(); |
652 | 652 | ||
653 | /* | 653 | /* |
654 | a = new QAction( tr( "Ideogram/Word" ), QString::null, 0, this, NULL, true ); | 654 | a = new QAction( tr( "Ideogram/Word" ), QString::null, 0, this, NULL, true ); |
655 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) ); | 655 | connect( a, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) ); |
656 | a->setOn(reader->m_bMonoSpaced); | 656 | a->setOn(reader->m_bMonoSpaced); |
657 | a->addTo( view ); | 657 | a->addTo( view ); |
658 | */ | 658 | */ |
659 | /* | 659 | /* |
660 | a = new QAction( tr( "Set Width" ), QString::null, 0, this, NULL); | 660 | a = new QAction( tr( "Set Width" ), QString::null, 0, this, NULL); |
661 | connect( a, SIGNAL( activated() ), this, SLOT( setspacing() ) ); | 661 | connect( a, SIGNAL( activated() ), this, SLOT( setspacing() ) ); |
662 | a->addTo( view ); | 662 | a->addTo( view ); |
663 | */ | 663 | */ |
664 | 664 | ||
665 | m_mark_action = new QAction( tr( "Bookmark" ), getmyicon( "bookmark" ), QString::null, 0, this, NULL); | 665 | m_mark_action = new QAction( tr( "Bookmark" ), getmyicon( "bookmark" ), QString::null, 0, this, NULL); |
666 | connect( m_mark_action, SIGNAL( activated() ), this, SLOT( addbkmk() ) ); | 666 | connect( m_mark_action, SIGNAL( activated() ), this, SLOT( addbkmk() ) ); |
667 | m_mark_action->addTo( marks ); | 667 | m_mark_action->addTo( marks ); |
668 | 668 | ||
669 | m_annotate_action = new QAction( tr( "Annotate" ), getmyicon( "annotate" ), QString::null, 0, this, NULL); | 669 | m_annotate_action = new QAction( tr( "Annotate" ), getmyicon( "annotate" ), QString::null, 0, this, NULL); |
670 | connect( m_annotate_action, SIGNAL( activated() ), this, SLOT( addanno() ) ); | 670 | connect( m_annotate_action, SIGNAL( activated() ), this, SLOT( addanno() ) ); |
671 | m_annotate_action->addTo( marks ); | 671 | m_annotate_action->addTo( marks ); |
672 | 672 | ||
673 | m_goto_action = new QAction( tr( "Goto" ), getmyicon( "bookmark_goto" ), QString::null, 0, this, NULL, false ); | 673 | m_goto_action = new QAction( tr( "Goto" ), getmyicon( "bookmark_goto" ), QString::null, 0, this, NULL, false ); |
674 | connect( m_goto_action, SIGNAL( activated() ), this, SLOT( do_gotomark() ) ); | 674 | connect( m_goto_action, SIGNAL( activated() ), this, SLOT( do_gotomark() ) ); |
675 | m_goto_action->addTo( marks ); | 675 | m_goto_action->addTo( marks ); |
676 | 676 | ||
677 | m_delete_action = new QAction( tr( "Delete" ), getmyicon( "bookmark_delete" ), QString::null, 0, this, NULL); | 677 | m_delete_action = new QAction( tr( "Delete" ), getmyicon( "bookmark_delete" ), QString::null, 0, this, NULL); |
678 | connect( m_delete_action, SIGNAL( activated() ), this, SLOT( do_delmark() ) ); | 678 | connect( m_delete_action, SIGNAL( activated() ), this, SLOT( do_delmark() ) ); |
679 | m_delete_action->addTo( marks ); | 679 | m_delete_action->addTo( marks ); |
680 | 680 | ||
681 | m_autogen_action = new QAction( tr( "Autogen" ), geticon( "exec" ), QString::null, 0, this, NULL, false ); | 681 | m_autogen_action = new QAction( tr( "Autogen" ), geticon( "exec" ), QString::null, 0, this, NULL, false ); |
682 | connect( m_autogen_action, SIGNAL( activated() ), this, SLOT( do_autogen() ) ); | 682 | connect( m_autogen_action, SIGNAL( activated() ), this, SLOT( do_autogen() ) ); |
683 | marks->insertSeparator(); | 683 | marks->insertSeparator(); |
684 | m_autogen_action->addTo( marks ); | 684 | m_autogen_action->addTo( marks ); |
685 | 685 | ||
686 | m_clear_action = new QAction( tr( "Clear" ), getmyicon( "bookmark_clear" ), QString::null, 0, this, NULL); | 686 | m_clear_action = new QAction( tr( "Clear" ), getmyicon( "bookmark_clear" ), QString::null, 0, this, NULL); |
687 | connect( m_clear_action, SIGNAL( activated() ), this, SLOT( clearBkmkList() ) ); | 687 | connect( m_clear_action, SIGNAL( activated() ), this, SLOT( clearBkmkList() ) ); |
688 | m_clear_action->addTo( marks ); | 688 | m_clear_action->addTo( marks ); |
689 | 689 | ||
690 | m_save_action = new QAction( tr( "Save" ), getmyicon( "bookmark_save" ), QString::null, 0, this, NULL ); | 690 | m_save_action = new QAction( tr( "Save" ), getmyicon( "bookmark_save" ), QString::null, 0, this, NULL ); |
691 | connect( m_save_action, SIGNAL( activated() ), this, SLOT( savebkmks() ) ); | 691 | connect( m_save_action, SIGNAL( activated() ), this, SLOT( savebkmks() ) ); |
692 | m_save_action->addTo( marks ); | 692 | m_save_action->addTo( marks ); |
693 | 693 | ||
694 | m_tidy_action = new QAction( tr( "Tidy" ), getmyicon( "bookmark_tidy" ), QString::null, 0, this, NULL); | 694 | m_tidy_action = new QAction( tr( "Tidy" ), getmyicon( "bookmark_tidy" ), QString::null, 0, this, NULL); |
695 | connect( m_tidy_action, SIGNAL( activated() ), this, SLOT( listBkmkFiles() ) ); | 695 | connect( m_tidy_action, SIGNAL( activated() ), this, SLOT( listBkmkFiles() ) ); |
696 | marks->insertSeparator(); | 696 | marks->insertSeparator(); |
697 | m_tidy_action->addTo( marks ); | 697 | m_tidy_action->addTo( marks ); |
698 | 698 | ||
699 | m_startBlock_action = new QAction( tr( "Start Block" ), geticon( "new" ), QString::null, 0, this, NULL); | 699 | m_startBlock_action = new QAction( tr( "Start Block" ), geticon( "new" ), QString::null, 0, this, NULL); |
700 | connect( m_startBlock_action, SIGNAL( activated() ), this, SLOT( editMark() ) ); | 700 | connect( m_startBlock_action, SIGNAL( activated() ), this, SLOT( editMark() ) ); |
701 | marks->insertSeparator(); | 701 | marks->insertSeparator(); |
702 | m_startBlock_action->addTo( marks ); | 702 | m_startBlock_action->addTo( marks ); |
703 | 703 | ||
704 | m_endBlock_action = new QAction( tr( "Copy Block" ), geticon( "copy" ), QString::null, 0, this, NULL); | 704 | m_endBlock_action = new QAction( tr( "Copy Block" ), geticon( "copy" ), QString::null, 0, this, NULL); |
705 | connect( m_endBlock_action, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 705 | connect( m_endBlock_action, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
706 | m_endBlock_action->addTo( marks ); | 706 | m_endBlock_action->addTo( marks ); |
707 | 707 | ||
708 | m_bkmkAvail = NULL; | 708 | m_bkmkAvail = NULL; |
709 | 709 | ||
710 | 710 | ||
711 | setToolBarsMovable(m_tbmove); | 711 | setToolBarsMovable(m_tbmove); |
712 | addtoolbars(&config); | 712 | addtoolbars(&config); |
713 | 713 | ||
714 | pbar = new QProgressBar(this); | 714 | pbar = new QProgressBar(this); |
715 | pbar->hide(); | 715 | pbar->hide(); |
716 | 716 | ||
717 | searchBar = new QFloatBar( "Search", this, QMainWindow::Top, TRUE ); | 717 | searchBar = new QFloatBar( "Search", this, QMainWindow::Top, TRUE ); |
718 | 718 | ||
719 | searchBar->setHorizontalStretchable( TRUE ); | 719 | searchBar->setHorizontalStretchable( TRUE ); |
720 | 720 | ||
721 | connect(searchBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() )); | 721 | connect(searchBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() )); |
722 | 722 | ||
723 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 723 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
724 | // QFont f("unifont", 16 /*, QFont::Bold*/); | 724 | // QFont f("unifont", 16 /*, QFont::Bold*/); |
725 | // searchEdit->setFont( f ); | 725 | // searchEdit->setFont( f ); |
726 | searchBar->setStretchableWidget( searchEdit ); | 726 | searchBar->setStretchableWidget( searchEdit ); |
727 | 727 | ||
728 | 728 | ||
729 | #ifdef __ISEARCH | 729 | #ifdef __ISEARCH |
730 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 730 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
731 | this, SLOT( search( const QString& ) ) ); | 731 | this, SLOT( search( const QString& ) ) ); |
732 | #else | 732 | #else |
733 | connect( searchEdit, SIGNAL( returnPressed( ) ), | 733 | connect( searchEdit, SIGNAL( returnPressed( ) ), |
734 | this, SLOT( search( ) ) ); | 734 | this, SLOT( search( ) ) ); |
735 | #endif | 735 | #endif |
736 | QAction*a = new QAction( tr( "Find Next" ), geticon( "next" ), QString::null, 0, this, 0 ); | 736 | QAction*a = new QAction( tr( "Find Next" ), geticon( "next" ), QString::null, 0, this, 0 ); |
737 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 737 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
738 | a->addTo( searchBar ); | 738 | a->addTo( searchBar ); |
739 | 739 | ||
740 | a = new QAction( tr( "Close Find" ), geticon( "close" ), QString::null, 0, this, 0 ); | 740 | a = new QAction( tr( "Close Find" ), geticon( "close" ), QString::null, 0, this, 0 ); |
741 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 741 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
742 | a->addTo( searchBar ); | 742 | a->addTo( searchBar ); |
743 | 743 | ||
744 | searchBar->hide(); | 744 | searchBar->hide(); |
745 | 745 | ||
746 | regBar = new QFloatBar( "Autogen", this, QMainWindow::Top, TRUE ); | 746 | regBar = new QFloatBar( "Autogen", this, QMainWindow::Top, TRUE ); |
747 | connect(regBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() )); | 747 | connect(regBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() )); |
748 | 748 | ||
749 | regBar->setHorizontalStretchable( TRUE ); | 749 | regBar->setHorizontalStretchable( TRUE ); |
750 | 750 | ||
751 | regEdit = new QLineEdit( regBar, "regEdit" ); | 751 | regEdit = new QLineEdit( regBar, "regEdit" ); |
752 | // regEdit->setFont( f ); | 752 | // regEdit->setFont( f ); |
753 | 753 | ||
754 | regBar->setStretchableWidget( regEdit ); | 754 | regBar->setStretchableWidget( regEdit ); |
755 | 755 | ||
756 | connect( regEdit, SIGNAL( returnPressed( ) ), | 756 | connect( regEdit, SIGNAL( returnPressed( ) ), |
757 | this, SLOT( do_regaction() ) ); | 757 | this, SLOT( do_regaction() ) ); |
758 | 758 | ||
759 | a = new QAction( tr( "Do Reg" ), geticon( "enter" ), QString::null, 0, this, 0 ); | 759 | a = new QAction( tr( "Do Reg" ), geticon( "enter" ), QString::null, 0, this, 0 ); |
760 | connect( a, SIGNAL( activated() ), this, SLOT( do_regaction() ) ); | 760 | connect( a, SIGNAL( activated() ), this, SLOT( do_regaction() ) ); |
761 | a->addTo( regBar ); | 761 | a->addTo( regBar ); |
762 | 762 | ||
763 | a = new QAction( tr( "Close Edit" ), geticon( "close" ), QString::null, 0, this, 0 ); | 763 | a = new QAction( tr( "Close Edit" ), geticon( "close" ), QString::null, 0, this, 0 ); |
764 | connect( a, SIGNAL( activated() ), this, SLOT( regClose() ) ); | 764 | connect( a, SIGNAL( activated() ), this, SLOT( regClose() ) ); |
765 | a->addTo( regBar ); | 765 | a->addTo( regBar ); |
766 | 766 | ||
767 | regBar->hide(); | 767 | regBar->hide(); |
768 | 768 | ||
769 | m_fontBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE ); | 769 | m_fontBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE ); |
770 | 770 | ||
771 | m_fontBar->setHorizontalStretchable( TRUE ); | 771 | m_fontBar->setHorizontalStretchable( TRUE ); |
772 | 772 | ||
773 | // qDebug("Font selector"); | 773 | // qDebug("Font selector"); |
774 | m_fontSelector = new QComboBox(false, m_fontBar); | 774 | m_fontSelector = new QComboBox(false, m_fontBar); |
775 | m_fontBar->setStretchableWidget( m_fontSelector ); | 775 | m_fontBar->setStretchableWidget( m_fontSelector ); |
776 | { | 776 | { |
777 | #ifndef USEQPE | 777 | #ifndef USEQPE |
778 | QFontDatabase f; | 778 | QFontDatabase f; |
779 | #else | 779 | #else |
780 | FontDatabase f; | 780 | FontDatabase f; |
781 | #endif | 781 | #endif |
782 | QStringList flist = f.families(); | 782 | QStringList flist = f.families(); |
783 | bool realfont = false; | 783 | bool realfont = false; |
784 | for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++) | 784 | for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++) |
785 | { | 785 | { |
786 | if (reader->m_fontname == *nm) | 786 | if (reader->m_fontname == *nm) |
787 | { | 787 | { |
788 | realfont = true; | 788 | realfont = true; |
789 | } | 789 | } |
790 | if ((*nm).contains(FIXEDFONT,false)) reader->m_fontControl.hasCourier(true, *nm); | 790 | if ((*nm).contains(FIXEDFONT,false)) reader->m_fontControl.hasCourier(true, *nm); |
791 | } | 791 | } |
792 | if (!realfont) reader->m_fontname = flist[0]; | 792 | if (!realfont) reader->m_fontname = flist[0]; |
793 | } // delete the FontDatabase!!! | 793 | } // delete the FontDatabase!!! |
794 | connect( m_fontSelector, SIGNAL( activated(const QString& ) ), | 794 | connect( m_fontSelector, SIGNAL( activated(const QString& ) ), |
795 | this, SLOT( do_setfont(const QString&) ) ); | 795 | this, SLOT( do_setfont(const QString&) ) ); |
796 | connect( m_fontSelector, SIGNAL( activated(int ) ), | 796 | connect( m_fontSelector, SIGNAL( activated(int ) ), |
797 | this, SLOT( do_setencoding(int) ) ); | 797 | this, SLOT( do_setencoding(int) ) ); |
798 | 798 | ||
799 | m_fontBar->hide(); | 799 | m_fontBar->hide(); |
800 | m_fontVisible = false; | 800 | m_fontVisible = false; |
801 | #ifdef USEMSGS | 801 | #ifdef USEMSGS |
802 | connect(qApp, SIGNAL( appMessage(const QCString&, const QByteArray& ) ), | 802 | connect(qApp, SIGNAL( appMessage(const QCString&, const QByteArray& ) ), |
803 | this, SLOT( msgHandler(const QCString&, const QByteArray&) ) ); | 803 | this, SLOT( msgHandler(const QCString&, const QByteArray&) ) ); |
804 | #endif | 804 | #endif |
805 | // qDebug("Initing"); | 805 | // qDebug("Initing"); |
806 | reader->init(); | 806 | reader->init(); |
807 | // qDebug("Inited"); | 807 | // qDebug("Inited"); |
808 | // m_buttonAction[m_spaceTarget]->setOn(true); | 808 | // m_buttonAction[m_spaceTarget]->setOn(true); |
809 | // qDebug("fonting"); | 809 | // qDebug("fonting"); |
810 | do_setfont(reader->m_fontname); | 810 | do_setfont(reader->m_fontname); |
811 | if (!reader->m_lastfile.isEmpty()) | 811 | if (!reader->m_lastfile.isEmpty()) |
812 | { | 812 | { |
813 | //qDebug("doclnk"); | 813 | //qDebug("doclnk"); |
814 | //doc = new DocLnk(reader->m_lastfile); | 814 | //doc = new DocLnk(reader->m_lastfile); |
815 | //qDebug("doclnk done"); | 815 | //qDebug("doclnk done"); |
816 | if (pOpenlist != NULL) | 816 | if (pOpenlist != NULL) |
817 | { | 817 | { |
818 | 818 | ||
819 | /* | 819 | /* |
820 | int ind = 0; | 820 | int ind = 0; |
821 | Bkmk* p = (*pOpenlist)[ind]; | 821 | Bkmk* p = (*pOpenlist)[ind]; |
822 | while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile) | 822 | while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile) |
823 | { | 823 | { |
824 | p = (*pOpenlist)[++ind]; | 824 | p = (*pOpenlist)[++ind]; |
825 | } | 825 | } |
826 | */ | 826 | */ |
827 | Bkmk* p = NULL; | 827 | Bkmk* p = NULL; |
828 | for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++) | 828 | for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++) |
829 | { | 829 | { |
830 | p = iter.pContent(); | 830 | p = iter.pContent(); |
831 | if (toQString(CFiledata(p->anno()).name()) == reader->m_lastfile) | 831 | if (toQString(CFiledata(p->anno()).name()) == reader->m_lastfile) |
832 | { | 832 | { |
833 | break; | 833 | break; |
834 | } | 834 | } |
835 | // qDebug("Item:%s", (const char*)toQString(CFiledata(p->anno()).name())); | 835 | // qDebug("Item:%s", (const char*)toQString(CFiledata(p->anno()).name())); |
836 | p = NULL; | 836 | p = NULL; |
837 | } | 837 | } |
838 | if (p != NULL) | 838 | if (p != NULL) |
839 | { | 839 | { |
840 | //qDebug("openfrombkmk"); | 840 | //qDebug("openfrombkmk"); |
841 | if (!openfrombkmk(p)) | 841 | if (!openfrombkmk(p)) |
842 | showEditTools(); | 842 | showEditTools(); |
843 | } | 843 | } |
844 | else | 844 | else |
845 | { | 845 | { |
846 | //qDebug("openfile"); | 846 | //qDebug("openfile"); |
847 | openFile( reader->m_lastfile ); | 847 | openFile( reader->m_lastfile ); |
848 | } | 848 | } |
849 | } | 849 | } |
850 | else | 850 | else |
851 | { | 851 | { |
852 | // qDebug("Openfile 2"); | 852 | // qDebug("Openfile 2"); |
853 | if (!reader->m_lastfile.isEmpty()) | 853 | if (!reader->m_lastfile.isEmpty()) |
854 | openFile( reader->m_lastfile ); | 854 | openFile( reader->m_lastfile ); |
855 | } | 855 | } |
856 | } | 856 | } |
857 | else | 857 | else |
858 | { | 858 | { |
859 | showEditTools(); | 859 | showEditTools(); |
860 | } | 860 | } |
861 | // qApp->processEvents(); | 861 | // qApp->processEvents(); |
862 | reader->bDoUpdates = true; | 862 | reader->bDoUpdates = true; |
863 | reader->update(); | 863 | reader->update(); |
864 | config.setGroup("Version"); | 864 | config.setGroup("Version"); |
865 | int major = config.readNumEntry("Major", 0); | 865 | int major = config.readNumEntry("Major", 0); |
866 | int bkmktype = config.readNumEntry("BkmkType", 0); | 866 | int bkmktype = config.readNumEntry("BkmkType", 0); |
867 | char minor = config.readNumEntry("Minor", 0); | 867 | char minor = config.readNumEntry("Minor", 0); |
868 | if (CheckVersion(major, bkmktype, minor)) | 868 | if (CheckVersion(major, bkmktype, minor)) |
869 | { | 869 | { |
870 | config.writeEntry("Major", major); | 870 | config.writeEntry("Major", major); |
871 | config.writeEntry("BkmkType", bkmktype); | 871 | config.writeEntry("BkmkType", bkmktype); |
872 | config.writeEntry("Minor", (int)minor); | 872 | config.writeEntry("Minor", (int)minor); |
873 | } | 873 | } |
874 | // qDebug("finished update"); | 874 | // qDebug("finished update"); |
875 | } | 875 | } |
876 | 876 | ||
877 | void QTReaderApp::addtoolbars(Config* config) | 877 | void QTReaderApp::addtoolbars(Config* config) |
878 | { | 878 | { |
879 | config->setGroup("Toolbar"); | 879 | config->setGroup("Toolbar"); |
880 | 880 | ||
881 | if (fileBar != NULL) | 881 | if (fileBar != NULL) |
882 | { | 882 | { |
883 | if (fileBar != menubar) | 883 | if (fileBar != menubar) |
884 | { | 884 | { |
885 | fileBar->clear(); | 885 | fileBar->clear(); |
886 | } | 886 | } |
887 | else | 887 | else |
888 | { | 888 | { |
889 | m_preferences_action->removeFrom( filebar() ); | 889 | m_preferences_action->removeFrom( filebar() ); |
890 | m_open_action->removeFrom( filebar() ); | 890 | m_open_action->removeFrom( filebar() ); |
891 | m_close_action->removeFrom( filebar() ); | 891 | m_close_action->removeFrom( filebar() ); |
892 | m_info_action->removeFrom( filebar() ); | 892 | m_info_action->removeFrom( filebar() ); |
893 | m_touch_action->removeFrom( filebar() ); | 893 | m_touch_action->removeFrom( filebar() ); |
894 | m_find_action->removeFrom( filebar() ); | 894 | m_find_action->removeFrom( filebar() ); |
895 | } | 895 | } |
896 | } | 896 | } |
897 | 897 | ||
898 | m_preferences_action->addTo( filebar() ); | 898 | m_preferences_action->addTo( filebar() ); |
899 | addfilebar(config, "Open", m_open_action); | 899 | addfilebar(config, "Open", m_open_action); |
900 | addfilebar(config, "Close", m_close_action); | 900 | addfilebar(config, "Close", m_close_action); |
901 | addfilebar(config, "Info", m_info_action); | 901 | addfilebar(config, "Info", m_info_action); |
902 | addfilebar(config, "Two/One Touch", m_touch_action); | 902 | addfilebar(config, "Two/One Touch", m_touch_action); |
903 | addfilebar(config, "Find", m_find_action); | 903 | addfilebar(config, "Find", m_find_action); |
904 | 904 | ||
905 | if (navBar != NULL) | 905 | if (navBar != NULL) |
906 | { | 906 | { |
907 | if ((navBar == fileBar) && (fileBar == menubar)) | 907 | if ((navBar == fileBar) && (fileBar == menubar)) |
908 | { | 908 | { |
909 | m_scrollButton->removeFrom( navbar() ); | 909 | m_scrollButton->removeFrom( navbar() ); |
910 | m_start_action->removeFrom( navbar() ); | 910 | m_start_action->removeFrom( navbar() ); |
911 | m_end_action->removeFrom( navbar() ); | 911 | m_end_action->removeFrom( navbar() ); |
912 | m_jump_action->removeFrom( navbar() ); | 912 | m_jump_action->removeFrom( navbar() ); |
913 | m_pageline_action->removeFrom( navbar() ); | 913 | m_pageline_action->removeFrom( navbar() ); |
914 | m_pageup_action->removeFrom( navbar() ); | 914 | m_pageup_action->removeFrom( navbar() ); |
915 | m_pagedn_action->removeFrom( navbar() ); | 915 | m_pagedn_action->removeFrom( navbar() ); |
916 | m_back_action->removeFrom( navbar() ); | 916 | m_back_action->removeFrom( navbar() ); |
917 | m_home_action->removeFrom( navbar() ); | 917 | m_home_action->removeFrom( navbar() ); |
918 | m_forward_action->removeFrom( navbar() ); | 918 | m_forward_action->removeFrom( navbar() ); |
919 | } | 919 | } |
920 | else if (navBar != fileBar) | 920 | else if (navBar != fileBar) |
921 | { | 921 | { |
922 | navBar->clear(); | 922 | navBar->clear(); |
923 | } | 923 | } |
924 | } | 924 | } |
925 | 925 | ||
926 | addnavbar(config, "Scroll", m_scrollButton); | 926 | addnavbar(config, "Scroll", m_scrollButton); |
927 | addnavbar(config, "Goto Start", m_start_action); | 927 | addnavbar(config, "Goto Start", m_start_action); |
928 | addnavbar(config, "Goto End", m_end_action); | 928 | addnavbar(config, "Goto End", m_end_action); |
929 | 929 | ||
930 | addnavbar(config, "Jump", m_jump_action); | 930 | addnavbar(config, "Jump", m_jump_action); |
931 | addnavbar(config, "Page/Line Scroll", m_pageline_action); | 931 | addnavbar(config, "Page/Line Scroll", m_pageline_action); |
932 | 932 | ||
933 | addnavbar(config, "Page Up", m_pageup_action); | 933 | addnavbar(config, "Page Up", m_pageup_action); |
934 | addnavbar(config, "Page Down", m_pagedn_action); | 934 | addnavbar(config, "Page Down", m_pagedn_action); |
935 | 935 | ||
936 | addnavbar(config, "Back", m_back_action); | 936 | addnavbar(config, "Back", m_back_action); |
937 | addnavbar(config, "Home", m_home_action); | 937 | addnavbar(config, "Home", m_home_action); |
938 | addnavbar(config, "Forward", m_forward_action); | 938 | addnavbar(config, "Forward", m_forward_action); |
939 | 939 | ||
940 | if (viewBar != NULL) | 940 | if (viewBar != NULL) |
941 | { | 941 | { |
942 | if ((viewBar == fileBar) && (fileBar == menubar)) | 942 | if ((viewBar == fileBar) && (fileBar == menubar)) |
943 | { | 943 | { |
944 | m_actFullscreen->removeFrom( filebar() ); | 944 | m_actFullscreen->removeFrom( filebar() ); |
945 | m_zoomin_action->removeFrom( viewbar() ); | 945 | m_zoomin_action->removeFrom( viewbar() ); |
946 | m_zoomout_action->removeFrom( viewbar() ); | 946 | m_zoomout_action->removeFrom( viewbar() ); |
947 | m_setfont_action->removeFrom( viewbar() ); | 947 | m_setfont_action->removeFrom( viewbar() ); |
948 | m_setenc_action->removeFrom( viewbar() ); | 948 | m_setenc_action->removeFrom( viewbar() ); |
949 | m_setmono_action->removeFrom( viewbar() ); | 949 | m_setmono_action->removeFrom( viewbar() ); |
950 | } | 950 | } |
951 | else if (viewBar != fileBar) | 951 | else if (viewBar != fileBar) |
952 | { | 952 | { |
953 | viewBar->clear(); | 953 | viewBar->clear(); |
954 | } | 954 | } |
955 | } | 955 | } |
956 | 956 | ||
957 | addviewbar(config, "Fullscreen", m_actFullscreen); | 957 | addviewbar(config, "Fullscreen", m_actFullscreen); |
958 | addviewbar(config, "Zoom In", m_zoomin_action); | 958 | addviewbar(config, "Zoom In", m_zoomin_action); |
959 | addviewbar(config, "Zoom Out", m_zoomout_action); | 959 | addviewbar(config, "Zoom Out", m_zoomout_action); |
960 | addviewbar(config, "Set Font", m_setfont_action); | 960 | addviewbar(config, "Set Font", m_setfont_action); |
961 | addviewbar(config, "Encoding Select", m_setenc_action); | 961 | addviewbar(config, "Encoding Select", m_setenc_action); |
962 | addviewbar(config, "Ideogram Mode", m_setmono_action); | 962 | addviewbar(config, "Ideogram Mode", m_setmono_action); |
963 | 963 | ||
964 | if (markBar != NULL) | 964 | if (markBar != NULL) |
965 | { | 965 | { |
966 | if ((markBar == fileBar) && (fileBar == menubar)) | 966 | if ((markBar == fileBar) && (fileBar == menubar)) |
967 | { | 967 | { |
968 | m_mark_action->removeFrom( markbar() ); | 968 | m_mark_action->removeFrom( markbar() ); |
969 | m_annotate_action->removeFrom( markbar()); | 969 | m_annotate_action->removeFrom( markbar()); |
970 | m_goto_action->removeFrom( markbar() ); | 970 | m_goto_action->removeFrom( markbar() ); |
971 | m_delete_action->removeFrom( markbar() ); | 971 | m_delete_action->removeFrom( markbar() ); |
972 | m_autogen_action->removeFrom( markbar() ); | 972 | m_autogen_action->removeFrom( markbar() ); |
973 | m_clear_action->removeFrom( markbar() ); | 973 | m_clear_action->removeFrom( markbar() ); |
974 | m_save_action->removeFrom( markbar() ); | 974 | m_save_action->removeFrom( markbar() ); |
975 | m_tidy_action->removeFrom( markbar() ); | 975 | m_tidy_action->removeFrom( markbar() ); |
976 | m_startBlock_action->removeFrom( markbar() ); | 976 | m_startBlock_action->removeFrom( markbar() ); |
977 | m_endBlock_action->removeFrom( markbar() ); | 977 | m_endBlock_action->removeFrom( markbar() ); |
978 | } | 978 | } |
979 | else if (markBar != fileBar) | 979 | else if (markBar != fileBar) |
980 | { | 980 | { |
981 | markBar->clear(); | 981 | markBar->clear(); |
982 | } | 982 | } |
983 | } | 983 | } |
984 | addmarkbar(config, "Mark", m_mark_action); | 984 | addmarkbar(config, "Mark", m_mark_action); |
985 | addmarkbar(config, "Annotate", m_annotate_action); | 985 | addmarkbar(config, "Annotate", m_annotate_action); |
986 | addmarkbar(config, "Goto", m_goto_action); | 986 | addmarkbar(config, "Goto", m_goto_action); |
987 | addmarkbar(config, "Delete", m_delete_action); | 987 | addmarkbar(config, "Delete", m_delete_action); |
988 | addmarkbar(config, "Autogen", m_autogen_action); | 988 | addmarkbar(config, "Autogen", m_autogen_action); |
989 | addmarkbar(config, "Clear", m_clear_action); | 989 | addmarkbar(config, "Clear", m_clear_action); |
990 | addmarkbar(config, "Save", m_save_action); | 990 | addmarkbar(config, "Save", m_save_action); |
991 | addmarkbar(config, "Tidy", m_tidy_action); | 991 | addmarkbar(config, "Tidy", m_tidy_action); |
992 | addmarkbar(config, "Start Block", m_startBlock_action); | 992 | addmarkbar(config, "Start Block", m_startBlock_action); |
993 | addmarkbar(config, "Copy Block", m_endBlock_action); | 993 | addmarkbar(config, "Copy Block", m_endBlock_action); |
994 | if (checkbar(config, "Annotation indicator")) | 994 | if (checkbar(config, "Annotation indicator")) |
995 | { | 995 | { |
996 | if (m_bkmkAvail == NULL) | 996 | if (m_bkmkAvail == NULL) |
997 | { | 997 | { |
998 | m_bkmkAvail = new QAction( tr( "Annotation" ), geticon( "find" ), QString::null, 0, this, 0 ); | 998 | m_bkmkAvail = new QAction( tr( "Annotation" ), geticon( "find" ), QString::null, 0, this, 0 ); |
999 | connect( m_bkmkAvail, SIGNAL( activated() ), this, SLOT( showAnnotation() ) ); | 999 | connect( m_bkmkAvail, SIGNAL( activated() ), this, SLOT( showAnnotation() ) ); |
1000 | 1000 | ||
1001 | m_bkmkAvail->setEnabled(false); | 1001 | m_bkmkAvail->setEnabled(false); |
1002 | } | 1002 | } |
1003 | QLabel *spacer = new QLabel(markBar, ""); | 1003 | QLabel *spacer = new QLabel(markBar, ""); |
1004 | markbar()->setStretchableWidget(spacer); | 1004 | markbar()->setStretchableWidget(spacer); |
1005 | m_bkmkAvail->removeFrom( markbar() ); | 1005 | m_bkmkAvail->removeFrom( markbar() ); |
1006 | m_bkmkAvail->addTo( markbar() ); | 1006 | m_bkmkAvail->addTo( markbar() ); |
1007 | } | 1007 | } |
1008 | else | 1008 | else |
1009 | { | 1009 | { |
1010 | if (m_bkmkAvail != NULL) | 1010 | if (m_bkmkAvail != NULL) |
1011 | { | 1011 | { |
1012 | m_bkmkAvail->removeFrom( markbar() ); | 1012 | m_bkmkAvail->removeFrom( markbar() ); |
1013 | delete m_bkmkAvail; | 1013 | delete m_bkmkAvail; |
1014 | m_bkmkAvail = NULL; | 1014 | m_bkmkAvail = NULL; |
1015 | } | 1015 | } |
1016 | } | 1016 | } |
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | bool QTReaderApp::checkbar(Config* _config, const QString& key) | 1019 | bool QTReaderApp::checkbar(Config* _config, const QString& key) |
1020 | { | 1020 | { |
1021 | return _config->readBoolEntry(key, false); | 1021 | return _config->readBoolEntry(key, false); |
1022 | } | 1022 | } |
1023 | 1023 | ||
1024 | 1024 | ||
1025 | QToolBar* QTReaderApp::filebar() | 1025 | QToolBar* QTReaderApp::filebar() |
1026 | { | 1026 | { |
1027 | if (fileBar == NULL) | 1027 | if (fileBar == NULL) |
1028 | { | 1028 | { |
1029 | switch (m_tbpol) | 1029 | switch (m_tbpol) |
1030 | { | 1030 | { |
1031 | case cesSingle: | 1031 | case cesSingle: |
1032 | // qDebug("Setting filebar to menubar"); | 1032 | // qDebug("Setting filebar to menubar"); |
1033 | fileBar = menubar; | 1033 | fileBar = menubar; |
1034 | break; | 1034 | break; |
1035 | default: | 1035 | default: |
1036 | qDebug("Incorrect toolbar policy set"); | 1036 | qDebug("Incorrect toolbar policy set"); |
1037 | case cesMenuTool: | 1037 | case cesMenuTool: |
1038 | case cesMultiple: | 1038 | case cesMultiple: |
1039 | // qDebug("Creating new file bar"); | 1039 | // qDebug("Creating new file bar"); |
1040 | fileBar = new QToolBar("File", this, m_tbposition); | 1040 | fileBar = new QToolBar("File", this, m_tbposition); |
1041 | break; | 1041 | break; |
1042 | } | 1042 | } |
1043 | //fileBar->setHorizontalStretchable( true ); | 1043 | //fileBar->setHorizontalStretchable( true ); |
1044 | } | 1044 | } |
1045 | return fileBar; | 1045 | return fileBar; |
1046 | } | 1046 | } |
1047 | QToolBar* QTReaderApp::viewbar() | 1047 | QToolBar* QTReaderApp::viewbar() |
1048 | { | 1048 | { |
1049 | if (viewBar == NULL) | 1049 | if (viewBar == NULL) |
1050 | { | 1050 | { |
1051 | switch (m_tbpol) | 1051 | switch (m_tbpol) |
1052 | { | 1052 | { |
1053 | case cesMultiple: | 1053 | case cesMultiple: |
1054 | viewBar = new QToolBar("View", this, m_tbposition); | 1054 | viewBar = new QToolBar("View", this, m_tbposition); |
1055 | break; | 1055 | break; |
1056 | default: | 1056 | default: |
1057 | qDebug("Incorrect toolbar policy set"); | 1057 | qDebug("Incorrect toolbar policy set"); |
1058 | case cesSingle: | 1058 | case cesSingle: |
1059 | case cesMenuTool: | 1059 | case cesMenuTool: |
1060 | viewBar = fileBar; | 1060 | viewBar = fileBar; |
1061 | break; | 1061 | break; |
1062 | } | 1062 | } |
1063 | } | 1063 | } |
1064 | return viewBar; | 1064 | return viewBar; |
1065 | } | 1065 | } |
1066 | QToolBar* QTReaderApp::navbar() | 1066 | QToolBar* QTReaderApp::navbar() |
1067 | { | 1067 | { |
1068 | if (navBar == NULL) | 1068 | if (navBar == NULL) |
1069 | { | 1069 | { |
1070 | switch (m_tbpol) | 1070 | switch (m_tbpol) |
1071 | { | 1071 | { |
1072 | case cesMultiple: | 1072 | case cesMultiple: |
1073 | // qDebug("Creating new nav bar"); | 1073 | // qDebug("Creating new nav bar"); |
1074 | navBar = new QToolBar("Navigation", this, m_tbposition); | 1074 | navBar = new QToolBar("Navigation", this, m_tbposition); |
1075 | break; | 1075 | break; |
1076 | default: | 1076 | default: |
1077 | qDebug("Incorrect toolbar policy set"); | 1077 | qDebug("Incorrect toolbar policy set"); |
1078 | case cesSingle: | 1078 | case cesSingle: |
1079 | case cesMenuTool: | 1079 | case cesMenuTool: |
1080 | navBar = fileBar; | 1080 | navBar = fileBar; |
1081 | // qDebug("Setting navbar to filebar"); | 1081 | // qDebug("Setting navbar to filebar"); |
1082 | break; | 1082 | break; |
1083 | } | 1083 | } |
1084 | } | 1084 | } |
1085 | return navBar; | 1085 | return navBar; |
1086 | } | 1086 | } |
1087 | QToolBar* QTReaderApp::markbar() | 1087 | QToolBar* QTReaderApp::markbar() |
1088 | { | 1088 | { |
1089 | if (markBar == NULL) | 1089 | if (markBar == NULL) |
1090 | { | 1090 | { |
1091 | switch (m_tbpol) | 1091 | switch (m_tbpol) |
1092 | { | 1092 | { |
1093 | case cesMultiple: | 1093 | case cesMultiple: |
1094 | markBar = new QToolBar("Marks", this, m_tbposition); | 1094 | markBar = new QToolBar("Marks", this, m_tbposition); |
1095 | break; | 1095 | break; |
1096 | default: | 1096 | default: |
1097 | qDebug("Incorrect toolbar policy set"); | 1097 | qDebug("Incorrect toolbar policy set"); |
1098 | case cesSingle: | 1098 | case cesSingle: |
1099 | case cesMenuTool: | 1099 | case cesMenuTool: |
1100 | markBar = fileBar; | 1100 | markBar = fileBar; |
1101 | break; | 1101 | break; |
1102 | } | 1102 | } |
1103 | } | 1103 | } |
1104 | return markBar; | 1104 | return markBar; |
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | void QTReaderApp::addfilebar(Config* _config, const QString& key, QAction* a) | 1107 | void QTReaderApp::addfilebar(Config* _config, const QString& key, QAction* a) |
1108 | { | 1108 | { |
1109 | if (_config->readBoolEntry(key, false)) a->addTo( filebar() ); | 1109 | if (_config->readBoolEntry(key, false)) a->addTo( filebar() ); |
1110 | } | 1110 | } |
1111 | void QTReaderApp::addnavbar(Config* _config, const QString& key, QAction* a) | 1111 | void QTReaderApp::addnavbar(Config* _config, const QString& key, QAction* a) |
1112 | { | 1112 | { |
1113 | if (_config->readBoolEntry(key, false)) a->addTo( navbar() ); | 1113 | if (_config->readBoolEntry(key, false)) a->addTo( navbar() ); |
1114 | } | 1114 | } |
1115 | void QTReaderApp::addmarkbar(Config* _config, const QString& key, QAction* a) | 1115 | void QTReaderApp::addmarkbar(Config* _config, const QString& key, QAction* a) |
1116 | { | 1116 | { |
1117 | if (_config->readBoolEntry(key, false)) a->addTo( markbar() ); | 1117 | if (_config->readBoolEntry(key, false)) a->addTo( markbar() ); |
1118 | } | 1118 | } |
1119 | void QTReaderApp::addviewbar(Config* _config, const QString& key, QAction* a) | 1119 | void QTReaderApp::addviewbar(Config* _config, const QString& key, QAction* a) |
1120 | { | 1120 | { |
1121 | if (_config->readBoolEntry(key, false)) a->addTo( viewbar() ); | 1121 | if (_config->readBoolEntry(key, false)) a->addTo( viewbar() ); |
1122 | } | 1122 | } |
1123 | 1123 | ||
1124 | void QTReaderApp::suspend() { reader->suspend(); } | 1124 | void QTReaderApp::suspend() { reader->suspend(); } |
1125 | 1125 | ||
1126 | #ifdef USEMSGS | 1126 | #ifdef USEMSGS |
1127 | void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data) | 1127 | void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data) |
1128 | { | 1128 | { |
1129 | QString msg = QString::fromUtf8(_msg); | 1129 | QString msg = QString::fromUtf8(_msg); |
1130 | 1130 | ||
1131 | //// qDebug("Received:%s", (const char*)msg); | 1131 | //// qDebug("Received:%s", (const char*)msg); |
1132 | 1132 | ||
1133 | QDataStream stream( _data, IO_ReadOnly ); | 1133 | QDataStream stream( _data, IO_ReadOnly ); |
1134 | if ( msg == "info(QString)" ) | 1134 | if ( msg == "info(QString)" ) |
1135 | { | 1135 | { |
1136 | QString info; | 1136 | QString info; |
1137 | stream >> info; | 1137 | stream >> info; |
1138 | QMessageBox::information(this, PROGNAME, info); | 1138 | QMessageBox::information(this, PROGNAME, info); |
1139 | } | 1139 | } |
1140 | else if ( msg == "Update(int)" ) | 1140 | else if ( msg == "Update(int)" ) |
1141 | { | 1141 | { |
1142 | int info; | 1142 | int info; |
1143 | stream >> info; | 1143 | stream >> info; |
1144 | if (info) | 1144 | if (info) |
1145 | { | 1145 | { |
1146 | reader->bDoUpdates = true; | 1146 | reader->bDoUpdates = true; |
1147 | reader->refresh(); | 1147 | reader->refresh(); |
1148 | } | 1148 | } |
1149 | else | 1149 | else |
1150 | { | 1150 | { |
1151 | reader->bDoUpdates = false; | 1151 | reader->bDoUpdates = false; |
1152 | } | 1152 | } |
1153 | } | 1153 | } |
1154 | else if ( msg == "warn(QString)" ) | 1154 | else if ( msg == "warn(QString)" ) |
1155 | { | 1155 | { |
1156 | QString info; | 1156 | QString info; |
1157 | stream >> info; | 1157 | stream >> info; |
1158 | QMessageBox::warning(this, PROGNAME, info); | 1158 | QMessageBox::warning(this, PROGNAME, info); |
1159 | } | 1159 | } |
1160 | else if ( msg == "exit()" ) | 1160 | else if ( msg == "exit()" ) |
1161 | { | 1161 | { |
1162 | m_dontSave = true; | 1162 | m_dontSave = true; |
1163 | close(); | 1163 | close(); |
1164 | } | 1164 | } |
1165 | else if ( msg == "pageDown()" ) | 1165 | else if ( msg == "pageDown()" ) |
1166 | { | 1166 | { |
1167 | reader->dopagedn(); | 1167 | reader->dopagedn(); |
1168 | } | 1168 | } |
1169 | else if ( msg == "pageUp()" ) | 1169 | else if ( msg == "pageUp()" ) |
1170 | { | 1170 | { |
1171 | reader->dopageup(); | 1171 | reader->dopageup(); |
1172 | } | 1172 | } |
1173 | else if ( msg == "lineDown()" ) | 1173 | else if ( msg == "lineDown()" ) |
1174 | { | 1174 | { |
1175 | reader->lineDown(); | 1175 | reader->lineDown(); |
1176 | } | 1176 | } |
1177 | else if ( msg == "lineUp()" ) | 1177 | else if ( msg == "lineUp()" ) |
1178 | { | 1178 | { |
1179 | reader->lineUp(); | 1179 | reader->lineUp(); |
1180 | } | 1180 | } |
1181 | else if ( msg == "showText()" ) | 1181 | else if ( msg == "showText()" ) |
1182 | { | 1182 | { |
1183 | showEditTools(); | 1183 | showEditTools(); |
1184 | } | 1184 | } |
1185 | else if ( msg == "home()" ) | 1185 | else if ( msg == "home()" ) |
1186 | { | 1186 | { |
1187 | reader->goHome(); | 1187 | reader->goHome(); |
1188 | } | 1188 | } |
1189 | else if ( msg == "back()" ) | 1189 | else if ( msg == "back()" ) |
1190 | { | 1190 | { |
1191 | reader->goBack(); | 1191 | reader->goBack(); |
1192 | } | 1192 | } |
1193 | else if ( msg == "forward()" ) | 1193 | else if ( msg == "forward()" ) |
1194 | { | 1194 | { |
1195 | reader->goForward(); | 1195 | reader->goForward(); |
1196 | } | 1196 | } |
1197 | else if ( msg == "File/Open(QString)" ) | 1197 | else if ( msg == "File/Open(QString)" ) |
1198 | { | 1198 | { |
1199 | QString info; | 1199 | QString info; |
1200 | stream >> info; | 1200 | stream >> info; |
1201 | openFile( info ); | 1201 | openFile( info ); |
1202 | } | 1202 | } |
1203 | else if ( msg == "File/Info()" ) | 1203 | else if ( msg == "File/Info()" ) |
1204 | { | 1204 | { |
1205 | showinfo(); | 1205 | showinfo(); |
1206 | } | 1206 | } |
1207 | else if ( msg == "File/Action(QString)" ) | 1207 | else if ( msg == "File/Action(QString)" ) |
1208 | { | 1208 | { |
1209 | QString info; | 1209 | QString info; |
1210 | stream >> info; | 1210 | stream >> info; |
1211 | m_spaceTarget = ActNameToInt(info); | 1211 | m_spaceTarget = ActNameToInt(info); |
1212 | } | 1212 | } |
1213 | else if ( msg == "Navigation/Scroll(int)" ) | 1213 | else if ( msg == "Navigation/Scroll(int)" ) |
1214 | { | 1214 | { |
1215 | int info; | 1215 | int info; |
1216 | stream >> info; | 1216 | stream >> info; |
1217 | autoScroll(info); | 1217 | autoScroll(info); |
1218 | } | 1218 | } |
1219 | 1219 | ||
1220 | else if ( msg == "Navigation/GotoStart()" ) | 1220 | else if ( msg == "Navigation/GotoStart()" ) |
1221 | { | 1221 | { |
1222 | gotoStart(); | 1222 | gotoStart(); |
1223 | } | 1223 | } |
1224 | else if ( msg == "Navigation/GotoEnd()" ) | 1224 | else if ( msg == "Navigation/GotoEnd()" ) |
1225 | { | 1225 | { |
1226 | gotoEnd(); | 1226 | gotoEnd(); |
1227 | } | 1227 | } |
1228 | else if ( msg == "Navigation/Jump(int)" ) | 1228 | else if ( msg == "Navigation/Jump(int)" ) |
1229 | { | 1229 | { |
1230 | int info; | 1230 | int info; |
1231 | stream >> info; | 1231 | stream >> info; |
1232 | reader->locate(info); | 1232 | reader->locate(info); |
1233 | } | 1233 | } |
1234 | else if ( msg == "Navigation/Page/LineScroll(int)" ) | 1234 | else if ( msg == "Navigation/Page/LineScroll(int)" ) |
1235 | { | 1235 | { |
1236 | int info; | 1236 | int info; |
1237 | stream >> info; | 1237 | stream >> info; |
1238 | pagemode(info); | 1238 | pagemode(info); |
1239 | } | 1239 | } |
1240 | else if ( msg == "Navigation/SetOverlap(int)" ) | 1240 | else if ( msg == "Navigation/SetOverlap(int)" ) |
1241 | { | 1241 | { |
1242 | int info; | 1242 | int info; |
1243 | stream >> info; | 1243 | stream >> info; |
1244 | reader->m_overlap = info; | 1244 | reader->m_overlap = info; |
1245 | } | 1245 | } |
1246 | else if ( msg == "Navigation/SetMargin(int)" ) | 1246 | else if ( msg == "Navigation/SetMargin(int)" ) |
1247 | { | 1247 | { |
1248 | int info; | 1248 | int info; |
1249 | stream >> info; | 1249 | stream >> info; |
1250 | do_margin(info); | 1250 | do_margin(info); |
1251 | } | 1251 | } |
1252 | else if ( msg == "File/SetDictionary(QString)" ) | 1252 | else if ( msg == "File/SetDictionary(QString)" ) |
1253 | { | 1253 | { |
1254 | QString info; | 1254 | QString info; |
1255 | stream >> info; | 1255 | stream >> info; |
1256 | do_settarget(info); | 1256 | do_settarget(info); |
1257 | } | 1257 | } |
1258 | #ifdef _SCROLLPIPE | 1258 | #ifdef _SCROLLPIPE |
1259 | else if ( msg == "File/SetScrollTarget(QString)" ) | 1259 | else if ( msg == "File/SetScrollTarget(QString)" ) |
1260 | { | 1260 | { |
1261 | QString info; | 1261 | QString info; |
1262 | stream >> info; | 1262 | stream >> info; |
1263 | reader->m_pipetarget = info; | 1263 | reader->m_pipetarget = info; |
1264 | } | 1264 | } |
1265 | #endif | 1265 | #endif |
1266 | else if ( msg == "File/Two/OneTouch(int)" ) | 1266 | else if ( msg == "File/Two/OneTouch(int)" ) |
1267 | { | 1267 | { |
1268 | int info; | 1268 | int info; |
1269 | stream >> info; | 1269 | stream >> info; |
1270 | setTwoTouch(info); | 1270 | setTwoTouch(info); |
1271 | } | 1271 | } |
1272 | else if ( msg == "Target/Annotation(int)" ) | 1272 | else if ( msg == "Target/Annotation(int)" ) |
1273 | { | 1273 | { |
1274 | int info; | 1274 | int info; |
1275 | stream >> info; | 1275 | stream >> info; |
1276 | OnAnnotation(info); | 1276 | OnAnnotation(info); |
1277 | } | 1277 | } |
1278 | else if ( msg == "Target/Dictionary(int)" ) | 1278 | else if ( msg == "Target/Dictionary(int)" ) |
1279 | { | 1279 | { |
1280 | int info; | 1280 | int info; |
1281 | stream >> info; | 1281 | stream >> info; |
1282 | OnDictionary(info); | 1282 | OnDictionary(info); |
1283 | } | 1283 | } |
1284 | else if ( msg == "Target/Clipboard(int)" ) | 1284 | else if ( msg == "Target/Clipboard(int)" ) |
1285 | { | 1285 | { |
1286 | int info; | 1286 | int info; |
1287 | stream >> info; | 1287 | stream >> info; |
1288 | OnClipboard(info); | 1288 | OnClipboard(info); |
1289 | } | 1289 | } |
1290 | else if ( msg == "File/Find(QString)" ) | 1290 | else if ( msg == "File/Find(QString)" ) |
1291 | { | 1291 | { |
1292 | QString info; | 1292 | QString info; |
1293 | stream >> info; | 1293 | stream >> info; |
1294 | QRegExp arg(info); | 1294 | QRegExp arg(info); |
1295 | size_t pos = reader->pagelocate(); | 1295 | size_t pos = reader->pagelocate(); |
1296 | size_t start = pos; | 1296 | size_t start = pos; |
1297 | CDrawBuffer test(&(reader->m_fontControl)); | 1297 | CDrawBuffer test(&(reader->m_fontControl)); |
1298 | reader->getline(&test); | 1298 | reader->getline(&test); |
1299 | while (arg.match(toQString(test.data())) == -1) | 1299 | while (arg.match(toQString(test.data())) == -1) |
1300 | { | 1300 | { |
1301 | pos = reader->locate(); | 1301 | pos = reader->locate(); |
1302 | if (!reader->getline(&test)) | 1302 | if (!reader->getline(&test)) |
1303 | { | 1303 | { |
1304 | QMessageBox::information(this, PROGNAME, QString("Can't find\n")+info); | 1304 | QMessageBox::information(this, PROGNAME, QString("Can't find\n")+info); |
1305 | pos = start; | 1305 | pos = start; |
1306 | break; | 1306 | break; |
1307 | } | 1307 | } |
1308 | } | 1308 | } |
1309 | reader->locate(pos); | 1309 | reader->locate(pos); |
1310 | } | 1310 | } |
1311 | else if ( msg == "File/Fullscreen(int)" ) | 1311 | else if ( msg == "File/Fullscreen(int)" ) |
1312 | { | 1312 | { |
1313 | int info; | 1313 | int info; |
1314 | stream >> info; | 1314 | stream >> info; |
1315 | setfullscreen(info); | 1315 | setfullscreen(info); |
1316 | } | 1316 | } |
1317 | else if ( msg == "File/Continuous(int)" ) | 1317 | else if ( msg == "File/Continuous(int)" ) |
1318 | { | 1318 | { |
1319 | int info; | 1319 | int info; |
1320 | stream >> info; | 1320 | stream >> info; |
1321 | setcontinuous(info); | 1321 | setcontinuous(info); |
1322 | } | 1322 | } |
1323 | else if ( msg == "Markup(QString)" ) | 1323 | else if ( msg == "Markup(QString)" ) |
1324 | { | 1324 | { |
1325 | QString info; | 1325 | QString info; |
1326 | stream >> info; | 1326 | stream >> info; |
1327 | if (info == "Auto") | 1327 | if (info == "Auto") |
1328 | { | 1328 | { |
1329 | autofmt(true); | 1329 | autofmt(true); |
1330 | } | 1330 | } |
1331 | if (info == "None") | 1331 | if (info == "None") |
1332 | { | 1332 | { |
1333 | autofmt(false); | 1333 | autofmt(false); |
1334 | textfmt(false); | 1334 | textfmt(false); |
1335 | striphtml(false); | 1335 | striphtml(false); |
1336 | peanut(false); | 1336 | peanut(false); |
1337 | } | 1337 | } |
1338 | if (info == "Text") | 1338 | if (info == "Text") |
1339 | { | 1339 | { |
1340 | textfmt(true); | 1340 | textfmt(true); |
1341 | } | 1341 | } |
1342 | if (info == "HTML") | 1342 | if (info == "HTML") |
1343 | { | 1343 | { |
1344 | striphtml(true); | 1344 | striphtml(true); |
1345 | } | 1345 | } |
1346 | if (info == "Peanut/PML") | 1346 | if (info == "Peanut/PML") |
1347 | { | 1347 | { |
1348 | peanut(true); | 1348 | peanut(true); |
1349 | } | 1349 | } |
1350 | } | 1350 | } |
1351 | else if ( msg == "Layout/StripCR(int)" ) | 1351 | else if ( msg == "Layout/StripCR(int)" ) |
1352 | { | 1352 | { |
1353 | int info; | 1353 | int info; |
1354 | stream >> info; | 1354 | stream >> info; |
1355 | stripcr(info); | 1355 | stripcr(info); |
1356 | } | 1356 | } |
1357 | else if ( msg == "Layout/Dehyphen(int)" ) | 1357 | else if ( msg == "Layout/Dehyphen(int)" ) |
1358 | { | 1358 | { |
1359 | int info; | 1359 | int info; |
1360 | stream >> info; | 1360 | stream >> info; |
1361 | dehyphen(info); | 1361 | dehyphen(info); |
1362 | } | 1362 | } |
1363 | else if ( msg == "Layout/Depluck(int)" ) | 1363 | else if ( msg == "Layout/Depluck(int)" ) |
1364 | { | 1364 | { |
1365 | int info; | 1365 | int info; |
1366 | stream >> info; | 1366 | stream >> info; |
1367 | depluck(info); | 1367 | depluck(info); |
1368 | } | 1368 | } |
1369 | else if ( msg == "Layout/Dejpluck(int)" ) | 1369 | else if ( msg == "Layout/Dejpluck(int)" ) |
1370 | { | 1370 | { |
1371 | int info; | 1371 | int info; |
1372 | stream >> info; | 1372 | stream >> info; |
1373 | dejpluck(info); | 1373 | dejpluck(info); |
1374 | } | 1374 | } |
1375 | else if ( msg == "Layout/SingleSpace(int)" ) | 1375 | else if ( msg == "Layout/SingleSpace(int)" ) |
1376 | { | 1376 | { |
1377 | int info; | 1377 | int info; |
1378 | stream >> info; | 1378 | stream >> info; |
1379 | onespace(info); | 1379 | onespace(info); |
1380 | } | 1380 | } |
1381 | #ifdef REPALM | 1381 | #ifdef REPALM |
1382 | else if ( msg == "Layout/Repalm(int)" ) | 1382 | else if ( msg == "Layout/Repalm(int)" ) |
1383 | { | 1383 | { |
1384 | int info; | 1384 | int info; |
1385 | stream >> info; | 1385 | stream >> info; |
1386 | repalm(info); | 1386 | repalm(info); |
1387 | } | 1387 | } |
1388 | #endif | 1388 | #endif |
1389 | else if ( msg == "Layout/Unindent(int)" ) | 1389 | else if ( msg == "Layout/Unindent(int)" ) |
1390 | { | 1390 | { |
1391 | int info; | 1391 | int info; |
1392 | stream >> info; | 1392 | stream >> info; |
1393 | unindent(info); | 1393 | unindent(info); |
1394 | } | 1394 | } |
1395 | else if ( msg == "Layout/Re-paragraph(int)" ) | 1395 | else if ( msg == "Layout/Re-paragraph(int)" ) |
1396 | { | 1396 | { |
1397 | int info; | 1397 | int info; |
1398 | stream >> info; | 1398 | stream >> info; |
1399 | repara(info); | 1399 | repara(info); |
1400 | } | 1400 | } |
1401 | else if ( msg == "Layout/DoubleSpace(int)" ) | 1401 | else if ( msg == "Layout/DoubleSpace(int)" ) |
1402 | { | 1402 | { |
1403 | int info; | 1403 | int info; |
1404 | stream >> info; | 1404 | stream >> info; |
1405 | dblspce(info); | 1405 | dblspce(info); |
1406 | } | 1406 | } |
1407 | else if ( msg == "Layout/Indent(int)" ) | 1407 | else if ( msg == "Layout/Indent(int)" ) |
1408 | { | 1408 | { |
1409 | int info; | 1409 | int info; |
1410 | stream >> info; | 1410 | stream >> info; |
1411 | reader->bindenter = info; | 1411 | reader->bindenter = info; |
1412 | reader->setfilter(reader->getfilter()); | 1412 | reader->setfilter(reader->getfilter()); |
1413 | } | 1413 | } |
1414 | else if ( msg == "Layout/Remap(int)" ) | 1414 | else if ( msg == "Layout/Remap(int)" ) |
1415 | { | 1415 | { |
1416 | int info; | 1416 | int info; |
1417 | stream >> info; | 1417 | stream >> info; |
1418 | remap(info); | 1418 | remap(info); |
1419 | } | 1419 | } |
1420 | else if ( msg == "Layout/Embolden(int)" ) | 1420 | else if ( msg == "Layout/Embolden(int)" ) |
1421 | { | 1421 | { |
1422 | int info; | 1422 | int info; |
1423 | stream >> info; | 1423 | stream >> info; |
1424 | embolden(info); | 1424 | embolden(info); |
1425 | } | 1425 | } |
1426 | else if ( msg == "Format/Ideogram/Word(int)" ) | 1426 | else if ( msg == "Format/Ideogram/Word(int)" ) |
1427 | { | 1427 | { |
1428 | int info; | 1428 | int info; |
1429 | stream >> info; | 1429 | stream >> info; |
1430 | monospace(info); | 1430 | monospace(info); |
1431 | } | 1431 | } |
1432 | else if ( msg == "Format/SetWidth(int)" ) | 1432 | else if ( msg == "Format/SetWidth(int)" ) |
1433 | { | 1433 | { |
1434 | int info; | 1434 | int info; |
1435 | stream >> info; | 1435 | stream >> info; |
1436 | reader->m_charpc = info; | 1436 | reader->m_charpc = info; |
1437 | reader->setfont(); | 1437 | reader->setfont(); |
1438 | reader->refresh(); | 1438 | reader->refresh(); |
1439 | } | 1439 | } |
1440 | else if ( msg == "Format/SetFont(QString,int)" ) | 1440 | else if ( msg == "Format/SetFont(QString,int)" ) |
1441 | { | 1441 | { |
1442 | QString fontname; | 1442 | QString fontname; |
1443 | int size; | 1443 | int size; |
1444 | stream >> fontname; | 1444 | stream >> fontname; |
1445 | stream >> size; | 1445 | stream >> size; |
1446 | setfontHelper(fontname, size); | 1446 | setfontHelper(fontname, size); |
1447 | } | 1447 | } |
1448 | else if ( msg == "Marks/Autogen(QString)" ) | 1448 | else if ( msg == "Marks/Autogen(QString)" ) |
1449 | { | 1449 | { |
1450 | QString info; | 1450 | QString info; |
1451 | stream >> info; | 1451 | stream >> info; |
1452 | do_autogen(info); | 1452 | do_autogen(info); |
1453 | } | 1453 | } |
1454 | else if ( msg == "File/StartBlock()" ) | 1454 | else if ( msg == "File/StartBlock()" ) |
1455 | { | 1455 | { |
1456 | editMark(); | 1456 | editMark(); |
1457 | } | 1457 | } |
1458 | else if ( msg == "File/CopyBlock()" ) | 1458 | else if ( msg == "File/CopyBlock()" ) |
1459 | { | 1459 | { |
1460 | editCopy(); | 1460 | editCopy(); |
1461 | } | 1461 | } |
1462 | } | 1462 | } |
1463 | #endif | 1463 | #endif |
1464 | ActionTypes QTReaderApp::ActNameToInt(const QString& _enc) | 1464 | ActionTypes QTReaderApp::ActNameToInt(const QString& _enc) |
1465 | { | 1465 | { |
1466 | for (int i = 0; i < MAX_ACTIONS; i++) | 1466 | for (int i = 0; i < MAX_ACTIONS; i++) |
1467 | { | 1467 | { |
1468 | if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i; | 1468 | if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i; |
1469 | } | 1469 | } |
1470 | return cesAutoScroll; | 1470 | return cesAutoScroll; |
1471 | } | 1471 | } |
1472 | 1472 | ||
1473 | void QTReaderApp::setfullscreen(bool sfs) | 1473 | void QTReaderApp::setfullscreen(bool sfs) |
1474 | { | 1474 | { |
1475 | reader->bDoUpdates = false; | 1475 | reader->bDoUpdates = false; |
1476 | m_fullscreen = sfs; | 1476 | m_fullscreen = sfs; |
1477 | showEditTools(); | 1477 | showEditTools(); |
1478 | // qApp->processEvents(); | 1478 | // qApp->processEvents(); |
1479 | reader->bDoUpdates = true; | 1479 | reader->bDoUpdates = true; |
1480 | reader->update(); | 1480 | reader->update(); |
1481 | } | 1481 | } |
1482 | 1482 | ||
1483 | void QTReaderApp::buttonActionSelected(QAction* _a) | 1483 | void QTReaderApp::buttonActionSelected(QAction* _a) |
1484 | { | 1484 | { |
1485 | //// qDebug("es:%x : %s (%u)", _a, (const char *)(_a->text()), ActNameToInt(_a->text())); | 1485 | //// qDebug("es:%x : %s (%u)", _a, (const char *)(_a->text()), ActNameToInt(_a->text())); |
1486 | m_spaceTarget = ActNameToInt(_a->text()); | 1486 | m_spaceTarget = ActNameToInt(_a->text()); |
1487 | } | 1487 | } |
1488 | 1488 | ||
1489 | QTReaderApp::~QTReaderApp() | 1489 | QTReaderApp::~QTReaderApp() |
1490 | { | 1490 | { |
1491 | } | 1491 | } |
1492 | 1492 | ||
1493 | void QTReaderApp::autoScroll(bool _b) | 1493 | void QTReaderApp::autoScroll(bool _b) |
1494 | { | 1494 | { |
1495 | reader->setautoscroll(_b); | 1495 | reader->setautoscroll(_b); |
1496 | setScrollState(reader->m_autoScroll); | 1496 | setScrollState(reader->m_autoScroll); |
1497 | } | 1497 | } |
1498 | 1498 | ||
1499 | void QTReaderApp::zoomin() | 1499 | void QTReaderApp::zoomin() |
1500 | { | 1500 | { |
1501 | reader->zoomin(); | 1501 | reader->zoomin(); |
1502 | } | 1502 | } |
1503 | 1503 | ||
1504 | void QTReaderApp::zoomout() | 1504 | void QTReaderApp::zoomout() |
1505 | { | 1505 | { |
1506 | reader->zoomout(); | 1506 | reader->zoomout(); |
1507 | } | 1507 | } |
1508 | 1508 | ||
1509 | void QTReaderApp::clearBkmkList() | 1509 | void QTReaderApp::clearBkmkList() |
1510 | { | 1510 | { |
1511 | delete pBkmklist; | 1511 | delete pBkmklist; |
1512 | pBkmklist = NULL; | 1512 | pBkmklist = NULL; |
1513 | m_fBkmksChanged = false; | 1513 | m_fBkmksChanged = false; |
1514 | } | 1514 | } |
1515 | 1515 | ||
1516 | void QTReaderApp::fileClose() | 1516 | void QTReaderApp::fileClose() |
1517 | { | 1517 | { |
1518 | CCloseDialog* cd = new CCloseDialog(reader->m_string, false, this); | 1518 | CCloseDialog* cd = new CCloseDialog(reader->m_string, false, this); |
1519 | if (cd->exec()) | 1519 | if (cd->exec()) |
1520 | { | 1520 | { |
1521 | if (pOpenlist != NULL) | 1521 | if (pOpenlist != NULL) |
1522 | { | 1522 | { |
1523 | int ind = 0; | 1523 | int ind = 0; |
1524 | Bkmk* p = (*pOpenlist)[ind]; | 1524 | Bkmk* p = (*pOpenlist)[ind]; |
1525 | while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile) | 1525 | while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile) |
1526 | { | 1526 | { |
1527 | p = (*pOpenlist)[++ind]; | 1527 | p = (*pOpenlist)[++ind]; |
1528 | } | 1528 | } |
1529 | if (p != NULL) pOpenlist->erase(ind); | 1529 | if (p != NULL) pOpenlist->erase(ind); |
1530 | if (cd->delFile()) | 1530 | if (cd->delFile()) |
1531 | { | 1531 | { |
1532 | unlink((const char*)reader->m_lastfile); | 1532 | unlink((const char*)reader->m_lastfile); |
1533 | } | 1533 | } |
1534 | if (cd->delMarks()) | 1534 | if (cd->delMarks()) |
1535 | { | 1535 | { |
1536 | #ifndef USEQPE | 1536 | #ifndef USEQPE |
1537 | QDir d = QDir::home(); // "/" | 1537 | QDir d = QDir::home(); // "/" |
1538 | d.cd(APPDIR); | 1538 | d.cd(APPDIR); |
1539 | d.remove(reader->m_string); | 1539 | d.remove(reader->m_string); |
1540 | #else /* USEQPE */ | 1540 | #else /* USEQPE */ |
1541 | unlink((const char *)Global::applicationFileName(APPDIR,reader->m_string)); | 1541 | unlink((const char *)Global::applicationFileName(APPDIR,reader->m_string)); |
1542 | #endif /* USEQPE */ | 1542 | #endif /* USEQPE */ |
1543 | } | 1543 | } |
1544 | if (cd->delConfig()) | 1544 | if (cd->delConfig()) |
1545 | { | 1545 | { |
1546 | #ifndef USEQPE | 1546 | #ifndef USEQPE |
1547 | QDir d = QDir::home(); // "/" | 1547 | QDir d = QDir::home(); // "/" |
1548 | d.cd(APPDIR "/configs"); | 1548 | d.cd(APPDIR "/configs"); |
1549 | d.remove(reader->m_string); | 1549 | d.remove(reader->m_string); |
1550 | #else /* USEQPE */ | 1550 | #else /* USEQPE */ |
1551 | unlink((const char *)Global::applicationFileName(APPDIR "/configs",reader->m_string)); | 1551 | unlink((const char *)Global::applicationFileName(APPDIR "/configs",reader->m_string)); |
1552 | #endif /* USEQPE */ | 1552 | #endif /* USEQPE */ |
1553 | } | 1553 | } |
1554 | } | 1554 | } |
1555 | 1555 | ||
1556 | fileOpen2(); | 1556 | fileOpen2(); |
1557 | } | 1557 | } |
1558 | delete cd; | 1558 | delete cd; |
1559 | } | 1559 | } |
1560 | 1560 | ||
1561 | void QTReaderApp::updatefileinfo() | 1561 | void QTReaderApp::updatefileinfo() |
1562 | { | 1562 | { |
1563 | if (reader->m_string.isEmpty()) return; | 1563 | if (reader->m_string.isEmpty()) return; |
1564 | if (reader->m_lastfile.isEmpty()) return; | 1564 | if (reader->m_lastfile.isEmpty()) return; |
1565 | tchar* nm = fromQString(reader->m_string); | 1565 | tchar* nm = fromQString(reader->m_string); |
1566 | tchar* fl = fromQString(reader->m_lastfile); | 1566 | tchar* fl = fromQString(reader->m_lastfile); |
1567 | // qDebug("Lastfile:%x", fl); | 1567 | // qDebug("Lastfile:%x", fl); |
1568 | bool notadded = true; | 1568 | bool notadded = true; |
1569 | if (pOpenlist == NULL) pOpenlist = new CList<Bkmk>; | 1569 | if (pOpenlist == NULL) pOpenlist = new CList<Bkmk>; |
1570 | else | 1570 | else |
1571 | { | 1571 | { |
1572 | for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++) | 1572 | for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++) |
1573 | { | 1573 | { |
1574 | if (ustrcmp(CFiledata(iter->anno()).name(), fl) == 0) | 1574 | if (ustrcmp(CFiledata(iter->anno()).name(), fl) == 0) |
1575 | { | 1575 | { |
1576 | iter->value(reader->pagelocate()); | 1576 | iter->value(reader->pagelocate()); |
1577 | unsigned short dlen; | 1577 | unsigned short dlen; |
1578 | unsigned char* data; | 1578 | unsigned char* data; |
1579 | CFiledata fd(iter->anno()); | 1579 | CFiledata fd(iter->anno()); |
1580 | reader->setSaveData(data, dlen, fd.content(), fd.length()); | 1580 | reader->setSaveData(data, dlen, fd.content(), fd.length()); |
1581 | // qDebug("Filedata(1):%u, %u", fd.length(), dlen); | 1581 | // qDebug("Filedata(1):%u, %u", fd.length(), dlen); |
1582 | // getstate(data, dlen); | 1582 | // getstate(data, dlen); |
1583 | iter->setAnno(data, dlen); | 1583 | iter->setAnno(data, dlen); |
1584 | notadded = false; | 1584 | notadded = false; |
1585 | delete [] data; | 1585 | delete [] data; |
1586 | break; | 1586 | break; |
1587 | } | 1587 | } |
1588 | } | 1588 | } |
1589 | } | 1589 | } |
1590 | // qDebug("Added?:%x", notadded); | 1590 | // qDebug("Added?:%x", notadded); |
1591 | if (notadded) | 1591 | if (notadded) |
1592 | { | 1592 | { |
1593 | struct stat fnstat; | 1593 | struct stat fnstat; |
1594 | stat((const char *)reader->m_lastfile, &fnstat); | 1594 | stat((const char *)reader->m_lastfile, &fnstat); |
1595 | CFiledata fd(fnstat.st_mtime, fl); | 1595 | CFiledata fd(fnstat.st_mtime, fl); |
1596 | unsigned short dlen; | 1596 | unsigned short dlen; |
1597 | unsigned char* data; | 1597 | unsigned char* data; |
1598 | reader->setSaveData(data, dlen, fd.content(), fd.length()); | 1598 | reader->setSaveData(data, dlen, fd.content(), fd.length()); |
1599 | pOpenlist->push_front(Bkmk(nm, data, dlen, reader->pagelocate())); | 1599 | pOpenlist->push_front(Bkmk(nm, data, dlen, reader->pagelocate())); |
1600 | //qDebug("Filedata(2):%u, %u", fd.length(), dlen); | 1600 | //qDebug("Filedata(2):%u, %u", fd.length(), dlen); |
1601 | delete [] data; | 1601 | delete [] data; |
1602 | } | 1602 | } |
1603 | delete [] nm; | 1603 | delete [] nm; |
1604 | delete [] fl; | 1604 | delete [] fl; |
1605 | } | 1605 | } |
1606 | 1606 | ||
1607 | void QTReaderApp::fileOpen() | 1607 | void QTReaderApp::fileOpen() |
1608 | { | 1608 | { |
1609 | /* | 1609 | /* |
1610 | menu->hide(); | 1610 | menu->hide(); |
1611 | fileBar->hide(); | 1611 | fileBar->hide(); |
1612 | if (regVisible) regBar->hide(); | 1612 | if (regVisible) regBar->hide(); |
1613 | if (searchVisible) searchBar->hide(); | 1613 | if (searchVisible) searchBar->hide(); |
1614 | */ | 1614 | */ |
1615 | // qDebug("fileOpen"); | 1615 | // qDebug("fileOpen"); |
1616 | // if (!reader->m_lastfile.isEmpty()) | 1616 | // if (!reader->m_lastfile.isEmpty()) |
1617 | updatefileinfo(); | 1617 | updatefileinfo(); |
1618 | fileOpen2(); | 1618 | fileOpen2(); |
1619 | } | 1619 | } |
1620 | 1620 | ||
1621 | void QTReaderApp::fileOpen2() | 1621 | void QTReaderApp::fileOpen2() |
1622 | { | 1622 | { |
1623 | if (pBkmklist != NULL) | 1623 | if (pBkmklist != NULL) |
1624 | { | 1624 | { |
1625 | if (m_fBkmksChanged) | 1625 | if (m_fBkmksChanged) |
1626 | { | 1626 | { |
1627 | if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0) | 1627 | if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0) |
1628 | savebkmks(); | 1628 | savebkmks(); |
1629 | } | 1629 | } |
1630 | delete pBkmklist; | 1630 | delete pBkmklist; |
1631 | pBkmklist = NULL; | 1631 | pBkmklist = NULL; |
1632 | m_fBkmksChanged = false; | 1632 | m_fBkmksChanged = false; |
1633 | } | 1633 | } |
1634 | reader->disableAutoscroll(); | 1634 | reader->disableAutoscroll(); |
1635 | /* | 1635 | /* |
1636 | editorStack->raiseWidget( fileSelector ); | 1636 | editorStack->raiseWidget( fileSelector ); |
1637 | fileSelector->reread(); | 1637 | fileSelector->reread(); |
1638 | */ | 1638 | */ |
1639 | bool usebrowser = true; | 1639 | bool usebrowser = true; |
1640 | if (pOpenlist != NULL) | 1640 | if (pOpenlist != NULL) |
1641 | { | 1641 | { |
1642 | m_nBkmkAction = cOpenFile; | 1642 | m_nBkmkAction = cOpenFile; |
1643 | if (listbkmk(pOpenlist, "Browse")) usebrowser = false; | 1643 | if (listbkmk(pOpenlist, "Browse")) usebrowser = false; |
1644 | } | 1644 | } |
1645 | if (usebrowser) | 1645 | if (usebrowser) |
1646 | { | 1646 | { |
1647 | QString fn = usefilebrowser(); | 1647 | QString fn = usefilebrowser(); |
1648 | //qApp->processEvents(); | 1648 | //qApp->processEvents(); |
1649 | if (!fn.isEmpty() && QFileInfo(fn).isFile()) | 1649 | if (!fn.isEmpty() && QFileInfo(fn).isFile()) |
1650 | { | 1650 | { |
1651 | openFile(fn); | 1651 | openFile(fn); |
1652 | } | 1652 | } |
1653 | reader->setFocus(); | 1653 | reader->setFocus(); |
1654 | } | 1654 | } |
1655 | // reader->refresh(); | 1655 | // reader->refresh(); |
1656 | // qDebug("HEIGHT:%d", reader->m_lastheight); | 1656 | // qDebug("HEIGHT:%d", reader->m_lastheight); |
1657 | } | 1657 | } |
1658 | 1658 | ||
1659 | QString QTReaderApp::usefilebrowser() | 1659 | QString QTReaderApp::usefilebrowser() |
1660 | { | 1660 | { |
1661 | #ifndef USEQPE | 1661 | #ifndef USEQPE |
1662 | QString s( QFileDialog::getOpenFileName( reader->m_lastfile, QString::null, this ) ); | 1662 | QString s( QFileDialog::getOpenFileName( reader->m_lastfile, QString::null, this ) ); |
1663 | return s; | 1663 | return s; |
1664 | #else | 1664 | #else |
1665 | fileBrowser* fb = new fileBrowser(false, this,"OpieReader",!m_bFloatingDialog, | 1665 | fileBrowser* fb = new fileBrowser(false, this,"OpieReader",!m_bFloatingDialog, |
1666 | 0, | 1666 | 0, |
1667 | // WStyle_Customize | WStyle_NoBorderEx, | 1667 | // WStyle_Customize | WStyle_NoBorderEx, |
1668 | "*", QFileInfo(reader->m_lastfile).dirPath(true)); | 1668 | "*", QFileInfo(reader->m_lastfile).dirPath(true)); |
1669 | 1669 | ||
1670 | 1670 | ||
1671 | QString fn; | 1671 | QString fn; |
1672 | if (fb->exec()) | 1672 | if (fb->exec()) |
1673 | { | 1673 | { |
1674 | fn = fb->getCurrentFile(); | 1674 | fn = fb->getCurrentFile(); |
1675 | } | 1675 | } |
1676 | // qDebug("Selected %s", (const char*)fn); | 1676 | // qDebug("Selected %s", (const char*)fn); |
1677 | delete fb; | 1677 | delete fb; |
1678 | showEditTools(); | 1678 | showEditTools(); |
1679 | return fn; | 1679 | return fn; |
1680 | #endif | 1680 | #endif |
1681 | } | 1681 | } |
1682 | 1682 | ||
1683 | void QTReaderApp::showgraphic(QImage& pm) | 1683 | void QTReaderApp::showgraphic(QImage& pm) |
1684 | { | 1684 | { |
1685 | QPixmap pc; | 1685 | QPixmap pc; |
1686 | pc.convertFromImage(pm); | 1686 | pc.convertFromImage(pm); |
1687 | m_graphicwin->setPixmap(pc); | 1687 | m_graphicwin->setPixmap(pc); |
1688 | editorStack->raiseWidget( m_graphicwin ); | 1688 | editorStack->raiseWidget( m_graphicwin ); |
1689 | m_graphicwin->setFocus(); | 1689 | m_graphicwin->setFocus(); |
1690 | } | 1690 | } |
1691 | 1691 | ||
1692 | 1692 | ||
1693 | void QTReaderApp::showprefs() | 1693 | void QTReaderApp::showprefs() |
1694 | { | 1694 | { |
1695 | CPrefs* prefwin = new CPrefs(!m_bFloatingDialog, this); | 1695 | CPrefs* prefwin = new CPrefs(!m_bFloatingDialog, this); |
1696 | 1696 | ||
1697 | prefwin->twotouch(m_twoTouch); | 1697 | prefwin->twotouch(m_twoTouch); |
1698 | prefwin->propfontchange(m_propogatefontchange); | 1698 | prefwin->propfontchange(m_propogatefontchange); |
1699 | prefwin->StripCR(reader->bstripcr); | 1699 | prefwin->StripCR(reader->bstripcr); |
1700 | prefwin->Dehyphen(reader->bdehyphen); | 1700 | prefwin->Dehyphen(reader->bdehyphen); |
1701 | prefwin->SingleSpace(reader->bonespace); | 1701 | prefwin->SingleSpace(reader->bonespace); |
1702 | prefwin->Unindent(reader->bunindent); | 1702 | prefwin->Unindent(reader->bunindent); |
1703 | prefwin->Reparagraph(reader->brepara); | 1703 | prefwin->Reparagraph(reader->brepara); |
1704 | prefwin->DoubleSpace(reader->bdblspce); | 1704 | prefwin->DoubleSpace(reader->bdblspce); |
1705 | prefwin->Remap(reader->bremap); | 1705 | prefwin->Remap(reader->bremap); |
1706 | prefwin->Embolden(reader->bmakebold); | 1706 | prefwin->Embolden(reader->bmakebold); |
1707 | prefwin->FullJustify(reader->bfulljust); | 1707 | prefwin->FullJustify(reader->bfulljust); |
1708 | prefwin->ParaLead(reader->getextraspace()); | 1708 | prefwin->ParaLead(reader->getextraspace()); |
1709 | prefwin->LineLead(reader->getlead()); | 1709 | prefwin->LineLead(reader->getlead()); |
1710 | prefwin->Margin(reader->m_border); | 1710 | prefwin->Margin(reader->m_border); |
1711 | prefwin->Indent(reader->bindenter); | 1711 | prefwin->Indent(reader->bindenter); |
1712 | if (reader->bautofmt) | 1712 | if (reader->bautofmt) |
1713 | { | 1713 | { |
1714 | prefwin->Markup(0); | 1714 | prefwin->Markup(0); |
1715 | } | 1715 | } |
1716 | else if (reader->btextfmt) | 1716 | else if (reader->btextfmt) |
1717 | { | 1717 | { |
1718 | prefwin->Markup(2); | 1718 | prefwin->Markup(2); |
1719 | } | 1719 | } |
1720 | else if (reader->bstriphtml) | 1720 | else if (reader->bstriphtml) |
1721 | { | 1721 | { |
1722 | prefwin->Markup(3); | 1722 | prefwin->Markup(3); |
1723 | } | 1723 | } |
1724 | else if (reader->bpeanut) | 1724 | else if (reader->bpeanut) |
1725 | { | 1725 | { |
1726 | prefwin->Markup(4); | 1726 | prefwin->Markup(4); |
1727 | } | 1727 | } |
1728 | else | 1728 | else |
1729 | { | 1729 | { |
1730 | prefwin->Markup(1); | 1730 | prefwin->Markup(1); |
1731 | } | 1731 | } |
1732 | prefwin->Depluck(reader->bdepluck); | 1732 | prefwin->Depluck(reader->bdepluck); |
1733 | prefwin->Dejpluck(reader->bdejpluck); | 1733 | prefwin->Dejpluck(reader->bdejpluck); |
1734 | prefwin->Continuous(reader->m_continuousDocument); | 1734 | prefwin->Continuous(reader->m_continuousDocument); |
1735 | 1735 | ||
1736 | prefwin->dictApplication(m_targetapp); | 1736 | prefwin->dictApplication(m_targetapp); |
1737 | prefwin->dictMessage(m_targetmsg); | 1737 | prefwin->dictMessage(m_targetmsg); |
1738 | 1738 | ||
1739 | prefwin->spaceAction(m_spaceTarget); | 1739 | prefwin->spaceAction(m_spaceTarget); |
1740 | prefwin->escapeAction(m_escapeTarget); | 1740 | prefwin->escapeAction(m_escapeTarget); |
1741 | prefwin->returnAction(m_returnTarget); | 1741 | prefwin->returnAction(m_returnTarget); |
1742 | prefwin->leftAction(m_leftTarget); | 1742 | prefwin->leftAction(m_leftTarget); |
1743 | prefwin->rightAction(m_rightTarget); | 1743 | prefwin->rightAction(m_rightTarget); |
1744 | prefwin->upAction(m_upTarget); | 1744 | prefwin->upAction(m_upTarget); |
1745 | prefwin->downAction(m_downTarget); | 1745 | prefwin->downAction(m_downTarget); |
1746 | 1746 | ||
1747 | prefwin->leftScroll(m_leftScroll); | 1747 | prefwin->leftScroll(m_leftScroll); |
1748 | prefwin->rightScroll(m_rightScroll); | 1748 | prefwin->rightScroll(m_rightScroll); |
1749 | prefwin->upScroll(m_upScroll); | 1749 | prefwin->upScroll(m_upScroll); |
1750 | prefwin->downScroll(m_downScroll); | 1750 | prefwin->downScroll(m_downScroll); |
1751 | 1751 | ||
1752 | prefwin->miscannotation(m_doAnnotation); | 1752 | prefwin->miscannotation(m_doAnnotation); |
1753 | prefwin->miscdictionary(m_doDictionary); | 1753 | prefwin->miscdictionary(m_doDictionary); |
1754 | prefwin->miscclipboard(m_doClipboard); | 1754 | prefwin->miscclipboard(m_doClipboard); |
1755 | 1755 | ||
1756 | prefwin->SwapMouse(reader->m_swapmouse); | 1756 | prefwin->SwapMouse(reader->m_swapmouse); |
1757 | 1757 | ||
1758 | prefwin->Font(reader->m_fontname); | 1758 | prefwin->Font(reader->m_fontname); |
1759 | 1759 | ||
1760 | prefwin->gfxsize(reader->getBaseSize()); | 1760 | prefwin->gfxsize(reader->getBaseSize()); |
1761 | 1761 | ||
1762 | prefwin->pageoverlap(reader->m_overlap); | 1762 | prefwin->pageoverlap(reader->m_overlap); |
1763 | 1763 | ||
1764 | prefwin->ideogram(reader->m_bMonoSpaced); | 1764 | prefwin->ideogram(reader->m_bMonoSpaced); |
1765 | 1765 | ||
1766 | prefwin->encoding(reader->m_encd); | 1766 | prefwin->encoding(reader->m_encd); |
1767 | 1767 | ||
1768 | prefwin->ideogramwidth(reader->m_charpc); | 1768 | prefwin->ideogramwidth(reader->m_charpc); |
1769 | 1769 | ||
1770 | if (prefwin->exec()) | 1770 | if (prefwin->exec()) |
1771 | { | 1771 | { |
1772 | m_twoTouch = prefwin->twotouch(); | 1772 | m_twoTouch = prefwin->twotouch(); |
1773 | reader->setTwoTouch(m_twoTouch); | 1773 | reader->setTwoTouch(m_twoTouch); |
1774 | m_touch_action->setOn(m_twoTouch); | 1774 | m_touch_action->setOn(m_twoTouch); |
1775 | 1775 | ||
1776 | reader->bstripcr = prefwin->StripCR(); | 1776 | reader->bstripcr = prefwin->StripCR(); |
1777 | reader->bdehyphen = prefwin->Dehyphen(); | 1777 | reader->bdehyphen = prefwin->Dehyphen(); |
1778 | reader->bonespace = prefwin->SingleSpace(); | 1778 | reader->bonespace = prefwin->SingleSpace(); |
1779 | reader->bunindent = prefwin->Unindent(); | 1779 | reader->bunindent = prefwin->Unindent(); |
1780 | reader->brepara = prefwin->Reparagraph(); | 1780 | reader->brepara = prefwin->Reparagraph(); |
1781 | reader->bdblspce = prefwin->DoubleSpace(); | 1781 | reader->bdblspce = prefwin->DoubleSpace(); |
1782 | reader->bremap = prefwin->Remap(); | 1782 | reader->bremap = prefwin->Remap(); |
1783 | reader->bmakebold = prefwin->Embolden(); | 1783 | reader->bmakebold = prefwin->Embolden(); |
1784 | reader->bfulljust = prefwin->FullJustify(); | 1784 | reader->bfulljust = prefwin->FullJustify(); |
1785 | reader->setextraspace(prefwin->ParaLead()); | 1785 | reader->setextraspace(prefwin->ParaLead()); |
1786 | reader->setlead(prefwin->LineLead()); | 1786 | reader->setlead(prefwin->LineLead()); |
1787 | reader->m_border = prefwin->Margin(); | 1787 | reader->m_border = prefwin->Margin(); |
1788 | reader->bindenter = prefwin->Indent(); | 1788 | reader->bindenter = prefwin->Indent(); |
1789 | reader->bautofmt = reader->btextfmt = reader->bstriphtml = reader->bpeanut = false; | 1789 | reader->bautofmt = reader->btextfmt = reader->bstriphtml = reader->bpeanut = false; |
1790 | switch (prefwin->Markup()) | 1790 | switch (prefwin->Markup()) |
1791 | { | 1791 | { |
1792 | case 0: | 1792 | case 0: |
1793 | reader->bautofmt = true; | 1793 | reader->bautofmt = true; |
1794 | break; | 1794 | break; |
1795 | case 1: | 1795 | case 1: |
1796 | break; | 1796 | break; |
1797 | case 2: | 1797 | case 2: |
1798 | reader->btextfmt = true; | 1798 | reader->btextfmt = true; |
1799 | break; | 1799 | break; |
1800 | case 3: | 1800 | case 3: |
1801 | reader->bstriphtml = true; | 1801 | reader->bstriphtml = true; |
1802 | break; | 1802 | break; |
1803 | case 4: | 1803 | case 4: |
1804 | reader->bpeanut = true; | 1804 | reader->bpeanut = true; |
1805 | break; | 1805 | break; |
1806 | default: | 1806 | default: |
1807 | qDebug("Format out of range"); | 1807 | qDebug("Format out of range"); |
1808 | } | 1808 | } |
1809 | reader->bdepluck = prefwin->Depluck(); | 1809 | reader->bdepluck = prefwin->Depluck(); |
1810 | reader->bdejpluck = prefwin->Dejpluck(); | 1810 | reader->bdejpluck = prefwin->Dejpluck(); |
1811 | reader->setContinuous(prefwin->Continuous()); | 1811 | reader->setContinuous(prefwin->Continuous()); |
1812 | 1812 | ||
1813 | m_spaceTarget = (ActionTypes)prefwin->spaceAction(); | 1813 | m_spaceTarget = (ActionTypes)prefwin->spaceAction(); |
1814 | m_escapeTarget = (ActionTypes)prefwin->escapeAction(); | 1814 | m_escapeTarget = (ActionTypes)prefwin->escapeAction(); |
1815 | m_returnTarget = (ActionTypes)prefwin->returnAction(); | 1815 | m_returnTarget = (ActionTypes)prefwin->returnAction(); |
1816 | m_leftTarget = (ActionTypes)prefwin->leftAction(); | 1816 | m_leftTarget = (ActionTypes)prefwin->leftAction(); |
1817 | m_rightTarget = (ActionTypes)prefwin->rightAction(); | 1817 | m_rightTarget = (ActionTypes)prefwin->rightAction(); |
1818 | m_upTarget = (ActionTypes)prefwin->upAction(); | 1818 | m_upTarget = (ActionTypes)prefwin->upAction(); |
1819 | m_downTarget = (ActionTypes)prefwin->downAction(); | 1819 | m_downTarget = (ActionTypes)prefwin->downAction(); |
1820 | m_leftScroll = prefwin->leftScroll(); | 1820 | m_leftScroll = prefwin->leftScroll(); |
1821 | m_rightScroll = prefwin->rightScroll(); | 1821 | m_rightScroll = prefwin->rightScroll(); |
1822 | m_upScroll = prefwin->upScroll(); | 1822 | m_upScroll = prefwin->upScroll(); |
1823 | m_downScroll = prefwin->downScroll(); | 1823 | m_downScroll = prefwin->downScroll(); |
1824 | 1824 | ||
1825 | m_targetapp = prefwin->dictApplication(); | 1825 | m_targetapp = prefwin->dictApplication(); |
1826 | m_targetmsg = prefwin->dictMessage(); | 1826 | m_targetmsg = prefwin->dictMessage(); |
1827 | 1827 | ||
1828 | m_doAnnotation = prefwin->miscannotation(); | 1828 | m_doAnnotation = prefwin->miscannotation(); |
1829 | m_doDictionary = prefwin->miscdictionary(); | 1829 | m_doDictionary = prefwin->miscdictionary(); |
1830 | m_doClipboard = prefwin->miscclipboard(); | 1830 | m_doClipboard = prefwin->miscclipboard(); |
1831 | reader->m_swapmouse = prefwin->SwapMouse(); | 1831 | reader->m_swapmouse = prefwin->SwapMouse(); |
1832 | reader->setBaseSize(prefwin->gfxsize()); | 1832 | reader->setBaseSize(prefwin->gfxsize()); |
1833 | reader->m_overlap = prefwin->pageoverlap(); | 1833 | reader->m_overlap = prefwin->pageoverlap(); |
1834 | reader->m_bMonoSpaced = prefwin->ideogram(); | 1834 | reader->m_bMonoSpaced = prefwin->ideogram(); |
1835 | m_setmono_action->setOn(reader->m_bMonoSpaced); | 1835 | m_setmono_action->setOn(reader->m_bMonoSpaced); |
1836 | reader->m_encd = prefwin->encoding(); | 1836 | reader->m_encd = prefwin->encoding(); |
1837 | reader->m_charpc = prefwin->ideogramwidth(); | 1837 | reader->m_charpc = prefwin->ideogramwidth(); |
1838 | 1838 | ||
1839 | if ( | 1839 | if ( |
1840 | reader->m_fontname != prefwin->Font() | 1840 | reader->m_fontname != prefwin->Font() |
1841 | || | 1841 | || |
1842 | m_propogatefontchange != prefwin->propfontchange()) | 1842 | m_propogatefontchange != prefwin->propfontchange()) |
1843 | { | 1843 | { |
1844 | m_propogatefontchange = prefwin->propfontchange(); | 1844 | m_propogatefontchange = prefwin->propfontchange(); |
1845 | setfontHelper(prefwin->Font()); | 1845 | setfontHelper(prefwin->Font()); |
1846 | } | 1846 | } |
1847 | delete prefwin; | 1847 | delete prefwin; |
1848 | reader->setfilter(reader->getfilter()); | 1848 | reader->setfilter(reader->getfilter()); |
1849 | reader->refresh(); | 1849 | reader->refresh(); |
1850 | 1850 | ||
1851 | } | 1851 | } |
1852 | else | 1852 | else |
1853 | { | 1853 | { |
1854 | delete prefwin; | 1854 | delete prefwin; |
1855 | } | 1855 | } |
1856 | } | 1856 | } |
1857 | 1857 | ||
1858 | void QTReaderApp::showtoolbarprefs() | 1858 | void QTReaderApp::showtoolbarprefs() |
1859 | { | 1859 | { |
1860 | #ifdef USEQPE | 1860 | #ifdef USEQPE |
1861 | CBarPrefs* prefwin = new CBarPrefs(APPDIR, !m_bFloatingDialog, this); | 1861 | CBarPrefs* prefwin = new CBarPrefs(APPDIR, !m_bFloatingDialog, this); |
1862 | #else | 1862 | #else |
1863 | QFileInfo fi; | 1863 | QFileInfo fi; |
1864 | QDir d = QDir::home(); // "/" | 1864 | QDir d = QDir::home(); // "/" |
1865 | if ( !d.cd(APPDIR) ) | 1865 | if ( !d.cd(APPDIR) ) |
1866 | { // "/tmp" | 1866 | { // "/tmp" |
1867 | qWarning( "Cannot find the \"~/%s\" directory", APPDIR ); | 1867 | qWarning( "Cannot find the \"~/%s\" directory", APPDIR ); |
1868 | d = QDir::home(); | 1868 | d = QDir::home(); |
1869 | d.mkdir(APPDIR); | 1869 | d.mkdir(APPDIR); |
1870 | d.cd(APPDIR); | 1870 | d.cd(APPDIR); |
1871 | } | 1871 | } |
1872 | fi.setFile(d, INIFILE); | 1872 | fi.setFile(d, INIFILE); |
1873 | CBarPrefs* prefwin = new CBarPrefs(fi.absFilePath(), !m_bFloatingDialog, this); | 1873 | CBarPrefs* prefwin = new CBarPrefs(fi.absFilePath(), !m_bFloatingDialog, this); |
1874 | #endif | 1874 | #endif |
1875 | prefwin->tbpolicy(m_tbpolsave); | 1875 | prefwin->tbpolicy(m_tbpolsave); |
1876 | prefwin->tbposition(m_tbposition-2); | 1876 | prefwin->tbposition(m_tbposition-2); |
1877 | prefwin->tbmovable(m_tbmovesave); | 1877 | prefwin->tbmovable(m_tbmovesave); |
1878 | prefwin->floating(m_bFloatingDialog); | 1878 | prefwin->floating(m_bFloatingDialog); |
1879 | if (prefwin->exec()) | 1879 | if (prefwin->exec()) |
1880 | { | 1880 | { |
1881 | m_bFloatingDialog = prefwin->floating(); | 1881 | m_bFloatingDialog = prefwin->floating(); |
1882 | if ( | 1882 | if ( |
1883 | m_tbpolsave != (ToolbarPolicy)prefwin->tbpolicy() | 1883 | m_tbpolsave != (ToolbarPolicy)prefwin->tbpolicy() |
1884 | || | 1884 | || |
1885 | m_tbposition != (ToolBarDock)(prefwin->tbposition()+2) | 1885 | m_tbposition != (ToolBarDock)(prefwin->tbposition()+2) |
1886 | || | 1886 | || |
1887 | m_tbmovesave != prefwin->tbmovable() | 1887 | m_tbmovesave != prefwin->tbmovable() |
1888 | ) | 1888 | ) |
1889 | { | 1889 | { |
1890 | QMessageBox::warning(this, PROGNAME, "Some changes won't take effect\nuntil the next time the\napplication is started"); | 1890 | QMessageBox::warning(this, PROGNAME, "Some changes won't take effect\nuntil the next time the\napplication is started"); |
1891 | } | 1891 | } |
1892 | m_tbpolsave = (ToolbarPolicy)prefwin->tbpolicy(); | 1892 | m_tbpolsave = (ToolbarPolicy)prefwin->tbpolicy(); |
1893 | m_tbposition = (ToolBarDock)(prefwin->tbposition()+2); | 1893 | m_tbposition = (ToolBarDock)(prefwin->tbposition()+2); |
1894 | m_tbmovesave = prefwin->tbmovable(); | 1894 | m_tbmovesave = prefwin->tbmovable(); |
1895 | bool isChanged = prefwin->isChanged(); | 1895 | bool isChanged = prefwin->isChanged(); |
1896 | delete prefwin; | 1896 | delete prefwin; |
1897 | #ifdef USEQPE | 1897 | #ifdef USEQPE |
1898 | Config config( APPDIR ); | 1898 | Config config( APPDIR ); |
1899 | #else | 1899 | #else |
1900 | QFileInfo fi; | 1900 | QFileInfo fi; |
1901 | QDir d = QDir::home(); // "/" | 1901 | QDir d = QDir::home(); // "/" |
1902 | if ( !d.cd(APPDIR) ) | 1902 | if ( !d.cd(APPDIR) ) |
1903 | { // "/tmp" | 1903 | { // "/tmp" |
1904 | qWarning( "Cannot find the \"~/%s\" directory", APPDIR ); | 1904 | qWarning( "Cannot find the \"~/%s\" directory", APPDIR ); |
1905 | d = QDir::home(); | 1905 | d = QDir::home(); |
1906 | d.mkdir(APPDIR); | 1906 | d.mkdir(APPDIR); |
1907 | d.cd(APPDIR); | 1907 | d.cd(APPDIR); |
1908 | } | 1908 | } |
1909 | fi.setFile(d, INIFILE); | 1909 | fi.setFile(d, INIFILE); |
1910 | Config config( fi.absFilePath() ); | 1910 | Config config( fi.absFilePath() ); |
1911 | #endif | 1911 | #endif |
1912 | if (isChanged) addtoolbars(&config); | 1912 | if (isChanged) addtoolbars(&config); |
1913 | } | 1913 | } |
1914 | else | 1914 | else |
1915 | { | 1915 | { |
1916 | delete prefwin; | 1916 | delete prefwin; |
1917 | } | 1917 | } |
1918 | } | 1918 | } |
1919 | 1919 | ||
1920 | void QTReaderApp::showinfo() | 1920 | void QTReaderApp::showinfo() |
1921 | { | 1921 | { |
1922 | unsigned long fs, ts, pl; | 1922 | unsigned long fs, ts, pl; |
1923 | if (reader->empty()) | 1923 | if (reader->empty()) |
1924 | { | 1924 | { |
1925 | QMessageBox::information(this, PROGNAME, "No file loaded", 1); | 1925 | QMessageBox::information(this, PROGNAME, "No file loaded", 1); |
1926 | } | 1926 | } |
1927 | else | 1927 | else |
1928 | { | 1928 | { |
1929 | reader->sizes(fs,ts); | 1929 | reader->sizes(fs,ts); |
1930 | pl = reader->pagelocate(); | 1930 | pl = reader->pagelocate(); |
1931 | m_infoWin->setFileSize(fs); | 1931 | m_infoWin->setFileSize(fs); |
1932 | m_infoWin->setTextSize(ts); | 1932 | m_infoWin->setTextSize(ts); |
1933 | m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts); | 1933 | m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts); |
1934 | m_infoWin->setLocation(pl); | 1934 | m_infoWin->setLocation(pl); |
1935 | m_infoWin->setRead((100*pl + (ts >> 1))/ts); | 1935 | m_infoWin->setRead((100*pl + (ts >> 1))/ts); |
1936 | editorStack->raiseWidget( m_infoWin ); | 1936 | editorStack->raiseWidget( m_infoWin ); |
1937 | m_infoWin->setFocus(); | 1937 | m_infoWin->setFocus(); |
1938 | } | 1938 | } |
1939 | } | 1939 | } |
1940 | 1940 | ||
1941 | void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn) | 1941 | void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn) |
1942 | { | 1942 | { |
1943 | if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>; | 1943 | if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>; |
1944 | #ifdef _UNICODE | 1944 | #ifdef _UNICODE |
1945 | CBuffer buff(name.length()+1); | 1945 | CBuffer buff(name.length()+1); |
1946 | int i; | 1946 | int i; |
1947 | for (i = 0; i < name.length(); i++) | 1947 | for (i = 0; i < name.length(); i++) |
1948 | { | 1948 | { |
1949 | buff[i] = name[i].unicode(); | 1949 | buff[i] = name[i].unicode(); |
1950 | } | 1950 | } |
1951 | buff[i] = 0; | 1951 | buff[i] = 0; |
1952 | CBuffer buff2(text.length()+1); | 1952 | CBuffer buff2(text.length()+1); |
1953 | for (i = 0; i < text.length(); i++) | 1953 | for (i = 0; i < text.length(); i++) |
1954 | { | 1954 | { |
1955 | buff2[i] = text[i].unicode(); | 1955 | buff2[i] = text[i].unicode(); |
1956 | } | 1956 | } |
1957 | buff2[i] = 0; | 1957 | buff2[i] = 0; |
1958 | pBkmklist->push_front(Bkmk(buff.data(), buff2.data(), posn)); | 1958 | pBkmklist->push_front(Bkmk(buff.data(), buff2.data(), posn)); |
1959 | #else | 1959 | #else |
1960 | pBkmklist->push_front(Bkmk((const tchar*)text,posn)); | 1960 | pBkmklist->push_front(Bkmk((const tchar*)text,posn)); |
1961 | #endif | 1961 | #endif |
1962 | m_fBkmksChanged = true; | 1962 | m_fBkmksChanged = true; |
1963 | pBkmklist->sort(); | 1963 | pBkmklist->sort(); |
1964 | } | 1964 | } |
1965 | 1965 | ||
1966 | void QTReaderApp::addAnno(const QString& name, const QString& text) | 1966 | void QTReaderApp::addAnno(const QString& name, const QString& text) |
1967 | { | 1967 | { |
1968 | if (m_annoIsEditing) | 1968 | if (m_annoIsEditing) |
1969 | { | 1969 | { |
1970 | if (name.isEmpty()) | 1970 | if (name.isEmpty()) |
1971 | { | 1971 | { |
1972 | QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nPlease try again", 1); | 1972 | QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nPlease try again", 1); |
1973 | } | 1973 | } |
1974 | else | 1974 | else |
1975 | { | 1975 | { |
1976 | addAnno(name, text, m_annoWin->getPosn()); | 1976 | addAnno(name, text, m_annoWin->getPosn()); |
1977 | } | 1977 | } |
1978 | showEditTools(); | 1978 | showEditTools(); |
1979 | } | 1979 | } |
1980 | else | 1980 | else |
1981 | { | 1981 | { |
1982 | if (m_annoWin->edited()) | 1982 | if (m_annoWin->edited()) |
1983 | { | 1983 | { |
1984 | CBuffer buff(text.length()+1); | 1984 | CBuffer buff(text.length()+1); |
1985 | int i; | 1985 | int i; |
1986 | for (i = 0; i < text.length(); i++) | 1986 | for (i = 0; i < text.length(); i++) |
1987 | { | 1987 | { |
1988 | buff[i] = text[i].unicode(); | 1988 | buff[i] = text[i].unicode(); |
1989 | } | 1989 | } |
1990 | buff[i] = 0; | 1990 | buff[i] = 0; |
1991 | m_fBkmksChanged = true; | 1991 | m_fBkmksChanged = true; |
1992 | m_anno->setAnno(buff.data()); | 1992 | m_anno->setAnno(buff.data()); |
1993 | } | 1993 | } |
1994 | bool found = findNextBookmark(m_anno->value()+1); | 1994 | bool found = findNextBookmark(m_anno->value()+1); |
1995 | if (found) | 1995 | if (found) |
1996 | { | 1996 | { |
1997 | m_annoWin->setName(toQString(m_anno->name())); | 1997 | m_annoWin->setName(toQString(m_anno->name())); |
1998 | m_annoWin->setAnno(toQString(m_anno->anno())); | 1998 | m_annoWin->setAnno(toQString(m_anno->anno())); |
1999 | } | 1999 | } |
2000 | else | 2000 | else |
2001 | { | 2001 | { |
2002 | showEditTools(); | 2002 | showEditTools(); |
2003 | } | 2003 | } |
2004 | } | 2004 | } |
2005 | } | 2005 | } |
2006 | 2006 | ||
2007 | bool QTReaderApp::findNextBookmark(size_t start) | 2007 | bool QTReaderApp::findNextBookmark(size_t start) |
2008 | { | 2008 | { |
2009 | bool found = false; | 2009 | bool found = false; |
2010 | for (CList<Bkmk>::iterator iter = pBkmklist->begin(); iter != pBkmklist->end(); iter++) | 2010 | for (CList<Bkmk>::iterator iter = pBkmklist->begin(); iter != pBkmklist->end(); iter++) |
2011 | { | 2011 | { |
2012 | if (iter->value() >= start) | 2012 | if (iter->value() >= start) |
2013 | { | 2013 | { |
2014 | if (iter->value() < reader->locate()) | 2014 | if (iter->value() < reader->locate()) |
2015 | { | 2015 | { |
2016 | found = true; | 2016 | found = true; |
2017 | m_anno = iter.pContent(); | 2017 | m_anno = iter.pContent(); |
2018 | } | 2018 | } |
2019 | break; | 2019 | break; |
2020 | } | 2020 | } |
2021 | } | 2021 | } |
2022 | return found; | 2022 | return found; |
2023 | } | 2023 | } |
2024 | 2024 | ||
2025 | void QTReaderApp::addanno() | 2025 | void QTReaderApp::addanno() |
2026 | { | 2026 | { |
2027 | if (reader->empty()) | 2027 | if (reader->empty()) |
2028 | { | 2028 | { |
2029 | QMessageBox::information(this, PROGNAME, "No file loaded", 1); | 2029 | QMessageBox::information(this, PROGNAME, "No file loaded", 1); |
2030 | } | 2030 | } |
2031 | else | 2031 | else |
2032 | { | 2032 | { |
2033 | m_annoWin->setName(""); | 2033 | m_annoWin->setName(""); |
2034 | m_annoWin->setAnno(""); | 2034 | m_annoWin->setAnno(""); |
2035 | m_annoWin->setPosn(reader->pagelocate()); | 2035 | m_annoWin->setPosn(reader->pagelocate()); |
2036 | m_annoIsEditing = true; | 2036 | m_annoIsEditing = true; |
2037 | editorStack->raiseWidget( m_annoWin ); | 2037 | editorStack->raiseWidget( m_annoWin ); |
2038 | #ifdef USEQPE | 2038 | #ifdef USEQPE |
2039 | Global::showInputMethod(); | 2039 | Global::showInputMethod(); |
2040 | #endif | 2040 | #endif |
2041 | m_annoWin->setFocus(); | 2041 | m_annoWin->setFocus(); |
2042 | } | 2042 | } |
2043 | } | 2043 | } |
2044 | 2044 | ||
2045 | void QTReaderApp::infoClose() | 2045 | void QTReaderApp::infoClose() |
2046 | { | 2046 | { |
2047 | showEditTools(); | 2047 | showEditTools(); |
2048 | } | 2048 | } |
2049 | 2049 | ||
2050 | /* | 2050 | /* |
2051 | void QTReaderApp::fileRevert() | 2051 | void QTReaderApp::fileRevert() |
2052 | { | 2052 | { |
2053 | clear(); | 2053 | clear(); |
2054 | fileOpen(); | 2054 | fileOpen(); |
2055 | } | 2055 | } |
2056 | 2056 | ||
2057 | void QTReaderApp::editCut() | 2057 | void QTReaderApp::editCut() |
2058 | { | 2058 | { |
2059 | #ifndef QT_NO_CLIPBOARD | 2059 | #ifndef QT_NO_CLIPBOARD |
2060 | editor->cut(); | 2060 | editor->cut(); |
2061 | #endif | 2061 | #endif |
2062 | } | 2062 | } |
2063 | */ | 2063 | */ |
2064 | void QTReaderApp::editMark() | 2064 | void QTReaderApp::editMark() |
2065 | { | 2065 | { |
2066 | m_savedpos = reader->pagelocate(); | 2066 | m_savedpos = reader->pagelocate(); |
2067 | } | 2067 | } |
2068 | 2068 | ||
2069 | void QTReaderApp::editCopy() | 2069 | void QTReaderApp::editCopy() |
2070 | { | 2070 | { |
2071 | QClipboard* cb = QApplication::clipboard(); | 2071 | QClipboard* cb = QApplication::clipboard(); |
2072 | QString text; | 2072 | QString text; |
2073 | int ch; | 2073 | int ch; |
2074 | unsigned long currentpos = reader->pagelocate(); | 2074 | unsigned long currentpos = reader->pagelocate(); |
2075 | unsigned long endpos = reader->locate(); | 2075 | unsigned long endpos = reader->locate(); |
2076 | if (m_savedpos == 0xffffffff) | 2076 | if (m_savedpos == 0xffffffff) |
2077 | { | 2077 | { |
2078 | m_savedpos = currentpos; | 2078 | m_savedpos = currentpos; |
2079 | } | 2079 | } |
2080 | reader->jumpto(m_savedpos); | 2080 | reader->jumpto(m_savedpos); |
2081 | while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF) | 2081 | while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF) |
2082 | { | 2082 | { |
2083 | text += ch; | 2083 | text += ch; |
2084 | } | 2084 | } |
2085 | cb->setText(text); | 2085 | cb->setText(text); |
2086 | reader->locate(currentpos); | 2086 | reader->locate(currentpos); |
2087 | m_savedpos = 0xffffffff; | 2087 | m_savedpos = 0xffffffff; |
2088 | } | 2088 | } |
2089 | 2089 | ||
2090 | void QTReaderApp::gotoStart() | 2090 | void QTReaderApp::gotoStart() |
2091 | { | 2091 | { |
2092 | reader->locate(reader->buffdoc.startSection()); | 2092 | reader->locate(reader->buffdoc.startSection()); |
2093 | } | 2093 | } |
2094 | 2094 | ||
2095 | void QTReaderApp::gotoEnd() | 2095 | void QTReaderApp::gotoEnd() |
2096 | { | 2096 | { |
2097 | reader->dopageup(reader->buffdoc.endSection()); | 2097 | reader->dopageup(reader->buffdoc.endSection()); |
2098 | } | 2098 | } |
2099 | 2099 | ||
2100 | void QTReaderApp::pageup() | 2100 | void QTReaderApp::pageup() |
2101 | { | 2101 | { |
2102 | reader->NavUp(); | 2102 | reader->NavUp(); |
2103 | } | 2103 | } |
2104 | 2104 | ||
2105 | void QTReaderApp::pagedn() | 2105 | void QTReaderApp::pagedn() |
2106 | { | 2106 | { |
2107 | reader->NavDown(); | 2107 | reader->NavDown(); |
2108 | } | 2108 | } |
2109 | 2109 | ||
2110 | void QTReaderApp::pagemode(bool _b) | 2110 | void QTReaderApp::pagemode(bool _b) |
2111 | { | 2111 | { |
2112 | reader->setpagemode(_b); | 2112 | reader->setpagemode(_b); |
2113 | } | 2113 | } |
2114 | 2114 | ||
2115 | /* | 2115 | /* |
2116 | void QTReaderApp::setspacing() | 2116 | void QTReaderApp::setspacing() |
2117 | { | 2117 | { |
2118 | m_nRegAction = cMonoSpace; | 2118 | m_nRegAction = cMonoSpace; |
2119 | char lcn[20]; | 2119 | char lcn[20]; |
2120 | sprintf(lcn, "%lu", reader->m_charpc); | 2120 | sprintf(lcn, "%lu", reader->m_charpc); |
2121 | regEdit->setText(lcn); | 2121 | regEdit->setText(lcn); |
2122 | do_regedit(); | 2122 | do_regedit(); |
2123 | } | 2123 | } |
2124 | */ | 2124 | */ |
2125 | void QTReaderApp::settarget() | 2125 | void QTReaderApp::settarget() |
2126 | { | 2126 | { |
2127 | m_nRegAction = cSetTarget; | 2127 | m_nRegAction = cSetTarget; |
2128 | QString text = ((m_targetapp.isEmpty()) ? QString("") : m_targetapp) | 2128 | QString text = ((m_targetapp.isEmpty()) ? QString("") : m_targetapp) |
2129 | + "/" | 2129 | + "/" |
2130 | + ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg); | 2130 | + ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg); |
2131 | regEdit->setText(text); | 2131 | regEdit->setText(text); |
2132 | do_regedit(); | 2132 | do_regedit(); |
2133 | } | 2133 | } |
2134 | 2134 | ||
2135 | /* | 2135 | /* |
2136 | void QTReaderApp::do_mono(const QString& lcn) | 2136 | void QTReaderApp::do_mono(const QString& lcn) |
2137 | { | 2137 | { |
2138 | bool ok; | 2138 | bool ok; |
2139 | unsigned long ulcn = lcn.toULong(&ok); | 2139 | unsigned long ulcn = lcn.toULong(&ok); |
2140 | if (ok) | 2140 | if (ok) |
2141 | { | 2141 | { |
2142 | reader->m_charpc = ulcn; | 2142 | reader->m_charpc = ulcn; |
2143 | reader->setfont(); | 2143 | reader->setfont(); |
2144 | reader->refresh(); | 2144 | reader->refresh(); |
2145 | //reader->setmono(true); | 2145 | //reader->setmono(true); |
2146 | } | 2146 | } |
2147 | else | 2147 | else |
2148 | QMessageBox::information(this, PROGNAME, "Must be a number"); | 2148 | QMessageBox::information(this, PROGNAME, "Must be a number"); |
2149 | } | 2149 | } |
2150 | */ | 2150 | */ |
2151 | /* | 2151 | /* |
2152 | void QTReaderApp::editPaste() | 2152 | void QTReaderApp::editPaste() |
2153 | { | 2153 | { |
2154 | #ifndef QT_NO_CLIPBOARD | 2154 | #ifndef QT_NO_CLIPBOARD |
2155 | editor->paste(); | 2155 | editor->paste(); |
2156 | #endif | 2156 | #endif |
2157 | } | 2157 | } |
2158 | */ | 2158 | */ |
2159 | 2159 | ||
2160 | void QTReaderApp::editFind() | 2160 | void QTReaderApp::editFind() |
2161 | { | 2161 | { |
2162 | searchStart = reader->pagelocate(); | 2162 | searchStart = reader->pagelocate(); |
2163 | #ifdef __ISEARCH | 2163 | #ifdef __ISEARCH |
2164 | searchStack = new QStack<searchrecord>; | 2164 | searchStack = new QStack<searchrecord>; |
2165 | #endif | 2165 | #endif |
2166 | #ifdef USEQPE | 2166 | #ifdef USEQPE |
2167 | Global::showInputMethod(); | 2167 | Global::showInputMethod(); |
2168 | #endif | 2168 | #endif |
2169 | searchBar->show(); | 2169 | searchBar->show(); |
2170 | searchVisible = TRUE; | 2170 | searchVisible = TRUE; |
2171 | searchEdit->setFocus(); | 2171 | searchEdit->setFocus(); |
2172 | #ifdef __ISEARCH | 2172 | #ifdef __ISEARCH |
2173 | searchStack->push(new searchrecord("",reader->pagelocate())); | 2173 | searchStack->push(new searchrecord("",reader->pagelocate())); |
2174 | #endif | 2174 | #endif |
2175 | } | 2175 | } |
2176 | 2176 | ||
2177 | void QTReaderApp::findNext() | 2177 | void QTReaderApp::findNext() |
2178 | { | 2178 | { |
2179 | // // qDebug("findNext called\n"); | 2179 | // // qDebug("findNext called\n"); |
2180 | #ifdef __ISEARCH | 2180 | #ifdef __ISEARCH |
2181 | QString arg = searchEdit->text(); | 2181 | QString arg = searchEdit->text(); |
2182 | #else | 2182 | #else |
2183 | QRegExp arg = searchEdit->text(); | 2183 | QRegExp arg = searchEdit->text(); |
2184 | #endif | 2184 | #endif |
2185 | CDrawBuffer test(&(reader->m_fontControl)); | 2185 | CDrawBuffer test(&(reader->m_fontControl)); |
2186 | size_t start = reader->pagelocate(); | 2186 | size_t start = reader->pagelocate(); |
2187 | reader->jumpto(start); | 2187 | reader->jumpto(start); |
2188 | reader->getline(&test); | 2188 | reader->getline(&test); |
2189 | dosearch(start, test, arg); | 2189 | dosearch(start, test, arg); |
2190 | } | 2190 | } |
2191 | 2191 | ||
2192 | void QTReaderApp::findClose() | 2192 | void QTReaderApp::findClose() |
2193 | { | 2193 | { |
2194 | searchVisible = FALSE; | 2194 | searchVisible = FALSE; |
2195 | searchEdit->setText(""); | 2195 | searchEdit->setText(""); |
2196 | #ifdef USEQPE | 2196 | #ifdef USEQPE |
2197 | Global::hideInputMethod(); | 2197 | Global::hideInputMethod(); |
2198 | #endif | 2198 | #endif |
2199 | searchBar->hide(); | 2199 | searchBar->hide(); |
2200 | #ifdef __ISEARCH | 2200 | #ifdef __ISEARCH |
2201 | // searchStack = new QStack<searchrecord>; | 2201 | // searchStack = new QStack<searchrecord>; |
2202 | while (!searchStack->isEmpty()) | 2202 | while (!searchStack->isEmpty()) |
2203 | { | 2203 | { |
2204 | delete searchStack->pop(); | 2204 | delete searchStack->pop(); |
2205 | } | 2205 | } |
2206 | delete searchStack; | 2206 | delete searchStack; |
2207 | #endif | 2207 | #endif |
2208 | reader->setFocus(); | 2208 | reader->setFocus(); |
2209 | } | 2209 | } |
2210 | 2210 | ||
2211 | void QTReaderApp::regClose() | 2211 | void QTReaderApp::regClose() |
2212 | { | 2212 | { |
2213 | regVisible = FALSE; | 2213 | regVisible = FALSE; |
2214 | regEdit->setText(""); | 2214 | regEdit->setText(""); |
2215 | regBar->hide(); | 2215 | regBar->hide(); |
2216 | #ifdef USEQPE | 2216 | #ifdef USEQPE |
2217 | Global::hideInputMethod(); | 2217 | Global::hideInputMethod(); |
2218 | #endif | 2218 | #endif |
2219 | reader->setFocus(); | 2219 | reader->setFocus(); |
2220 | } | 2220 | } |
2221 | 2221 | ||
2222 | #ifdef __ISEARCH | 2222 | #ifdef __ISEARCH |
2223 | bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QString& arg) | 2223 | bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QString& arg) |
2224 | #else | 2224 | #else |
2225 | bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg) | 2225 | bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg) |
2226 | #endif | 2226 | #endif |
2227 | { | 2227 | { |
2228 | bool ret = true; | 2228 | bool ret = true; |
2229 | unsigned long fs, ts; | 2229 | unsigned long fs, ts; |
2230 | reader->sizes(fs,ts); | 2230 | reader->sizes(fs,ts); |
2231 | size_t pos = reader->locate(); | 2231 | size_t pos = reader->locate(); |
2232 | pbar->setGeometry(searchBar->x(),searchBar->y(),searchBar->width(), searchBar->height()); | 2232 | pbar->setGeometry(searchBar->x(),searchBar->y(),searchBar->width(), searchBar->height()); |
2233 | pbar->show(); | 2233 | pbar->show(); |
2234 | pbar->raise(); | 2234 | pbar->raise(); |
2235 | pbar->reset(); | 2235 | pbar->reset(); |
2236 | int offset; | 2236 | int offset; |
2237 | int lastpc = (100*pos)/ts; | 2237 | int lastpc = (100*pos)/ts; |
2238 | pbar->setProgress(lastpc); | 2238 | pbar->setProgress(lastpc); |
2239 | // qApp->processEvents(); | 2239 | // qApp->processEvents(); |
2240 | if (reader->buffdoc.getpara(test) >= 0) | 2240 | if (reader->buffdoc.getpara(test) >= 0) |
2241 | { | 2241 | { |
2242 | reader->setFocus(); | 2242 | reader->setFocus(); |
2243 | #ifdef __ISEARCH | 2243 | #ifdef __ISEARCH |
2244 | while (strstr(test.data(),(const tchar*)arg) == NULL) | 2244 | while (strstr(test.data(),(const tchar*)arg) == NULL) |
2245 | #else | 2245 | #else |
2246 | #ifdef _UNICODE | 2246 | #ifdef _UNICODE |
2247 | while ((offset = arg.match(toQString(test.data()))) == -1) | 2247 | while ((offset = arg.match(toQString(test.data()))) == -1) |
2248 | #else | 2248 | #else |
2249 | while (arg.match(test.data()) == -1) | 2249 | while (arg.match(test.data()) == -1) |
2250 | #endif | 2250 | #endif |
2251 | #endif | 2251 | #endif |
2252 | { | 2252 | { |
2253 | pos = reader->locate(); | 2253 | pos = reader->locate(); |
2254 | int pc = (100*pos)/ts; | 2254 | int pc = (100*pos)/ts; |
2255 | if (pc != lastpc) | 2255 | if (pc != lastpc) |
2256 | { | 2256 | { |
2257 | pbar->setProgress(pc); | 2257 | pbar->setProgress(pc); |
2258 | qApp->processEvents(); | 2258 | qApp->processEvents(); |
2259 | reader->setFocus(); | 2259 | reader->setFocus(); |
2260 | lastpc = pc; | 2260 | lastpc = pc; |
2261 | } | 2261 | } |
2262 | 2262 | ||
2263 | if (reader->buffdoc.getpara(test) < 0) | 2263 | if (reader->buffdoc.getpara(test) < 0) |
2264 | { | 2264 | { |
2265 | if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2) | 2265 | if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2) |
2266 | pos = searchStart; | 2266 | pos = searchStart; |
2267 | else | 2267 | else |
2268 | pos = start; | 2268 | pos = start; |
2269 | findClose(); | 2269 | findClose(); |
2270 | pbar->hide(); | 2270 | pbar->hide(); |
2271 | reader->locate(pos); | 2271 | reader->locate(pos); |
2272 | return false; | 2272 | return false; |
2273 | } | 2273 | } |
2274 | } | 2274 | } |
2275 | // qDebug("Found it at %u:%u", pos, offset); | 2275 | // qDebug("Found it at %u:%u", pos, offset); |
2276 | pbar->hide(); | 2276 | pbar->hide(); |
2277 | // qDebug("Hid"); | 2277 | // qDebug("Hid"); |
2278 | reader->locate(pos+offset); | 2278 | reader->locate(pos+offset); |
2279 | // qDebug("Loacted"); | 2279 | // qDebug("Loacted"); |
2280 | // qDebug("page up"); | 2280 | // qDebug("page up"); |
2281 | ret = true; | 2281 | ret = true; |
2282 | } | 2282 | } |
2283 | else | 2283 | else |
2284 | { | 2284 | { |
2285 | if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2) | 2285 | if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2) |
2286 | pos = searchStart; | 2286 | pos = searchStart; |
2287 | else | 2287 | else |
2288 | pos = start; | 2288 | pos = start; |
2289 | ret = false; | 2289 | ret = false; |
2290 | findClose(); | 2290 | findClose(); |
2291 | } | 2291 | } |
2292 | return ret; | 2292 | return ret; |
2293 | } | 2293 | } |
2294 | 2294 | ||
2295 | #ifdef __ISEARCH | 2295 | #ifdef __ISEARCH |
2296 | void QTReaderApp::search(const QString & arg) | 2296 | void QTReaderApp::search(const QString & arg) |
2297 | { | 2297 | { |
2298 | searchrecord* ss = searchStack->top(); | 2298 | searchrecord* ss = searchStack->top(); |
2299 | CBuffer test; | 2299 | CBuffer test; |
2300 | size_t start = reader->pagelocate(); | 2300 | size_t start = reader->pagelocate(); |
2301 | bool haspopped = false; | 2301 | bool haspopped = false; |
2302 | while (arg.left(ss->s.length()) != ss->s) | 2302 | while (arg.left(ss->s.length()) != ss->s) |
2303 | { | 2303 | { |
2304 | haspopped = true; | 2304 | haspopped = true; |
2305 | start = ss->pos; | 2305 | start = ss->pos; |
2306 | // reader->locate(start); | 2306 | // reader->locate(start); |
2307 | searchStack->pop(); | 2307 | searchStack->pop(); |
2308 | delete ss; | 2308 | delete ss; |
2309 | } | 2309 | } |
2310 | if (haspopped) reader->locate(start); | 2310 | if (haspopped) reader->locate(start); |
2311 | /* | 2311 | /* |
2312 | if (arg.length() < ss->len) | 2312 | if (arg.length() < ss->len) |
2313 | { | 2313 | { |
2314 | start = ss->pos; | 2314 | start = ss->pos; |
2315 | reader->locate(start); | 2315 | reader->locate(start); |
2316 | searchStack->pop(); | 2316 | searchStack->pop(); |
2317 | delete ss; | 2317 | delete ss; |
2318 | } | 2318 | } |
2319 | */ | 2319 | */ |
2320 | else | 2320 | else |
2321 | { | 2321 | { |
2322 | start = reader->pagelocate(); | 2322 | start = reader->pagelocate(); |
2323 | reader->jumpto(start); | 2323 | reader->jumpto(start); |
2324 | searchStack->push(new searchrecord(arg,start)); | 2324 | searchStack->push(new searchrecord(arg,start)); |
2325 | } | 2325 | } |
2326 | dosearch(start, test, arg); | 2326 | dosearch(start, test, arg); |
2327 | } | 2327 | } |
2328 | #else | 2328 | #else |
2329 | void QTReaderApp::search() | 2329 | void QTReaderApp::search() |
2330 | { | 2330 | { |
2331 | findNext(); | 2331 | findNext(); |
2332 | } | 2332 | } |
2333 | #endif | 2333 | #endif |
2334 | 2334 | ||
2335 | void QTReaderApp::openFile( const QString &f ) | 2335 | void QTReaderApp::openFile( const QString &f ) |
2336 | { | 2336 | { |
2337 | // qDebug("File:%s", (const char*)f); | 2337 | // qDebug("File:%s", (const char*)f); |
2338 | // openFile(DocLnk(f)); | 2338 | // openFile(DocLnk(f)); |
2339 | //} | 2339 | //} |
2340 | // | 2340 | // |
2341 | //void QTReaderApp::openFile( const DocLnk &f ) | 2341 | //void QTReaderApp::openFile( const DocLnk &f ) |
2342 | //{ | 2342 | //{ |
2343 | clear(); | 2343 | clear(); |
2344 | QFileInfo fm(f); | 2344 | QFileInfo fm(f); |
2345 | if ( fm.exists() ) | 2345 | if ( fm.exists() ) |
2346 | { | 2346 | { |
2347 | // QMessageBox::information(0, "Progress", "Calling fileNew()"); | 2347 | // QMessageBox::information(0, "Progress", "Calling fileNew()"); |
2348 | #ifdef USEQPE | 2348 | #ifdef USEQPE |
2349 | if (fm.extension( FALSE ) == "desktop") | 2349 | if (fm.extension( FALSE ) == "desktop") |
2350 | { | 2350 | { |
2351 | DocLnk d(f); | 2351 | DocLnk d(f); |
2352 | QFileInfo fnew(d.file()); | 2352 | QFileInfo fnew(d.file()); |
2353 | fm = fnew; | 2353 | fm = fnew; |
2354 | if (!fm.exists()) return; | 2354 | if (!fm.exists()) return; |
2355 | } | 2355 | } |
2356 | #endif | 2356 | #endif |
2357 | clear(); | 2357 | clear(); |
2358 | 2358 | ||
2359 | reader->setText(fm.baseName(), fm.absFilePath()); | 2359 | reader->setText(fm.baseName(), fm.absFilePath()); |
2360 | m_loadedconfig = readconfig(reader->m_string, false); | 2360 | m_loadedconfig = readconfig(reader->m_string, false); |
2361 | showEditTools(); | 2361 | showEditTools(); |
2362 | readbkmks(); | 2362 | readbkmks(); |
2363 | m_savedpos = 0xffffffff; | 2363 | m_savedpos = 0xffffffff; |
2364 | } | 2364 | } |
2365 | else | 2365 | else |
2366 | { | 2366 | { |
2367 | QMessageBox::information(this, PROGNAME, "File does not exist"); | 2367 | QMessageBox::information(this, PROGNAME, "File does not exist"); |
2368 | reader->m_lastfile = QString::null; | 2368 | reader->m_lastfile = QString::null; |
2369 | } | 2369 | } |
2370 | 2370 | ||
2371 | } | 2371 | } |
2372 | /* | 2372 | /* |
2373 | void QTReaderApp::resizeEvent(QResizeEvent* e) | 2373 | void QTReaderApp::resizeEvent(QResizeEvent* e) |
2374 | { | 2374 | { |
2375 | if (m_fullscreen) | 2375 | if (m_fullscreen) |
2376 | { | 2376 | { |
2377 | showNormal(); | 2377 | showNormal(); |
2378 | showFullScreen(); | 2378 | showFullScreen(); |
2379 | } | 2379 | } |
2380 | } | 2380 | } |
2381 | */ | 2381 | */ |
2382 | void QTReaderApp::handlekey(QKeyEvent* e) | 2382 | void QTReaderApp::handlekey(QKeyEvent* e) |
2383 | { | 2383 | { |
2384 | // qDebug("Keypress event"); | 2384 | // qDebug("Keypress event"); |
2385 | timeb now; | 2385 | timeb now; |
2386 | ftime(&now); | 2386 | ftime(&now); |
2387 | unsigned long etime = (1000*(now.time - m_lastkeytime.time) + now.millitm)-m_lastkeytime.millitm; | 2387 | unsigned long etime = (1000*(now.time - m_lastkeytime.time) + now.millitm)-m_lastkeytime.millitm; |
2388 | if (etime < m_debounce) | 2388 | if (etime < m_debounce) |
2389 | { | 2389 | { |
2390 | return; | 2390 | return; |
2391 | } | 2391 | } |
2392 | m_lastkeytime = now; | 2392 | m_lastkeytime = now; |
2393 | switch(e->key()) | 2393 | switch(e->key()) |
2394 | { | 2394 | { |
2395 | case Key_Escape: | 2395 | case Key_Escape: |
2396 | // qDebug("escape event"); | 2396 | // qDebug("escape event"); |
2397 | if (m_disableesckey) | 2397 | if (m_disableesckey) |
2398 | { | 2398 | { |
2399 | m_disableesckey = false; | 2399 | m_disableesckey = false; |
2400 | } | 2400 | } |
2401 | else | 2401 | else |
2402 | { | 2402 | { |
2403 | m_bcloseDisabled = true; | 2403 | m_bcloseDisabled = true; |
2404 | if (m_fullscreen) | 2404 | if (m_fullscreen) |
2405 | { | 2405 | { |
2406 | m_actFullscreen->setOn(false); | 2406 | m_actFullscreen->setOn(false); |
2407 | e->accept(); | 2407 | e->accept(); |
2408 | } | 2408 | } |
2409 | else | 2409 | else |
2410 | { | 2410 | { |
2411 | // qDebug("escape action"); | 2411 | // qDebug("escape action"); |
2412 | doAction(m_escapeTarget, e); | 2412 | doAction(m_escapeTarget, e); |
2413 | } | 2413 | } |
2414 | } | 2414 | } |
2415 | break; | 2415 | break; |
2416 | case Key_Space: | 2416 | case Key_Space: |
2417 | { | 2417 | { |
2418 | doAction(m_spaceTarget, e); | 2418 | doAction(m_spaceTarget, e); |
2419 | } | 2419 | } |
2420 | break; | 2420 | break; |
2421 | case Key_Return: | 2421 | case Key_Return: |
2422 | { | 2422 | { |
2423 | doAction(m_returnTarget, e); | 2423 | doAction(m_returnTarget, e); |
2424 | } | 2424 | } |
2425 | break; | 2425 | break; |
2426 | case Key_Left: | 2426 | case Key_Left: |
2427 | { | 2427 | { |
2428 | if (reader->m_autoScroll && m_leftScroll) | 2428 | if (reader->m_autoScroll && m_leftScroll) |
2429 | { | 2429 | { |
2430 | reader->reduceScroll(); | 2430 | reader->reduceScroll(); |
2431 | } | 2431 | } |
2432 | else | 2432 | else |
2433 | { | 2433 | { |
2434 | doAction(m_leftTarget, e); | 2434 | doAction(m_leftTarget, e); |
2435 | } | 2435 | } |
2436 | } | 2436 | } |
2437 | break; | 2437 | break; |
2438 | case Key_Right: | 2438 | case Key_Right: |
2439 | { | 2439 | { |
2440 | if (reader->m_autoScroll && m_rightScroll) | 2440 | if (reader->m_autoScroll && m_rightScroll) |
2441 | { | 2441 | { |
2442 | reader->increaseScroll(); | 2442 | reader->increaseScroll(); |
2443 | } | 2443 | } |
2444 | else | 2444 | else |
2445 | { | 2445 | { |
2446 | doAction(m_rightTarget, e); | 2446 | doAction(m_rightTarget, e); |
2447 | } | 2447 | } |
2448 | } | 2448 | } |
2449 | break; | 2449 | break; |
2450 | case Key_Up: | 2450 | case Key_Up: |
2451 | { | 2451 | { |
2452 | if (reader->m_autoScroll && m_upScroll) | 2452 | if (reader->m_autoScroll && m_upScroll) |
2453 | { | 2453 | { |
2454 | reader->increaseScroll(); | 2454 | reader->increaseScroll(); |
2455 | } | 2455 | } |
2456 | else | 2456 | else |
2457 | { | 2457 | { |
2458 | doAction(m_upTarget, e); | 2458 | doAction(m_upTarget, e); |
2459 | } | 2459 | } |
2460 | } | 2460 | } |
2461 | break; | 2461 | break; |
2462 | case Key_Down: | 2462 | case Key_Down: |
2463 | { | 2463 | { |
2464 | if (reader->m_autoScroll && m_downScroll) | 2464 | if (reader->m_autoScroll && m_downScroll) |
2465 | { | 2465 | { |
2466 | reader->reduceScroll(); | 2466 | reader->reduceScroll(); |
2467 | } | 2467 | } |
2468 | else | 2468 | else |
2469 | { | 2469 | { |
2470 | doAction(m_downTarget, e); | 2470 | doAction(m_downTarget, e); |
2471 | } | 2471 | } |
2472 | } | 2472 | } |
2473 | break; | 2473 | break; |
2474 | default: | 2474 | default: |
2475 | { | 2475 | { |
2476 | e->ignore(); | 2476 | e->ignore(); |
2477 | } | 2477 | } |
2478 | 2478 | ||
2479 | /* | 2479 | /* |
2480 | QString msg("Key press was:"); | 2480 | QString msg("Key press was:"); |
2481 | QString key; | 2481 | QString key; |
2482 | msg += key.setNum(e->key()); | 2482 | msg += key.setNum(e->key()); |
2483 | QMessageBox::information(this, PROGNAME, msg); | 2483 | QMessageBox::information(this, PROGNAME, msg); |
2484 | */ | 2484 | */ |
2485 | } | 2485 | } |
2486 | } | 2486 | } |
2487 | 2487 | ||
2488 | void QTReaderApp::showEditTools() | 2488 | void QTReaderApp::showEditTools() |
2489 | { | 2489 | { |
2490 | // if ( !doc ) | 2490 | // if ( !doc ) |
2491 | //close(); | 2491 | //close(); |
2492 | if (m_fullscreen) | 2492 | if (m_fullscreen) |
2493 | { | 2493 | { |
2494 | if (menubar != NULL) menubar->hide(); | 2494 | if (menubar != NULL) menubar->hide(); |
2495 | if (fileBar != NULL) fileBar->hide(); | 2495 | if (fileBar != NULL) fileBar->hide(); |
2496 | if (viewBar != NULL) viewBar->hide(); | 2496 | if (viewBar != NULL) viewBar->hide(); |
2497 | if (navBar != NULL) navBar->hide(); | 2497 | if (navBar != NULL) navBar->hide(); |
2498 | if (markBar != NULL) markBar->hide(); | 2498 | if (markBar != NULL) markBar->hide(); |
2499 | searchBar->hide(); | 2499 | searchBar->hide(); |
2500 | regBar->hide(); | 2500 | regBar->hide(); |
2501 | #ifdef USEQPE | 2501 | #ifdef USEQPE |
2502 | Global::hideInputMethod(); | 2502 | Global::hideInputMethod(); |
2503 | #endif | 2503 | #endif |
2504 | m_fontBar->hide(); | 2504 | m_fontBar->hide(); |
2505 | //showNormal(); | 2505 | //showNormal(); |
2506 | showFullScreen(); | 2506 | showFullScreen(); |
2507 | } | 2507 | } |
2508 | else | 2508 | else |
2509 | { | 2509 | { |
2510 | //qDebug("him"); | 2510 | //qDebug("him"); |
2511 | #ifdef USEQPE | 2511 | #ifdef USEQPE |
2512 | Global::hideInputMethod(); | 2512 | Global::hideInputMethod(); |
2513 | #endif | 2513 | #endif |
2514 | //qDebug("eb"); | 2514 | //qDebug("eb"); |
2515 | menubar->show(); | 2515 | menubar->show(); |
2516 | if (fileBar != NULL) fileBar->show(); | 2516 | if (fileBar != NULL) fileBar->show(); |
2517 | if (viewBar != NULL) viewBar->show(); | 2517 | if (viewBar != NULL) viewBar->show(); |
2518 | if (navBar != NULL) navBar->show(); | 2518 | if (navBar != NULL) navBar->show(); |
2519 | if (markBar != NULL) markBar->show(); | 2519 | if (markBar != NULL) markBar->show(); |
2520 | mb->show(); | 2520 | mb->show(); |
2521 | if ( searchVisible ) | 2521 | if ( searchVisible ) |
2522 | { | 2522 | { |
2523 | #ifdef USEQPE | 2523 | #ifdef USEQPE |
2524 | Global::showInputMethod(); | 2524 | Global::showInputMethod(); |
2525 | #endif | 2525 | #endif |
2526 | searchBar->show(); | 2526 | searchBar->show(); |
2527 | } | 2527 | } |
2528 | if ( regVisible ) | 2528 | if ( regVisible ) |
2529 | { | 2529 | { |
2530 | #ifdef USEQPE | 2530 | #ifdef USEQPE |
2531 | Global::showInputMethod(); | 2531 | Global::showInputMethod(); |
2532 | #endif | 2532 | #endif |
2533 | regBar->show(); | 2533 | regBar->show(); |
2534 | } | 2534 | } |
2535 | if (m_fontVisible) m_fontBar->show(); | 2535 | if (m_fontVisible) m_fontBar->show(); |
2536 | //qDebug("sn"); | 2536 | //qDebug("sn"); |
2537 | showNormal(); | 2537 | showNormal(); |
2538 | //qDebug("sm"); | 2538 | //qDebug("sm"); |
2539 | #ifdef USEQPE | 2539 | #ifdef USEQPE |
2540 | showMaximized(); | 2540 | showMaximized(); |
2541 | #endif | 2541 | #endif |
2542 | //setCentralWidget(reader); | 2542 | //setCentralWidget(reader); |
2543 | } | 2543 | } |
2544 | 2544 | ||
2545 | // qDebug("uc"); | 2545 | // qDebug("uc"); |
2546 | updateCaption(); | 2546 | updateCaption(); |
2547 | // qDebug("rw"); | 2547 | // qDebug("rw"); |
2548 | editorStack->raiseWidget( reader ); | 2548 | editorStack->raiseWidget( reader ); |
2549 | // qDebug("sf"); | 2549 | // qDebug("sf"); |
2550 | reader->setFocus(); | 2550 | reader->setFocus(); |
2551 | reader->refresh(); | 2551 | reader->refresh(); |
2552 | } | 2552 | } |
2553 | /* | 2553 | /* |
2554 | void QTReaderApp::save() | 2554 | void QTReaderApp::save() |
2555 | { | 2555 | { |
2556 | if ( !doc ) | 2556 | if ( !doc ) |
2557 | return; | 2557 | return; |
2558 | if ( !editor->edited() ) | 2558 | if ( !editor->edited() ) |
2559 | return; | 2559 | return; |
2560 | 2560 | ||
2561 | QString rt = editor->text(); | 2561 | QString rt = editor->text(); |
2562 | QString pt = rt; | 2562 | QString pt = rt; |
2563 | 2563 | ||
2564 | if ( doc->name().isEmpty() ) { | 2564 | if ( doc->name().isEmpty() ) { |
2565 | unsigned ispace = pt.find( ' ' ); | 2565 | unsigned ispace = pt.find( ' ' ); |
2566 | unsigned ienter = pt.find( '\n' ); | 2566 | unsigned ienter = pt.find( '\n' ); |
2567 | int i = (ispace < ienter) ? ispace : ienter; | 2567 | int i = (ispace < ienter) ? ispace : ienter; |
2568 | QString docname; | 2568 | QString docname; |
2569 | if ( i == -1 ) { | 2569 | if ( i == -1 ) { |
2570 | if ( pt.isEmpty() ) | 2570 | if ( pt.isEmpty() ) |
2571 | docname = "Empty Text"; | 2571 | docname = "Empty Text"; |
2572 | else | 2572 | else |
2573 | docname = pt; | 2573 | docname = pt; |
2574 | } else { | 2574 | } else { |
2575 | docname = pt.left( i ); | 2575 | docname = pt.left( i ); |
2576 | } | 2576 | } |
2577 | doc->setName(docname); | 2577 | doc->setName(docname); |
2578 | } | 2578 | } |
2579 | FileManager fm; | 2579 | FileManager fm; |
2580 | fm.saveFile( *doc, rt ); | 2580 | fm.saveFile( *doc, rt ); |
2581 | } | 2581 | } |
2582 | */ | 2582 | */ |
2583 | 2583 | ||
2584 | void QTReaderApp::clear() | 2584 | void QTReaderApp::clear() |
2585 | { | 2585 | { |
2586 | // if (doc != 0) | 2586 | // if (doc != 0) |
2587 | // { | 2587 | // { |
2588 | // QMessageBox::information(this, PROGNAME, "Deleting doc", 1); | 2588 | // QMessageBox::information(this, PROGNAME, "Deleting doc", 1); |
2589 | //delete doc; | 2589 | //delete doc; |
2590 | // QMessageBox::information(this, PROGNAME, "Deleted doc", 1); | 2590 | // QMessageBox::information(this, PROGNAME, "Deleted doc", 1); |
2591 | //doc = 0; | 2591 | //doc = 0; |
2592 | // } | 2592 | // } |
2593 | reader->clear(); | 2593 | reader->clear(); |
2594 | } | 2594 | } |
2595 | 2595 | ||
2596 | void QTReaderApp::updateCaption() | 2596 | void QTReaderApp::updateCaption() |
2597 | { | 2597 | { |
2598 | // if ( !doc ) | 2598 | // if ( !doc ) |
2599 | //setCaption( tr("QTReader") ); | 2599 | //setCaption( tr("QTReader") ); |
2600 | // else { | 2600 | // else { |
2601 | //QString s = doc->name(); | 2601 | //QString s = doc->name(); |
2602 | //if ( s.isEmpty() ) | 2602 | //if ( s.isEmpty() ) |
2603 | // s = tr( "Unnamed" ); | 2603 | // s = tr( "Unnamed" ); |
2604 | setCaption( reader->m_string + " - " + tr("Reader") ); | 2604 | setCaption( reader->m_string + " - " + tr("Reader") ); |
2605 | // } | 2605 | // } |
2606 | } | 2606 | } |
2607 | 2607 | ||
2608 | void QTReaderApp::setDocument(const QString& fileref) | 2608 | void QTReaderApp::setDocument(const QString& fileref) |
2609 | { | 2609 | { |
2610 | bFromDocView = TRUE; | 2610 | bFromDocView = TRUE; |
2611 | //QMessageBox::information(0, "setDocument", fileref); | 2611 | //QMessageBox::information(0, "setDocument", fileref); |
2612 | openFile(fileref); | 2612 | openFile(fileref); |
2613 | // showEditTools(); | 2613 | // showEditTools(); |
2614 | } | 2614 | } |
2615 | 2615 | ||
2616 | void QTReaderApp::closeEvent( QCloseEvent *e ) | 2616 | void QTReaderApp::closeEvent( QCloseEvent *e ) |
2617 | { | 2617 | { |
2618 | // qDebug("Close event"); | 2618 | // qDebug("Close event"); |
2619 | if (m_fullscreen) | 2619 | if (m_fullscreen) |
2620 | { | 2620 | { |
2621 | m_fullscreen = false; | 2621 | m_fullscreen = false; |
2622 | showEditTools(); | 2622 | showEditTools(); |
2623 | e->accept(); | 2623 | e->accept(); |
2624 | } | 2624 | } |
2625 | else if (m_dontSave) | 2625 | else if (m_dontSave) |
2626 | { | 2626 | { |
2627 | e->accept(); | 2627 | e->accept(); |
2628 | } | 2628 | } |
2629 | else | 2629 | else |
2630 | { | 2630 | { |
2631 | if (editorStack->visibleWidget() == reader) | 2631 | if (editorStack->visibleWidget() == reader) |
2632 | { | 2632 | { |
2633 | if ((m_escapeTarget != cesNone) && m_bcloseDisabled) | 2633 | if ((m_escapeTarget != cesNone) && m_bcloseDisabled) |
2634 | { | 2634 | { |
2635 | //qDebug("Close disabled"); | 2635 | //qDebug("Close disabled"); |
2636 | m_bcloseDisabled = false; | 2636 | m_bcloseDisabled = false; |
2637 | e->ignore(); | 2637 | e->ignore(); |
2638 | } | 2638 | } |
2639 | else | 2639 | else |
2640 | { | 2640 | { |
2641 | if (m_fontVisible) | 2641 | if (m_fontVisible) |
2642 | { | 2642 | { |
2643 | m_fontBar->hide(); | 2643 | m_fontBar->hide(); |
2644 | m_fontVisible = false; | 2644 | m_fontVisible = false; |
2645 | } | 2645 | } |
2646 | if (regVisible) | 2646 | if (regVisible) |
2647 | { | 2647 | { |
2648 | regBar->hide(); | 2648 | regBar->hide(); |
2649 | #ifdef USEQPE | 2649 | #ifdef USEQPE |
2650 | Global::hideInputMethod(); | 2650 | Global::hideInputMethod(); |
2651 | #endif | 2651 | #endif |
2652 | regVisible = false; | 2652 | regVisible = false; |
2653 | return; | 2653 | return; |
2654 | } | 2654 | } |
2655 | if (searchVisible) | 2655 | if (searchVisible) |
2656 | { | 2656 | { |
2657 | searchBar->hide(); | 2657 | searchBar->hide(); |
2658 | #ifdef USEQPE | 2658 | #ifdef USEQPE |
2659 | Global::hideInputMethod(); | 2659 | Global::hideInputMethod(); |
2660 | #endif | 2660 | #endif |
2661 | searchVisible = false; | 2661 | searchVisible = false; |
2662 | return; | 2662 | return; |
2663 | } | 2663 | } |
2664 | if (m_fBkmksChanged && pBkmklist != NULL) | 2664 | if (m_fBkmksChanged && pBkmklist != NULL) |
2665 | { | 2665 | { |
2666 | if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0) | 2666 | if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0) |
2667 | savebkmks(); | 2667 | savebkmks(); |
2668 | delete pBkmklist; | 2668 | delete pBkmklist; |
2669 | pBkmklist = NULL; | 2669 | pBkmklist = NULL; |
2670 | m_fBkmksChanged = false; | 2670 | m_fBkmksChanged = false; |
2671 | } | 2671 | } |
2672 | bFromDocView = FALSE; | 2672 | bFromDocView = FALSE; |
2673 | updatefileinfo(); | 2673 | updatefileinfo(); |
2674 | saveprefs(); | 2674 | saveprefs(); |
2675 | e->accept(); | 2675 | e->accept(); |
2676 | } | 2676 | } |
2677 | } | 2677 | } |
2678 | else | 2678 | else |
2679 | { | 2679 | { |
2680 | showEditTools(); | 2680 | showEditTools(); |
2681 | m_disableesckey = true; | 2681 | m_disableesckey = true; |
2682 | } | 2682 | } |
2683 | } | 2683 | } |
2684 | } | 2684 | } |
2685 | 2685 | ||
2686 | void QTReaderApp::do_gotomark() | 2686 | void QTReaderApp::do_gotomark() |
2687 | { | 2687 | { |
2688 | m_nBkmkAction = cGotoBkmk; | 2688 | m_nBkmkAction = cGotoBkmk; |
2689 | if (!listbkmk(pBkmklist)) | 2689 | if (!listbkmk(pBkmklist)) |
2690 | QMessageBox::information(this, PROGNAME, "No bookmarks in memory"); | 2690 | QMessageBox::information(this, PROGNAME, "No bookmarks in memory"); |
2691 | } | 2691 | } |
2692 | 2692 | ||
2693 | void QTReaderApp::do_delmark() | 2693 | void QTReaderApp::do_delmark() |
2694 | { | 2694 | { |
2695 | m_nBkmkAction = cDelBkmk; | 2695 | m_nBkmkAction = cDelBkmk; |
2696 | if (!listbkmk(pBkmklist)) | 2696 | if (!listbkmk(pBkmklist)) |
2697 | QMessageBox::information(this, PROGNAME, "No bookmarks in memory"); | 2697 | QMessageBox::information(this, PROGNAME, "No bookmarks in memory"); |
2698 | } | 2698 | } |
2699 | 2699 | ||
2700 | bool QTReaderApp::listbkmk(CList<Bkmk>* plist, const QString& _lab) | 2700 | bool QTReaderApp::listbkmk(CList<Bkmk>* plist, const QString& _lab) |
2701 | { | 2701 | { |
2702 | bkmkselector->clear(); | 2702 | bkmkselector->clear(); |
2703 | if (_lab.isEmpty()) | 2703 | if (_lab.isEmpty()) |
2704 | bkmkselector->setText("Cancel"); | 2704 | bkmkselector->setText("Cancel"); |
2705 | else | 2705 | else |
2706 | bkmkselector->setText(_lab); | 2706 | bkmkselector->setText(_lab); |
2707 | int cnt = 0; | 2707 | int cnt = 0; |
2708 | if (plist != NULL) | 2708 | if (plist != NULL) |
2709 | { | 2709 | { |
2710 | for (CList<Bkmk>::iterator i = plist->begin(); i != plist->end(); i++) | 2710 | for (CList<Bkmk>::iterator i = plist->begin(); i != plist->end(); i++) |
2711 | { | 2711 | { |
2712 | #ifdef _UNICODE | 2712 | #ifdef _UNICODE |
2713 | // qDebug("Item:%s", (const char*)toQString(i->name())); | 2713 | // qDebug("Item:%s", (const char*)toQString(i->name())); |
2714 | bkmkselector->insertItem(toQString(i->name())); | 2714 | bkmkselector->insertItem(toQString(i->name())); |
2715 | #else | 2715 | #else |
2716 | bkmkselector->insertItem(i->name()); | 2716 | bkmkselector->insertItem(i->name()); |
2717 | #endif | 2717 | #endif |
2718 | cnt++; | 2718 | cnt++; |
2719 | } | 2719 | } |
2720 | } | 2720 | } |
2721 | if (cnt > 0) | 2721 | if (cnt > 0) |
2722 | { | 2722 | { |
2723 | hidetoolbars(); | 2723 | hidetoolbars(); |
2724 | editorStack->raiseWidget( bkmkselector ); | 2724 | editorStack->raiseWidget( bkmkselector ); |
2725 | return true; | 2725 | return true; |
2726 | } | 2726 | } |
2727 | else | 2727 | else |
2728 | return false; | 2728 | return false; |
2729 | } | 2729 | } |
2730 | 2730 | ||
2731 | void QTReaderApp::do_autogen() | 2731 | void QTReaderApp::do_autogen() |
2732 | { | 2732 | { |
2733 | m_nRegAction = cAutoGen; | 2733 | m_nRegAction = cAutoGen; |
2734 | regEdit->setText(m_autogenstr); | 2734 | regEdit->setText(m_autogenstr); |
2735 | do_regedit(); | 2735 | do_regedit(); |
2736 | } | 2736 | } |
2737 | 2737 | ||
2738 | void QTReaderApp::do_regedit() | 2738 | void QTReaderApp::do_regedit() |
2739 | { | 2739 | { |
2740 | // fileBar->hide(); | 2740 | // fileBar->hide(); |
2741 | reader->bDoUpdates = false; | 2741 | reader->bDoUpdates = false; |
2742 | // qDebug("Showing regbar"); | 2742 | // qDebug("Showing regbar"); |
2743 | regBar->show(); | 2743 | regBar->show(); |
2744 | // qDebug("Showing kbd"); | 2744 | // qDebug("Showing kbd"); |
2745 | #ifdef USEQPE | 2745 | #ifdef USEQPE |
2746 | Global::showInputMethod(); | 2746 | Global::showInputMethod(); |
2747 | #endif | 2747 | #endif |
2748 | regVisible = true; | 2748 | regVisible = true; |
2749 | regEdit->setFocus(); | 2749 | regEdit->setFocus(); |
2750 | // qApp->processEvents(); | 2750 | // qApp->processEvents(); |
2751 | reader->bDoUpdates = true; | 2751 | reader->bDoUpdates = true; |
2752 | reader->update(); | 2752 | reader->update(); |
2753 | } | 2753 | } |
2754 | 2754 | ||
2755 | bool QTReaderApp::openfrombkmk(Bkmk* bk) | 2755 | bool QTReaderApp::openfrombkmk(Bkmk* bk) |
2756 | { | 2756 | { |
2757 | QString fn = toQString( | 2757 | QString fn = toQString( |
2758 | CFiledata(bk->anno()).name() | 2758 | CFiledata(bk->anno()).name() |
2759 | ); | 2759 | ); |
2760 | //qDebug("fileinfo"); | 2760 | //qDebug("fileinfo"); |
2761 | if (!fn.isEmpty() && QFileInfo(fn).isFile()) | 2761 | if (!fn.isEmpty() && QFileInfo(fn).isFile()) |
2762 | { | 2762 | { |
2763 | //qDebug("Opening"); | 2763 | //qDebug("Opening"); |
2764 | openFile(fn); | 2764 | openFile(fn); |
2765 | struct stat fnstat; | 2765 | struct stat fnstat; |
2766 | stat((const char *)reader->m_lastfile, &fnstat); | 2766 | stat((const char *)reader->m_lastfile, &fnstat); |
2767 | 2767 | ||
2768 | if (CFiledata(bk->anno()).date() | 2768 | if (CFiledata(bk->anno()).date() |
2769 | != fnstat.st_mtime) | 2769 | != fnstat.st_mtime) |
2770 | { | 2770 | { |
2771 | CFiledata fd(bk->anno()); | 2771 | CFiledata fd(bk->anno()); |
2772 | fd.setdate(fnstat.st_mtime); | 2772 | fd.setdate(fnstat.st_mtime); |
2773 | bk->value(0); | 2773 | bk->value(0); |
2774 | } | 2774 | } |
2775 | else | 2775 | else |
2776 | { | 2776 | { |
2777 | unsigned short svlen = bk->filedatalen(); | 2777 | unsigned short svlen = bk->filedatalen(); |
2778 | unsigned char* svdata = bk->filedata(); | 2778 | unsigned char* svdata = bk->filedata(); |
2779 | reader->putSaveData(svdata, svlen); | 2779 | reader->putSaveData(svdata, svlen); |
2780 | // setstate(svdata, svlen); | 2780 | // setstate(svdata, svlen); |
2781 | if (svlen != 0) | 2781 | if (svlen != 0) |
2782 | { | 2782 | { |
2783 | QMessageBox::warning(this, PROGNAME, "Not all file data used\nNew version?"); | 2783 | QMessageBox::warning(this, PROGNAME, "Not all file data used\nNew version?"); |
2784 | } | 2784 | } |
2785 | // qDebug("updating"); | 2785 | // qDebug("updating"); |
2786 | // showEditTools(); | 2786 | // showEditTools(); |
2787 | reader->locate(bk->value()); | 2787 | reader->locate(bk->value()); |
2788 | } | 2788 | } |
2789 | return true; | 2789 | return true; |
2790 | } | 2790 | } |
2791 | else | 2791 | else |
2792 | { | 2792 | { |
2793 | return false; | 2793 | return false; |
2794 | } | 2794 | } |
2795 | } | 2795 | } |
2796 | 2796 | ||
2797 | void QTReaderApp::gotobkmk(int ind) | 2797 | void QTReaderApp::gotobkmk(int ind) |
2798 | { | 2798 | { |
2799 | showEditTools(); | 2799 | showEditTools(); |
2800 | switch (m_nBkmkAction) | 2800 | switch (m_nBkmkAction) |
2801 | { | 2801 | { |
2802 | case cOpenFile: | 2802 | case cOpenFile: |
2803 | { | 2803 | { |
2804 | // qApp->processEvents(); | 2804 | // qApp->processEvents(); |
2805 | if (!openfrombkmk((*pOpenlist)[ind])) | 2805 | if (!openfrombkmk((*pOpenlist)[ind])) |
2806 | { | 2806 | { |
2807 | pOpenlist->erase(ind); | 2807 | pOpenlist->erase(ind); |
2808 | QMessageBox::information(this, PROGNAME, "Can't find file"); | 2808 | QMessageBox::information(this, PROGNAME, "Can't find file"); |
2809 | } | 2809 | } |
2810 | } | 2810 | } |
2811 | break; | 2811 | break; |
2812 | case cGotoBkmk: | 2812 | case cGotoBkmk: |
2813 | reader->locate((*pBkmklist)[ind]->value()); | 2813 | reader->locate((*pBkmklist)[ind]->value()); |
2814 | break; | 2814 | break; |
2815 | case cDelBkmk: | 2815 | case cDelBkmk: |
2816 | //// qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name()); | 2816 | //// qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name()); |
2817 | pBkmklist->erase(ind); | 2817 | pBkmklist->erase(ind); |
2818 | m_fBkmksChanged = true; | 2818 | m_fBkmksChanged = true; |
2819 | // pBkmklist->sort(); | 2819 | // pBkmklist->sort(); |
2820 | break; | 2820 | break; |
2821 | case cRmBkmkFile: | 2821 | case cRmBkmkFile: |
2822 | { | 2822 | { |
2823 | #ifndef USEQPE | 2823 | #ifndef USEQPE |
2824 | QDir d = QDir::home(); // "/" | 2824 | QDir d = QDir::home(); // "/" |
2825 | d.cd(APPDIR); | 2825 | d.cd(APPDIR); |
2826 | d.remove(bkmkselector->text(ind)); | 2826 | d.remove(bkmkselector->text(ind)); |
2827 | #else /* USEQPE */ | 2827 | #else /* USEQPE */ |
2828 | unlink((const char *)Global::applicationFileName(APPDIR,bkmkselector->text(ind))); | 2828 | unlink((const char *)Global::applicationFileName(APPDIR,bkmkselector->text(ind))); |
2829 | #endif /* USEQPE */ | 2829 | #endif /* USEQPE */ |
2830 | } | 2830 | } |
2831 | break; | 2831 | break; |
2832 | case cLdConfig: | 2832 | case cLdConfig: |
2833 | readconfig(bkmkselector->text(ind), false); | 2833 | readconfig(bkmkselector->text(ind), false); |
2834 | break; | 2834 | break; |
2835 | case cRmConfig: | 2835 | case cRmConfig: |
2836 | { | 2836 | { |
2837 | #ifndef USEQPE | 2837 | #ifndef USEQPE |
2838 | QDir d = QDir::home(); // "/" | 2838 | QDir d = QDir::home(); // "/" |
2839 | d.cd(APPDIR "/configs"); | 2839 | d.cd(APPDIR "/configs"); |
2840 | d.remove(bkmkselector->text(ind)); | 2840 | d.remove(bkmkselector->text(ind)); |
2841 | #else /* USEQPE */ | 2841 | #else /* USEQPE */ |
2842 | unlink((const char *)Global::applicationFileName(APPDIR "/configs",bkmkselector->text(ind))); | 2842 | unlink((const char *)Global::applicationFileName(APPDIR "/configs",bkmkselector->text(ind))); |
2843 | #endif /* USEQPE */ | 2843 | #endif /* USEQPE */ |
2844 | } | 2844 | } |
2845 | break; | 2845 | break; |
2846 | case cExportLinks: | 2846 | case cExportLinks: |
2847 | { | 2847 | { |
2848 | #ifndef USEQPE | 2848 | #ifndef USEQPE |
2849 | QDir d = QDir::home(); // "/" | 2849 | QDir d = QDir::home(); // "/" |
2850 | d.cd(APPDIR "/urls"); | 2850 | d.cd(APPDIR "/urls"); |
2851 | QFileInfo fi(d, bkmkselector->text(ind)); | 2851 | QFileInfo fi(d, bkmkselector->text(ind)); |
2852 | if (fi.exists()) | 2852 | if (fi.exists()) |
2853 | { | 2853 | { |
2854 | QString outfile( QFileDialog::getSaveFileName( QString::null, QString::null, this ) ); | 2854 | QString outfile( QFileDialog::getSaveFileName( QString::null, QString::null, this ) ); |
2855 | if (!outfile.isEmpty()) | 2855 | if (!outfile.isEmpty()) |
2856 | { | 2856 | { |
2857 | FILE* fout = fopen((const char *)outfile, "w"); | 2857 | FILE* fout = fopen((const char *)outfile, "w"); |
2858 | if (fout != NULL) | 2858 | if (fout != NULL) |
2859 | { | 2859 | { |
2860 | FILE* fin = fopen((const char *)fi.absFilePath(), "r"); | 2860 | FILE* fin = fopen((const char *)fi.absFilePath(), "r"); |
2861 | if (fin != NULL) | 2861 | if (fin != NULL) |
2862 | { | 2862 | { |
2863 | fprintf(fout, "<html><body>\n"); | 2863 | fprintf(fout, "<html><body>\n"); |
2864 | int ch = 0; | 2864 | int ch = 0; |
2865 | while ((ch = fgetc(fin)) != EOF) | 2865 | while ((ch = fgetc(fin)) != EOF) |
2866 | { | 2866 | { |
2867 | fputc(ch, fout); | 2867 | fputc(ch, fout); |
2868 | } | 2868 | } |
2869 | fclose(fin); | 2869 | fclose(fin); |
2870 | fprintf(fout, "</html></body>\n"); | 2870 | fprintf(fout, "</html></body>\n"); |
2871 | d.remove(bkmkselector->text(ind)); | 2871 | d.remove(bkmkselector->text(ind)); |
2872 | } | 2872 | } |
2873 | fclose(fout); | 2873 | fclose(fout); |
2874 | } | 2874 | } |
2875 | else | 2875 | else |
2876 | QMessageBox::information(this, PROGNAME, "Couldn't open output"); | 2876 | QMessageBox::information(this, PROGNAME, "Couldn't open output"); |
2877 | } | 2877 | } |
2878 | } | 2878 | } |
2879 | #else /* USEQPE */ | 2879 | #else /* USEQPE */ |
2880 | FILE* fin = fopen((const char *)Global::applicationFileName(APPDIR "/urls",bkmkselector->text(ind)), "r"); | 2880 | FILE* fin = fopen((const char *)Global::applicationFileName(APPDIR "/urls",bkmkselector->text(ind)), "r"); |
2881 | if (fin != NULL) | 2881 | if (fin != NULL) |
2882 | { | 2882 | { |
2883 | bool allok = false; | 2883 | bool allok = false; |
2884 | fileBrowser* fb = new fileBrowser(true, this,"OpieReader",!m_bFloatingDialog, 0, "*", QString::null); | 2884 | fileBrowser* fb = new fileBrowser(true, this,"OpieReader",!m_bFloatingDialog, 0, "*", QString::null); |
2885 | if (fb->exec()) | 2885 | if (fb->exec()) |
2886 | { | 2886 | { |
2887 | QString outfile = fb->getCurrentFile(); | 2887 | QString outfile = fb->getCurrentFile(); |
2888 | FILE* fout = fopen((const char *)outfile, "w"); | 2888 | FILE* fout = fopen((const char *)outfile, "w"); |
2889 | if (fout != NULL) | 2889 | if (fout != NULL) |
2890 | { | 2890 | { |
2891 | fprintf(fout, "<html><body>\n"); | 2891 | fprintf(fout, "<html><body>\n"); |
2892 | int ch = 0; | 2892 | int ch = 0; |
2893 | while ((ch = fgetc(fin)) != EOF) | 2893 | while ((ch = fgetc(fin)) != EOF) |
2894 | { | 2894 | { |
2895 | fputc(ch, fout); | 2895 | fputc(ch, fout); |
2896 | } | 2896 | } |
2897 | fprintf(fout, "</html></body>\n"); | 2897 | fprintf(fout, "</html></body>\n"); |
2898 | fclose(fout); | 2898 | fclose(fout); |
2899 | allok = true; | 2899 | allok = true; |
2900 | } | 2900 | } |
2901 | else | 2901 | else |
2902 | QMessageBox::information(this, PROGNAME, "Couldn't open output"); | 2902 | QMessageBox::information(this, PROGNAME, "Couldn't open output"); |
2903 | } | 2903 | } |
2904 | delete fb; | 2904 | delete fb; |
2905 | fclose(fin); | 2905 | fclose(fin); |
2906 | if (allok) unlink((const char *)Global::applicationFileName(APPDIR "/urls",bkmkselector->text(ind))); | 2906 | if (allok) unlink((const char *)Global::applicationFileName(APPDIR "/urls",bkmkselector->text(ind))); |
2907 | } | 2907 | } |
2908 | else | 2908 | else |
2909 | { | 2909 | { |
2910 | QMessageBox::information(this, PROGNAME, "Couldn't open input"); | 2910 | QMessageBox::information(this, PROGNAME, "Couldn't open input"); |
2911 | } | 2911 | } |
2912 | 2912 | ||
2913 | /* | 2913 | /* |
2914 | CFileSelector *f = new CFileSelector("text/html", this, NULL, !m_bFloatingDialog, TRUE, TRUE ); | 2914 | CFileSelector *f = new CFileSelector("text/html", this, NULL, !m_bFloatingDialog, TRUE, TRUE ); |
2915 | int ret = f->exec(); | 2915 | int ret = f->exec(); |
2916 | qDebug("Return:%d", ret); | 2916 | qDebug("Return:%d", ret); |
2917 | DocLnk* doc = f->getDoc(); | 2917 | DocLnk* doc = f->getDoc(); |
2918 | if (doc != NULL) | 2918 | if (doc != NULL) |
2919 | { | 2919 | { |
2920 | FILE* fin = fopen((const char *)Global::applicationFileName(APPDIR "/urls",bkmkselector->text(ind)), "r"); | 2920 | FILE* fin = fopen((const char *)Global::applicationFileName(APPDIR "/urls",bkmkselector->text(ind)), "r"); |
2921 | QString rt; | 2921 | QString rt; |
2922 | rt = "<html><body>\n"; | 2922 | rt = "<html><body>\n"; |
2923 | int ch = 0; | 2923 | int ch = 0; |
2924 | while ((ch = fgetc(fin)) != EOF) | 2924 | while ((ch = fgetc(fin)) != EOF) |
2925 | { | 2925 | { |
2926 | rt += (char)ch; | 2926 | rt += (char)ch; |
2927 | } | 2927 | } |
2928 | fclose(fin); | 2928 | fclose(fin); |
2929 | rt += "</html></body>\n"; | 2929 | rt += "</html></body>\n"; |
2930 | if ( doc->name().isEmpty() ) | 2930 | if ( doc->name().isEmpty() ) |
2931 | { | 2931 | { |
2932 | doc->setName(bkmkselector->text(ind)); | 2932 | doc->setName(bkmkselector->text(ind)); |
2933 | } | 2933 | } |
2934 | FileManager fm; | 2934 | FileManager fm; |
2935 | fm.saveFile( *doc, rt ); | 2935 | fm.saveFile( *doc, rt ); |
2936 | qDebug("YES"); | 2936 | qDebug("YES"); |
2937 | } | 2937 | } |
2938 | else | 2938 | else |
2939 | { | 2939 | { |
2940 | qDebug("NO"); | 2940 | qDebug("NO"); |
2941 | } | 2941 | } |
2942 | delete f; | 2942 | delete f; |
2943 | */ | 2943 | */ |
2944 | 2944 | ||
2945 | #endif /* USEQPE */ | 2945 | #endif /* USEQPE */ |
2946 | } | 2946 | } |
2947 | break; | 2947 | break; |
2948 | } | 2948 | } |
2949 | } | 2949 | } |
2950 | 2950 | ||
2951 | void QTReaderApp::cancelbkmk() | 2951 | void QTReaderApp::cancelbkmk() |
2952 | { | 2952 | { |
2953 | if (m_nBkmkAction == cOpenFile) | 2953 | if (m_nBkmkAction == cOpenFile) |
2954 | { | 2954 | { |
2955 | QString fn = usefilebrowser(); | 2955 | QString fn = usefilebrowser(); |
2956 | if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn); | 2956 | if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn); |
2957 | } | 2957 | } |
2958 | showEditTools(); | 2958 | showEditTools(); |
2959 | } | 2959 | } |
2960 | 2960 | ||
2961 | void QTReaderApp::jump() | 2961 | void QTReaderApp::jump() |
2962 | { | 2962 | { |
2963 | m_nRegAction = cJump; | 2963 | m_nRegAction = cJump; |
2964 | char lcn[20]; | 2964 | char lcn[20]; |
2965 | sprintf(lcn, "%lu", reader->pagelocate()); | 2965 | sprintf(lcn, "%lu", reader->pagelocate()); |
2966 | regEdit->setText(lcn); | 2966 | regEdit->setText(lcn); |
2967 | do_regedit(); | 2967 | do_regedit(); |
2968 | } | 2968 | } |
2969 | 2969 | ||
2970 | void QTReaderApp::do_jump(const QString& lcn) | 2970 | void QTReaderApp::do_jump(const QString& lcn) |
2971 | { | 2971 | { |
2972 | bool ok; | 2972 | bool ok; |
2973 | unsigned long ulcn = lcn.toULong(&ok); | 2973 | unsigned long ulcn = lcn.toULong(&ok); |
2974 | if (ok) | 2974 | if (ok) |
2975 | reader->locate(ulcn); | 2975 | reader->locate(ulcn); |
2976 | else | 2976 | else |
2977 | QMessageBox::information(this, PROGNAME, "Must be a number"); | 2977 | QMessageBox::information(this, PROGNAME, "Must be a number"); |
2978 | } | 2978 | } |
2979 | 2979 | ||
2980 | void QTReaderApp::do_regaction() | 2980 | void QTReaderApp::do_regaction() |
2981 | { | 2981 | { |
2982 | reader->bDoUpdates = false; | 2982 | reader->bDoUpdates = false; |
2983 | regBar->hide(); | 2983 | regBar->hide(); |
2984 | #ifdef USEQPE | 2984 | #ifdef USEQPE |
2985 | Global::hideInputMethod(); | 2985 | Global::hideInputMethod(); |
2986 | #endif | 2986 | #endif |
2987 | regVisible = false; | 2987 | regVisible = false; |
2988 | switch(m_nRegAction) | 2988 | switch(m_nRegAction) |
2989 | { | 2989 | { |
2990 | case cAutoGen: | 2990 | case cAutoGen: |
2991 | do_autogen(regEdit->text()); | 2991 | do_autogen(regEdit->text()); |
2992 | break; | 2992 | break; |
2993 | case cAddBkmk: | 2993 | case cAddBkmk: |
2994 | do_addbkmk(regEdit->text()); | 2994 | do_addbkmk(regEdit->text()); |
2995 | break; | 2995 | break; |
2996 | case cJump: | 2996 | case cJump: |
2997 | do_jump(regEdit->text()); | 2997 | do_jump(regEdit->text()); |
2998 | break; | 2998 | break; |
2999 | /* | 2999 | /* |
3000 | case cMonoSpace: | 3000 | case cMonoSpace: |
3001 | do_mono(regEdit->text()); | 3001 | do_mono(regEdit->text()); |
3002 | break; | 3002 | break; |
3003 | */ | 3003 | */ |
3004 | case cSetTarget: | 3004 | case cSetTarget: |
3005 | do_settarget(regEdit->text()); | 3005 | do_settarget(regEdit->text()); |
3006 | break; | 3006 | break; |
3007 | #ifdef _SCROLLPIPE | 3007 | #ifdef _SCROLLPIPE |
3008 | case cSetPipeTarget: | 3008 | case cSetPipeTarget: |
3009 | do_setpipetarget(regEdit->text()); | 3009 | do_setpipetarget(regEdit->text()); |
3010 | break; | 3010 | break; |
3011 | #endif | 3011 | #endif |
3012 | case cSetConfigName: | 3012 | case cSetConfigName: |
3013 | // qDebug("Saving config"); | 3013 | // qDebug("Saving config"); |
3014 | do_saveconfig(regEdit->text(), false); | 3014 | do_saveconfig(regEdit->text(), false); |
3015 | break; | 3015 | break; |
3016 | } | 3016 | } |
3017 | // reader->restore(); | 3017 | // reader->restore(); |
3018 | // fileBar->show(); | 3018 | // fileBar->show(); |
3019 | reader->setFocus(); | 3019 | reader->setFocus(); |
3020 | // qApp->processEvents(); | 3020 | // qApp->processEvents(); |
3021 | reader->bDoUpdates = true; | 3021 | reader->bDoUpdates = true; |
3022 | reader->update(); | 3022 | reader->update(); |
3023 | } | 3023 | } |
3024 | 3024 | ||
3025 | void QTReaderApp::do_settarget(const QString& _txt) | 3025 | void QTReaderApp::do_settarget(const QString& _txt) |
3026 | { | 3026 | { |
3027 | int ind = _txt.find('/'); | 3027 | int ind = _txt.find('/'); |
3028 | if (ind == -1) | 3028 | if (ind == -1) |
3029 | { | 3029 | { |
3030 | m_targetapp = ""; | 3030 | m_targetapp = ""; |
3031 | m_targetmsg = ""; | 3031 | m_targetmsg = ""; |
3032 | QMessageBox::information(this, PROGNAME, "Format is\nappname/messagename"); | 3032 | QMessageBox::information(this, PROGNAME, "Format is\nappname/messagename"); |
3033 | } | 3033 | } |
3034 | else | 3034 | else |
3035 | { | 3035 | { |
3036 | m_targetapp = _txt.left(ind); | 3036 | m_targetapp = _txt.left(ind); |
3037 | m_targetmsg = _txt.right(_txt.length()-ind-1); | 3037 | m_targetmsg = _txt.right(_txt.length()-ind-1); |
3038 | } | 3038 | } |
3039 | } | 3039 | } |
3040 | 3040 | ||
3041 | void QTReaderApp::chooseencoding() | 3041 | void QTReaderApp::chooseencoding() |
3042 | { | 3042 | { |
3043 | m_fontSelector->clear(); | 3043 | m_fontSelector->clear(); |
3044 | m_fontSelector->insertItem("Ascii"); | 3044 | m_fontSelector->insertItem("Ascii"); |
3045 | m_fontSelector->insertItem("UTF-8"); | 3045 | m_fontSelector->insertItem("UTF-8"); |
3046 | m_fontSelector->insertItem("UCS-2(BE)"); | 3046 | m_fontSelector->insertItem("UCS-2(BE)"); |
3047 | m_fontSelector->insertItem("USC-2(LE)"); | 3047 | m_fontSelector->insertItem("USC-2(LE)"); |
3048 | m_fontSelector->insertItem("Palm"); | 3048 | m_fontSelector->insertItem("Palm"); |
3049 | for (unicodetable::iterator iter = unicodetable::begin(); iter != unicodetable::end(); iter++) | 3049 | for (unicodetable::iterator iter = unicodetable::begin(); iter != unicodetable::end(); iter++) |
3050 | { | 3050 | { |
3051 | m_fontSelector->insertItem(iter->mime); | 3051 | m_fontSelector->insertItem(iter->mime); |
3052 | } // delete the FontDatabase!!! | 3052 | } // delete the FontDatabase!!! |
3053 | m_fontSelector->setCurrentItem (reader->m_encd); | 3053 | m_fontSelector->setCurrentItem (reader->m_encd); |
3054 | m_fontAction = cChooseEncoding; | 3054 | m_fontAction = cChooseEncoding; |
3055 | m_fontBar->show(); | 3055 | m_fontBar->show(); |
3056 | m_fontVisible = true; | 3056 | m_fontVisible = true; |
3057 | } | 3057 | } |
3058 | 3058 | ||
3059 | void QTReaderApp::setfont() | 3059 | void QTReaderApp::setfont() |
3060 | { | 3060 | { |
3061 | m_fontSelector->clear(); | 3061 | m_fontSelector->clear(); |
3062 | { | 3062 | { |
3063 | #ifdef USEQPE | 3063 | #ifdef USEQPE |
3064 | FontDatabase f; | 3064 | FontDatabase f; |
3065 | #else | 3065 | #else |
3066 | QFontDatabase f; | 3066 | QFontDatabase f; |
3067 | #endif | 3067 | #endif |
3068 | QStringList flist = f.families(); | 3068 | QStringList flist = f.families(); |
3069 | m_fontSelector->insertStringList(flist); | 3069 | m_fontSelector->insertStringList(flist); |
3070 | } // delete the FontDatabase!!! | 3070 | } // delete the FontDatabase!!! |
3071 | 3071 | ||
3072 | for (int i = 1; i <= m_fontSelector->count(); i++) | 3072 | for (int i = 1; i <= m_fontSelector->count(); i++) |
3073 | { | 3073 | { |
3074 | if (m_fontSelector->text(i) == reader->m_fontname) | 3074 | if (m_fontSelector->text(i) == reader->m_fontname) |
3075 | { | 3075 | { |
3076 | m_fontSelector->setCurrentItem(i); | 3076 | m_fontSelector->setCurrentItem(i); |
3077 | break; | 3077 | break; |
3078 | } | 3078 | } |
3079 | } | 3079 | } |
3080 | m_fontAction = cChooseFont; | 3080 | m_fontAction = cChooseFont; |
3081 | m_fontBar->show(); | 3081 | m_fontBar->show(); |
3082 | m_fontVisible = true; | 3082 | m_fontVisible = true; |
3083 | } | 3083 | } |
3084 | 3084 | ||
3085 | void QTReaderApp::setfontHelper(const QString& lcn, int size) | 3085 | void QTReaderApp::setfontHelper(const QString& lcn, int size) |
3086 | { | 3086 | { |
3087 | if (size == 0) size = reader->m_fontControl.currentsize(); | 3087 | if (size == 0) size = reader->m_fontControl.currentsize(); |
3088 | if (m_propogatefontchange) | 3088 | if (m_propogatefontchange) |
3089 | { | 3089 | { |
3090 | QFont f(lcn, 10); | 3090 | QFont f(lcn, 10); |
3091 | bkmkselector->setFont( f ); | 3091 | bkmkselector->setFont( f ); |
3092 | regEdit->setFont( f ); | 3092 | regEdit->setFont( f ); |
3093 | searchEdit->setFont( f ); | 3093 | searchEdit->setFont( f ); |
3094 | m_annoWin->setFont( f ); | 3094 | m_annoWin->setFont( f ); |
3095 | } | 3095 | } |
3096 | reader->m_fontname = lcn; | 3096 | reader->m_fontname = lcn; |
3097 | if (!reader->ChangeFont(size)) | 3097 | if (!reader->ChangeFont(size)) |
3098 | { | 3098 | { |
3099 | reader->ChangeFont(size); | 3099 | reader->ChangeFont(size); |
3100 | } | 3100 | } |
3101 | } | 3101 | } |
3102 | 3102 | ||
3103 | void QTReaderApp::do_setencoding(int i) | 3103 | void QTReaderApp::do_setencoding(int i) |
3104 | { | 3104 | { |
3105 | // qDebug("setencoding:%d", i); | 3105 | // qDebug("setencoding:%d", i); |
3106 | if (m_fontAction == cChooseEncoding) | 3106 | if (m_fontAction == cChooseEncoding) |
3107 | { | 3107 | { |
3108 | reader->setencoding(i); | 3108 | reader->setencoding(i); |
3109 | } | 3109 | } |
3110 | reader->refresh(); | 3110 | reader->refresh(); |
3111 | m_fontBar->hide(); | 3111 | m_fontBar->hide(); |
3112 | m_fontVisible = false; | 3112 | m_fontVisible = false; |
3113 | // qDebug("showedit"); | 3113 | // qDebug("showedit"); |
3114 | if (reader->isVisible()) showEditTools(); | 3114 | if (reader->isVisible()) showEditTools(); |
3115 | // qDebug("showeditdone"); | 3115 | // qDebug("showeditdone"); |
3116 | } | 3116 | } |
3117 | 3117 | ||
3118 | void QTReaderApp::do_setfont(const QString& lcn) | 3118 | void QTReaderApp::do_setfont(const QString& lcn) |
3119 | { | 3119 | { |
3120 | if (m_fontAction == cChooseFont) | 3120 | if (m_fontAction == cChooseFont) |
3121 | { | 3121 | { |
3122 | setfontHelper(lcn); | 3122 | setfontHelper(lcn); |
3123 | } | 3123 | } |
3124 | reader->refresh(); | 3124 | reader->refresh(); |
3125 | m_fontBar->hide(); | 3125 | m_fontBar->hide(); |
3126 | m_fontVisible = false; | 3126 | m_fontVisible = false; |
3127 | // qDebug("showedit"); | 3127 | // qDebug("showedit"); |
3128 | //if (reader->isVisible()) | 3128 | //if (reader->isVisible()) |
3129 | showEditTools(); | 3129 | showEditTools(); |
3130 | // qDebug("showeditdone"); | 3130 | // qDebug("showeditdone"); |
3131 | } | 3131 | } |
3132 | 3132 | ||
3133 | void QTReaderApp::do_autogen(const QString& regText) | 3133 | void QTReaderApp::do_autogen(const QString& regText) |
3134 | { | 3134 | { |
3135 | unsigned long fs, ts; | 3135 | unsigned long fs, ts; |
3136 | reader->sizes(fs,ts); | 3136 | reader->sizes(fs,ts); |
3137 | // // qDebug("Reg:%s\n", (const tchar*)(regEdit->text())); | 3137 | // // qDebug("Reg:%s\n", (const tchar*)(regEdit->text())); |
3138 | m_autogenstr = regText; | 3138 | m_autogenstr = regText; |
3139 | QRegExp re(regText); | 3139 | QRegExp re(regText); |
3140 | CBuffer buff; | 3140 | CBuffer buff; |
3141 | if (pBkmklist != NULL) delete pBkmklist; | 3141 | if (pBkmklist != NULL) delete pBkmklist; |
3142 | pBkmklist = new CList<Bkmk>; | 3142 | pBkmklist = new CList<Bkmk>; |
3143 | m_fBkmksChanged = true; | 3143 | m_fBkmksChanged = true; |
3144 | 3144 | ||
3145 | pbar->setGeometry(regBar->x(),regBar->y(),regBar->width(), regBar->height()); | 3145 | pbar->setGeometry(regBar->x(),regBar->y(),regBar->width(), regBar->height()); |
3146 | pbar->show(); | 3146 | pbar->show(); |
3147 | pbar->raise(); | 3147 | pbar->raise(); |
3148 | pbar->reset(); | 3148 | pbar->reset(); |
3149 | reader->update(); | 3149 | reader->update(); |
3150 | qApp->processEvents(); | 3150 | qApp->processEvents(); |
3151 | reader->setFocus(); | 3151 | reader->setFocus(); |
3152 | reader->jumpto(0); | 3152 | reader->jumpto(0); |
3153 | int lastpc = 0; | 3153 | int lastpc = 0; |
3154 | int i = 0; | 3154 | int i = 0; |
3155 | while (i >= 0) | 3155 | while (i >= 0) |
3156 | { | 3156 | { |
3157 | unsigned int lcn = reader->locate(); | 3157 | unsigned int lcn = reader->locate(); |
3158 | int pc = (100*lcn)/ts; | 3158 | int pc = (100*lcn)/ts; |
3159 | if (pc != lastpc) | 3159 | if (pc != lastpc) |
3160 | { | 3160 | { |
3161 | pbar->setProgress(pc); | 3161 | pbar->setProgress(pc); |
3162 | qApp->processEvents(); | 3162 | qApp->processEvents(); |
3163 | if (reader->locate() != lcn) reader->jumpto(lcn); | 3163 | if (reader->locate() != lcn) reader->jumpto(lcn); |
3164 | reader->setFocus(); | 3164 | reader->setFocus(); |
3165 | lastpc = pc; | 3165 | lastpc = pc; |
3166 | } | 3166 | } |
3167 | i = reader->buffdoc.getpara(buff); | 3167 | i = reader->buffdoc.getpara(buff); |
3168 | #ifdef _UNICODE | 3168 | #ifdef _UNICODE |
3169 | if (re.match(toQString(buff.data())) != -1) | 3169 | if (re.match(toQString(buff.data())) != -1) |
3170 | #else | 3170 | #else |
3171 | if (re.match(buff.data()) != -1) | 3171 | if (re.match(buff.data()) != -1) |
3172 | #endif | 3172 | #endif |
3173 | pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn)); | 3173 | pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn)); |
3174 | } | 3174 | } |
3175 | pBkmklist->sort(); | 3175 | pBkmklist->sort(); |
3176 | pbar->setProgress(100); | 3176 | pbar->setProgress(100); |
3177 | qApp->processEvents(); | 3177 | qApp->processEvents(); |
3178 | pbar->hide(); | 3178 | pbar->hide(); |
3179 | reader->refresh(); | 3179 | reader->refresh(); |
3180 | } | 3180 | } |
3181 | 3181 | ||
3182 | void QTReaderApp::saveprefs() | 3182 | void QTReaderApp::saveprefs() |
3183 | { | 3183 | { |
3184 | // qDebug("saveprefs"); | 3184 | // qDebug("saveprefs"); |
3185 | // reader->saveprefs("uqtreader"); | 3185 | // reader->saveprefs("uqtreader"); |
3186 | // if (!m_loadedconfig) | 3186 | // if (!m_loadedconfig) |
3187 | do_saveconfig( APPDIR, true ); | 3187 | do_saveconfig( APPDIR, true ); |
3188 | 3188 | ||
3189 | /* | 3189 | /* |
3190 | Config config( APPDIR ); | 3190 | Config config( APPDIR ); |
3191 | config.setGroup( "View" ); | 3191 | config.setGroup( "View" ); |
3192 | 3192 | ||
3193 | reader->m_lastposn = reader->pagelocate(); | 3193 | reader->m_lastposn = reader->pagelocate(); |
3194 | 3194 | ||
3195 | config.writeEntry("FloatDialogs", m_bFloatingDialog); | 3195 | config.writeEntry("FloatDialogs", m_bFloatingDialog); |
3196 | config.writeEntry( "StripCr", reader->bstripcr ); | 3196 | config.writeEntry( "StripCr", reader->bstripcr ); |
3197 | config.writeEntry( "AutoFmt", reader->bautofmt ); | 3197 | config.writeEntry( "AutoFmt", reader->bautofmt ); |
3198 | config.writeEntry( "TextFmt", reader->btextfmt ); | 3198 | config.writeEntry( "TextFmt", reader->btextfmt ); |
3199 | config.writeEntry( "StripHtml", reader->bstriphtml ); | 3199 | config.writeEntry( "StripHtml", reader->bstriphtml ); |
3200 | config.writeEntry( "Dehyphen", reader->bdehyphen ); | 3200 | config.writeEntry( "Dehyphen", reader->bdehyphen ); |
3201 | config.writeEntry( "Depluck", reader->bdepluck ); | 3201 | config.writeEntry( "Depluck", reader->bdepluck ); |
3202 | config.writeEntry( "Dejpluck", reader->bdejpluck ); | 3202 | config.writeEntry( "Dejpluck", reader->bdejpluck ); |
3203 | config.writeEntry( "OneSpace", reader->bonespace ); | 3203 | config.writeEntry( "OneSpace", reader->bonespace ); |
3204 | config.writeEntry( "Unindent", reader->bunindent ); | 3204 | config.writeEntry( "Unindent", reader->bunindent ); |
3205 | config.writeEntry( "Repara", reader->brepara ); | 3205 | config.writeEntry( "Repara", reader->brepara ); |
3206 | config.writeEntry( "DoubleSpace", reader->bdblspce ); | 3206 | config.writeEntry( "DoubleSpace", reader->bdblspce ); |
3207 | config.writeEntry( "Indent", reader->bindenter ); | 3207 | config.writeEntry( "Indent", reader->bindenter ); |
3208 | config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) ); | 3208 | config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) ); |
3209 | config.writeEntry( "ScrollDelay", reader->m_delay); | 3209 | config.writeEntry( "ScrollDelay", reader->m_delay); |
3210 | config.writeEntry( "LastFile", reader->m_lastfile ); | 3210 | config.writeEntry( "LastFile", reader->m_lastfile ); |
3211 | config.writeEntry( "LastPosn", (int)(reader->pagelocate()) ); | 3211 | config.writeEntry( "LastPosn", (int)(reader->pagelocate()) ); |
3212 | config.writeEntry( "PageMode", reader->m_bpagemode ); | 3212 | config.writeEntry( "PageMode", reader->m_bpagemode ); |
3213 | config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced ); | 3213 | config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced ); |
3214 | config.writeEntry( "SwapMouse", reader->m_swapmouse); | 3214 | config.writeEntry( "SwapMouse", reader->m_swapmouse); |
3215 | config.writeEntry( "Fontname", reader->m_fontname ); | 3215 | config.writeEntry( "Fontname", reader->m_fontname ); |
3216 | config.writeEntry( "Encoding", reader->m_encd ); | 3216 | config.writeEntry( "Encoding", reader->m_encd ); |
3217 | config.writeEntry( "CharSpacing", reader->m_charpc ); | 3217 | config.writeEntry( "CharSpacing", reader->m_charpc ); |
3218 | config.writeEntry( "Overlap", (int)(reader->m_overlap) ); | 3218 | config.writeEntry( "Overlap", (int)(reader->m_overlap) ); |
3219 | config.writeEntry( "Margin", (int)reader->m_border ); | 3219 | config.writeEntry( "Margin", (int)reader->m_border ); |
3220 | config.writeEntry( "TargetApp", m_targetapp ); | 3220 | config.writeEntry( "TargetApp", m_targetapp ); |
3221 | config.writeEntry( "TargetMsg", m_targetmsg ); | 3221 | config.writeEntry( "TargetMsg", m_targetmsg ); |
3222 | #ifdef _SCROLLPIPE | 3222 | #ifdef _SCROLLPIPE |
3223 | config.writeEntry( "PipeTarget", reader->m_pipetarget ); | 3223 | config.writeEntry( "PipeTarget", reader->m_pipetarget ); |
3224 | config.writeEntry( "PauseAfterPara", reader->m_pauseAfterEachPara ); | 3224 | config.writeEntry( "PauseAfterPara", reader->m_pauseAfterEachPara ); |
3225 | #endif | 3225 | #endif |
3226 | config.writeEntry( "TwoTouch", m_twoTouch ); | 3226 | config.writeEntry( "TwoTouch", m_twoTouch ); |
3227 | config.writeEntry( "Annotation", m_doAnnotation); | 3227 | config.writeEntry( "Annotation", m_doAnnotation); |
3228 | config.writeEntry( "Dictionary", m_doDictionary); | 3228 | config.writeEntry( "Dictionary", m_doDictionary); |
3229 | config.writeEntry( "Clipboard", m_doClipboard); | 3229 | config.writeEntry( "Clipboard", m_doClipboard); |
3230 | config.writeEntry( "SpaceTarget", m_spaceTarget); | 3230 | config.writeEntry( "SpaceTarget", m_spaceTarget); |
3231 | config.writeEntry( "EscapeTarget", m_escapeTarget); | 3231 | config.writeEntry( "EscapeTarget", m_escapeTarget); |
3232 | config.writeEntry( "ReturnTarget", m_returnTarget); | 3232 | config.writeEntry( "ReturnTarget", m_returnTarget); |
3233 | config.writeEntry( "LeftTarget", m_leftTarget); | 3233 | config.writeEntry( "LeftTarget", m_leftTarget); |
3234 | config.writeEntry( "RightTarget", m_rightTarget); | 3234 | config.writeEntry( "RightTarget", m_rightTarget); |
3235 | config.writeEntry( "UpTarget", m_upTarget); | 3235 | config.writeEntry( "UpTarget", m_upTarget); |
3236 | config.writeEntry( "DownTarget", m_downTarget); | 3236 | config.writeEntry( "DownTarget", m_downTarget); |
3237 | config.writeEntry("LeftScroll", m_leftScroll); | 3237 | config.writeEntry("LeftScroll", m_leftScroll); |
3238 | config.writeEntry("RightScroll", m_rightScroll); | 3238 | config.writeEntry("RightScroll", m_rightScroll); |
3239 | config.writeEntry("UpScroll", m_upScroll); | 3239 | config.writeEntry("UpScroll", m_upScroll); |
3240 | config.writeEntry("DownScroll", m_downScroll); | 3240 | config.writeEntry("DownScroll", m_downScroll); |
3241 | #ifdef REPALM | 3241 | #ifdef REPALM |
3242 | config.writeEntry( "Repalm", reader->brepalm ); | 3242 | config.writeEntry( "Repalm", reader->brepalm ); |
3243 | #endif | 3243 | #endif |
3244 | config.writeEntry( "Remap", reader->bremap ); | 3244 | config.writeEntry( "Remap", reader->bremap ); |
3245 | config.writeEntry( "Peanut", reader->bpeanut ); | 3245 | config.writeEntry( "Peanut", reader->bpeanut ); |
3246 | config.writeEntry( "MakeBold", reader->bmakebold ); | 3246 | config.writeEntry( "MakeBold", reader->bmakebold ); |
3247 | config.writeEntry( "Continuous", reader->m_continuousDocument ); | 3247 | config.writeEntry( "Continuous", reader->m_continuousDocument ); |
3248 | config.writeEntry( "FullJust", reader->bfulljust ); | 3248 | config.writeEntry( "FullJust", reader->bfulljust ); |
3249 | config.writeEntry( "ExtraSpace", reader->getextraspace() ); | 3249 | config.writeEntry( "ExtraSpace", reader->getextraspace() ); |
3250 | config.writeEntry( "ExtraLead", reader->getlead() ); | 3250 | config.writeEntry( "ExtraLead", reader->getlead() ); |
3251 | config.writeEntry( "Basesize", (int)reader->getBaseSize()); | 3251 | config.writeEntry( "Basesize", (int)reader->getBaseSize()); |
3252 | config.writeEntry( "RequestorFontChange", m_propogatefontchange); | 3252 | config.writeEntry( "RequestorFontChange", m_propogatefontchange); |
3253 | 3253 | ||
3254 | config.setGroup( "Toolbar" ); | 3254 | config.setGroup( "Toolbar" ); |
3255 | config.writeEntry("Movable", m_tbmovesave); | 3255 | config.writeEntry("Movable", m_tbmovesave); |
3256 | config.writeEntry("Policy", m_tbpolsave); | 3256 | config.writeEntry("Policy", m_tbpolsave); |
3257 | config.writeEntry("Position", m_tbposition); | 3257 | config.writeEntry("Position", m_tbposition); |
3258 | */ | 3258 | */ |
3259 | savefilelist(); | 3259 | savefilelist(); |
3260 | } | 3260 | } |
3261 | 3261 | ||
3262 | /* | 3262 | /* |
3263 | void QTReaderApp::oldFile() | 3263 | void QTReaderApp::oldFile() |
3264 | { | 3264 | { |
3265 | // qDebug("oldFile called"); | 3265 | // qDebug("oldFile called"); |
3266 | reader->setText(true); | 3266 | reader->setText(true); |
3267 | // qDebug("settext called"); | 3267 | // qDebug("settext called"); |
3268 | showEditTools(); | 3268 | showEditTools(); |
3269 | // qDebug("showedit called"); | 3269 | // qDebug("showedit called"); |
3270 | } | 3270 | } |
3271 | */ | 3271 | */ |
3272 | 3272 | ||
3273 | /* | 3273 | /* |
3274 | void info_cb(Fl_Widget* o, void* _data) | 3274 | void info_cb(Fl_Widget* o, void* _data) |
3275 | { | 3275 | { |
3276 | 3276 | ||
3277 | if (infowin == NULL) | 3277 | if (infowin == NULL) |
3278 | { | 3278 | { |
3279 | 3279 | ||
3280 | infowin = new Fl_Window(160,240); | 3280 | infowin = new Fl_Window(160,240); |
3281 | filename = new Fl_Output(45,5,110,14,"Filename"); | 3281 | filename = new Fl_Output(45,5,110,14,"Filename"); |
3282 | filesize = new Fl_Output(45,25,110,14,"Filesize"); | 3282 | filesize = new Fl_Output(45,25,110,14,"Filesize"); |
3283 | textsize = new Fl_Output(45,45,110,14,"Textsize"); | 3283 | textsize = new Fl_Output(45,45,110,14,"Textsize"); |
3284 | comprat = new CBar(45,65,110,14,"Ratio %"); | 3284 | comprat = new CBar(45,65,110,14,"Ratio %"); |
3285 | posn = new Fl_Output(45,85,110,14,"Location"); | 3285 | posn = new Fl_Output(45,85,110,14,"Location"); |
3286 | frcn = new CBar(45,105,110,14,"% Read"); | 3286 | frcn = new CBar(45,105,110,14,"% Read"); |
3287 | about = new Fl_Multiline_Output(5,125,150,90); | 3287 | about = new Fl_Multiline_Output(5,125,150,90); |
3288 | about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files"); | 3288 | about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files"); |
3289 | Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay"); | 3289 | Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay"); |
3290 | infowin->set_modal(); | 3290 | infowin->set_modal(); |
3291 | } | 3291 | } |
3292 | if (((reader_ui *)_data)->g_filename[0] != '\0') | 3292 | if (((reader_ui *)_data)->g_filename[0] != '\0') |
3293 | { | 3293 | { |
3294 | unsigned long fs,ts; | 3294 | unsigned long fs,ts; |
3295 | tchar sz[20]; | 3295 | tchar sz[20]; |
3296 | ((reader_ui *)_data)->input->sizes(fs,ts); | 3296 | ((reader_ui *)_data)->input->sizes(fs,ts); |
3297 | unsigned long pl = ((reader_ui *)_data)->input->locate(); | 3297 | unsigned long pl = ((reader_ui *)_data)->input->locate(); |
3298 | 3298 | ||
3299 | filename->value(((reader_ui *)_data)->g_filename); | 3299 | filename->value(((reader_ui *)_data)->g_filename); |
3300 | 3300 | ||
3301 | sprintf(sz,"%u",fs); | 3301 | sprintf(sz,"%u",fs); |
3302 | filesize->value(sz); | 3302 | filesize->value(sz); |
3303 | 3303 | ||
3304 | sprintf(sz,"%u",ts); | 3304 | sprintf(sz,"%u",ts); |
3305 | textsize->value(sz); | 3305 | textsize->value(sz); |
3306 | 3306 | ||
3307 | comprat->value(100-(100*fs + (ts >> 1))/ts); | 3307 | comprat->value(100-(100*fs + (ts >> 1))/ts); |
3308 | 3308 | ||
3309 | sprintf(sz,"%u",pl); | 3309 | sprintf(sz,"%u",pl); |
3310 | posn->value(sz); | 3310 | posn->value(sz); |
3311 | 3311 | ||
3312 | frcn->value((100*pl + (ts >> 1))/ts); | 3312 | frcn->value((100*pl + (ts >> 1))/ts); |
3313 | } | 3313 | } |
3314 | infowin->show(); | 3314 | infowin->show(); |
3315 | } | 3315 | } |
3316 | */ | 3316 | */ |
3317 | 3317 | ||
3318 | void QTReaderApp::savebkmks() | 3318 | void QTReaderApp::savebkmks() |
3319 | { | 3319 | { |
3320 | if (pBkmklist != NULL) | 3320 | if (pBkmklist != NULL) |
3321 | { | 3321 | { |
3322 | #ifndef USEQPE | 3322 | #ifndef USEQPE |
3323 | QDir d = QDir::home(); // "/" | 3323 | QDir d = QDir::home(); // "/" |
3324 | d.cd(APPDIR); | 3324 | d.cd(APPDIR); |
3325 | QFileInfo fi(d, reader->m_string); | 3325 | QFileInfo fi(d, reader->m_string); |
3326 | BkmkFile bf((const char *)fi.absFilePath(), true); | 3326 | BkmkFile bf((const char *)fi.absFilePath(), true); |
3327 | #else /* USEQPE */ | 3327 | #else /* USEQPE */ |
3328 | BkmkFile bf((const char *)Global::applicationFileName(APPDIR,reader->m_string), true); | 3328 | BkmkFile bf((const char *)Global::applicationFileName(APPDIR,reader->m_string), true); |
3329 | #endif /* USEQPE */ | 3329 | #endif /* USEQPE */ |
3330 | bf.write(*pBkmklist); | 3330 | bf.write(*pBkmklist); |
3331 | } | 3331 | } |
3332 | m_fBkmksChanged = false; | 3332 | m_fBkmksChanged = false; |
3333 | } | 3333 | } |
3334 | 3334 | ||
3335 | void QTReaderApp::readfilelist() | 3335 | void QTReaderApp::readfilelist() |
3336 | { | 3336 | { |
3337 | #ifndef USEQPE | 3337 | #ifndef USEQPE |
3338 | QDir d = QDir::home(); // "/" | 3338 | QDir d = QDir::home(); // "/" |
3339 | d.cd(APPDIR); | 3339 | d.cd(APPDIR); |
3340 | QFileInfo fi(d, ".openfiles"); | 3340 | QFileInfo fi(d, ".openfiles"); |
3341 | BkmkFile bf((const char *)fi.absFilePath()); | 3341 | BkmkFile bf((const char *)fi.absFilePath()); |
3342 | #else /* USEQPE */ | 3342 | #else /* USEQPE */ |
3343 | BkmkFile bf((const char *)Global::applicationFileName(APPDIR,".openfiles")); | 3343 | BkmkFile bf((const char *)Global::applicationFileName(APPDIR,".openfiles")); |
3344 | #endif /* USEQPE */ | 3344 | #endif /* USEQPE */ |
3345 | // qDebug("Reading open files"); | 3345 | // qDebug("Reading open files"); |
3346 | pOpenlist = bf.readall(); | 3346 | pOpenlist = bf.readall(); |
3347 | // if (pOpenlist != NULL) qDebug("...with success"); | 3347 | // if (pOpenlist != NULL) qDebug("...with success"); |
3348 | // else qDebug("...without success!"); | 3348 | // else qDebug("...without success!"); |
3349 | } | 3349 | } |
3350 | 3350 | ||
3351 | void QTReaderApp::savefilelist() | 3351 | void QTReaderApp::savefilelist() |
3352 | { | 3352 | { |
3353 | if (pOpenlist != NULL) | 3353 | if (pOpenlist != NULL) |
3354 | { | 3354 | { |
3355 | #ifndef USEQPE | 3355 | #ifndef USEQPE |
3356 | QDir d = QDir::home(); // "/" | 3356 | QDir d = QDir::home(); // "/" |
3357 | d.cd(APPDIR); | 3357 | d.cd(APPDIR); |
3358 | QFileInfo fi(d, ".openfiles"); | 3358 | QFileInfo fi(d, ".openfiles"); |
3359 | BkmkFile bf((const char *)fi.absFilePath(), true); | 3359 | BkmkFile bf((const char *)fi.absFilePath(), true); |
3360 | #else /* USEQPE */ | 3360 | #else /* USEQPE */ |
3361 | BkmkFile bf((const char *)Global::applicationFileName(APPDIR,".openfiles"), true); | 3361 | BkmkFile bf((const char *)Global::applicationFileName(APPDIR,".openfiles"), true); |
3362 | #endif /* USEQPE */ | 3362 | #endif /* USEQPE */ |
3363 | //qDebug("Writing open files"); | 3363 | //qDebug("Writing open files"); |
3364 | bf.write(*pOpenlist); | 3364 | bf.write(*pOpenlist); |
3365 | } | 3365 | } |
3366 | } | 3366 | } |
3367 | 3367 | ||
3368 | void QTReaderApp::readbkmks() | 3368 | void QTReaderApp::readbkmks() |
3369 | { | 3369 | { |
3370 | if (pBkmklist != NULL) | 3370 | if (pBkmklist != NULL) |
3371 | { | 3371 | { |
3372 | delete pBkmklist; | 3372 | delete pBkmklist; |
3373 | } | 3373 | } |
3374 | struct stat fnstat; | 3374 | struct stat fnstat; |
3375 | struct stat bkstat; | 3375 | struct stat bkstat; |
3376 | #ifndef USEQPE | 3376 | #ifndef USEQPE |
3377 | QDir d = QDir::home(); // "/" | 3377 | QDir d = QDir::home(); // "/" |
3378 | d.cd(APPDIR); | 3378 | d.cd(APPDIR); |
3379 | QFileInfo fi(d, reader->m_string); | 3379 | QFileInfo fi(d, reader->m_string); |
3380 | #endif /* ! USEQPE */ | 3380 | #endif /* ! USEQPE */ |
3381 | if ( | 3381 | if ( |
3382 | stat((const char *)reader->m_lastfile, &fnstat) == 0 | 3382 | stat((const char *)reader->m_lastfile, &fnstat) == 0 |
3383 | && | 3383 | && |
3384 | #ifndef USEQPE | 3384 | #ifndef USEQPE |
3385 | stat((const char *)fi.absFilePath(), &bkstat) == 0 | 3385 | stat((const char *)fi.absFilePath(), &bkstat) == 0 |
3386 | #else /* USEQPE */ | 3386 | #else /* USEQPE */ |
3387 | stat((const char *)Global::applicationFileName(APPDIR,reader->m_string), &bkstat) == 0 | 3387 | stat((const char *)Global::applicationFileName(APPDIR,reader->m_string), &bkstat) == 0 |
3388 | #endif /* USEQPE */ | 3388 | #endif /* USEQPE */ |
3389 | ) | 3389 | ) |
3390 | { | 3390 | { |
3391 | if (bkstat.st_mtime < fnstat.st_mtime) | 3391 | if (bkstat.st_mtime < fnstat.st_mtime) |
3392 | { | 3392 | { |
3393 | #ifndef USEQPE | 3393 | #ifndef USEQPE |
3394 | unlink((const char *)fi.absFilePath()); | 3394 | unlink((const char *)fi.absFilePath()); |
3395 | #else /* USEQPE */ | 3395 | #else /* USEQPE */ |
3396 | unlink((const char *)Global::applicationFileName(APPDIR,reader->m_string)); | 3396 | unlink((const char *)Global::applicationFileName(APPDIR,reader->m_string)); |
3397 | #endif /* USEQPE */ | 3397 | #endif /* USEQPE */ |
3398 | } | 3398 | } |
3399 | } | 3399 | } |
3400 | 3400 | ||
3401 | #ifndef USEQPE | 3401 | #ifndef USEQPE |
3402 | BkmkFile bf((const char *)fi.absFilePath()); | 3402 | BkmkFile bf((const char *)fi.absFilePath()); |
3403 | #else /* USEQPE */ | 3403 | #else /* USEQPE */ |
3404 | BkmkFile bf((const char *)Global::applicationFileName(APPDIR,reader->m_string)); | 3404 | BkmkFile bf((const char *)Global::applicationFileName(APPDIR,reader->m_string)); |
3405 | #endif /* USEQPE */ | 3405 | #endif /* USEQPE */ |
3406 | 3406 | ||
3407 | pBkmklist = bf.readall(); | 3407 | pBkmklist = bf.readall(); |
3408 | m_fBkmksChanged = bf.upgraded(); | 3408 | m_fBkmksChanged = bf.upgraded(); |
3409 | if (pBkmklist == NULL) | 3409 | if (pBkmklist == NULL) |
3410 | { | 3410 | { |
3411 | pBkmklist = reader->getbkmklist(); | 3411 | pBkmklist = reader->getbkmklist(); |
3412 | } | 3412 | } |
3413 | if (pBkmklist != NULL) | 3413 | if (pBkmklist != NULL) |
3414 | pBkmklist->sort(); | 3414 | pBkmklist->sort(); |
3415 | } | 3415 | } |
3416 | 3416 | ||
3417 | void QTReaderApp::addbkmk() | 3417 | void QTReaderApp::addbkmk() |
3418 | { | 3418 | { |
3419 | m_nRegAction = cAddBkmk; | 3419 | m_nRegAction = cAddBkmk; |
3420 | regEdit->setText(reader->firstword()); | 3420 | regEdit->setText(reader->firstword()); |
3421 | do_regedit(); | 3421 | do_regedit(); |
3422 | } | 3422 | } |
3423 | 3423 | ||
3424 | void QTReaderApp::do_addbkmk(const QString& text) | 3424 | void QTReaderApp::do_addbkmk(const QString& text) |
3425 | { | 3425 | { |
3426 | if (text.isEmpty()) | 3426 | if (text.isEmpty()) |
3427 | { | 3427 | { |
3428 | QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nSelect add again", 1); | 3428 | QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nSelect add again", 1); |
3429 | } | 3429 | } |
3430 | else | 3430 | else |
3431 | { | 3431 | { |
3432 | if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>; | 3432 | if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>; |
3433 | #ifdef _UNICODE | 3433 | #ifdef _UNICODE |
3434 | CBuffer buff; | 3434 | CBuffer buff; |
3435 | int i = 0; | 3435 | int i = 0; |
3436 | for (i = 0; i < text.length(); i++) | 3436 | for (i = 0; i < text.length(); i++) |
3437 | { | 3437 | { |
3438 | buff[i] = text[i].unicode(); | 3438 | buff[i] = text[i].unicode(); |
3439 | } | 3439 | } |
3440 | buff[i] = 0; | 3440 | buff[i] = 0; |
3441 | pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate())); | 3441 | pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate())); |
3442 | #else | 3442 | #else |
3443 | pBkmklist->push_front(Bkmk((const tchar*)text, reader->pagelocate())); | 3443 | pBkmklist->push_front(Bkmk((const tchar*)text, reader->pagelocate())); |
3444 | #endif | 3444 | #endif |
3445 | m_fBkmksChanged = true; | 3445 | m_fBkmksChanged = true; |
3446 | pBkmklist->sort(); | 3446 | pBkmklist->sort(); |
3447 | } | 3447 | } |
3448 | } | 3448 | } |
3449 | 3449 | ||
3450 | void QTReaderApp::OnRedraw() | 3450 | void QTReaderApp::OnRedraw() |
3451 | { | 3451 | { |
3452 | if ((pBkmklist != NULL) && (m_bkmkAvail != NULL)) | 3452 | if ((pBkmklist != NULL) && (m_bkmkAvail != NULL)) |
3453 | { | 3453 | { |
3454 | bool found = findNextBookmark(reader->pagelocate()); | 3454 | bool found = findNextBookmark(reader->pagelocate()); |
3455 | m_bkmkAvail->setEnabled(found); | 3455 | m_bkmkAvail->setEnabled(found); |
3456 | } | 3456 | } |
3457 | } | 3457 | } |
3458 | 3458 | ||
3459 | void QTReaderApp::showAnnotation() | 3459 | void QTReaderApp::showAnnotation() |
3460 | { | 3460 | { |
3461 | m_annoWin->setName(toQString(m_anno->name())); | 3461 | m_annoWin->setName(toQString(m_anno->name())); |
3462 | m_annoWin->setAnno(toQString(m_anno->anno())); | 3462 | m_annoWin->setAnno(toQString(m_anno->anno())); |
3463 | m_annoIsEditing = false; | 3463 | m_annoIsEditing = false; |
3464 | #ifdef USEQPE | 3464 | #ifdef USEQPE |
3465 | Global::showInputMethod(); | 3465 | Global::showInputMethod(); |
3466 | #endif | 3466 | #endif |
3467 | editorStack->raiseWidget( m_annoWin ); | 3467 | editorStack->raiseWidget( m_annoWin ); |
3468 | m_annoWin->setFocus(); | 3468 | m_annoWin->setFocus(); |
3469 | } | 3469 | } |
3470 | 3470 | ||
3471 | void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, const QString& line) | 3471 | void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, const QString& line) |
3472 | { | 3472 | { |
3473 | //// qDebug("OnWordSelected(%u):%s", posn, (const char*)wrd); | 3473 | //// qDebug("OnWordSelected(%u):%s", posn, (const char*)wrd); |
3474 | 3474 | ||
3475 | if (m_doClipboard) | 3475 | if (m_doClipboard) |
3476 | { | 3476 | { |
3477 | QClipboard* cb = QApplication::clipboard(); | 3477 | QClipboard* cb = QApplication::clipboard(); |
3478 | cb->setText(wrd); | 3478 | cb->setText(wrd); |
3479 | #ifdef USEQPE | 3479 | #ifdef USEQPE |
3480 | if (wrd.length() > 10) | 3480 | if (wrd.length() > 10) |
3481 | { | 3481 | { |
3482 | Global::statusMessage(wrd.left(8) + ".."); | 3482 | Global::statusMessage(wrd.left(8) + ".."); |
3483 | } | 3483 | } |
3484 | else | 3484 | else |
3485 | { | 3485 | { |
3486 | Global::statusMessage(wrd); | 3486 | Global::statusMessage(wrd); |
3487 | } | 3487 | } |
3488 | #endif | 3488 | #endif |
3489 | } | 3489 | } |
3490 | if (m_doAnnotation) | 3490 | if (m_doAnnotation) |
3491 | { | 3491 | { |
3492 | //addAnno(wrd, "Need to be able to edit this", posn); | 3492 | //addAnno(wrd, "Need to be able to edit this", posn); |
3493 | m_annoWin->setName(line); | 3493 | m_annoWin->setName(line); |
3494 | m_annoWin->setAnno(""); | 3494 | m_annoWin->setAnno(""); |
3495 | m_annoWin->setPosn(posn); | 3495 | m_annoWin->setPosn(posn); |
3496 | m_annoIsEditing = true; | 3496 | m_annoIsEditing = true; |
3497 | #ifdef USEQPE | 3497 | #ifdef USEQPE |
3498 | Global::showInputMethod(); | 3498 | Global::showInputMethod(); |
3499 | #endif | 3499 | #endif |
3500 | editorStack->raiseWidget( m_annoWin ); | 3500 | editorStack->raiseWidget( m_annoWin ); |
3501 | } | 3501 | } |
3502 | #ifdef USEQPE | 3502 | #ifdef USEQPE |
3503 | if (m_doDictionary) | 3503 | if (m_doDictionary) |
3504 | { | 3504 | { |
3505 | if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty()) | 3505 | if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty()) |
3506 | { | 3506 | { |
3507 | QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8()); | 3507 | QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8()); |
3508 | e << wrd; | 3508 | e << wrd; |
3509 | } | 3509 | } |
3510 | } | 3510 | } |
3511 | #endif | 3511 | #endif |
3512 | } | 3512 | } |
3513 | 3513 | ||
3514 | void QTReaderApp::doAction(ActionTypes a, QKeyEvent* e) | 3514 | void QTReaderApp::doAction(ActionTypes a, QKeyEvent* e) |
3515 | { | 3515 | { |
3516 | if (a == 0) | 3516 | if (a == 0) |
3517 | { | 3517 | { |
3518 | e->ignore(); | 3518 | e->ignore(); |
3519 | } | 3519 | } |
3520 | else | 3520 | else |
3521 | { | 3521 | { |
3522 | e->accept(); | 3522 | e->accept(); |
3523 | //qDebug("Accepted"); | 3523 | //qDebug("Accepted"); |
3524 | switch (a) | 3524 | switch (a) |
3525 | { | 3525 | { |
3526 | case cesOpenFile: | 3526 | case cesOpenFile: |
3527 | { | 3527 | { |
3528 | fileOpen(); | 3528 | fileOpen(); |
3529 | } | 3529 | } |
3530 | break; | 3530 | break; |
3531 | case cesAutoScroll: | 3531 | case cesAutoScroll: |
3532 | { | 3532 | { |
3533 | reader->setautoscroll(!reader->m_autoScroll); | 3533 | reader->setautoscroll(!reader->m_autoScroll); |
3534 | setScrollState(reader->m_autoScroll); | 3534 | setScrollState(reader->m_autoScroll); |
3535 | } | 3535 | } |
3536 | break; | 3536 | break; |
3537 | case cesActionMark: | 3537 | case cesActionMark: |
3538 | { | 3538 | { |
3539 | addbkmk(); | 3539 | addbkmk(); |
3540 | } | 3540 | } |
3541 | break; | 3541 | break; |
3542 | case cesFullScreen: | 3542 | case cesFullScreen: |
3543 | { | 3543 | { |
3544 | m_actFullscreen->setOn(!m_fullscreen); | 3544 | m_actFullscreen->setOn(!m_fullscreen); |
3545 | } | 3545 | } |
3546 | break; | 3546 | break; |
3547 | case cesActionAnno: | 3547 | case cesActionAnno: |
3548 | { | 3548 | { |
3549 | addanno(); | 3549 | addanno(); |
3550 | } | 3550 | } |
3551 | break; | 3551 | break; |
3552 | case cesZoomIn: | 3552 | case cesZoomIn: |
3553 | zoomin(); | 3553 | zoomin(); |
3554 | break; | 3554 | break; |
3555 | case cesZoomOut: | 3555 | case cesZoomOut: |
3556 | zoomout(); | 3556 | zoomout(); |
3557 | break; | 3557 | break; |
3558 | case cesBack: | 3558 | case cesBack: |
3559 | reader->goBack(); | 3559 | reader->goBack(); |
3560 | break; | 3560 | break; |
3561 | case cesForward: | 3561 | case cesForward: |
3562 | reader->goForward(); | 3562 | reader->goForward(); |
3563 | break; | 3563 | break; |
3564 | case cesHome: | 3564 | case cesHome: |
3565 | reader->goHome(); | 3565 | reader->goHome(); |
3566 | break; | 3566 | break; |
3567 | case cesPageUp: | 3567 | case cesPageUp: |
3568 | reader->dopageup(); | 3568 | reader->dopageup(); |
3569 | break; | 3569 | break; |
3570 | case cesPageDown: | 3570 | case cesPageDown: |
3571 | reader->dopagedn(); | 3571 | reader->dopagedn(); |
3572 | break; | 3572 | break; |
3573 | case cesLineUp: | 3573 | case cesLineUp: |
3574 | reader->lineUp(); | 3574 | reader->lineUp(); |
3575 | break; | 3575 | break; |
3576 | case cesLineDown: | 3576 | case cesLineDown: |
3577 | reader->lineDown(); | 3577 | reader->lineDown(); |
3578 | break; | 3578 | break; |
3579 | case cesStartDoc: | 3579 | case cesStartDoc: |
3580 | gotoStart(); | 3580 | gotoStart(); |
3581 | break; | 3581 | break; |
3582 | case cesEndDoc: | 3582 | case cesEndDoc: |
3583 | gotoEnd(); | 3583 | gotoEnd(); |
3584 | break; | 3584 | break; |
3585 | default: | 3585 | default: |
3586 | qDebug("Unknown ActionType:%u", a); | 3586 | qDebug("Unknown ActionType:%u", a); |
3587 | break; | 3587 | break; |
3588 | } | 3588 | } |
3589 | } | 3589 | } |
3590 | } | 3590 | } |
3591 | 3591 | ||
3592 | void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); } | 3592 | void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); } |
3593 | void QTReaderApp::restoreFocus() { reader->setFocus(); } | 3593 | void QTReaderApp::restoreFocus() { reader->setFocus(); } |
3594 | 3594 | ||
3595 | void QTReaderApp::SaveConfig() | 3595 | void QTReaderApp::SaveConfig() |
3596 | { | 3596 | { |
3597 | m_nRegAction = cSetConfigName; | 3597 | m_nRegAction = cSetConfigName; |
3598 | regEdit->setText(reader->m_string); | 3598 | regEdit->setText(reader->m_string); |
3599 | do_regedit(); | 3599 | do_regedit(); |
3600 | } | 3600 | } |
3601 | 3601 | ||
3602 | void QTReaderApp::do_saveconfig(const QString& _txt, bool full) | 3602 | void QTReaderApp::do_saveconfig(const QString& _txt, bool full) |
3603 | { | 3603 | { |
3604 | // qDebug("do_saveconfig:%s", (const char*)_txt); | 3604 | // qDebug("do_saveconfig:%s", (const char*)_txt); |
3605 | #ifdef USEQPE | 3605 | #ifdef USEQPE |
3606 | QString configname; | 3606 | QString configname; |
3607 | Config::Domain dom; | 3607 | Config::Domain dom; |
3608 | 3608 | ||
3609 | if (full) | 3609 | if (full) |
3610 | { | 3610 | { |
3611 | configname = _txt; | 3611 | configname = _txt; |
3612 | dom = Config::User; | 3612 | dom = Config::User; |
3613 | } | 3613 | } |
3614 | else | 3614 | else |
3615 | { | 3615 | { |
3616 | configname = Global::applicationFileName(APPDIR "/configs", _txt); | 3616 | configname = Global::applicationFileName(APPDIR "/configs", _txt); |
3617 | dom = Config::File; | 3617 | dom = Config::File; |
3618 | } | 3618 | } |
3619 | 3619 | ||
3620 | Config config(configname, dom); | 3620 | Config config(configname, dom); |
3621 | config.setGroup( "View" ); | 3621 | config.setGroup( "View" ); |
3622 | 3622 | ||
3623 | #else | 3623 | #else |
3624 | QFileInfo fi; | 3624 | QFileInfo fi; |
3625 | if (full) | 3625 | if (full) |
3626 | { | 3626 | { |
3627 | // qDebug("full:%s", (const char*)_txt); | 3627 | // qDebug("full:%s", (const char*)_txt); |
3628 | QDir d = QDir::home(); // "/" | 3628 | QDir d = QDir::home(); // "/" |
3629 | if ( !d.cd(_txt) ) | 3629 | if ( !d.cd(_txt) ) |
3630 | { // "/tmp" | 3630 | { // "/tmp" |
3631 | qWarning( "Cannot find the \"~/%s\" directory", (const char*)_txt ); | 3631 | qWarning( "Cannot find the \"~/%s\" directory", (const char*)_txt ); |
3632 | d = QDir::home(); | 3632 | d = QDir::home(); |
3633 | d.mkdir(_txt); | 3633 | d.mkdir(_txt); |
3634 | d.cd(_txt); | 3634 | d.cd(_txt); |
3635 | } | 3635 | } |
3636 | fi.setFile(d, INIFILE); | 3636 | fi.setFile(d, INIFILE); |
3637 | } | 3637 | } |
3638 | else | 3638 | else |
3639 | { | 3639 | { |
3640 | QDir d = QDir::home(); // "/" | 3640 | QDir d = QDir::home(); // "/" |
3641 | if ( !d.cd(APPDIR) ) | 3641 | if ( !d.cd(APPDIR) ) |
3642 | { // "/tmp" | 3642 | { // "/tmp" |
3643 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); | 3643 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); |
3644 | d = QDir::home(); | 3644 | d = QDir::home(); |
3645 | d.mkdir(APPDIR); | 3645 | d.mkdir(APPDIR); |
3646 | d.cd(APPDIR); | 3646 | d.cd(APPDIR); |
3647 | } | 3647 | } |
3648 | if ( !d.cd("configs") ) | 3648 | if ( !d.cd("configs") ) |
3649 | { // "/tmp" | 3649 | { // "/tmp" |
3650 | qWarning( "Cannot find the \"~/" APPDIR "/configs\" directory" ); | 3650 | qWarning( "Cannot find the \"~/" APPDIR "/configs\" directory" ); |
3651 | d = QDir::home(); | 3651 | d = QDir::home(); |
3652 | d.cd(APPDIR); | 3652 | d.cd(APPDIR); |
3653 | d.mkdir("configs"); | 3653 | d.mkdir("configs"); |
3654 | d.cd("configs"); | 3654 | d.cd("configs"); |
3655 | } | 3655 | } |
3656 | fi.setFile(d, _txt); | 3656 | fi.setFile(d, _txt); |
3657 | } | 3657 | } |
3658 | //qDebug("Path:%s", (const char*)fi.absFilePath()); | 3658 | //qDebug("Path:%s", (const char*)fi.absFilePath()); |
3659 | Config config(fi.absFilePath()); | 3659 | Config config(fi.absFilePath()); |
3660 | #endif | 3660 | #endif |
3661 | 3661 | ||
3662 | 3662 | ||
3663 | config.writeEntry( "StripCr", reader->bstripcr ); | 3663 | config.writeEntry( "StripCr", reader->bstripcr ); |
3664 | config.writeEntry( "AutoFmt", reader->bautofmt ); | 3664 | config.writeEntry( "AutoFmt", reader->bautofmt ); |
3665 | config.writeEntry( "TextFmt", reader->btextfmt ); | 3665 | config.writeEntry( "TextFmt", reader->btextfmt ); |
3666 | config.writeEntry( "StripHtml", reader->bstriphtml ); | 3666 | config.writeEntry( "StripHtml", reader->bstriphtml ); |
3667 | config.writeEntry( "Dehyphen", reader->bdehyphen ); | 3667 | config.writeEntry( "Dehyphen", reader->bdehyphen ); |
3668 | config.writeEntry( "Depluck", reader->bdepluck ); | 3668 | config.writeEntry( "Depluck", reader->bdepluck ); |
3669 | config.writeEntry( "Dejpluck", reader->bdejpluck ); | 3669 | config.writeEntry( "Dejpluck", reader->bdejpluck ); |
3670 | config.writeEntry( "OneSpace", reader->bonespace ); | 3670 | config.writeEntry( "OneSpace", reader->bonespace ); |
3671 | config.writeEntry( "Unindent", reader->bunindent ); | 3671 | config.writeEntry( "Unindent", reader->bunindent ); |
3672 | config.writeEntry( "Repara", reader->brepara ); | 3672 | config.writeEntry( "Repara", reader->brepara ); |
3673 | config.writeEntry( "DoubleSpace", reader->bdblspce ); | 3673 | config.writeEntry( "DoubleSpace", reader->bdblspce ); |
3674 | config.writeEntry( "Indent", reader->bindenter ); | 3674 | config.writeEntry( "Indent", reader->bindenter ); |
3675 | config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) ); | 3675 | config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) ); |
3676 | config.writeEntry( "ScrollDelay", reader->m_delay); | 3676 | config.writeEntry( "ScrollDelay", reader->m_delay); |
3677 | if (full) | 3677 | if (full) |
3678 | { | 3678 | { |
3679 | config.writeEntry("Debounce", m_debounce); | 3679 | config.writeEntry("Debounce", m_debounce); |
3680 | config.writeEntry("FloatDialogs", m_bFloatingDialog); | 3680 | config.writeEntry("FloatDialogs", m_bFloatingDialog); |
3681 | reader->m_lastposn = reader->pagelocate(); | 3681 | reader->m_lastposn = reader->pagelocate(); |
3682 | config.writeEntry( "LastFile", reader->m_lastfile ); | 3682 | config.writeEntry( "LastFile", reader->m_lastfile ); |
3683 | config.writeEntry( "LastPosn", (int)(reader->pagelocate()) ); | 3683 | config.writeEntry( "LastPosn", (int)(reader->pagelocate()) ); |
3684 | } | 3684 | } |
3685 | config.writeEntry( "PageMode", reader->m_bpagemode ); | 3685 | config.writeEntry( "PageMode", reader->m_bpagemode ); |
3686 | config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced ); | 3686 | config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced ); |
3687 | config.writeEntry( "SwapMouse", reader->m_swapmouse); | 3687 | config.writeEntry( "SwapMouse", reader->m_swapmouse); |
3688 | config.writeEntry( "Fontname", reader->m_fontname ); | 3688 | config.writeEntry( "Fontname", reader->m_fontname ); |
3689 | config.writeEntry( "Encoding", reader->m_encd ); | 3689 | config.writeEntry( "Encoding", reader->m_encd ); |
3690 | config.writeEntry( "CharSpacing", reader->m_charpc ); | 3690 | config.writeEntry( "CharSpacing", reader->m_charpc ); |
3691 | config.writeEntry( "Overlap", (int)(reader->m_overlap) ); | 3691 | config.writeEntry( "Overlap", (int)(reader->m_overlap) ); |
3692 | config.writeEntry( "Margin", (int)reader->m_border ); | 3692 | config.writeEntry( "Margin", (int)reader->m_border ); |
3693 | config.writeEntry( "TargetApp", m_targetapp ); | 3693 | config.writeEntry( "TargetApp", m_targetapp ); |
3694 | config.writeEntry( "TargetMsg", m_targetmsg ); | 3694 | config.writeEntry( "TargetMsg", m_targetmsg ); |
3695 | #ifdef _SCROLLPIPE | 3695 | #ifdef _SCROLLPIPE |
3696 | config.writeEntry( "PipeTarget", reader->m_pipetarget ); | 3696 | config.writeEntry( "PipeTarget", reader->m_pipetarget ); |
3697 | config.writeEntry( "PauseAfterPara", reader->m_pauseAfterEachPara ); | 3697 | config.writeEntry( "PauseAfterPara", reader->m_pauseAfterEachPara ); |
3698 | #endif | 3698 | #endif |
3699 | config.writeEntry( "TwoTouch", m_twoTouch ); | 3699 | config.writeEntry( "TwoTouch", m_twoTouch ); |
3700 | config.writeEntry( "Annotation", m_doAnnotation); | 3700 | config.writeEntry( "Annotation", m_doAnnotation); |
3701 | config.writeEntry( "Dictionary", m_doDictionary); | 3701 | config.writeEntry( "Dictionary", m_doDictionary); |
3702 | config.writeEntry( "Clipboard", m_doClipboard); | 3702 | config.writeEntry( "Clipboard", m_doClipboard); |
3703 | config.writeEntry( "SpaceTarget", m_spaceTarget); | 3703 | config.writeEntry( "SpaceTarget", m_spaceTarget); |
3704 | config.writeEntry( "EscapeTarget", m_escapeTarget); | 3704 | config.writeEntry( "EscapeTarget", m_escapeTarget); |
3705 | config.writeEntry( "ReturnTarget", m_returnTarget); | 3705 | config.writeEntry( "ReturnTarget", m_returnTarget); |
3706 | config.writeEntry( "LeftTarget", m_leftTarget); | 3706 | config.writeEntry( "LeftTarget", m_leftTarget); |
3707 | config.writeEntry( "RightTarget", m_rightTarget); | 3707 | config.writeEntry( "RightTarget", m_rightTarget); |
3708 | config.writeEntry( "UpTarget", m_upTarget); | 3708 | config.writeEntry( "UpTarget", m_upTarget); |
3709 | config.writeEntry( "DownTarget", m_downTarget); | 3709 | config.writeEntry( "DownTarget", m_downTarget); |
3710 | config.writeEntry("LeftScroll", m_leftScroll); | 3710 | config.writeEntry("LeftScroll", m_leftScroll); |
3711 | config.writeEntry("RightScroll", m_rightScroll); | 3711 | config.writeEntry("RightScroll", m_rightScroll); |
3712 | config.writeEntry("UpScroll", m_upScroll); | 3712 | config.writeEntry("UpScroll", m_upScroll); |
3713 | config.writeEntry("DownScroll", m_downScroll); | 3713 | config.writeEntry("DownScroll", m_downScroll); |
3714 | #ifdef REPALM | 3714 | #ifdef REPALM |
3715 | config.writeEntry( "Repalm", reader->brepalm ); | 3715 | config.writeEntry( "Repalm", reader->brepalm ); |
3716 | #endif | 3716 | #endif |
3717 | config.writeEntry( "Remap", reader->bremap ); | 3717 | config.writeEntry( "Remap", reader->bremap ); |
3718 | config.writeEntry( "Peanut", reader->bpeanut ); | 3718 | config.writeEntry( "Peanut", reader->bpeanut ); |
3719 | config.writeEntry( "MakeBold", reader->bmakebold ); | 3719 | config.writeEntry( "MakeBold", reader->bmakebold ); |
3720 | config.writeEntry( "Continuous", reader->m_continuousDocument ); | 3720 | config.writeEntry( "Continuous", reader->m_continuousDocument ); |
3721 | config.writeEntry( "FullJust", reader->bfulljust ); | 3721 | config.writeEntry( "FullJust", reader->bfulljust ); |
3722 | config.writeEntry( "ExtraSpace", reader->getextraspace() ); | 3722 | config.writeEntry( "ExtraSpace", reader->getextraspace() ); |
3723 | config.writeEntry( "ExtraLead", reader->getlead() ); | 3723 | config.writeEntry( "ExtraLead", reader->getlead() ); |
3724 | config.writeEntry( "Basesize", (int)reader->getBaseSize()); | 3724 | config.writeEntry( "Basesize", (int)reader->getBaseSize()); |
3725 | config.writeEntry( "RequestorFontChange", m_propogatefontchange); | 3725 | config.writeEntry( "RequestorFontChange", m_propogatefontchange); |
3726 | if (full) | 3726 | if (full) |
3727 | { | 3727 | { |
3728 | config.setGroup( "Toolbar" ); | 3728 | config.setGroup( "Toolbar" ); |
3729 | config.writeEntry("Movable", m_tbmovesave); | 3729 | config.writeEntry("Movable", m_tbmovesave); |
3730 | config.writeEntry("Policy", m_tbpolsave); | 3730 | config.writeEntry("Policy", m_tbpolsave); |
3731 | config.writeEntry("Position", m_tbposition); | 3731 | config.writeEntry("Position", m_tbposition); |
3732 | #ifndef USEQPE | 3732 | #ifndef USEQPE |
3733 | config.setGroup( "Geometry" ); | 3733 | config.setGroup( "Geometry" ); |
3734 | config.writeEntry( "x", x() ); | 3734 | config.writeEntry( "x", x() ); |
3735 | config.writeEntry( "y", y() ); | 3735 | config.writeEntry( "y", y() ); |
3736 | config.writeEntry( "width", width() ); | 3736 | config.writeEntry( "width", width() ); |
3737 | config.writeEntry( "height", height() ); | 3737 | config.writeEntry( "height", height() ); |
3738 | #endif | 3738 | #endif |
3739 | } | 3739 | } |
3740 | } | 3740 | } |
3741 | 3741 | ||
3742 | /* | 3742 | /* |
3743 | void QTReaderApp::setstate(unsigned char* _sd, unsigned short _sdlen) | 3743 | void QTReaderApp::setstate(unsigned char* _sd, unsigned short _sdlen) |
3744 | { | 3744 | { |
3745 | unsigned short sdlen; | 3745 | unsigned short sdlen; |
3746 | memcpy(&sdlen, _sd, sizeof(sdlen)); | 3746 | memcpy(&sdlen, _sd, sizeof(sdlen)); |
3747 | sdlen -= sizeof(sdlen); | 3747 | sdlen -= sizeof(sdlen); |
3748 | _sd += sizeof(sdlen); | 3748 | _sd += sizeof(sdlen); |
3749 | statedata* sd; | 3749 | statedata* sd; |
3750 | char* data; | 3750 | char* data; |
3751 | if (sdlen < sizeof(statedata)+1) | 3751 | if (sdlen < sizeof(statedata)+1) |
3752 | { | 3752 | { |
3753 | sdlen = sizeof(statedata)+1; | 3753 | sdlen = sizeof(statedata)+1; |
3754 | } | 3754 | } |
3755 | data = new char[sdlen]; | 3755 | data = new char[sdlen]; |
3756 | sd = (statedata*)data; | 3756 | sd = (statedata*)data; |
3757 | memcpy(sd, _sd, sdlen); | 3757 | memcpy(sd, _sd, sdlen); |
3758 | data[sdlen] = 0; | 3758 | data[sdlen] = 0; |
3759 | reader->setstate(*sd); | 3759 | reader->setstate(*sd); |
3760 | delete [] data; | 3760 | delete [] data; |
3761 | } | 3761 | } |
3762 | 3762 | ||
3763 | void QTReaderApp::getstate(unsigned char*& data, unsigned short& len) | 3763 | void QTReaderApp::getstate(unsigned char*& data, unsigned short& len) |
3764 | { | 3764 | { |
3765 | unsigned char* olddata = data; | 3765 | unsigned char* olddata = data; |
3766 | unsigned short oldlen = len; | 3766 | unsigned short oldlen = len; |
3767 | len = oldlen+sizeof(unsigned short)+sizeof(statedata)+reader->m_fontname.length(); | 3767 | len = oldlen+sizeof(unsigned short)+sizeof(statedata)+reader->m_fontname.length(); |
3768 | data = new unsigned char[len]; | 3768 | data = new unsigned char[len]; |
3769 | memcpy(data, olddata, oldlen); | 3769 | memcpy(data, olddata, oldlen); |
3770 | delete [] olddata; | 3770 | delete [] olddata; |
3771 | memcpy(data+oldlen, &len, sizeof(len)); | 3771 | memcpy(data+oldlen, &len, sizeof(len)); |
3772 | statedata* sd = (statedata*)(data+oldlen+sizeof(unsigned short)); | 3772 | statedata* sd = (statedata*)(data+oldlen+sizeof(unsigned short)); |
3773 | 3773 | ||
3774 | sd->bstripcr = reader->bstripcr; | 3774 | sd->bstripcr = reader->bstripcr; |
3775 | sd->btextfmt = reader->btextfmt; | 3775 | sd->btextfmt = reader->btextfmt; |
3776 | sd->bautofmt = reader->bautofmt; | 3776 | sd->bautofmt = reader->bautofmt; |
3777 | sd->bstriphtml = reader->bstriphtml; | 3777 | sd->bstriphtml = reader->bstriphtml; |
3778 | sd->bpeanut = reader->bpeanut; | 3778 | sd->bpeanut = reader->bpeanut; |
3779 | sd->bdehyphen = reader->bdehyphen; | 3779 | sd->bdehyphen = reader->bdehyphen; |
3780 | sd->bdepluck = reader->bdepluck; | 3780 | sd->bdepluck = reader->bdepluck; |
3781 | sd->bdejpluck = reader->bdejpluck; | 3781 | sd->bdejpluck = reader->bdejpluck; |
3782 | sd->bonespace = reader->bonespace; | 3782 | sd->bonespace = reader->bonespace; |
3783 | sd->bunindent = reader->bunindent; | 3783 | sd->bunindent = reader->bunindent; |
3784 | sd->brepara = reader->brepara; | 3784 | sd->brepara = reader->brepara; |
3785 | sd->bdblspce = reader->bdblspce; | 3785 | sd->bdblspce = reader->bdblspce; |
3786 | sd->m_bpagemode = reader->m_bpagemode; | 3786 | sd->m_bpagemode = reader->m_bpagemode; |
3787 | sd->m_bMonoSpaced = reader->m_bMonoSpaced; | 3787 | sd->m_bMonoSpaced = reader->m_bMonoSpaced; |
3788 | sd->bremap = reader->bremap; | 3788 | sd->bremap = reader->bremap; |
3789 | sd->bmakebold = reader->bmakebold; | 3789 | sd->bmakebold = reader->bmakebold; |
3790 | sd->Continuous = reader->m_continuousDocument; | 3790 | sd->Continuous = reader->m_continuousDocument; |
3791 | #ifdef REPALM | 3791 | #ifdef REPALM |
3792 | sd->brepalm = reader->brepalm; | 3792 | sd->brepalm = reader->brepalm; |
3793 | #endif | 3793 | #endif |
3794 | sd->bindenter = reader->bindenter; | 3794 | sd->bindenter = reader->bindenter; |
3795 | sd->m_textsize = reader->m_textsize; //reader->m_fontControl.currentsize() | 3795 | sd->m_textsize = reader->m_textsize; //reader->m_fontControl.currentsize() |
3796 | sd->m_encd = reader->m_encd; | 3796 | sd->m_encd = reader->m_encd; |
3797 | sd->m_charpc = reader->m_charpc; | 3797 | sd->m_charpc = reader->m_charpc; |
3798 | strcpy(sd->m_fontname, reader->m_fontname.latin1()); | 3798 | strcpy(sd->m_fontname, reader->m_fontname.latin1()); |
3799 | } | 3799 | } |
3800 | */ | 3800 | */ |
3801 | #ifdef _SCRIPT | 3801 | #ifdef _SCRIPT |
3802 | void QTReaderApp::RunScript() | 3802 | void QTReaderApp::RunScript() |
3803 | { | 3803 | { |
3804 | fileBrowser* fb = new fileBrowser(this,"OpieReader",!m_bFloatingDialog, | 3804 | fileBrowser* fb = new fileBrowser(this,"OpieReader",!m_bFloatingDialog, |
3805 | 0, | 3805 | 0, |
3806 | // WStyle_Customize | WStyle_NoBorderEx, | 3806 | // WStyle_Customize | WStyle_NoBorderEx, |
3807 | "*", Global::applicationFileName(APPDIR "/scripts", "")); | 3807 | "*", Global::applicationFileName(APPDIR "/scripts", "")); |
3808 | 3808 | ||
3809 | QString fn; | 3809 | QString fn; |
3810 | if (fb->exec()) | 3810 | if (fb->exec()) |
3811 | { | 3811 | { |
3812 | fn = fb->fileList[0]; | 3812 | fn = fb->fileList[0]; |
3813 | } | 3813 | } |
3814 | delete fb; | 3814 | delete fb; |
3815 | if ( !fn.isEmpty() && fork() == 0 ) | 3815 | if ( !fn.isEmpty() && fork() == 0 ) |
3816 | { | 3816 | { |
3817 | execlp((const char *)fn,(const char *)fn,NULL); | 3817 | execlp((const char *)fn,(const char *)fn,NULL); |
3818 | } | 3818 | } |
3819 | } | 3819 | } |
3820 | 3820 | ||
3821 | void QTReaderApp::SaveScript(const char* sname) | 3821 | void QTReaderApp::SaveScript(const char* sname) |
3822 | { | 3822 | { |
3823 | FILE* f = fopen(sname,"w"); | 3823 | FILE* f = fopen(sname,"w"); |
3824 | if (f != NULL) | 3824 | if (f != NULL) |
3825 | { | 3825 | { |
3826 | #ifdef OPIE | 3826 | #ifdef OPIE |
3827 | fprintf(f, "#!/bin/sh\nmsg() {\n\tqcop QPE/Application/reader \"$1\" \"$2\" \"$3\"\n}\n"); | 3827 | fprintf(f, "#!/bin/sh\nmsg() {\n\tqcop QPE/Application/reader \"$1\" \"$2\" \"$3\"\n}\n"); |
3828 | #else | 3828 | #else |
3829 | fprintf(f, "#!/bin/bash\nmsg() {\n\tqcop QPE/Application/uqtreader \"$1\" \"$2\" \"$3\"\n}\n"); | 3829 | fprintf(f, "#!/bin/bash\nmsg() {\n\tqcop QPE/Application/uqtreader \"$1\" \"$2\" \"$3\"\n}\n"); |
3830 | #endif | 3830 | #endif |
3831 | fprintf(f, "msg \"Update(int)\" 0\n"); | 3831 | fprintf(f, "msg \"Update(int)\" 0\n"); |
3832 | fprintf(f, "msg \"Layout/StripCR(int)\" %d\n", (reader->bstripcr) ? 1:0); | 3832 | fprintf(f, "msg \"Layout/StripCR(int)\" %d\n", (reader->bstripcr) ? 1:0); |
3833 | if (reader->btextfmt) fprintf(f, "msg \"Markup(QString)\" \"Text\"\n"); | 3833 | if (reader->btextfmt) fprintf(f, "msg \"Markup(QString)\" \"Text\"\n"); |
3834 | else if (reader->bautofmt) fprintf(f, "msg \"Markup(QString)\" \"Auto\"\n"); | 3834 | else if (reader->bautofmt) fprintf(f, "msg \"Markup(QString)\" \"Auto\"\n"); |
3835 | else if (reader->bstriphtml) fprintf(f, "msg \"Markup(QString)\" \"HTML\"\n"); | 3835 | else if (reader->bstriphtml) fprintf(f, "msg \"Markup(QString)\" \"HTML\"\n"); |
3836 | else if (reader->bpeanut) fprintf(f, "msg \"Markup(QString)\" \"Peanut/PML\"\n"); | 3836 | else if (reader->bpeanut) fprintf(f, "msg \"Markup(QString)\" \"Peanut/PML\"\n"); |
3837 | else fprintf(f, "msg \"Markup(QString)\" \"None\"\n"); | 3837 | else fprintf(f, "msg \"Markup(QString)\" \"None\"\n"); |
3838 | fprintf(f, "msg \"Layout/Dehyphen(int)\" %d\n", (reader->bdehyphen) ? 1:0); | 3838 | fprintf(f, "msg \"Layout/Dehyphen(int)\" %d\n", (reader->bdehyphen) ? 1:0); |
3839 | fprintf(f, "msg \"Layout/Depluck(int)\" %d\n", (reader->bdepluck) ? 1:0); | 3839 | fprintf(f, "msg \"Layout/Depluck(int)\" %d\n", (reader->bdepluck) ? 1:0); |
3840 | fprintf(f, "msg \"Layout/Dejpluck(int)\" %d\n", (reader->bdejpluck) ? 1:0); | 3840 | fprintf(f, "msg \"Layout/Dejpluck(int)\" %d\n", (reader->bdejpluck) ? 1:0); |
3841 | fprintf(f, "msg \"Layout/SingleSpace(int)\" %d\n", (reader->bonespace) ? 1:0); | 3841 | fprintf(f, "msg \"Layout/SingleSpace(int)\" %d\n", (reader->bonespace) ? 1:0); |
3842 | fprintf(f, "msg \"Layout/Unindent(int)\" %d\n", (reader->bunindent) ? 1:0); | 3842 | fprintf(f, "msg \"Layout/Unindent(int)\" %d\n", (reader->bunindent) ? 1:0); |
3843 | fprintf(f, "msg \"Layout/Re-paragraph(int)\" %d\n", (reader->brepara) ? 1:0); | 3843 | fprintf(f, "msg \"Layout/Re-paragraph(int)\" %d\n", (reader->brepara) ? 1:0); |
3844 | fprintf(f, "msg \"Layout/DoubleSpace(int)\" %d\n", (reader->bdblspce) ? 1:0); | 3844 | fprintf(f, "msg \"Layout/DoubleSpace(int)\" %d\n", (reader->bdblspce) ? 1:0); |
3845 | fprintf(f, "msg \"Layout/Indent(int)\" %d\n", reader->bindenter); | 3845 | fprintf(f, "msg \"Layout/Indent(int)\" %d\n", reader->bindenter); |
3846 | fprintf(f, "msg \"Format/SetFont(QString,int)\" \"%s\" %d\n", (const char*)reader->m_fontname, reader->m_textsize); | 3846 | fprintf(f, "msg \"Format/SetFont(QString,int)\" \"%s\" %d\n", (const char*)reader->m_fontname, reader->m_textsize); |
3847 | fprintf(f, "msg \"Navigation/Page/LineScroll(int)\" %d\n", (reader->m_bpagemode) ? 1:0); | 3847 | fprintf(f, "msg \"Navigation/Page/LineScroll(int)\" %d\n", (reader->m_bpagemode) ? 1:0); |
3848 | fprintf(f, "msg \"Format/Ideogram/Word(int)\" %d\n", (reader->m_bMonoSpaced) ? 1:0); | 3848 | fprintf(f, "msg \"Format/Ideogram/Word(int)\" %d\n", (reader->m_bMonoSpaced) ? 1:0); |
3849 | fprintf(f, "msg \"Format/Encoding(QString)\" \"%s\"\n", (const char*)m_EncodingAction[reader->m_encd]->text()); | 3849 | fprintf(f, "msg \"Format/Encoding(QString)\" \"%s\"\n", (const char*)m_EncodingAction[reader->m_encd]->text()); |
3850 | fprintf(f, "msg \"Format/SetWidth(int)\" %d\n", reader->m_charpc); | 3850 | fprintf(f, "msg \"Format/SetWidth(int)\" %d\n", reader->m_charpc); |
3851 | fprintf(f, "msg \"Navigation/SetOverlap(int)\" %d\n", reader->m_overlap); | 3851 | fprintf(f, "msg \"Navigation/SetOverlap(int)\" %d\n", reader->m_overlap); |
3852 | fprintf(f, "msg \"Layout/Remap(int)\" %d\n", (reader->bremap) ? 1:0); | 3852 | fprintf(f, "msg \"Layout/Remap(int)\" %d\n", (reader->bremap) ? 1:0); |
3853 | fprintf(f, "msg \"Layout/Embolden(int)\" %d\n", (reader->bmakebold) ? 1:0); | 3853 | fprintf(f, "msg \"Layout/Embolden(int)\" %d\n", (reader->bmakebold) ? 1:0); |
3854 | fprintf(f, "msg \"File/Continuous(int)\" %d\n", (reader->m_continuousDocument) ? 1:0); | 3854 | fprintf(f, "msg \"File/Continuous(int)\" %d\n", (reader->m_continuousDocument) ? 1:0); |
3855 | fprintf(f, "msg \"File/SetDictionary(QString)\" \"%s/%s\"\n", (const char *)m_targetapp, (const char *)m_targetmsg); | 3855 | fprintf(f, "msg \"File/SetDictionary(QString)\" \"%s/%s\"\n", (const char *)m_targetapp, (const char *)m_targetmsg); |
3856 | #ifdef _SCROLLPIPE | 3856 | #ifdef _SCROLLPIPE |
3857 | fprintf(f, "msg \"File/SetScrollTarget(QString)\" \"%s\"\n", (const char *)reader->m_pipetarget); | 3857 | fprintf(f, "msg \"File/SetScrollTarget(QString)\" \"%s\"\n", (const char *)reader->m_pipetarget); |
3858 | #endif | 3858 | #endif |
3859 | fprintf(f, "msg \"File/Two/OneTouch(int)\" %d\n", (m_twoTouch) ? 1:0); | 3859 | fprintf(f, "msg \"File/Two/OneTouch(int)\" %d\n", (m_twoTouch) ? 1:0); |
3860 | fprintf(f, "msg \"Target/Annotation(int)\" %d\n", (m_doAnnotation) ? 1:0); | 3860 | fprintf(f, "msg \"Target/Annotation(int)\" %d\n", (m_doAnnotation) ? 1:0); |
3861 | fprintf(f, "msg \"Target/Dictionary(int)\" %d\n", (m_doDictionary) ? 1:0); | 3861 | fprintf(f, "msg \"Target/Dictionary(int)\" %d\n", (m_doDictionary) ? 1:0); |
3862 | fprintf(f, "msg \"Target/Clipboard(int)\" %d\n", (m_doClipboard) ? 1:0); | 3862 | fprintf(f, "msg \"Target/Clipboard(int)\" %d\n", (m_doClipboard) ? 1:0); |
3863 | fprintf(f, "msg \"File/Action(QString)\" \"%s\"\n", (const char *)m_buttonAction[m_spaceTarget]->text()); | 3863 | fprintf(f, "msg \"File/Action(QString)\" \"%s\"\n", (const char *)m_buttonAction[m_spaceTarget]->text()); |
3864 | fprintf(f, "msg \"Update(int)\" 1\n"); | 3864 | fprintf(f, "msg \"Update(int)\" 1\n"); |
3865 | fprintf(f, "msg \"info(QString)\" \"All Done\"\n"); | 3865 | fprintf(f, "msg \"info(QString)\" \"All Done\"\n"); |
3866 | fclose(f); | 3866 | fclose(f); |
3867 | chmod(sname, S_IXUSR | S_IXGRP | S_IXOTH); | 3867 | chmod(sname, S_IXUSR | S_IXGRP | S_IXOTH); |
3868 | } | 3868 | } |
3869 | } | 3869 | } |
3870 | 3870 | ||
3871 | void QTReaderApp::SaveConfig() | 3871 | void QTReaderApp::SaveConfig() |
3872 | { | 3872 | { |
3873 | m_nRegAction = cSetConfigName; | 3873 | m_nRegAction = cSetConfigName; |
3874 | regEdit->setText(""); | 3874 | regEdit->setText(""); |
3875 | do_regedit(); | 3875 | do_regedit(); |
3876 | } | 3876 | } |
3877 | 3877 | ||
3878 | void QTReaderApp::do_saveconfig(const QString& _txt) | 3878 | void QTReaderApp::do_saveconfig(const QString& _txt) |
3879 | { | 3879 | { |
3880 | SaveScript(Global::applicationFileName(APPDIR "/scripts", _txt)); | 3880 | SaveScript(Global::applicationFileName(APPDIR "/scripts", _txt)); |
3881 | } | 3881 | } |
3882 | #endif | 3882 | #endif |
3883 | 3883 | ||
3884 | #ifdef _SCROLLPIPE | 3884 | #ifdef _SCROLLPIPE |
3885 | void QTReaderApp::setpipetarget() | 3885 | void QTReaderApp::setpipetarget() |
3886 | { | 3886 | { |
3887 | m_nRegAction = cSetPipeTarget; | 3887 | m_nRegAction = cSetPipeTarget; |
3888 | QString text = (reader->m_pipetarget.isEmpty()) ? QString("") : reader->m_pipetarget; | 3888 | QString text = (reader->m_pipetarget.isEmpty()) ? QString("") : reader->m_pipetarget; |
3889 | regEdit->setText(text); | 3889 | regEdit->setText(text); |
3890 | do_regedit(); | 3890 | do_regedit(); |
3891 | } | 3891 | } |
3892 | 3892 | ||
3893 | void QTReaderApp::do_setpipetarget(const QString& _txt) | 3893 | void QTReaderApp::do_setpipetarget(const QString& _txt) |
3894 | { | 3894 | { |
3895 | reader->m_pipetarget = _txt; | 3895 | reader->m_pipetarget = _txt; |
3896 | } | 3896 | } |
3897 | 3897 | ||
3898 | void QTReaderApp::setpause(bool sfs) | 3898 | void QTReaderApp::setpause(bool sfs) |
3899 | { | 3899 | { |
3900 | reader->m_pauseAfterEachPara = sfs; | 3900 | reader->m_pauseAfterEachPara = sfs; |
3901 | } | 3901 | } |
3902 | #endif | 3902 | #endif |
3903 | 3903 | ||
3904 | void QTReaderApp::monospace(bool _b) | 3904 | void QTReaderApp::monospace(bool _b) |
3905 | { | 3905 | { |
3906 | reader->setmono(_b); | 3906 | reader->setmono(_b); |
3907 | } | 3907 | } |
3908 | 3908 | ||
3909 | bool QTReaderApp::readconfig(const QString& _txt, bool full=false) | 3909 | bool QTReaderApp::readconfig(const QString& _txt, bool full=false) |
3910 | { | 3910 | { |
3911 | #ifdef USEQPE | 3911 | #ifdef USEQPE |
3912 | QString configname; | 3912 | QString configname; |
3913 | Config::Domain dom; | 3913 | Config::Domain dom; |
3914 | 3914 | ||
3915 | if (full) | 3915 | if (full) |
3916 | { | 3916 | { |
3917 | configname = _txt; | 3917 | configname = _txt; |
3918 | dom = Config::User; | 3918 | dom = Config::User; |
3919 | } | 3919 | } |
3920 | else | 3920 | else |
3921 | { | 3921 | { |
3922 | configname = Global::applicationFileName(APPDIR "/configs", _txt); | 3922 | configname = Global::applicationFileName(APPDIR "/configs", _txt); |
3923 | QFileInfo fm(configname); | 3923 | QFileInfo fm(configname); |
3924 | if ( !fm.exists() ) return false; | 3924 | if ( !fm.exists() ) return false; |
3925 | dom = Config::File; | 3925 | dom = Config::File; |
3926 | } | 3926 | } |
3927 | 3927 | ||
3928 | Config config(configname, dom); | 3928 | Config config(configname, dom); |
3929 | config.setGroup( "View" ); | 3929 | config.setGroup( "View" ); |
3930 | 3930 | ||
3931 | #else | 3931 | #else |
3932 | QFileInfo fi; | 3932 | QFileInfo fi; |
3933 | if (full) | 3933 | if (full) |
3934 | { | 3934 | { |
3935 | QDir d = QDir::home(); // "/" | 3935 | QDir d = QDir::home(); // "/" |
3936 | if ( !d.cd(_txt) ) | 3936 | if ( !d.cd(_txt) ) |
3937 | { // "/tmp" | 3937 | { // "/tmp" |
3938 | qWarning( "Cannot find the \"~/%s\" directory", (const char*)_txt ); | 3938 | qWarning( "Cannot find the \"~/%s\" directory", (const char*)_txt ); |
3939 | d = QDir::home(); | 3939 | d = QDir::home(); |
3940 | d.mkdir(_txt); | 3940 | d.mkdir(_txt); |
3941 | d.cd(_txt); | 3941 | d.cd(_txt); |
3942 | } | 3942 | } |
3943 | fi.setFile(d, INIFILE); | 3943 | fi.setFile(d, INIFILE); |
3944 | } | 3944 | } |
3945 | else | 3945 | else |
3946 | { | 3946 | { |
3947 | QDir d = QDir::home(); // "/" | 3947 | QDir d = QDir::home(); // "/" |
3948 | if ( !d.cd(APPDIR) ) | 3948 | if ( !d.cd(APPDIR) ) |
3949 | { // "/tmp" | 3949 | { // "/tmp" |
3950 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); | 3950 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); |
3951 | d = QDir::home(); | 3951 | d = QDir::home(); |
3952 | d.mkdir(APPDIR); | 3952 | d.mkdir(APPDIR); |
3953 | d.cd(APPDIR); | 3953 | d.cd(APPDIR); |
3954 | } | 3954 | } |
3955 | if ( !d.cd("configs") ) | 3955 | if ( !d.cd("configs") ) |
3956 | { // "/tmp" | 3956 | { // "/tmp" |
3957 | qWarning( "Cannot find the \"~/" APPDIR "/configs\" directory" ); | 3957 | qWarning( "Cannot find the \"~/" APPDIR "/configs\" directory" ); |
3958 | d = QDir::home(); | 3958 | d = QDir::home(); |
3959 | d.mkdir("configs"); | 3959 | d.mkdir("configs"); |
3960 | d.cd("configs"); | 3960 | d.cd("configs"); |
3961 | } | 3961 | } |
3962 | fi.setFile(d, _txt); | 3962 | fi.setFile(d, _txt); |
3963 | } | 3963 | } |
3964 | #ifdef _WINDOWS | 3964 | #ifdef _WINDOWS |
3965 | struct stat fnstat; | 3965 | struct stat fnstat; |
3966 | if (stat((const char *)reader->m_lastfile, &fnstat) == 0) return false; // get round fileinfo bug on windows | 3966 | if (stat((const char *)reader->m_lastfile, &fnstat) == 0) return false; // get round fileinfo bug on windows |
3967 | #else | 3967 | #else |
3968 | if (!fi.exists()) return false; | 3968 | if (!fi.exists()) return false; |
3969 | #endif | 3969 | #endif |
3970 | Config config(fi.absFilePath()); | 3970 | Config config(fi.absFilePath()); |
3971 | #endif | 3971 | #endif |
3972 | if (full) | 3972 | if (full) |
3973 | { | 3973 | { |
3974 | config.setGroup("Toolbar"); | 3974 | config.setGroup("Toolbar"); |
3975 | m_tbmovesave = m_tbmove = config.readBoolEntry("Movable", false); | 3975 | m_tbmovesave = m_tbmove = config.readBoolEntry("Movable", false); |
3976 | m_tbpolsave = m_tbpol = (ToolbarPolicy)config.readNumEntry("Policy", 1); | 3976 | m_tbpolsave = m_tbpol = (ToolbarPolicy)config.readNumEntry("Policy", 1); |
3977 | m_tbposition = (ToolBarDock)config.readNumEntry("Position", 2); | 3977 | m_tbposition = (ToolBarDock)config.readNumEntry("Position", 2); |
3978 | } | 3978 | } |
3979 | config.setGroup( "View" ); | 3979 | config.setGroup( "View" ); |
3980 | m_bFloatingDialog = config.readBoolEntry("FloatDialogs", false); | 3980 | m_bFloatingDialog = config.readBoolEntry("FloatDialogs", false); |
3981 | reader->bstripcr = config.readBoolEntry( "StripCr", true ); | 3981 | reader->bstripcr = config.readBoolEntry( "StripCr", true ); |
3982 | reader->bfulljust = config.readBoolEntry( "FullJust", false ); | 3982 | reader->bfulljust = config.readBoolEntry( "FullJust", false ); |
3983 | reader->setextraspace(config.readNumEntry( "ExtraSpace", 0 )); | 3983 | reader->setextraspace(config.readNumEntry( "ExtraSpace", 0 )); |
3984 | reader->setlead(config.readNumEntry( "ExtraLead", 0 )); | 3984 | reader->setlead(config.readNumEntry( "ExtraLead", 0 )); |
3985 | reader->btextfmt = config.readBoolEntry( "TextFmt", false ); | 3985 | reader->btextfmt = config.readBoolEntry( "TextFmt", false ); |
3986 | reader->bautofmt = config.readBoolEntry( "AutoFmt", true ); | 3986 | reader->bautofmt = config.readBoolEntry( "AutoFmt", true ); |
3987 | reader->bstriphtml = config.readBoolEntry( "StripHtml", false ); | 3987 | reader->bstriphtml = config.readBoolEntry( "StripHtml", false ); |
3988 | reader->bpeanut = config.readBoolEntry( "Peanut", false ); | 3988 | reader->bpeanut = config.readBoolEntry( "Peanut", false ); |
3989 | reader->bdehyphen = config.readBoolEntry( "Dehyphen", false ); | 3989 | reader->bdehyphen = config.readBoolEntry( "Dehyphen", false ); |
3990 | reader->bdepluck = config.readBoolEntry( "Depluck", false ); | 3990 | reader->bdepluck = config.readBoolEntry( "Depluck", false ); |
3991 | reader->bdejpluck = config.readBoolEntry( "Dejpluck", false ); | 3991 | reader->bdejpluck = config.readBoolEntry( "Dejpluck", false ); |
3992 | reader->bonespace = config.readBoolEntry( "OneSpace", false ); | 3992 | reader->bonespace = config.readBoolEntry( "OneSpace", false ); |
3993 | reader->bunindent = config.readBoolEntry( "Unindent", false ); | 3993 | reader->bunindent = config.readBoolEntry( "Unindent", false ); |
3994 | reader->brepara = config.readBoolEntry( "Repara", false ); | 3994 | reader->brepara = config.readBoolEntry( "Repara", false ); |
3995 | reader->bdblspce = config.readBoolEntry( "DoubleSpace", false ); | 3995 | reader->bdblspce = config.readBoolEntry( "DoubleSpace", false ); |
3996 | reader->bindenter = config.readNumEntry( "Indent", 0 ); | 3996 | reader->bindenter = config.readNumEntry( "Indent", 0 ); |
3997 | reader->m_textsize = config.readNumEntry( "FontSize", 12 ); | 3997 | reader->m_textsize = config.readNumEntry( "FontSize", 12 ); |
3998 | reader->m_delay = config.readNumEntry( "ScrollDelay", 5184); | 3998 | reader->m_delay = config.readNumEntry( "ScrollDelay", 5184); |
3999 | if (full) | 3999 | if (full) |
4000 | { | 4000 | { |
4001 | reader->m_lastfile = config.readEntry( "LastFile", QString::null ); | 4001 | reader->m_lastfile = config.readEntry( "LastFile", QString::null ); |
4002 | reader->m_lastposn = config.readNumEntry( "LastPosn", 0 ); | 4002 | reader->m_lastposn = config.readNumEntry( "LastPosn", 0 ); |
4003 | } | 4003 | } |
4004 | reader->m_bpagemode = config.readBoolEntry( "PageMode", true ); | 4004 | reader->m_bpagemode = config.readBoolEntry( "PageMode", true ); |
4005 | reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false); | 4005 | reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false); |
4006 | reader->m_swapmouse = config.readBoolEntry( "SwapMouse", false); | 4006 | reader->m_swapmouse = config.readBoolEntry( "SwapMouse", false); |
4007 | reader->m_fontname = config.readEntry( "Fontname", "helvetica" ); | 4007 | reader->m_fontname = config.readEntry( "Fontname", "helvetica" ); |
4008 | reader->m_encd = config.readNumEntry( "Encoding", 0 ); | 4008 | reader->m_encd = config.readNumEntry( "Encoding", 0 ); |
4009 | reader->m_charpc = config.readNumEntry( "CharSpacing", 100 ); | 4009 | reader->m_charpc = config.readNumEntry( "CharSpacing", 100 ); |
4010 | reader->m_overlap = config.readNumEntry( "Overlap", 0 ); | 4010 | reader->m_overlap = config.readNumEntry( "Overlap", 0 ); |
4011 | reader->m_border = config.readNumEntry( "Margin", 6 ); | 4011 | reader->m_border = config.readNumEntry( "Margin", 6 ); |
4012 | #ifdef REPALM | 4012 | #ifdef REPALM |
4013 | reader->brepalm = config.readBoolEntry( "Repalm", true ); | 4013 | reader->brepalm = config.readBoolEntry( "Repalm", true ); |
4014 | #endif | 4014 | #endif |
4015 | reader->bremap = config.readBoolEntry( "Remap", true ); | 4015 | reader->bremap = config.readBoolEntry( "Remap", true ); |
4016 | reader->bmakebold = config.readBoolEntry( "MakeBold", false ); | 4016 | reader->bmakebold = config.readBoolEntry( "MakeBold", false ); |
4017 | reader->setContinuous(config.readBoolEntry( "Continuous", true )); | 4017 | reader->setContinuous(config.readBoolEntry( "Continuous", true )); |
4018 | m_targetapp = config.readEntry( "TargetApp", QString::null ); | 4018 | m_targetapp = config.readEntry( "TargetApp", QString::null ); |
4019 | m_targetmsg = config.readEntry( "TargetMsg", QString::null ); | 4019 | m_targetmsg = config.readEntry( "TargetMsg", QString::null ); |
4020 | #ifdef _SCROLLPIPE | 4020 | #ifdef _SCROLLPIPE |
4021 | reader->m_pipetarget = config.readEntry( "PipeTarget", QString::null ); | 4021 | reader->m_pipetarget = config.readEntry( "PipeTarget", QString::null ); |
4022 | reader->m_pauseAfterEachPara = config.readBoolEntry( "PauseAfterPara", true ); | 4022 | reader->m_pauseAfterEachPara = config.readBoolEntry( "PauseAfterPara", true ); |
4023 | #endif | 4023 | #endif |
4024 | m_twoTouch = config.readBoolEntry( "TwoTouch", false); | 4024 | m_twoTouch = config.readBoolEntry( "TwoTouch", false); |
4025 | m_doAnnotation = config.readBoolEntry( "Annotation", false); | 4025 | m_doAnnotation = config.readBoolEntry( "Annotation", false); |
4026 | m_doDictionary = config.readBoolEntry( "Dictionary", false); | 4026 | m_doDictionary = config.readBoolEntry( "Dictionary", false); |
4027 | m_doClipboard = config.readBoolEntry( "Clipboard", false); | 4027 | m_doClipboard = config.readBoolEntry( "Clipboard", false); |
4028 | m_spaceTarget = (ActionTypes)config.readNumEntry("SpaceTarget", cesAutoScroll); | 4028 | m_spaceTarget = (ActionTypes)config.readNumEntry("SpaceTarget", cesAutoScroll); |
4029 | m_escapeTarget = (ActionTypes)config.readNumEntry("EscapeTarget", cesNone); | 4029 | m_escapeTarget = (ActionTypes)config.readNumEntry("EscapeTarget", cesNone); |
4030 | m_returnTarget = (ActionTypes)config.readNumEntry("ReturnTarget", cesFullScreen); | 4030 | m_returnTarget = (ActionTypes)config.readNumEntry("ReturnTarget", cesFullScreen); |
4031 | m_leftTarget = (ActionTypes)config.readNumEntry("LeftTarget", cesZoomOut); | 4031 | m_leftTarget = (ActionTypes)config.readNumEntry("LeftTarget", cesZoomOut); |
4032 | m_rightTarget = (ActionTypes)config.readNumEntry("RightTarget", cesZoomIn); | 4032 | m_rightTarget = (ActionTypes)config.readNumEntry("RightTarget", cesZoomIn); |
4033 | m_upTarget = (ActionTypes)config.readNumEntry("UpTarget", cesPageUp); | 4033 | m_upTarget = (ActionTypes)config.readNumEntry("UpTarget", cesPageUp); |
4034 | m_downTarget = (ActionTypes)config.readNumEntry("DownTarget", cesPageDown); | 4034 | m_downTarget = (ActionTypes)config.readNumEntry("DownTarget", cesPageDown); |
4035 | 4035 | ||
4036 | m_leftScroll = config.readBoolEntry("LeftScroll", false); | 4036 | m_leftScroll = config.readBoolEntry("LeftScroll", false); |
4037 | m_rightScroll = config.readBoolEntry("RightScroll", false); | 4037 | m_rightScroll = config.readBoolEntry("RightScroll", false); |
4038 | m_upScroll = config.readBoolEntry("UpScroll", true); | 4038 | m_upScroll = config.readBoolEntry("UpScroll", true); |
4039 | m_downScroll = config.readBoolEntry("DownScroll", true); | 4039 | m_downScroll = config.readBoolEntry("DownScroll", true); |
4040 | m_propogatefontchange = config.readBoolEntry( "RequestorFontChange", false); | 4040 | m_propogatefontchange = config.readBoolEntry( "RequestorFontChange", false); |
4041 | reader->setBaseSize(config.readNumEntry( "Basesize", 10 )); | 4041 | reader->setBaseSize(config.readNumEntry( "Basesize", 10 )); |
4042 | reader->setTwoTouch(m_twoTouch); | 4042 | reader->setTwoTouch(m_twoTouch); |
4043 | 4043 | ||
4044 | m_touch_action->setOn(m_twoTouch); | 4044 | m_touch_action->setOn(m_twoTouch); |
4045 | m_setmono_action->setOn(reader->m_bMonoSpaced); | 4045 | m_setmono_action->setOn(reader->m_bMonoSpaced); |
4046 | setfontHelper(reader->m_fontname); | 4046 | setfontHelper(reader->m_fontname); |
4047 | if (full) | 4047 | if (full) |
4048 | { | 4048 | { |
4049 | addtoolbars(&config); | 4049 | addtoolbars(&config); |
4050 | } | 4050 | } |
4051 | reader->setfilter(reader->getfilter()); | 4051 | reader->setfilter(reader->getfilter()); |
4052 | reader->refresh(); | 4052 | reader->refresh(); |
4053 | return true; | 4053 | return true; |
4054 | } | 4054 | } |
4055 | 4055 | ||
4056 | bool QTReaderApp::PopulateConfig(const char* tgtdir) | 4056 | bool QTReaderApp::PopulateConfig(const char* tgtdir) |
4057 | { | 4057 | { |
4058 | bkmkselector->clear(); | 4058 | bkmkselector->clear(); |
4059 | bkmkselector->setText("Cancel"); | 4059 | bkmkselector->setText("Cancel"); |
4060 | #ifndef USEQPE | 4060 | #ifndef USEQPE |
4061 | int cnt = 0; | 4061 | int cnt = 0; |
4062 | 4062 | ||
4063 | QDir d = QDir::home(); // "/" | 4063 | QDir d = QDir::home(); // "/" |
4064 | if ( !d.cd(APPDIR) ) { // "/tmp" | 4064 | if ( !d.cd(APPDIR) ) { // "/tmp" |
4065 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); | 4065 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); |
4066 | d = QDir::home(); | 4066 | d = QDir::home(); |
4067 | d.mkdir(APPDIR); | 4067 | d.mkdir(APPDIR); |
4068 | d.cd(APPDIR); | 4068 | d.cd(APPDIR); |
4069 | } | 4069 | } |
4070 | if ( !d.cd(tgtdir) ) { // "/tmp" | 4070 | if ( !d.cd(tgtdir) ) { // "/tmp" |
4071 | qWarning( "Cannot find the \"~/" APPDIR "/%s\" directory", tgtdir ); | 4071 | qWarning( "Cannot find the \"~/" APPDIR "/%s\" directory", tgtdir ); |
4072 | d = QDir::home(); | 4072 | d = QDir::home(); |
4073 | d.mkdir(tgtdir); | 4073 | d.mkdir(tgtdir); |
4074 | d.cd(tgtdir); | 4074 | d.cd(tgtdir); |
4075 | } | 4075 | } |
4076 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 4076 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
4077 | // d.setSorting( QDir::Size | QDir::Reversed ); | 4077 | // d.setSorting( QDir::Size | QDir::Reversed ); |
4078 | 4078 | ||
4079 | const QFileInfoList *list = d.entryInfoList(); | 4079 | const QFileInfoList *list = d.entryInfoList(); |
4080 | QFileInfoListIterator it( *list ); // create list iterator | 4080 | QFileInfoListIterator it( *list ); // create list iterator |
4081 | QFileInfo *fi; // pointer for traversing | 4081 | QFileInfo *fi; // pointer for traversing |
4082 | 4082 | ||
4083 | while ( (fi=it.current()) ) { // for each file... | 4083 | while ( (fi=it.current()) ) { // for each file... |
4084 | 4084 | ||
4085 | bkmkselector->insertItem(fi->fileName()); | 4085 | bkmkselector->insertItem(fi->fileName()); |
4086 | cnt++; | 4086 | cnt++; |
4087 | 4087 | ||
4088 | //qDebug( "%10li %s", fi->size(), fi->fileName().data() ); | 4088 | //qDebug( "%10li %s", fi->size(), fi->fileName().data() ); |
4089 | ++it; // goto next list element | 4089 | ++it; // goto next list element |
4090 | } | 4090 | } |
4091 | 4091 | ||
4092 | #else /* USEQPE */ | 4092 | #else /* USEQPE */ |
4093 | int cnt = 0; | 4093 | int cnt = 0; |
4094 | DIR *d; | 4094 | DIR *d; |
4095 | char* finaldir; | 4095 | char* finaldir; |
4096 | finaldir = new char[strlen(APPDIR)+1+strlen(tgtdir)+1]; | 4096 | finaldir = new char[strlen(APPDIR)+1+strlen(tgtdir)+1]; |
4097 | strcpy(finaldir, APPDIR); | 4097 | strcpy(finaldir, APPDIR); |
4098 | strcat(finaldir, "/"); | 4098 | strcat(finaldir, "/"); |
4099 | strcat(finaldir, tgtdir); | 4099 | strcat(finaldir, tgtdir); |
4100 | d = opendir((const char *)Global::applicationFileName(finaldir,"")); | 4100 | d = opendir((const char *)Global::applicationFileName(finaldir,"")); |
4101 | 4101 | ||
4102 | while(1) | 4102 | while(1) |
4103 | { | 4103 | { |
4104 | struct dirent* de; | 4104 | struct dirent* de; |
4105 | struct stat buf; | 4105 | struct stat buf; |
4106 | de = readdir(d); | 4106 | de = readdir(d); |
4107 | if (de == NULL) break; | 4107 | if (de == NULL) break; |
4108 | 4108 | ||
4109 | if (lstat((const char *)Global::applicationFileName(finaldir,de->d_name),&buf) == 0 && S_ISREG(buf.st_mode)) | 4109 | if (lstat((const char *)Global::applicationFileName(finaldir,de->d_name),&buf) == 0 && S_ISREG(buf.st_mode)) |
4110 | { | 4110 | { |
4111 | bkmkselector->insertItem(de->d_name); | 4111 | bkmkselector->insertItem(de->d_name); |
4112 | cnt++; | 4112 | cnt++; |
4113 | } | 4113 | } |
4114 | } | 4114 | } |
4115 | delete [] finaldir; | 4115 | delete [] finaldir; |
4116 | closedir(d); | 4116 | closedir(d); |
4117 | #endif | 4117 | #endif |
4118 | return (cnt > 0); | 4118 | return (cnt > 0); |
4119 | } | 4119 | } |
4120 | 4120 | ||
4121 | void QTReaderApp::LoadConfig() | 4121 | void QTReaderApp::LoadConfig() |
4122 | { | 4122 | { |
4123 | if (PopulateConfig("configs")) | 4123 | if (PopulateConfig("configs")) |
4124 | { | 4124 | { |
4125 | editorStack->raiseWidget( bkmkselector ); | 4125 | editorStack->raiseWidget( bkmkselector ); |
4126 | hidetoolbars(); | 4126 | hidetoolbars(); |
4127 | m_nBkmkAction = cLdConfig; | 4127 | m_nBkmkAction = cLdConfig; |
4128 | } | 4128 | } |
4129 | else | 4129 | else |
4130 | QMessageBox::information(this, PROGNAME, "No config files"); | 4130 | QMessageBox::information(this, PROGNAME, "No config files"); |
4131 | } | 4131 | } |
4132 | 4132 | ||
4133 | void QTReaderApp::TidyConfig() | 4133 | void QTReaderApp::TidyConfig() |
4134 | { | 4134 | { |
4135 | if (PopulateConfig("configs")) | 4135 | if (PopulateConfig("configs")) |
4136 | { | 4136 | { |
4137 | editorStack->raiseWidget( bkmkselector ); | 4137 | editorStack->raiseWidget( bkmkselector ); |
4138 | hidetoolbars(); | 4138 | hidetoolbars(); |
4139 | m_nBkmkAction = cRmConfig; | 4139 | m_nBkmkAction = cRmConfig; |
4140 | } | 4140 | } |
4141 | else | 4141 | else |
4142 | QMessageBox::information(this, PROGNAME, "No config files"); | 4142 | QMessageBox::information(this, PROGNAME, "No config files"); |
4143 | } | 4143 | } |
4144 | 4144 | ||
4145 | void QTReaderApp::ExportLinks() | 4145 | void QTReaderApp::ExportLinks() |
4146 | { | 4146 | { |
4147 | if (PopulateConfig("urls")) | 4147 | if (PopulateConfig("urls")) |
4148 | { | 4148 | { |
4149 | editorStack->raiseWidget( bkmkselector ); | 4149 | editorStack->raiseWidget( bkmkselector ); |
4150 | hidetoolbars(); | 4150 | hidetoolbars(); |
4151 | m_nBkmkAction = cExportLinks; | 4151 | m_nBkmkAction = cExportLinks; |
4152 | } | 4152 | } |
4153 | else | 4153 | else |
4154 | QMessageBox::information(this, PROGNAME, "No url files"); | 4154 | QMessageBox::information(this, PROGNAME, "No url files"); |
4155 | } | 4155 | } |
4156 | 4156 | ||
4157 | void QTReaderApp::OnURLSelected(const QString& href) | 4157 | void QTReaderApp::OnURLSelected(const QString& href) |
4158 | { | 4158 | { |
4159 | CURLDialog* urld = new CURLDialog(href, false, this); | 4159 | CURLDialog* urld = new CURLDialog(href, false, this); |
4160 | urld->clipboard(m_url_clipboard); | 4160 | urld->clipboard(m_url_clipboard); |
4161 | urld->localfile(m_url_localfile); | 4161 | urld->localfile(m_url_localfile); |
4162 | urld->globalfile(m_url_globalfile); | 4162 | urld->globalfile(m_url_globalfile); |
4163 | if (urld->exec()) | 4163 | if (urld->exec()) |
4164 | { | 4164 | { |
4165 | m_url_clipboard = urld->clipboard(); | 4165 | m_url_clipboard = urld->clipboard(); |
4166 | m_url_localfile = urld->localfile(); | 4166 | m_url_localfile = urld->localfile(); |
4167 | m_url_globalfile = urld->globalfile(); | 4167 | m_url_globalfile = urld->globalfile(); |
4168 | if (m_url_clipboard) | 4168 | if (m_url_clipboard) |
4169 | { | 4169 | { |
4170 | QClipboard* cb = QApplication::clipboard(); | 4170 | QClipboard* cb = QApplication::clipboard(); |
4171 | cb->setText(href); | 4171 | cb->setText(href); |
4172 | qDebug("<a href=\"%s\">%s</a>", (const char*)href, (const char*)href); | 4172 | qDebug("<a href=\"%s\">%s</a>", (const char*)href, (const char*)href); |
4173 | } | 4173 | } |
4174 | if (m_url_localfile) | 4174 | if (m_url_localfile) |
4175 | { | 4175 | { |
4176 | writeUrl(reader->m_string, href); | 4176 | writeUrl(reader->m_string, href); |
4177 | } | 4177 | } |
4178 | if (m_url_globalfile) | 4178 | if (m_url_globalfile) |
4179 | { | 4179 | { |
4180 | writeUrl("GlobalURLFile", href); | 4180 | writeUrl("GlobalURLFile", href); |
4181 | } | 4181 | } |
4182 | } | 4182 | } |
4183 | delete urld; | 4183 | delete urld; |
4184 | } | 4184 | } |
4185 | 4185 | ||
4186 | void QTReaderApp::writeUrl(const QString& file, const QString& href) | 4186 | void QTReaderApp::writeUrl(const QString& file, const QString& href) |
4187 | { | 4187 | { |
4188 | QString filename; | 4188 | QString filename; |
4189 | #ifdef USEQPE | 4189 | #ifdef USEQPE |
4190 | filename = Global::applicationFileName(APPDIR "/urls", file); | 4190 | filename = Global::applicationFileName(APPDIR "/urls", file); |
4191 | #else | 4191 | #else |
4192 | QFileInfo fi; | 4192 | QFileInfo fi; |
4193 | QDir d = QDir::home(); // "/" | 4193 | QDir d = QDir::home(); // "/" |
4194 | if ( !d.cd(APPDIR) ) | 4194 | if ( !d.cd(APPDIR) ) |
4195 | { // "/tmp" | 4195 | { // "/tmp" |
4196 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); | 4196 | qWarning( "Cannot find the \"~/" APPDIR "\" directory" ); |
4197 | d = QDir::home(); | 4197 | d = QDir::home(); |
4198 | d.mkdir(APPDIR); | 4198 | d.mkdir(APPDIR); |
4199 | d.cd(APPDIR); | 4199 | d.cd(APPDIR); |
4200 | } | 4200 | } |
4201 | if ( !d.cd("urls") ) | 4201 | if ( !d.cd("urls") ) |
4202 | { // "/tmp" | 4202 | { // "/tmp" |
4203 | qWarning( "Cannot find the \"~/" APPDIR "/urls\" directory" ); | 4203 | qWarning( "Cannot find the \"~/" APPDIR "/urls\" directory" ); |
4204 | d = QDir::home(); | 4204 | d = QDir::home(); |
4205 | d.cd(APPDIR); | 4205 | d.cd(APPDIR); |
4206 | d.mkdir("urls"); | 4206 | d.mkdir("urls"); |
4207 | d.cd("urls"); | 4207 | d.cd("urls"); |
4208 | } | 4208 | } |
4209 | fi.setFile(d, file); | 4209 | fi.setFile(d, file); |
4210 | filename = fi.absFilePath(); | 4210 | filename = fi.absFilePath(); |
4211 | #endif | 4211 | #endif |
4212 | FILE* fout = fopen(filename, "a"); | 4212 | FILE* fout = fopen(filename, "a"); |
4213 | if (fout != NULL) | 4213 | if (fout != NULL) |
4214 | { | 4214 | { |
4215 | fprintf(fout, "<p><a href=\"%s\">%s</a>\n", (const char*)href, (const char*)href); | 4215 | fprintf(fout, "<p><a href=\"%s\">%s</a>\n", (const char*)href, (const char*)href); |
4216 | fclose(fout); | 4216 | fclose(fout); |
4217 | } | 4217 | } |
4218 | else | 4218 | else |
4219 | { | 4219 | { |
4220 | QMessageBox::warning(this, PROGNAME, "Problem with writing URL"); | 4220 | QMessageBox::warning(this, PROGNAME, "Problem with writing URL"); |
4221 | } | 4221 | } |
4222 | } | 4222 | } |
diff --git a/noncore/apps/opie-reader/QTReaderApp.h b/noncore/apps/opie-reader/QTReaderApp.h index 86c14b1..ab6f60e 100644 --- a/noncore/apps/opie-reader/QTReaderApp.h +++ b/noncore/apps/opie-reader/QTReaderApp.h | |||
@@ -1,442 +1,442 @@ | |||
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 Qt Palmtop Environment. | 4 | ** This file is part of Qt Palmtop 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 | #ifndef __QTREADERAPP_H | 20 | #ifndef __QTREADERAPP_H |
21 | #define __QTREADERAPP_H | 21 | #define __QTREADERAPP_H |
22 | 22 | ||
23 | //#define _SCROLLPIPE | 23 | //#define _SCROLLPIPE |
24 | //#define __ISEARCH | 24 | //#define __ISEARCH |
25 | 25 | ||
26 | //#define MAX_ENCODING 6 | 26 | //#define MAX_ENCODING 6 |
27 | #define MAX_ACTIONS 5 | 27 | #define MAX_ACTIONS 5 |
28 | 28 | ||
29 | #include "useqpe.h" | 29 | #include "useqpe.h" |
30 | #include <sys/timeb.h> | 30 | #include <sys/timeb.h> |
31 | #include <qmainwindow.h> | 31 | #include <qmainwindow.h> |
32 | #include "CExpander.h" | 32 | #include "CExpander.h" |
33 | #include "CEncoding.h" | 33 | #include "CEncoding.h" |
34 | #include <qlist.h> | 34 | #include <qlist.h> |
35 | //#include <qpe/filemanager.h> | 35 | //#include <qpe/filemanager.h> |
36 | #include <qmap.h> | 36 | #include <qmap.h> |
37 | #include <qlineedit.h> | 37 | #include <qlineedit.h> |
38 | #include <qstack.h> | 38 | #include <qstack.h> |
39 | #include <qlistbox.h> | 39 | #include <qlistbox.h> |
40 | //#include "Queue.h" | 40 | //#include "Queue.h" |
41 | 41 | ||
42 | class QWidgetStack; | 42 | class QWidgetStack; |
43 | class QToolButton; | 43 | class QToolButton; |
44 | class QPopupMenu; | 44 | class QPopupMenu; |
45 | class QToolBar; | 45 | class QToolBar; |
46 | #ifdef USEQPE | 46 | #ifdef USEQPE |
47 | class QPEToolBar; | 47 | class QToolBar; |
48 | class QMenuBar; | 48 | class QMenuBar; |
49 | #endif | 49 | #endif |
50 | class CBkmkSelector; | 50 | class CBkmkSelector; |
51 | class QProgressBar; | 51 | class QProgressBar; |
52 | class QAction; | 52 | class QAction; |
53 | class CAnnoEdit; | 53 | class CAnnoEdit; |
54 | class QFloatBar; | 54 | class QFloatBar; |
55 | class CDrawBuffer; | 55 | class CDrawBuffer; |
56 | class QTReader; | 56 | class QTReader; |
57 | class QImage; | 57 | class QImage; |
58 | class Config; | 58 | class Config; |
59 | 59 | ||
60 | enum ActionTypes | 60 | enum ActionTypes |
61 | { | 61 | { |
62 | cesNone = 0, | 62 | cesNone = 0, |
63 | cesOpenFile, | 63 | cesOpenFile, |
64 | cesAutoScroll, | 64 | cesAutoScroll, |
65 | cesActionMark, | 65 | cesActionMark, |
66 | cesActionAnno, | 66 | cesActionAnno, |
67 | cesFullScreen, | 67 | cesFullScreen, |
68 | cesZoomIn, | 68 | cesZoomIn, |
69 | cesZoomOut, | 69 | cesZoomOut, |
70 | cesBack, | 70 | cesBack, |
71 | cesForward, | 71 | cesForward, |
72 | cesHome, | 72 | cesHome, |
73 | cesPageUp, | 73 | cesPageUp, |
74 | cesPageDown, | 74 | cesPageDown, |
75 | cesLineUp, | 75 | cesLineUp, |
76 | cesLineDown, | 76 | cesLineDown, |
77 | cesStartDoc, | 77 | cesStartDoc, |
78 | cesEndDoc | 78 | cesEndDoc |
79 | }; | 79 | }; |
80 | /* | 80 | /* |
81 | *m_preferences_action, *m_close_action *m_info_action, *m_touch_action, | 81 | *m_preferences_action, *m_close_action *m_info_action, *m_touch_action, |
82 | *m_find_action, *m_jump_action, *m_setfont_action *m_goto_action, | 82 | *m_find_action, *m_jump_action, *m_setfont_action *m_goto_action, |
83 | *m_delete_action; *m_autogen_action, *m_clear_action, *m_save_action; | 83 | *m_delete_action; *m_autogen_action, *m_clear_action, *m_save_action; |
84 | *m_tidy_action, *m_startBlock_action, *m_endBlock_action; | 84 | *m_tidy_action, *m_startBlock_action, *m_endBlock_action; |
85 | *m_setenc_action, *m_setmono_action; | 85 | *m_setenc_action, *m_setmono_action; |
86 | */ | 86 | */ |
87 | enum ToolbarPolicy | 87 | enum ToolbarPolicy |
88 | { | 88 | { |
89 | cesSingle = 0, | 89 | cesSingle = 0, |
90 | cesMenuTool, | 90 | cesMenuTool, |
91 | cesMultiple | 91 | cesMultiple |
92 | }; | 92 | }; |
93 | 93 | ||
94 | enum regedit_type | 94 | enum regedit_type |
95 | { | 95 | { |
96 | cAutoGen, | 96 | cAutoGen, |
97 | cAddBkmk, | 97 | cAddBkmk, |
98 | cJump, | 98 | cJump, |
99 | cMonoSpace, | 99 | cMonoSpace, |
100 | cSetTarget, | 100 | cSetTarget, |
101 | #ifdef _SCROLLPIPE | 101 | #ifdef _SCROLLPIPE |
102 | cSetPipeTarget, | 102 | cSetPipeTarget, |
103 | #endif | 103 | #endif |
104 | cSetConfigName, | 104 | cSetConfigName, |
105 | cMargin, | 105 | cMargin, |
106 | cExtraSpace, | 106 | cExtraSpace, |
107 | cExtraLead | 107 | cExtraLead |
108 | }; | 108 | }; |
109 | 109 | ||
110 | enum bkmk_action | 110 | enum bkmk_action |
111 | { | 111 | { |
112 | cOpenFile, | 112 | cOpenFile, |
113 | cGotoBkmk, | 113 | cGotoBkmk, |
114 | cDelBkmk, | 114 | cDelBkmk, |
115 | cRmBkmkFile, | 115 | cRmBkmkFile, |
116 | cLdConfig, | 116 | cLdConfig, |
117 | cRmConfig, | 117 | cRmConfig, |
118 | cExportLinks | 118 | cExportLinks |
119 | }; | 119 | }; |
120 | 120 | ||
121 | enum fontselector_action | 121 | enum fontselector_action |
122 | { | 122 | { |
123 | cChooseFont, | 123 | cChooseFont, |
124 | cChooseEncoding | 124 | cChooseEncoding |
125 | }; | 125 | }; |
126 | 126 | ||
127 | #ifdef __ISEARCH | 127 | #ifdef __ISEARCH |
128 | struct searchrecord | 128 | struct searchrecord |
129 | { | 129 | { |
130 | QString s; | 130 | QString s; |
131 | size_t pos; | 131 | size_t pos; |
132 | searchrecord(const QString& _s, size_t _pos) : s(_s), pos(_pos) {} | 132 | searchrecord(const QString& _s, size_t _pos) : s(_s), pos(_pos) {} |
133 | }; | 133 | }; |
134 | #endif | 134 | #endif |
135 | 135 | ||
136 | class infowin; | 136 | class infowin; |
137 | class GraphicWin; | 137 | class GraphicWin; |
138 | 138 | ||
139 | class QTReaderApp : public QMainWindow | 139 | class QTReaderApp : public QMainWindow |
140 | { | 140 | { |
141 | Q_OBJECT | 141 | Q_OBJECT |
142 | 142 | ||
143 | unsigned long m_savedpos; | 143 | unsigned long m_savedpos; |
144 | int m_debounce; | 144 | int m_debounce; |
145 | timeb m_lastkeytime; | 145 | timeb m_lastkeytime; |
146 | bool m_annoIsEditing; | 146 | bool m_annoIsEditing; |
147 | bool m_propogatefontchange, m_bFloatingDialog; | 147 | bool m_propogatefontchange, m_bFloatingDialog; |
148 | bool m_url_clipboard, m_url_localfile, m_url_globalfile; | 148 | bool m_url_clipboard, m_url_localfile, m_url_globalfile; |
149 | fontselector_action m_fontAction; | 149 | fontselector_action m_fontAction; |
150 | void doAction(ActionTypes a, QKeyEvent* e); | 150 | void doAction(ActionTypes a, QKeyEvent* e); |
151 | 151 | ||
152 | public: | 152 | public: |
153 | QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 153 | QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
154 | ~QTReaderApp(); | 154 | ~QTReaderApp(); |
155 | 155 | ||
156 | void handlekey(QKeyEvent* e); | 156 | void handlekey(QKeyEvent* e); |
157 | void hideEvent(QHideEvent*) | 157 | void hideEvent(QHideEvent*) |
158 | { | 158 | { |
159 | suspend(); | 159 | suspend(); |
160 | } | 160 | } |
161 | 161 | ||
162 | void suspend(); | 162 | void suspend(); |
163 | void openFile( const QString & ); | 163 | void openFile( const QString & ); |
164 | 164 | ||
165 | void setScrollState(bool _b); | 165 | void setScrollState(bool _b); |
166 | 166 | ||
167 | protected: | 167 | protected: |
168 | void setfontHelper(const QString& lcn, int size = 0); | 168 | void setfontHelper(const QString& lcn, int size = 0); |
169 | QAction* m_bkmkAvail, *m_actFullscreen; | 169 | QAction* m_bkmkAvail, *m_actFullscreen; |
170 | CAnnoEdit* m_annoWin; | 170 | CAnnoEdit* m_annoWin; |
171 | Bkmk* m_anno; | 171 | Bkmk* m_anno; |
172 | // void resizeEvent(QResizeEvent* e); | 172 | // void resizeEvent(QResizeEvent* e); |
173 | void closeEvent( QCloseEvent *e ); | 173 | void closeEvent( QCloseEvent *e ); |
174 | void readbkmks(); | 174 | void readbkmks(); |
175 | void do_mono(const QString&); | 175 | void do_mono(const QString&); |
176 | void do_jump(const QString&); | 176 | void do_jump(const QString&); |
177 | void do_settarget(const QString&); | 177 | void do_settarget(const QString&); |
178 | #ifdef _SCROLLPIPE | 178 | #ifdef _SCROLLPIPE |
179 | //void do_setpipetarget(const QString&); | 179 | //void do_setpipetarget(const QString&); |
180 | #endif | 180 | #endif |
181 | void do_saveconfig(const QString&, bool); | 181 | void do_saveconfig(const QString&, bool); |
182 | bool readconfig(const QString&, bool); | 182 | bool readconfig(const QString&, bool); |
183 | bool PopulateConfig(const char*); | 183 | bool PopulateConfig(const char*); |
184 | ActionTypes ActNameToInt(const QString&); | 184 | ActionTypes ActNameToInt(const QString&); |
185 | bool m_doAnnotation; | 185 | bool m_doAnnotation; |
186 | bool m_doDictionary; | 186 | bool m_doDictionary; |
187 | bool m_doClipboard; | 187 | bool m_doClipboard; |
188 | bool m_fullscreen; | 188 | bool m_fullscreen; |
189 | bool m_loadedconfig; | 189 | bool m_loadedconfig; |
190 | public: | 190 | public: |
191 | void saveprefs(); | 191 | void saveprefs(); |
192 | public slots: | 192 | public slots: |
193 | void setDocument(const QString&); | 193 | void setDocument(const QString&); |
194 | private slots: | 194 | private slots: |
195 | #ifdef _SCRIPT | 195 | #ifdef _SCRIPT |
196 | // void RunScript(); | 196 | // void RunScript(); |
197 | #endif | 197 | #endif |
198 | void SaveConfig(); | 198 | void SaveConfig(); |
199 | void LoadConfig(); | 199 | void LoadConfig(); |
200 | void TidyConfig(); | 200 | void TidyConfig(); |
201 | void ExportLinks(); | 201 | void ExportLinks(); |
202 | void zoomin(); | 202 | void zoomin(); |
203 | void zoomout(); | 203 | void zoomout(); |
204 | void chooseencoding(); | 204 | void chooseencoding(); |
205 | void setfullscreen(bool sfs); | 205 | void setfullscreen(bool sfs); |
206 | // void setcontinuous(bool sfs); | 206 | // void setcontinuous(bool sfs); |
207 | void setTwoTouch(bool _b); | 207 | void setTwoTouch(bool _b); |
208 | void restoreFocus(); | 208 | void restoreFocus(); |
209 | void OnAnnotation(bool _b) | 209 | void OnAnnotation(bool _b) |
210 | { | 210 | { |
211 | m_doAnnotation = _b; | 211 | m_doAnnotation = _b; |
212 | } | 212 | } |
213 | void OnDictionary(bool _b) | 213 | void OnDictionary(bool _b) |
214 | { | 214 | { |
215 | m_doDictionary = _b; | 215 | m_doDictionary = _b; |
216 | } | 216 | } |
217 | void OnClipboard(bool _b) | 217 | void OnClipboard(bool _b) |
218 | { | 218 | { |
219 | m_doClipboard = _b; | 219 | m_doClipboard = _b; |
220 | } | 220 | } |
221 | void OnWordSelected(const QString&, size_t, const QString&); | 221 | void OnWordSelected(const QString&, size_t, const QString&); |
222 | void OnURLSelected(const QString& href); | 222 | void OnURLSelected(const QString& href); |
223 | void showgraphic(QImage&); | 223 | void showgraphic(QImage&); |
224 | void addAnno(const QString&, const QString&, size_t); | 224 | void addAnno(const QString&, const QString&, size_t); |
225 | void addAnno(const QString&, const QString&); | 225 | void addAnno(const QString&, const QString&); |
226 | void addanno(); | 226 | void addanno(); |
227 | void showAnnotation(); | 227 | void showAnnotation(); |
228 | void do_setencoding(int i); | 228 | void do_setencoding(int i); |
229 | void do_setfont(const QString&); | 229 | void do_setfont(const QString&); |
230 | void buttonActionSelected(QAction*); | 230 | void buttonActionSelected(QAction*); |
231 | //void msgHandler(const QCString&, const QByteArray&); | 231 | //void msgHandler(const QCString&, const QByteArray&); |
232 | void monospace(bool); | 232 | void monospace(bool); |
233 | void jump(); | 233 | void jump(); |
234 | void settarget(); | 234 | void settarget(); |
235 | #ifdef _SCROLLPIPE | 235 | #ifdef _SCROLLPIPE |
236 | //void setpipetarget(); | 236 | //void setpipetarget(); |
237 | //void setpause(bool); | 237 | //void setpause(bool); |
238 | #endif | 238 | #endif |
239 | //void setspacing(); | 239 | //void setspacing(); |
240 | void setfont(); | 240 | void setfont(); |
241 | void clearBkmkList(); | 241 | void clearBkmkList(); |
242 | void listBkmkFiles(); | 242 | void listBkmkFiles(); |
243 | void editMark(); | 243 | void editMark(); |
244 | void autoScroll(bool); | 244 | void autoScroll(bool); |
245 | void addbkmk(); | 245 | void addbkmk(); |
246 | void savebkmks(); | 246 | void savebkmks(); |
247 | //void importFiles(); | 247 | //void importFiles(); |
248 | void showprefs(); | 248 | void showprefs(); |
249 | void showtoolbarprefs(); | 249 | void showtoolbarprefs(); |
250 | void infoClose(); | 250 | void infoClose(); |
251 | // void oldFile(); | 251 | // void oldFile(); |
252 | void showinfo(); | 252 | void showinfo(); |
253 | 253 | ||
254 | // void indentplus(); | 254 | // void indentplus(); |
255 | // void indentminus(); | 255 | // void indentminus(); |
256 | 256 | ||
257 | void fileOpen(); | 257 | void fileOpen(); |
258 | void fileClose(); | 258 | void fileClose(); |
259 | 259 | ||
260 | void editCopy(); | 260 | void editCopy(); |
261 | void editFind(); | 261 | void editFind(); |
262 | 262 | ||
263 | void gotoStart(); | 263 | void gotoStart(); |
264 | void gotoEnd(); | 264 | void gotoEnd(); |
265 | 265 | ||
266 | void pageup(); | 266 | void pageup(); |
267 | void pagedn(); | 267 | void pagedn(); |
268 | 268 | ||
269 | void findNext(); | 269 | void findNext(); |
270 | void findClose(); | 270 | void findClose(); |
271 | 271 | ||
272 | void regClose(); | 272 | void regClose(); |
273 | 273 | ||
274 | #ifdef __ISEARCH | 274 | #ifdef __ISEARCH |
275 | // void search( const QString& ); | 275 | // void search( const QString& ); |
276 | #else | 276 | #else |
277 | void search(); | 277 | void search(); |
278 | #endif | 278 | #endif |
279 | 279 | ||
280 | void showEditTools(); | 280 | void showEditTools(); |
281 | 281 | ||
282 | // void stripcr(bool); | 282 | // void stripcr(bool); |
283 | // void setfulljust(bool); | 283 | // void setfulljust(bool); |
284 | // void onespace(bool); | 284 | // void onespace(bool); |
285 | #ifdef REPALM | 285 | #ifdef REPALM |
286 | // void repalm(bool); | 286 | // void repalm(bool); |
287 | #endif | 287 | #endif |
288 | // void peanut(bool _b); | 288 | // void peanut(bool _b); |
289 | // void remap(bool); | 289 | // void remap(bool); |
290 | // void embolden(bool); | 290 | // void embolden(bool); |
291 | // void autofmt(bool); | 291 | // void autofmt(bool); |
292 | // void textfmt(bool); | 292 | // void textfmt(bool); |
293 | // void striphtml(bool); | 293 | // void striphtml(bool); |
294 | // void dehyphen(bool); | 294 | // void dehyphen(bool); |
295 | // void depluck(bool); | 295 | // void depluck(bool); |
296 | // void dejpluck(bool); | 296 | // void dejpluck(bool); |
297 | // void unindent(bool); | 297 | // void unindent(bool); |
298 | // void repara(bool); | 298 | // void repara(bool); |
299 | // void dblspce(bool); | 299 | // void dblspce(bool); |
300 | void pagemode(bool); | 300 | void pagemode(bool); |
301 | // void gotobkmk(const QString& bm); | 301 | // void gotobkmk(const QString& bm); |
302 | void gotobkmk(int); | 302 | void gotobkmk(int); |
303 | void cancelbkmk(); | 303 | void cancelbkmk(); |
304 | void do_gotomark(); | 304 | void do_gotomark(); |
305 | void do_delmark(); | 305 | void do_delmark(); |
306 | void do_autogen(); | 306 | void do_autogen(); |
307 | void do_regaction(); | 307 | void do_regaction(); |
308 | void OnRedraw(); | 308 | void OnRedraw(); |
309 | 309 | ||
310 | private: | 310 | private: |
311 | void writeUrl(const QString& file, const QString& href); | 311 | void writeUrl(const QString& file, const QString& href); |
312 | QAction *m_preferences_action, *m_open_action, *m_close_action; | 312 | QAction *m_preferences_action, *m_open_action, *m_close_action; |
313 | QAction *m_info_action, *m_touch_action, *m_find_action, *m_start_action; | 313 | QAction *m_info_action, *m_touch_action, *m_find_action, *m_start_action; |
314 | QAction *m_end_action, *m_jump_action, *m_pageline_action; | 314 | QAction *m_end_action, *m_jump_action, *m_pageline_action; |
315 | QAction *m_pageup_action, *m_pagedn_action, *m_back_action; | 315 | QAction *m_pageup_action, *m_pagedn_action, *m_back_action; |
316 | QAction *m_home_action, *m_forward_action, *m_zoomin_action; | 316 | QAction *m_home_action, *m_forward_action, *m_zoomin_action; |
317 | QAction *m_zoomout_action, *m_setfont_action, *m_mark_action; | 317 | QAction *m_zoomout_action, *m_setfont_action, *m_mark_action; |
318 | QAction *m_annotate_action, *m_goto_action, *m_delete_action; | 318 | QAction *m_annotate_action, *m_goto_action, *m_delete_action; |
319 | QAction *m_autogen_action, *m_clear_action, *m_save_action; | 319 | QAction *m_autogen_action, *m_clear_action, *m_save_action; |
320 | QAction *m_tidy_action, *m_startBlock_action, *m_endBlock_action; | 320 | QAction *m_tidy_action, *m_startBlock_action, *m_endBlock_action; |
321 | QAction *m_setenc_action, *m_setmono_action, *m_saveconfig_action; | 321 | QAction *m_setenc_action, *m_setmono_action, *m_saveconfig_action; |
322 | QAction *m_loadconfig_action, *m_toolbarprefs_action, *m_tidyconfig_action; | 322 | QAction *m_loadconfig_action, *m_toolbarprefs_action, *m_tidyconfig_action; |
323 | QAction *m_exportlinks_action; | 323 | QAction *m_exportlinks_action; |
324 | void addtoolbars(Config* config); | 324 | void addtoolbars(Config* config); |
325 | ToolbarPolicy m_tbpol, m_tbpolsave; | 325 | ToolbarPolicy m_tbpol, m_tbpolsave; |
326 | ToolBarDock m_tbposition; | 326 | ToolBarDock m_tbposition; |
327 | bool m_tbmove, m_tbmovesave; | 327 | bool m_tbmove, m_tbmovesave; |
328 | QToolBar* filebar(); | 328 | QToolBar* filebar(); |
329 | QToolBar* viewbar(); | 329 | QToolBar* viewbar(); |
330 | QToolBar* navbar(); | 330 | QToolBar* navbar(); |
331 | QToolBar* markbar(); | 331 | QToolBar* markbar(); |
332 | void hidetoolbars(); | 332 | void hidetoolbars(); |
333 | void addfilebar(Config* _config, const QString& key, QAction* a); | 333 | void addfilebar(Config* _config, const QString& key, QAction* a); |
334 | void addviewbar(Config* _config, const QString& key, QAction* a); | 334 | void addviewbar(Config* _config, const QString& key, QAction* a); |
335 | void addnavbar(Config* _config, const QString& key, QAction* a); | 335 | void addnavbar(Config* _config, const QString& key, QAction* a); |
336 | void addmarkbar(Config* _config, const QString& key, QAction* a); | 336 | void addmarkbar(Config* _config, const QString& key, QAction* a); |
337 | bool checkbar(Config* _config, const QString& key); | 337 | bool checkbar(Config* _config, const QString& key); |
338 | #ifdef _SCRIPT | 338 | #ifdef _SCRIPT |
339 | void SaveScript(const char* sname); | 339 | void SaveScript(const char* sname); |
340 | #endif | 340 | #endif |
341 | /* | 341 | /* |
342 | void setstate(unsigned char* _sd, unsigned short _sdlen); | 342 | void setstate(unsigned char* _sd, unsigned short _sdlen); |
343 | void getstate(unsigned char*& data, unsigned short& len); | 343 | void getstate(unsigned char*& data, unsigned short& len); |
344 | */ | 344 | */ |
345 | void fileOpen2(); | 345 | void fileOpen2(); |
346 | void readfilelist(); | 346 | void readfilelist(); |
347 | void savefilelist(); | 347 | void savefilelist(); |
348 | void updatefileinfo(); | 348 | void updatefileinfo(); |
349 | bool openfrombkmk(Bkmk*); | 349 | bool openfrombkmk(Bkmk*); |
350 | QString m_targetapp, m_targetmsg; | 350 | QString m_targetapp, m_targetmsg; |
351 | bool listbkmk(CList<Bkmk>*, const QString& _lab = QString::null); | 351 | bool listbkmk(CList<Bkmk>*, const QString& _lab = QString::null); |
352 | QString usefilebrowser(); | 352 | QString usefilebrowser(); |
353 | void do_regedit(); | 353 | void do_regedit(); |
354 | void colorChanged( const QColor &c ); | 354 | void colorChanged( const QColor &c ); |
355 | void clear(); | 355 | void clear(); |
356 | void updateCaption(); | 356 | void updateCaption(); |
357 | void do_autogen(const QString&); | 357 | void do_autogen(const QString&); |
358 | void do_addbkmk(const QString&); | 358 | void do_addbkmk(const QString&); |
359 | bool findNextBookmark(size_t start); | 359 | bool findNextBookmark(size_t start); |
360 | 360 | ||
361 | private: | 361 | private: |
362 | 362 | ||
363 | QAction* m_scrollButton; | 363 | QAction* m_scrollButton; |
364 | 364 | ||
365 | QAction* m_buttonAction[MAX_ACTIONS]; | 365 | QAction* m_buttonAction[MAX_ACTIONS]; |
366 | 366 | ||
367 | CBkmkSelector* bkmkselector; | 367 | CBkmkSelector* bkmkselector; |
368 | 368 | ||
369 | ActionTypes m_spaceTarget, m_escapeTarget, m_returnTarget, m_leftTarget, m_rightTarget, | 369 | ActionTypes m_spaceTarget, m_escapeTarget, m_returnTarget, m_leftTarget, m_rightTarget, |
370 | m_upTarget, m_downTarget; | 370 | m_upTarget, m_downTarget; |
371 | bool m_leftScroll, m_rightScroll, m_upScroll, m_downScroll; | 371 | bool m_leftScroll, m_rightScroll, m_upScroll, m_downScroll; |
372 | bool m_bcloseDisabled, m_disableesckey; | 372 | bool m_bcloseDisabled, m_disableesckey; |
373 | size_t searchStart; | 373 | size_t searchStart; |
374 | #ifdef __ISEARCH | 374 | #ifdef __ISEARCH |
375 | QStack<searchrecord>* searchStack; | 375 | QStack<searchrecord>* searchStack; |
376 | bool dosearch(size_t start, CDrawBuffer& test, const QString& arg); | 376 | bool dosearch(size_t start, CDrawBuffer& test, const QString& arg); |
377 | #else | 377 | #else |
378 | bool dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg); | 378 | bool dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg); |
379 | #endif | 379 | #endif |
380 | QWidgetStack *editorStack; | 380 | QWidgetStack *editorStack; |
381 | QTReader* reader; | 381 | QTReader* reader; |
382 | QComboBox* m_fontSelector; | 382 | QComboBox* m_fontSelector; |
383 | // QPEToolBar /* *menu,*/ *fileBar; | 383 | // QToolBar /* *menu,*/ *fileBar; |
384 | QToolBar *menubar, *fileBar, *navBar, *viewBar, *markBar; | 384 | QToolBar *menubar, *fileBar, *navBar, *viewBar, *markBar; |
385 | #ifdef USEQPE | 385 | #ifdef USEQPE |
386 | QMenuBar *mb; | 386 | QMenuBar *mb; |
387 | #else | 387 | #else |
388 | QMenuBar *mb; | 388 | QMenuBar *mb; |
389 | #endif | 389 | #endif |
390 | QFloatBar *searchBar, *regBar/*, *m_fontBar*/; | 390 | QFloatBar *searchBar, *regBar/*, *m_fontBar*/; |
391 | QToolBar /* *searchBar, *regBar,*/ *m_fontBar; | 391 | QToolBar /* *searchBar, *regBar,*/ *m_fontBar; |
392 | QLineEdit *searchEdit, *regEdit; | 392 | QLineEdit *searchEdit, *regEdit; |
393 | bool searchVisible; | 393 | bool searchVisible; |
394 | bool regVisible; | 394 | bool regVisible; |
395 | bool m_fontVisible, m_twoTouch; | 395 | bool m_fontVisible, m_twoTouch; |
396 | bool bFromDocView; | 396 | bool bFromDocView; |
397 | static unsigned long m_uid; | 397 | static unsigned long m_uid; |
398 | long unsigned get_unique_id() { return m_uid++; } | 398 | long unsigned get_unique_id() { return m_uid++; } |
399 | /* | 399 | /* |
400 | void resizeEvent( QResizeEvent * r) | 400 | void resizeEvent( QResizeEvent * r) |
401 | { | 401 | { |
402 | // qDebug("resize:(%u,%u)", r->oldSize().width(), r->oldSize().height()); | 402 | // qDebug("resize:(%u,%u)", r->oldSize().width(), r->oldSize().height()); |
403 | // qDebug("resize:(%u,%u)", r->size().width(), r->size().height()); | 403 | // qDebug("resize:(%u,%u)", r->size().width(), r->size().height()); |
404 | // bgroup->move( width()-bgroup->width(), 0 ); | 404 | // bgroup->move( width()-bgroup->width(), 0 ); |
405 | } | 405 | } |
406 | */ | 406 | */ |
407 | CList<Bkmk>* pBkmklist; | 407 | CList<Bkmk>* pBkmklist; |
408 | CList<Bkmk>* pOpenlist; | 408 | CList<Bkmk>* pOpenlist; |
409 | infowin* m_infoWin; | 409 | infowin* m_infoWin; |
410 | GraphicWin* m_graphicwin; | 410 | GraphicWin* m_graphicwin; |
411 | QProgressBar* pbar; | 411 | QProgressBar* pbar; |
412 | bool m_fBkmksChanged; | 412 | bool m_fBkmksChanged; |
413 | // int m_nRegAction; | 413 | // int m_nRegAction; |
414 | regedit_type m_nRegAction; | 414 | regedit_type m_nRegAction; |
415 | bkmk_action m_nBkmkAction; | 415 | bkmk_action m_nBkmkAction; |
416 | QString m_autogenstr; | 416 | QString m_autogenstr; |
417 | bool m_dontSave; | 417 | bool m_dontSave; |
418 | }; | 418 | }; |
419 | 419 | ||
420 | //const int cAutoGen = 0; | 420 | //const int cAutoGen = 0; |
421 | //const int cAddBkmk = 1; | 421 | //const int cAddBkmk = 1; |
422 | //const int cDelBkmk = 2; | 422 | //const int cDelBkmk = 2; |
423 | //const int cGotoBkmk = 3; | 423 | //const int cGotoBkmk = 3; |
424 | //const int cRmBkmkFile = 4; | 424 | //const int cRmBkmkFile = 4; |
425 | //const int cJump = 5; | 425 | //const int cJump = 5; |
426 | //const int cMonoSpace = 6; | 426 | //const int cMonoSpace = 6; |
427 | //const int cOverlap = 7; | 427 | //const int cOverlap = 7; |
428 | //const int cSetTarget = 8; | 428 | //const int cSetTarget = 8; |
429 | //const int cOpenFile = 9; | 429 | //const int cOpenFile = 9; |
430 | //const int cSetPipeTarget = 10; | 430 | //const int cSetPipeTarget = 10; |
431 | //const int cSetConfigName = 11; | 431 | //const int cSetConfigName = 11; |
432 | //const int cMargin = 12; | 432 | //const int cMargin = 12; |
433 | //const int cExtraSpace = 14; | 433 | //const int cExtraSpace = 14; |
434 | //const int cExtraLead = 15; | 434 | //const int cExtraLead = 15; |
435 | //const int cGfxSize = 16; | 435 | //const int cGfxSize = 16; |
436 | //const int cChooseFont = 2; | 436 | //const int cChooseFont = 2; |
437 | //const int cChooseEncoding = 1; | 437 | //const int cChooseEncoding = 1; |
438 | 438 | ||
439 | #endif | 439 | #endif |
440 | 440 | ||
441 | 441 | ||
442 | 442 | ||
diff --git a/noncore/apps/opie-sheet/mainwindow.cpp b/noncore/apps/opie-sheet/mainwindow.cpp index fb2ca79..78b3073 100644 --- a/noncore/apps/opie-sheet/mainwindow.cpp +++ b/noncore/apps/opie-sheet/mainwindow.cpp | |||
@@ -1,835 +1,835 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include "mainwindow.h" | 15 | #include "mainwindow.h" |
16 | 16 | ||
17 | #include <qpe/filemanager.h> | 17 | #include <qpe/filemanager.h> |
18 | #include <qpe/qcopenvelope_qws.h> | 18 | #include <qpe/qcopenvelope_qws.h> |
19 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
20 | #include <qmessagebox.h> | 20 | #include <qmessagebox.h> |
21 | #include <qfile.h> | 21 | #include <qfile.h> |
22 | #include <qtranslator.h> | 22 | #include <qtranslator.h> |
23 | #include <qradiobutton.h> | 23 | #include <qradiobutton.h> |
24 | #include "cellformat.h" | 24 | #include "cellformat.h" |
25 | #include "numberdlg.h" | 25 | #include "numberdlg.h" |
26 | #include "textdlg.h" | 26 | #include "textdlg.h" |
27 | #include "sortdlg.h" | 27 | #include "sortdlg.h" |
28 | #include "finddlg.h" | 28 | #include "finddlg.h" |
29 | 29 | ||
30 | 30 | ||
31 | #include "func-plus.xpm" | 31 | #include "func-plus.xpm" |
32 | #include "func-minus.xpm" | 32 | #include "func-minus.xpm" |
33 | #include "func-cross.xpm" | 33 | #include "func-cross.xpm" |
34 | #include "func-divide.xpm" | 34 | #include "func-divide.xpm" |
35 | #include "func-paran-open.xpm" | 35 | #include "func-paran-open.xpm" |
36 | #include "func-paran-close.xpm" | 36 | #include "func-paran-close.xpm" |
37 | #include "func-comma.xpm" | 37 | #include "func-comma.xpm" |
38 | #include "func-func.xpm" | 38 | #include "func-func.xpm" |
39 | #include "func-equal.xpm" | 39 | #include "func-equal.xpm" |
40 | #include "cell-select.xpm" | 40 | #include "cell-select.xpm" |
41 | 41 | ||
42 | #define DEFAULT_NUM_ROWS 199 | 42 | #define DEFAULT_NUM_ROWS 199 |
43 | #define DEFAULT_NUM_COLS (26*3) | 43 | #define DEFAULT_NUM_COLS (26*3) |
44 | #define DEFAULT_NUM_SHEETS 3 | 44 | #define DEFAULT_NUM_SHEETS 3 |
45 | 45 | ||
46 | MainWindow::MainWindow(QWidget *parent, const char* n, WFlags fl) | 46 | MainWindow::MainWindow(QWidget *parent, const char* n, WFlags fl) |
47 | :QMainWindow(parent, n, fl) | 47 | :QMainWindow(parent, n, fl) |
48 | { | 48 | { |
49 | // initialize variables | 49 | // initialize variables |
50 | documentModified=FALSE; | 50 | documentModified=FALSE; |
51 | 51 | ||
52 | // construct objects | 52 | // construct objects |
53 | currentDoc=0; | 53 | currentDoc=0; |
54 | fileSelector=new FileSelector("application/sheet-qt", this, QString::null); | 54 | fileSelector=new FileSelector("application/sheet-qt", this, QString::null); |
55 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); | 55 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(selectorHide())); |
56 | connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); | 56 | connect(fileSelector, SIGNAL(newSelected(const DocLnk &)), this, SLOT(selectorFileNew(const DocLnk &))); |
57 | connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); | 57 | connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), this, SLOT(selectorFileOpen(const DocLnk &))); |
58 | 58 | ||
59 | listSheets.setAutoDelete(TRUE); | 59 | listSheets.setAutoDelete(TRUE); |
60 | 60 | ||
61 | initActions(); | 61 | initActions(); |
62 | initMenu(); | 62 | initMenu(); |
63 | initEditToolbar(); | 63 | initEditToolbar(); |
64 | initFunctionsToolbar(); | 64 | initFunctionsToolbar(); |
65 | initStandardToolbar(); | 65 | initStandardToolbar(); |
66 | initSheet(); | 66 | initSheet(); |
67 | 67 | ||
68 | // set window title | 68 | // set window title |
69 | setCaption(tr("Opie Sheet")); | 69 | setCaption(tr("Opie Sheet")); |
70 | 70 | ||
71 | // create sheets | 71 | // create sheets |
72 | selectorFileNew(DocLnk()); | 72 | selectorFileNew(DocLnk()); |
73 | } | 73 | } |
74 | 74 | ||
75 | MainWindow::~MainWindow() | 75 | MainWindow::~MainWindow() |
76 | { | 76 | { |
77 | if (currentDoc) delete currentDoc; | 77 | if (currentDoc) delete currentDoc; |
78 | } | 78 | } |
79 | 79 | ||
80 | void MainWindow::documentSave(DocLnk *lnkDoc) | 80 | void MainWindow::documentSave(DocLnk *lnkDoc) |
81 | { | 81 | { |
82 | FileManager fm; | 82 | FileManager fm; |
83 | QByteArray streamBuffer; | 83 | QByteArray streamBuffer; |
84 | QDataStream stream(streamBuffer, IO_WriteOnly); | 84 | QDataStream stream(streamBuffer, IO_WriteOnly); |
85 | 85 | ||
86 | typeSheet *currentSheet=findSheet(sheet->getName()); | 86 | typeSheet *currentSheet=findSheet(sheet->getName()); |
87 | if (!currentSheet) | 87 | if (!currentSheet) |
88 | { | 88 | { |
89 | QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!")); | 89 | QMessageBox::critical(this, tr("Error"), tr("Inconsistency error!")); |
90 | return; | 90 | return; |
91 | } | 91 | } |
92 | sheet->copySheetData(¤tSheet->data); | 92 | sheet->copySheetData(¤tSheet->data); |
93 | stream.writeRawBytes("SQT100", 6); | 93 | stream.writeRawBytes("SQT100", 6); |
94 | stream << (Q_UINT32)listSheets.count(); | 94 | stream << (Q_UINT32)listSheets.count(); |
95 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) | 95 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) |
96 | { | 96 | { |
97 | stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); | 97 | stream << tempSheet->name << (Q_UINT32)tempSheet->data.count(); |
98 | for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) | 98 | for (typeCellData *tempCell=tempSheet->data.first(); tempCell; tempCell=tempSheet->data.next()) |
99 | stream << (Q_UINT32)tempCell->col << (Q_UINT32)tempCell->row << tempCell->borders.right << tempCell->borders.bottom << tempCell->background << (Q_UINT32)tempCell->alignment << tempCell->fontColor << tempCell->font << tempCell->data; | 99 | stream << (Q_UINT32)tempCell->col << (Q_UINT32)tempCell->row << tempCell->borders.right << tempCell->borders.bottom << tempCell->background << (Q_UINT32)tempCell->alignment << tempCell->fontColor << tempCell->font << tempCell->data; |
100 | } | 100 | } |
101 | 101 | ||
102 | lnkDoc->setType("application/sheet-qt"); | 102 | lnkDoc->setType("application/sheet-qt"); |
103 | if (!fm.saveFile(*lnkDoc, streamBuffer)) | 103 | if (!fm.saveFile(*lnkDoc, streamBuffer)) |
104 | { | 104 | { |
105 | QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); | 105 | QMessageBox::critical(this, tr("Error"), tr("File cannot be saved!")); |
106 | return; | 106 | return; |
107 | } | 107 | } |
108 | documentModified=FALSE; | 108 | documentModified=FALSE; |
109 | } | 109 | } |
110 | 110 | ||
111 | void MainWindow::documentOpen(const DocLnk &lnkDoc) | 111 | void MainWindow::documentOpen(const DocLnk &lnkDoc) |
112 | { | 112 | { |
113 | FileManager fm; | 113 | FileManager fm; |
114 | QByteArray streamBuffer; | 114 | QByteArray streamBuffer; |
115 | if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer)) | 115 | if (!lnkDoc.isValid() || !fm.loadFile(lnkDoc, streamBuffer)) |
116 | { | 116 | { |
117 | QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!")); | 117 | QMessageBox::critical(this, tr("Error"), tr("File cannot be opened!")); |
118 | documentModified=FALSE; | 118 | documentModified=FALSE; |
119 | selectorFileNew(DocLnk()); | 119 | selectorFileNew(DocLnk()); |
120 | return; | 120 | return; |
121 | } | 121 | } |
122 | QDataStream stream(streamBuffer, IO_ReadOnly); | 122 | QDataStream stream(streamBuffer, IO_ReadOnly); |
123 | 123 | ||
124 | Q_UINT32 countSheet, countCell, i, j, row, col, alignment; | 124 | Q_UINT32 countSheet, countCell, i, j, row, col, alignment; |
125 | typeSheet *newSheet; | 125 | typeSheet *newSheet; |
126 | typeCellData *newCell; | 126 | typeCellData *newCell; |
127 | 127 | ||
128 | char fileFormat[7]; | 128 | char fileFormat[7]; |
129 | stream.readRawBytes(fileFormat, 6); | 129 | stream.readRawBytes(fileFormat, 6); |
130 | fileFormat[6]=0; | 130 | fileFormat[6]=0; |
131 | if ((QString)fileFormat!="SQT100") | 131 | if ((QString)fileFormat!="SQT100") |
132 | { | 132 | { |
133 | QMessageBox::critical(this, tr("Error"), tr("Invalid file format!")); | 133 | QMessageBox::critical(this, tr("Error"), tr("Invalid file format!")); |
134 | documentModified=FALSE; | 134 | documentModified=FALSE; |
135 | selectorFileNew(DocLnk()); | 135 | selectorFileNew(DocLnk()); |
136 | return; | 136 | return; |
137 | } | 137 | } |
138 | 138 | ||
139 | stream >> countSheet; | 139 | stream >> countSheet; |
140 | for (i=0; i<countSheet; ++i) | 140 | for (i=0; i<countSheet; ++i) |
141 | { | 141 | { |
142 | newSheet=new typeSheet; | 142 | newSheet=new typeSheet; |
143 | newSheet->data.setAutoDelete(TRUE); | 143 | newSheet->data.setAutoDelete(TRUE); |
144 | stream >> newSheet->name >> countCell; | 144 | stream >> newSheet->name >> countCell; |
145 | comboSheets->insertItem(newSheet->name); | 145 | comboSheets->insertItem(newSheet->name); |
146 | 146 | ||
147 | for (j=0; j<countCell; ++j) | 147 | for (j=0; j<countCell; ++j) |
148 | { | 148 | { |
149 | newCell=new typeCellData; | 149 | newCell=new typeCellData; |
150 | stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data; | 150 | stream >> col >> row >> newCell->borders.right >> newCell->borders.bottom >> newCell->background >> alignment >> newCell->fontColor >> newCell->font >> newCell->data; |
151 | newCell->col=col; | 151 | newCell->col=col; |
152 | newCell->row=row; | 152 | newCell->row=row; |
153 | newCell->alignment=(Qt::AlignmentFlags)alignment; | 153 | newCell->alignment=(Qt::AlignmentFlags)alignment; |
154 | newSheet->data.append(newCell); | 154 | newSheet->data.append(newCell); |
155 | } | 155 | } |
156 | listSheets.append(newSheet); | 156 | listSheets.append(newSheet); |
157 | 157 | ||
158 | if (i==0) | 158 | if (i==0) |
159 | { | 159 | { |
160 | sheet->setName(newSheet->name); | 160 | sheet->setName(newSheet->name); |
161 | sheet->setSheetData(&newSheet->data); | 161 | sheet->setSheetData(&newSheet->data); |
162 | } | 162 | } |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | int MainWindow::saveCurrentFile(bool ask) | 166 | int MainWindow::saveCurrentFile(bool ask) |
167 | { | 167 | { |
168 | if (ask) | 168 | if (ask) |
169 | { | 169 | { |
170 | int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); | 170 | int result=QMessageBox::information(this, tr("Save File"), tr("Do you want to save the current file?"), QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel); |
171 | if (result!=QMessageBox::Yes) return result; | 171 | if (result!=QMessageBox::Yes) return result; |
172 | } | 172 | } |
173 | 173 | ||
174 | if (!currentDoc->isValid()) | 174 | if (!currentDoc->isValid()) |
175 | { | 175 | { |
176 | TextDialog dialogText(this); | 176 | TextDialog dialogText(this); |
177 | if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; | 177 | if (dialogText.exec(tr("Save File"), tr("&File Name:"), tr("UnnamedFile"))!=QDialog::Accepted || dialogText.getValue().isEmpty()) return QMessageBox::Cancel; |
178 | 178 | ||
179 | currentDoc->setName(dialogText.getValue()); | 179 | currentDoc->setName(dialogText.getValue()); |
180 | currentDoc->setFile(QString::null); | 180 | currentDoc->setFile(QString::null); |
181 | currentDoc->setLinkFile(QString::null); | 181 | currentDoc->setLinkFile(QString::null); |
182 | } | 182 | } |
183 | 183 | ||
184 | documentSave(currentDoc); | 184 | documentSave(currentDoc); |
185 | return QMessageBox::Yes; | 185 | return QMessageBox::Yes; |
186 | } | 186 | } |
187 | 187 | ||
188 | void MainWindow::selectorFileNew(const DocLnk &lnkDoc) | 188 | void MainWindow::selectorFileNew(const DocLnk &lnkDoc) |
189 | { | 189 | { |
190 | selectorHide(); | 190 | selectorHide(); |
191 | 191 | ||
192 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; | 192 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; |
193 | if (currentDoc) delete currentDoc; | 193 | if (currentDoc) delete currentDoc; |
194 | currentDoc = new DocLnk(lnkDoc); | 194 | currentDoc = new DocLnk(lnkDoc); |
195 | editData->clear(); | 195 | editData->clear(); |
196 | listSheets.clear(); | 196 | listSheets.clear(); |
197 | comboSheets->clear(); | 197 | comboSheets->clear(); |
198 | 198 | ||
199 | typeSheet *newSheet=createNewSheet(); | 199 | typeSheet *newSheet=createNewSheet(); |
200 | newSheet->data.setAutoDelete(TRUE); | 200 | newSheet->data.setAutoDelete(TRUE); |
201 | sheet->setName(newSheet->name); | 201 | sheet->setName(newSheet->name); |
202 | sheet->setSheetData(&newSheet->data); | 202 | sheet->setSheetData(&newSheet->data); |
203 | for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) | 203 | for (int i=1; i<DEFAULT_NUM_SHEETS; ++i) |
204 | createNewSheet(); | 204 | createNewSheet(); |
205 | documentModified=FALSE; | 205 | documentModified=FALSE; |
206 | } | 206 | } |
207 | 207 | ||
208 | void MainWindow::closeEvent(QCloseEvent *e) | 208 | void MainWindow::closeEvent(QCloseEvent *e) |
209 | { | 209 | { |
210 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore(); | 210 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) e->ignore(); |
211 | else e->accept(); | 211 | else e->accept(); |
212 | } | 212 | } |
213 | 213 | ||
214 | void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) | 214 | void MainWindow::selectorFileOpen(const DocLnk &lnkDoc) |
215 | { | 215 | { |
216 | selectorHide(); | 216 | selectorHide(); |
217 | 217 | ||
218 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; | 218 | if (documentModified && saveCurrentFile()==QMessageBox::Cancel) return; |
219 | if (currentDoc) delete currentDoc; | 219 | if (currentDoc) delete currentDoc; |
220 | currentDoc = new DocLnk(lnkDoc); | 220 | currentDoc = new DocLnk(lnkDoc); |
221 | listSheets.clear(); | 221 | listSheets.clear(); |
222 | comboSheets->clear(); | 222 | comboSheets->clear(); |
223 | 223 | ||
224 | documentOpen(lnkDoc); | 224 | documentOpen(lnkDoc); |
225 | documentModified=FALSE; | 225 | documentModified=FALSE; |
226 | } | 226 | } |
227 | 227 | ||
228 | void MainWindow::selectorShow() | 228 | void MainWindow::selectorShow() |
229 | { | 229 | { |
230 | sheet->hide(); | 230 | sheet->hide(); |
231 | setCentralWidget(fileSelector); | 231 | setCentralWidget(fileSelector); |
232 | fileSelector->show(); | 232 | fileSelector->show(); |
233 | fileSelector->reread(); | 233 | fileSelector->reread(); |
234 | } | 234 | } |
235 | 235 | ||
236 | void MainWindow::selectorHide() | 236 | void MainWindow::selectorHide() |
237 | { | 237 | { |
238 | fileSelector->hide(); | 238 | fileSelector->hide(); |
239 | setCentralWidget(sheet); | 239 | setCentralWidget(sheet); |
240 | sheet->show(); | 240 | sheet->show(); |
241 | } | 241 | } |
242 | 242 | ||
243 | void MainWindow::slotFileNew() | 243 | void MainWindow::slotFileNew() |
244 | { | 244 | { |
245 | selectorFileNew(DocLnk()); | 245 | selectorFileNew(DocLnk()); |
246 | } | 246 | } |
247 | 247 | ||
248 | void MainWindow::slotFileOpen() | 248 | void MainWindow::slotFileOpen() |
249 | { | 249 | { |
250 | selectorShow(); | 250 | selectorShow(); |
251 | } | 251 | } |
252 | 252 | ||
253 | void MainWindow::slotFileSave() | 253 | void MainWindow::slotFileSave() |
254 | { | 254 | { |
255 | saveCurrentFile(FALSE); | 255 | saveCurrentFile(FALSE); |
256 | } | 256 | } |
257 | 257 | ||
258 | void MainWindow::setDocument(const QString &applnk_filename) | 258 | void MainWindow::setDocument(const QString &applnk_filename) |
259 | { | 259 | { |
260 | selectorFileOpen(DocLnk(applnk_filename)); | 260 | selectorFileOpen(DocLnk(applnk_filename)); |
261 | } | 261 | } |
262 | 262 | ||
263 | void MainWindow::initActions() | 263 | void MainWindow::initActions() |
264 | { | 264 | { |
265 | fileNew=new QAction(tr("New File"), Resource::loadPixmap( "new" ), tr("&New"), 0, this); | 265 | fileNew=new QAction(tr("New File"), Resource::loadPixmap( "new" ), tr("&New"), 0, this); |
266 | connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew())); | 266 | connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew())); |
267 | fileOpen=new QAction(tr("Open File"), Resource::loadPixmap( "fileopen" ), tr("&Open"), 0, this); | 267 | fileOpen=new QAction(tr("Open File"), Resource::loadPixmap( "fileopen" ), tr("&Open"), 0, this); |
268 | connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen())); | 268 | connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen())); |
269 | fileSave=new QAction(tr("Save File"),Resource::loadPixmap( "save" ), tr("&Save"), 0, this); | 269 | fileSave=new QAction(tr("Save File"),Resource::loadPixmap( "save" ), tr("&Save"), 0, this); |
270 | connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave())); | 270 | connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave())); |
271 | fileSaveAs=new QAction(tr("Save File As"), Resource::loadPixmap( "save" ), tr("Save &As"), 0, this); | 271 | fileSaveAs=new QAction(tr("Save File As"), Resource::loadPixmap( "save" ), tr("Save &As"), 0, this); |
272 | connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs())); | 272 | connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs())); |
273 | //fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this); | 273 | //fileQuit=new QAction(tr("Quit"), tr("&Quit"), 0, this); |
274 | //connect(fileQuit, SIGNAL(activated()), this, SLOT(close())); | 274 | //connect(fileQuit, SIGNAL(activated()), this, SLOT(close())); |
275 | 275 | ||
276 | // helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this); | 276 | // helpGeneral=new QAction(tr("General Help"), QPixmap(help_general_xpm), tr("&General"), 0, this); |
277 | //connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral())); | 277 | //connect(helpGeneral, SIGNAL(activated()), this, SLOT(slotHelpGeneral())); |
278 | //helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this); | 278 | //helpAbout=new QAction(tr("About Opie Sheet"), tr("&About"), 0, this); |
279 | //connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout())); | 279 | //connect(helpAbout, SIGNAL(activated()), this, SLOT(slotHelpAbout())); |
280 | 280 | ||
281 | editAccept=new QAction(tr("Accept"),Resource::loadPixmap( "enter" ) , tr("&Accept"), 0, this); | 281 | editAccept=new QAction(tr("Accept"),Resource::loadPixmap( "enter" ) , tr("&Accept"), 0, this); |
282 | connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept())); | 282 | connect(editAccept, SIGNAL(activated()), this, SLOT(slotEditAccept())); |
283 | editCancel=new QAction(tr("Cancel"), Resource::loadPixmap( "close" ), tr("&Cancel"), 0, this); | 283 | editCancel=new QAction(tr("Cancel"), Resource::loadPixmap( "close" ), tr("&Cancel"), 0, this); |
284 | connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel())); | 284 | connect(editCancel, SIGNAL(activated()), this, SLOT(slotEditCancel())); |
285 | editCellSelect=new QAction(tr("Cell Selector"), QPixmap(cell_select_xpm), tr("Cell &Selector"), 0, this); | 285 | editCellSelect=new QAction(tr("Cell Selector"), QPixmap(cell_select_xpm), tr("Cell &Selector"), 0, this); |
286 | editCellSelect->setToggleAction(TRUE); | 286 | editCellSelect->setToggleAction(TRUE); |
287 | connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool))); | 287 | connect(editCellSelect, SIGNAL(toggled(bool)), this, SLOT(slotCellSelect(bool))); |
288 | editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this); | 288 | editCut=new QAction(tr("Cut Cells"), tr("Cu&t"), 0, this); |
289 | editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this); | 289 | editCopy=new QAction(tr("Copy Cells"), tr("&Copy"), 0, this); |
290 | editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this); | 290 | editPaste=new QAction(tr("Paste Cells"), tr("&Paste"), 0, this); |
291 | connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste())); | 291 | connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste())); |
292 | editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this); | 292 | editPasteContents=new QAction(tr("Paste Contents"), tr("Paste Cont&ents"), 0, this); |
293 | connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents())); | 293 | connect(editPasteContents, SIGNAL(activated()), this, SLOT(slotEditPasteContents())); |
294 | editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this); | 294 | editClear=new QAction(tr("Clear Cells"), tr("C&lear"), 0, this); |
295 | 295 | ||
296 | insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this); | 296 | insertCells=new QAction(tr("Insert Cells"), tr("C&ells"), 0, this); |
297 | connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells())); | 297 | connect(insertCells, SIGNAL(activated()), this, SLOT(slotInsertCells())); |
298 | insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this); | 298 | insertRows=new QAction(tr("Insert Rows"), tr("&Rows"), 0, this); |
299 | connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows())); | 299 | connect(insertRows, SIGNAL(activated()), this, SLOT(slotInsertRows())); |
300 | insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this); | 300 | insertCols=new QAction(tr("Insert Columns"), tr("&Columns"), 0, this); |
301 | connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols())); | 301 | connect(insertCols, SIGNAL(activated()), this, SLOT(slotInsertCols())); |
302 | insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this); | 302 | insertSheets=new QAction(tr("Add Sheets"), tr("&Sheets"), 0, this); |
303 | connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets())); | 303 | connect(insertSheets, SIGNAL(activated()), this, SLOT(slotInsertSheets())); |
304 | 304 | ||
305 | formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this); | 305 | formatCells=new QAction(tr("Cells"), tr("&Cells"), 0, this); |
306 | connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells())); | 306 | connect(formatCells, SIGNAL(activated()), this, SLOT(slotFormatCells())); |
307 | 307 | ||
308 | rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this); | 308 | rowHeight=new QAction(tr("Row Height"), tr("H&eight"), 0, this); |
309 | connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight())); | 309 | connect(rowHeight, SIGNAL(activated()), this, SLOT(slotRowHeight())); |
310 | rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this); | 310 | rowAdjust=new QAction(tr("Adjust Row"), tr("&Adjust"), 0, this); |
311 | connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust())); | 311 | connect(rowAdjust, SIGNAL(activated()), this, SLOT(slotRowAdjust())); |
312 | rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this); | 312 | rowShow=new QAction(tr("Show Row"), tr("&Show"), 0, this); |
313 | connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow())); | 313 | connect(rowShow, SIGNAL(activated()), this, SLOT(slotRowShow())); |
314 | rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this); | 314 | rowHide=new QAction(tr("Hide Row"), tr("&Hide"), 0, this); |
315 | connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide())); | 315 | connect(rowHide, SIGNAL(activated()), this, SLOT(slotRowHide())); |
316 | 316 | ||
317 | colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this); | 317 | colWidth=new QAction(tr("Column Width"), tr("&Width"), 0, this); |
318 | connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth())); | 318 | connect(colWidth, SIGNAL(activated()), this, SLOT(slotColumnWidth())); |
319 | colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this); | 319 | colAdjust=new QAction(tr("Adjust Column"), tr("&Adjust"), 0, this); |
320 | connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust())); | 320 | connect(colAdjust, SIGNAL(activated()), this, SLOT(slotColumnAdjust())); |
321 | colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this); | 321 | colShow=new QAction(tr("Show Column"), tr("&Show"), 0, this); |
322 | connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow())); | 322 | connect(colShow, SIGNAL(activated()), this, SLOT(slotColumnShow())); |
323 | colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this); | 323 | colHide=new QAction(tr("Hide Column"), tr("&Hide"), 0, this); |
324 | connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide())); | 324 | connect(colHide, SIGNAL(activated()), this, SLOT(slotColumnHide())); |
325 | 325 | ||
326 | sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this); | 326 | sheetRename=new QAction(tr("Rename Sheet"), tr("&Rename"), 0, this); |
327 | connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename())); | 327 | connect(sheetRename, SIGNAL(activated()), this, SLOT(slotSheetRename())); |
328 | sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this); | 328 | sheetRemove=new QAction(tr("Remove Sheet"), tr("R&emove"), 0, this); |
329 | connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove())); | 329 | connect(sheetRemove, SIGNAL(activated()), this, SLOT(slotSheetRemove())); |
330 | 330 | ||
331 | dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this); | 331 | dataSort=new QAction(tr("Sort Data"), tr("&Sort"), 0, this); |
332 | connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort())); | 332 | connect(dataSort, SIGNAL(activated()), this, SLOT(slotDataSort())); |
333 | dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this); | 333 | dataFindReplace=new QAction(tr("Find && Replace"), tr("&Find && Replace"), 0, this); |
334 | connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace())); | 334 | connect(dataFindReplace, SIGNAL(activated()), this, SLOT(slotDataFindReplace())); |
335 | 335 | ||
336 | funcEqual=new QAction(tr("Equal To"), QPixmap(func_equal_xpm), tr("&Equal To"), 0, this); | 336 | funcEqual=new QAction(tr("Equal To"), QPixmap(func_equal_xpm), tr("&Equal To"), 0, this); |
337 | funcEqual->setToolTip("="); | 337 | funcEqual->setToolTip("="); |
338 | connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 338 | connect(funcEqual, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
339 | funcPlus=new QAction(tr("Addition"), QPixmap(func_plus_xpm), tr("&Addition"), 0, this); | 339 | funcPlus=new QAction(tr("Addition"), QPixmap(func_plus_xpm), tr("&Addition"), 0, this); |
340 | funcPlus->setToolTip("+"); | 340 | funcPlus->setToolTip("+"); |
341 | connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 341 | connect(funcPlus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
342 | funcMinus=new QAction(tr("Subtraction"), QPixmap(func_minus_xpm), tr("&Subtraction"), 0, this); | 342 | funcMinus=new QAction(tr("Subtraction"), QPixmap(func_minus_xpm), tr("&Subtraction"), 0, this); |
343 | funcMinus->setToolTip("-"); | 343 | funcMinus->setToolTip("-"); |
344 | connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 344 | connect(funcMinus, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
345 | funcCross=new QAction(tr("Multiplication"), QPixmap(func_cross_xpm), tr("&Multiplication"), 0, this); | 345 | funcCross=new QAction(tr("Multiplication"), QPixmap(func_cross_xpm), tr("&Multiplication"), 0, this); |
346 | funcCross->setToolTip("*"); | 346 | funcCross->setToolTip("*"); |
347 | connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 347 | connect(funcCross, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
348 | funcDivide=new QAction(tr("Division"), QPixmap(func_divide_xpm), tr("&Division"), 0, this); | 348 | funcDivide=new QAction(tr("Division"), QPixmap(func_divide_xpm), tr("&Division"), 0, this); |
349 | funcDivide->setToolTip("/"); | 349 | funcDivide->setToolTip("/"); |
350 | connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 350 | connect(funcDivide, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
351 | funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"), QPixmap(func_paran_open_xpm), tr("&Open Paranthesis"), 0, this); | 351 | funcParanOpen=new QAction(tr("Open ParanthesistempCellData->row+row1, tempCellData->col+col1"), QPixmap(func_paran_open_xpm), tr("&Open Paranthesis"), 0, this); |
352 | funcParanOpen->setToolTip("("); | 352 | funcParanOpen->setToolTip("("); |
353 | connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 353 | connect(funcParanOpen, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
354 | funcParanClose=new QAction(tr("Close Paranthesis"), QPixmap(func_paran_close_xpm), tr("&Close Paranthesis"), 0, this); | 354 | funcParanClose=new QAction(tr("Close Paranthesis"), QPixmap(func_paran_close_xpm), tr("&Close Paranthesis"), 0, this); |
355 | funcParanClose->setToolTip(")"); | 355 | funcParanClose->setToolTip(")"); |
356 | connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 356 | connect(funcParanClose, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
357 | funcComma=new QAction(tr("Comma"), QPixmap(func_comma_xpm), tr("&Comma"), 0, this); | 357 | funcComma=new QAction(tr("Comma"), QPixmap(func_comma_xpm), tr("&Comma"), 0, this); |
358 | funcComma->setToolTip(","); | 358 | funcComma->setToolTip(","); |
359 | connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 359 | connect(funcComma, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
360 | } | 360 | } |
361 | 361 | ||
362 | void MainWindow::initMenu() | 362 | void MainWindow::initMenu() |
363 | { | 363 | { |
364 | menu=new QMenuBar(this); | 364 | menu=new QMenuBar(this); |
365 | 365 | ||
366 | menuFile=new QPopupMenu; | 366 | menuFile=new QPopupMenu; |
367 | fileNew->addTo(menuFile); | 367 | fileNew->addTo(menuFile); |
368 | fileOpen->addTo(menuFile); | 368 | fileOpen->addTo(menuFile); |
369 | fileSave->addTo(menuFile); | 369 | fileSave->addTo(menuFile); |
370 | fileSaveAs->addTo(menuFile); | 370 | fileSaveAs->addTo(menuFile); |
371 | // menuFile->insertSeparator(); | 371 | // menuFile->insertSeparator(); |
372 | // fileQuit->addTo(menuFile); | 372 | // fileQuit->addTo(menuFile); |
373 | menu->insertItem(tr("&File"), menuFile); | 373 | menu->insertItem(tr("&File"), menuFile); |
374 | 374 | ||
375 | menuEdit=new QPopupMenu; | 375 | menuEdit=new QPopupMenu; |
376 | editAccept->addTo(menuEdit); | 376 | editAccept->addTo(menuEdit); |
377 | editCancel->addTo(menuEdit); | 377 | editCancel->addTo(menuEdit); |
378 | editCellSelect->addTo(menuEdit); | 378 | editCellSelect->addTo(menuEdit); |
379 | menuEdit->insertSeparator(); | 379 | menuEdit->insertSeparator(); |
380 | editCut->addTo(menuEdit); | 380 | editCut->addTo(menuEdit); |
381 | editCopy->addTo(menuEdit); | 381 | editCopy->addTo(menuEdit); |
382 | editPaste->addTo(menuEdit); | 382 | editPaste->addTo(menuEdit); |
383 | editPasteContents->addTo(menuEdit); | 383 | editPasteContents->addTo(menuEdit); |
384 | editClear->addTo(menuEdit); | 384 | editClear->addTo(menuEdit); |
385 | menu->insertItem(tr("&Edit"), menuEdit); | 385 | menu->insertItem(tr("&Edit"), menuEdit); |
386 | 386 | ||
387 | menuInsert=new QPopupMenu; | 387 | menuInsert=new QPopupMenu; |
388 | menu->insertItem(tr("&Insert"), menuInsert); | 388 | menu->insertItem(tr("&Insert"), menuInsert); |
389 | 389 | ||
390 | menuFormat=new QPopupMenu; | 390 | menuFormat=new QPopupMenu; |
391 | formatCells->addTo(menuFormat); | 391 | formatCells->addTo(menuFormat); |
392 | menu->insertItem(tr("&Format"), menuFormat); | 392 | menu->insertItem(tr("&Format"), menuFormat); |
393 | 393 | ||
394 | menuData=new QPopupMenu; | 394 | menuData=new QPopupMenu; |
395 | dataSort->addTo(menuData); | 395 | dataSort->addTo(menuData); |
396 | dataFindReplace->addTo(menuData); | 396 | dataFindReplace->addTo(menuData); |
397 | menu->insertItem(tr("&Data"), menuData); | 397 | menu->insertItem(tr("&Data"), menuData); |
398 | 398 | ||
399 | // menuHelp=new QPopupMenu; | 399 | // menuHelp=new QPopupMenu; |
400 | // helpGeneral->addTo(menuHelp); | 400 | // helpGeneral->addTo(menuHelp); |
401 | // helpAbout->addTo(menuHelp); | 401 | // helpAbout->addTo(menuHelp); |
402 | // menu->insertItem(tr("&Help"), menuHelp); | 402 | // menu->insertItem(tr("&Help"), menuHelp); |
403 | 403 | ||
404 | submenuRow=new QPopupMenu; | 404 | submenuRow=new QPopupMenu; |
405 | rowHeight->addTo(submenuRow); | 405 | rowHeight->addTo(submenuRow); |
406 | rowAdjust->addTo(submenuRow); | 406 | rowAdjust->addTo(submenuRow); |
407 | rowShow->addTo(submenuRow); | 407 | rowShow->addTo(submenuRow); |
408 | rowHide->addTo(submenuRow); | 408 | rowHide->addTo(submenuRow); |
409 | menuFormat->insertItem(tr("&Row"), submenuRow); | 409 | menuFormat->insertItem(tr("&Row"), submenuRow); |
410 | 410 | ||
411 | submenuCol=new QPopupMenu; | 411 | submenuCol=new QPopupMenu; |
412 | colWidth->addTo(submenuCol); | 412 | colWidth->addTo(submenuCol); |
413 | colAdjust->addTo(submenuCol); | 413 | colAdjust->addTo(submenuCol); |
414 | colShow->addTo(submenuCol); | 414 | colShow->addTo(submenuCol); |
415 | colHide->addTo(submenuCol); | 415 | colHide->addTo(submenuCol); |
416 | menuFormat->insertItem(tr("Colum&n"), submenuCol); | 416 | menuFormat->insertItem(tr("Colum&n"), submenuCol); |
417 | 417 | ||
418 | submenuSheet=new QPopupMenu; | 418 | submenuSheet=new QPopupMenu; |
419 | sheetRename->addTo(submenuSheet); | 419 | sheetRename->addTo(submenuSheet); |
420 | sheetRemove->addTo(submenuSheet); | 420 | sheetRemove->addTo(submenuSheet); |
421 | menuFormat->insertItem(tr("&Sheet"), submenuSheet); | 421 | menuFormat->insertItem(tr("&Sheet"), submenuSheet); |
422 | 422 | ||
423 | submenuFunc=new QPopupMenu; | 423 | submenuFunc=new QPopupMenu; |
424 | menuInsert->insertItem(tr("&Function"), submenuFunc); | 424 | menuInsert->insertItem(tr("&Function"), submenuFunc); |
425 | 425 | ||
426 | submenuFuncStd=new QPopupMenu; | 426 | submenuFuncStd=new QPopupMenu; |
427 | funcPlus->addTo(submenuFuncStd); | 427 | funcPlus->addTo(submenuFuncStd); |
428 | funcMinus->addTo(submenuFuncStd); | 428 | funcMinus->addTo(submenuFuncStd); |
429 | funcCross->addTo(submenuFuncStd); | 429 | funcCross->addTo(submenuFuncStd); |
430 | funcDivide->addTo(submenuFuncStd); | 430 | funcDivide->addTo(submenuFuncStd); |
431 | submenuFunc->insertItem(tr("&Standard"), submenuFuncStd); | 431 | submenuFunc->insertItem(tr("&Standard"), submenuFuncStd); |
432 | 432 | ||
433 | submenuFuncMath=new QPopupMenu; | 433 | submenuFuncMath=new QPopupMenu; |
434 | addFlyAction(tr("Summation"), tr("&Summation"), "SUM(", submenuFuncMath); | 434 | addFlyAction(tr("Summation"), tr("&Summation"), "SUM(", submenuFuncMath); |
435 | addFlyAction(tr("Absolute Value"), tr("&Absolute"), "ABS(", submenuFuncMath); | 435 | addFlyAction(tr("Absolute Value"), tr("&Absolute"), "ABS(", submenuFuncMath); |
436 | submenuFuncMath->insertSeparator(); | 436 | submenuFuncMath->insertSeparator(); |
437 | addFlyAction(tr("Sine"), tr("Si&ne"), "SIN(", submenuFuncMath); | 437 | addFlyAction(tr("Sine"), tr("Si&ne"), "SIN(", submenuFuncMath); |
438 | addFlyAction(tr("Arc Sine"), tr("A&rc Sine"), "ASIN(", submenuFuncMath); | 438 | addFlyAction(tr("Arc Sine"), tr("A&rc Sine"), "ASIN(", submenuFuncMath); |
439 | addFlyAction(tr("Cosine"), tr("&Cosine"), "COS(", submenuFuncMath); | 439 | addFlyAction(tr("Cosine"), tr("&Cosine"), "COS(", submenuFuncMath); |
440 | addFlyAction(tr("ArcCosine"), tr("Arc Cos&ine"), "COS(", submenuFuncMath); | 440 | addFlyAction(tr("ArcCosine"), tr("Arc Cos&ine"), "COS(", submenuFuncMath); |
441 | addFlyAction(tr("Tangent"), tr("&Tangent"), "TAN(", submenuFuncMath); | 441 | addFlyAction(tr("Tangent"), tr("&Tangent"), "TAN(", submenuFuncMath); |
442 | addFlyAction(tr("Arc Tangent"), tr("Arc Tan&gent"), "ATAN(", submenuFuncMath); | 442 | addFlyAction(tr("Arc Tangent"), tr("Arc Tan&gent"), "ATAN(", submenuFuncMath); |
443 | addFlyAction(tr("Arc Tangent of Coordinates"), tr("C&oor. Arc Tangent"), "ATAN2(", submenuFuncMath); | 443 | addFlyAction(tr("Arc Tangent of Coordinates"), tr("C&oor. Arc Tangent"), "ATAN2(", submenuFuncMath); |
444 | submenuFuncMath->insertSeparator(); | 444 | submenuFuncMath->insertSeparator(); |
445 | addFlyAction(tr("Exponential"), tr("&Exponential"), "EXP(", submenuFuncMath); | 445 | addFlyAction(tr("Exponential"), tr("&Exponential"), "EXP(", submenuFuncMath); |
446 | addFlyAction(tr("Logarithm"), tr("&Logarithm"), "LOG(", submenuFuncMath); | 446 | addFlyAction(tr("Logarithm"), tr("&Logarithm"), "LOG(", submenuFuncMath); |
447 | addFlyAction(tr("Power"), tr("&Power"), "POW(", submenuFuncMath); | 447 | addFlyAction(tr("Power"), tr("&Power"), "POW(", submenuFuncMath); |
448 | submenuFunc->insertItem(tr("&Mathematical"), submenuFuncMath); | 448 | submenuFunc->insertItem(tr("&Mathematical"), submenuFuncMath); |
449 | 449 | ||
450 | submenuFuncStat=new QPopupMenu; | 450 | submenuFuncStat=new QPopupMenu; |
451 | addFlyAction(tr("Average"), tr("&Average"), "AVG(", submenuFuncStat); | 451 | addFlyAction(tr("Average"), tr("&Average"), "AVG(", submenuFuncStat); |
452 | addFlyAction(tr("Maximum"), tr("Ma&ximum"), "MAX(", submenuFuncStat); | 452 | addFlyAction(tr("Maximum"), tr("Ma&ximum"), "MAX(", submenuFuncStat); |
453 | addFlyAction(tr("Minimum"), tr("&Minimum"), "MIN(", submenuFuncStat); | 453 | addFlyAction(tr("Minimum"), tr("&Minimum"), "MIN(", submenuFuncStat); |
454 | addFlyAction(tr("Count"), tr("&Count"), "COUNT(", submenuFuncStat); | 454 | addFlyAction(tr("Count"), tr("&Count"), "COUNT(", submenuFuncStat); |
455 | submenuFunc->insertItem(tr("&Statistical"), submenuFuncStat); | 455 | submenuFunc->insertItem(tr("&Statistical"), submenuFuncStat); |
456 | 456 | ||
457 | menuInsert->insertSeparator(); | 457 | menuInsert->insertSeparator(); |
458 | insertCells->addTo(menuInsert); | 458 | insertCells->addTo(menuInsert); |
459 | insertRows->addTo(menuInsert); | 459 | insertRows->addTo(menuInsert); |
460 | insertCols->addTo(menuInsert); | 460 | insertCols->addTo(menuInsert); |
461 | insertSheets->addTo(menuInsert); | 461 | insertSheets->addTo(menuInsert); |
462 | } | 462 | } |
463 | 463 | ||
464 | void MainWindow::initStandardToolbar() | 464 | void MainWindow::initStandardToolbar() |
465 | { | 465 | { |
466 | toolbarStandard=new QPEToolBar(this); | 466 | toolbarStandard=new QToolBar(this); |
467 | toolbarStandard->setHorizontalStretchable(TRUE); | 467 | toolbarStandard->setHorizontalStretchable(TRUE); |
468 | moveToolBar(toolbarStandard, Top); | 468 | moveToolBar(toolbarStandard, Top); |
469 | 469 | ||
470 | fileNew->addTo(toolbarStandard); | 470 | fileNew->addTo(toolbarStandard); |
471 | fileOpen->addTo(toolbarStandard); | 471 | fileOpen->addTo(toolbarStandard); |
472 | fileSave->addTo(toolbarStandard); | 472 | fileSave->addTo(toolbarStandard); |
473 | 473 | ||
474 | comboSheets=new QComboBox(toolbarStandard); | 474 | comboSheets=new QComboBox(toolbarStandard); |
475 | toolbarStandard->setStretchableWidget(comboSheets); | 475 | toolbarStandard->setStretchableWidget(comboSheets); |
476 | connect(comboSheets, SIGNAL(activated(const QString &)), this, SLOT(slotSheetChanged(const QString &))); | 476 | connect(comboSheets, SIGNAL(activated(const QString &)), this, SLOT(slotSheetChanged(const QString &))); |
477 | } | 477 | } |
478 | 478 | ||
479 | void MainWindow::initFunctionsToolbar() | 479 | void MainWindow::initFunctionsToolbar() |
480 | { | 480 | { |
481 | toolbarFunctions=new QPEToolBar(this); | 481 | toolbarFunctions=new QToolBar(this); |
482 | toolbarFunctions->setHorizontalStretchable(TRUE); | 482 | toolbarFunctions->setHorizontalStretchable(TRUE); |
483 | moveToolBar(toolbarFunctions, Bottom); | 483 | moveToolBar(toolbarFunctions, Bottom); |
484 | 484 | ||
485 | funcEqual->addTo(toolbarFunctions); | 485 | funcEqual->addTo(toolbarFunctions); |
486 | funcPlus->addTo(toolbarFunctions); | 486 | funcPlus->addTo(toolbarFunctions); |
487 | funcMinus->addTo(toolbarFunctions); | 487 | funcMinus->addTo(toolbarFunctions); |
488 | funcCross->addTo(toolbarFunctions); | 488 | funcCross->addTo(toolbarFunctions); |
489 | funcDivide->addTo(toolbarFunctions); | 489 | funcDivide->addTo(toolbarFunctions); |
490 | funcParanOpen->addTo(toolbarFunctions); | 490 | funcParanOpen->addTo(toolbarFunctions); |
491 | funcParanClose->addTo(toolbarFunctions); | 491 | funcParanClose->addTo(toolbarFunctions); |
492 | funcComma->addTo(toolbarFunctions); | 492 | funcComma->addTo(toolbarFunctions); |
493 | 493 | ||
494 | toolFunction=new QToolButton(toolbarFunctions); | 494 | toolFunction=new QToolButton(toolbarFunctions); |
495 | toolFunction->setPixmap(func_func_xpm); | 495 | toolFunction->setPixmap(func_func_xpm); |
496 | toolFunction->setTextLabel(tr("Functions")); | 496 | toolFunction->setTextLabel(tr("Functions")); |
497 | toolFunction->setPopup(submenuFunc); | 497 | toolFunction->setPopup(submenuFunc); |
498 | toolFunction->setPopupDelay(0); | 498 | toolFunction->setPopupDelay(0); |
499 | } | 499 | } |
500 | 500 | ||
501 | void MainWindow::initEditToolbar() | 501 | void MainWindow::initEditToolbar() |
502 | { | 502 | { |
503 | toolbarEdit=new QPEToolBar(this); | 503 | toolbarEdit=new QToolBar(this); |
504 | toolbarEdit->setHorizontalStretchable(TRUE); | 504 | toolbarEdit->setHorizontalStretchable(TRUE); |
505 | moveToolBar(toolbarEdit, Bottom); | 505 | moveToolBar(toolbarEdit, Bottom); |
506 | 506 | ||
507 | editAccept->addTo(toolbarEdit); | 507 | editAccept->addTo(toolbarEdit); |
508 | editCancel->addTo(toolbarEdit); | 508 | editCancel->addTo(toolbarEdit); |
509 | 509 | ||
510 | editData=new QLineEdit(toolbarEdit); | 510 | editData=new QLineEdit(toolbarEdit); |
511 | toolbarEdit->setStretchableWidget(editData); | 511 | toolbarEdit->setStretchableWidget(editData); |
512 | connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept())); | 512 | connect(editData, SIGNAL(returnPressed()), this, SLOT(slotEditAccept())); |
513 | 513 | ||
514 | editCellSelect->addTo(toolbarEdit); | 514 | editCellSelect->addTo(toolbarEdit); |
515 | } | 515 | } |
516 | 516 | ||
517 | void MainWindow::slotHelpAbout() | 517 | void MainWindow::slotHelpAbout() |
518 | { | 518 | { |
519 | QDialog dialogAbout(this, 0, TRUE); | 519 | QDialog dialogAbout(this, 0, TRUE); |
520 | dialogAbout.resize(width()-40, height()-80); | 520 | dialogAbout.resize(width()-40, height()-80); |
521 | dialogAbout.setCaption(tr("About Opie Sheet")); | 521 | dialogAbout.setCaption(tr("About Opie Sheet")); |
522 | 522 | ||
523 | QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nRelease 1.0.2\nRelease Date: October 08, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout); | 523 | QLabel label(tr("Opie Sheet\nSpreadsheet Software for Opie\nQWDC Beta Winner (as Sheet/Qt)\n\nDeveloped by: Serdar Ozler\nRelease 1.0.2\nRelease Date: October 08, 2002\n\nThis product is licensed under GPL. It is freely distributable. If you want to get the latest version and also the source code, please visit the web site.\n\nhttp://qtopia.sitebest.com"), &dialogAbout); |
524 | label.setGeometry(dialogAbout.rect()); | 524 | label.setGeometry(dialogAbout.rect()); |
525 | label.setAlignment(Qt::AlignCenter | Qt::WordBreak); | 525 | label.setAlignment(Qt::AlignCenter | Qt::WordBreak); |
526 | 526 | ||
527 | dialogAbout.exec(); | 527 | dialogAbout.exec(); |
528 | } | 528 | } |
529 | 529 | ||
530 | void MainWindow::initSheet() | 530 | void MainWindow::initSheet() |
531 | { | 531 | { |
532 | sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this); | 532 | sheet=new Sheet(DEFAULT_NUM_ROWS, DEFAULT_NUM_COLS, this); |
533 | setCentralWidget(sheet); | 533 | setCentralWidget(sheet); |
534 | 534 | ||
535 | connect(sheet, SIGNAL(currentDataChanged(const QString &)), editData, SLOT(setText(const QString &))); | 535 | connect(sheet, SIGNAL(currentDataChanged(const QString &)), editData, SLOT(setText(const QString &))); |
536 | connect(sheet, SIGNAL(cellClicked(const QString &)), this, SLOT(slotCellClicked(const QString &))); | 536 | connect(sheet, SIGNAL(cellClicked(const QString &)), this, SLOT(slotCellClicked(const QString &))); |
537 | connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified())); | 537 | connect(sheet, SIGNAL(sheetModified()), this, SLOT(slotDocModified())); |
538 | 538 | ||
539 | connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut())); | 539 | connect(editCut, SIGNAL(activated()), sheet, SLOT(editCut())); |
540 | connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy())); | 540 | connect(editCopy, SIGNAL(activated()), sheet, SLOT(editCopy())); |
541 | connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear())); | 541 | connect(editClear, SIGNAL(activated()), sheet, SLOT(editClear())); |
542 | } | 542 | } |
543 | 543 | ||
544 | void MainWindow::slotEditAccept() | 544 | void MainWindow::slotEditAccept() |
545 | { | 545 | { |
546 | sheet->setData(editData->text()); | 546 | sheet->setData(editData->text()); |
547 | } | 547 | } |
548 | 548 | ||
549 | void MainWindow::slotEditCancel() | 549 | void MainWindow::slotEditCancel() |
550 | { | 550 | { |
551 | editData->setText(sheet->getData()); | 551 | editData->setText(sheet->getData()); |
552 | } | 552 | } |
553 | 553 | ||
554 | void MainWindow::slotCellSelect(bool lock) | 554 | void MainWindow::slotCellSelect(bool lock) |
555 | { | 555 | { |
556 | sheet->lockClicks(lock); | 556 | sheet->lockClicks(lock); |
557 | } | 557 | } |
558 | 558 | ||
559 | void MainWindow::addToData(const QString &data) | 559 | void MainWindow::addToData(const QString &data) |
560 | { | 560 | { |
561 | editData->setText(editData->text().insert(editData->cursorPosition(), data)); | 561 | editData->setText(editData->text().insert(editData->cursorPosition(), data)); |
562 | } | 562 | } |
563 | 563 | ||
564 | void MainWindow::slotFuncOutput() | 564 | void MainWindow::slotFuncOutput() |
565 | { | 565 | { |
566 | if (sender()->isA("QAction")) | 566 | if (sender()->isA("QAction")) |
567 | addToData(((QAction *)sender())->toolTip()); | 567 | addToData(((QAction *)sender())->toolTip()); |
568 | } | 568 | } |
569 | 569 | ||
570 | void MainWindow::slotInsertRows() | 570 | void MainWindow::slotInsertRows() |
571 | { | 571 | { |
572 | NumberDialog dialogNumber(this); | 572 | NumberDialog dialogNumber(this); |
573 | if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted) | 573 | if (dialogNumber.exec(tr("Insert Rows"), tr("&Number of rows:"))==QDialog::Accepted) |
574 | sheet->insertRows(dialogNumber.getValue()); | 574 | sheet->insertRows(dialogNumber.getValue()); |
575 | } | 575 | } |
576 | 576 | ||
577 | void MainWindow::slotInsertCols() | 577 | void MainWindow::slotInsertCols() |
578 | { | 578 | { |
579 | NumberDialog dialogNumber(this); | 579 | NumberDialog dialogNumber(this); |
580 | if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted) | 580 | if (dialogNumber.exec(tr("Insert Columns"), tr("&Number of columns:"))==QDialog::Accepted) |
581 | sheet->insertColumns(dialogNumber.getValue()); | 581 | sheet->insertColumns(dialogNumber.getValue()); |
582 | } | 582 | } |
583 | 583 | ||
584 | void MainWindow::slotInsertSheets() | 584 | void MainWindow::slotInsertSheets() |
585 | { | 585 | { |
586 | NumberDialog dialogNumber(this); | 586 | NumberDialog dialogNumber(this); |
587 | if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted) | 587 | if (dialogNumber.exec(tr("Add Sheets"), tr("&Number of sheets:"))==QDialog::Accepted) |
588 | for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet(); | 588 | for (int i=dialogNumber.getValue(); i>0; --i) createNewSheet(); |
589 | } | 589 | } |
590 | 590 | ||
591 | void MainWindow::slotCellClicked(const QString &cell) | 591 | void MainWindow::slotCellClicked(const QString &cell) |
592 | { | 592 | { |
593 | editCellSelect->setOn(FALSE); | 593 | editCellSelect->setOn(FALSE); |
594 | addToData(cell); | 594 | addToData(cell); |
595 | } | 595 | } |
596 | 596 | ||
597 | typeSheet *MainWindow::createNewSheet() | 597 | typeSheet *MainWindow::createNewSheet() |
598 | { | 598 | { |
599 | typeSheet *newSheet=new typeSheet; | 599 | typeSheet *newSheet=new typeSheet; |
600 | int currentNo=1, tempNo; | 600 | int currentNo=1, tempNo; |
601 | bool ok; | 601 | bool ok; |
602 | 602 | ||
603 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) | 603 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) |
604 | if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok) | 604 | if (tempSheet->name.startsWith(tr("Sheet")) && (tempNo=tempSheet->name.mid(tr("Sheet").length()).toInt(&ok))>=currentNo && ok) |
605 | currentNo=tempNo+1; | 605 | currentNo=tempNo+1; |
606 | 606 | ||
607 | newSheet->name=tr("Sheet")+QString::number(currentNo); | 607 | newSheet->name=tr("Sheet")+QString::number(currentNo); |
608 | newSheet->data.setAutoDelete(TRUE); | 608 | newSheet->data.setAutoDelete(TRUE); |
609 | 609 | ||
610 | comboSheets->insertItem(newSheet->name); | 610 | comboSheets->insertItem(newSheet->name); |
611 | listSheets.append(newSheet); | 611 | listSheets.append(newSheet); |
612 | return newSheet; | 612 | return newSheet; |
613 | } | 613 | } |
614 | 614 | ||
615 | typeSheet *MainWindow::findSheet(const QString &name) | 615 | typeSheet *MainWindow::findSheet(const QString &name) |
616 | { | 616 | { |
617 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) | 617 | for (typeSheet *tempSheet=listSheets.first(); tempSheet; tempSheet=listSheets.next()) |
618 | if (tempSheet->name==name) | 618 | if (tempSheet->name==name) |
619 | return tempSheet; | 619 | return tempSheet; |
620 | return NULL; | 620 | return NULL; |
621 | } | 621 | } |
622 | 622 | ||
623 | void MainWindow::slotSheetChanged(const QString &name) | 623 | void MainWindow::slotSheetChanged(const QString &name) |
624 | { | 624 | { |
625 | sheet->copySheetData(&findSheet(sheet->getName())->data); | 625 | sheet->copySheetData(&findSheet(sheet->getName())->data); |
626 | sheet->setName(name); | 626 | sheet->setName(name); |
627 | sheet->setSheetData(&findSheet(name)->data); | 627 | sheet->setSheetData(&findSheet(name)->data); |
628 | } | 628 | } |
629 | 629 | ||
630 | void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w) | 630 | void MainWindow::addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w) |
631 | { | 631 | { |
632 | QAction *action=new QAction(text, menuText, 0, this); | 632 | QAction *action=new QAction(text, menuText, 0, this); |
633 | action->setToolTip(tip); | 633 | action->setToolTip(tip); |
634 | connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput())); | 634 | connect(action, SIGNAL(activated()), this, SLOT(slotFuncOutput())); |
635 | action->addTo(w); | 635 | action->addTo(w); |
636 | } | 636 | } |
637 | 637 | ||
638 | void MainWindow::slotFormatCells() | 638 | void MainWindow::slotFormatCells() |
639 | { | 639 | { |
640 | CellFormat dialogCellFormat(this); | 640 | CellFormat dialogCellFormat(this); |
641 | dialogCellFormat.showMaximized(); | 641 | dialogCellFormat.showMaximized(); |
642 | dialogCellFormat.exec(sheet); | 642 | dialogCellFormat.exec(sheet); |
643 | } | 643 | } |
644 | 644 | ||
645 | void MainWindow::slotEditPaste() | 645 | void MainWindow::slotEditPaste() |
646 | { | 646 | { |
647 | sheet->editPaste(); | 647 | sheet->editPaste(); |
648 | } | 648 | } |
649 | 649 | ||
650 | void MainWindow::slotEditPasteContents() | 650 | void MainWindow::slotEditPasteContents() |
651 | { | 651 | { |
652 | sheet->editPaste(TRUE); | 652 | sheet->editPaste(TRUE); |
653 | } | 653 | } |
654 | 654 | ||
655 | void MainWindow::slotRowHeight() | 655 | void MainWindow::slotRowHeight() |
656 | { | 656 | { |
657 | int row1, row2, col1, col2; | 657 | int row1, row2, col1, col2; |
658 | sheet->getSelection(&row1, &col1, &row2, &col2); | 658 | sheet->getSelection(&row1, &col1, &row2, &col2); |
659 | 659 | ||
660 | NumberDialog dialogNumber(this); | 660 | NumberDialog dialogNumber(this); |
661 | if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted) | 661 | if (dialogNumber.exec(tr("Row Height"), tr("&Height of each row:"), sheet->rowHeight(row1))==QDialog::Accepted) |
662 | { | 662 | { |
663 | int newHeight=dialogNumber.getValue(), row; | 663 | int newHeight=dialogNumber.getValue(), row; |
664 | for (row=row1; row<=row2; ++row) | 664 | for (row=row1; row<=row2; ++row) |
665 | sheet->setRowHeight(row, newHeight); | 665 | sheet->setRowHeight(row, newHeight); |
666 | } | 666 | } |
667 | } | 667 | } |
668 | 668 | ||
669 | void MainWindow::slotRowAdjust() | 669 | void MainWindow::slotRowAdjust() |
670 | { | 670 | { |
671 | int row1, row2, col1, col2; | 671 | int row1, row2, col1, col2; |
672 | sheet->getSelection(&row1, &col1, &row2, &col2); | 672 | sheet->getSelection(&row1, &col1, &row2, &col2); |
673 | 673 | ||
674 | for (int row=row1; row<=row2; ++row) | 674 | for (int row=row1; row<=row2; ++row) |
675 | sheet->adjustRow(row); | 675 | sheet->adjustRow(row); |
676 | } | 676 | } |
677 | 677 | ||
678 | void MainWindow::slotRowShow() | 678 | void MainWindow::slotRowShow() |
679 | { | 679 | { |
680 | int row1, row2, col1, col2; | 680 | int row1, row2, col1, col2; |
681 | sheet->getSelection(&row1, &col1, &row2, &col2); | 681 | sheet->getSelection(&row1, &col1, &row2, &col2); |
682 | 682 | ||
683 | for (int row=row1; row<=row2; ++row) | 683 | for (int row=row1; row<=row2; ++row) |
684 | sheet->showRow(row); | 684 | sheet->showRow(row); |
685 | } | 685 | } |
686 | 686 | ||
687 | void MainWindow::slotRowHide() | 687 | void MainWindow::slotRowHide() |
688 | { | 688 | { |
689 | int row1, row2, col1, col2; | 689 | int row1, row2, col1, col2; |
690 | sheet->getSelection(&row1, &col1, &row2, &col2); | 690 | sheet->getSelection(&row1, &col1, &row2, &col2); |
691 | 691 | ||
692 | for (int row=row1; row<=row2; ++row) | 692 | for (int row=row1; row<=row2; ++row) |
693 | sheet->hideRow(row); | 693 | sheet->hideRow(row); |
694 | } | 694 | } |
695 | 695 | ||
696 | void MainWindow::slotColumnWidth() | 696 | void MainWindow::slotColumnWidth() |
697 | { | 697 | { |
698 | int row1, row2, col1, col2; | 698 | int row1, row2, col1, col2; |
699 | sheet->getSelection(&row1, &col1, &row2, &col2); | 699 | sheet->getSelection(&row1, &col1, &row2, &col2); |
700 | 700 | ||
701 | NumberDialog dialogNumber(this); | 701 | NumberDialog dialogNumber(this); |
702 | if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted) | 702 | if (dialogNumber.exec(tr("Column Width"), tr("&Width of each column:"), sheet->columnWidth(col1))==QDialog::Accepted) |
703 | { | 703 | { |
704 | int newWidth=dialogNumber.getValue(), col; | 704 | int newWidth=dialogNumber.getValue(), col; |
705 | for (col=col1; col<=col2; ++col) | 705 | for (col=col1; col<=col2; ++col) |
706 | sheet->setColumnWidth(col, newWidth); | 706 | sheet->setColumnWidth(col, newWidth); |
707 | } | 707 | } |
708 | } | 708 | } |
709 | 709 | ||
710 | void MainWindow::slotColumnAdjust() | 710 | void MainWindow::slotColumnAdjust() |
711 | { | 711 | { |
712 | int row1, row2, col1, col2; | 712 | int row1, row2, col1, col2; |
713 | sheet->getSelection(&row1, &col1, &row2, &col2); | 713 | sheet->getSelection(&row1, &col1, &row2, &col2); |
714 | 714 | ||
715 | for (int col=col1; col<=col2; ++col) | 715 | for (int col=col1; col<=col2; ++col) |
716 | sheet->adjustColumn(col); | 716 | sheet->adjustColumn(col); |
717 | } | 717 | } |
718 | 718 | ||
719 | void MainWindow::slotColumnShow() | 719 | void MainWindow::slotColumnShow() |
720 | { | 720 | { |
721 | int row1, row2, col1, col2; | 721 | int row1, row2, col1, col2; |
722 | sheet->getSelection(&row1, &col1, &row2, &col2); | 722 | sheet->getSelection(&row1, &col1, &row2, &col2); |
723 | 723 | ||
724 | for (int col=col1; col<=col2; ++col) | 724 | for (int col=col1; col<=col2; ++col) |
725 | sheet->showColumn(col); | 725 | sheet->showColumn(col); |
726 | } | 726 | } |
727 | 727 | ||
728 | void MainWindow::slotColumnHide() | 728 | void MainWindow::slotColumnHide() |
729 | { | 729 | { |
730 | int row1, row2, col1, col2; | 730 | int row1, row2, col1, col2; |
731 | sheet->getSelection(&row1, &col1, &row2, &col2); | 731 | sheet->getSelection(&row1, &col1, &row2, &col2); |
732 | 732 | ||
733 | for (int col=col1; col<=col2; ++col) | 733 | for (int col=col1; col<=col2; ++col) |
734 | sheet->hideColumn(col); | 734 | sheet->hideColumn(col); |
735 | } | 735 | } |
736 | 736 | ||
737 | void MainWindow::slotFileSaveAs() | 737 | void MainWindow::slotFileSaveAs() |
738 | { | 738 | { |
739 | TextDialog dialogText(this); | 739 | TextDialog dialogText(this); |
740 | if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; | 740 | if (dialogText.exec(tr("Save File As"), tr("&File Name:"), currentDoc->name())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; |
741 | 741 | ||
742 | currentDoc->setName(dialogText.getValue()); | 742 | currentDoc->setName(dialogText.getValue()); |
743 | currentDoc->setFile(QString::null); | 743 | currentDoc->setFile(QString::null); |
744 | currentDoc->setLinkFile(QString::null); | 744 | currentDoc->setLinkFile(QString::null); |
745 | documentSave(currentDoc); | 745 | documentSave(currentDoc); |
746 | } | 746 | } |
747 | 747 | ||
748 | void MainWindow::slotSheetRename() | 748 | void MainWindow::slotSheetRename() |
749 | { | 749 | { |
750 | TextDialog dialogText(this); | 750 | TextDialog dialogText(this); |
751 | if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; | 751 | if (dialogText.exec(tr("Rename Sheet"), tr("&Sheet Name:"), sheet->getName())!=QDialog::Accepted || dialogText.getValue().isEmpty()) return; |
752 | QString newName=dialogText.getValue(); | 752 | QString newName=dialogText.getValue(); |
753 | 753 | ||
754 | typeSheet *tempSheet=findSheet(newName); | 754 | typeSheet *tempSheet=findSheet(newName); |
755 | if (tempSheet) | 755 | if (tempSheet) |
756 | { | 756 | { |
757 | QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\'')); | 757 | QMessageBox::critical(this, tr("Error"), tr("There is already a sheet named '"+newName+'\'')); |
758 | return; | 758 | return; |
759 | } | 759 | } |
760 | 760 | ||
761 | tempSheet=findSheet(sheet->getName()); | 761 | tempSheet=findSheet(sheet->getName()); |
762 | for (int i=0; i<comboSheets->count(); ++i) | 762 | for (int i=0; i<comboSheets->count(); ++i) |
763 | if (comboSheets->text(i)==tempSheet->name) | 763 | if (comboSheets->text(i)==tempSheet->name) |
764 | { | 764 | { |
765 | comboSheets->changeItem(newName, i); | 765 | comboSheets->changeItem(newName, i); |
766 | break; | 766 | break; |
767 | } | 767 | } |
768 | tempSheet->name=newName; | 768 | tempSheet->name=newName; |
769 | sheet->setName(newName); | 769 | sheet->setName(newName); |
770 | } | 770 | } |
771 | 771 | ||
772 | void MainWindow::slotSheetRemove() | 772 | void MainWindow::slotSheetRemove() |
773 | { | 773 | { |
774 | if (comboSheets->count()<2) | 774 | if (comboSheets->count()<2) |
775 | { | 775 | { |
776 | QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!")); | 776 | QMessageBox::warning(this, tr("Error"), tr("There is only one sheet!")); |
777 | return; | 777 | return; |
778 | } | 778 | } |
779 | if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) | 779 | if (QMessageBox::information(this, tr("Remove Sheet"), tr("Are you sure?"), QMessageBox::Yes, QMessageBox::No)==QMessageBox::Yes) |
780 | { | 780 | { |
781 | typeSheet *tempSheet=findSheet(sheet->getName()); | 781 | typeSheet *tempSheet=findSheet(sheet->getName()); |
782 | for (int i=0; i<comboSheets->count(); ++i) | 782 | for (int i=0; i<comboSheets->count(); ++i) |
783 | if (comboSheets->text(i)==tempSheet->name) | 783 | if (comboSheets->text(i)==tempSheet->name) |
784 | { | 784 | { |
785 | comboSheets->removeItem(i); | 785 | comboSheets->removeItem(i); |
786 | break; | 786 | break; |
787 | } | 787 | } |
788 | comboSheets->setCurrentItem(0); | 788 | comboSheets->setCurrentItem(0); |
789 | slotSheetChanged(comboSheets->currentText()); | 789 | slotSheetChanged(comboSheets->currentText()); |
790 | listSheets.remove(tempSheet); | 790 | listSheets.remove(tempSheet); |
791 | } | 791 | } |
792 | } | 792 | } |
793 | 793 | ||
794 | void MainWindow::slotDataSort() | 794 | void MainWindow::slotDataSort() |
795 | { | 795 | { |
796 | SortDialog dialogSort(this); | 796 | SortDialog dialogSort(this); |
797 | dialogSort.showMaximized(); | 797 | dialogSort.showMaximized(); |
798 | dialogSort.exec(sheet); | 798 | dialogSort.exec(sheet); |
799 | } | 799 | } |
800 | 800 | ||
801 | void MainWindow::slotDocModified() | 801 | void MainWindow::slotDocModified() |
802 | { | 802 | { |
803 | documentModified=TRUE; | 803 | documentModified=TRUE; |
804 | } | 804 | } |
805 | 805 | ||
806 | void MainWindow::slotInsertCells() | 806 | void MainWindow::slotInsertCells() |
807 | { | 807 | { |
808 | QDialog dialogInsert(this, 0, TRUE); | 808 | QDialog dialogInsert(this, 0, TRUE); |
809 | dialogInsert.resize(180, 130); | 809 | dialogInsert.resize(180, 130); |
810 | dialogInsert.setCaption(tr("Insert Cells")); | 810 | dialogInsert.setCaption(tr("Insert Cells")); |
811 | 811 | ||
812 | QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert); | 812 | QVButtonGroup *group=new QVButtonGroup(tr("&Type"), &dialogInsert); |
813 | group->setGeometry(10, 10, 160, 110); | 813 | group->setGeometry(10, 10, 160, 110); |
814 | QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group); | 814 | QRadioButton *radio=new QRadioButton(tr("Shift cells &down"), group); |
815 | radio=new QRadioButton(tr("Shift cells &right"), group); | 815 | radio=new QRadioButton(tr("Shift cells &right"), group); |
816 | radio=new QRadioButton(tr("Entire ro&w"), group); | 816 | radio=new QRadioButton(tr("Entire ro&w"), group); |
817 | radio=new QRadioButton(tr("Entire &column"), group); | 817 | radio=new QRadioButton(tr("Entire &column"), group); |
818 | group->setButton(0); | 818 | group->setButton(0); |
819 | 819 | ||
820 | if (dialogInsert.exec()==QDialog::Accepted) | 820 | if (dialogInsert.exec()==QDialog::Accepted) |
821 | switch (group->id(group->selected())) | 821 | switch (group->id(group->selected())) |
822 | { | 822 | { |
823 | case 0: sheet->insertRows(1, FALSE); break; | 823 | case 0: sheet->insertRows(1, FALSE); break; |
824 | case 1: sheet->insertColumns(1, FALSE); break; | 824 | case 1: sheet->insertColumns(1, FALSE); break; |
825 | case 2: sheet->insertRows(1, TRUE); break; | 825 | case 2: sheet->insertRows(1, TRUE); break; |
826 | case 3: sheet->insertColumns(1, TRUE); break; | 826 | case 3: sheet->insertColumns(1, TRUE); break; |
827 | } | 827 | } |
828 | } | 828 | } |
829 | 829 | ||
830 | void MainWindow::slotDataFindReplace() | 830 | void MainWindow::slotDataFindReplace() |
831 | { | 831 | { |
832 | FindDialog dialogFind(this); | 832 | FindDialog dialogFind(this); |
833 | dialogFind.showMaximized(); | 833 | dialogFind.showMaximized(); |
834 | dialogFind.exec(sheet); | 834 | dialogFind.exec(sheet); |
835 | } | 835 | } |
diff --git a/noncore/apps/opie-sheet/mainwindow.h b/noncore/apps/opie-sheet/mainwindow.h index 4007f88..bd99c36 100644 --- a/noncore/apps/opie-sheet/mainwindow.h +++ b/noncore/apps/opie-sheet/mainwindow.h | |||
@@ -1,133 +1,133 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | /* | 10 | /* |
11 | * Opie Sheet (formerly Sheet/Qt) | 11 | * Opie Sheet (formerly Sheet/Qt) |
12 | * by Serdar Ozler <sozler@sitebest.com> | 12 | * by Serdar Ozler <sozler@sitebest.com> |
13 | */ | 13 | */ |
14 | 14 | ||
15 | #ifndef MAINWINDOW_H | 15 | #ifndef MAINWINDOW_H |
16 | #define MAINWINDOW_H | 16 | #define MAINWINDOW_H |
17 | 17 | ||
18 | #include <qpe/applnk.h> | 18 | #include <qpe/applnk.h> |
19 | #include <qpe/fileselector.h> | 19 | #include <qpe/fileselector.h> |
20 | #include <qmenubar.h> | 20 | #include <qmenubar.h> |
21 | #include <qpe/qpetoolbar.h> | 21 | #include <qtoolbar.h> |
22 | #include <qmainwindow.h> | 22 | #include <qmainwindow.h> |
23 | #include <qaction.h> | 23 | #include <qaction.h> |
24 | #include <qlineedit.h> | 24 | #include <qlineedit.h> |
25 | #include <qbutton.h> | 25 | #include <qbutton.h> |
26 | #include <qcombobox.h> | 26 | #include <qcombobox.h> |
27 | #include <qtoolbutton.h> | 27 | #include <qtoolbutton.h> |
28 | 28 | ||
29 | #include "sheet.h" | 29 | #include "sheet.h" |
30 | 30 | ||
31 | typedef struct typeSheet | 31 | typedef struct typeSheet |
32 | { | 32 | { |
33 | QString name; | 33 | QString name; |
34 | QList<typeCellData> data; | 34 | QList<typeCellData> data; |
35 | }; | 35 | }; |
36 | 36 | ||
37 | class MainWindow: public QMainWindow | 37 | class MainWindow: public QMainWindow |
38 | { | 38 | { |
39 | Q_OBJECT | 39 | Q_OBJECT |
40 | 40 | ||
41 | // QPE objects | 41 | // QPE objects |
42 | DocLnk* currentDoc; | 42 | DocLnk* currentDoc; |
43 | QMenuBar *menu; | 43 | QMenuBar *menu; |
44 | QPEToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard; | 44 | QToolBar *toolbarFunctions, *toolbarEdit, *toolbarStandard; |
45 | FileSelector *fileSelector; | 45 | FileSelector *fileSelector; |
46 | 46 | ||
47 | // QT objects | 47 | // QT objects |
48 | QPopupMenu *menuFile, *menuEdit, *menuInsert, *menuFormat, *menuData, *menuHelp, | 48 | QPopupMenu *menuFile, *menuEdit, *menuInsert, *menuFormat, *menuData, *menuHelp, |
49 | *submenuFunc, *submenuFuncStd, *submenuFuncMath, *submenuFuncStat, | 49 | *submenuFunc, *submenuFuncStd, *submenuFuncMath, *submenuFuncStat, |
50 | *submenuRow, *submenuCol, *submenuSheet; | 50 | *submenuRow, *submenuCol, *submenuSheet; |
51 | QAction *fileNew, *fileOpen, *fileSave, *fileSaveAs, *fileQuit, *helpAbout, *editAccept, *editCancel, *formatCells, | 51 | QAction *fileNew, *fileOpen, *fileSave, *fileSaveAs, *fileQuit, *helpAbout, *editAccept, *editCancel, *formatCells, |
52 | *funcPlus, *funcMinus, *funcCross, *funcDivide, *funcParanOpen, *funcParanClose, *funcComma, *funcEqual, | 52 | *funcPlus, *funcMinus, *funcCross, *funcDivide, *funcParanOpen, *funcParanClose, *funcComma, *funcEqual, |
53 | *editCut, *editCopy, *editPaste, *editPasteContents, *editClear, *insertCols, *insertRows, *insertSheets, *insertCells, | 53 | *editCut, *editCopy, *editPaste, *editPasteContents, *editClear, *insertCols, *insertRows, *insertSheets, *insertCells, |
54 | *rowHeight, *rowShow, *rowHide, *rowAdjust, *colWidth, *colShow, *colHide, *colAdjust, *sheetRename, *sheetRemove, | 54 | *rowHeight, *rowShow, *rowHide, *rowAdjust, *colWidth, *colShow, *colHide, *colAdjust, *sheetRename, *sheetRemove, |
55 | *dataSort, *dataFindReplace, *editCellSelect, *helpGeneral; | 55 | *dataSort, *dataFindReplace, *editCellSelect, *helpGeneral; |
56 | QLineEdit *editData; | 56 | QLineEdit *editData; |
57 | QButton *buttonUp, *buttonDown, *buttonLeft, *buttonRight; | 57 | QButton *buttonUp, *buttonDown, *buttonLeft, *buttonRight; |
58 | QComboBox *comboSheets; | 58 | QComboBox *comboSheets; |
59 | QToolButton *toolFunction; | 59 | QToolButton *toolFunction; |
60 | QList<typeSheet> listSheets; | 60 | QList<typeSheet> listSheets; |
61 | QString helpFile; | 61 | QString helpFile; |
62 | 62 | ||
63 | // Other objects | 63 | // Other objects |
64 | Sheet *sheet; | 64 | Sheet *sheet; |
65 | 65 | ||
66 | // Variables | 66 | // Variables |
67 | bool documentModified; | 67 | bool documentModified; |
68 | 68 | ||
69 | // Private functions | 69 | // Private functions |
70 | void initMenu(); | 70 | void initMenu(); |
71 | void initActions(); | 71 | void initActions(); |
72 | void initFunctionsToolbar(); | 72 | void initFunctionsToolbar(); |
73 | void initEditToolbar(); | 73 | void initEditToolbar(); |
74 | void initStandardToolbar(); | 74 | void initStandardToolbar(); |
75 | void initSheet(); | 75 | void initSheet(); |
76 | void addToData(const QString &data); | 76 | void addToData(const QString &data); |
77 | int saveCurrentFile(bool ask=TRUE); | 77 | int saveCurrentFile(bool ask=TRUE); |
78 | void documentOpen(const DocLnk &lnkDoc); | 78 | void documentOpen(const DocLnk &lnkDoc); |
79 | void documentSave(DocLnk *lnkDoc); | 79 | void documentSave(DocLnk *lnkDoc); |
80 | void closeEvent(QCloseEvent *e); | 80 | void closeEvent(QCloseEvent *e); |
81 | void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w); | 81 | void addFlyAction(const QString &text, const QString &menuText, const QString &tip, QWidget *w); |
82 | typeSheet *createNewSheet(); | 82 | typeSheet *createNewSheet(); |
83 | typeSheet *findSheet(const QString &name); | 83 | typeSheet *findSheet(const QString &name); |
84 | 84 | ||
85 | private slots: | 85 | private slots: |
86 | void slotFileNew(); | 86 | void slotFileNew(); |
87 | void slotFileOpen(); | 87 | void slotFileOpen(); |
88 | void slotFileSave(); | 88 | void slotFileSave(); |
89 | void slotFileSaveAs(); | 89 | void slotFileSaveAs(); |
90 | void slotHelpAbout(); | 90 | void slotHelpAbout(); |
91 | void slotEditAccept(); | 91 | void slotEditAccept(); |
92 | void slotEditCancel(); | 92 | void slotEditCancel(); |
93 | void slotEditPaste(); | 93 | void slotEditPaste(); |
94 | void slotEditPasteContents(); | 94 | void slotEditPasteContents(); |
95 | void slotFormatCells(); | 95 | void slotFormatCells(); |
96 | void slotInsertCells(); | 96 | void slotInsertCells(); |
97 | void slotInsertRows(); | 97 | void slotInsertRows(); |
98 | void slotInsertCols(); | 98 | void slotInsertCols(); |
99 | void slotInsertSheets(); | 99 | void slotInsertSheets(); |
100 | void slotDataSort(); | 100 | void slotDataSort(); |
101 | void slotDataFindReplace(); | 101 | void slotDataFindReplace(); |
102 | void slotRowHeight(); | 102 | void slotRowHeight(); |
103 | void slotRowAdjust(); | 103 | void slotRowAdjust(); |
104 | void slotRowShow(); | 104 | void slotRowShow(); |
105 | void slotRowHide(); | 105 | void slotRowHide(); |
106 | void slotColumnWidth(); | 106 | void slotColumnWidth(); |
107 | void slotColumnAdjust(); | 107 | void slotColumnAdjust(); |
108 | void slotColumnShow(); | 108 | void slotColumnShow(); |
109 | void slotColumnHide(); | 109 | void slotColumnHide(); |
110 | void slotSheetRename(); | 110 | void slotSheetRename(); |
111 | void slotSheetRemove(); | 111 | void slotSheetRemove(); |
112 | void slotFuncOutput(); | 112 | void slotFuncOutput(); |
113 | void slotCellSelect(bool lock); | 113 | void slotCellSelect(bool lock); |
114 | void slotCellClicked(const QString &cell); | 114 | void slotCellClicked(const QString &cell); |
115 | void slotSheetChanged(const QString &name); | 115 | void slotSheetChanged(const QString &name); |
116 | void slotDocModified(); | 116 | void slotDocModified(); |
117 | void selectorShow(); | 117 | void selectorShow(); |
118 | void selectorHide(); | 118 | void selectorHide(); |
119 | void selectorFileNew(const DocLnk &lnkDoc); | 119 | void selectorFileNew(const DocLnk &lnkDoc); |
120 | void selectorFileOpen(const DocLnk &lnkDoc); | 120 | void selectorFileOpen(const DocLnk &lnkDoc); |
121 | 121 | ||
122 | public: | 122 | public: |
123 | static QString appName() { return QString::fromLatin1("sheetqt"); } | 123 | static QString appName() { return QString::fromLatin1("sheetqt"); } |
124 | MainWindow(QWidget *p, const char*, WFlags); | 124 | MainWindow(QWidget *p, const char*, WFlags); |
125 | ~MainWindow(); | 125 | ~MainWindow(); |
126 | 126 | ||
127 | void setHelpFile(const QString &help_filename) { helpFile=help_filename; } | 127 | void setHelpFile(const QString &help_filename) { helpFile=help_filename; } |
128 | 128 | ||
129 | public slots: | 129 | public slots: |
130 | void setDocument(const QString &applnk_filename); | 130 | void setDocument(const QString &applnk_filename); |
131 | }; | 131 | }; |
132 | 132 | ||
133 | #endif | 133 | #endif |
diff --git a/noncore/apps/tableviewer/tableviewer.cpp b/noncore/apps/tableviewer/tableviewer.cpp index fdf0072..207172d 100644 --- a/noncore/apps/tableviewer/tableviewer.cpp +++ b/noncore/apps/tableviewer/tableviewer.cpp | |||
@@ -1,481 +1,481 @@ | |||
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 | /* local includes */ | 21 | /* local includes */ |
22 | #include "tableviewer.h" | 22 | #include "tableviewer.h" |
23 | #include "ui/tvbrowseview.h" | 23 | #include "ui/tvbrowseview.h" |
24 | #include "ui/tvfilterview.h" | 24 | #include "ui/tvfilterview.h" |
25 | #include "ui/tvlistview.h" | 25 | #include "ui/tvlistview.h" |
26 | #include "ui/tveditview.h" | 26 | #include "ui/tveditview.h" |
27 | #include "ui/tvkeyedit.h" | 27 | #include "ui/tvkeyedit.h" |
28 | #include "db/datacache.h" | 28 | #include "db/datacache.h" |
29 | 29 | ||
30 | /* QPE includes */ | 30 | /* QPE includes */ |
31 | #include <qpe/fileselector.h> | 31 | #include <qpe/fileselector.h> |
32 | #include <qpe/resource.h> | 32 | #include <qpe/resource.h> |
33 | #include <qpe/qpetoolbar.h> | 33 | #include <qpe/qpetoolbar.h> |
34 | 34 | ||
35 | /* QTE includes */ | 35 | /* QTE includes */ |
36 | #include <qpe/qpemenubar.h> | 36 | #include <qmenubar.h> |
37 | #include <qpe/qpetoolbar.h> | 37 | #include <qpe/qpetoolbar.h> |
38 | #include <qpopupmenu.h> | 38 | #include <qpopupmenu.h> |
39 | #include <qapplication.h> | 39 | #include <qapplication.h> |
40 | #include <qwidgetstack.h> | 40 | #include <qwidgetstack.h> |
41 | #include <qlayout.h> | 41 | #include <qlayout.h> |
42 | #include <qbuffer.h> | 42 | #include <qbuffer.h> |
43 | /*! | 43 | /*! |
44 | \class TableViewerWindow | 44 | \class TableViewerWindow |
45 | \brief The main window widget of the application | 45 | \brief The main window widget of the application |
46 | 46 | ||
47 | This is the main widget of the table viewer application. | 47 | This is the main widget of the table viewer application. |
48 | It is the co-ordination point. | 48 | It is the co-ordination point. |
49 | */ | 49 | */ |
50 | 50 | ||
51 | /*! | 51 | /*! |
52 | Constructs a new TableViewerWindow | 52 | Constructs a new TableViewerWindow |
53 | */ | 53 | */ |
54 | TableViewerWindow::TableViewerWindow(QWidget *parent, const char *name, WFlags f) | 54 | TableViewerWindow::TableViewerWindow(QWidget *parent, const char *name, WFlags f) |
55 | : QMainWindow(parent, name, f) | 55 | : QMainWindow(parent, name, f) |
56 | { | 56 | { |
57 | setCaption(tr("Table Viewer")); | 57 | setCaption(tr("Table Viewer")); |
58 | 58 | ||
59 | /* Build data */ | 59 | /* Build data */ |
60 | ds = new DBStore(); | 60 | ds = new DBStore(); |
61 | doc.setType("text/x-xml-tableviewer"); | 61 | doc.setType("text/x-xml-tableviewer"); |
62 | doc.setName("table"); | 62 | doc.setName("table"); |
63 | 63 | ||
64 | dirty = FALSE; | 64 | dirty = FALSE; |
65 | ts.current_column = 0; | 65 | ts.current_column = 0; |
66 | ts.kRep = ds->getKeys(); | 66 | ts.kRep = ds->getKeys(); |
67 | 67 | ||
68 | /* build menus */ | 68 | /* build menus */ |
69 | menu = new QMenuBar(this, 0); | 69 | menu = new QMenuBar(this, 0); |
70 | 70 | ||
71 | QPopupMenu *file_menu = new QPopupMenu; | 71 | QPopupMenu *file_menu = new QPopupMenu; |
72 | file_menu->insertItem("New", this, SLOT(newDocument())); | 72 | file_menu->insertItem("New", this, SLOT(newDocument())); |
73 | 73 | ||
74 | file_menu->insertItem("Open", this, SLOT(selectDocument())); | 74 | file_menu->insertItem("Open", this, SLOT(selectDocument())); |
75 | file_menu->insertSeparator(); | 75 | file_menu->insertSeparator(); |
76 | file_menu->insertItem("Properties"); | 76 | file_menu->insertItem("Properties"); |
77 | 77 | ||
78 | /* later will want to set this up to clean up first via this, SLOT(quit) */ | 78 | /* later will want to set this up to clean up first via this, SLOT(quit) */ |
79 | menu->insertItem("Document", file_menu); | 79 | menu->insertItem("Document", file_menu); |
80 | 80 | ||
81 | QPopupMenu *edit_menu = new QPopupMenu; | 81 | QPopupMenu *edit_menu = new QPopupMenu; |
82 | edit_menu->insertItem("Edit Item", this, SLOT(editItemSlot())); | 82 | edit_menu->insertItem("Edit Item", this, SLOT(editItemSlot())); |
83 | edit_menu->insertItem("Edit Keys", this, SLOT(editKeysSlot())); | 83 | edit_menu->insertItem("Edit Keys", this, SLOT(editKeysSlot())); |
84 | edit_menu->insertItem("Edit filters", this, SLOT(filterViewSlot())); | 84 | edit_menu->insertItem("Edit filters", this, SLOT(filterViewSlot())); |
85 | menu->insertItem("Edit", edit_menu); | 85 | menu->insertItem("Edit", edit_menu); |
86 | 86 | ||
87 | QPopupMenu *view_menu = new QPopupMenu; | 87 | QPopupMenu *view_menu = new QPopupMenu; |
88 | view_menu->insertItem("Browse View", this, SLOT(browseViewSlot())); | 88 | view_menu->insertItem("Browse View", this, SLOT(browseViewSlot())); |
89 | view_menu->insertItem("List View", this, SLOT(listViewSlot())); | 89 | view_menu->insertItem("List View", this, SLOT(listViewSlot())); |
90 | menu->insertItem("View", view_menu); | 90 | menu->insertItem("View", view_menu); |
91 | 91 | ||
92 | QVBoxLayout *main_layout = new QVBoxLayout; | 92 | QVBoxLayout *main_layout = new QVBoxLayout; |
93 | 93 | ||
94 | /* Build tool bar */ | 94 | /* Build tool bar */ |
95 | navigation = new QPEToolBar(this, "navigation"); | 95 | navigation = new QToolBar(this, "navigation"); |
96 | QToolButton *newItemButton = new QToolButton( | 96 | QToolButton *newItemButton = new QToolButton( |
97 | QIconSet(Resource::loadPixmap("new")), "New Item", QString::null, | 97 | QIconSet(Resource::loadPixmap("new")), "New Item", QString::null, |
98 | this, SLOT(newItemSlot()), navigation, "New Item"); | 98 | this, SLOT(newItemSlot()), navigation, "New Item"); |
99 | QToolButton *editItemButton = new QToolButton( | 99 | QToolButton *editItemButton = new QToolButton( |
100 | QIconSet(Resource::loadPixmap("edit")), "Edit Item", QString::null, | 100 | QIconSet(Resource::loadPixmap("edit")), "Edit Item", QString::null, |
101 | this, SLOT(editItemSlot()), navigation, "Edit Item"); | 101 | this, SLOT(editItemSlot()), navigation, "Edit Item"); |
102 | QToolButton *deleteItemButton = new QToolButton( | 102 | QToolButton *deleteItemButton = new QToolButton( |
103 | QIconSet(Resource::loadPixmap("trash")), "Delete Item", | 103 | QIconSet(Resource::loadPixmap("trash")), "Delete Item", |
104 | QString::null, this, | 104 | QString::null, this, |
105 | SLOT(deleteItemSlot()), navigation, "Delete Item"); | 105 | SLOT(deleteItemSlot()), navigation, "Delete Item"); |
106 | 106 | ||
107 | navigation->addSeparator(); | 107 | navigation->addSeparator(); |
108 | 108 | ||
109 | QToolButton *firstItemButton = new QToolButton( | 109 | QToolButton *firstItemButton = new QToolButton( |
110 | QIconSet(Resource::loadPixmap("fastback")), "First Item", | 110 | QIconSet(Resource::loadPixmap("fastback")), "First Item", |
111 | QString::null, this, | 111 | QString::null, this, |
112 | SLOT(firstItem()), navigation, "First Item"); | 112 | SLOT(firstItem()), navigation, "First Item"); |
113 | QToolButton *previousItemButton = new QToolButton( | 113 | QToolButton *previousItemButton = new QToolButton( |
114 | QIconSet(Resource::loadPixmap("back")), "Previous Item", | 114 | QIconSet(Resource::loadPixmap("back")), "Previous Item", |
115 | QString::null, this, | 115 | QString::null, this, |
116 | SLOT(previousItem()), navigation, "Previous Item"); | 116 | SLOT(previousItem()), navigation, "Previous Item"); |
117 | QToolButton *nextItemButton = new QToolButton( | 117 | QToolButton *nextItemButton = new QToolButton( |
118 | QIconSet(Resource::loadPixmap("forward")), "Next Item", | 118 | QIconSet(Resource::loadPixmap("forward")), "Next Item", |
119 | QString::null, this, | 119 | QString::null, this, |
120 | SLOT(nextItem()), navigation, "Next Item"); | 120 | SLOT(nextItem()), navigation, "Next Item"); |
121 | QToolButton *lastItemButton = new QToolButton( | 121 | QToolButton *lastItemButton = new QToolButton( |
122 | QIconSet(Resource::loadPixmap("fastforward")), "Last Item", | 122 | QIconSet(Resource::loadPixmap("fastforward")), "Last Item", |
123 | QString::null, this, | 123 | QString::null, this, |
124 | SLOT(lastItem()), navigation, "Last Item"); | 124 | SLOT(lastItem()), navigation, "Last Item"); |
125 | 125 | ||
126 | navigation->addSeparator(); | 126 | navigation->addSeparator(); |
127 | QToolButton *browseButton = new QToolButton( | 127 | QToolButton *browseButton = new QToolButton( |
128 | QIconSet(Resource::loadPixmap("day")), "View Single Item", | 128 | QIconSet(Resource::loadPixmap("day")), "View Single Item", |
129 | QString::null, this, | 129 | QString::null, this, |
130 | SLOT(browseViewSlot()), navigation, "View Single Item"); | 130 | SLOT(browseViewSlot()), navigation, "View Single Item"); |
131 | QToolButton *listButton = new QToolButton( | 131 | QToolButton *listButton = new QToolButton( |
132 | QIconSet(Resource::loadPixmap("month")), "View Multiple Items", | 132 | QIconSet(Resource::loadPixmap("month")), "View Multiple Items", |
133 | QString::null, this, | 133 | QString::null, this, |
134 | SLOT(listViewSlot()), navigation, "View Multiple Items"); | 134 | SLOT(listViewSlot()), navigation, "View Multiple Items"); |
135 | 135 | ||
136 | setToolBarsMovable(FALSE); | 136 | setToolBarsMovable(FALSE); |
137 | setToolBarsMovable(FALSE); | 137 | setToolBarsMovable(FALSE); |
138 | setToolBarsMovable(FALSE); | 138 | setToolBarsMovable(FALSE); |
139 | 139 | ||
140 | /* Build widgets */ | 140 | /* Build widgets */ |
141 | browseView = new TVBrowseView(&ts, this, 0); | 141 | browseView = new TVBrowseView(&ts, this, 0); |
142 | listView = new TVListView(&ts, this, 0); | 142 | listView = new TVListView(&ts, this, 0); |
143 | filterView = new TVFilterView(&ts, this, 0); | 143 | filterView = new TVFilterView(&ts, this, 0); |
144 | fileSelector = new FileSelector("text/csv;text/x-xml-tableviewer", | 144 | fileSelector = new FileSelector("text/csv;text/x-xml-tableviewer", |
145 | this, "fileselector"); | 145 | this, "fileselector"); |
146 | fileSelector->setNewVisible(FALSE); | 146 | fileSelector->setNewVisible(FALSE); |
147 | fileSelector->setCloseVisible(FALSE); | 147 | fileSelector->setCloseVisible(FALSE); |
148 | 148 | ||
149 | cw = new QWidgetStack(this, 0); | 149 | cw = new QWidgetStack(this, 0); |
150 | cw->addWidget(listView, ListState); | 150 | cw->addWidget(listView, ListState); |
151 | cw->addWidget(browseView, BrowseState); | 151 | cw->addWidget(browseView, BrowseState); |
152 | cw->addWidget(filterView, FilterState); | 152 | cw->addWidget(filterView, FilterState); |
153 | cw->addWidget(fileSelector, FileState); | 153 | cw->addWidget(fileSelector, FileState); |
154 | 154 | ||
155 | current_view = FileState; | 155 | current_view = FileState; |
156 | cw->raiseWidget(current_view); | 156 | cw->raiseWidget(current_view); |
157 | fileSelector->reread(); | 157 | fileSelector->reread(); |
158 | 158 | ||
159 | connect(browseView, SIGNAL(searchOnKey(int, TVVariant)), | 159 | connect(browseView, SIGNAL(searchOnKey(int, TVVariant)), |
160 | this, SLOT(searchOnKey(int, TVVariant))); | 160 | this, SLOT(searchOnKey(int, TVVariant))); |
161 | connect(browseView, SIGNAL(sortChanged(int)), | 161 | connect(browseView, SIGNAL(sortChanged(int)), |
162 | this, SLOT(setPrimaryKey(int))); | 162 | this, SLOT(setPrimaryKey(int))); |
163 | 163 | ||
164 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(browseViewSlot())); | 164 | connect(fileSelector, SIGNAL(closeMe()), this, SLOT(browseViewSlot())); |
165 | connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), | 165 | connect(fileSelector, SIGNAL(fileSelected(const DocLnk &)), |
166 | this, SLOT(openDocument(const DocLnk &))); | 166 | this, SLOT(openDocument(const DocLnk &))); |
167 | 167 | ||
168 | main_layout->addWidget(menu); | 168 | main_layout->addWidget(menu); |
169 | main_layout->addWidget(cw); | 169 | main_layout->addWidget(cw); |
170 | 170 | ||
171 | setCentralWidget(cw); | 171 | setCentralWidget(cw); |
172 | 172 | ||
173 | } | 173 | } |
174 | 174 | ||
175 | /*! | 175 | /*! |
176 | Destroys the TableViewerWindow | 176 | Destroys the TableViewerWindow |
177 | */ | 177 | */ |
178 | TableViewerWindow::~TableViewerWindow() | 178 | TableViewerWindow::~TableViewerWindow() |
179 | { | 179 | { |
180 | if(dirty) | 180 | if(dirty) |
181 | saveDocument(); | 181 | saveDocument(); |
182 | } | 182 | } |
183 | 183 | ||
184 | /*! | 184 | /*! |
185 | Opens a file dialog and loads the file specified by the dialog | 185 | Opens a file dialog and loads the file specified by the dialog |
186 | */ | 186 | */ |
187 | void TableViewerWindow::selectDocument() | 187 | void TableViewerWindow::selectDocument() |
188 | { | 188 | { |
189 | if(dirty) | 189 | if(dirty) |
190 | saveDocument(); | 190 | saveDocument(); |
191 | current_view = FileState; | 191 | current_view = FileState; |
192 | cw->raiseWidget(current_view); | 192 | cw->raiseWidget(current_view); |
193 | fileSelector->reread(); | 193 | fileSelector->reread(); |
194 | } | 194 | } |
195 | 195 | ||
196 | void TableViewerWindow::saveDocument() | 196 | void TableViewerWindow::saveDocument() |
197 | { | 197 | { |
198 | if(!dirty) | 198 | if(!dirty) |
199 | return; | 199 | return; |
200 | 200 | ||
201 | FileManager fm; | 201 | FileManager fm; |
202 | QIODevice *dev = fm.saveFile(doc); | 202 | QIODevice *dev = fm.saveFile(doc); |
203 | 203 | ||
204 | if(!ds->saveSource(dev, doc.type())){ | 204 | if(!ds->saveSource(dev, doc.type())){ |
205 | qWarning("Save unsuccessful"); | 205 | qWarning("Save unsuccessful"); |
206 | return; | 206 | return; |
207 | } | 207 | } |
208 | dev->close(); | 208 | dev->close(); |
209 | dirty = FALSE; | 209 | dirty = FALSE; |
210 | } | 210 | } |
211 | 211 | ||
212 | void TableViewerWindow::newDocument() | 212 | void TableViewerWindow::newDocument() |
213 | { | 213 | { |
214 | DocLnk nf; | 214 | DocLnk nf; |
215 | nf.setType("text/x-xml-tableviewer"); | 215 | nf.setType("text/x-xml-tableviewer"); |
216 | nf.setName("table"); | 216 | nf.setName("table"); |
217 | 217 | ||
218 | delete ds; | 218 | delete ds; |
219 | ds = new DBStore(); | 219 | ds = new DBStore(); |
220 | 220 | ||
221 | ts.current_column = 0; | 221 | ts.current_column = 0; |
222 | ts.kRep = ds->getKeys(); | 222 | ts.kRep = ds->getKeys(); |
223 | browseView->reset(); | 223 | browseView->reset(); |
224 | listView->reset(); | 224 | listView->reset(); |
225 | filterView->reset(); | 225 | filterView->reset(); |
226 | 226 | ||
227 | doc = nf; | 227 | doc = nf; |
228 | dirty = FALSE; | 228 | dirty = FALSE; |
229 | 229 | ||
230 | current_view = BrowseState; | 230 | current_view = BrowseState; |
231 | cw->raiseWidget(current_view); | 231 | cw->raiseWidget(current_view); |
232 | 232 | ||
233 | /* now set up for editing the keys */ | 233 | /* now set up for editing the keys */ |
234 | ts.kRep->addKey("key", TVVariant::String); | 234 | ts.kRep->addKey("key", TVVariant::String); |
235 | editKeysSlot(); | 235 | editKeysSlot(); |
236 | } | 236 | } |
237 | 237 | ||
238 | void TableViewerWindow::setDocument(const QString &f) | 238 | void TableViewerWindow::setDocument(const QString &f) |
239 | { | 239 | { |
240 | openDocument(DocLnk(f, TRUE)); | 240 | openDocument(DocLnk(f, TRUE)); |
241 | } | 241 | } |
242 | 242 | ||
243 | void TableViewerWindow::openDocument(const DocLnk &f) | 243 | void TableViewerWindow::openDocument(const DocLnk &f) |
244 | { | 244 | { |
245 | 245 | ||
246 | if (!f.isValid()) | 246 | if (!f.isValid()) |
247 | return; | 247 | return; |
248 | 248 | ||
249 | FileManager fm; | 249 | FileManager fm; |
250 | QIODevice *dev = fm.openFile(f); | 250 | QIODevice *dev = fm.openFile(f); |
251 | doc = f; | 251 | doc = f; |
252 | 252 | ||
253 | if(ds->openSource(dev, doc.type())) { | 253 | if(ds->openSource(dev, doc.type())) { |
254 | DataElem *d; | 254 | DataElem *d; |
255 | 255 | ||
256 | browseView->reset(); | 256 | browseView->reset(); |
257 | listView->reset(); | 257 | listView->reset(); |
258 | filterView->reset(); | 258 | filterView->reset(); |
259 | 259 | ||
260 | current_view = BrowseState; | 260 | current_view = BrowseState; |
261 | cw->raiseWidget(current_view); | 261 | cw->raiseWidget(current_view); |
262 | 262 | ||
263 | /* set up new table state and ensure sub widgets have a reference */ | 263 | /* set up new table state and ensure sub widgets have a reference */ |
264 | ts.current_column = 0; | 264 | ts.current_column = 0; |
265 | ts.kRep = ds->getKeys(); | 265 | ts.kRep = ds->getKeys(); |
266 | browseView->rebuildKeys(); | 266 | browseView->rebuildKeys(); |
267 | listView->rebuildKeys(); | 267 | listView->rebuildKeys(); |
268 | filterView->rebuildKeys(); | 268 | filterView->rebuildKeys(); |
269 | 269 | ||
270 | ds->first(); | 270 | ds->first(); |
271 | /* set up the list view */ | 271 | /* set up the list view */ |
272 | listView->clearItems(); | 272 | listView->clearItems(); |
273 | do { | 273 | do { |
274 | d = ds->getCurrentData(); | 274 | d = ds->getCurrentData(); |
275 | if(d) | 275 | if(d) |
276 | listView->addItem(d); | 276 | listView->addItem(d); |
277 | } while(ds->next()); | 277 | } while(ds->next()); |
278 | 278 | ||
279 | /* Set up browse view, Will be based of structure of listView */ | 279 | /* Set up browse view, Will be based of structure of listView */ |
280 | listView->first(); | 280 | listView->first(); |
281 | ts.current_elem = listView->getCurrentData(); | 281 | ts.current_elem = listView->getCurrentData(); |
282 | browseView->rebuildData(); | 282 | browseView->rebuildData(); |
283 | listView->rebuildData(); | 283 | listView->rebuildData(); |
284 | 284 | ||
285 | QString scratch = "Table Viewer";/* later take from constant */ | 285 | QString scratch = "Table Viewer";/* later take from constant */ |
286 | scratch += " - "; | 286 | scratch += " - "; |
287 | scratch += ds->getName(); | 287 | scratch += ds->getName(); |
288 | setCaption(tr(scratch)); | 288 | setCaption(tr(scratch)); |
289 | 289 | ||
290 | dirty = FALSE; | 290 | dirty = FALSE; |
291 | } else { | 291 | } else { |
292 | qWarning(tr("could not load Document")); | 292 | qWarning(tr("could not load Document")); |
293 | } | 293 | } |
294 | dev->close(); | 294 | dev->close(); |
295 | } | 295 | } |
296 | 296 | ||
297 | /*! | 297 | /*! |
298 | Moves to the first item of the current table | 298 | Moves to the first item of the current table |
299 | */ | 299 | */ |
300 | void TableViewerWindow::firstItem() | 300 | void TableViewerWindow::firstItem() |
301 | { | 301 | { |
302 | listView->first(); | 302 | listView->first(); |
303 | ts.current_elem = listView->getCurrentData(); | 303 | ts.current_elem = listView->getCurrentData(); |
304 | browseView->rebuildData(); | 304 | browseView->rebuildData(); |
305 | } | 305 | } |
306 | 306 | ||
307 | /*! | 307 | /*! |
308 | Moves to the lat item of the current table | 308 | Moves to the lat item of the current table |
309 | */ | 309 | */ |
310 | void TableViewerWindow::lastItem() | 310 | void TableViewerWindow::lastItem() |
311 | { | 311 | { |
312 | listView->last(); | 312 | listView->last(); |
313 | ts.current_elem = listView->getCurrentData(); | 313 | ts.current_elem = listView->getCurrentData(); |
314 | browseView->rebuildData(); | 314 | browseView->rebuildData(); |
315 | } | 315 | } |
316 | 316 | ||
317 | /*! | 317 | /*! |
318 | Moves to the next item of the current table | 318 | Moves to the next item of the current table |
319 | */ | 319 | */ |
320 | void TableViewerWindow::nextItem() | 320 | void TableViewerWindow::nextItem() |
321 | { | 321 | { |
322 | listView->next(); | 322 | listView->next(); |
323 | ts.current_elem = listView->getCurrentData(); | 323 | ts.current_elem = listView->getCurrentData(); |
324 | browseView->rebuildData(); | 324 | browseView->rebuildData(); |
325 | } | 325 | } |
326 | 326 | ||
327 | /*! | 327 | /*! |
328 | Moves to the previous item of the current table | 328 | Moves to the previous item of the current table |
329 | */ | 329 | */ |
330 | void TableViewerWindow::previousItem() | 330 | void TableViewerWindow::previousItem() |
331 | { | 331 | { |
332 | listView->previous(); | 332 | listView->previous(); |
333 | ts.current_elem = listView->getCurrentData(); | 333 | ts.current_elem = listView->getCurrentData(); |
334 | browseView->rebuildData(); | 334 | browseView->rebuildData(); |
335 | } | 335 | } |
336 | 336 | ||
337 | /*! | 337 | /*! |
338 | Raises the List View. This is a mode change for the application. | 338 | Raises the List View. This is a mode change for the application. |
339 | */ | 339 | */ |
340 | void TableViewerWindow::listViewSlot() | 340 | void TableViewerWindow::listViewSlot() |
341 | { | 341 | { |
342 | if(current_view == FilterState) | 342 | if(current_view == FilterState) |
343 | applyFilter(); | 343 | applyFilter(); |
344 | current_view = ListState; | 344 | current_view = ListState; |
345 | cw->raiseWidget(current_view); | 345 | cw->raiseWidget(current_view); |
346 | } | 346 | } |
347 | 347 | ||
348 | void TableViewerWindow::applyFilter() | 348 | void TableViewerWindow::applyFilter() |
349 | { | 349 | { |
350 | DataElem *d; | 350 | DataElem *d; |
351 | 351 | ||
352 | listView->clearItems(); | 352 | listView->clearItems(); |
353 | ds->first(); | 353 | ds->first(); |
354 | do { | 354 | do { |
355 | d = ds->getCurrentData(); | 355 | d = ds->getCurrentData(); |
356 | if(d) | 356 | if(d) |
357 | if(filterView->passesFilter(d)) | 357 | if(filterView->passesFilter(d)) |
358 | listView->addItem(d); | 358 | listView->addItem(d); |
359 | } while(ds->next()); | 359 | } while(ds->next()); |
360 | listView->first(); | 360 | listView->first(); |
361 | listView->rebuildData(); | 361 | listView->rebuildData(); |
362 | } | 362 | } |
363 | 363 | ||
364 | /*! | 364 | /*! |
365 | Raises the Browse View. This is a mode change for the application. | 365 | Raises the Browse View. This is a mode change for the application. |
366 | */ | 366 | */ |
367 | void TableViewerWindow::browseViewSlot() | 367 | void TableViewerWindow::browseViewSlot() |
368 | { | 368 | { |
369 | if(current_view == FilterState) | 369 | if(current_view == FilterState) |
370 | applyFilter(); | 370 | applyFilter(); |
371 | 371 | ||
372 | ts.current_elem = listView->getCurrentData(); | 372 | ts.current_elem = listView->getCurrentData(); |
373 | browseView->rebuildData(); | 373 | browseView->rebuildData(); |
374 | 374 | ||
375 | current_view = BrowseState; | 375 | current_view = BrowseState; |
376 | cw->raiseWidget(current_view); | 376 | cw->raiseWidget(current_view); |
377 | } | 377 | } |
378 | 378 | ||
379 | /*! | 379 | /*! |
380 | Raises the List View. This is a mode change for the application. | 380 | Raises the List View. This is a mode change for the application. |
381 | */ | 381 | */ |
382 | void TableViewerWindow::filterViewSlot() | 382 | void TableViewerWindow::filterViewSlot() |
383 | { | 383 | { |
384 | current_view = FilterState; | 384 | current_view = FilterState; |
385 | cw->raiseWidget(current_view); | 385 | cw->raiseWidget(current_view); |
386 | } | 386 | } |
387 | 387 | ||
388 | 388 | ||
389 | 389 | ||
390 | 390 | ||
391 | void TableViewerWindow::editItemSlot() | 391 | void TableViewerWindow::editItemSlot() |
392 | { | 392 | { |
393 | if(TVEditView::openEditItemDialog(&ts, ts.current_elem, this)) { | 393 | if(TVEditView::openEditItemDialog(&ts, ts.current_elem, this)) { |
394 | listView->rebuildData(); | 394 | listView->rebuildData(); |
395 | browseView->rebuildData(); | 395 | browseView->rebuildData(); |
396 | dirty = TRUE; | 396 | dirty = TRUE; |
397 | } | 397 | } |
398 | } | 398 | } |
399 | 399 | ||
400 | void TableViewerWindow::newItemSlot() | 400 | void TableViewerWindow::newItemSlot() |
401 | { | 401 | { |
402 | DataElem *d = new DataElem(ds); | 402 | DataElem *d = new DataElem(ds); |
403 | if (TVEditView::openEditItemDialog(&ts, d, this)) { | 403 | if (TVEditView::openEditItemDialog(&ts, d, this)) { |
404 | 404 | ||
405 | ds->addItem(d); | 405 | ds->addItem(d); |
406 | ts.current_elem = d; | 406 | ts.current_elem = d; |
407 | applyFilter(); | 407 | applyFilter(); |
408 | listView->rebuildData(); | 408 | listView->rebuildData(); |
409 | browseView->rebuildData(); | 409 | browseView->rebuildData(); |
410 | dirty = TRUE; | 410 | dirty = TRUE; |
411 | } | 411 | } |
412 | } | 412 | } |
413 | 413 | ||
414 | void TableViewerWindow::deleteItemSlot() | 414 | void TableViewerWindow::deleteItemSlot() |
415 | { | 415 | { |
416 | /* delete the actual item, then do a 'filter' */ | 416 | /* delete the actual item, then do a 'filter' */ |
417 | DataElem *to_remove = ts.current_elem; | 417 | DataElem *to_remove = ts.current_elem; |
418 | 418 | ||
419 | if(!to_remove) | 419 | if(!to_remove) |
420 | return; | 420 | return; |
421 | 421 | ||
422 | listView->removeItem(); | 422 | listView->removeItem(); |
423 | ds->removeItem(to_remove); | 423 | ds->removeItem(to_remove); |
424 | 424 | ||
425 | applyFilter(); | 425 | applyFilter(); |
426 | listView->rebuildData(); | 426 | listView->rebuildData(); |
427 | browseView->rebuildData(); | 427 | browseView->rebuildData(); |
428 | dirty = TRUE; | 428 | dirty = TRUE; |
429 | } | 429 | } |
430 | 430 | ||
431 | void TableViewerWindow::editKeysSlot() | 431 | void TableViewerWindow::editKeysSlot() |
432 | { | 432 | { |
433 | DataElem *d; | 433 | DataElem *d; |
434 | KeyList *k = TVKeyEdit::openEditKeysDialog(&ts, this); | 434 | KeyList *k = TVKeyEdit::openEditKeysDialog(&ts, this); |
435 | 435 | ||
436 | if(k) { | 436 | if(k) { |
437 | /* set as new keys */ | 437 | /* set as new keys */ |
438 | ds->setKeys(k); | 438 | ds->setKeys(k); |
439 | 439 | ||
440 | ts.current_column = 0; | 440 | ts.current_column = 0; |
441 | ts.kRep = k; | 441 | ts.kRep = k; |
442 | 442 | ||
443 | browseView->reset(); | 443 | browseView->reset(); |
444 | listView->reset(); | 444 | listView->reset(); |
445 | filterView->reset(); | 445 | filterView->reset(); |
446 | 446 | ||
447 | browseView->rebuildKeys(); | 447 | browseView->rebuildKeys(); |
448 | listView->rebuildKeys(); | 448 | listView->rebuildKeys(); |
449 | filterView->rebuildKeys(); | 449 | filterView->rebuildKeys(); |
450 | 450 | ||
451 | ds->first(); | 451 | ds->first(); |
452 | /* set up the list view */ | 452 | /* set up the list view */ |
453 | listView->clearItems(); | 453 | listView->clearItems(); |
454 | do { | 454 | do { |
455 | d = ds->getCurrentData(); | 455 | d = ds->getCurrentData(); |
456 | if(d) | 456 | if(d) |
457 | listView->addItem(d); | 457 | listView->addItem(d); |
458 | } while(ds->next()); | 458 | } while(ds->next()); |
459 | 459 | ||
460 | /* Set up browse view, Will be based of structure of listView */ | 460 | /* Set up browse view, Will be based of structure of listView */ |
461 | dirty = TRUE; | 461 | dirty = TRUE; |
462 | } | 462 | } |
463 | } | 463 | } |
464 | 464 | ||
465 | /*! | 465 | /*! |
466 | A Slot that allows for widgets above to indicate a search should be | 466 | A Slot that allows for widgets above to indicate a search should be |
467 | done on a specified key index for a specified value | 467 | done on a specified key index for a specified value |
468 | */ | 468 | */ |
469 | void TableViewerWindow::searchOnKey(int i, TVVariant v) | 469 | void TableViewerWindow::searchOnKey(int i, TVVariant v) |
470 | { | 470 | { |
471 | listView->findItem(i, v); | 471 | listView->findItem(i, v); |
472 | ts.current_elem = listView->getCurrentData(); | 472 | ts.current_elem = listView->getCurrentData(); |
473 | browseView->rebuildData(); | 473 | browseView->rebuildData(); |
474 | } | 474 | } |
475 | 475 | ||
476 | void TableViewerWindow::setPrimaryKey(int i) | 476 | void TableViewerWindow::setPrimaryKey(int i) |
477 | { | 477 | { |
478 | ts.current_column = i; | 478 | ts.current_column = i; |
479 | listView->rebuildData(); | 479 | listView->rebuildData(); |
480 | browseView->rebuildData(); | 480 | browseView->rebuildData(); |
481 | } | 481 | } |
diff --git a/noncore/comm/keypebble/kvnc.cpp b/noncore/comm/keypebble/kvnc.cpp index c89dec5..25c8919 100644 --- a/noncore/comm/keypebble/kvnc.cpp +++ b/noncore/comm/keypebble/kvnc.cpp | |||
@@ -1,295 +1,295 @@ | |||
1 | #include <qiconset.h> | 1 | #include <qiconset.h> |
2 | #include <qdialog.h> | 2 | #include <qdialog.h> |
3 | #include <qpixmap.h> | 3 | #include <qpixmap.h> |
4 | #include <qdom.h> | 4 | #include <qdom.h> |
5 | #include <qaction.h> | 5 | #include <qaction.h> |
6 | #include <qpe/qpemenubar.h> | 6 | #include <qmenubar.h> |
7 | #include <qstatusbar.h> | 7 | #include <qstatusbar.h> |
8 | #include <qpopupmenu.h> | 8 | #include <qpopupmenu.h> |
9 | #include <qpushbutton.h> | 9 | #include <qpushbutton.h> |
10 | #include <qpe/qpetoolbar.h> | 10 | #include <qpe/qpetoolbar.h> |
11 | #include <qtimer.h> | 11 | #include <qtimer.h> |
12 | #include <qmessagebox.h> | 12 | #include <qmessagebox.h> |
13 | #include <qspinbox.h> | 13 | #include <qspinbox.h> |
14 | #include <qlistbox.h> | 14 | #include <qlistbox.h> |
15 | #include <qlineedit.h> | 15 | #include <qlineedit.h> |
16 | #include <qpe/qpeapplication.h> | 16 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/global.h> | 17 | #include <qpe/global.h> |
18 | #include <qpe/qpetoolbar.h> | 18 | #include <qpe/qpetoolbar.h> |
19 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
20 | 20 | ||
21 | #include <assert.h> | 21 | #include <assert.h> |
22 | 22 | ||
23 | #include "kvnc.h" | 23 | #include "kvnc.h" |
24 | #include "krfbcanvas.h" | 24 | #include "krfbcanvas.h" |
25 | #include "krfbconnection.h" | 25 | #include "krfbconnection.h" |
26 | #include "kvncconndlg.h" | 26 | #include "kvncconndlg.h" |
27 | #include "krfbserver.h" | 27 | #include "krfbserver.h" |
28 | 28 | ||
29 | static int u_id = 1; | 29 | static int u_id = 1; |
30 | static int get_unique_id() | 30 | static int get_unique_id() |
31 | { | 31 | { |
32 | return u_id++; | 32 | return u_id++; |
33 | } | 33 | } |
34 | 34 | ||
35 | 35 | ||
36 | /* XPM */ | 36 | /* XPM */ |
37 | static char * menu_xpm[] = { | 37 | static char * menu_xpm[] = { |
38 | "12 12 5 1", | 38 | "12 12 5 1", |
39 | " c None", | 39 | " c None", |
40 | ".c #000000", | 40 | ".c #000000", |
41 | "+c #FFFDAD", | 41 | "+c #FFFDAD", |
42 | "@c #FFFF00", | 42 | "@c #FFFF00", |
43 | "#c #E5E100", | 43 | "#c #E5E100", |
44 | " ", | 44 | " ", |
45 | " ", | 45 | " ", |
46 | " ......... ", | 46 | " ......... ", |
47 | " .+++++++. ", | 47 | " .+++++++. ", |
48 | " .+@@@@#. ", | 48 | " .+@@@@#. ", |
49 | " .+@@@#. ", | 49 | " .+@@@#. ", |
50 | " .+@@#. ", | 50 | " .+@@#. ", |
51 | " .+@#. ", | 51 | " .+@#. ", |
52 | " .+#. ", | 52 | " .+#. ", |
53 | " .+. ", | 53 | " .+. ", |
54 | " .. ", | 54 | " .. ", |
55 | " "}; | 55 | " "}; |
56 | 56 | ||
57 | const int StatusTextId = 0; | 57 | const int StatusTextId = 0; |
58 | 58 | ||
59 | KVNC::KVNC( QWidget *parent, const char *name, WFlags f) : QMainWindow( 0, name ,WStyle_ContextHelp) | 59 | KVNC::KVNC( QWidget *parent, const char *name, WFlags f) : QMainWindow( 0, name ,WStyle_ContextHelp) |
60 | { | 60 | { |
61 | setCaption( tr("VNC Viewer") ); | 61 | setCaption( tr("VNC Viewer") ); |
62 | fullscreen = false; | 62 | fullscreen = false; |
63 | 63 | ||
64 | stack = new QWidgetStack( this ); | 64 | stack = new QWidgetStack( this ); |
65 | setCentralWidget( stack ); | 65 | setCentralWidget( stack ); |
66 | 66 | ||
67 | bookmarkSelector=new KVNCBookmarkDlg(); | 67 | bookmarkSelector=new KVNCBookmarkDlg(); |
68 | stack->addWidget(bookmarkSelector,get_unique_id()); | 68 | stack->addWidget(bookmarkSelector,get_unique_id()); |
69 | stack->raiseWidget( bookmarkSelector ); | 69 | stack->raiseWidget( bookmarkSelector ); |
70 | 70 | ||
71 | canvas = new KRFBCanvas( stack, "canvas" ); | 71 | canvas = new KRFBCanvas( stack, "canvas" ); |
72 | stack->addWidget(canvas,get_unique_id()); | 72 | stack->addWidget(canvas,get_unique_id()); |
73 | setCentralWidget( stack ); | 73 | setCentralWidget( stack ); |
74 | 74 | ||
75 | 75 | ||
76 | connect( bookmarkSelector->bookmarkList, SIGNAL(clicked(QListBoxItem *)), | 76 | connect( bookmarkSelector->bookmarkList, SIGNAL(clicked(QListBoxItem *)), |
77 | this, SLOT(openConnection(QListBoxItem *)) ); | 77 | this, SLOT(openConnection(QListBoxItem *)) ); |
78 | connect( canvas->connection(), SIGNAL(statusChanged(const QString &)), | 78 | connect( canvas->connection(), SIGNAL(statusChanged(const QString &)), |
79 | this, SLOT(statusMessage(const QString &)) ); | 79 | this, SLOT(statusMessage(const QString &)) ); |
80 | connect( canvas->connection(), SIGNAL(error(const QString &)), | 80 | connect( canvas->connection(), SIGNAL(error(const QString &)), |
81 | this, SLOT(error(const QString &)) ); | 81 | this, SLOT(error(const QString &)) ); |
82 | connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) ); | 82 | connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) ); |
83 | connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) ); | 83 | connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) ); |
84 | connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) ); | 84 | connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) ); |
85 | 85 | ||
86 | setupActions(); | 86 | setupActions(); |
87 | 87 | ||
88 | cornerButton = new QPushButton( this ); | 88 | cornerButton = new QPushButton( this ); |
89 | cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); | 89 | cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); |
90 | connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) ); | 90 | connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) ); |
91 | canvas->setCornerWidget( cornerButton ); | 91 | canvas->setCornerWidget( cornerButton ); |
92 | 92 | ||
93 | stack->raiseWidget( bookmarkSelector ); | 93 | stack->raiseWidget( bookmarkSelector ); |
94 | 94 | ||
95 | 95 | ||
96 | bar= new QToolBar( this ); | 96 | bar= new QToolBar( this ); |
97 | setToolBarsMovable( false ); | 97 | setToolBarsMovable( false ); |
98 | setRightJustification(false); | 98 | setRightJustification(false); |
99 | 99 | ||
100 | 100 | ||
101 | QAction *n = new QAction( tr( "New Connection" ), Resource::loadPixmap( "new" ), | 101 | QAction *n = new QAction( tr( "New Connection" ), Resource::loadPixmap( "new" ), |
102 | QString::null, 0, this, 0 ); | 102 | QString::null, 0, this, 0 ); |
103 | connect( n, SIGNAL( activated() ), | 103 | connect( n, SIGNAL( activated() ), |
104 | this, SLOT( newConnection() ) ); | 104 | this, SLOT( newConnection() ) ); |
105 | n->addTo( bar ); | 105 | n->addTo( bar ); |
106 | 106 | ||
107 | QAction *o = new QAction( tr( "Open Bookmark" ), Resource::loadPixmap( "fileopen" ), | 107 | QAction *o = new QAction( tr( "Open Bookmark" ), Resource::loadPixmap( "fileopen" ), |
108 | QString::null, 0, this, 0 ); | 108 | QString::null, 0, this, 0 ); |
109 | connect( o, SIGNAL( activated() ), | 109 | connect( o, SIGNAL( activated() ), |
110 | this, SLOT( openConnection() ) ); | 110 | this, SLOT( openConnection() ) ); |
111 | o->addTo( bar ); | 111 | o->addTo( bar ); |
112 | 112 | ||
113 | QAction *d = new QAction( tr( "Delete Bookmark" ), Resource::loadPixmap( "trash" ), | 113 | QAction *d = new QAction( tr( "Delete Bookmark" ), Resource::loadPixmap( "trash" ), |
114 | QString::null, 0, this, 0 ); | 114 | QString::null, 0, this, 0 ); |
115 | connect( d, SIGNAL( activated() ), | 115 | connect( d, SIGNAL( activated() ), |
116 | this, SLOT( deleteBookmark() ) ); | 116 | this, SLOT( deleteBookmark() ) ); |
117 | d->addTo( bar ); | 117 | d->addTo( bar ); |
118 | } | 118 | } |
119 | 119 | ||
120 | KVNC::~KVNC() | 120 | KVNC::~KVNC() |
121 | { | 121 | { |
122 | 122 | ||
123 | } | 123 | } |
124 | 124 | ||
125 | void KVNC::newConnection() | 125 | void KVNC::newConnection() |
126 | { | 126 | { |
127 | curServer=new KRFBServer; | 127 | curServer=new KRFBServer; |
128 | 128 | ||
129 | KVNCConnDlg dlg( curServer,this); | 129 | KVNCConnDlg dlg( curServer,this); |
130 | dlg.showMaximized(); | 130 | dlg.showMaximized(); |
131 | if (dlg.exec()) { | 131 | if (dlg.exec()) { |
132 | if (!curServer->name.isEmpty()) | 132 | if (!curServer->name.isEmpty()) |
133 | bookmarkSelector->addBookmark(curServer); | 133 | bookmarkSelector->addBookmark(curServer); |
134 | canvas->openConnection(*curServer); | 134 | canvas->openConnection(*curServer); |
135 | } else | 135 | } else |
136 | curServer=0; | 136 | curServer=0; |
137 | } | 137 | } |
138 | 138 | ||
139 | void KVNC::openConnection( QString name) | 139 | void KVNC::openConnection( QString name) |
140 | { | 140 | { |
141 | curServer=bookmarkSelector->getServer(name); | 141 | curServer=bookmarkSelector->getServer(name); |
142 | 142 | ||
143 | if (curServer) { | 143 | if (curServer) { |
144 | KVNCConnDlg dlg( curServer,this); | 144 | KVNCConnDlg dlg( curServer,this); |
145 | dlg.showMaximized(); | 145 | dlg.showMaximized(); |
146 | 146 | ||
147 | if ( dlg.exec() ) { | 147 | if ( dlg.exec() ) { |
148 | canvas->openConnection(*curServer); | 148 | canvas->openConnection(*curServer); |
149 | bookmarkSelector->writeBookmarks(); | 149 | bookmarkSelector->writeBookmarks(); |
150 | } else | 150 | } else |
151 | curServer=0; | 151 | curServer=0; |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | void KVNC::openConnection( void ) | 155 | void KVNC::openConnection( void ) |
156 | { | 156 | { |
157 | openConnection( bookmarkSelector->selectedBookmark()); | 157 | openConnection( bookmarkSelector->selectedBookmark()); |
158 | } | 158 | } |
159 | 159 | ||
160 | void KVNC::openConnection( QListBoxItem * item) | 160 | void KVNC::openConnection( QListBoxItem * item) |
161 | { | 161 | { |
162 | if (item) | 162 | if (item) |
163 | openConnection(item->text()); | 163 | openConnection(item->text()); |
164 | } | 164 | } |
165 | 165 | ||
166 | void KVNC::setupActions() | 166 | void KVNC::setupActions() |
167 | { | 167 | { |
168 | cornerMenu = new QPopupMenu( this ); | 168 | cornerMenu = new QPopupMenu( this ); |
169 | 169 | ||
170 | fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 ); | 170 | fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 ); |
171 | connect( fullScreenAction, SIGNAL(activated()), | 171 | connect( fullScreenAction, SIGNAL(activated()), |
172 | this, SLOT( toggleFullScreen() ) ); | 172 | this, SLOT( toggleFullScreen() ) ); |
173 | fullScreenAction->addTo( cornerMenu ); | 173 | fullScreenAction->addTo( cornerMenu ); |
174 | fullScreenAction->setEnabled( false ); | 174 | fullScreenAction->setEnabled( false ); |
175 | 175 | ||
176 | ctlAltDelAction = new QAction( tr("Send Contrl-Alt-Delete"), QString::null, 0, 0 ); | 176 | ctlAltDelAction = new QAction( tr("Send Contrl-Alt-Delete"), QString::null, 0, 0 ); |
177 | connect( ctlAltDelAction, SIGNAL(activated()), | 177 | connect( ctlAltDelAction, SIGNAL(activated()), |
178 | canvas, SLOT( sendCtlAltDel() ) ); | 178 | canvas, SLOT( sendCtlAltDel() ) ); |
179 | ctlAltDelAction->addTo( cornerMenu ); | 179 | ctlAltDelAction->addTo( cornerMenu ); |
180 | ctlAltDelAction->setEnabled( false ); | 180 | ctlAltDelAction->setEnabled( false ); |
181 | 181 | ||
182 | disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 ); | 182 | disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 ); |
183 | connect( disconnectAction, SIGNAL(activated()), | 183 | connect( disconnectAction, SIGNAL(activated()), |
184 | this, SLOT( closeConnection() ) ); | 184 | this, SLOT( closeConnection() ) ); |
185 | disconnectAction->addTo( cornerMenu ); | 185 | disconnectAction->addTo( cornerMenu ); |
186 | disconnectAction->setEnabled( false ); | 186 | disconnectAction->setEnabled( false ); |
187 | 187 | ||
188 | doubleClickAction = new QAction( tr("Next Click is Double Click"), QString::null, 0, 0 ); | 188 | doubleClickAction = new QAction( tr("Next Click is Double Click"), QString::null, 0, 0 ); |
189 | connect( doubleClickAction, SIGNAL(activated()), | 189 | connect( doubleClickAction, SIGNAL(activated()), |
190 | canvas, SLOT( markDoubleClick() ) ); | 190 | canvas, SLOT( markDoubleClick() ) ); |
191 | doubleClickAction->addTo( cornerMenu ); | 191 | doubleClickAction->addTo( cornerMenu ); |
192 | doubleClickAction->setEnabled( false ); | 192 | doubleClickAction->setEnabled( false ); |
193 | 193 | ||
194 | rightClickAction = new QAction( tr("Next Click is Right Click"), QString::null, 0, 0 ); | 194 | rightClickAction = new QAction( tr("Next Click is Right Click"), QString::null, 0, 0 ); |
195 | connect( rightClickAction, SIGNAL(activated()), | 195 | connect( rightClickAction, SIGNAL(activated()), |
196 | canvas, SLOT( markRightClick() ) ); | 196 | canvas, SLOT( markRightClick() ) ); |
197 | rightClickAction->addTo( cornerMenu ); | 197 | rightClickAction->addTo( cornerMenu ); |
198 | rightClickAction->setEnabled( false ); | 198 | rightClickAction->setEnabled( false ); |
199 | } | 199 | } |
200 | 200 | ||
201 | void KVNC::toggleFullScreen() | 201 | void KVNC::toggleFullScreen() |
202 | { | 202 | { |
203 | if ( fullscreen ) { | 203 | if ( fullscreen ) { |
204 | canvas->releaseKeyboard(); | 204 | canvas->releaseKeyboard(); |
205 | canvas->reparent( stack, 0, QPoint(0,0), false ); | 205 | canvas->reparent( stack, 0, QPoint(0,0), false ); |
206 | canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 206 | canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
207 | setCentralWidget( stack ); | 207 | setCentralWidget( stack ); |
208 | stack->addWidget(canvas,get_unique_id()); | 208 | stack->addWidget(canvas,get_unique_id()); |
209 | stack->raiseWidget(canvas); | 209 | stack->raiseWidget(canvas); |
210 | canvas->show(); | 210 | canvas->show(); |
211 | stack->show(); | 211 | stack->show(); |
212 | fullScreenAction->setText( tr("Full Screen") ); | 212 | fullScreenAction->setText( tr("Full Screen") ); |
213 | } else { | 213 | } else { |
214 | canvas->setFrameStyle( QFrame::NoFrame ); | 214 | canvas->setFrameStyle( QFrame::NoFrame ); |
215 | stack->removeWidget(canvas); | 215 | stack->removeWidget(canvas); |
216 | canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop, | 216 | canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop, |
217 | QPoint(0,0),false); | 217 | QPoint(0,0),false); |
218 | canvas->resize(qApp->desktop()->width(), qApp->desktop()->height()); | 218 | canvas->resize(qApp->desktop()->width(), qApp->desktop()->height()); |
219 | canvas->raise(); | 219 | canvas->raise(); |
220 | canvas->setFocus(); | 220 | canvas->setFocus(); |
221 | canvas->grabKeyboard(); | 221 | canvas->grabKeyboard(); |
222 | canvas->show(); | 222 | canvas->show(); |
223 | 223 | ||
224 | fullScreenAction->setText( tr("Stop Full Screen") ); | 224 | fullScreenAction->setText( tr("Stop Full Screen") ); |
225 | } | 225 | } |
226 | 226 | ||
227 | 227 | ||
228 | fullscreen = !fullscreen; | 228 | fullscreen = !fullscreen; |
229 | } | 229 | } |
230 | 230 | ||
231 | void KVNC::closeConnection() | 231 | void KVNC::closeConnection() |
232 | { | 232 | { |
233 | if ( fullscreen ) | 233 | if ( fullscreen ) |
234 | toggleFullScreen(); | 234 | toggleFullScreen(); |
235 | canvas->closeConnection(); | 235 | canvas->closeConnection(); |
236 | } | 236 | } |
237 | 237 | ||
238 | void KVNC::showMenu() | 238 | void KVNC::showMenu() |
239 | { | 239 | { |
240 | QPoint pt = mapToGlobal(cornerButton->pos()); | 240 | QPoint pt = mapToGlobal(cornerButton->pos()); |
241 | QSize s = cornerMenu->sizeHint(); | 241 | QSize s = cornerMenu->sizeHint(); |
242 | pt.ry() -= s.height(); | 242 | pt.ry() -= s.height(); |
243 | pt.rx() -= s.width(); | 243 | pt.rx() -= s.width(); |
244 | cornerMenu->popup( pt ); | 244 | cornerMenu->popup( pt ); |
245 | } | 245 | } |
246 | 246 | ||
247 | void KVNC::connected() | 247 | void KVNC::connected() |
248 | { | 248 | { |
249 | static QString msg = tr( "Connected to remote host" ); | 249 | static QString msg = tr( "Connected to remote host" ); |
250 | statusMessage( msg ); | 250 | statusMessage( msg ); |
251 | ctlAltDelAction->setEnabled(true); | 251 | ctlAltDelAction->setEnabled(true); |
252 | disconnectAction->setEnabled( true ); | 252 | disconnectAction->setEnabled( true ); |
253 | fullScreenAction->setEnabled( true ); | 253 | fullScreenAction->setEnabled( true ); |
254 | doubleClickAction->setEnabled( false ); | 254 | doubleClickAction->setEnabled( false ); |
255 | rightClickAction->setEnabled( true ); | 255 | rightClickAction->setEnabled( true ); |
256 | stack->raiseWidget(canvas); | 256 | stack->raiseWidget(canvas); |
257 | bar->hide(); | 257 | bar->hide(); |
258 | } | 258 | } |
259 | 259 | ||
260 | void KVNC::loggedIn() | 260 | void KVNC::loggedIn() |
261 | { | 261 | { |
262 | static QString msg = tr( "Logged in to remote host" ); | 262 | static QString msg = tr( "Logged in to remote host" ); |
263 | statusMessage( msg ); | 263 | statusMessage( msg ); |
264 | } | 264 | } |
265 | 265 | ||
266 | void KVNC::disconnected() | 266 | void KVNC::disconnected() |
267 | { | 267 | { |
268 | 268 | ||
269 | if ( fullscreen ) | 269 | if ( fullscreen ) |
270 | toggleFullScreen(); | 270 | toggleFullScreen(); |
271 | static QString msg = tr( "Connection closed" ); | 271 | static QString msg = tr( "Connection closed" ); |
272 | statusMessage( msg ); | 272 | statusMessage( msg ); |
273 | ctlAltDelAction->setEnabled(false); | 273 | ctlAltDelAction->setEnabled(false); |
274 | disconnectAction->setEnabled( false ); | 274 | disconnectAction->setEnabled( false ); |
275 | fullScreenAction->setEnabled( false ); | 275 | fullScreenAction->setEnabled( false ); |
276 | doubleClickAction->setEnabled( false ); | 276 | doubleClickAction->setEnabled( false ); |
277 | rightClickAction->setEnabled( false ); | 277 | rightClickAction->setEnabled( false ); |
278 | stack->raiseWidget(bookmarkSelector); | 278 | stack->raiseWidget(bookmarkSelector); |
279 | bar->show(); | 279 | bar->show(); |
280 | } | 280 | } |
281 | 281 | ||
282 | void KVNC::statusMessage( const QString &m ) | 282 | void KVNC::statusMessage( const QString &m ) |
283 | { | 283 | { |
284 | Global::statusMessage( m ); | 284 | Global::statusMessage( m ); |
285 | } | 285 | } |
286 | 286 | ||
287 | void KVNC::error( const QString &msg ) | 287 | void KVNC::error( const QString &msg ) |
288 | { | 288 | { |
289 | statusMessage( msg ); | 289 | statusMessage( msg ); |
290 | QMessageBox::warning( this, tr("VNC Viewer"), msg ); | 290 | QMessageBox::warning( this, tr("VNC Viewer"), msg ); |
291 | } | 291 | } |
292 | void KVNC::deleteBookmark(void) | 292 | void KVNC::deleteBookmark(void) |
293 | { | 293 | { |
294 | bookmarkSelector->deleteBookmark(bookmarkSelector->selectedBookmark()); | 294 | bookmarkSelector->deleteBookmark(bookmarkSelector->selectedBookmark()); |
295 | } | 295 | } |
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp index 755ed10..e9e5467 100644 --- a/noncore/games/backgammon/backgammon.cpp +++ b/noncore/games/backgammon/backgammon.cpp | |||
@@ -1,974 +1,974 @@ | |||
1 | #include "backgammon.h" | 1 | #include "backgammon.h" |
2 | 2 | ||
3 | #include "aidialog.h" | 3 | #include "aidialog.h" |
4 | #include "filedialog.h" | 4 | #include "filedialog.h" |
5 | #include "playerdialog.h" | 5 | #include "playerdialog.h" |
6 | #include "rulesdialog.h" | 6 | #include "rulesdialog.h" |
7 | #include "themedialog.h" | 7 | #include "themedialog.h" |
8 | 8 | ||
9 | #include <qdatetime.h> | 9 | #include <qdatetime.h> |
10 | #include <qfile.h> | 10 | #include <qfile.h> |
11 | #include <qlayout.h> | 11 | #include <qlayout.h> |
12 | #include <qmessagebox.h> | 12 | #include <qmessagebox.h> |
13 | #include <qstring.h> | 13 | #include <qstring.h> |
14 | #include <qtimer.h> | 14 | #include <qtimer.h> |
15 | #include <qmainwindow.h> | 15 | #include <qmainwindow.h> |
16 | #include <qpe/qpeapplication.h> | 16 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/config.h> | 17 | #include <qpe/config.h> |
18 | #include <qpe/qpemenubar.h> | 18 | #include <qmenubar.h> |
19 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
20 | 20 | ||
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | 22 | ||
23 | 23 | ||
24 | BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) | 24 | BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) |
25 | : QMainWindow(parent, name, fl) | 25 | : QMainWindow(parent, name, fl) |
26 | { | 26 | { |
27 | if (!name) setName("BackGammon"); | 27 | if (!name) setName("BackGammon"); |
28 | setCaption(tr( "Backgammon") ); | 28 | setCaption(tr( "Backgammon") ); |
29 | setIcon( Resource::loadPixmap( "backgammon" ) ); | 29 | setIcon( Resource::loadPixmap( "backgammon" ) ); |
30 | //general counter varaible | 30 | //general counter varaible |
31 | int a=0; | 31 | int a=0; |
32 | //the game engine | 32 | //the game engine |
33 | move=new MoveEngine(); | 33 | move=new MoveEngine(); |
34 | 34 | ||
35 | //load the default theme | 35 | //load the default theme |
36 | Config conf("backgammon"); | 36 | Config conf("backgammon"); |
37 | if(!conf.isValid()) | 37 | if(!conf.isValid()) |
38 | { | 38 | { |
39 | qDebug("config file does not exist"); | 39 | qDebug("config file does not exist"); |
40 | conf.setGroup("general"); | 40 | conf.setGroup("general"); |
41 | conf.writeEntry("theme","default"); | 41 | conf.writeEntry("theme","default"); |
42 | conf.setGroup("rules"); | 42 | conf.setGroup("rules"); |
43 | conf.writeEntry("move_with_pieces_out",false); | 43 | conf.writeEntry("move_with_pieces_out",false); |
44 | conf.writeEntry("nice_dice",false); | 44 | conf.writeEntry("nice_dice",false); |
45 | conf.setGroup("display"); | 45 | conf.setGroup("display"); |
46 | conf.writeEntry("small",false); | 46 | conf.writeEntry("small",false); |
47 | conf.writeEntry("warning",true); | 47 | conf.writeEntry("warning",true); |
48 | conf.setGroup("ai"); | 48 | conf.setGroup("ai"); |
49 | conf.writeEntry("rescue",6); | 49 | conf.writeEntry("rescue",6); |
50 | conf.writeEntry("eliminate",4); | 50 | conf.writeEntry("eliminate",4); |
51 | conf.writeEntry("expose",1); | 51 | conf.writeEntry("expose",1); |
52 | conf.writeEntry("protect",5); | 52 | conf.writeEntry("protect",5); |
53 | conf.writeEntry("safe",3); | 53 | conf.writeEntry("safe",3); |
54 | conf.writeEntry("empty",2); | 54 | conf.writeEntry("empty",2); |
55 | 55 | ||
56 | } | 56 | } |
57 | conf.setGroup("general"); | 57 | conf.setGroup("general"); |
58 | theme_name=conf.readEntry("theme","default"); | 58 | theme_name=conf.readEntry("theme","default"); |
59 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 59 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
60 | 60 | ||
61 | //the rules | 61 | //the rules |
62 | conf.setGroup("rules"); | 62 | conf.setGroup("rules"); |
63 | rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false); | 63 | rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false); |
64 | rules.generous_dice=conf.readBoolEntry("nice_dice",false); | 64 | rules.generous_dice=conf.readBoolEntry("nice_dice",false); |
65 | 65 | ||
66 | move->setRules(rules); | 66 | move->setRules(rules); |
67 | 67 | ||
68 | //get the AI settings | 68 | //get the AI settings |
69 | AISettings ai; | 69 | AISettings ai; |
70 | conf.setGroup("ai"); | 70 | conf.setGroup("ai"); |
71 | ai.rescue=conf.readNumEntry("rescue",6); | 71 | ai.rescue=conf.readNumEntry("rescue",6); |
72 | ai.eliminate=conf.readNumEntry("eliminate",4); | 72 | ai.eliminate=conf.readNumEntry("eliminate",4); |
73 | ai.expose=conf.readNumEntry("expose",1); | 73 | ai.expose=conf.readNumEntry("expose",1); |
74 | ai.protect=conf.readNumEntry("protect",5); | 74 | ai.protect=conf.readNumEntry("protect",5); |
75 | ai.safe=conf.readNumEntry("safe",3); | 75 | ai.safe=conf.readNumEntry("safe",3); |
76 | ai.empty=conf.readNumEntry("empty",2); | 76 | ai.empty=conf.readNumEntry("empty",2); |
77 | move->setAISettings(ai); | 77 | move->setAISettings(ai); |
78 | 78 | ||
79 | 79 | ||
80 | //get the theme component names | 80 | //get the theme component names |
81 | Config theme(theme_file,Config::File); | 81 | Config theme(theme_file,Config::File); |
82 | if(!theme.isValid()) | 82 | if(!theme.isValid()) |
83 | { | 83 | { |
84 | qDebug("theme file does not exist"); | 84 | qDebug("theme file does not exist"); |
85 | theme.setGroup("theme"); | 85 | theme.setGroup("theme"); |
86 | theme.writeEntry("board","casino_board_1"); | 86 | theme.writeEntry("board","casino_board_1"); |
87 | theme.writeEntry("pieces1","casino_pieces_blue"); | 87 | theme.writeEntry("pieces1","casino_pieces_blue"); |
88 | theme.writeEntry("pieces2","casino_pieces_white"); | 88 | theme.writeEntry("pieces2","casino_pieces_white"); |
89 | theme.writeEntry("dice1","casino_dice"); | 89 | theme.writeEntry("dice1","casino_dice"); |
90 | theme.writeEntry("dice2","casino_dice"); | 90 | theme.writeEntry("dice2","casino_dice"); |
91 | theme.writeEntry("table","casino_table_green"); | 91 | theme.writeEntry("table","casino_table_green"); |
92 | theme.writeEntry("odds","casino_odds"); | 92 | theme.writeEntry("odds","casino_odds"); |
93 | } | 93 | } |
94 | theme.setGroup("theme"); | 94 | theme.setGroup("theme"); |
95 | board_name=theme.readEntry("board","casino_board_1"); | 95 | board_name=theme.readEntry("board","casino_board_1"); |
96 | piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); | 96 | piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); |
97 | piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); | 97 | piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); |
98 | diceA_name=theme.readEntry("dice1","casino_dice"); | 98 | diceA_name=theme.readEntry("dice1","casino_dice"); |
99 | diceB_name=theme.readEntry("dice2","casino_dice"); | 99 | diceB_name=theme.readEntry("dice2","casino_dice"); |
100 | table_name=theme.readEntry("table","casino_table_green"); | 100 | table_name=theme.readEntry("table","casino_table_green"); |
101 | odds_name=theme.readEntry("odds","casino_odds"); | 101 | odds_name=theme.readEntry("odds","casino_odds"); |
102 | 102 | ||
103 | 103 | ||
104 | //the menu | 104 | //the menu |
105 | QMenuBar* menuBar = new QMenuBar(this); | 105 | QMenuBar* menuBar = new QMenuBar(this); |
106 | 106 | ||
107 | QPopupMenu* gamemenu= new QPopupMenu(this); | 107 | QPopupMenu* gamemenu= new QPopupMenu(this); |
108 | gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); | 108 | gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); |
109 | gamemenu->insertSeparator(); | 109 | gamemenu->insertSeparator(); |
110 | gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); | 110 | gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); |
111 | gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); | 111 | gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); |
112 | gamemenu->insertSeparator(); | 112 | gamemenu->insertSeparator(); |
113 | gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); | 113 | gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); |
114 | menuBar->insertItem(tr( "Game" ),gamemenu); | 114 | menuBar->insertItem(tr( "Game" ),gamemenu); |
115 | 115 | ||
116 | QPopupMenu* thememenu= new QPopupMenu(this); | 116 | QPopupMenu* thememenu= new QPopupMenu(this); |
117 | thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); | 117 | thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); |
118 | thememenu->insertSeparator(); | 118 | thememenu->insertSeparator(); |
119 | thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); | 119 | thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); |
120 | thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); | 120 | thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); |
121 | thememenu->insertSeparator(); | 121 | thememenu->insertSeparator(); |
122 | thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); | 122 | thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); |
123 | thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); | 123 | thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); |
124 | menuBar->insertItem(tr( "Theme" ),thememenu); | 124 | menuBar->insertItem(tr( "Theme" ),thememenu); |
125 | 125 | ||
126 | QPopupMenu* optionmenu=new QPopupMenu(this); | 126 | QPopupMenu* optionmenu=new QPopupMenu(this); |
127 | optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); | 127 | optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); |
128 | optionmenu->insertSeparator(); | 128 | optionmenu->insertSeparator(); |
129 | optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); | 129 | optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); |
130 | optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); | 130 | optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); |
131 | menuBar->insertItem(tr( "Options"),optionmenu); | 131 | menuBar->insertItem(tr( "Options"),optionmenu); |
132 | 132 | ||
133 | QWidget* mainarea=new QWidget(this); | 133 | QWidget* mainarea=new QWidget(this); |
134 | setCentralWidget(mainarea); | 134 | setCentralWidget(mainarea); |
135 | //the main area | 135 | //the main area |
136 | QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); | 136 | QBoxLayout* layout=new QBoxLayout(mainarea,QBoxLayout::TopToBottom); |
137 | area=new QCanvas(235,235); | 137 | area=new QCanvas(235,235); |
138 | boardview=new BackGammonView(area,mainarea); | 138 | boardview=new BackGammonView(area,mainarea); |
139 | boardview->setMaximumHeight(240); | 139 | boardview->setMaximumHeight(240); |
140 | layout->addWidget(boardview); | 140 | layout->addWidget(boardview); |
141 | connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); | 141 | connect(boardview,SIGNAL(mouse(int,int)),this,SLOT(mouse(int,int))); |
142 | //status bar | 142 | //status bar |
143 | message=new QLabel("<b>Backgammon</b>",mainarea); | 143 | message=new QLabel("<b>Backgammon</b>",mainarea); |
144 | message->setAlignment(AlignHCenter); | 144 | message->setAlignment(AlignHCenter); |
145 | layout->addWidget(message); | 145 | layout->addWidget(message); |
146 | 146 | ||
147 | //the marker | 147 | //the marker |
148 | marker_current=new QCanvasRectangle(area); | 148 | marker_current=new QCanvasRectangle(area); |
149 | marker_current->setBrush(QColor(0,0,255)); | 149 | marker_current->setBrush(QColor(0,0,255)); |
150 | marker_current->setSize(15,5); | 150 | marker_current->setSize(15,5); |
151 | marker_current->setZ(1); | 151 | marker_current->setZ(1); |
152 | 152 | ||
153 | for(a=0;a<4;a++) | 153 | for(a=0;a<4;a++) |
154 | { | 154 | { |
155 | marker_next[a]=new QCanvasRectangle(area); | 155 | marker_next[a]=new QCanvasRectangle(area); |
156 | marker_next[a]->setBrush(QColor(0,255,0)); | 156 | marker_next[a]->setBrush(QColor(0,255,0)); |
157 | marker_next[a]->setSize(15,5); | 157 | marker_next[a]->setSize(15,5); |
158 | marker_next[a]->setZ(1); | 158 | marker_next[a]->setZ(1); |
159 | } | 159 | } |
160 | 160 | ||
161 | connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); | 161 | connect(move,SIGNAL(done_dice1()),this,SLOT(done_dice1())); |
162 | connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); | 162 | connect(move,SIGNAL(done_dice2()),this,SLOT(done_dice2())); |
163 | connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); | 163 | connect(move,SIGNAL(done_dice3()),this,SLOT(done_dice3())); |
164 | connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); | 164 | connect(move,SIGNAL(done_dice4()),this,SLOT(done_dice4())); |
165 | connect(move,SIGNAL(nomove()),this,SLOT(nomove())); | 165 | connect(move,SIGNAL(nomove()),this,SLOT(nomove())); |
166 | connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); | 166 | connect(move,SIGNAL(player_finished(int)),this,SLOT(finished(int))); |
167 | 167 | ||
168 | //the pieces | 168 | //the pieces |
169 | p1=new CanvasImageItem*[15]; | 169 | p1=new CanvasImageItem*[15]; |
170 | p1_side=new CanvasImageItem*[15]; | 170 | p1_side=new CanvasImageItem*[15]; |
171 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); | 171 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); |
172 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); | 172 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); |
173 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); | 173 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); |
174 | 174 | ||
175 | p2=new CanvasImageItem*[15]; | 175 | p2=new CanvasImageItem*[15]; |
176 | p2_side=new CanvasImageItem*[15]; | 176 | p2_side=new CanvasImageItem*[15]; |
177 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); | 177 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); |
178 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); | 178 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); |
179 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); | 179 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); |
180 | 180 | ||
181 | 181 | ||
182 | for(a=0;a<15;a++) | 182 | for(a=0;a<15;a++) |
183 | { | 183 | { |
184 | p1[a]=new CanvasImageItem(piece_1_front,area); | 184 | p1[a]=new CanvasImageItem(piece_1_front,area); |
185 | p1[a]->setSize(15,15); | 185 | p1[a]->setSize(15,15); |
186 | p1_side[a]=new CanvasImageItem(piece_1_side,area); | 186 | p1_side[a]=new CanvasImageItem(piece_1_side,area); |
187 | p1_side[a]->setSize(15,5); | 187 | p1_side[a]->setSize(15,5); |
188 | 188 | ||
189 | p2[a]=new CanvasImageItem(piece_2_front,area); | 189 | p2[a]=new CanvasImageItem(piece_2_front,area); |
190 | p2[a]->setSize(15,15); | 190 | p2[a]->setSize(15,15); |
191 | p2_side[a]=new CanvasImageItem(piece_2_side,area); | 191 | p2_side[a]=new CanvasImageItem(piece_2_side,area); |
192 | p2_side[a]->setSize(15,5); | 192 | p2_side[a]->setSize(15,5); |
193 | } | 193 | } |
194 | draw(); | 194 | draw(); |
195 | 195 | ||
196 | //the dice | 196 | //the dice |
197 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); | 197 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); |
198 | diceA1=new CanvasImageItem*[7]; | 198 | diceA1=new CanvasImageItem*[7]; |
199 | diceA2=new CanvasImageItem*[7]; | 199 | diceA2=new CanvasImageItem*[7]; |
200 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); | 200 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); |
201 | diceB1=new CanvasImageItem*[7]; | 201 | diceB1=new CanvasImageItem*[7]; |
202 | diceB2=new CanvasImageItem*[7]; | 202 | diceB2=new CanvasImageItem*[7]; |
203 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); | 203 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); |
204 | //oddsDice=new CanvasImageItem*[6]; | 204 | //oddsDice=new CanvasImageItem*[6]; |
205 | 205 | ||
206 | 206 | ||
207 | for(a=0;a<7;a++) | 207 | for(a=0;a<7;a++) |
208 | { | 208 | { |
209 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); | 209 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); |
210 | diceA1[a]=new CanvasImageItem(dicebgA,area); | 210 | diceA1[a]=new CanvasImageItem(dicebgA,area); |
211 | diceA1[a]->setX(5); | 211 | diceA1[a]->setX(5); |
212 | diceA1[a]->setY(205-2); | 212 | diceA1[a]->setY(205-2); |
213 | diceA1[a]->setZ(1); | 213 | diceA1[a]->setZ(1); |
214 | diceA1[a]->setSize(25,25); | 214 | diceA1[a]->setSize(25,25); |
215 | diceA2[a]=new CanvasImageItem(dicebgA,area); | 215 | diceA2[a]=new CanvasImageItem(dicebgA,area); |
216 | diceA2[a]->setX(35); | 216 | diceA2[a]->setX(35); |
217 | diceA2[a]->setY(205-2); | 217 | diceA2[a]->setY(205-2); |
218 | diceA2[a]->setZ(1); | 218 | diceA2[a]->setZ(1); |
219 | diceA2[a]->setSize(25,25); | 219 | diceA2[a]->setSize(25,25); |
220 | 220 | ||
221 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); | 221 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); |
222 | diceB1[a]=new CanvasImageItem(dicebgB,area); | 222 | diceB1[a]=new CanvasImageItem(dicebgB,area); |
223 | diceB1[a]->setX(175); | 223 | diceB1[a]->setX(175); |
224 | diceB1[a]->setY(205-2); | 224 | diceB1[a]->setY(205-2); |
225 | diceB1[a]->setZ(1); | 225 | diceB1[a]->setZ(1); |
226 | diceB1[a]->setSize(25,25); | 226 | diceB1[a]->setSize(25,25); |
227 | diceB2[a]=new CanvasImageItem(dicebgB,area); | 227 | diceB2[a]=new CanvasImageItem(dicebgB,area); |
228 | diceB2[a]->setX(205); | 228 | diceB2[a]->setX(205); |
229 | diceB2[a]->setY(205-2); | 229 | diceB2[a]->setY(205-2); |
230 | diceB2[a]->setZ(1); | 230 | diceB2[a]->setZ(1); |
231 | diceB2[a]->setSize(25,25); | 231 | diceB2[a]->setSize(25,25); |
232 | 232 | ||
233 | /* | 233 | /* |
234 | if(a<6) | 234 | if(a<6) |
235 | { | 235 | { |
236 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); | 236 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); |
237 | oddsDice[a]=new CanvasImageItem(oddsbg,area); | 237 | oddsDice[a]=new CanvasImageItem(oddsbg,area); |
238 | oddsDice[a]->setX(110); | 238 | oddsDice[a]->setX(110); |
239 | oddsDice[a]->setY(210-2); | 239 | oddsDice[a]->setY(210-2); |
240 | oddsDice[a]->setZ(1); | 240 | oddsDice[a]->setZ(1); |
241 | oddsDice[a]->setSize(15,15); | 241 | oddsDice[a]->setSize(15,15); |
242 | oddsDice[a]->hide(); | 242 | oddsDice[a]->hide(); |
243 | } | 243 | } |
244 | */ | 244 | */ |
245 | } | 245 | } |
246 | //oddsDice[0]->show(); | 246 | //oddsDice[0]->show(); |
247 | 247 | ||
248 | //set the board | 248 | //set the board |
249 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); | 249 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); |
250 | board=new CanvasImageItem(boardbg,area); | 250 | board=new CanvasImageItem(boardbg,area); |
251 | board->setX(0); | 251 | board->setX(0); |
252 | board->setY(0); | 252 | board->setY(0); |
253 | board->setZ(0); | 253 | board->setZ(0); |
254 | board->setSize(235-2,200-2); | 254 | board->setSize(235-2,200-2); |
255 | board->show(); | 255 | board->show(); |
256 | 256 | ||
257 | //the table | 257 | //the table |
258 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); | 258 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); |
259 | table=new CanvasImageItem(tablebg,area); | 259 | table=new CanvasImageItem(tablebg,area); |
260 | table->setX(0); | 260 | table->setX(0); |
261 | table->setY(200-2); | 261 | table->setY(200-2); |
262 | table->setZ(0); | 262 | table->setZ(0); |
263 | table->setSize(235-2,20); | 263 | table->setSize(235-2,20); |
264 | table->show(); | 264 | table->show(); |
265 | 265 | ||
266 | //the no move marker | 266 | //the no move marker |
267 | QImage nomovebg(Resource::loadImage("backgammon/no_move")); | 267 | QImage nomovebg(Resource::loadImage("backgammon/no_move")); |
268 | nomove_marker=new CanvasImageItem(nomovebg,area); | 268 | nomove_marker=new CanvasImageItem(nomovebg,area); |
269 | nomove_marker->setX(0); | 269 | nomove_marker->setX(0); |
270 | nomove_marker->setY(200); | 270 | nomove_marker->setY(200); |
271 | nomove_marker->setZ(2); | 271 | nomove_marker->setZ(2); |
272 | nomove_marker->hide(); | 272 | nomove_marker->hide(); |
273 | 273 | ||
274 | //default human against computer | 274 | //default human against computer |
275 | player1_auto=false; | 275 | player1_auto=false; |
276 | player2_auto=true; | 276 | player2_auto=true; |
277 | //start new game | 277 | //start new game |
278 | newgame(); | 278 | newgame(); |
279 | } | 279 | } |
280 | 280 | ||
281 | BackGammon::~BackGammon() | 281 | BackGammon::~BackGammon() |
282 | { | 282 | { |
283 | //DESTRUCTOR | 283 | //DESTRUCTOR |
284 | } | 284 | } |
285 | 285 | ||
286 | void BackGammon::newgame() | 286 | void BackGammon::newgame() |
287 | { | 287 | { |
288 | gameFinished=false; | 288 | gameFinished=false; |
289 | QDateTime now=QDateTime::currentDateTime(); | 289 | QDateTime now=QDateTime::currentDateTime(); |
290 | game_name=now.date().toString()+"_"+now.time().toString(); | 290 | game_name=now.date().toString()+"_"+now.time().toString(); |
291 | move->reset(); | 291 | move->reset(); |
292 | draw(); | 292 | draw(); |
293 | diceA1_value=7; | 293 | diceA1_value=7; |
294 | diceA2_value=7; | 294 | diceA2_value=7; |
295 | diceA3_value=7; | 295 | diceA3_value=7; |
296 | diceA4_value=7; | 296 | diceA4_value=7; |
297 | diceB1_value=7; | 297 | diceB1_value=7; |
298 | diceB2_value=7; | 298 | diceB2_value=7; |
299 | diceB3_value=7; | 299 | diceB3_value=7; |
300 | diceB4_value=7; | 300 | diceB4_value=7; |
301 | showdice(); | 301 | showdice(); |
302 | player=2; | 302 | player=2; |
303 | dice1_played=true; | 303 | dice1_played=true; |
304 | dice2_played=true; | 304 | dice2_played=true; |
305 | dice3_played=true; | 305 | dice3_played=true; |
306 | dice4_played=true; | 306 | dice4_played=true; |
307 | dice_rolled=false; | 307 | dice_rolled=false; |
308 | setplayer(); | 308 | setplayer(); |
309 | area->update(); | 309 | area->update(); |
310 | } | 310 | } |
311 | 311 | ||
312 | void BackGammon::playerselect() | 312 | void BackGammon::playerselect() |
313 | { | 313 | { |
314 | PlayerDialog* playerdialog=new PlayerDialog(this); | 314 | PlayerDialog* playerdialog=new PlayerDialog(this); |
315 | playerdialog->setAuto1(player1_auto); | 315 | playerdialog->setAuto1(player1_auto); |
316 | playerdialog->setAuto2(player2_auto); | 316 | playerdialog->setAuto2(player2_auto); |
317 | if(!playerdialog->exec()) | 317 | if(!playerdialog->exec()) |
318 | return; | 318 | return; |
319 | player1_auto=playerdialog->getAuto1(); | 319 | player1_auto=playerdialog->getAuto1(); |
320 | player2_auto=playerdialog->getAuto2(); | 320 | player2_auto=playerdialog->getAuto2(); |
321 | } | 321 | } |
322 | 322 | ||
323 | void BackGammon::loadgame() | 323 | void BackGammon::loadgame() |
324 | { | 324 | { |
325 | FileDialog* file=new FileDialog(this,"Load Game",".game"); | 325 | FileDialog* file=new FileDialog(this,"Load Game",".game"); |
326 | if(!file->exec()) | 326 | if(!file->exec()) |
327 | return; | 327 | return; |
328 | 328 | ||
329 | game_name=file->filename(); | 329 | game_name=file->filename(); |
330 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 330 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
331 | 331 | ||
332 | Config game(game_file,Config::File); | 332 | Config game(game_file,Config::File); |
333 | game.setGroup("dice"); | 333 | game.setGroup("dice"); |
334 | diceA1_value=game.readNumEntry("diceA1_value"); | 334 | diceA1_value=game.readNumEntry("diceA1_value"); |
335 | diceA2_value=game.readNumEntry("diceA2_value"); | 335 | diceA2_value=game.readNumEntry("diceA2_value"); |
336 | diceA3_value=game.readNumEntry("diceA3_value"); | 336 | diceA3_value=game.readNumEntry("diceA3_value"); |
337 | diceA4_value=game.readNumEntry("diceA4_value"); | 337 | diceA4_value=game.readNumEntry("diceA4_value"); |
338 | diceB1_value=game.readNumEntry("diceB1_value"); | 338 | diceB1_value=game.readNumEntry("diceB1_value"); |
339 | diceB2_value=game.readNumEntry("diceB2_value"); | 339 | diceB2_value=game.readNumEntry("diceB2_value"); |
340 | diceB3_value=game.readNumEntry("diceB3_value"); | 340 | diceB3_value=game.readNumEntry("diceB3_value"); |
341 | diceB4_value=game.readNumEntry("diceB4_value"); | 341 | diceB4_value=game.readNumEntry("diceB4_value"); |
342 | player=game.readNumEntry("player"); | 342 | player=game.readNumEntry("player"); |
343 | dice1_played=game.readBoolEntry("dice1_played"); | 343 | dice1_played=game.readBoolEntry("dice1_played"); |
344 | dice2_played=game.readBoolEntry("dice2_played"); | 344 | dice2_played=game.readBoolEntry("dice2_played"); |
345 | dice3_played=game.readBoolEntry("dice3_played"); | 345 | dice3_played=game.readBoolEntry("dice3_played"); |
346 | dice4_played=game.readBoolEntry("dice4_played"); | 346 | dice4_played=game.readBoolEntry("dice4_played"); |
347 | dice_rolled=game.readBoolEntry("dice_rolled"); | 347 | dice_rolled=game.readBoolEntry("dice_rolled"); |
348 | player1_auto=game.readBoolEntry("player1_auto"); | 348 | player1_auto=game.readBoolEntry("player1_auto"); |
349 | player2_auto=game.readBoolEntry("player2_auto"); | 349 | player2_auto=game.readBoolEntry("player2_auto"); |
350 | 350 | ||
351 | game.setGroup("pieces"); | 351 | game.setGroup("pieces"); |
352 | QString label; | 352 | QString label; |
353 | LoadSave load; | 353 | LoadSave load; |
354 | for(int a=0;a<28;a++) | 354 | for(int a=0;a<28;a++) |
355 | { | 355 | { |
356 | label.setNum(a); | 356 | label.setNum(a); |
357 | load.pop[a].total = game.readNumEntry(label,0); | 357 | load.pop[a].total = game.readNumEntry(label,0); |
358 | } | 358 | } |
359 | 359 | ||
360 | move->loadGame(load); | 360 | move->loadGame(load); |
361 | setplayer(); | 361 | setplayer(); |
362 | showdice(); | 362 | showdice(); |
363 | draw(); | 363 | draw(); |
364 | area->update(); | 364 | area->update(); |
365 | } | 365 | } |
366 | 366 | ||
367 | void BackGammon::savegame() | 367 | void BackGammon::savegame() |
368 | { | 368 | { |
369 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 369 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
370 | 370 | ||
371 | Config game(game_file,Config::File); | 371 | Config game(game_file,Config::File); |
372 | game.setGroup("dice"); | 372 | game.setGroup("dice"); |
373 | game.writeEntry("diceA1_value",diceA1_value); | 373 | game.writeEntry("diceA1_value",diceA1_value); |
374 | game.writeEntry("diceA2_value",diceA2_value); | 374 | game.writeEntry("diceA2_value",diceA2_value); |
375 | game.writeEntry("diceA3_value",diceA3_value); | 375 | game.writeEntry("diceA3_value",diceA3_value); |
376 | game.writeEntry("diceA4_value",diceA4_value); | 376 | game.writeEntry("diceA4_value",diceA4_value); |
377 | game.writeEntry("diceB1_value",diceB1_value); | 377 | game.writeEntry("diceB1_value",diceB1_value); |
378 | game.writeEntry("diceB2_value",diceB3_value); | 378 | game.writeEntry("diceB2_value",diceB3_value); |
379 | game.writeEntry("diceB3_value",diceB4_value); | 379 | game.writeEntry("diceB3_value",diceB4_value); |
380 | game.writeEntry("diceB4_value",diceB4_value); | 380 | game.writeEntry("diceB4_value",diceB4_value); |
381 | game.writeEntry("player",player); | 381 | game.writeEntry("player",player); |
382 | game.writeEntry("dice1_played",dice1_played); | 382 | game.writeEntry("dice1_played",dice1_played); |
383 | game.writeEntry("dice2_played",dice2_played); | 383 | game.writeEntry("dice2_played",dice2_played); |
384 | game.writeEntry("dice3_played",dice3_played); | 384 | game.writeEntry("dice3_played",dice3_played); |
385 | game.writeEntry("dice4_played",dice4_played); | 385 | game.writeEntry("dice4_played",dice4_played); |
386 | game.writeEntry("dice_rolled",dice_rolled); | 386 | game.writeEntry("dice_rolled",dice_rolled); |
387 | game.writeEntry("player1_auto",player1_auto); | 387 | game.writeEntry("player1_auto",player1_auto); |
388 | game.writeEntry("player2_auto",player2_auto); | 388 | game.writeEntry("player2_auto",player2_auto); |
389 | 389 | ||
390 | game.setGroup("pieces"); | 390 | game.setGroup("pieces"); |
391 | QString label; | 391 | QString label; |
392 | LoadSave save=move->saveGame(); | 392 | LoadSave save=move->saveGame(); |
393 | for(int a=0;a<28;a++) | 393 | for(int a=0;a<28;a++) |
394 | { | 394 | { |
395 | label.setNum(a); | 395 | label.setNum(a); |
396 | game.writeEntry(label,save.pop[a].total); | 396 | game.writeEntry(label,save.pop[a].total); |
397 | } | 397 | } |
398 | QMessageBox::information(this,"Backgammon","Game saved","OK"); | 398 | QMessageBox::information(this,"Backgammon","Game saved","OK"); |
399 | } | 399 | } |
400 | 400 | ||
401 | void BackGammon::deletegame() | 401 | void BackGammon::deletegame() |
402 | { | 402 | { |
403 | FileDialog* file=new FileDialog(this,"Delete Game",".game"); | 403 | FileDialog* file=new FileDialog(this,"Delete Game",".game"); |
404 | if(!file->exec()) | 404 | if(!file->exec()) |
405 | return; | 405 | return; |
406 | 406 | ||
407 | game_name=file->filename(); | 407 | game_name=file->filename(); |
408 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; | 408 | QString game_file=QPEApplication::qpeDir()+"/backgammon/"+game_name+".game"; |
409 | 409 | ||
410 | if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) | 410 | if(!QMessageBox::warning(this,"Backgammon","deleted game\n"+game_name+" ?","OK","Cancel")) |
411 | { | 411 | { |
412 | QFile(game_file).remove(); | 412 | QFile(game_file).remove(); |
413 | } | 413 | } |
414 | } | 414 | } |
415 | 415 | ||
416 | 416 | ||
417 | void BackGammon::newtheme() | 417 | void BackGammon::newtheme() |
418 | { | 418 | { |
419 | ThemeDialog* theme=new ThemeDialog(this); | 419 | ThemeDialog* theme=new ThemeDialog(this); |
420 | 420 | ||
421 | ImageNames names; | 421 | ImageNames names; |
422 | names.theme=theme_name; | 422 | names.theme=theme_name; |
423 | names.board=board_name; | 423 | names.board=board_name; |
424 | names.pieces1=piecesA_name; | 424 | names.pieces1=piecesA_name; |
425 | names.pieces2=piecesB_name; | 425 | names.pieces2=piecesB_name; |
426 | names.dice1=diceA_name; | 426 | names.dice1=diceA_name; |
427 | names.dice2=diceB_name; | 427 | names.dice2=diceB_name; |
428 | names.odds=odds_name; | 428 | names.odds=odds_name; |
429 | names.table=table_name; | 429 | names.table=table_name; |
430 | 430 | ||
431 | theme->setCurrent(names); | 431 | theme->setCurrent(names); |
432 | if(!theme->exec()) | 432 | if(!theme->exec()) |
433 | return; | 433 | return; |
434 | 434 | ||
435 | names=theme->getNames(); | 435 | names=theme->getNames(); |
436 | theme_name=names.theme; | 436 | theme_name=names.theme; |
437 | board_name=names.board; | 437 | board_name=names.board; |
438 | piecesA_name=names.pieces1; | 438 | piecesA_name=names.pieces1; |
439 | piecesB_name=names.pieces2; | 439 | piecesB_name=names.pieces2; |
440 | diceA_name=names.dice1; | 440 | diceA_name=names.dice1; |
441 | diceB_name=names.dice2; | 441 | diceB_name=names.dice2; |
442 | odds_name=names.odds; | 442 | odds_name=names.odds; |
443 | table_name=names.table; | 443 | table_name=names.table; |
444 | 444 | ||
445 | applytheme(); | 445 | applytheme(); |
446 | } | 446 | } |
447 | 447 | ||
448 | void BackGammon::loadtheme() | 448 | void BackGammon::loadtheme() |
449 | { | 449 | { |
450 | FileDialog* file=new FileDialog(this,"Load Theme",".theme"); | 450 | FileDialog* file=new FileDialog(this,"Load Theme",".theme"); |
451 | if(!file->exec()) | 451 | if(!file->exec()) |
452 | return; | 452 | return; |
453 | 453 | ||
454 | theme_name=file->filename(); | 454 | theme_name=file->filename(); |
455 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 455 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
456 | 456 | ||
457 | Config theme(theme_file,Config::File); | 457 | Config theme(theme_file,Config::File); |
458 | theme.setGroup("theme"); | 458 | theme.setGroup("theme"); |
459 | board_name=theme.readEntry("board","board_1"); | 459 | board_name=theme.readEntry("board","board_1"); |
460 | piecesA_name=theme.readEntry("pieces1","pieces_1"); | 460 | piecesA_name=theme.readEntry("pieces1","pieces_1"); |
461 | piecesB_name=theme.readEntry("pieces2","pieces_2"); | 461 | piecesB_name=theme.readEntry("pieces2","pieces_2"); |
462 | diceA_name=theme.readEntry("dice1","dice_1"); | 462 | diceA_name=theme.readEntry("dice1","dice_1"); |
463 | diceB_name=theme.readEntry("dice2","dice_2"); | 463 | diceB_name=theme.readEntry("dice2","dice_2"); |
464 | table_name=theme.readEntry("table","table_1"); | 464 | table_name=theme.readEntry("table","table_1"); |
465 | odds_name=theme.readEntry("odds","odds_1"); | 465 | odds_name=theme.readEntry("odds","odds_1"); |
466 | 466 | ||
467 | applytheme(); | 467 | applytheme(); |
468 | 468 | ||
469 | } | 469 | } |
470 | 470 | ||
471 | void BackGammon::savetheme() | 471 | void BackGammon::savetheme() |
472 | { | 472 | { |
473 | if(theme_name=="default") | 473 | if(theme_name=="default") |
474 | { | 474 | { |
475 | QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); | 475 | QMessageBox::information(this,"Backgammon","Sorry\nCannot overwrite default.theme","OK"); |
476 | return; | 476 | return; |
477 | } | 477 | } |
478 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 478 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
479 | if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) | 479 | if(QMessageBox::information(this,"Backgammon","Save Theme\n"+theme_name,"Yes","No")) |
480 | return; | 480 | return; |
481 | 481 | ||
482 | Config theme(theme_file,Config::File); | 482 | Config theme(theme_file,Config::File); |
483 | theme.setGroup("theme"); | 483 | theme.setGroup("theme"); |
484 | theme.writeEntry("board",board_name); | 484 | theme.writeEntry("board",board_name); |
485 | theme.writeEntry("pieces1",piecesA_name); | 485 | theme.writeEntry("pieces1",piecesA_name); |
486 | theme.writeEntry("pieces2",piecesB_name); | 486 | theme.writeEntry("pieces2",piecesB_name); |
487 | theme.writeEntry("dice1",diceA_name); | 487 | theme.writeEntry("dice1",diceA_name); |
488 | theme.writeEntry("dice2",diceB_name); | 488 | theme.writeEntry("dice2",diceB_name); |
489 | theme.writeEntry("table",table_name); | 489 | theme.writeEntry("table",table_name); |
490 | theme.writeEntry("odds",odds_name); | 490 | theme.writeEntry("odds",odds_name); |
491 | 491 | ||
492 | } | 492 | } |
493 | 493 | ||
494 | void BackGammon::themedefault() | 494 | void BackGammon::themedefault() |
495 | { | 495 | { |
496 | if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) | 496 | if(QMessageBox::information(this,"Backgammon","Make Theme\n"+theme_name+"\nthe default theme","Yes","No")) |
497 | return; | 497 | return; |
498 | 498 | ||
499 | Config conf("backgammon"); | 499 | Config conf("backgammon"); |
500 | conf.setGroup("general"); | 500 | conf.setGroup("general"); |
501 | conf.writeEntry("theme",theme_name); | 501 | conf.writeEntry("theme",theme_name); |
502 | } | 502 | } |
503 | 503 | ||
504 | void BackGammon::deletetheme() | 504 | void BackGammon::deletetheme() |
505 | { | 505 | { |
506 | FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); | 506 | FileDialog* file=new FileDialog(this,"Delete Theme",".theme"); |
507 | if(!file->exec()) | 507 | if(!file->exec()) |
508 | return; | 508 | return; |
509 | 509 | ||
510 | theme_name=file->filename(); | 510 | theme_name=file->filename(); |
511 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; | 511 | QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; |
512 | 512 | ||
513 | if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" ))) | 513 | if(!QMessageBox::warning(this,tr( "Backgammon" ),tr( "deleted theme %1?").arg(theme_name),tr( "OK" ),tr( "Cancel" ))) |
514 | { | 514 | { |
515 | QFile(theme_file).remove(); | 515 | QFile(theme_file).remove(); |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | void BackGammon::modify_AI() | 519 | void BackGammon::modify_AI() |
520 | { | 520 | { |
521 | AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme"); | 521 | AI_Dialog* ai_mod=new AI_Dialog(this,tr( "Load Theme" ),".theme"); |
522 | ai_mod->setAISettings(move->getAISettings()); | 522 | ai_mod->setAISettings(move->getAISettings()); |
523 | if(!ai_mod->exec()) | 523 | if(!ai_mod->exec()) |
524 | return; | 524 | return; |
525 | 525 | ||
526 | //get the AI settings | 526 | //get the AI settings |
527 | AISettings ai=ai_mod->getAISettings(); | 527 | AISettings ai=ai_mod->getAISettings(); |
528 | move->setAISettings(ai); | 528 | move->setAISettings(ai); |
529 | //write new settings to conf file | 529 | //write new settings to conf file |
530 | Config conf("backgammon"); | 530 | Config conf("backgammon"); |
531 | conf.setGroup("ai"); | 531 | conf.setGroup("ai"); |
532 | conf.writeEntry("rescue",ai.rescue); | 532 | conf.writeEntry("rescue",ai.rescue); |
533 | conf.writeEntry("eliminate",ai.eliminate); | 533 | conf.writeEntry("eliminate",ai.eliminate); |
534 | conf.writeEntry("expose",ai.expose); | 534 | conf.writeEntry("expose",ai.expose); |
535 | conf.writeEntry("protect",ai.protect); | 535 | conf.writeEntry("protect",ai.protect); |
536 | conf.writeEntry("safe",ai.safe); | 536 | conf.writeEntry("safe",ai.safe); |
537 | conf.writeEntry("empty",ai.empty); | 537 | conf.writeEntry("empty",ai.empty); |
538 | } | 538 | } |
539 | 539 | ||
540 | void BackGammon::setrules() | 540 | void BackGammon::setrules() |
541 | { | 541 | { |
542 | RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme"); | 542 | RulesDialog* rulesdialog=new RulesDialog(this,tr( "Load Theme" ),".theme"); |
543 | rulesdialog->setRules(rules); | 543 | rulesdialog->setRules(rules); |
544 | if(!rulesdialog->exec()) | 544 | if(!rulesdialog->exec()) |
545 | return; | 545 | return; |
546 | rules=rulesdialog->getRules(); | 546 | rules=rulesdialog->getRules(); |
547 | Config conf("backgammon"); | 547 | Config conf("backgammon"); |
548 | conf.setGroup("rules"); | 548 | conf.setGroup("rules"); |
549 | conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); | 549 | conf.writeEntry("move_with_pieces_out",rules.move_with_pieces_out); |
550 | conf.writeEntry("nice_dice",rules.generous_dice); | 550 | conf.writeEntry("nice_dice",rules.generous_dice); |
551 | move->setRules(rules); | 551 | move->setRules(rules); |
552 | } | 552 | } |
553 | 553 | ||
554 | 554 | ||
555 | void BackGammon::draw() | 555 | void BackGammon::draw() |
556 | { | 556 | { |
557 | Pieces pieces; | 557 | Pieces pieces; |
558 | move->position(pieces); | 558 | move->position(pieces); |
559 | for(int a=0;a<15;a++) | 559 | for(int a=0;a<15;a++) |
560 | { | 560 | { |
561 | if(!pieces.player1[a].side) | 561 | if(!pieces.player1[a].side) |
562 | { | 562 | { |
563 | p1[a]->setX(pieces.player1[a].x); | 563 | p1[a]->setX(pieces.player1[a].x); |
564 | p1[a]->setY(pieces.player1[a].y); | 564 | p1[a]->setY(pieces.player1[a].y); |
565 | p1[a]->setZ(pieces.player1[a].z); | 565 | p1[a]->setZ(pieces.player1[a].z); |
566 | p1[a]->show(); | 566 | p1[a]->show(); |
567 | p1_side[a]->hide(); | 567 | p1_side[a]->hide(); |
568 | } | 568 | } |
569 | else | 569 | else |
570 | { | 570 | { |
571 | p1_side[a]->setX(pieces.player1[a].x); | 571 | p1_side[a]->setX(pieces.player1[a].x); |
572 | p1_side[a]->setY(pieces.player1[a].y); | 572 | p1_side[a]->setY(pieces.player1[a].y); |
573 | p1_side[a]->setZ(pieces.player1[a].z); | 573 | p1_side[a]->setZ(pieces.player1[a].z); |
574 | p1_side[a]->show(); | 574 | p1_side[a]->show(); |
575 | p1[a]->hide(); | 575 | p1[a]->hide(); |
576 | } | 576 | } |
577 | 577 | ||
578 | if(!pieces.player2[a].side) | 578 | if(!pieces.player2[a].side) |
579 | { | 579 | { |
580 | p2[a]->setX(pieces.player2[a].x); | 580 | p2[a]->setX(pieces.player2[a].x); |
581 | p2[a]->setY(pieces.player2[a].y); | 581 | p2[a]->setY(pieces.player2[a].y); |
582 | p2[a]->setZ(pieces.player2[a].z); | 582 | p2[a]->setZ(pieces.player2[a].z); |
583 | p2[a]->show(); | 583 | p2[a]->show(); |
584 | p2_side[a]->hide(); | 584 | p2_side[a]->hide(); |
585 | } | 585 | } |
586 | else | 586 | else |
587 | { | 587 | { |
588 | p2_side[a]->setX(pieces.player2[a].x); | 588 | p2_side[a]->setX(pieces.player2[a].x); |
589 | p2_side[a]->setY(pieces.player2[a].y); | 589 | p2_side[a]->setY(pieces.player2[a].y); |
590 | p2_side[a]->setZ(pieces.player2[a].z); | 590 | p2_side[a]->setZ(pieces.player2[a].z); |
591 | p2_side[a]->show(); | 591 | p2_side[a]->show(); |
592 | p2[a]->hide(); | 592 | p2[a]->hide(); |
593 | } | 593 | } |
594 | } | 594 | } |
595 | } | 595 | } |
596 | 596 | ||
597 | void BackGammon::mouse(int x,int y) | 597 | void BackGammon::mouse(int x,int y) |
598 | { | 598 | { |
599 | if(gameFinished) | 599 | if(gameFinished) |
600 | { | 600 | { |
601 | newgame(); | 601 | newgame(); |
602 | return; | 602 | return; |
603 | } | 603 | } |
604 | if(y<=200) //move pieces | 604 | if(y<=200) //move pieces |
605 | { | 605 | { |
606 | if((player==1 && player1_auto) || (player==2 && player2_auto)) | 606 | if((player==1 && player1_auto) || (player==2 && player2_auto)) |
607 | return; | 607 | return; |
608 | 608 | ||
609 | Marker marker; | 609 | Marker marker; |
610 | 610 | ||
611 | move->boardpressed(x,y,marker); | 611 | move->boardpressed(x,y,marker); |
612 | if(marker.visible_current) | 612 | if(marker.visible_current) |
613 | { | 613 | { |
614 | marker_current->setX(marker.x_current); | 614 | marker_current->setX(marker.x_current); |
615 | marker_current->setY(marker.y_current); | 615 | marker_current->setY(marker.y_current); |
616 | marker_current->show(); | 616 | marker_current->show(); |
617 | } | 617 | } |
618 | else | 618 | else |
619 | { | 619 | { |
620 | marker_current->hide(); | 620 | marker_current->hide(); |
621 | } | 621 | } |
622 | 622 | ||
623 | for(int a=0;a<4;a++) | 623 | for(int a=0;a<4;a++) |
624 | { | 624 | { |
625 | if(marker.visible_next[a]) | 625 | if(marker.visible_next[a]) |
626 | { | 626 | { |
627 | marker_next[a]->setX(marker.x_next[a]); | 627 | marker_next[a]->setX(marker.x_next[a]); |
628 | marker_next[a]->setY(marker.y_next[a]); | 628 | marker_next[a]->setY(marker.y_next[a]); |
629 | marker_next[a]->show(); | 629 | marker_next[a]->show(); |
630 | } | 630 | } |
631 | else | 631 | else |
632 | { | 632 | { |
633 | marker_next[a]->hide(); | 633 | marker_next[a]->hide(); |
634 | } | 634 | } |
635 | } | 635 | } |
636 | area->update(); | 636 | area->update(); |
637 | } | 637 | } |
638 | else //roll dice | 638 | else //roll dice |
639 | { | 639 | { |
640 | if(x>=10 && x<=65 && player==1 && !dice_rolled) | 640 | if(x>=10 && x<=65 && player==1 && !dice_rolled) |
641 | { | 641 | { |
642 | dice1_played=false; | 642 | dice1_played=false; |
643 | dice2_played=false; | 643 | dice2_played=false; |
644 | dice3_played=false; | 644 | dice3_played=false; |
645 | dice4_played=false; | 645 | dice4_played=false; |
646 | dice_rolled=true; | 646 | dice_rolled=true; |
647 | srand(QTime::currentTime().msec()); | 647 | srand(QTime::currentTime().msec()); |
648 | diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 648 | diceA1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
649 | diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 649 | diceA2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
650 | if(diceA1_value==diceA2_value) | 650 | if(diceA1_value==diceA2_value) |
651 | { | 651 | { |
652 | diceA3_value=diceA1_value; | 652 | diceA3_value=diceA1_value; |
653 | diceA4_value=diceA1_value; | 653 | diceA4_value=diceA1_value; |
654 | } | 654 | } |
655 | else | 655 | else |
656 | { | 656 | { |
657 | diceA3_value=7; | 657 | diceA3_value=7; |
658 | dice3_played=true; | 658 | dice3_played=true; |
659 | diceA4_value=7; | 659 | diceA4_value=7; |
660 | dice4_played=true; | 660 | dice4_played=true; |
661 | } | 661 | } |
662 | showdice(); | 662 | showdice(); |
663 | area->update(); | 663 | area->update(); |
664 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 664 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
665 | 665 | ||
666 | } | 666 | } |
667 | else if(x>=160 && x<=225 && player==2 && !dice_rolled) | 667 | else if(x>=160 && x<=225 && player==2 && !dice_rolled) |
668 | { | 668 | { |
669 | dice1_played=false; | 669 | dice1_played=false; |
670 | dice2_played=false; | 670 | dice2_played=false; |
671 | dice3_played=false; | 671 | dice3_played=false; |
672 | dice4_played=false; | 672 | dice4_played=false; |
673 | dice_rolled=true; | 673 | dice_rolled=true; |
674 | srand(QTime::currentTime().msec()); | 674 | srand(QTime::currentTime().msec()); |
675 | diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 675 | diceB1_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
676 | diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); | 676 | diceB2_value=1+(int) (6.0*rand()/(RAND_MAX+1.0)); |
677 | if(diceB1_value==diceB2_value) | 677 | if(diceB1_value==diceB2_value) |
678 | { | 678 | { |
679 | diceB3_value=diceB1_value; | 679 | diceB3_value=diceB1_value; |
680 | diceB4_value=diceB1_value; | 680 | diceB4_value=diceB1_value; |
681 | } | 681 | } |
682 | else | 682 | else |
683 | { | 683 | { |
684 | diceB3_value=7; | 684 | diceB3_value=7; |
685 | dice3_played=true; | 685 | dice3_played=true; |
686 | diceB4_value=7; | 686 | diceB4_value=7; |
687 | dice4_played=true; | 687 | dice4_played=true; |
688 | } | 688 | } |
689 | showdice(); | 689 | showdice(); |
690 | area->update(); | 690 | area->update(); |
691 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 691 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
692 | } | 692 | } |
693 | } | 693 | } |
694 | } | 694 | } |
695 | 695 | ||
696 | void BackGammon::done_dice1() | 696 | void BackGammon::done_dice1() |
697 | { | 697 | { |
698 | dice1_played=true; | 698 | dice1_played=true; |
699 | if(player==1) | 699 | if(player==1) |
700 | diceA1_value=7; | 700 | diceA1_value=7; |
701 | else | 701 | else |
702 | diceB1_value=7; | 702 | diceB1_value=7; |
703 | setplayer(); | 703 | setplayer(); |
704 | showdice(); | 704 | showdice(); |
705 | draw(); | 705 | draw(); |
706 | area->update(); | 706 | area->update(); |
707 | if(!dice2_played || !dice3_played || !dice4_played) | 707 | if(!dice2_played || !dice3_played || !dice4_played) |
708 | { | 708 | { |
709 | if(player==1) | 709 | if(player==1) |
710 | { | 710 | { |
711 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 711 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
712 | } | 712 | } |
713 | else | 713 | else |
714 | { | 714 | { |
715 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 715 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
716 | } | 716 | } |
717 | } | 717 | } |
718 | } | 718 | } |
719 | 719 | ||
720 | void BackGammon::done_dice2() | 720 | void BackGammon::done_dice2() |
721 | { | 721 | { |
722 | dice2_played=true; | 722 | dice2_played=true; |
723 | if(player==1) | 723 | if(player==1) |
724 | diceA2_value=7; | 724 | diceA2_value=7; |
725 | else | 725 | else |
726 | diceB2_value=7; | 726 | diceB2_value=7; |
727 | setplayer(); | 727 | setplayer(); |
728 | showdice(); | 728 | showdice(); |
729 | draw(); | 729 | draw(); |
730 | area->update(); | 730 | area->update(); |
731 | if(!dice1_played || !dice3_played || !dice4_played) | 731 | if(!dice1_played || !dice3_played || !dice4_played) |
732 | { | 732 | { |
733 | if(player==1) | 733 | if(player==1) |
734 | { | 734 | { |
735 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 735 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
736 | } | 736 | } |
737 | else | 737 | else |
738 | { | 738 | { |
739 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 739 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
740 | } | 740 | } |
741 | } | 741 | } |
742 | } | 742 | } |
743 | 743 | ||
744 | 744 | ||
745 | void BackGammon::done_dice3() | 745 | void BackGammon::done_dice3() |
746 | { | 746 | { |
747 | dice3_played=true; | 747 | dice3_played=true; |
748 | if(player==1) | 748 | if(player==1) |
749 | diceA3_value=7; | 749 | diceA3_value=7; |
750 | else | 750 | else |
751 | diceB3_value=7; | 751 | diceB3_value=7; |
752 | setplayer(); | 752 | setplayer(); |
753 | showdice(); | 753 | showdice(); |
754 | draw(); | 754 | draw(); |
755 | area->update(); | 755 | area->update(); |
756 | if(!dice1_played || !dice2_played || !dice4_played) | 756 | if(!dice1_played || !dice2_played || !dice4_played) |
757 | { | 757 | { |
758 | if(player==1) | 758 | if(player==1) |
759 | { | 759 | { |
760 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 760 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
761 | } | 761 | } |
762 | else | 762 | else |
763 | { | 763 | { |
764 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 764 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
765 | } | 765 | } |
766 | } | 766 | } |
767 | } | 767 | } |
768 | 768 | ||
769 | 769 | ||
770 | void BackGammon::done_dice4() | 770 | void BackGammon::done_dice4() |
771 | { | 771 | { |
772 | dice4_played=true; | 772 | dice4_played=true; |
773 | if(player==1) | 773 | if(player==1) |
774 | diceA4_value=7; | 774 | diceA4_value=7; |
775 | else | 775 | else |
776 | diceB4_value=7; | 776 | diceB4_value=7; |
777 | setplayer(); | 777 | setplayer(); |
778 | showdice(); | 778 | showdice(); |
779 | draw(); | 779 | draw(); |
780 | area->update(); | 780 | area->update(); |
781 | if(!dice1_played || !dice2_played || !dice3_played) | 781 | if(!dice1_played || !dice2_played || !dice3_played) |
782 | { | 782 | { |
783 | if(player==1) | 783 | if(player==1) |
784 | { | 784 | { |
785 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); | 785 | move->diceroll(1,diceA1_value,diceA2_value,diceA3_value,diceA4_value,player1_auto); |
786 | } | 786 | } |
787 | else | 787 | else |
788 | { | 788 | { |
789 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); | 789 | move->diceroll(2,diceB1_value,diceB2_value,diceB3_value,diceB4_value,player2_auto); |
790 | } | 790 | } |
791 | } | 791 | } |
792 | } | 792 | } |
793 | 793 | ||
794 | 794 | ||
795 | void BackGammon::nomove() | 795 | void BackGammon::nomove() |
796 | { | 796 | { |
797 | if(player==1) | 797 | if(player==1) |
798 | nomove_marker->setX(0); | 798 | nomove_marker->setX(0); |
799 | else | 799 | else |
800 | nomove_marker->setX(170); | 800 | nomove_marker->setX(170); |
801 | nomove_marker->show(); | 801 | nomove_marker->show(); |
802 | message->setText(tr( "<b>no move</b>" )); | 802 | message->setText(tr( "<b>no move</b>" )); |
803 | dice1_played=true; | 803 | dice1_played=true; |
804 | dice2_played=true; | 804 | dice2_played=true; |
805 | dice3_played=true; | 805 | dice3_played=true; |
806 | dice4_played=true; | 806 | dice4_played=true; |
807 | if(player==1) | 807 | if(player==1) |
808 | { | 808 | { |
809 | diceA1_value=7; | 809 | diceA1_value=7; |
810 | diceA2_value=7; | 810 | diceA2_value=7; |
811 | diceA3_value=7; | 811 | diceA3_value=7; |
812 | diceA4_value=7; | 812 | diceA4_value=7; |
813 | } | 813 | } |
814 | else | 814 | else |
815 | { | 815 | { |
816 | diceB1_value=7; | 816 | diceB1_value=7; |
817 | diceB2_value=7; | 817 | diceB2_value=7; |
818 | diceB3_value=7; | 818 | diceB3_value=7; |
819 | diceB4_value=7; | 819 | diceB4_value=7; |
820 | } | 820 | } |
821 | area->update(); | 821 | area->update(); |
822 | QTimer::singleShot(2000,this,SLOT(nomove2())); | 822 | QTimer::singleShot(2000,this,SLOT(nomove2())); |
823 | } | 823 | } |
824 | 824 | ||
825 | void BackGammon::nomove2() | 825 | void BackGammon::nomove2() |
826 | { | 826 | { |
827 | nomove_marker->hide(); | 827 | nomove_marker->hide(); |
828 | setplayer(); | 828 | setplayer(); |
829 | showdice(); | 829 | showdice(); |
830 | draw(); | 830 | draw(); |
831 | area->update(); | 831 | area->update(); |
832 | } | 832 | } |
833 | 833 | ||
834 | void BackGammon::finished(int theplayer) | 834 | void BackGammon::finished(int theplayer) |
835 | { | 835 | { |
836 | nomove_marker->hide(); | 836 | nomove_marker->hide(); |
837 | if(theplayer==1) | 837 | if(theplayer==1) |
838 | message->setText(tr( "<b>Player 1 wins. Click on board for new game.</b>" )); | 838 | message->setText(tr( "<b>Player 1 wins. Click on board for new game.</b>" )); |
839 | else | 839 | else |
840 | message->setText(tr( "<b>Player 2 wins. Click on board for new game.</b>" )); | 840 | message->setText(tr( "<b>Player 2 wins. Click on board for new game.</b>" )); |
841 | diceA1_value=7; | 841 | diceA1_value=7; |
842 | diceA2_value=7; | 842 | diceA2_value=7; |
843 | diceB1_value=7; | 843 | diceB1_value=7; |
844 | diceB2_value=7; | 844 | diceB2_value=7; |
845 | player=0; | 845 | player=0; |
846 | showdice(); | 846 | showdice(); |
847 | draw(); | 847 | draw(); |
848 | area->update(); | 848 | area->update(); |
849 | gameFinished=true; | 849 | gameFinished=true; |
850 | } | 850 | } |
851 | 851 | ||
852 | void BackGammon::showdice() | 852 | void BackGammon::showdice() |
853 | { | 853 | { |
854 | int value_diceA1=diceA1_value-1; | 854 | int value_diceA1=diceA1_value-1; |
855 | if(diceA1_value==7 && diceA3_value!=7) | 855 | if(diceA1_value==7 && diceA3_value!=7) |
856 | value_diceA1=diceA3_value-1; | 856 | value_diceA1=diceA3_value-1; |
857 | 857 | ||
858 | int value_diceA2=diceA2_value-1; | 858 | int value_diceA2=diceA2_value-1; |
859 | if(diceA2_value==7 && diceA4_value!=7) | 859 | if(diceA2_value==7 && diceA4_value!=7) |
860 | value_diceA2=diceA4_value-1; | 860 | value_diceA2=diceA4_value-1; |
861 | 861 | ||
862 | int value_diceB1=diceB1_value-1; | 862 | int value_diceB1=diceB1_value-1; |
863 | if(diceB1_value==7 && diceB3_value!=7) | 863 | if(diceB1_value==7 && diceB3_value!=7) |
864 | value_diceB1=diceB3_value-1; | 864 | value_diceB1=diceB3_value-1; |
865 | 865 | ||
866 | int value_diceB2=diceB2_value-1; | 866 | int value_diceB2=diceB2_value-1; |
867 | if(diceB2_value==7 && diceB4_value!=7) | 867 | if(diceB2_value==7 && diceB4_value!=7) |
868 | value_diceB2=diceB4_value-1; | 868 | value_diceB2=diceB4_value-1; |
869 | 869 | ||
870 | for(int index=0;index<7;index++) | 870 | for(int index=0;index<7;index++) |
871 | { | 871 | { |
872 | if(value_diceA1==index) | 872 | if(value_diceA1==index) |
873 | diceA1[index]->show(); | 873 | diceA1[index]->show(); |
874 | else | 874 | else |
875 | diceA1[index]->hide(); | 875 | diceA1[index]->hide(); |
876 | 876 | ||
877 | if(value_diceA2==index) | 877 | if(value_diceA2==index) |
878 | diceA2[index]->show(); | 878 | diceA2[index]->show(); |
879 | else | 879 | else |
880 | diceA2[index]->hide(); | 880 | diceA2[index]->hide(); |
881 | 881 | ||
882 | if(value_diceB1==index) | 882 | if(value_diceB1==index) |
883 | diceB1[index]->show(); | 883 | diceB1[index]->show(); |
884 | else | 884 | else |
885 | diceB1[index]->hide(); | 885 | diceB1[index]->hide(); |
886 | 886 | ||
887 | if(value_diceB2==index) | 887 | if(value_diceB2==index) |
888 | diceB2[index]->show(); | 888 | diceB2[index]->show(); |
889 | else | 889 | else |
890 | diceB2[index]->hide(); | 890 | diceB2[index]->hide(); |
891 | } | 891 | } |
892 | } | 892 | } |
893 | 893 | ||
894 | void BackGammon::setplayer() | 894 | void BackGammon::setplayer() |
895 | { | 895 | { |
896 | if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) | 896 | if(dice1_played && dice2_played && dice3_played && dice4_played && player==1) |
897 | { | 897 | { |
898 | message->setText(tr( "<b>P2 turn</b>", "P means player" )); | 898 | message->setText(tr( "<b>P2 turn</b>", "P means player" )); |
899 | dice_rolled=false; | 899 | dice_rolled=false; |
900 | player=2; | 900 | player=2; |
901 | if(player2_auto) | 901 | if(player2_auto) |
902 | QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); | 902 | QTimer::singleShot(2000,this,SLOT(autoroll_dice2())); |
903 | } | 903 | } |
904 | else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) | 904 | else if(dice1_played && dice2_played && dice3_played && dice4_played && player==2) |
905 | { | 905 | { |
906 | message->setText(tr( "<b>P1 turn</b>", "P means player" )); | 906 | message->setText(tr( "<b>P1 turn</b>", "P means player" )); |
907 | dice_rolled=false; | 907 | dice_rolled=false; |
908 | player=1; | 908 | player=1; |
909 | if(player1_auto) | 909 | if(player1_auto) |
910 | QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); | 910 | QTimer::singleShot(2000,this,SLOT(autoroll_dice1())); |
911 | } | 911 | } |
912 | } | 912 | } |
913 | 913 | ||
914 | void BackGammon::autoroll_dice1() | 914 | void BackGammon::autoroll_dice1() |
915 | { | 915 | { |
916 | mouse(20,210); | 916 | mouse(20,210); |
917 | } | 917 | } |
918 | 918 | ||
919 | void BackGammon::autoroll_dice2() | 919 | void BackGammon::autoroll_dice2() |
920 | { | 920 | { |
921 | mouse(170,210); | 921 | mouse(170,210); |
922 | } | 922 | } |
923 | 923 | ||
924 | void BackGammon::applytheme() | 924 | void BackGammon::applytheme() |
925 | { | 925 | { |
926 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); | 926 | QImage boardbg(Resource::loadImage("backgammon/boards/"+board_name)); |
927 | board->setImage(boardbg); | 927 | board->setImage(boardbg); |
928 | 928 | ||
929 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); | 929 | QImage tablebg(Resource::loadImage("backgammon/table/"+table_name)); |
930 | table->setImage(tablebg); | 930 | table->setImage(tablebg); |
931 | 931 | ||
932 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); | 932 | QImage piece_1_all(Resource::loadImage("backgammon/pieces/"+piecesA_name)); |
933 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); | 933 | QImage piece_1_front=piece_1_all.copy(0,0,15,15); |
934 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); | 934 | QImage piece_1_side=piece_1_all.copy(0,15,15,5); |
935 | 935 | ||
936 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); | 936 | QImage piece_2_all(Resource::loadImage("backgammon/pieces/"+piecesB_name)); |
937 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); | 937 | QImage piece_2_front=piece_2_all.copy(0,0,15,15); |
938 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); | 938 | QImage piece_2_side=piece_2_all.copy(0,15,15,5); |
939 | 939 | ||
940 | int a=0; | 940 | int a=0; |
941 | for(a=0;a<15;a++) | 941 | for(a=0;a<15;a++) |
942 | { | 942 | { |
943 | p1[a]->setImage(piece_1_front); | 943 | p1[a]->setImage(piece_1_front); |
944 | p1_side[a]->setImage(piece_1_side); | 944 | p1_side[a]->setImage(piece_1_side); |
945 | 945 | ||
946 | p2[a]->setImage(piece_2_front); | 946 | p2[a]->setImage(piece_2_front); |
947 | p2_side[a]->setImage(piece_2_side); | 947 | p2_side[a]->setImage(piece_2_side); |
948 | } | 948 | } |
949 | draw(); | 949 | draw(); |
950 | 950 | ||
951 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); | 951 | QImage dicebgA_all(Resource::loadImage("backgammon/dice/"+diceA_name)); |
952 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); | 952 | QImage dicebgB_all(Resource::loadImage("backgammon/dice/"+diceB_name)); |
953 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); | 953 | QImage oddsbg_all=(Resource::loadImage("backgammon/odds/"+odds_name)); |
954 | 954 | ||
955 | for(a=0;a<7;a++) | 955 | for(a=0;a<7;a++) |
956 | { | 956 | { |
957 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); | 957 | QImage dicebgA=dicebgA_all.copy(a*25,0,25,25); |
958 | diceA1[a]->setImage(dicebgA); | 958 | diceA1[a]->setImage(dicebgA); |
959 | diceA2[a]->setImage(dicebgA); | 959 | diceA2[a]->setImage(dicebgA); |
960 | 960 | ||
961 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); | 961 | QImage dicebgB=dicebgB_all.copy(a*25,0,25,25); |
962 | diceB1[a]->setImage(dicebgB); | 962 | diceB1[a]->setImage(dicebgB); |
963 | diceB2[a]->setImage(dicebgB); | 963 | diceB2[a]->setImage(dicebgB); |
964 | /* | 964 | /* |
965 | if(a<6) | 965 | if(a<6) |
966 | { | 966 | { |
967 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); | 967 | QImage oddsbg=oddsbg_all.copy(a*15,0,15,15); |
968 | oddsDice[a]->setImage(oddsbg); | 968 | oddsDice[a]->setImage(oddsbg); |
969 | } | 969 | } |
970 | */ | 970 | */ |
971 | } | 971 | } |
972 | } | 972 | } |
973 | 973 | ||
974 | 974 | ||
diff --git a/noncore/games/fifteen/fifteen.cpp b/noncore/games/fifteen/fifteen.cpp index 212f7b1..2e4ed94 100644 --- a/noncore/games/fifteen/fifteen.cpp +++ b/noncore/games/fifteen/fifteen.cpp | |||
@@ -1,364 +1,364 @@ | |||
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 "fifteen.h" | 21 | #include "fifteen.h" |
22 | 22 | ||
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
25 | 25 | ||
26 | #include <qvbox.h> | 26 | #include <qvbox.h> |
27 | #include <qaction.h> | 27 | #include <qaction.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qpainter.h> | 29 | #include <qpainter.h> |
30 | #include <qpopupmenu.h> | 30 | #include <qpopupmenu.h> |
31 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
32 | #include <qpe/qpetoolbar.h> | 32 | #include <qpe/qpetoolbar.h> |
33 | #include <qpe/qpemenubar.h> | 33 | #include <qmenubar.h> |
34 | #include <qstringlist.h> | 34 | #include <qstringlist.h> |
35 | #include <qapplication.h> | 35 | #include <qapplication.h> |
36 | 36 | ||
37 | #include <stdlib.h> | 37 | #include <stdlib.h> |
38 | #include <time.h> | 38 | #include <time.h> |
39 | 39 | ||
40 | FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name) | 40 | FifteenMainWindow::FifteenMainWindow(QWidget *parent, const char* name) |
41 | : QMainWindow( parent, name ) | 41 | : QMainWindow( parent, name ) |
42 | { | 42 | { |
43 | // random seed | 43 | // random seed |
44 | srand(time(0)); | 44 | srand(time(0)); |
45 | 45 | ||
46 | setToolBarsMovable( FALSE ); | 46 | setToolBarsMovable( FALSE ); |
47 | QVBox *vbox = new QVBox( this ); | 47 | QVBox *vbox = new QVBox( this ); |
48 | PiecesTable *table = new PiecesTable( vbox ); | 48 | PiecesTable *table = new PiecesTable( vbox ); |
49 | setCentralWidget(vbox); | 49 | setCentralWidget(vbox); |
50 | 50 | ||
51 | QPEToolBar *toolbar = new QPEToolBar(this); | 51 | QToolBar *toolbar = new QToolBar(this); |
52 | toolbar->setHorizontalStretchable( TRUE ); | 52 | toolbar->setHorizontalStretchable( TRUE ); |
53 | addToolBar(toolbar); | 53 | addToolBar(toolbar); |
54 | 54 | ||
55 | QMenuBar *menubar = new QMenuBar( toolbar ); | 55 | QMenuBar *menubar = new QMenuBar( toolbar ); |
56 | menubar->setMargin(0); | 56 | menubar->setMargin(0); |
57 | 57 | ||
58 | QPopupMenu *game = new QPopupMenu( this ); | 58 | QPopupMenu *game = new QPopupMenu( this ); |
59 | 59 | ||
60 | QWidget *spacer = new QWidget( toolbar ); | 60 | QWidget *spacer = new QWidget( toolbar ); |
61 | spacer->setBackgroundMode( PaletteButton ); | 61 | spacer->setBackgroundMode( PaletteButton ); |
62 | toolbar->setStretchableWidget( spacer ); | 62 | toolbar->setStretchableWidget( spacer ); |
63 | 63 | ||
64 | QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ), | 64 | QAction *a = new QAction( tr( "Randomize" ), Resource::loadPixmap( "new" ), |
65 | QString::null, 0, this, 0 ); | 65 | QString::null, 0, this, 0 ); |
66 | connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) ); | 66 | connect( a, SIGNAL( activated() ), table, SLOT( slotRandomize() ) ); |
67 | a->addTo( game ); | 67 | a->addTo( game ); |
68 | a->addTo( toolbar ); | 68 | a->addTo( toolbar ); |
69 | 69 | ||
70 | a = new QAction( tr( "Solve" ), Resource::loadPixmap( "repeat" ), | 70 | a = new QAction( tr( "Solve" ), Resource::loadPixmap( "repeat" ), |
71 | QString::null, 0, this, 0 ); | 71 | QString::null, 0, this, 0 ); |
72 | connect( a, SIGNAL( activated() ), table, SLOT( slotReset() ) ); | 72 | connect( a, SIGNAL( activated() ), table, SLOT( slotReset() ) ); |
73 | a->addTo( game ); | 73 | a->addTo( game ); |
74 | a->addTo( toolbar ); | 74 | a->addTo( toolbar ); |
75 | 75 | ||
76 | menubar->insertItem( tr( "Game" ), game ); | 76 | menubar->insertItem( tr( "Game" ), game ); |
77 | } | 77 | } |
78 | 78 | ||
79 | PiecesTable::PiecesTable(QWidget* parent, const char* name ) | 79 | PiecesTable::PiecesTable(QWidget* parent, const char* name ) |
80 | : QTableView(parent, name), _menu(0), _randomized(false) | 80 | : QTableView(parent, name), _menu(0), _randomized(false) |
81 | { | 81 | { |
82 | // setup table view | 82 | // setup table view |
83 | setFrameStyle(StyledPanel | Sunken); | 83 | setFrameStyle(StyledPanel | Sunken); |
84 | setBackgroundMode(NoBackground); | 84 | setBackgroundMode(NoBackground); |
85 | setMouseTracking(true); | 85 | setMouseTracking(true); |
86 | 86 | ||
87 | setNumRows(4); | 87 | setNumRows(4); |
88 | setNumCols(4); | 88 | setNumCols(4); |
89 | 89 | ||
90 | // init arrays | 90 | // init arrays |
91 | initMap(); | 91 | initMap(); |
92 | readConfig(); | 92 | readConfig(); |
93 | initColors(); | 93 | initColors(); |
94 | 94 | ||
95 | // set font | 95 | // set font |
96 | QFont f = font(); | 96 | QFont f = font(); |
97 | f.setPixelSize(18); | 97 | f.setPixelSize(18); |
98 | f.setBold( TRUE ); | 98 | f.setBold( TRUE ); |
99 | setFont(f); | 99 | setFont(f); |
100 | } | 100 | } |
101 | 101 | ||
102 | PiecesTable::~PiecesTable() | 102 | PiecesTable::~PiecesTable() |
103 | { | 103 | { |
104 | writeConfig(); | 104 | writeConfig(); |
105 | } | 105 | } |
106 | 106 | ||
107 | void PiecesTable::writeConfig() | 107 | void PiecesTable::writeConfig() |
108 | { | 108 | { |
109 | Config cfg("Fifteen"); | 109 | Config cfg("Fifteen"); |
110 | cfg.setGroup("Game"); | 110 | cfg.setGroup("Game"); |
111 | QStringList map; | 111 | QStringList map; |
112 | for (unsigned int i = 0; i < 16; i++) | 112 | for (unsigned int i = 0; i < 16; i++) |
113 | map.append( QString::number( _map[i] ) ); | 113 | map.append( QString::number( _map[i] ) ); |
114 | cfg.writeEntry("Map", map, '-'); | 114 | cfg.writeEntry("Map", map, '-'); |
115 | cfg.writeEntry("Randomized", _randomized ); | 115 | cfg.writeEntry("Randomized", _randomized ); |
116 | } | 116 | } |
117 | 117 | ||
118 | void PiecesTable::readConfig() | 118 | void PiecesTable::readConfig() |
119 | { | 119 | { |
120 | Config cfg("Fifteen"); | 120 | Config cfg("Fifteen"); |
121 | cfg.setGroup("Game"); | 121 | cfg.setGroup("Game"); |
122 | QStringList map = cfg.readListEntry("Map", '-'); | 122 | QStringList map = cfg.readListEntry("Map", '-'); |
123 | _randomized = cfg.readBoolEntry( "Randomized", FALSE ); | 123 | _randomized = cfg.readBoolEntry( "Randomized", FALSE ); |
124 | unsigned int i = 0; | 124 | unsigned int i = 0; |
125 | for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { | 125 | for ( QStringList::Iterator it = map.begin(); it != map.end(); ++it ) { |
126 | _map[i] = (*it).toInt(); | 126 | _map[i] = (*it).toInt(); |
127 | i++; | 127 | i++; |
128 | if ( i > 15 ) break; | 128 | if ( i > 15 ) break; |
129 | } | 129 | } |
130 | } | 130 | } |
131 | 131 | ||
132 | void PiecesTable::paintCell(QPainter *p, int row, int col) | 132 | void PiecesTable::paintCell(QPainter *p, int row, int col) |
133 | { | 133 | { |
134 | int w = cellWidth(); | 134 | int w = cellWidth(); |
135 | int h = cellHeight(); | 135 | int h = cellHeight(); |
136 | int x2 = w - 1; | 136 | int x2 = w - 1; |
137 | int y2 = h - 1; | 137 | int y2 = h - 1; |
138 | 138 | ||
139 | int number = _map[col + row * numCols()] + 1; | 139 | int number = _map[col + row * numCols()] + 1; |
140 | 140 | ||
141 | // draw cell background | 141 | // draw cell background |
142 | if(number == 16) | 142 | if(number == 16) |
143 | p->setBrush(colorGroup().background()); | 143 | p->setBrush(colorGroup().background()); |
144 | else | 144 | else |
145 | p->setBrush(_colors[number-1]); | 145 | p->setBrush(_colors[number-1]); |
146 | p->setPen(NoPen); | 146 | p->setPen(NoPen); |
147 | p->drawRect(0, 0, w, h); | 147 | p->drawRect(0, 0, w, h); |
148 | 148 | ||
149 | // draw borders | 149 | // draw borders |
150 | if (height() > 40) { | 150 | if (height() > 40) { |
151 | p->setPen(colorGroup().text()); | 151 | p->setPen(colorGroup().text()); |
152 | if(col < numCols()-1) | 152 | if(col < numCols()-1) |
153 | p->drawLine(x2, 0, x2, y2); // right border line | 153 | p->drawLine(x2, 0, x2, y2); // right border line |
154 | 154 | ||
155 | if(row < numRows()-1) | 155 | if(row < numRows()-1) |
156 | p->drawLine(0, y2, x2, y2); // bottom boder line | 156 | p->drawLine(0, y2, x2, y2); // bottom boder line |
157 | } | 157 | } |
158 | 158 | ||
159 | // draw number | 159 | // draw number |
160 | if (number == 16) return; | 160 | if (number == 16) return; |
161 | p->setPen(black); | 161 | p->setPen(black); |
162 | p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(number)); | 162 | p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString::number(number)); |
163 | } | 163 | } |
164 | 164 | ||
165 | void PiecesTable::resizeEvent(QResizeEvent *e) | 165 | void PiecesTable::resizeEvent(QResizeEvent *e) |
166 | { | 166 | { |
167 | QTableView::resizeEvent(e); | 167 | QTableView::resizeEvent(e); |
168 | 168 | ||
169 | setCellWidth(contentsRect().width()/ numRows()); | 169 | setCellWidth(contentsRect().width()/ numRows()); |
170 | setCellHeight(contentsRect().height() / numCols()); | 170 | setCellHeight(contentsRect().height() / numCols()); |
171 | } | 171 | } |
172 | 172 | ||
173 | void PiecesTable::initColors() | 173 | void PiecesTable::initColors() |
174 | { | 174 | { |
175 | _colors.resize(numRows() * numCols()); | 175 | _colors.resize(numRows() * numCols()); |
176 | for (int r = 0; r < numRows(); r++) | 176 | for (int r = 0; r < numRows(); r++) |
177 | for (int c = 0; c < numCols(); c++) | 177 | for (int c = 0; c < numCols(); c++) |
178 | _colors[c + r *numCols()] = QColor(255 - 70 * c,255 - 70 * r, 150); | 178 | _colors[c + r *numCols()] = QColor(255 - 70 * c,255 - 70 * r, 150); |
179 | } | 179 | } |
180 | 180 | ||
181 | void PiecesTable::initMap() | 181 | void PiecesTable::initMap() |
182 | { | 182 | { |
183 | _map.resize(16); | 183 | _map.resize(16); |
184 | for (unsigned int i = 0; i < 16; i++) | 184 | for (unsigned int i = 0; i < 16; i++) |
185 | _map[i] = i; | 185 | _map[i] = i; |
186 | 186 | ||
187 | _randomized = false; | 187 | _randomized = false; |
188 | } | 188 | } |
189 | 189 | ||
190 | void PiecesTable::randomizeMap() | 190 | void PiecesTable::randomizeMap() |
191 | { | 191 | { |
192 | initMap(); | 192 | initMap(); |
193 | _randomized = true; | 193 | _randomized = true; |
194 | // find the free position | 194 | // find the free position |
195 | int pos = _map.find(15); | 195 | int pos = _map.find(15); |
196 | 196 | ||
197 | int move = 0; | 197 | int move = 0; |
198 | while ( move < 333 ) { | 198 | while ( move < 333 ) { |
199 | 199 | ||
200 | int frow = pos / numCols(); | 200 | int frow = pos / numCols(); |
201 | int fcol = pos - frow * numCols(); | 201 | int fcol = pos - frow * numCols(); |
202 | 202 | ||
203 | // find click position | 203 | // find click position |
204 | int row = rand()%4; | 204 | int row = rand()%4; |
205 | int col = rand()%4; | 205 | int col = rand()%4; |
206 | 206 | ||
207 | // sanity check | 207 | // sanity check |
208 | if ( row < 0 || row >= numRows() ) continue; | 208 | if ( row < 0 || row >= numRows() ) continue; |
209 | if ( col < 0 || col >= numCols() ) continue; | 209 | if ( col < 0 || col >= numCols() ) continue; |
210 | if ( row != frow && col != fcol ) continue; | 210 | if ( row != frow && col != fcol ) continue; |
211 | 211 | ||
212 | move++; | 212 | move++; |
213 | 213 | ||
214 | // rows match -> shift pieces | 214 | // rows match -> shift pieces |
215 | if(row == frow) { | 215 | if(row == frow) { |
216 | 216 | ||
217 | if (col < fcol) { | 217 | if (col < fcol) { |
218 | for(int c = fcol; c > col; c--) { | 218 | for(int c = fcol; c > col; c--) { |
219 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; | 219 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; |
220 | } | 220 | } |
221 | } | 221 | } |
222 | else if (col > fcol) { | 222 | else if (col > fcol) { |
223 | for(int c = fcol; c < col; c++) { | 223 | for(int c = fcol; c < col; c++) { |
224 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; | 224 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; |
225 | } | 225 | } |
226 | } | 226 | } |
227 | } | 227 | } |
228 | // cols match -> shift pieces | 228 | // cols match -> shift pieces |
229 | else if (col == fcol) { | 229 | else if (col == fcol) { |
230 | 230 | ||
231 | if (row < frow) { | 231 | if (row < frow) { |
232 | for(int r = frow; r > row; r--) { | 232 | for(int r = frow; r > row; r--) { |
233 | _map[col + r * numCols()] = _map[ col + (r-1) *numCols()]; | 233 | _map[col + r * numCols()] = _map[ col + (r-1) *numCols()]; |
234 | } | 234 | } |
235 | } | 235 | } |
236 | else if (row > frow) { | 236 | else if (row > frow) { |
237 | for(int r = frow; r < row; r++) { | 237 | for(int r = frow; r < row; r++) { |
238 | _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; | 238 | _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; |
239 | } | 239 | } |
240 | } | 240 | } |
241 | } | 241 | } |
242 | // move free cell to click position | 242 | // move free cell to click position |
243 | _map[pos=(col + row * numCols())] = 15; | 243 | _map[pos=(col + row * numCols())] = 15; |
244 | repaint(); | 244 | repaint(); |
245 | } | 245 | } |
246 | } | 246 | } |
247 | 247 | ||
248 | void PiecesTable::checkwin() | 248 | void PiecesTable::checkwin() |
249 | { | 249 | { |
250 | if(!_randomized) return; | 250 | if(!_randomized) return; |
251 | 251 | ||
252 | int i; | 252 | int i; |
253 | for (i = 0; i < 16; i++) | 253 | for (i = 0; i < 16; i++) |
254 | if(i != _map[i]) | 254 | if(i != _map[i]) |
255 | break; | 255 | break; |
256 | 256 | ||
257 | if (i == 16) { | 257 | if (i == 16) { |
258 | QMessageBox::information(this, tr("Fifteen Pieces"), | 258 | QMessageBox::information(this, tr("Fifteen Pieces"), |
259 | tr("Congratulations!\nYou win the game!")); | 259 | tr("Congratulations!\nYou win the game!")); |
260 | _randomized = FALSE; | 260 | _randomized = FALSE; |
261 | } | 261 | } |
262 | 262 | ||
263 | } | 263 | } |
264 | 264 | ||
265 | void PiecesTable::slotRandomize() | 265 | void PiecesTable::slotRandomize() |
266 | { | 266 | { |
267 | randomizeMap(); | 267 | randomizeMap(); |
268 | } | 268 | } |
269 | 269 | ||
270 | void PiecesTable::slotReset() | 270 | void PiecesTable::slotReset() |
271 | { | 271 | { |
272 | initMap(); | 272 | initMap(); |
273 | repaint(); | 273 | repaint(); |
274 | } | 274 | } |
275 | 275 | ||
276 | void PiecesTable::mousePressEvent(QMouseEvent* e) | 276 | void PiecesTable::mousePressEvent(QMouseEvent* e) |
277 | { | 277 | { |
278 | QTableView::mousePressEvent(e); | 278 | QTableView::mousePressEvent(e); |
279 | 279 | ||
280 | if (e->button() == RightButton) { | 280 | if (e->button() == RightButton) { |
281 | 281 | ||
282 | // setup RMB pupup menu | 282 | // setup RMB pupup menu |
283 | if(!_menu) { | 283 | if(!_menu) { |
284 | _menu = new QPopupMenu(this); | 284 | _menu = new QPopupMenu(this); |
285 | _menu->insertItem(tr("R&andomize Pieces"), mRandomize); | 285 | _menu->insertItem(tr("R&andomize Pieces"), mRandomize); |
286 | _menu->insertItem(tr("&Reset Pieces"), mReset); | 286 | _menu->insertItem(tr("&Reset Pieces"), mReset); |
287 | _menu->adjustSize(); | 287 | _menu->adjustSize(); |
288 | } | 288 | } |
289 | 289 | ||
290 | // execute RMB popup and check result | 290 | // execute RMB popup and check result |
291 | switch(_menu->exec(mapToGlobal(e->pos()))) { | 291 | switch(_menu->exec(mapToGlobal(e->pos()))) { |
292 | case mRandomize: | 292 | case mRandomize: |
293 | randomizeMap(); | 293 | randomizeMap(); |
294 | break; | 294 | break; |
295 | case mReset: | 295 | case mReset: |
296 | initMap(); | 296 | initMap(); |
297 | repaint(); | 297 | repaint(); |
298 | break; | 298 | break; |
299 | default: | 299 | default: |
300 | break; | 300 | break; |
301 | } | 301 | } |
302 | } | 302 | } |
303 | else { | 303 | else { |
304 | // GAME LOGIC | 304 | // GAME LOGIC |
305 | 305 | ||
306 | // find the free position | 306 | // find the free position |
307 | int pos = _map.find(15); | 307 | int pos = _map.find(15); |
308 | if(pos < 0) return; | 308 | if(pos < 0) return; |
309 | 309 | ||
310 | int frow = pos / numCols(); | 310 | int frow = pos / numCols(); |
311 | int fcol = pos - frow * numCols(); | 311 | int fcol = pos - frow * numCols(); |
312 | 312 | ||
313 | // find click position | 313 | // find click position |
314 | int row = findRow(e->y()); | 314 | int row = findRow(e->y()); |
315 | int col = findCol(e->x()); | 315 | int col = findCol(e->x()); |
316 | 316 | ||
317 | // sanity check | 317 | // sanity check |
318 | if (row < 0 || row >= numRows()) return; | 318 | if (row < 0 || row >= numRows()) return; |
319 | if (col < 0 || col >= numCols()) return; | 319 | if (col < 0 || col >= numCols()) return; |
320 | if ( row != frow && col != fcol ) return; | 320 | if ( row != frow && col != fcol ) return; |
321 | 321 | ||
322 | // valid move? | 322 | // valid move? |
323 | if(row != frow && col != fcol) return; | 323 | if(row != frow && col != fcol) return; |
324 | 324 | ||
325 | // rows match -> shift pieces | 325 | // rows match -> shift pieces |
326 | if(row == frow) { | 326 | if(row == frow) { |
327 | 327 | ||
328 | if (col < fcol) { | 328 | if (col < fcol) { |
329 | for(int c = fcol; c > col; c--) { | 329 | for(int c = fcol; c > col; c--) { |
330 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; | 330 | _map[c + row * numCols()] = _map[ c-1 + row *numCols()]; |
331 | updateCell(row, c, false); | 331 | updateCell(row, c, false); |
332 | } | 332 | } |
333 | } | 333 | } |
334 | else if (col > fcol) { | 334 | else if (col > fcol) { |
335 | for(int c = fcol; c < col; c++) { | 335 | for(int c = fcol; c < col; c++) { |
336 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; | 336 | _map[c + row * numCols()] = _map[ c+1 + row *numCols()]; |
337 | updateCell(row, c, false); | 337 | updateCell(row, c, false); |
338 | } | 338 | } |
339 | } | 339 | } |
340 | } | 340 | } |
341 | // cols match -> shift pieces | 341 | // cols match -> shift pieces |
342 | else if (col == fcol) { | 342 | else if (col == fcol) { |
343 | 343 | ||
344 | if (row < frow) { | 344 | if (row < frow) { |
345 | for(int r = frow; r > row; r--) { | 345 | for(int r = frow; r > row; r--) { |
346 | _map[col + r * numCols()] = _map[ col + (r-1) *numCols()]; | 346 | _map[col + r * numCols()] = _map[ col + (r-1) *numCols()]; |
347 | updateCell(r, col, false); | 347 | updateCell(r, col, false); |
348 | } | 348 | } |
349 | } | 349 | } |
350 | else if (row > frow) { | 350 | else if (row > frow) { |
351 | for(int r = frow; r < row; r++) { | 351 | for(int r = frow; r < row; r++) { |
352 | _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; | 352 | _map[col + r * numCols()] = _map[ col + (r+1) *numCols()]; |
353 | updateCell(r, col, false); | 353 | updateCell(r, col, false); |
354 | } | 354 | } |
355 | } | 355 | } |
356 | } | 356 | } |
357 | // move free cell to click position | 357 | // move free cell to click position |
358 | _map[col + row * numCols()] = 15; | 358 | _map[col + row * numCols()] = 15; |
359 | updateCell(row, col, false); | 359 | updateCell(row, col, false); |
360 | 360 | ||
361 | // check if the player wins with this move | 361 | // check if the player wins with this move |
362 | checkwin(); | 362 | checkwin(); |
363 | } | 363 | } |
364 | } | 364 | } |
diff --git a/noncore/games/go/gowidget.cpp b/noncore/games/go/gowidget.cpp index 476f7ce1..6d06f3b 100644 --- a/noncore/games/go/gowidget.cpp +++ b/noncore/games/go/gowidget.cpp | |||
@@ -1,464 +1,464 @@ | |||
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 "gowidget.h" | 21 | #include "gowidget.h" |
22 | 22 | ||
23 | #include <qpe/config.h> | 23 | #include <qpe/config.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qpixmap.h> | 27 | #include <qpixmap.h> |
28 | #include <qpe/qpetoolbar.h> | 28 | #include <qpe/qpetoolbar.h> |
29 | #include <qpe/qpemenubar.h> | 29 | #include <qmenubar.h> |
30 | #include <qpopupmenu.h> | 30 | #include <qpopupmenu.h> |
31 | #include <qaction.h> | 31 | #include <qaction.h> |
32 | #include <qapplication.h> //processEvents() | 32 | #include <qapplication.h> //processEvents() |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | 34 | ||
35 | //#include <stdio.h> | 35 | //#include <stdio.h> |
36 | 36 | ||
37 | #include "amigo.h" | 37 | #include "amigo.h" |
38 | #include "goplayutils.h" | 38 | #include "goplayutils.h" |
39 | 39 | ||
40 | static const enum bVal computer_color = BLACK; | 40 | static const enum bVal computer_color = BLACK; |
41 | 41 | ||
42 | static int current_handicap = 1; | 42 | static int current_handicap = 1; |
43 | 43 | ||
44 | static QBrush *goBrush; | 44 | static QBrush *goBrush; |
45 | //static QImage *newBlackStone; | 45 | //static QImage *newBlackStone; |
46 | //static QImage *blackStone; | 46 | //static QImage *blackStone; |
47 | //static QImage *whiteStone; | 47 | //static QImage *whiteStone; |
48 | static QPixmap *newBlackStone; | 48 | static QPixmap *newBlackStone; |
49 | static QPixmap *blackStone; | 49 | static QPixmap *blackStone; |
50 | static QPixmap *whiteStone; | 50 | static QPixmap *whiteStone; |
51 | 51 | ||
52 | static bool smallStones = FALSE; | 52 | static bool smallStones = FALSE; |
53 | 53 | ||
54 | GoMainWidget::GoMainWidget( QWidget *parent, const char* name) : | 54 | GoMainWidget::GoMainWidget( QWidget *parent, const char* name) : |
55 | QMainWindow( parent, name ) | 55 | QMainWindow( parent, name ) |
56 | { | 56 | { |
57 | setToolBarsMovable( FALSE ); | 57 | setToolBarsMovable( FALSE ); |
58 | GoWidget *go = new GoWidget(this); | 58 | GoWidget *go = new GoWidget(this); |
59 | 59 | ||
60 | setCentralWidget(go); | 60 | setCentralWidget(go); |
61 | toolbar = new QPEToolBar(this); | 61 | toolbar = new QToolBar(this); |
62 | toolbar->setHorizontalStretchable( TRUE ); | 62 | toolbar->setHorizontalStretchable( TRUE ); |
63 | addToolBar(toolbar); | 63 | addToolBar(toolbar); |
64 | 64 | ||
65 | QMenuBar *mb = new QMenuBar( toolbar ); | 65 | QMenuBar *mb = new QMenuBar( toolbar ); |
66 | mb->setMargin(0); | 66 | mb->setMargin(0); |
67 | QPopupMenu *file = new QPopupMenu( this ); | 67 | QPopupMenu *file = new QPopupMenu( this ); |
68 | 68 | ||
69 | QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); | 69 | QAction *a = new QAction( tr( "New Game" ), QString::null, 0, this, 0 ); |
70 | connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); | 70 | connect( a, SIGNAL( activated() ), go, SLOT( newGame() ) ); |
71 | a->addTo( file ); | 71 | a->addTo( file ); |
72 | 72 | ||
73 | a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); | 73 | a = new QAction( tr( "Pass" ), Resource::loadPixmap( "pass" ), QString::null, 0, this, 0 ); |
74 | connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); | 74 | connect( a, SIGNAL( activated() ), go, SLOT( pass() ) ); |
75 | a->addTo( file ); | 75 | a->addTo( file ); |
76 | a->addTo( toolbar ); | 76 | a->addTo( toolbar ); |
77 | 77 | ||
78 | 78 | ||
79 | a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 ); | 79 | a = new QAction( tr( "Resign" ), Resource::loadPixmap( "reset" ), QString::null, 0, this, 0 ); |
80 | connect( a, SIGNAL( activated() ), go, SLOT( resign() ) ); | 80 | connect( a, SIGNAL( activated() ), go, SLOT( resign() ) ); |
81 | a->addTo( file ); | 81 | a->addTo( file ); |
82 | 82 | ||
83 | a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 ); | 83 | a = new QAction( tr( "Two player option" ), QString::null, 0, this, 0 ); |
84 | a->setToggleAction( TRUE ); | 84 | a->setToggleAction( TRUE ); |
85 | connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) ); | 85 | connect( a, SIGNAL( toggled(bool) ), go, SLOT( setTwoplayer(bool) ) ); |
86 | a->addTo( file ); | 86 | a->addTo( file ); |
87 | 87 | ||
88 | mb->insertItem( tr( "Game" ), file ); | 88 | mb->insertItem( tr( "Game" ), file ); |
89 | 89 | ||
90 | QLabel *turnLabel = new QLabel( toolbar ); | 90 | QLabel *turnLabel = new QLabel( toolbar ); |
91 | turnLabel->setBackgroundMode( PaletteButton ); | 91 | turnLabel->setBackgroundMode( PaletteButton ); |
92 | connect( go, SIGNAL(showTurn(const QPixmap&)), | 92 | connect( go, SIGNAL(showTurn(const QPixmap&)), |
93 | turnLabel, SLOT(setPixmap(const QPixmap&)) ); | 93 | turnLabel, SLOT(setPixmap(const QPixmap&)) ); |
94 | 94 | ||
95 | 95 | ||
96 | QLabel * scoreLabel = new QLabel( toolbar ); | 96 | QLabel * scoreLabel = new QLabel( toolbar ); |
97 | scoreLabel->setBackgroundMode( PaletteButton ); | 97 | scoreLabel->setBackgroundMode( PaletteButton ); |
98 | connect( go, SIGNAL(showScore(const QString&)), | 98 | connect( go, SIGNAL(showScore(const QString&)), |
99 | scoreLabel, SLOT(setText(const QString&)) ); | 99 | scoreLabel, SLOT(setText(const QString&)) ); |
100 | 100 | ||
101 | toolbar->setStretchableWidget( scoreLabel ); | 101 | toolbar->setStretchableWidget( scoreLabel ); |
102 | 102 | ||
103 | go->readConfig(); | 103 | go->readConfig(); |
104 | } | 104 | } |
105 | 105 | ||
106 | void GoMainWidget::resizeEvent( QResizeEvent * ) | 106 | void GoMainWidget::resizeEvent( QResizeEvent * ) |
107 | { | 107 | { |
108 | //### this won't work because of the text label... | 108 | //### this won't work because of the text label... |
109 | /* | 109 | /* |
110 | if ( width() > height() ) | 110 | if ( width() > height() ) |
111 | moveToolBar( toolbar, Left ); | 111 | moveToolBar( toolbar, Left ); |
112 | else | 112 | else |
113 | moveToolBar( toolbar, Top ); | 113 | moveToolBar( toolbar, Top ); |
114 | */ | 114 | */ |
115 | } | 115 | } |
116 | 116 | ||
117 | GoWidget *GoWidget::self = 0; | 117 | GoWidget *GoWidget::self = 0; |
118 | 118 | ||
119 | GoWidget::GoWidget( QWidget *parent, const char* name) : | 119 | GoWidget::GoWidget( QWidget *parent, const char* name) : |
120 | QWidget( parent, name ) | 120 | QWidget( parent, name ) |
121 | { | 121 | { |
122 | if ( self ) | 122 | if ( self ) |
123 | fatal( "Only one Go widget allowed" ); | 123 | fatal( "Only one Go widget allowed" ); |
124 | self = this; | 124 | self = this; |
125 | twoplayer = FALSE; | 125 | twoplayer = FALSE; |
126 | 126 | ||
127 | 127 | ||
128 | d = bx = by = 1; | 128 | d = bx = by = 1; |
129 | 129 | ||
130 | QPixmap pix = Resource::loadPixmap( "go/pine" ); | 130 | QPixmap pix = Resource::loadPixmap( "go/pine" ); |
131 | goBrush = new QBrush( black, pix ); | 131 | goBrush = new QBrush( black, pix ); |
132 | /* | 132 | /* |
133 | QString fn = Resource::findPixmap("Go-black"); | 133 | QString fn = Resource::findPixmap("Go-black"); |
134 | blackStone = new QImage( fn ); | 134 | blackStone = new QImage( fn ); |
135 | fn = Resource::findPixmap("Go-black-highlight"); | 135 | fn = Resource::findPixmap("Go-black-highlight"); |
136 | newBlackStone = new QImage( fn ); | 136 | newBlackStone = new QImage( fn ); |
137 | fn = Resource::findPixmap("Go-white"); | 137 | fn = Resource::findPixmap("Go-white"); |
138 | whiteStone = new QImage( fn ); | 138 | whiteStone = new QImage( fn ); |
139 | */ | 139 | */ |
140 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); | 140 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); |
141 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); | 141 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); |
142 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); | 142 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); |
143 | 143 | ||
144 | init(); | 144 | init(); |
145 | } | 145 | } |
146 | 146 | ||
147 | GoWidget::~GoWidget() | 147 | GoWidget::~GoWidget() |
148 | { | 148 | { |
149 | writeConfig(); | 149 | writeConfig(); |
150 | } | 150 | } |
151 | 151 | ||
152 | void GoWidget::writeConfig() | 152 | void GoWidget::writeConfig() |
153 | { | 153 | { |
154 | Config cfg("Go"); | 154 | Config cfg("Go"); |
155 | cfg.setGroup("Game"); | 155 | cfg.setGroup("Game"); |
156 | cfg.writeEntry("TwoPlayer", twoplayer); | 156 | cfg.writeEntry("TwoPlayer", twoplayer); |
157 | cfg.writeEntry("CurrentPlayer", currentPlayer); | 157 | cfg.writeEntry("CurrentPlayer", currentPlayer); |
158 | cfg.writeEntry("NPassed", nPassed); | 158 | cfg.writeEntry("NPassed", nPassed); |
159 | QString b; | 159 | QString b; |
160 | for (int i=0; i<19; i++) | 160 | for (int i=0; i<19; i++) |
161 | for (int j=0; j<19; j++) | 161 | for (int j=0; j<19; j++) |
162 | b += board[i][j] == BLACK ? 'B' : board[i][j] == WHITE ? 'W' : '.'; | 162 | b += board[i][j] == BLACK ? 'B' : board[i][j] == WHITE ? 'W' : '.'; |
163 | cfg.writeEntry("Board", b); | 163 | cfg.writeEntry("Board", b); |
164 | cfg.writeEntry("LastX", lastX); | 164 | cfg.writeEntry("LastX", lastX); |
165 | cfg.writeEntry("LastY", lastY); | 165 | cfg.writeEntry("LastY", lastY); |
166 | extern int blackPrisoners, whitePrisoners; | 166 | extern int blackPrisoners, whitePrisoners; |
167 | cfg.writeEntry("BlackPrisoners", blackPrisoners); | 167 | cfg.writeEntry("BlackPrisoners", blackPrisoners); |
168 | cfg.writeEntry("WhitePrisoners", whitePrisoners); | 168 | cfg.writeEntry("WhitePrisoners", whitePrisoners); |
169 | } | 169 | } |
170 | 170 | ||
171 | void GoWidget::readConfig() | 171 | void GoWidget::readConfig() |
172 | { | 172 | { |
173 | init(); | 173 | init(); |
174 | Config cfg("Go"); | 174 | Config cfg("Go"); |
175 | cfg.setGroup("Game"); | 175 | cfg.setGroup("Game"); |
176 | twoplayer = cfg.readBoolEntry("TwoPlayer"); | 176 | twoplayer = cfg.readBoolEntry("TwoPlayer"); |
177 | currentPlayer = (bVal)cfg.readNumEntry("CurrentPlayer",1); | 177 | currentPlayer = (bVal)cfg.readNumEntry("CurrentPlayer",1); |
178 | nPassed = cfg.readNumEntry("NPassed",0); | 178 | nPassed = cfg.readNumEntry("NPassed",0); |
179 | QString b = cfg.readEntry("Board"); | 179 | QString b = cfg.readEntry("Board"); |
180 | if ( b.length() == 19*19 ) | 180 | if ( b.length() == 19*19 ) |
181 | for (int i=0; i<19; i++) | 181 | for (int i=0; i<19; i++) |
182 | for (int j=0; j<19; j++) { | 182 | for (int j=0; j<19; j++) { |
183 | QChar ch = b[j+19*i]; | 183 | QChar ch = b[j+19*i]; |
184 | if ( ch != '.' ) | 184 | if ( ch != '.' ) |
185 | GoPlaceStone( ch == 'B' ? BLACK : WHITE, i, j ); | 185 | GoPlaceStone( ch == 'B' ? BLACK : WHITE, i, j ); |
186 | } | 186 | } |
187 | lastX = cfg.readNumEntry("LastX"); | 187 | lastX = cfg.readNumEntry("LastX"); |
188 | lastY = cfg.readNumEntry("LastY"); | 188 | lastY = cfg.readNumEntry("LastY"); |
189 | extern int blackPrisoners, whitePrisoners; | 189 | extern int blackPrisoners, whitePrisoners; |
190 | blackPrisoners = cfg.readNumEntry("BlackPrisoners",0); | 190 | blackPrisoners = cfg.readNumEntry("BlackPrisoners",0); |
191 | whitePrisoners = cfg.readNumEntry("WhitePrisoners",0); | 191 | whitePrisoners = cfg.readNumEntry("WhitePrisoners",0); |
192 | reportPrisoners(blackPrisoners,whitePrisoners); | 192 | reportPrisoners(blackPrisoners,whitePrisoners); |
193 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); | 193 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); |
194 | } | 194 | } |
195 | 195 | ||
196 | void GoWidget::resizeEvent( QResizeEvent * ) | 196 | void GoWidget::resizeEvent( QResizeEvent * ) |
197 | { | 197 | { |
198 | d = QMIN(width(),height())/19; | 198 | d = QMIN(width(),height())/19; |
199 | // int r = (d/2-1); | 199 | // int r = (d/2-1); |
200 | bx = (width() - 18*d)/2 ; | 200 | bx = (width() - 18*d)/2 ; |
201 | by = (height() - 18*d)/2 ; | 201 | by = (height() - 18*d)/2 ; |
202 | 202 | ||
203 | if ( d < 10 && !smallStones ) { | 203 | if ( d < 10 && !smallStones ) { |
204 | blackStone->convertFromImage( blackStone->convertToImage().smoothScale(8,8) ); | 204 | blackStone->convertFromImage( blackStone->convertToImage().smoothScale(8,8) ); |
205 | whiteStone->convertFromImage( whiteStone->convertToImage().smoothScale(8,8) ); | 205 | whiteStone->convertFromImage( whiteStone->convertToImage().smoothScale(8,8) ); |
206 | newBlackStone->convertFromImage( newBlackStone->convertToImage().smoothScale(8,8) ); | 206 | newBlackStone->convertFromImage( newBlackStone->convertToImage().smoothScale(8,8) ); |
207 | 207 | ||
208 | smallStones = TRUE; | 208 | smallStones = TRUE; |
209 | } else if ( d >= 10 && smallStones ) { | 209 | } else if ( d >= 10 && smallStones ) { |
210 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); | 210 | blackStone = new QPixmap(Resource::loadPixmap( "Go-black" )); |
211 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); | 211 | whiteStone = new QPixmap(Resource::loadPixmap( "Go-white" )); |
212 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); | 212 | newBlackStone = new QPixmap(Resource::loadPixmap( "Go-black-highlight" )); |
213 | smallStones = FALSE; | 213 | smallStones = FALSE; |
214 | } | 214 | } |
215 | } | 215 | } |
216 | 216 | ||
217 | void GoWidget::init() | 217 | void GoWidget::init() |
218 | { | 218 | { |
219 | lastX = lastY = newX = newY = -1; | 219 | lastX = lastY = newX = newY = -1; |
220 | nPassed = 0; | 220 | nPassed = 0; |
221 | for ( int i = 0; i < 19; i++ ) | 221 | for ( int i = 0; i < 19; i++ ) |
222 | for ( int j = 0; j < 19; j++ ) | 222 | for ( int j = 0; j < 19; j++ ) |
223 | board[i][j]=-1; | 223 | board[i][j]=-1; |
224 | gameActive = TRUE; | 224 | gameActive = TRUE; |
225 | goRestart(current_handicap); | 225 | goRestart(current_handicap); |
226 | 226 | ||
227 | if ( twoplayer ) { | 227 | if ( twoplayer ) { |
228 | currentPlayer = BLACK; | 228 | currentPlayer = BLACK; |
229 | } else { | 229 | } else { |
230 | doComputerMove(); | 230 | doComputerMove(); |
231 | currentPlayer = WHITE; | 231 | currentPlayer = WHITE; |
232 | } | 232 | } |
233 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); | 233 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); |
234 | } | 234 | } |
235 | 235 | ||
236 | void GoWidget::paintEvent( QPaintEvent *e ) | 236 | void GoWidget::paintEvent( QPaintEvent *e ) |
237 | { | 237 | { |
238 | int i,j; | 238 | int i,j; |
239 | 239 | ||
240 | int r = whiteStone->width()/2; | 240 | int r = whiteStone->width()/2; |
241 | 241 | ||
242 | QPainter p(this); | 242 | QPainter p(this); |
243 | p.fillRect( bx - d/2, by - d/2, 19*d, 19*d, *goBrush ); | 243 | p.fillRect( bx - d/2, by - d/2, 19*d, 19*d, *goBrush ); |
244 | 244 | ||
245 | int xMin = QMAX( x2board(e->rect().left()), 0 ); | 245 | int xMin = QMAX( x2board(e->rect().left()), 0 ); |
246 | int xMax = QMIN( x2board(e->rect().right()), 18 ); | 246 | int xMax = QMIN( x2board(e->rect().right()), 18 ); |
247 | int yMin = QMAX( y2board(e->rect().top()), 0 ); | 247 | int yMin = QMAX( y2board(e->rect().top()), 0 ); |
248 | int yMax = QMIN( y2board(e->rect().bottom()), 18 ); | 248 | int yMax = QMIN( y2board(e->rect().bottom()), 18 ); |
249 | 249 | ||
250 | QColor pine( 255, 186, 89 ); | 250 | QColor pine( 255, 186, 89 ); |
251 | p.setPen( pine.dark() ); | 251 | p.setPen( pine.dark() ); |
252 | 252 | ||
253 | for ( i = xMin; i < xMax+1 ; i ++ ) { | 253 | for ( i = xMin; i < xMax+1 ; i ++ ) { |
254 | p.drawLine( bx+i*d, by, bx+i*d, by+18*d ); | 254 | p.drawLine( bx+i*d, by, bx+i*d, by+18*d ); |
255 | } | 255 | } |
256 | for ( j = yMin; j < yMax+1 ; j ++ ) { | 256 | for ( j = yMin; j < yMax+1 ; j ++ ) { |
257 | p.drawLine( bx, by+j*d, bx+18*d, by+j*d); | 257 | p.drawLine( bx, by+j*d, bx+18*d, by+j*d); |
258 | } | 258 | } |
259 | 259 | ||
260 | // dots are at (3,3), (3,9), (3,15) and so on | 260 | // dots are at (3,3), (3,9), (3,15) and so on |
261 | p.setBrush( black ); | 261 | p.setBrush( black ); |
262 | for ( i = 3; i < xMax+1; i+=6 ) | 262 | for ( i = 3; i < xMax+1; i+=6 ) |
263 | for ( j = 3; j < yMax+1; j+=6 ) | 263 | for ( j = 3; j < yMax+1; j+=6 ) |
264 | p.drawEllipse( bx+i*d-2, by+j*d-2, 5, 5 ); | 264 | p.drawEllipse( bx+i*d-2, by+j*d-2, 5, 5 ); |
265 | 265 | ||
266 | 266 | ||
267 | for ( i = xMin; i < xMax+1; i++ ) | 267 | for ( i = xMin; i < xMax+1; i++ ) |
268 | for ( j = yMin; j < yMax+1; j++ ) { | 268 | for ( j = yMin; j < yMax+1; j++ ) { |
269 | if ( board[i][j] == WHITE || | 269 | if ( board[i][j] == WHITE || |
270 | currentPlayer==WHITE && newX == i && newY == j ) | 270 | currentPlayer==WHITE && newX == i && newY == j ) |
271 | p.drawPixmap( bx+i*d - r, by+j*d - r, *whiteStone ); | 271 | p.drawPixmap( bx+i*d - r, by+j*d - r, *whiteStone ); |
272 | else if ( i == lastX && j == lastY ) | 272 | else if ( i == lastX && j == lastY ) |
273 | p.drawPixmap( bx+i*d - r, by+j*d - r, *newBlackStone ); | 273 | p.drawPixmap( bx+i*d - r, by+j*d - r, *newBlackStone ); |
274 | else if ( board[i][j] == BLACK || | 274 | else if ( board[i][j] == BLACK || |
275 | currentPlayer==BLACK && newX == i && newY == j) | 275 | currentPlayer==BLACK && newX == i && newY == j) |
276 | p.drawPixmap( bx+i*d - r, by+j*d - r, *blackStone ); | 276 | p.drawPixmap( bx+i*d - r, by+j*d - r, *blackStone ); |
277 | } | 277 | } |
278 | } | 278 | } |
279 | 279 | ||
280 | void GoWidget::doMove( int x, int y ) | 280 | void GoWidget::doMove( int x, int y ) |
281 | { | 281 | { |
282 | 282 | ||
283 | if ( !GoPlaceStone( currentPlayer, x, y ) ) { | 283 | if ( !GoPlaceStone( currentPlayer, x, y ) ) { |
284 | //printf( "Illegal move (%d,%d)\n", x, y ); | 284 | //printf( "Illegal move (%d,%d)\n", x, y ); |
285 | return; | 285 | return; |
286 | } | 286 | } |
287 | //printf( "you do (%d,%d)\n", x, y ); | 287 | //printf( "you do (%d,%d)\n", x, y ); |
288 | nPassed = 0; | 288 | nPassed = 0; |
289 | if ( twoplayer ) | 289 | if ( twoplayer ) |
290 | currentPlayer = (currentPlayer==WHITE) ? BLACK : WHITE; | 290 | currentPlayer = (currentPlayer==WHITE) ? BLACK : WHITE; |
291 | else | 291 | else |
292 | doComputerMove(); | 292 | doComputerMove(); |
293 | 293 | ||
294 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); | 294 | emit showTurn( currentPlayer == WHITE ? *whiteStone : *blackStone ); |
295 | 295 | ||
296 | } | 296 | } |
297 | 297 | ||
298 | void GoWidget::pass() | 298 | void GoWidget::pass() |
299 | { | 299 | { |
300 | if ( !gameActive ) | 300 | if ( !gameActive ) |
301 | return; | 301 | return; |
302 | nPassed++; | 302 | nPassed++; |
303 | if ( nPassed >= 2 ) | 303 | if ( nPassed >= 2 ) |
304 | endGame(); | 304 | endGame(); |
305 | else if ( !twoplayer ) | 305 | else if ( !twoplayer ) |
306 | doComputerMove(); | 306 | doComputerMove(); |
307 | } | 307 | } |
308 | 308 | ||
309 | void GoWidget::resign() | 309 | void GoWidget::resign() |
310 | { | 310 | { |
311 | if ( gameActive ) | 311 | if ( gameActive ) |
312 | endGame(); | 312 | endGame(); |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | void GoWidget::newGame() | 316 | void GoWidget::newGame() |
317 | { | 317 | { |
318 | init(); | 318 | init(); |
319 | update(); | 319 | update(); |
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
323 | void GoWidget::endGame() | 323 | void GoWidget::endGame() |
324 | { | 324 | { |
325 | gameActive = FALSE; | 325 | gameActive = FALSE; |
326 | 326 | ||
327 | int w,b; | 327 | int w,b; |
328 | CountUp( &w, &b); | 328 | CountUp( &w, &b); |
329 | QString s = tr("White %1, Black %2. ").arg(w).arg(b); | 329 | QString s = tr("White %1, Black %2. ").arg(w).arg(b); |
330 | if ( w > b ) | 330 | if ( w > b ) |
331 | s += tr("White wins."); | 331 | s += tr("White wins."); |
332 | else if ( w < b ) | 332 | else if ( w < b ) |
333 | s += tr("Black wins."); | 333 | s += tr("Black wins."); |
334 | else | 334 | else |
335 | s += tr("A draw."); | 335 | s += tr("A draw."); |
336 | emit showScore( s ); | 336 | emit showScore( s ); |
337 | } | 337 | } |
338 | 338 | ||
339 | void GoWidget::doComputerMove() | 339 | void GoWidget::doComputerMove() |
340 | { | 340 | { |
341 | int ox = lastX; | 341 | int ox = lastX; |
342 | int oy = lastY; | 342 | int oy = lastY; |
343 | lastX = lastY = -1; | 343 | lastX = lastY = -1; |
344 | emit showTurn( *blackStone ); | 344 | emit showTurn( *blackStone ); |
345 | refresh( ox, oy); | 345 | refresh( ox, oy); |
346 | qApp->processEvents(); | 346 | qApp->processEvents(); |
347 | short int x,y; | 347 | short int x,y; |
348 | if ( genMove( computer_color, &x, &y ) ) { | 348 | if ( genMove( computer_color, &x, &y ) ) { |
349 | lastX = x; | 349 | lastX = x; |
350 | lastY = y; | 350 | lastY = y; |
351 | //printf( "I do (%d,%d)\n", x, y ); | 351 | //printf( "I do (%d,%d)\n", x, y ); |
352 | GoPlaceStone(computer_color,x,y); | 352 | GoPlaceStone(computer_color,x,y); |
353 | nPassed = 0; | 353 | nPassed = 0; |
354 | } else { | 354 | } else { |
355 | emit showScore( tr("I pass") ); | 355 | emit showScore( tr("I pass") ); |
356 | nPassed++; | 356 | nPassed++; |
357 | if ( nPassed >= 2 ) | 357 | if ( nPassed >= 2 ) |
358 | endGame(); | 358 | endGame(); |
359 | } | 359 | } |
360 | } | 360 | } |
361 | 361 | ||
362 | void GoWidget::mousePressEvent( QMouseEvent *me ) | 362 | void GoWidget::mousePressEvent( QMouseEvent *me ) |
363 | { | 363 | { |
364 | if ( !gameActive ) | 364 | if ( !gameActive ) |
365 | return; | 365 | return; |
366 | int x = x2board(me->x()); | 366 | int x = x2board(me->x()); |
367 | int y = y2board(me->y()); | 367 | int y = y2board(me->y()); |
368 | showStone(x,y,currentPlayer); | 368 | showStone(x,y,currentPlayer); |
369 | } | 369 | } |
370 | 370 | ||
371 | void GoWidget::mouseMoveEvent( QMouseEvent *me ) | 371 | void GoWidget::mouseMoveEvent( QMouseEvent *me ) |
372 | { | 372 | { |
373 | if ( !gameActive ) | 373 | if ( !gameActive ) |
374 | return; | 374 | return; |
375 | int x = x2board(me->x()); | 375 | int x = x2board(me->x()); |
376 | int y = y2board(me->y()); | 376 | int y = y2board(me->y()); |
377 | if ( x != newX || y != newY ) | 377 | if ( x != newX || y != newY ) |
378 | showStone(x,y,currentPlayer); | 378 | showStone(x,y,currentPlayer); |
379 | } | 379 | } |
380 | 380 | ||
381 | void GoWidget::showStone( int x, int y, enum bVal c ) | 381 | void GoWidget::showStone( int x, int y, enum bVal c ) |
382 | { | 382 | { |
383 | 383 | ||
384 | if ( newX > -1 ) { | 384 | if ( newX > -1 ) { |
385 | refresh( newX, newY ); | 385 | refresh( newX, newY ); |
386 | newY = newX = -1; | 386 | newY = newX = -1; |
387 | } | 387 | } |
388 | if ( x < 0 || x > 18 || y < 0 || y > 18 ) { | 388 | if ( x < 0 || x > 18 || y < 0 || y > 18 ) { |
389 | newX = newY = -1; | 389 | newX = newY = -1; |
390 | return; | 390 | return; |
391 | } | 391 | } |
392 | if ( board[x][y] == -1 && !Suicide( c, x, y ) ) { | 392 | if ( board[x][y] == -1 && !Suicide( c, x, y ) ) { |
393 | newX = x; | 393 | newX = x; |
394 | newY = y; | 394 | newY = y; |
395 | refresh(x,y); | 395 | refresh(x,y); |
396 | } | 396 | } |
397 | 397 | ||
398 | } | 398 | } |
399 | 399 | ||
400 | void GoWidget::mouseReleaseEvent( QMouseEvent * ) | 400 | void GoWidget::mouseReleaseEvent( QMouseEvent * ) |
401 | { | 401 | { |
402 | if ( gameActive && newX > -1 ) | 402 | if ( gameActive && newX > -1 ) |
403 | doMove( newX, newY ); | 403 | doMove( newX, newY ); |
404 | newX = newY = -1; | 404 | newX = newY = -1; |
405 | } | 405 | } |
406 | 406 | ||
407 | void GoWidget::refresh( int x, int y ) | 407 | void GoWidget::refresh( int x, int y ) |
408 | { | 408 | { |
409 | update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 ); | 409 | update( bx+d*x-d/2-1, by+d*y-d/2-1, d+2, d+2 ); |
410 | } | 410 | } |
411 | 411 | ||
412 | void GoWidget::removeStone(short x, short y) | 412 | void GoWidget::removeStone(short x, short y) |
413 | { | 413 | { |
414 | board[x][y]=-1; | 414 | board[x][y]=-1; |
415 | refresh( x, y ); | 415 | refresh( x, y ); |
416 | } | 416 | } |
417 | 417 | ||
418 | void GoWidget::placeStone (enum bVal c, short x, short y ) | 418 | void GoWidget::placeStone (enum bVal c, short x, short y ) |
419 | { | 419 | { |
420 | board[x][y]=c; | 420 | board[x][y]=c; |
421 | refresh( x, y ); | 421 | refresh( x, y ); |
422 | } | 422 | } |
423 | 423 | ||
424 | void GoWidget::reportPrisoners( int blackcnt, int whitecnt ) | 424 | void GoWidget::reportPrisoners( int blackcnt, int whitecnt ) |
425 | { | 425 | { |
426 | QString s = tr( "Prisoners: black %1, white %2" ).arg(blackcnt).arg(whitecnt); | 426 | QString s = tr( "Prisoners: black %1, white %2" ).arg(blackcnt).arg(whitecnt); |
427 | emit showScore( s ); | 427 | emit showScore( s ); |
428 | } | 428 | } |
429 | 429 | ||
430 | void GoWidget::setTwoplayer( bool b ) | 430 | void GoWidget::setTwoplayer( bool b ) |
431 | { | 431 | { |
432 | twoplayer = b; | 432 | twoplayer = b; |
433 | } | 433 | } |
434 | 434 | ||
435 | void GoWidget::setHandicap( int h ) | 435 | void GoWidget::setHandicap( int h ) |
436 | { | 436 | { |
437 | current_handicap = h; | 437 | current_handicap = h; |
438 | } | 438 | } |
439 | 439 | ||
440 | 440 | ||
441 | extern "C" { | 441 | extern "C" { |
442 | 442 | ||
443 | voidremovestone(short x, short y) | 443 | voidremovestone(short x, short y) |
444 | { | 444 | { |
445 | GoWidget::self->removeStone(x,y); | 445 | GoWidget::self->removeStone(x,y); |
446 | } | 446 | } |
447 | 447 | ||
448 | voidplacestone (enum bVal c, short x, short y ) | 448 | voidplacestone (enum bVal c, short x, short y ) |
449 | { | 449 | { |
450 | GoWidget::self->placeStone(c,x,y); | 450 | GoWidget::self->placeStone(c,x,y); |
451 | } | 451 | } |
452 | 452 | ||
453 | voidintrMoveReport(enum bVal c ,char *coord ,char *reason ) | 453 | voidintrMoveReport(enum bVal c ,char *coord ,char *reason ) |
454 | { | 454 | { |
455 | qDebug( "intrMoveReport colour %d, %s %s", c, coord, reason ); | 455 | qDebug( "intrMoveReport colour %d, %s %s", c, coord, reason ); |
456 | } | 456 | } |
457 | 457 | ||
458 | voidintrPrisonerReport( short blackcnt, short whitecnt ) | 458 | voidintrPrisonerReport( short blackcnt, short whitecnt ) |
459 | { | 459 | { |
460 | GoWidget::self->reportPrisoners(blackcnt,whitecnt); | 460 | GoWidget::self->reportPrisoners(blackcnt,whitecnt); |
461 | } | 461 | } |
462 | 462 | ||
463 | } | 463 | } |
464 | 464 | ||
diff --git a/noncore/games/mindbreaker/mindbreaker.cpp b/noncore/games/mindbreaker/mindbreaker.cpp index 1a1d05d..7802e38 100644 --- a/noncore/games/mindbreaker/mindbreaker.cpp +++ b/noncore/games/mindbreaker/mindbreaker.cpp | |||
@@ -1,818 +1,818 @@ | |||
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 "mindbreaker.h" | 21 | #include "mindbreaker.h" |
22 | 22 | ||
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | #include <qpe/config.h> | 24 | #include <qpe/config.h> |
25 | 25 | ||
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qpixmap.h> | 27 | #include <qpixmap.h> |
28 | #include <qpe/qpetoolbar.h> | 28 | #include <qpe/qpetoolbar.h> |
29 | #include <qtoolbutton.h> | 29 | #include <qtoolbutton.h> |
30 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
31 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
32 | #include <qlabel.h> | 32 | #include <qlabel.h> |
33 | #include <qstyle.h> | 33 | #include <qstyle.h> |
34 | 34 | ||
35 | #include <stdlib.h> | 35 | #include <stdlib.h> |
36 | #include <sys/time.h> | 36 | #include <sys/time.h> |
37 | #include <unistd.h> | 37 | #include <unistd.h> |
38 | 38 | ||
39 | static int pegRTTI = 3393393; | 39 | static int pegRTTI = 3393393; |
40 | 40 | ||
41 | /* helper class, */ | 41 | /* helper class, */ |
42 | class Peg : public QCanvasRectangle | 42 | class Peg : public QCanvasRectangle |
43 | { | 43 | { |
44 | public: | 44 | public: |
45 | Peg(QCanvas *canvas, int type, int go = -1, int pos = -1); | 45 | Peg(QCanvas *canvas, int type, int go = -1, int pos = -1); |
46 | int rtti() const {return pegRTTI; } | 46 | int rtti() const {return pegRTTI; } |
47 | void advance(int phase); | 47 | void advance(int phase); |
48 | 48 | ||
49 | bool hit( const QPoint &) const; | 49 | bool hit( const QPoint &) const; |
50 | 50 | ||
51 | /* a placed peg is one that has been set down on the board correctly and | 51 | /* a placed peg is one that has been set down on the board correctly and |
52 | should not be moved, only copied */ | 52 | should not be moved, only copied */ |
53 | bool placed() const; | 53 | bool placed() const; |
54 | void setPlaced(bool); | 54 | void setPlaced(bool); |
55 | 55 | ||
56 | int pegGo() const; | 56 | int pegGo() const; |
57 | int pegPos() const; | 57 | int pegPos() const; |
58 | void setPegPos(int); | 58 | void setPegPos(int); |
59 | 59 | ||
60 | int type() const; | 60 | int type() const; |
61 | 61 | ||
62 | static void buildImages(); | 62 | static void buildImages(); |
63 | static QImage imageForType(int t); | 63 | static QImage imageForType(int t); |
64 | 64 | ||
65 | static int eggLevel; | 65 | static int eggLevel; |
66 | 66 | ||
67 | protected: | 67 | protected: |
68 | void drawShape(QPainter &); | 68 | void drawShape(QPainter &); |
69 | private: | 69 | private: |
70 | static QVector<QImage> normalPegs; | 70 | static QVector<QImage> normalPegs; |
71 | static QVector<QImage> specialPegs; | 71 | static QVector<QImage> specialPegs; |
72 | 72 | ||
73 | bool isplaced; | 73 | bool isplaced; |
74 | int pegtype; | 74 | int pegtype; |
75 | int peg_go; | 75 | int peg_go; |
76 | int peg_pos; | 76 | int peg_pos; |
77 | 77 | ||
78 | int aniStep; | 78 | int aniStep; |
79 | }; | 79 | }; |
80 | 80 | ||
81 | int Peg::eggLevel = 0; | 81 | int Peg::eggLevel = 0; |
82 | QVector<QImage> Peg::normalPegs; | 82 | QVector<QImage> Peg::normalPegs; |
83 | QVector<QImage> Peg::specialPegs; | 83 | QVector<QImage> Peg::specialPegs; |
84 | 84 | ||
85 | void Peg::buildImages() | 85 | void Peg::buildImages() |
86 | { | 86 | { |
87 | 87 | ||
88 | QImage pegs = Resource::loadImage("mindbreaker/pegs"); | 88 | QImage pegs = Resource::loadImage("mindbreaker/pegs"); |
89 | int x = 0; | 89 | int x = 0; |
90 | int y = 0; | 90 | int y = 0; |
91 | int i; | 91 | int i; |
92 | eggLevel = 0; | 92 | eggLevel = 0; |
93 | normalPegs.resize(10); | 93 | normalPegs.resize(10); |
94 | for (i = 0; i < 6; i++) { | 94 | for (i = 0; i < 6; i++) { |
95 | normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size))); | 95 | normalPegs.insert(i, new QImage(pegs.copy(x, y, peg_size, peg_size))); |
96 | x += peg_size; | 96 | x += peg_size; |
97 | } | 97 | } |
98 | specialPegs.resize(5); | 98 | specialPegs.resize(5); |
99 | for (i = 0; i < 5; i++) { | 99 | for (i = 0; i < 5; i++) { |
100 | specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size))); | 100 | specialPegs.insert(i, new QImage(pegs.copy(x,y,peg_size, peg_size))); |
101 | x += peg_size; | 101 | x += peg_size; |
102 | } | 102 | } |
103 | 103 | ||
104 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); | 104 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); |
105 | /* copy from master image to functional images */ | 105 | /* copy from master image to functional images */ |
106 | x = 0; | 106 | x = 0; |
107 | y = panel_height; | 107 | y = panel_height; |
108 | normalPegs.insert(8, | 108 | normalPegs.insert(8, |
109 | new QImage(image.copy(x, y, panel_width, panel_height))); | 109 | new QImage(image.copy(x, y, panel_width, panel_height))); |
110 | y += panel_height; | 110 | y += panel_height; |
111 | y += title_height; | 111 | y += title_height; |
112 | normalPegs.insert(9, | 112 | normalPegs.insert(9, |
113 | new QImage(image.copy(x, y, title_width, title_height))); | 113 | new QImage(image.copy(x, y, title_width, title_height))); |
114 | y += title_height; | 114 | y += title_height; |
115 | 115 | ||
116 | x = 6 * peg_size; | 116 | x = 6 * peg_size; |
117 | normalPegs.insert(6, | 117 | normalPegs.insert(6, |
118 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size))); | 118 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size))); |
119 | x += answerpeg_size; | 119 | x += answerpeg_size; |
120 | normalPegs.insert(7, | 120 | normalPegs.insert(7, |
121 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size))); | 121 | new QImage(image.copy(x, y, answerpeg_size, answerpeg_size))); |
122 | } | 122 | } |
123 | 123 | ||
124 | QImage Peg::imageForType(int t) | 124 | QImage Peg::imageForType(int t) |
125 | { | 125 | { |
126 | if (eggLevel > t ) { | 126 | if (eggLevel > t ) { |
127 | if( t < 5) { | 127 | if( t < 5) { |
128 | return *specialPegs[t]; | 128 | return *specialPegs[t]; |
129 | } else { | 129 | } else { |
130 | return *normalPegs[rand() % 6]; | 130 | return *normalPegs[rand() % 6]; |
131 | } | 131 | } |
132 | } | 132 | } |
133 | return *normalPegs[t]; | 133 | return *normalPegs[t]; |
134 | } | 134 | } |
135 | 135 | ||
136 | Peg::Peg(QCanvas *canvas , int t, int g, int p) | 136 | Peg::Peg(QCanvas *canvas , int t, int g, int p) |
137 | : QCanvasRectangle(canvas) | 137 | : QCanvasRectangle(canvas) |
138 | { | 138 | { |
139 | setSize(normalPegs[t]->width(), normalPegs[t]->height() ); | 139 | setSize(normalPegs[t]->width(), normalPegs[t]->height() ); |
140 | pegtype = t; | 140 | pegtype = t; |
141 | isplaced = FALSE; | 141 | isplaced = FALSE; |
142 | peg_pos = p; | 142 | peg_pos = p; |
143 | peg_go = g; | 143 | peg_go = g; |
144 | aniStep = rand() % 6; | 144 | aniStep = rand() % 6; |
145 | setAnimated(TRUE); | 145 | setAnimated(TRUE); |
146 | } | 146 | } |
147 | 147 | ||
148 | void Peg::advance(int phase) { | 148 | void Peg::advance(int phase) { |
149 | if (phase == 0) | 149 | if (phase == 0) |
150 | aniStep = (++aniStep) % 6; | 150 | aniStep = (++aniStep) % 6; |
151 | else { | 151 | else { |
152 | hide(); | 152 | hide(); |
153 | show(); | 153 | show(); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | 156 | ||
157 | void Peg::drawShape(QPainter &p ) | 157 | void Peg::drawShape(QPainter &p ) |
158 | { | 158 | { |
159 | if ((pegtype == 5) && eggLevel > 5) { | 159 | if ((pegtype == 5) && eggLevel > 5) { |
160 | p.drawImage(x(), y(), *normalPegs[aniStep]); | 160 | p.drawImage(x(), y(), *normalPegs[aniStep]); |
161 | } else | 161 | } else |
162 | p.drawImage(x(), y(), imageForType(pegtype)); | 162 | p.drawImage(x(), y(), imageForType(pegtype)); |
163 | } | 163 | } |
164 | 164 | ||
165 | bool Peg::hit( const QPoint &p ) const | 165 | bool Peg::hit( const QPoint &p ) const |
166 | { | 166 | { |
167 | int ix = p.x() - int(x()); | 167 | int ix = p.x() - int(x()); |
168 | int iy = p.y() - int(y()); | 168 | int iy = p.y() - int(y()); |
169 | if (!normalPegs[pegtype]->valid(ix, iy)) | 169 | if (!normalPegs[pegtype]->valid(ix, iy)) |
170 | return FALSE; | 170 | return FALSE; |
171 | QRgb pixel = normalPegs[pegtype]->pixel(ix, iy); | 171 | QRgb pixel = normalPegs[pegtype]->pixel(ix, iy); |
172 | return (qAlpha(pixel ) != 0); | 172 | return (qAlpha(pixel ) != 0); |
173 | } | 173 | } |
174 | 174 | ||
175 | inline bool Peg::placed() const | 175 | inline bool Peg::placed() const |
176 | { | 176 | { |
177 | return isplaced; | 177 | return isplaced; |
178 | } | 178 | } |
179 | 179 | ||
180 | inline int Peg::pegGo() const | 180 | inline int Peg::pegGo() const |
181 | { | 181 | { |
182 | return peg_go; | 182 | return peg_go; |
183 | } | 183 | } |
184 | 184 | ||
185 | inline int Peg::pegPos() const | 185 | inline int Peg::pegPos() const |
186 | { | 186 | { |
187 | return peg_pos; | 187 | return peg_pos; |
188 | } | 188 | } |
189 | 189 | ||
190 | inline void Peg::setPegPos(int p) | 190 | inline void Peg::setPegPos(int p) |
191 | { | 191 | { |
192 | peg_pos = p; | 192 | peg_pos = p; |
193 | } | 193 | } |
194 | 194 | ||
195 | inline void Peg::setPlaced(bool p) | 195 | inline void Peg::setPlaced(bool p) |
196 | { | 196 | { |
197 | isplaced = p; | 197 | isplaced = p; |
198 | } | 198 | } |
199 | 199 | ||
200 | inline int Peg::type() const | 200 | inline int Peg::type() const |
201 | { | 201 | { |
202 | return pegtype; | 202 | return pegtype; |
203 | } | 203 | } |
204 | 204 | ||
205 | /* Load the main image, copy from it the pegs, the board, and the answer image | 205 | /* Load the main image, copy from it the pegs, the board, and the answer image |
206 | * and use these to create the tray, answer and board | 206 | * and use these to create the tray, answer and board |
207 | */ | 207 | */ |
208 | MindBreaker::MindBreaker( QWidget *parent, const char *name, int wFlags ) | 208 | MindBreaker::MindBreaker( QWidget *parent, const char *name, int wFlags ) |
209 | : QMainWindow(parent, name, wFlags), | 209 | : QMainWindow(parent, name, wFlags), |
210 | canvas(board_height, board_width) | 210 | canvas(board_height, board_width) |
211 | { | 211 | { |
212 | MindBreakerBoard *m = new MindBreakerBoard(canvas, this); | 212 | MindBreakerBoard *m = new MindBreakerBoard(canvas, this); |
213 | setCentralWidget(m); | 213 | setCentralWidget(m); |
214 | 214 | ||
215 | setToolBarsMovable( FALSE ); | 215 | setToolBarsMovable( FALSE ); |
216 | 216 | ||
217 | QPEToolBar *tb = new QPEToolBar(this); | 217 | QToolBar *tb = new QToolBar(this); |
218 | tb->setHorizontalStretchable( TRUE ); | 218 | tb->setHorizontalStretchable( TRUE ); |
219 | 219 | ||
220 | QPixmap newicon = Resource::loadPixmap("new"); | 220 | QPixmap newicon = Resource::loadPixmap("new"); |
221 | new QToolButton(newicon, tr("New Game"), 0, | 221 | new QToolButton(newicon, tr("New Game"), 0, |
222 | m, SLOT(clear()), tb, "NewGame"); | 222 | m, SLOT(clear()), tb, "NewGame"); |
223 | 223 | ||
224 | score = new QToolButton(tb); | 224 | score = new QToolButton(tb); |
225 | score->setText(""); | 225 | score->setText(""); |
226 | score->setMaximumHeight(20); | 226 | score->setMaximumHeight(20); |
227 | score->setUsesTextLabel(TRUE); | 227 | score->setUsesTextLabel(TRUE); |
228 | tb->setStretchableWidget(score); | 228 | tb->setStretchableWidget(score); |
229 | 229 | ||
230 | connect(m, SIGNAL(scoreChanged(int, int)), this, SLOT(setScore(int, int))); | 230 | connect(m, SIGNAL(scoreChanged(int, int)), this, SLOT(setScore(int, int))); |
231 | connect(score, SIGNAL(clicked()), m, SLOT(resetScore())); | 231 | connect(score, SIGNAL(clicked()), m, SLOT(resetScore())); |
232 | 232 | ||
233 | int a, b; | 233 | int a, b; |
234 | m->getScore(&a, &b); | 234 | m->getScore(&a, &b); |
235 | setScore(a,b); | 235 | setScore(a,b); |
236 | } | 236 | } |
237 | 237 | ||
238 | void MindBreaker::setScore(int turns, int games) | 238 | void MindBreaker::setScore(int turns, int games) |
239 | { | 239 | { |
240 | double average; | 240 | double average; |
241 | double total_turns = turns; | 241 | double total_turns = turns; |
242 | double total_games = games; | 242 | double total_games = games; |
243 | 243 | ||
244 | if(total_games > 0) | 244 | if(total_games > 0) |
245 | average = total_turns / total_games; | 245 | average = total_turns / total_games; |
246 | else | 246 | else |
247 | average = 0.0; | 247 | average = 0.0; |
248 | 248 | ||
249 | score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games)); | 249 | score->setText(tr("win avg: %1 turns (%2 games)").arg(average).arg(games)); |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | MindBreakerBoard::MindBreakerBoard( QCanvas &canv, QWidget *parent, | 253 | MindBreakerBoard::MindBreakerBoard( QCanvas &canv, QWidget *parent, |
254 | const char *name, int wFlags ) | 254 | const char *name, int wFlags ) |
255 | : QCanvasView(&canv, parent, name, wFlags) | 255 | : QCanvasView(&canv, parent, name, wFlags) |
256 | { | 256 | { |
257 | int i, x, y; | 257 | int i, x, y; |
258 | struct timeval tv; | 258 | struct timeval tv; |
259 | 259 | ||
260 | current_go = 0; | 260 | current_go = 0; |
261 | gettimeofday(&tv, 0); | 261 | gettimeofday(&tv, 0); |
262 | 262 | ||
263 | srand(tv.tv_usec); | 263 | srand(tv.tv_usec); |
264 | 264 | ||
265 | canvas()->setAdvancePeriod(500); | 265 | canvas()->setAdvancePeriod(500); |
266 | 266 | ||
267 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); | 267 | QImage image = Resource::loadImage("mindbreaker/mindbreaker"); |
268 | 268 | ||
269 | /* copy from master image to functional images */ | 269 | /* copy from master image to functional images */ |
270 | x = 0; | 270 | x = 0; |
271 | y = 0; | 271 | y = 0; |
272 | panelImage = image.copy(x,y, panel_width, panel_height); | 272 | panelImage = image.copy(x,y, panel_width, panel_height); |
273 | y += panel_height; | 273 | y += panel_height; |
274 | y += panel_height; | 274 | y += panel_height; |
275 | 275 | ||
276 | titleImage = image.copy(x, y, title_width, title_height); | 276 | titleImage = image.copy(x, y, title_width, title_height); |
277 | 277 | ||
278 | Peg::buildImages(); // must be done BEFORE any pegs are made | 278 | Peg::buildImages(); // must be done BEFORE any pegs are made |
279 | 279 | ||
280 | current_highlight = new Peg(canvas(), 8); | 280 | current_highlight = new Peg(canvas(), 8); |
281 | current_highlight->setPlaced(TRUE); | 281 | current_highlight->setPlaced(TRUE); |
282 | current_highlight->setX(0); | 282 | current_highlight->setX(0); |
283 | current_highlight->setY(board_height - ((current_go + 1) * panel_height)); | 283 | current_highlight->setY(board_height - ((current_go + 1) * panel_height)); |
284 | current_highlight->setZ(0); | 284 | current_highlight->setZ(0); |
285 | current_highlight->show(); | 285 | current_highlight->show(); |
286 | 286 | ||
287 | 287 | ||
288 | /* set up the game */ | 288 | /* set up the game */ |
289 | Config c("MindBreaker", Config::User); | 289 | Config c("MindBreaker", Config::User); |
290 | c.setGroup("Board"); | 290 | c.setGroup("Board"); |
291 | game_over = FALSE; | 291 | game_over = FALSE; |
292 | if (c.readNumEntry("Answer0") < 0) { | 292 | if (c.readNumEntry("Answer0") < 0) { |
293 | for (i = 0; i < 4; i++) { | 293 | for (i = 0; i < 4; i++) { |
294 | answer[i] = rand() % 6; | 294 | answer[i] = rand() % 6; |
295 | current_guess[i] = 6; | 295 | current_guess[i] = 6; |
296 | } | 296 | } |
297 | total_turns = 0; | 297 | total_turns = 0; |
298 | total_games = 0; | 298 | total_games = 0; |
299 | } else { | 299 | } else { |
300 | int j; | 300 | int j; |
301 | c.setGroup("Score"); | 301 | c.setGroup("Score"); |
302 | total_turns = c.readNumEntry("Turns"); | 302 | total_turns = c.readNumEntry("Turns"); |
303 | total_games = c.readNumEntry("Games"); | 303 | total_games = c.readNumEntry("Games"); |
304 | if(total_turns < 0) | 304 | if(total_turns < 0) |
305 | total_turns = 0; | 305 | total_turns = 0; |
306 | if(total_games < 0) | 306 | if(total_games < 0) |
307 | total_games = 0; | 307 | total_games = 0; |
308 | 308 | ||
309 | 309 | ||
310 | checkScores(); | 310 | checkScores(); |
311 | c.setGroup("Board"); | 311 | c.setGroup("Board"); |
312 | for(i = 0; i < 4; i++) | 312 | for(i = 0; i < 4; i++) |
313 | answer[i] = c.readNumEntry(QString("Answer%1").arg(i)); | 313 | answer[i] = c.readNumEntry(QString("Answer%1").arg(i)); |
314 | /* read, and parse past guesses */ | 314 | /* read, and parse past guesses */ |
315 | current_go = 0; | 315 | current_go = 0; |
316 | for(j=0; j < 9; j++) { | 316 | for(j=0; j < 9; j++) { |
317 | current_guess[0] = c.readNumEntry(QString("Go%1p0").arg(j)); | 317 | current_guess[0] = c.readNumEntry(QString("Go%1p0").arg(j)); |
318 | if (current_guess[0] < 0) | 318 | if (current_guess[0] < 0) |
319 | break; | 319 | break; |
320 | placeGuessPeg(0, current_guess[0]); | 320 | placeGuessPeg(0, current_guess[0]); |
321 | current_guess[1] = c.readNumEntry(QString("Go%1p1").arg(j)); | 321 | current_guess[1] = c.readNumEntry(QString("Go%1p1").arg(j)); |
322 | placeGuessPeg(1, current_guess[1]); | 322 | placeGuessPeg(1, current_guess[1]); |
323 | current_guess[2] = c.readNumEntry(QString("Go%1p2").arg(j)); | 323 | current_guess[2] = c.readNumEntry(QString("Go%1p2").arg(j)); |
324 | placeGuessPeg(2, current_guess[2]); | 324 | placeGuessPeg(2, current_guess[2]); |
325 | current_guess[3] = c.readNumEntry(QString("Go%1p3").arg(j)); | 325 | current_guess[3] = c.readNumEntry(QString("Go%1p3").arg(j)); |
326 | placeGuessPeg(3, current_guess[3]); | 326 | placeGuessPeg(3, current_guess[3]); |
327 | checkGuess(); | 327 | checkGuess(); |
328 | } | 328 | } |
329 | for(i = 0; i < 4; i++) { | 329 | for(i = 0; i < 4; i++) { |
330 | current_guess[i] = c.readNumEntry(QString("CurrentGo%1").arg(i)); | 330 | current_guess[i] = c.readNumEntry(QString("CurrentGo%1").arg(i)); |
331 | if (current_guess[i] != 6) | 331 | if (current_guess[i] != 6) |
332 | placeGuessPeg(i, current_guess[i]); | 332 | placeGuessPeg(i, current_guess[i]); |
333 | } | 333 | } |
334 | } | 334 | } |
335 | 335 | ||
336 | /* draw initial screen */ | 336 | /* draw initial screen */ |
337 | drawBackground(); | 337 | drawBackground(); |
338 | canvas()->update(); | 338 | canvas()->update(); |
339 | } | 339 | } |
340 | 340 | ||
341 | MindBreakerBoard::~MindBreakerBoard() | 341 | MindBreakerBoard::~MindBreakerBoard() |
342 | { | 342 | { |
343 | int i, j; | 343 | int i, j; |
344 | if (game_over) { | 344 | if (game_over) { |
345 | current_go = 0; | 345 | current_go = 0; |
346 | /* clear the answer, clear the guess */ | 346 | /* clear the answer, clear the guess */ |
347 | for (i = 0; i < 4; i++) { | 347 | for (i = 0; i < 4; i++) { |
348 | answer[i] = rand() % 6; | 348 | answer[i] = rand() % 6; |
349 | current_guess[i] = 6; | 349 | current_guess[i] = 6; |
350 | } | 350 | } |
351 | } | 351 | } |
352 | 352 | ||
353 | Config c("MindBreaker", Config::User); | 353 | Config c("MindBreaker", Config::User); |
354 | c.setGroup("Board"); | 354 | c.setGroup("Board"); |
355 | c.clearGroup(); | 355 | c.clearGroup(); |
356 | /* write the board */ | 356 | /* write the board */ |
357 | for (i = 0; i < current_go; i++) { | 357 | for (i = 0; i < current_go; i++) { |
358 | for(j = 0; j < 4; j++) | 358 | for(j = 0; j < 4; j++) |
359 | c.writeEntry(tr("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]); | 359 | c.writeEntry(tr("Go%1p%2").arg(i).arg(j), past_guesses[4*i+j]); |
360 | } | 360 | } |
361 | for(j = 0; j < 4; j++) | 361 | for(j = 0; j < 4; j++) |
362 | c.writeEntry(tr("CurrentGo%1").arg(j), current_guess[j]); | 362 | c.writeEntry(tr("CurrentGo%1").arg(j), current_guess[j]); |
363 | for(j = 0; j < 4; j++) | 363 | for(j = 0; j < 4; j++) |
364 | c.writeEntry(tr("Answer%1").arg(j), answer[j]); | 364 | c.writeEntry(tr("Answer%1").arg(j), answer[j]); |
365 | 365 | ||
366 | c.setGroup("Score"); | 366 | c.setGroup("Score"); |
367 | /* write the score */ | 367 | /* write the score */ |
368 | 368 | ||
369 | c.writeEntry("Turns", total_turns); | 369 | c.writeEntry("Turns", total_turns); |
370 | c.writeEntry("Games", total_games); | 370 | c.writeEntry("Games", total_games); |
371 | } | 371 | } |
372 | 372 | ||
373 | void MindBreakerBoard::getScore(int *a, int *b) | 373 | void MindBreakerBoard::getScore(int *a, int *b) |
374 | { | 374 | { |
375 | *a = total_turns; | 375 | *a = total_turns; |
376 | *b = total_games; | 376 | *b = total_games; |
377 | return; | 377 | return; |
378 | } | 378 | } |
379 | 379 | ||
380 | void MindBreakerBoard::placeGuessPeg(int pos, int pegId) | 380 | void MindBreakerBoard::placeGuessPeg(int pos, int pegId) |
381 | { | 381 | { |
382 | int x = first_peg_x_diff + (pos * peg_spacing); | 382 | int x = first_peg_x_diff + (pos * peg_spacing); |
383 | int y = board_height - ((current_go + 1) * panel_height) | 383 | int y = board_height - ((current_go + 1) * panel_height) |
384 | + first_peg_y_diff; | 384 | + first_peg_y_diff; |
385 | 385 | ||
386 | Peg *peg = new Peg(canvas(), pegId, current_go, pos); | 386 | Peg *peg = new Peg(canvas(), pegId, current_go, pos); |
387 | peg->setPegPos(pos); | 387 | peg->setPegPos(pos); |
388 | peg->setPlaced(TRUE); | 388 | peg->setPlaced(TRUE); |
389 | peg->setX(x); | 389 | peg->setX(x); |
390 | peg->setY(y); | 390 | peg->setY(y); |
391 | peg->setZ(2); | 391 | peg->setZ(2); |
392 | peg->show(); | 392 | peg->show(); |
393 | } | 393 | } |
394 | 394 | ||
395 | void MindBreakerBoard::drawBackground() | 395 | void MindBreakerBoard::drawBackground() |
396 | { | 396 | { |
397 | int i, j, x, y, x_gap, y_gap; | 397 | int i, j, x, y, x_gap, y_gap; |
398 | QPixmap background = QPixmap(canvas()->width(), canvas()->height()); | 398 | QPixmap background = QPixmap(canvas()->width(), canvas()->height()); |
399 | 399 | ||
400 | QPainter painter(&background); | 400 | QPainter painter(&background); |
401 | 401 | ||
402 | painter.fillRect(0, 0, canvas()->width(), canvas()->height(), QColor(0,0,0)); | 402 | painter.fillRect(0, 0, canvas()->width(), canvas()->height(), QColor(0,0,0)); |
403 | /* very first thing is to draw the bins, as everything else needs | 403 | /* very first thing is to draw the bins, as everything else needs |
404 | * to be drawn over them */ | 404 | * to be drawn over them */ |
405 | 405 | ||
406 | QPen pen(QColor(85, 45, 27), 4); | 406 | QPen pen(QColor(85, 45, 27), 4); |
407 | painter.setPen(pen); | 407 | painter.setPen(pen); |
408 | x_gap = canvas()->width() - (panel_width + (2 * bin_margin)); | 408 | x_gap = canvas()->width() - (panel_width + (2 * bin_margin)); |
409 | //x_gap += peg_size >> 1; | 409 | //x_gap += peg_size >> 1; |
410 | if (x_gap < 1) | 410 | if (x_gap < 1) |
411 | x_gap = 1; | 411 | x_gap = 1; |
412 | 412 | ||
413 | y_gap = board_height / 6; | 413 | y_gap = board_height / 6; |
414 | y_gap -= (2 * bin_margin); | 414 | y_gap -= (2 * bin_margin); |
415 | //y_gap += peg_size >> 1; | 415 | //y_gap += peg_size >> 1; |
416 | if (y_gap < 1) | 416 | if (y_gap < 1) |
417 | y_gap = 1; | 417 | y_gap = 1; |
418 | x = panel_width + bin_margin - (peg_size >> 1); | 418 | x = panel_width + bin_margin - (peg_size >> 1); |
419 | y = bin_margin - (peg_size >> 1) + 2; | 419 | y = bin_margin - (peg_size >> 1) + 2; |
420 | 420 | ||
421 | for (i = 0; i < 6; i++) { | 421 | for (i = 0; i < 6; i++) { |
422 | for (j = 0; j < 10; j++) { | 422 | for (j = 0; j < 10; j++) { |
423 | int rx = x + (rand() % x_gap); | 423 | int rx = x + (rand() % x_gap); |
424 | int ry = y + (rand() % y_gap); | 424 | int ry = y + (rand() % y_gap); |
425 | painter.drawImage(rx,ry, Peg::imageForType(i)); | 425 | painter.drawImage(rx,ry, Peg::imageForType(i)); |
426 | } | 426 | } |
427 | y += board_height / 6; | 427 | y += board_height / 6; |
428 | } | 428 | } |
429 | /* now draw the surrounding boxes */ | 429 | /* now draw the surrounding boxes */ |
430 | x_gap = canvas()->width() - panel_width; | 430 | x_gap = canvas()->width() - panel_width; |
431 | if (x_gap < 1) x_gap = 1; | 431 | if (x_gap < 1) x_gap = 1; |
432 | y_gap = board_height / 6; | 432 | y_gap = board_height / 6; |
433 | x = panel_width; | 433 | x = panel_width; |
434 | y = 1; | 434 | y = 1; |
435 | 435 | ||
436 | for (i = 0; i < 6; i++) { | 436 | for (i = 0; i < 6; i++) { |
437 | painter.drawRect(x, y, x_gap, y_gap); | 437 | painter.drawRect(x, y, x_gap, y_gap); |
438 | y += y_gap; | 438 | y += y_gap; |
439 | } | 439 | } |
440 | 440 | ||
441 | x = 0; | 441 | x = 0; |
442 | y = 0; | 442 | y = 0; |
443 | 443 | ||
444 | painter.drawImage(x,y, titleImage); | 444 | painter.drawImage(x,y, titleImage); |
445 | y = title_height; | 445 | y = title_height; |
446 | /* now nine gues panels */ | 446 | /* now nine gues panels */ |
447 | for (i = 0; i < 9; i ++) { | 447 | for (i = 0; i < 9; i ++) { |
448 | painter.drawImage(x, y, panelImage); | 448 | painter.drawImage(x, y, panelImage); |
449 | y += panel_height; | 449 | y += panel_height; |
450 | } | 450 | } |
451 | 451 | ||
452 | painter.flush(); | 452 | painter.flush(); |
453 | canvas()->setBackgroundPixmap(background); | 453 | canvas()->setBackgroundPixmap(background); |
454 | } | 454 | } |
455 | 455 | ||
456 | void MindBreakerBoard::checkGuess() | 456 | void MindBreakerBoard::checkGuess() |
457 | { | 457 | { |
458 | int i,j; | 458 | int i,j; |
459 | int num_white = 0; | 459 | int num_white = 0; |
460 | int num_black = 0; | 460 | int num_black = 0; |
461 | int copy_answer[4]; | 461 | int copy_answer[4]; |
462 | int copy_guess[4]; | 462 | int copy_guess[4]; |
463 | 463 | ||
464 | for(i = 0; i < 4; i++) { | 464 | for(i = 0; i < 4; i++) { |
465 | copy_answer[i] = answer[i]; | 465 | copy_answer[i] = answer[i]; |
466 | copy_guess[i] = current_guess[i]; | 466 | copy_guess[i] = current_guess[i]; |
467 | if (current_guess[i] == 6) | 467 | if (current_guess[i] == 6) |
468 | return; | 468 | return; |
469 | if (answer[i] == current_guess[i]) { | 469 | if (answer[i] == current_guess[i]) { |
470 | num_black++; | 470 | num_black++; |
471 | copy_answer[i] = 6; | 471 | copy_answer[i] = 6; |
472 | copy_guess[i] = 7; | 472 | copy_guess[i] = 7; |
473 | } | 473 | } |
474 | } | 474 | } |
475 | 475 | ||
476 | /* now sure that user has completed a 'guess' */ | 476 | /* now sure that user has completed a 'guess' */ |
477 | for (i = 0; i < 4; i++) { | 477 | for (i = 0; i < 4; i++) { |
478 | if (copy_guess[i] == 7) | 478 | if (copy_guess[i] == 7) |
479 | continue; // already marked for a black | 479 | continue; // already marked for a black |
480 | for (j = 0; j < 4; j++) { | 480 | for (j = 0; j < 4; j++) { |
481 | if(copy_guess[i] == copy_answer[j]) { | 481 | if(copy_guess[i] == copy_answer[j]) { |
482 | copy_answer[j] = 6; | 482 | copy_answer[j] = 6; |
483 | num_white++; | 483 | num_white++; |
484 | break; | 484 | break; |
485 | } | 485 | } |
486 | } | 486 | } |
487 | } | 487 | } |
488 | 488 | ||
489 | int x = answerpegx; | 489 | int x = answerpegx; |
490 | int y = (board_height - ((current_go + 1) * panel_height)) + answerpegy; | 490 | int y = (board_height - ((current_go + 1) * panel_height)) + answerpegy; |
491 | 491 | ||
492 | if (num_black == 4) | 492 | if (num_black == 4) |
493 | game_over = TRUE; | 493 | game_over = TRUE; |
494 | 494 | ||
495 | while(num_black > 0) { | 495 | while(num_black > 0) { |
496 | Peg *p = new Peg(canvas(), 7); | 496 | Peg *p = new Peg(canvas(), 7); |
497 | p->setPlaced(TRUE); | 497 | p->setPlaced(TRUE); |
498 | p->setX(x); | 498 | p->setX(x); |
499 | p->setY(y); | 499 | p->setY(y); |
500 | p->setZ(1); | 500 | p->setZ(1); |
501 | p->show(); | 501 | p->show(); |
502 | num_black--; | 502 | num_black--; |
503 | 503 | ||
504 | if (x == answerpegx) | 504 | if (x == answerpegx) |
505 | x = answerpegx + answerpeg_diff; | 505 | x = answerpegx + answerpeg_diff; |
506 | else { | 506 | else { |
507 | x = answerpegx; | 507 | x = answerpegx; |
508 | y += answerpeg_diff; | 508 | y += answerpeg_diff; |
509 | } | 509 | } |
510 | } | 510 | } |
511 | while(num_white > 0){ | 511 | while(num_white > 0){ |
512 | Peg *p = new Peg(canvas(), 6); | 512 | Peg *p = new Peg(canvas(), 6); |
513 | p->setPlaced(TRUE); | 513 | p->setPlaced(TRUE); |
514 | p->setX(x); | 514 | p->setX(x); |
515 | p->setY(y); | 515 | p->setY(y); |
516 | p->setZ(1); | 516 | p->setZ(1); |
517 | p->show(); | 517 | p->show(); |
518 | num_white--; | 518 | num_white--; |
519 | 519 | ||
520 | if (x == answerpegx) | 520 | if (x == answerpegx) |
521 | x = answerpegx + answerpeg_diff; | 521 | x = answerpegx + answerpeg_diff; |
522 | else { | 522 | else { |
523 | x = answerpegx; | 523 | x = answerpegx; |
524 | y += answerpeg_diff; | 524 | y += answerpeg_diff; |
525 | } | 525 | } |
526 | } | 526 | } |
527 | /* move to next go */ | 527 | /* move to next go */ |
528 | for(i = 0; i < 4; i++) { | 528 | for(i = 0; i < 4; i++) { |
529 | past_guesses[4*current_go+i] = current_guess[i]; | 529 | past_guesses[4*current_go+i] = current_guess[i]; |
530 | current_guess[i] = 6; | 530 | current_guess[i] = 6; |
531 | } | 531 | } |
532 | 532 | ||
533 | current_go++; | 533 | current_go++; |
534 | if((current_go > 8) || game_over) { | 534 | if((current_go > 8) || game_over) { |
535 | total_games++; | 535 | total_games++; |
536 | if(!game_over) | 536 | if(!game_over) |
537 | total_turns += 10; | 537 | total_turns += 10; |
538 | else | 538 | else |
539 | total_turns += current_go; | 539 | total_turns += current_go; |
540 | 540 | ||
541 | emit scoreChanged(total_turns, total_games); | 541 | emit scoreChanged(total_turns, total_games); |
542 | Peg *p = new Peg(canvas(), 9); | 542 | Peg *p = new Peg(canvas(), 9); |
543 | game_over = TRUE; | 543 | game_over = TRUE; |
544 | p->setPlaced(TRUE); | 544 | p->setPlaced(TRUE); |
545 | p->setX(0); | 545 | p->setX(0); |
546 | p->setY(0); | 546 | p->setY(0); |
547 | p->setZ(0); | 547 | p->setZ(0); |
548 | p->show(); | 548 | p->show(); |
549 | 549 | ||
550 | for (i = 0; i < 4; i++) { | 550 | for (i = 0; i < 4; i++) { |
551 | p = new Peg(canvas(), answer[i], -1); | 551 | p = new Peg(canvas(), answer[i], -1); |
552 | p->setX(first_peg_x_diff + (i * peg_spacing)); | 552 | p->setX(first_peg_x_diff + (i * peg_spacing)); |
553 | p->setY(5); | 553 | p->setY(5); |
554 | p->setZ(3); | 554 | p->setZ(3); |
555 | p->show(); | 555 | p->show(); |
556 | } | 556 | } |
557 | } else { | 557 | } else { |
558 | current_highlight->setY(board_height - ((current_go + 1) * panel_height)); | 558 | current_highlight->setY(board_height - ((current_go + 1) * panel_height)); |
559 | } | 559 | } |
560 | canvas()->update(); | 560 | canvas()->update(); |
561 | } | 561 | } |
562 | 562 | ||
563 | void MindBreakerBoard::clear() | 563 | void MindBreakerBoard::clear() |
564 | { | 564 | { |
565 | if(!game_over) { | 565 | if(!game_over) { |
566 | total_games++; | 566 | total_games++; |
567 | total_turns += 10; | 567 | total_turns += 10; |
568 | emit scoreChanged(total_turns, total_games); | 568 | emit scoreChanged(total_turns, total_games); |
569 | } | 569 | } |
570 | int i; | 570 | int i; |
571 | /* reset the game board */ | 571 | /* reset the game board */ |
572 | game_over = FALSE; | 572 | game_over = FALSE; |
573 | /* clear the answer, clear the guess */ | 573 | /* clear the answer, clear the guess */ |
574 | for (i = 0; i < 4; i++) { | 574 | for (i = 0; i < 4; i++) { |
575 | answer[i] = rand() % 6; | 575 | answer[i] = rand() % 6; |
576 | current_guess[i] = 6; | 576 | current_guess[i] = 6; |
577 | } | 577 | } |
578 | current_go = 0; | 578 | current_go = 0; |
579 | 579 | ||
580 | QCanvasItemList list = canvas()->allItems(); | 580 | QCanvasItemList list = canvas()->allItems(); |
581 | QCanvasItemList::Iterator it = list.begin(); | 581 | QCanvasItemList::Iterator it = list.begin(); |
582 | for (; it != list.end(); ++it) { | 582 | for (; it != list.end(); ++it) { |
583 | if (*it == current_highlight) | 583 | if (*it == current_highlight) |
584 | continue; | 584 | continue; |
585 | if (*it) | 585 | if (*it) |
586 | delete *it; | 586 | delete *it; |
587 | } | 587 | } |
588 | 588 | ||
589 | current_highlight->setY(board_height - ((current_go + 1) * panel_height)); | 589 | current_highlight->setY(board_height - ((current_go + 1) * panel_height)); |
590 | checkScores(); | 590 | checkScores(); |
591 | drawBackground(); | 591 | drawBackground(); |
592 | canvas()->update(); | 592 | canvas()->update(); |
593 | } | 593 | } |
594 | 594 | ||
595 | void MindBreakerBoard::resetScore() | 595 | void MindBreakerBoard::resetScore() |
596 | { | 596 | { |
597 | /* are u sure */ | 597 | /* are u sure */ |
598 | 598 | ||
599 | if (QMessageBox::information(this, tr( "Reset Statistics" ), | 599 | if (QMessageBox::information(this, tr( "Reset Statistics" ), |
600 | tr( "Reset the win ratio?" ), | 600 | tr( "Reset the win ratio?" ), |
601 | tr( "OK" ), tr( "Cancel" ) ) == 0) { | 601 | tr( "OK" ), tr( "Cancel" ) ) == 0) { |
602 | total_turns = 0; | 602 | total_turns = 0; |
603 | total_games = 0; | 603 | total_games = 0; |
604 | Peg::eggLevel = 0; | 604 | Peg::eggLevel = 0; |
605 | drawBackground(); | 605 | drawBackground(); |
606 | canvas()->update(); | 606 | canvas()->update(); |
607 | emit scoreChanged(total_turns, total_games); | 607 | emit scoreChanged(total_turns, total_games); |
608 | } | 608 | } |
609 | } | 609 | } |
610 | 610 | ||
611 | /* EVENTS */ | 611 | /* EVENTS */ |
612 | 612 | ||
613 | void MindBreakerBoard::contentsMousePressEvent(QMouseEvent *e) | 613 | void MindBreakerBoard::contentsMousePressEvent(QMouseEvent *e) |
614 | { | 614 | { |
615 | copy_press = FALSE; | 615 | copy_press = FALSE; |
616 | null_press = FALSE; | 616 | null_press = FALSE; |
617 | /* ok, first work out if it is one of the bins that | 617 | /* ok, first work out if it is one of the bins that |
618 | got clicked */ | 618 | got clicked */ |
619 | if (e->x() > panel_width) { | 619 | if (e->x() > panel_width) { |
620 | /* its a bin, but which bin */ | 620 | /* its a bin, but which bin */ |
621 | if(e->y() > board_height) | 621 | if(e->y() > board_height) |
622 | return; // missed everything | 622 | return; // missed everything |
623 | int bin = (e->y() + 2) / (board_height / 6); | 623 | int bin = (e->y() + 2) / (board_height / 6); |
624 | 624 | ||
625 | /* make new peg... set it moving */ | 625 | /* make new peg... set it moving */ |
626 | moving_pos = e->pos(); | 626 | moving_pos = e->pos(); |
627 | moving = new Peg(canvas(), bin, current_go); | 627 | moving = new Peg(canvas(), bin, current_go); |
628 | moving->setX(e->x() - (peg_size >> 1)); | 628 | moving->setX(e->x() - (peg_size >> 1)); |
629 | moving->setY(e->y() - (peg_size >> 1)); | 629 | moving->setY(e->y() - (peg_size >> 1)); |
630 | moving->setZ(5); | 630 | moving->setZ(5); |
631 | moving->show(); | 631 | moving->show(); |
632 | canvas()->update(); | 632 | canvas()->update(); |
633 | return; | 633 | return; |
634 | } | 634 | } |
635 | 635 | ||
636 | QCanvasItemList l = canvas()->collisions(e->pos()); | 636 | QCanvasItemList l = canvas()->collisions(e->pos()); |
637 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { | 637 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { |
638 | if ( (*it)->rtti() == pegRTTI ) { | 638 | if ( (*it)->rtti() == pegRTTI ) { |
639 | Peg *item = (Peg *)(*it); | 639 | Peg *item = (Peg *)(*it); |
640 | if (!item->hit(e->pos())) | 640 | if (!item->hit(e->pos())) |
641 | continue; | 641 | continue; |
642 | if (item->type() > 5) { | 642 | if (item->type() > 5) { |
643 | null_press = TRUE; | 643 | null_press = TRUE; |
644 | null_point = e->pos(); | 644 | null_point = e->pos(); |
645 | continue; /* not a color peg */ | 645 | continue; /* not a color peg */ |
646 | } | 646 | } |
647 | if (item->placed()) { | 647 | if (item->placed()) { |
648 | /* copy */ | 648 | /* copy */ |
649 | if(item->pegGo() == -1) | 649 | if(item->pegGo() == -1) |
650 | return; | 650 | return; |
651 | if(item->pegGo() == current_go) { | 651 | if(item->pegGo() == current_go) { |
652 | copy_press = TRUE; | 652 | copy_press = TRUE; |
653 | copy_peg = item; | 653 | copy_peg = item; |
654 | } | 654 | } |
655 | moving = new Peg(canvas(), | 655 | moving = new Peg(canvas(), |
656 | item->type(), current_go); | 656 | item->type(), current_go); |
657 | moving->setX(e->x() - (peg_size >> 1)); | 657 | moving->setX(e->x() - (peg_size >> 1)); |
658 | moving->setY(e->y() - (peg_size >> 1)); | 658 | moving->setY(e->y() - (peg_size >> 1)); |
659 | moving->setZ(5); | 659 | moving->setZ(5); |
660 | moving->show(); | 660 | moving->show(); |
661 | moving_pos = QPoint(e->x(), e->y()); | 661 | moving_pos = QPoint(e->x(), e->y()); |
662 | canvas()->update(); | 662 | canvas()->update(); |
663 | return; | 663 | return; |
664 | } | 664 | } |
665 | moving = (Peg *)*it; | 665 | moving = (Peg *)*it; |
666 | moving_pos = e->pos(); | 666 | moving_pos = e->pos(); |
667 | canvas()->update(); | 667 | canvas()->update(); |
668 | return; | 668 | return; |
669 | } | 669 | } |
670 | } | 670 | } |
671 | null_press = TRUE; | 671 | null_press = TRUE; |
672 | null_point = e->pos(); | 672 | null_point = e->pos(); |
673 | moving = 0; | 673 | moving = 0; |
674 | } | 674 | } |
675 | 675 | ||
676 | void MindBreakerBoard::contentsMouseMoveEvent(QMouseEvent* e) | 676 | void MindBreakerBoard::contentsMouseMoveEvent(QMouseEvent* e) |
677 | { | 677 | { |
678 | if (moving ) { | 678 | if (moving ) { |
679 | moving->moveBy(e->pos().x() - moving_pos.x(), | 679 | moving->moveBy(e->pos().x() - moving_pos.x(), |
680 | e->pos().y() - moving_pos.y()); | 680 | e->pos().y() - moving_pos.y()); |
681 | moving_pos = e->pos(); | 681 | moving_pos = e->pos(); |
682 | canvas()->update(); | 682 | canvas()->update(); |
683 | return; | 683 | return; |
684 | } | 684 | } |
685 | } | 685 | } |
686 | 686 | ||
687 | void MindBreakerBoard::contentsMouseReleaseEvent(QMouseEvent* e) | 687 | void MindBreakerBoard::contentsMouseReleaseEvent(QMouseEvent* e) |
688 | { | 688 | { |
689 | /* time to put down the peg */ | 689 | /* time to put down the peg */ |
690 | if(moving) { | 690 | if(moving) { |
691 | if(copy_press) { | 691 | if(copy_press) { |
692 | /* check if collided with original. if so, delete both */ | 692 | /* check if collided with original. if so, delete both */ |
693 | copy_press = FALSE; | 693 | copy_press = FALSE; |
694 | QCanvasItemList l = canvas()->collisions(e->pos()); | 694 | QCanvasItemList l = canvas()->collisions(e->pos()); |
695 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { | 695 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { |
696 | if (*it == copy_peg) | 696 | if (*it == copy_peg) |
697 | copy_press = TRUE; | 697 | copy_press = TRUE; |
698 | } | 698 | } |
699 | if (copy_press) { | 699 | if (copy_press) { |
700 | current_guess[copy_peg->pegPos()] = 6; | 700 | current_guess[copy_peg->pegPos()] = 6; |
701 | delete copy_peg; | 701 | delete copy_peg; |
702 | delete moving; | 702 | delete moving; |
703 | copy_press = FALSE; | 703 | copy_press = FALSE; |
704 | moving = 0; | 704 | moving = 0; |
705 | copy_peg = 0; | 705 | copy_peg = 0; |
706 | canvas()->update(); | 706 | canvas()->update(); |
707 | return; | 707 | return; |
708 | } | 708 | } |
709 | } | 709 | } |
710 | 710 | ||
711 | /* first work out if in y */ | 711 | /* first work out if in y */ |
712 | if (e->y() > (board_height - (current_go * panel_height))) { | 712 | if (e->y() > (board_height - (current_go * panel_height))) { |
713 | delete moving; | 713 | delete moving; |
714 | moving = 0; | 714 | moving = 0; |
715 | canvas()->update(); | 715 | canvas()->update(); |
716 | return; | 716 | return; |
717 | } | 717 | } |
718 | if (e->y() < (board_height - ((current_go + 1) * panel_height))) { | 718 | if (e->y() < (board_height - ((current_go + 1) * panel_height))) { |
719 | delete moving; | 719 | delete moving; |
720 | moving = 0; | 720 | moving = 0; |
721 | canvas()->update(); | 721 | canvas()->update(); |
722 | return; | 722 | return; |
723 | } | 723 | } |
724 | /* ok, a valid go, but which peg */ | 724 | /* ok, a valid go, but which peg */ |
725 | int x_bar = first_peg_x_diff - (peg_size >> 1); | 725 | int x_bar = first_peg_x_diff - (peg_size >> 1); |
726 | x_bar += peg_spacing; | 726 | x_bar += peg_spacing; |
727 | int pos = 0; | 727 | int pos = 0; |
728 | if (e->x() > x_bar) | 728 | if (e->x() > x_bar) |
729 | pos = 1; | 729 | pos = 1; |
730 | x_bar += peg_spacing; | 730 | x_bar += peg_spacing; |
731 | if (e->x() > x_bar) | 731 | if (e->x() > x_bar) |
732 | pos = 2; | 732 | pos = 2; |
733 | x_bar += peg_spacing; | 733 | x_bar += peg_spacing; |
734 | if (e->x() > x_bar) | 734 | if (e->x() > x_bar) |
735 | pos = 3; | 735 | pos = 3; |
736 | x_bar += peg_spacing; | 736 | x_bar += peg_spacing; |
737 | 737 | ||
738 | if (e->x() > x_bar) { | 738 | if (e->x() > x_bar) { |
739 | /* invalid x */ | 739 | /* invalid x */ |
740 | delete moving; | 740 | delete moving; |
741 | moving = 0; | 741 | moving = 0; |
742 | canvas()->update(); | 742 | canvas()->update(); |
743 | return; | 743 | return; |
744 | } | 744 | } |
745 | 745 | ||
746 | int x = first_peg_x_diff + (pos * peg_spacing); | 746 | int x = first_peg_x_diff + (pos * peg_spacing); |
747 | int y = board_height - ((current_go + 1) * panel_height) | 747 | int y = board_height - ((current_go + 1) * panel_height) |
748 | + first_peg_y_diff; | 748 | + first_peg_y_diff; |
749 | moving->setPegPos(pos); | 749 | moving->setPegPos(pos); |
750 | moving->setX(x); | 750 | moving->setX(x); |
751 | moving->setY(y); | 751 | moving->setY(y); |
752 | moving->setZ(2); | 752 | moving->setZ(2); |
753 | 753 | ||
754 | /* remove all other pegs from this position */ | 754 | /* remove all other pegs from this position */ |
755 | QCanvasItemList l = canvas()->collisions(QPoint(x,y)); | 755 | QCanvasItemList l = canvas()->collisions(QPoint(x,y)); |
756 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { | 756 | for (QCanvasItemList::Iterator it=l.begin(); it !=l.end(); ++it) { |
757 | if ( (*it)->rtti() == pegRTTI ) { | 757 | if ( (*it)->rtti() == pegRTTI ) { |
758 | Peg *item = (Peg *)(*it); | 758 | Peg *item = (Peg *)(*it); |
759 | if ((item != moving) && (item != current_highlight)) | 759 | if ((item != moving) && (item != current_highlight)) |
760 | delete item; | 760 | delete item; |
761 | } | 761 | } |
762 | } | 762 | } |
763 | current_guess[pos] = ((Peg *)moving)->type(); | 763 | current_guess[pos] = ((Peg *)moving)->type(); |
764 | 764 | ||
765 | ((Peg *)moving)->setPlaced(true); | 765 | ((Peg *)moving)->setPlaced(true); |
766 | canvas()->update(); | 766 | canvas()->update(); |
767 | return; | 767 | return; |
768 | } | 768 | } |
769 | moving = 0; | 769 | moving = 0; |
770 | null_point -= e->pos(); | 770 | null_point -= e->pos(); |
771 | if(null_point.manhattanLength() < 6) { | 771 | if(null_point.manhattanLength() < 6) { |
772 | if (game_over) | 772 | if (game_over) |
773 | clear(); | 773 | clear(); |
774 | else | 774 | else |
775 | checkGuess(); | 775 | checkGuess(); |
776 | } | 776 | } |
777 | } | 777 | } |
778 | 778 | ||
779 | void MindBreakerBoard::resizeEvent(QResizeEvent *e) | 779 | void MindBreakerBoard::resizeEvent(QResizeEvent *e) |
780 | { | 780 | { |
781 | QSize s = e->size(); | 781 | QSize s = e->size(); |
782 | int fw = style().defaultFrameWidth(); | 782 | int fw = style().defaultFrameWidth(); |
783 | s.setWidth(s.width() - fw); | 783 | s.setWidth(s.width() - fw); |
784 | s.setHeight(s.height() - fw); | 784 | s.setHeight(s.height() - fw); |
785 | 785 | ||
786 | /* min size is 200 x 260 */ | 786 | /* min size is 200 x 260 */ |
787 | if (s.width() < board_width) | 787 | if (s.width() < board_width) |
788 | s.setWidth(board_width); | 788 | s.setWidth(board_width); |
789 | 789 | ||
790 | if (s.height() < board_height) | 790 | if (s.height() < board_height) |
791 | s.setHeight(board_height); | 791 | s.setHeight(board_height); |
792 | 792 | ||
793 | canvas()->resize(s.width() - fw, s.height() - fw); | 793 | canvas()->resize(s.width() - fw, s.height() - fw); |
794 | drawBackground(); | 794 | drawBackground(); |
795 | } | 795 | } |
796 | 796 | ||
797 | 797 | ||
798 | /* Easter egg function... beat the clock */ | 798 | /* Easter egg function... beat the clock */ |
799 | void MindBreakerBoard::checkScores() | 799 | void MindBreakerBoard::checkScores() |
800 | { | 800 | { |
801 | double games = total_games; | 801 | double games = total_games; |
802 | double turns = total_turns; | 802 | double turns = total_turns; |
803 | double g = games / 10.0; | 803 | double g = games / 10.0; |
804 | Peg::eggLevel = 0; | 804 | Peg::eggLevel = 0; |
805 | 805 | ||
806 | double break_even = 5.0; | 806 | double break_even = 5.0; |
807 | if (g < 1.0) | 807 | if (g < 1.0) |
808 | return; | 808 | return; |
809 | double avg = turns / games; | 809 | double avg = turns / games; |
810 | g--; | 810 | g--; |
811 | while (break_even >= 0.0) { | 811 | while (break_even >= 0.0) { |
812 | if (avg >= (break_even + g)) | 812 | if (avg >= (break_even + g)) |
813 | return; | 813 | return; |
814 | // score a peg. | 814 | // score a peg. |
815 | break_even -= 1.0; | 815 | break_even -= 1.0; |
816 | Peg::eggLevel = int(5.0 - break_even); | 816 | Peg::eggLevel = int(5.0 - break_even); |
817 | } | 817 | } |
818 | } | 818 | } |
diff --git a/noncore/games/minesweep/minesweep.cpp b/noncore/games/minesweep/minesweep.cpp index 814070b..48644b3 100644 --- a/noncore/games/minesweep/minesweep.cpp +++ b/noncore/games/minesweep/minesweep.cpp | |||
@@ -1,405 +1,405 @@ | |||
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 "minesweep.h" | 21 | #include "minesweep.h" |
22 | #include "minefield.h" | 22 | #include "minefield.h" |
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/config.h> | 25 | #include <qpe/config.h> |
26 | 26 | ||
27 | #include <qpe/qpetoolbar.h> | 27 | #include <qpe/qpetoolbar.h> |
28 | #include <qpe/qpemenubar.h> | 28 | #include <qmenubar.h> |
29 | #include <qpopupmenu.h> | 29 | #include <qpopupmenu.h> |
30 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
31 | #include <qlcdnumber.h> | 31 | #include <qlcdnumber.h> |
32 | #include <qmessagebox.h> | 32 | #include <qmessagebox.h> |
33 | #include <qtimer.h> | 33 | #include <qtimer.h> |
34 | #include <qpalette.h> | 34 | #include <qpalette.h> |
35 | #include <qapplication.h> | 35 | #include <qapplication.h> |
36 | #include <qlayout.h> | 36 | #include <qlayout.h> |
37 | #include <qlabel.h> | 37 | #include <qlabel.h> |
38 | 38 | ||
39 | #include <stdlib.h> | 39 | #include <stdlib.h> |
40 | #include <time.h> | 40 | #include <time.h> |
41 | 41 | ||
42 | 42 | ||
43 | 43 | ||
44 | 44 | ||
45 | static const char *pix_new[]={ | 45 | static const char *pix_new[]={ |
46 | "20 20 3 1", | 46 | "20 20 3 1", |
47 | " c None", | 47 | " c None", |
48 | "# c #00FF00", | 48 | "# c #00FF00", |
49 | ". c #000000", | 49 | ". c #000000", |
50 | " ", | 50 | " ", |
51 | " ...... ", | 51 | " ...... ", |
52 | " ..######.. ", | 52 | " ..######.. ", |
53 | " .##########. ", | 53 | " .##########. ", |
54 | " .############. ", | 54 | " .############. ", |
55 | " .##############. ", | 55 | " .##############. ", |
56 | " .##############. ", | 56 | " .##############. ", |
57 | " .################. ", | 57 | " .################. ", |
58 | " .################. ", | 58 | " .################. ", |
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 | /* XPM */ | 72 | /* XPM */ |
73 | static const char * happy_xpm[] = { | 73 | static const char * happy_xpm[] = { |
74 | "20 20 3 1", | 74 | "20 20 3 1", |
75 | " c None", | 75 | " c None", |
76 | ".c #ffff3f ", | 76 | ".c #ffff3f ", |
77 | "#c #000000", | 77 | "#c #000000", |
78 | " ", | 78 | " ", |
79 | " ###### ", | 79 | " ###### ", |
80 | " ##......## ", | 80 | " ##......## ", |
81 | " #..........# ", | 81 | " #..........# ", |
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 | 99 | ||
100 | /* XPM */ | 100 | /* XPM */ |
101 | static const char * worried_xpm[] = { | 101 | static const char * worried_xpm[] = { |
102 | "20 20 3 1", | 102 | "20 20 3 1", |
103 | " c None", | 103 | " c None", |
104 | ".c #ffff3f", | 104 | ".c #ffff3f", |
105 | "#c #000000", | 105 | "#c #000000", |
106 | " ", | 106 | " ", |
107 | " ###### ", | 107 | " ###### ", |
108 | " ##......## ", | 108 | " ##......## ", |
109 | " #..........# ", | 109 | " #..........# ", |
110 | " #............# ", | 110 | " #............# ", |
111 | " #..............# ", | 111 | " #..............# ", |
112 | " #..............# ", | 112 | " #..............# ", |
113 | " #....##....##....# ", | 113 | " #....##....##....# ", |
114 | " #....##....##....# ", | 114 | " #....##....##....# ", |
115 | " #................# ", | 115 | " #................# ", |
116 | " #................# ", | 116 | " #................# ", |
117 | " #................# ", | 117 | " #................# ", |
118 | " #................# ", | 118 | " #................# ", |
119 | " #....######....# ", | 119 | " #....######....# ", |
120 | " #..............# ", | 120 | " #..............# ", |
121 | " #............# ", | 121 | " #............# ", |
122 | " #..........# ", | 122 | " #..........# ", |
123 | " ##......## ", | 123 | " ##......## ", |
124 | " ###### ", | 124 | " ###### ", |
125 | " "}; | 125 | " "}; |
126 | 126 | ||
127 | 127 | ||
128 | /* XPM */ | 128 | /* XPM */ |
129 | static const char * dead_xpm[] = { | 129 | static const char * dead_xpm[] = { |
130 | "20 20 3 1", | 130 | "20 20 3 1", |
131 | " c None", | 131 | " c None", |
132 | ".c #ffff3f", | 132 | ".c #ffff3f", |
133 | "#c #000000", | 133 | "#c #000000", |
134 | " ", | 134 | " ", |
135 | " ###### ", | 135 | " ###### ", |
136 | " ##......## ", | 136 | " ##......## ", |
137 | " #..........# ", | 137 | " #..........# ", |
138 | " #............# ", | 138 | " #............# ", |
139 | " #..............# ", | 139 | " #..............# ", |
140 | " #..#.#...#.#...# ", | 140 | " #..#.#...#.#...# ", |
141 | " #....#.....#.....# ", | 141 | " #....#.....#.....# ", |
142 | " #...#.#...#.#....# ", | 142 | " #...#.#...#.#....# ", |
143 | " #................# ", | 143 | " #................# ", |
144 | " #................# ", | 144 | " #................# ", |
145 | " #................# ", | 145 | " #................# ", |
146 | " #......####......# ", | 146 | " #......####......# ", |
147 | " #....# #....# ", | 147 | " #....# #....# ", |
148 | " #...#......#...# ", | 148 | " #...#......#...# ", |
149 | " #............# ", | 149 | " #............# ", |
150 | " #..........# ", | 150 | " #..........# ", |
151 | " ##......## ", | 151 | " ##......## ", |
152 | " ###### ", | 152 | " ###### ", |
153 | " "}; | 153 | " "}; |
154 | 154 | ||
155 | 155 | ||
156 | class ResultIndicator : private QLabel | 156 | class ResultIndicator : private QLabel |
157 | { | 157 | { |
158 | public: | 158 | public: |
159 | static void showResult( QWidget *ref, bool won ); | 159 | static void showResult( QWidget *ref, bool won ); |
160 | private: | 160 | private: |
161 | ResultIndicator( QWidget *parent, const char *name, WFlags f) | 161 | ResultIndicator( QWidget *parent, const char *name, WFlags f) |
162 | :QLabel( parent, name, f ) {} | 162 | :QLabel( parent, name, f ) {} |
163 | 163 | ||
164 | void timerEvent( QTimerEvent *); | 164 | void timerEvent( QTimerEvent *); |
165 | void center(); | 165 | void center(); |
166 | bool twoStage; | 166 | bool twoStage; |
167 | int timerId; | 167 | int timerId; |
168 | }; | 168 | }; |
169 | 169 | ||
170 | void ResultIndicator::showResult( QWidget *ref, bool won ) | 170 | void ResultIndicator::showResult( QWidget *ref, bool won ) |
171 | { | 171 | { |
172 | ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel ); | 172 | ResultIndicator *r = new ResultIndicator( ref, 0, WStyle_Customize | WStyle_Tool | WType_TopLevel ); |
173 | 173 | ||
174 | r->setAlignment( AlignCenter ); | 174 | r->setAlignment( AlignCenter ); |
175 | r->setFrameStyle( Sunken|StyledPanel ); | 175 | r->setFrameStyle( Sunken|StyledPanel ); |
176 | if ( won ) { | 176 | if ( won ) { |
177 | r->setText( MineSweep::tr("You won!") ); | 177 | r->setText( MineSweep::tr("You won!") ); |
178 | r->center(); | 178 | r->center(); |
179 | r->show(); | 179 | r->show(); |
180 | r->twoStage = FALSE; | 180 | r->twoStage = FALSE; |
181 | r->timerId = r->startTimer(1500); | 181 | r->timerId = r->startTimer(1500); |
182 | } else { | 182 | } else { |
183 | QPalette p( red ); | 183 | QPalette p( red ); |
184 | r->setPalette( p ); | 184 | r->setPalette( p ); |
185 | r->setText( MineSweep::tr("You exploded!") ); | 185 | r->setText( MineSweep::tr("You exploded!") ); |
186 | r->resize( ref->size() ); | 186 | r->resize( ref->size() ); |
187 | r->move( ref->mapToGlobal(QPoint(0,0)) ); | 187 | r->move( ref->mapToGlobal(QPoint(0,0)) ); |
188 | r->show(); | 188 | r->show(); |
189 | r->twoStage = TRUE; | 189 | r->twoStage = TRUE; |
190 | r->timerId =r->startTimer(200); | 190 | r->timerId =r->startTimer(200); |
191 | } | 191 | } |
192 | } | 192 | } |
193 | 193 | ||
194 | void ResultIndicator::center() | 194 | void ResultIndicator::center() |
195 | { | 195 | { |
196 | QWidget *w = parentWidget(); | 196 | QWidget *w = parentWidget(); |
197 | 197 | ||
198 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); | 198 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); |
199 | QSize s = sizeHint()*3; | 199 | QSize s = sizeHint()*3; |
200 | pp = QPoint( pp.x() + w->width()/2 - s.width()/2, | 200 | pp = QPoint( pp.x() + w->width()/2 - s.width()/2, |
201 | pp.y() + w->height()/ 2 - s.height()/2 ); | 201 | pp.y() + w->height()/ 2 - s.height()/2 ); |
202 | 202 | ||
203 | setGeometry( QRect(pp, s) ); | 203 | setGeometry( QRect(pp, s) ); |
204 | 204 | ||
205 | } | 205 | } |
206 | 206 | ||
207 | void ResultIndicator::timerEvent( QTimerEvent *te ) | 207 | void ResultIndicator::timerEvent( QTimerEvent *te ) |
208 | { | 208 | { |
209 | if ( te->timerId() != timerId ) | 209 | if ( te->timerId() != timerId ) |
210 | return; | 210 | return; |
211 | killTimer( timerId ); | 211 | killTimer( timerId ); |
212 | if ( twoStage ) { | 212 | if ( twoStage ) { |
213 | center(); | 213 | center(); |
214 | twoStage = FALSE; | 214 | twoStage = FALSE; |
215 | timerId = startTimer( 1000 ); | 215 | timerId = startTimer( 1000 ); |
216 | } else { | 216 | } else { |
217 | delete this; | 217 | delete this; |
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
222 | class MineFrame : public QFrame | 222 | class MineFrame : public QFrame |
223 | { | 223 | { |
224 | public: | 224 | public: |
225 | MineFrame( QWidget *parent, const char *name = 0 ) | 225 | MineFrame( QWidget *parent, const char *name = 0 ) |
226 | :QFrame( parent, name ) {} | 226 | :QFrame( parent, name ) {} |
227 | void setField( MineField *f ) { field = f; } | 227 | void setField( MineField *f ) { field = f; } |
228 | protected: | 228 | protected: |
229 | void resizeEvent( QResizeEvent *e ) { | 229 | void resizeEvent( QResizeEvent *e ) { |
230 | field->setAvailableRect( contentsRect()); | 230 | field->setAvailableRect( contentsRect()); |
231 | QFrame::resizeEvent(e); | 231 | QFrame::resizeEvent(e); |
232 | } | 232 | } |
233 | private: | 233 | private: |
234 | MineField *field; | 234 | MineField *field; |
235 | }; | 235 | }; |
236 | 236 | ||
237 | 237 | ||
238 | 238 | ||
239 | MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) | 239 | MineSweep::MineSweep( QWidget* parent, const char* name, WFlags f ) |
240 | : QMainWindow( parent, name, f ) | 240 | : QMainWindow( parent, name, f ) |
241 | { | 241 | { |
242 | srand(::time(0)); | 242 | srand(::time(0)); |
243 | setCaption( tr("Mine Hunt") ); | 243 | setCaption( tr("Mine Hunt") ); |
244 | setIcon( Resource::loadPixmap( "minesweep_icon" ) ); | 244 | setIcon( Resource::loadPixmap( "minesweep_icon" ) ); |
245 | 245 | ||
246 | QPEToolBar *toolBar = new QPEToolBar( this ); | 246 | QToolBar *toolBar = new QToolBar( this ); |
247 | toolBar->setHorizontalStretchable( TRUE ); | 247 | toolBar->setHorizontalStretchable( TRUE ); |
248 | 248 | ||
249 | QMenuBar *menuBar = new QMenuBar( toolBar ); | 249 | QMenuBar *menuBar = new QMenuBar( toolBar ); |
250 | 250 | ||
251 | QPopupMenu *gameMenu = new QPopupMenu( this ); | 251 | QPopupMenu *gameMenu = new QPopupMenu( this ); |
252 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); | 252 | gameMenu->insertItem( tr("Beginner"), this, SLOT( beginner() ) ); |
253 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); | 253 | gameMenu->insertItem( tr("Advanced"), this, SLOT( advanced() ) ); |
254 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); | 254 | gameMenu->insertItem( tr("Expert"), this, SLOT( expert() ) ); |
255 | 255 | ||
256 | menuBar->insertItem( tr("Game"), gameMenu ); | 256 | menuBar->insertItem( tr("Game"), gameMenu ); |
257 | 257 | ||
258 | guessLCD = new QLCDNumber( toolBar ); | 258 | guessLCD = new QLCDNumber( toolBar ); |
259 | toolBar->setStretchableWidget( guessLCD ); | 259 | toolBar->setStretchableWidget( guessLCD ); |
260 | 260 | ||
261 | QPalette lcdPal( red ); | 261 | QPalette lcdPal( red ); |
262 | lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); | 262 | lcdPal.setColor( QColorGroup::Background, QApplication::palette().active().background() ); |
263 | lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); | 263 | lcdPal.setColor( QColorGroup::Button, QApplication::palette().active().button() ); |
264 | 264 | ||
265 | // guessLCD->setPalette( lcdPal ); | 265 | // guessLCD->setPalette( lcdPal ); |
266 | guessLCD->setSegmentStyle( QLCDNumber::Flat ); | 266 | guessLCD->setSegmentStyle( QLCDNumber::Flat ); |
267 | guessLCD->setFrameStyle( QFrame::NoFrame ); | 267 | guessLCD->setFrameStyle( QFrame::NoFrame ); |
268 | guessLCD->setNumDigits( 2 ); | 268 | guessLCD->setNumDigits( 2 ); |
269 | guessLCD->setBackgroundMode( PaletteButton ); | 269 | guessLCD->setBackgroundMode( PaletteButton ); |
270 | newGameButton = new QPushButton( toolBar ); | 270 | newGameButton = new QPushButton( toolBar ); |
271 | newGameButton->setPixmap( QPixmap( pix_new ) ); | 271 | newGameButton->setPixmap( QPixmap( pix_new ) ); |
272 | newGameButton->setFocusPolicy(QWidget::NoFocus); | 272 | newGameButton->setFocusPolicy(QWidget::NoFocus); |
273 | connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); | 273 | connect( newGameButton, SIGNAL(clicked()), this, SLOT(newGame()) ); |
274 | 274 | ||
275 | timeLCD = new QLCDNumber( toolBar ); | 275 | timeLCD = new QLCDNumber( toolBar ); |
276 | // timeLCD->setPalette( lcdPal ); | 276 | // timeLCD->setPalette( lcdPal ); |
277 | timeLCD->setSegmentStyle( QLCDNumber::Flat ); | 277 | timeLCD->setSegmentStyle( QLCDNumber::Flat ); |
278 | timeLCD->setFrameStyle( QFrame::NoFrame ); | 278 | timeLCD->setFrameStyle( QFrame::NoFrame ); |
279 | timeLCD->setNumDigits( 5 ); // "mm:ss" | 279 | timeLCD->setNumDigits( 5 ); // "mm:ss" |
280 | timeLCD->setBackgroundMode( PaletteButton ); | 280 | timeLCD->setBackgroundMode( PaletteButton ); |
281 | 281 | ||
282 | setToolBarsMovable ( FALSE ); | 282 | setToolBarsMovable ( FALSE ); |
283 | 283 | ||
284 | addToolBar( toolBar ); | 284 | addToolBar( toolBar ); |
285 | 285 | ||
286 | MineFrame *mainframe = new MineFrame( this ); | 286 | MineFrame *mainframe = new MineFrame( this ); |
287 | mainframe->setFrameShape( QFrame::Box ); | 287 | mainframe->setFrameShape( QFrame::Box ); |
288 | mainframe->setFrameShadow( QFrame::Raised ); | 288 | mainframe->setFrameShadow( QFrame::Raised ); |
289 | 289 | ||
290 | mainframe->setLineWidth(2); | 290 | mainframe->setLineWidth(2); |
291 | 291 | ||
292 | field = new MineField( mainframe ); | 292 | field = new MineField( mainframe ); |
293 | mainframe->setField( field ); | 293 | mainframe->setField( field ); |
294 | QFont fnt = field->font(); | 294 | QFont fnt = field->font(); |
295 | fnt.setBold( TRUE ); | 295 | fnt.setBold( TRUE ); |
296 | field->setFont( QFont( fnt ) ); | 296 | field->setFont( QFont( fnt ) ); |
297 | field->setFocus(); | 297 | field->setFocus(); |
298 | setCentralWidget( mainframe ); | 298 | setCentralWidget( mainframe ); |
299 | 299 | ||
300 | connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) ); | 300 | connect( field, SIGNAL( gameOver( bool ) ), this, SLOT( gameOver( bool ) ) ); |
301 | connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) ); | 301 | connect( field, SIGNAL( mineCount( int ) ), this, SLOT( setCounter( int ) ) ); |
302 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); | 302 | connect( field, SIGNAL( gameStarted()), this, SLOT( startPlaying() ) ); |
303 | 303 | ||
304 | timer = new QTimer( this ); | 304 | timer = new QTimer( this ); |
305 | 305 | ||
306 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); | 306 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateTime() ) ); |
307 | 307 | ||
308 | readConfig(); | 308 | readConfig(); |
309 | } | 309 | } |
310 | 310 | ||
311 | MineSweep::~MineSweep() | 311 | MineSweep::~MineSweep() |
312 | { | 312 | { |
313 | writeConfig(); | 313 | writeConfig(); |
314 | } | 314 | } |
315 | 315 | ||
316 | void MineSweep::gameOver( bool won ) | 316 | void MineSweep::gameOver( bool won ) |
317 | { | 317 | { |
318 | field->showMines(); | 318 | field->showMines(); |
319 | if ( won ) { | 319 | if ( won ) { |
320 | newGameButton->setPixmap( QPixmap( happy_xpm ) ); | 320 | newGameButton->setPixmap( QPixmap( happy_xpm ) ); |
321 | } else { | 321 | } else { |
322 | newGameButton->setPixmap( QPixmap( dead_xpm ) ); | 322 | newGameButton->setPixmap( QPixmap( dead_xpm ) ); |
323 | } | 323 | } |
324 | ResultIndicator::showResult( this, won ); | 324 | ResultIndicator::showResult( this, won ); |
325 | timer->stop(); | 325 | timer->stop(); |
326 | } | 326 | } |
327 | 327 | ||
328 | void MineSweep::newGame() | 328 | void MineSweep::newGame() |
329 | { | 329 | { |
330 | newGame(field->level()); | 330 | newGame(field->level()); |
331 | } | 331 | } |
332 | 332 | ||
333 | void MineSweep::newGame(int level) | 333 | void MineSweep::newGame(int level) |
334 | { | 334 | { |
335 | timeLCD->display( "0:00" ); | 335 | timeLCD->display( "0:00" ); |
336 | field->setup( level ); | 336 | field->setup( level ); |
337 | newGameButton->setPixmap( QPixmap( pix_new ) ); | 337 | newGameButton->setPixmap( QPixmap( pix_new ) ); |
338 | timer->stop(); | 338 | timer->stop(); |
339 | } | 339 | } |
340 | 340 | ||
341 | void MineSweep::startPlaying() | 341 | void MineSweep::startPlaying() |
342 | { | 342 | { |
343 | newGameButton->setPixmap( QPixmap( worried_xpm ) ); | 343 | newGameButton->setPixmap( QPixmap( worried_xpm ) ); |
344 | starttime = QDateTime::currentDateTime(); | 344 | starttime = QDateTime::currentDateTime(); |
345 | timer->start( 1000 ); | 345 | timer->start( 1000 ); |
346 | } | 346 | } |
347 | 347 | ||
348 | void MineSweep::beginner() | 348 | void MineSweep::beginner() |
349 | { | 349 | { |
350 | newGame(1); | 350 | newGame(1); |
351 | } | 351 | } |
352 | 352 | ||
353 | void MineSweep::advanced() | 353 | void MineSweep::advanced() |
354 | { | 354 | { |
355 | newGame(2); | 355 | newGame(2); |
356 | } | 356 | } |
357 | 357 | ||
358 | void MineSweep::expert() | 358 | void MineSweep::expert() |
359 | { | 359 | { |
360 | newGame(3); | 360 | newGame(3); |
361 | } | 361 | } |
362 | 362 | ||
363 | void MineSweep::setCounter( int c ) | 363 | void MineSweep::setCounter( int c ) |
364 | { | 364 | { |
365 | if ( !guessLCD ) | 365 | if ( !guessLCD ) |
366 | return; | 366 | return; |
367 | 367 | ||
368 | guessLCD->display( c ); | 368 | guessLCD->display( c ); |
369 | } | 369 | } |
370 | 370 | ||
371 | void MineSweep::updateTime() | 371 | void MineSweep::updateTime() |
372 | { | 372 | { |
373 | if ( !timeLCD ) | 373 | if ( !timeLCD ) |
374 | return; | 374 | return; |
375 | 375 | ||
376 | int s = starttime.secsTo(QDateTime::currentDateTime()); | 376 | int s = starttime.secsTo(QDateTime::currentDateTime()); |
377 | if ( s/60 > 99 ) | 377 | if ( s/60 > 99 ) |
378 | timeLCD->display( "-----" ); | 378 | timeLCD->display( "-----" ); |
379 | else | 379 | else |
380 | timeLCD->display( QString().sprintf("%2d:%02d",s/60,s%60) ); | 380 | timeLCD->display( QString().sprintf("%2d:%02d",s/60,s%60) ); |
381 | } | 381 | } |
382 | 382 | ||
383 | void MineSweep::writeConfig() const | 383 | void MineSweep::writeConfig() const |
384 | { | 384 | { |
385 | Config cfg("MineSweep"); | 385 | Config cfg("MineSweep"); |
386 | cfg.setGroup("Panel"); | 386 | cfg.setGroup("Panel"); |
387 | cfg.writeEntry("Time", | 387 | cfg.writeEntry("Time", |
388 | timer->isActive() ? starttime.secsTo(QDateTime::currentDateTime()) : -1); | 388 | timer->isActive() ? starttime.secsTo(QDateTime::currentDateTime()) : -1); |
389 | field->writeConfig(cfg); | 389 | field->writeConfig(cfg); |
390 | } | 390 | } |
391 | 391 | ||
392 | void MineSweep::readConfig() | 392 | void MineSweep::readConfig() |
393 | { | 393 | { |
394 | Config cfg("MineSweep"); | 394 | Config cfg("MineSweep"); |
395 | field->readConfig(cfg); | 395 | field->readConfig(cfg); |
396 | cfg.setGroup("Panel"); | 396 | cfg.setGroup("Panel"); |
397 | int s = cfg.readNumEntry("Time",-1); | 397 | int s = cfg.readNumEntry("Time",-1); |
398 | if ( s<0 ) { | 398 | if ( s<0 ) { |
399 | newGame(); | 399 | newGame(); |
400 | } else { | 400 | } else { |
401 | startPlaying(); | 401 | startPlaying(); |
402 | starttime = QDateTime::currentDateTime().addSecs(-s); | 402 | starttime = QDateTime::currentDateTime().addSecs(-s); |
403 | updateTime(); | 403 | updateTime(); |
404 | } | 404 | } |
405 | } | 405 | } |
diff --git a/noncore/games/parashoot/interface.cpp b/noncore/games/parashoot/interface.cpp index 84e5e60..db98720 100644 --- a/noncore/games/parashoot/interface.cpp +++ b/noncore/games/parashoot/interface.cpp | |||
@@ -1,247 +1,247 @@ | |||
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 "interface.h" | 21 | #include "interface.h" |
22 | #include "man.h" | 22 | #include "man.h" |
23 | 23 | ||
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | 25 | ||
26 | #include <qlabel.h> | 26 | #include <qlabel.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qapplication.h> | 28 | #include <qapplication.h> |
29 | #include <qstyle.h> | 29 | #include <qstyle.h> |
30 | #include <qpe/qpetoolbar.h> | 30 | #include <qpe/qpetoolbar.h> |
31 | #include <qtoolbutton.h> | 31 | #include <qtoolbutton.h> |
32 | 32 | ||
33 | ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : | 33 | ParaShoot::ParaShoot(QWidget* parent, const char* name, WFlags f) : |
34 | QMainWindow(parent,name,f), | 34 | QMainWindow(parent,name,f), |
35 | canvas(232, 258), | 35 | canvas(232, 258), |
36 | fanfare("level_up"), | 36 | fanfare("level_up"), |
37 | score(0) | 37 | score(0) |
38 | { | 38 | { |
39 | canvas.setAdvancePeriod(80); | 39 | canvas.setAdvancePeriod(80); |
40 | QPixmap bg = Resource::loadPixmap("parashoot/sky"); | 40 | QPixmap bg = Resource::loadPixmap("parashoot/sky"); |
41 | canvas.setBackgroundPixmap(bg); | 41 | canvas.setBackgroundPixmap(bg); |
42 | 42 | ||
43 | pb = new QCanvasView(&canvas, this); | 43 | pb = new QCanvasView(&canvas, this); |
44 | pb->setFocus(); | 44 | pb->setFocus(); |
45 | 45 | ||
46 | setToolBarsMovable( FALSE ); | 46 | setToolBarsMovable( FALSE ); |
47 | 47 | ||
48 | QPEToolBar* toolbar = new QPEToolBar(this); | 48 | QToolBar* toolbar = new QToolBar(this); |
49 | toolbar->setHorizontalStretchable( TRUE ); | 49 | toolbar->setHorizontalStretchable( TRUE ); |
50 | 50 | ||
51 | setCaption( tr("ParaShoot") ); | 51 | setCaption( tr("ParaShoot") ); |
52 | QPixmap newicon = Resource::loadPixmap("parashoot/manicon"); | 52 | QPixmap newicon = Resource::loadPixmap("parashoot/manicon"); |
53 | setIcon(newicon); | 53 | setIcon(newicon); |
54 | new QToolButton(newicon, tr("New Game"), 0, | 54 | new QToolButton(newicon, tr("New Game"), 0, |
55 | this, SLOT(newGame()), toolbar, "New Game"); | 55 | this, SLOT(newGame()), toolbar, "New Game"); |
56 | 56 | ||
57 | levelscore = new QLabel(toolbar); | 57 | levelscore = new QLabel(toolbar); |
58 | levelscore->setBackgroundMode( PaletteButton ); | 58 | levelscore->setBackgroundMode( PaletteButton ); |
59 | levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); | 59 | levelscore->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); |
60 | toolbar->setStretchableWidget( levelscore ); | 60 | toolbar->setStretchableWidget( levelscore ); |
61 | showScore(0,0); | 61 | showScore(0,0); |
62 | 62 | ||
63 | setCentralWidget(pb); | 63 | setCentralWidget(pb); |
64 | 64 | ||
65 | autoDropTimer = new QTimer(this); | 65 | autoDropTimer = new QTimer(this); |
66 | connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); | 66 | connect (autoDropTimer, SIGNAL(timeout()), this, SLOT(play()) ); |
67 | 67 | ||
68 | pauseTimer = new QTimer(this); | 68 | pauseTimer = new QTimer(this); |
69 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); | 69 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); |
70 | 70 | ||
71 | setFocusPolicy(StrongFocus); | 71 | setFocusPolicy(StrongFocus); |
72 | 72 | ||
73 | newGame(); | 73 | newGame(); |
74 | } | 74 | } |
75 | 75 | ||
76 | 76 | ||
77 | void ParaShoot::resizeEvent(QResizeEvent *) | 77 | void ParaShoot::resizeEvent(QResizeEvent *) |
78 | { | 78 | { |
79 | QSize s = centralWidget()->size(); | 79 | QSize s = centralWidget()->size(); |
80 | int fw = style().defaultFrameWidth(); | 80 | int fw = style().defaultFrameWidth(); |
81 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); | 81 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | void ParaShoot::showScore( int score, int level ) | 85 | void ParaShoot::showScore( int score, int level ) |
86 | { | 86 | { |
87 | levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); | 87 | levelscore->setText(tr(" Level: %1 Score: %2 ").arg(score).arg(level) ); |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | void ParaShoot::newGame() | 91 | void ParaShoot::newGame() |
92 | { | 92 | { |
93 | clear(); | 93 | clear(); |
94 | if (pauseTimer->isActive()) | 94 | if (pauseTimer->isActive()) |
95 | pauseTimer->stop(); | 95 | pauseTimer->stop(); |
96 | clear(); | 96 | clear(); |
97 | Man::setManCount(0); | 97 | Man::setManCount(0); |
98 | score = 0; | 98 | score = 0; |
99 | Bullet::setShotCount(0); | 99 | Bullet::setShotCount(0); |
100 | Bullet::setNobullets(0); | 100 | Bullet::setNobullets(0); |
101 | nomen = 2; | 101 | nomen = 2; |
102 | Bullet::setLimit(nomen); | 102 | Bullet::setLimit(nomen); |
103 | level = 0; | 103 | level = 0; |
104 | updatespeed = 80; | 104 | updatespeed = 80; |
105 | showScore(0,0); | 105 | showScore(0,0); |
106 | gamestopped = false; | 106 | gamestopped = false; |
107 | Helicopter::deleteAll(); | 107 | Helicopter::deleteAll(); |
108 | waitover = true; | 108 | waitover = true; |
109 | base = new Base(&canvas); | 109 | base = new Base(&canvas); |
110 | cannon = new Cannon(&canvas); | 110 | cannon = new Cannon(&canvas); |
111 | connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); | 111 | connect( cannon, SIGNAL(score(int)), this, SLOT(increaseScore(int))); |
112 | autoDropTimer->start(100); | 112 | autoDropTimer->start(100); |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | void ParaShoot::clear() | 116 | void ParaShoot::clear() |
117 | { | 117 | { |
118 | autoDropTimer->stop(); | 118 | autoDropTimer->stop(); |
119 | // QCanvasItem* item; | 119 | // QCanvasItem* item; |
120 | QCanvasItemList l = canvas.allItems(); | 120 | QCanvasItemList l = canvas.allItems(); |
121 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 121 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
122 | delete *it; | 122 | delete *it; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | void ParaShoot::gameOver() | 126 | void ParaShoot::gameOver() |
127 | { | 127 | { |
128 | QCanvasItem* item; | 128 | QCanvasItem* item; |
129 | QCanvasItemList l = canvas.allItems(); | 129 | QCanvasItemList l = canvas.allItems(); |
130 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 130 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
131 | item = *it; | 131 | item = *it; |
132 | if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) | 132 | if ((item->rtti()==1500) || (item->rtti()==1600) || item->rtti()==1900) |
133 | item->setAnimated(false); | 133 | item->setAnimated(false); |
134 | } | 134 | } |
135 | autoDropTimer->stop(); | 135 | autoDropTimer->stop(); |
136 | Helicopter::silenceAll(); | 136 | Helicopter::silenceAll(); |
137 | 137 | ||
138 | int shots = Bullet::getShotCount(); | 138 | int shots = Bullet::getShotCount(); |
139 | 139 | ||
140 | int shotsFired = cannon->shotsFired(); | 140 | int shotsFired = cannon->shotsFired(); |
141 | if ( shotsFired == 0 ) | 141 | if ( shotsFired == 0 ) |
142 | shotsFired = 1; | 142 | shotsFired = 1; |
143 | QCanvasText* gameover = new QCanvasText( | 143 | QCanvasText* gameover = new QCanvasText( |
144 | tr( " GAME OVER!\n" | 144 | tr( " GAME OVER!\n" |
145 | " Your Score: %1\n" | 145 | " Your Score: %1\n" |
146 | " Parachuters Killed: %2\n" | 146 | " Parachuters Killed: %2\n" |
147 | " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), | 147 | " Accuracy: %3% " ).arg(score).arg(shots).arg(shots * 100 / shotsFired ), |
148 | &canvas); | 148 | &canvas); |
149 | gameover->setColor(red); | 149 | gameover->setColor(red); |
150 | gameover->setFont( QFont("times", 18, QFont::Bold) ); | 150 | gameover->setFont( QFont("times", 18, QFont::Bold) ); |
151 | gameover->move(canvas.width()/2 -110, canvas.height()/2 -50); | 151 | gameover->move(canvas.width()/2 -110, canvas.height()/2 -50); |
152 | gameover->setZ(500); | 152 | gameover->setZ(500); |
153 | gameover->show(); | 153 | gameover->show(); |
154 | gamestopped = true; | 154 | gamestopped = true; |
155 | waitover = false; | 155 | waitover = false; |
156 | pauseTimer->start(3000); | 156 | pauseTimer->start(3000); |
157 | } | 157 | } |
158 | 158 | ||
159 | void ParaShoot::wait() | 159 | void ParaShoot::wait() |
160 | { | 160 | { |
161 | waitover = true; | 161 | waitover = true; |
162 | pauseTimer->stop(); | 162 | pauseTimer->stop(); |
163 | } | 163 | } |
164 | 164 | ||
165 | void ParaShoot::play() | 165 | void ParaShoot::play() |
166 | { | 166 | { |
167 | if (Man::getManCount() < nomen ) { | 167 | if (Man::getManCount() < nomen ) { |
168 | new Man(&canvas); | 168 | new Man(&canvas); |
169 | } | 169 | } |
170 | if (Base::baseDestroyed()) { | 170 | if (Base::baseDestroyed()) { |
171 | gameOver(); | 171 | gameOver(); |
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | } | 174 | } |
175 | 175 | ||
176 | void ParaShoot::increaseScore(int x) | 176 | void ParaShoot::increaseScore(int x) |
177 | { | 177 | { |
178 | score += x; | 178 | score += x; |
179 | if ( score / 150 != (score-x) / 150 ) | 179 | if ( score / 150 != (score-x) / 150 ) |
180 | levelUp(); | 180 | levelUp(); |
181 | showScore(level,score); | 181 | showScore(level,score); |
182 | } | 182 | } |
183 | 183 | ||
184 | void ParaShoot::levelUp() | 184 | void ParaShoot::levelUp() |
185 | { | 185 | { |
186 | level++; | 186 | level++; |
187 | int stage = level % 3; | 187 | int stage = level % 3; |
188 | switch(stage) { | 188 | switch(stage) { |
189 | case 0: | 189 | case 0: |
190 | nomen++; | 190 | nomen++; |
191 | Bullet::setLimit(nomen); | 191 | Bullet::setLimit(nomen); |
192 | fanfare.play(); | 192 | fanfare.play(); |
193 | break; | 193 | break; |
194 | case 1: | 194 | case 1: |
195 | new Helicopter(&canvas); | 195 | new Helicopter(&canvas); |
196 | break; | 196 | break; |
197 | case 2: | 197 | case 2: |
198 | moveFaster(); | 198 | moveFaster(); |
199 | fanfare.play(); | 199 | fanfare.play(); |
200 | break; | 200 | break; |
201 | default: return; | 201 | default: return; |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | void ParaShoot::moveFaster() | 205 | void ParaShoot::moveFaster() |
206 | { | 206 | { |
207 | if (updatespeed > 50) | 207 | if (updatespeed > 50) |
208 | updatespeed = updatespeed-5; | 208 | updatespeed = updatespeed-5; |
209 | else | 209 | else |
210 | updatespeed = updatespeed-3; | 210 | updatespeed = updatespeed-3; |
211 | canvas.setAdvancePeriod(updatespeed); | 211 | canvas.setAdvancePeriod(updatespeed); |
212 | } | 212 | } |
213 | 213 | ||
214 | void ParaShoot::keyPressEvent(QKeyEvent* event) | 214 | void ParaShoot::keyPressEvent(QKeyEvent* event) |
215 | { | 215 | { |
216 | if (gamestopped) { | 216 | if (gamestopped) { |
217 | if (waitover) | 217 | if (waitover) |
218 | newGame(); | 218 | newGame(); |
219 | else | 219 | else |
220 | return; | 220 | return; |
221 | } else { | 221 | } else { |
222 | switch(event->key()) { | 222 | switch(event->key()) { |
223 | case Key_Up: | 223 | case Key_Up: |
224 | case Key_F1: | 224 | case Key_F1: |
225 | case Key_F9: | 225 | case Key_F9: |
226 | case Key_Space: | 226 | case Key_Space: |
227 | cannon->shoot(); | 227 | cannon->shoot(); |
228 | break; | 228 | break; |
229 | case Key_Left: | 229 | case Key_Left: |
230 | cannon->pointCannon(Cannon::Left); | 230 | cannon->pointCannon(Cannon::Left); |
231 | lastcannonkey=Key_Left; | 231 | lastcannonkey=Key_Left; |
232 | break; | 232 | break; |
233 | case Key_Right: | 233 | case Key_Right: |
234 | cannon->pointCannon(Cannon::Right); | 234 | cannon->pointCannon(Cannon::Right); |
235 | lastcannonkey=Key_Right; | 235 | lastcannonkey=Key_Right; |
236 | break; | 236 | break; |
237 | default: | 237 | default: |
238 | return; | 238 | return; |
239 | } | 239 | } |
240 | } | 240 | } |
241 | } | 241 | } |
242 | 242 | ||
243 | void ParaShoot::keyReleaseEvent(QKeyEvent* event) | 243 | void ParaShoot::keyReleaseEvent(QKeyEvent* event) |
244 | { | 244 | { |
245 | if ( lastcannonkey == event->key() ) | 245 | if ( lastcannonkey == event->key() ) |
246 | cannon->pointCannon(Cannon::NoDir); | 246 | cannon->pointCannon(Cannon::NoDir); |
247 | } | 247 | } |
diff --git a/noncore/games/snake/interface.cpp b/noncore/games/snake/interface.cpp index 68e0f14..f1227cb 100644 --- a/noncore/games/snake/interface.cpp +++ b/noncore/games/snake/interface.cpp | |||
@@ -1,221 +1,221 @@ | |||
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 "interface.h" | 21 | #include "interface.h" |
22 | 22 | ||
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | 24 | ||
25 | #include <qpe/qpetoolbar.h> | 25 | #include <qpe/qpetoolbar.h> |
26 | #include <qtoolbutton.h> | 26 | #include <qtoolbutton.h> |
27 | #include <qstyle.h> | 27 | #include <qstyle.h> |
28 | #include <qapplication.h> | 28 | #include <qapplication.h> |
29 | #include <qmessagebox.h> | 29 | #include <qmessagebox.h> |
30 | 30 | ||
31 | SnakeGame::SnakeGame(QWidget* parent, const char* name, WFlags f) : | 31 | SnakeGame::SnakeGame(QWidget* parent, const char* name, WFlags f) : |
32 | QMainWindow(parent,name,f), | 32 | QMainWindow(parent,name,f), |
33 | canvas(232, 258) | 33 | canvas(232, 258) |
34 | { | 34 | { |
35 | setCaption( tr("Snake") ); | 35 | setCaption( tr("Snake") ); |
36 | QPixmap bg = Resource::loadPixmap("snake/grass"); | 36 | QPixmap bg = Resource::loadPixmap("snake/grass"); |
37 | canvas.setBackgroundPixmap(bg); | 37 | canvas.setBackgroundPixmap(bg); |
38 | canvas.setUpdatePeriod(100); | 38 | canvas.setUpdatePeriod(100); |
39 | snake = 0; | 39 | snake = 0; |
40 | 40 | ||
41 | cv = new QCanvasView(&canvas, this); | 41 | cv = new QCanvasView(&canvas, this); |
42 | 42 | ||
43 | pauseTimer = new QTimer(this); | 43 | pauseTimer = new QTimer(this); |
44 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); | 44 | connect(pauseTimer, SIGNAL(timeout()), this, SLOT(wait()) ); |
45 | 45 | ||
46 | setToolBarsMovable( FALSE ); | 46 | setToolBarsMovable( FALSE ); |
47 | 47 | ||
48 | QPEToolBar* toolbar = new QPEToolBar( this); | 48 | QToolBar* toolbar = new QToolBar( this); |
49 | toolbar->setHorizontalStretchable( TRUE ); | 49 | toolbar->setHorizontalStretchable( TRUE ); |
50 | 50 | ||
51 | QPixmap newicon = Resource::loadPixmap("ksnake"); | 51 | QPixmap newicon = Resource::loadPixmap("ksnake"); |
52 | setIcon(newicon); | 52 | setIcon(newicon); |
53 | (void)new QToolButton(newicon, tr("New Game"), 0, | 53 | (void)new QToolButton(newicon, tr("New Game"), 0, |
54 | this, SLOT(newGame()), toolbar, "New Game"); | 54 | this, SLOT(newGame()), toolbar, "New Game"); |
55 | 55 | ||
56 | scorelabel = new QLabel(toolbar); | 56 | scorelabel = new QLabel(toolbar); |
57 | showScore(0); | 57 | showScore(0); |
58 | scorelabel->setBackgroundMode( PaletteButton ); | 58 | scorelabel->setBackgroundMode( PaletteButton ); |
59 | scorelabel->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); | 59 | scorelabel->setAlignment( AlignRight | AlignVCenter | ExpandTabs ); |
60 | toolbar->setStretchableWidget( scorelabel ); | 60 | toolbar->setStretchableWidget( scorelabel ); |
61 | 61 | ||
62 | setFocusPolicy(StrongFocus); | 62 | setFocusPolicy(StrongFocus); |
63 | 63 | ||
64 | setCentralWidget(cv); | 64 | setCentralWidget(cv); |
65 | 65 | ||
66 | QTimer::singleShot( 16, this, SLOT(welcomescreen()) ); | 66 | QTimer::singleShot( 16, this, SLOT(welcomescreen()) ); |
67 | gamestopped = true; | 67 | gamestopped = true; |
68 | waitover = true; | 68 | waitover = true; |
69 | } | 69 | } |
70 | 70 | ||
71 | SnakeGame::~SnakeGame() | 71 | SnakeGame::~SnakeGame() |
72 | { | 72 | { |
73 | delete snake; | 73 | delete snake; |
74 | } | 74 | } |
75 | 75 | ||
76 | void SnakeGame::resizeEvent(QResizeEvent *) | 76 | void SnakeGame::resizeEvent(QResizeEvent *) |
77 | { | 77 | { |
78 | QSize s = centralWidget()->size(); | 78 | QSize s = centralWidget()->size(); |
79 | int fw = style().defaultFrameWidth(); | 79 | int fw = style().defaultFrameWidth(); |
80 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); | 80 | canvas.resize( s.width() - fw - 2, s.height() - fw - 2); |
81 | } | 81 | } |
82 | 82 | ||
83 | void SnakeGame::welcomescreen() | 83 | void SnakeGame::welcomescreen() |
84 | { | 84 | { |
85 | QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas); | 85 | QCanvasText* title = new QCanvasText(tr("SNAKE!"), &canvas); |
86 | title->setColor(yellow); | 86 | title->setColor(yellow); |
87 | title->setFont( QFont("times", 18, QFont::Bold) ); | 87 | title->setFont( QFont("times", 18, QFont::Bold) ); |
88 | int w = title->boundingRect().width(); | 88 | int w = title->boundingRect().width(); |
89 | title->move(canvas.width()/2 -w/2, canvas.height()/2-110); | 89 | title->move(canvas.width()/2 -w/2, canvas.height()/2-110); |
90 | title->show(); | 90 | title->show(); |
91 | QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("snake/title")); | 91 | QCanvasPixmapArray* titlearray = new QCanvasPixmapArray(Resource::findPixmap("snake/title")); |
92 | QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas); | 92 | QCanvasSprite* titlepic = new QCanvasSprite(titlearray, &canvas); |
93 | titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85); | 93 | titlepic->move(canvas.width()/2 - 33, canvas.height()/2-85); |
94 | titlepic->show(); | 94 | titlepic->show(); |
95 | QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n" | 95 | QCanvasText* instr = new QCanvasText(tr("Use the arrow keys to guide the\n" |
96 | "snake to eat the mouse. You must not\n" | 96 | "snake to eat the mouse. You must not\n" |
97 | "crash into the walls, edges or its tail."), | 97 | "crash into the walls, edges or its tail."), |
98 | &canvas); | 98 | &canvas); |
99 | w = instr->boundingRect().width(); | 99 | w = instr->boundingRect().width(); |
100 | instr->move(canvas.width()/2-w/2, canvas.height()/2-20); | 100 | instr->move(canvas.width()/2-w/2, canvas.height()/2-20); |
101 | instr->setColor(white); | 101 | instr->setColor(white); |
102 | instr->show(); | 102 | instr->show(); |
103 | QCanvasText* cont = new QCanvasText(tr("Press any key to start"), &canvas); | 103 | QCanvasText* cont = new QCanvasText(tr("Press any key to start"), &canvas); |
104 | w = cont->boundingRect().width(); | 104 | w = cont->boundingRect().width(); |
105 | cont->move(canvas.width()/2-w/2, canvas.height()-20); | 105 | cont->move(canvas.width()/2-w/2, canvas.height()-20); |
106 | cont->setColor(yellow); | 106 | cont->setColor(yellow); |
107 | cont->show(); | 107 | cont->show(); |
108 | 108 | ||
109 | } | 109 | } |
110 | 110 | ||
111 | void SnakeGame::newGame() | 111 | void SnakeGame::newGame() |
112 | { | 112 | { |
113 | clear(); | 113 | clear(); |
114 | snake = new Snake(&canvas); | 114 | snake = new Snake(&canvas); |
115 | connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) ); | 115 | connect(snake, SIGNAL(dead()), this, SLOT(gameOver()) ); |
116 | connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) ); | 116 | connect(snake, SIGNAL(targethit()), this, SLOT(levelUp()) ); |
117 | connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) ); | 117 | connect(snake, SIGNAL(scorechanged()), this, SLOT(scoreInc()) ); |
118 | connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) ); | 118 | connect(this, SIGNAL(moveFaster()), snake, SLOT(increaseSpeed()) ); |
119 | last = 0; | 119 | last = 0; |
120 | targetamount = 1; | 120 | targetamount = 1; |
121 | notargets = 1; | 121 | notargets = 1; |
122 | level = 1; | 122 | level = 1; |
123 | stage = 1; | 123 | stage = 1; |
124 | showScore(0); | 124 | showScore(0); |
125 | gamestopped = false; | 125 | gamestopped = false; |
126 | waitover = true; | 126 | waitover = true; |
127 | int y = canvas.height()-50; | 127 | int y = canvas.height()-50; |
128 | (void)new Obstacle(&canvas, 32); | 128 | (void)new Obstacle(&canvas, 32); |
129 | (void)new Obstacle(&canvas, y); | 129 | (void)new Obstacle(&canvas, y); |
130 | createTargets(); | 130 | createTargets(); |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | void SnakeGame::showScore(int score) | 134 | void SnakeGame::showScore(int score) |
135 | { | 135 | { |
136 | scorelabel->setText(tr(" Score : %1 ").arg(score) ); | 136 | scorelabel->setText(tr(" Score : %1 ").arg(score) ); |
137 | } | 137 | } |
138 | 138 | ||
139 | 139 | ||
140 | void SnakeGame::scoreInc() | 140 | void SnakeGame::scoreInc() |
141 | { | 141 | { |
142 | showScore( snake->getScore() ); | 142 | showScore( snake->getScore() ); |
143 | } | 143 | } |
144 | 144 | ||
145 | void SnakeGame::levelUp() | 145 | void SnakeGame::levelUp() |
146 | { | 146 | { |
147 | notargets--; | 147 | notargets--; |
148 | if (notargets == 0) { | 148 | if (notargets == 0) { |
149 | stage++; | 149 | stage++; |
150 | if (stage == 3) { | 150 | if (stage == 3) { |
151 | level++; | 151 | level++; |
152 | emit moveFaster(); | 152 | emit moveFaster(); |
153 | targetamount++; | 153 | targetamount++; |
154 | stage = 0; | 154 | stage = 0; |
155 | } | 155 | } |
156 | createTargets(); | 156 | createTargets(); |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | void SnakeGame::createTargets() | 160 | void SnakeGame::createTargets() |
161 | { | 161 | { |
162 | for (int i = 0; i < targetamount; i++) | 162 | for (int i = 0; i < targetamount; i++) |
163 | (void)new Target(&canvas); | 163 | (void)new Target(&canvas); |
164 | notargets = targetamount; | 164 | notargets = targetamount; |
165 | } | 165 | } |
166 | 166 | ||
167 | void SnakeGame::clear() | 167 | void SnakeGame::clear() |
168 | { | 168 | { |
169 | delete snake; | 169 | delete snake; |
170 | snake = 0; | 170 | snake = 0; |
171 | QCanvasItemList l = canvas.allItems(); | 171 | QCanvasItemList l = canvas.allItems(); |
172 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { | 172 | for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) { |
173 | delete *it; | 173 | delete *it; |
174 | } | 174 | } |
175 | } | 175 | } |
176 | 176 | ||
177 | void SnakeGame::gameOver() | 177 | void SnakeGame::gameOver() |
178 | { | 178 | { |
179 | int score = snake->getScore(); | 179 | int score = snake->getScore(); |
180 | QString scoreoutput=""; | 180 | QString scoreoutput=""; |
181 | scoreoutput.setNum(score); | 181 | scoreoutput.setNum(score); |
182 | QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas); | 182 | QCanvasText* gameover = new QCanvasText(tr("GAME OVER!\n Your Score: %1").arg( scoreoutput), &canvas); |
183 | 183 | ||
184 | gameover->setZ(100); | 184 | gameover->setZ(100); |
185 | gameover->setColor(yellow); | 185 | gameover->setColor(yellow); |
186 | gameover->setFont( QFont("times", 18, QFont::Bold) ); | 186 | gameover->setFont( QFont("times", 18, QFont::Bold) ); |
187 | int w = gameover->boundingRect().width(); | 187 | int w = gameover->boundingRect().width(); |
188 | gameover->move(canvas.width()/2 -w/2, canvas.height()/2 -50); | 188 | gameover->move(canvas.width()/2 -w/2, canvas.height()/2 -50); |
189 | gameover->show(); | 189 | gameover->show(); |
190 | gamestopped = true; | 190 | gamestopped = true; |
191 | waitover = false; | 191 | waitover = false; |
192 | pauseTimer->start(1500); | 192 | pauseTimer->start(1500); |
193 | } | 193 | } |
194 | 194 | ||
195 | void SnakeGame::wait() | 195 | void SnakeGame::wait() |
196 | { | 196 | { |
197 | waitover = true; | 197 | waitover = true; |
198 | pauseTimer->stop(); | 198 | pauseTimer->stop(); |
199 | QCanvasText* cont = new QCanvasText(tr("Press any key to begin a new game."), | 199 | QCanvasText* cont = new QCanvasText(tr("Press any key to begin a new game."), |
200 | &canvas); | 200 | &canvas); |
201 | cont->setZ(100); | 201 | cont->setZ(100); |
202 | cont->setColor(white); | 202 | cont->setColor(white); |
203 | int w = cont->boundingRect().width(); | 203 | int w = cont->boundingRect().width(); |
204 | cont->move(canvas.width()/2 -w/2, canvas.height()/2); | 204 | cont->move(canvas.width()/2 -w/2, canvas.height()/2); |
205 | cont->show(); | 205 | cont->show(); |
206 | } | 206 | } |
207 | 207 | ||
208 | void SnakeGame::keyPressEvent(QKeyEvent* event) | 208 | void SnakeGame::keyPressEvent(QKeyEvent* event) |
209 | { | 209 | { |
210 | if (gamestopped) { | 210 | if (gamestopped) { |
211 | if (waitover) | 211 | if (waitover) |
212 | newGame(); | 212 | newGame(); |
213 | else | 213 | else |
214 | return; | 214 | return; |
215 | } | 215 | } |
216 | else { | 216 | else { |
217 | int newkey = event->key(); | 217 | int newkey = event->key(); |
218 | snake->go(newkey); | 218 | snake->go(newkey); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp index 8250193..9ae2a23 100644 --- a/noncore/games/solitaire/canvascardgame.cpp +++ b/noncore/games/solitaire/canvascardgame.cpp | |||
@@ -1,388 +1,388 @@ | |||
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 "cardgame.h" | 21 | #include "cardgame.h" |
22 | #include "canvasshapes.h" | 22 | #include "canvasshapes.h" |
23 | #include "canvascard.h" | 23 | #include "canvascard.h" |
24 | #include "canvascardgame.h" | 24 | #include "canvascardgame.h" |
25 | 25 | ||
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
28 | 28 | ||
29 | #include <qmainwindow.h> | 29 | #include <qmainwindow.h> |
30 | #include <qpe/qpemenubar.h> | 30 | #include <qmenubar.h> |
31 | #include <qpainter.h> | 31 | #include <qpainter.h> |
32 | #include <qgfx_qws.h> | 32 | #include <qgfx_qws.h> |
33 | 33 | ||
34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | #include <limits.h> | 35 | #include <limits.h> |
36 | #include <time.h> | 36 | #include <time.h> |
37 | #include <math.h> | 37 | #include <math.h> |
38 | 38 | ||
39 | 39 | ||
40 | extern int highestZ; | 40 | extern int highestZ; |
41 | 41 | ||
42 | 42 | ||
43 | class CanvasCardPile : public QCanvasRectangle | 43 | class CanvasCardPile : public QCanvasRectangle |
44 | { | 44 | { |
45 | public: | 45 | public: |
46 | CanvasCardPile( CanvasCardGame *ccg, QCanvas *canvas ) : QCanvasRectangle( canvas ), parent( ccg ) { | 46 | CanvasCardPile( CanvasCardGame *ccg, QCanvas *canvas ) : QCanvasRectangle( canvas ), parent( ccg ) { |
47 | pile = new QPixmap( 0, 0 ); | 47 | pile = new QPixmap( 0, 0 ); |
48 | pileHeight = 0; | 48 | pileHeight = 0; |
49 | firstCard = NULL; | 49 | firstCard = NULL; |
50 | } | 50 | } |
51 | 51 | ||
52 | void addCard( CanvasCard *card ); | 52 | void addCard( CanvasCard *card ); |
53 | void advance(int stage); | 53 | void advance(int stage); |
54 | void animatedMove() { animatedMove(savedX, savedY); } | 54 | void animatedMove() { animatedMove(savedX, savedY); } |
55 | void savePos(void) { savedX = (int)x(); savedY = (int)y(); } | 55 | void savePos(void) { savedX = (int)x(); savedY = (int)y(); } |
56 | void animatedMove(int x2, int y2, int steps = 7 ); | 56 | void animatedMove(int x2, int y2, int steps = 7 ); |
57 | 57 | ||
58 | protected: | 58 | protected: |
59 | virtual void draw( QPainter& p ); | 59 | virtual void draw( QPainter& p ); |
60 | 60 | ||
61 | private: | 61 | private: |
62 | CanvasCardGame *parent; | 62 | CanvasCardGame *parent; |
63 | QPixmap *pile; | 63 | QPixmap *pile; |
64 | QImage tempImage32; | 64 | QImage tempImage32; |
65 | CanvasCard *firstCard; | 65 | CanvasCard *firstCard; |
66 | int pileHeight; | 66 | int pileHeight; |
67 | int destX, destY; | 67 | int destX, destY; |
68 | int savedX, savedY; | 68 | int savedX, savedY; |
69 | int animSteps; | 69 | int animSteps; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | 72 | ||
73 | void CanvasCardPile::addCard( CanvasCard *card ) | 73 | void CanvasCardPile::addCard( CanvasCard *card ) |
74 | { | 74 | { |
75 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; | 75 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; |
76 | int cardHeight = ( qt_screen->deviceWidth() < 200 ) ? 27 : 36; | 76 | int cardHeight = ( qt_screen->deviceWidth() < 200 ) ? 27 : 36; |
77 | int cardWidth = ( qt_screen->deviceWidth() < 200 ) ? 20 : 23; | 77 | int cardWidth = ( qt_screen->deviceWidth() < 200 ) ? 20 : 23; |
78 | 78 | ||
79 | if ( !firstCard ) | 79 | if ( !firstCard ) |
80 | firstCard = card; | 80 | firstCard = card; |
81 | 81 | ||
82 | int height = cardHeight + pileHeight * offsetDown; | 82 | int height = cardHeight + pileHeight * offsetDown; |
83 | setSize( cardWidth, height ); | 83 | setSize( cardWidth, height ); |
84 | pile->resize( cardWidth, height ); | 84 | pile->resize( cardWidth, height ); |
85 | QPainter p( pile ); | 85 | QPainter p( pile ); |
86 | p.translate( -card->x(), -card->y() + pileHeight * offsetDown ); | 86 | p.translate( -card->x(), -card->y() + pileHeight * offsetDown ); |
87 | card->draw( p ); | 87 | card->draw( p ); |
88 | pileHeight++; | 88 | pileHeight++; |
89 | 89 | ||
90 | QImage tempImage; | 90 | QImage tempImage; |
91 | tempImage = *pile; | 91 | tempImage = *pile; |
92 | tempImage32 = tempImage.convertDepth( 32 ); | 92 | tempImage32 = tempImage.convertDepth( 32 ); |
93 | tempImage32.setAlphaBuffer( TRUE ); | 93 | tempImage32.setAlphaBuffer( TRUE ); |
94 | for ( int i = 0; i < tempImage32.width(); i++ ) | 94 | for ( int i = 0; i < tempImage32.width(); i++ ) |
95 | for ( int j = 0; j < tempImage32.height(); j++ ) { | 95 | for ( int j = 0; j < tempImage32.height(); j++ ) { |
96 | QRgb col = tempImage32.pixel( i, j ); | 96 | QRgb col = tempImage32.pixel( i, j ); |
97 | int a = 255-j*220/tempImage32.height(); | 97 | int a = 255-j*220/tempImage32.height(); |
98 | QRgb alpha = qRgba( qRed( col ), qGreen( col ), qBlue( col ), a ); | 98 | QRgb alpha = qRgba( qRed( col ), qGreen( col ), qBlue( col ), a ); |
99 | tempImage32.setPixel( i, j, alpha ); | 99 | tempImage32.setPixel( i, j, alpha ); |
100 | } | 100 | } |
101 | 101 | ||
102 | QRgb alpha = qRgba( 0, 0, 0, 0 ); | 102 | QRgb alpha = qRgba( 0, 0, 0, 0 ); |
103 | tempImage32.setPixel( 1, 0, alpha ); | 103 | tempImage32.setPixel( 1, 0, alpha ); |
104 | tempImage32.setPixel( 0, 0, alpha ); | 104 | tempImage32.setPixel( 0, 0, alpha ); |
105 | tempImage32.setPixel( 0, 1, alpha ); | 105 | tempImage32.setPixel( 0, 1, alpha ); |
106 | 106 | ||
107 | tempImage32.setPixel( cardWidth - 2, 0, alpha ); | 107 | tempImage32.setPixel( cardWidth - 2, 0, alpha ); |
108 | tempImage32.setPixel( cardWidth - 1, 0, alpha ); | 108 | tempImage32.setPixel( cardWidth - 1, 0, alpha ); |
109 | tempImage32.setPixel( cardWidth - 1, 1, alpha ); | 109 | tempImage32.setPixel( cardWidth - 1, 1, alpha ); |
110 | height--; | 110 | height--; |
111 | tempImage32.setPixel( 1, height, alpha ); | 111 | tempImage32.setPixel( 1, height, alpha ); |
112 | tempImage32.setPixel( 0, height - 1, alpha ); | 112 | tempImage32.setPixel( 0, height - 1, alpha ); |
113 | tempImage32.setPixel( 0, height, alpha ); | 113 | tempImage32.setPixel( 0, height, alpha ); |
114 | 114 | ||
115 | tempImage32.setPixel( cardWidth - 2, height, alpha ); | 115 | tempImage32.setPixel( cardWidth - 2, height, alpha ); |
116 | tempImage32.setPixel( cardWidth - 1, height, alpha ); | 116 | tempImage32.setPixel( cardWidth - 1, height, alpha ); |
117 | tempImage32.setPixel( cardWidth - 1, height - 1, alpha ); | 117 | tempImage32.setPixel( cardWidth - 1, height - 1, alpha ); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | void CanvasCardPile::advance(int stage) | 121 | void CanvasCardPile::advance(int stage) |
122 | { | 122 | { |
123 | if ( stage==1 ) { | 123 | if ( stage==1 ) { |
124 | if ( animSteps-- <= 0 ) { | 124 | if ( animSteps-- <= 0 ) { |
125 | CanvasCard *item = firstCard; | 125 | CanvasCard *item = firstCard; |
126 | while (item) { | 126 | while (item) { |
127 | item->show(); | 127 | item->show(); |
128 | item = (CanvasCard *)item->getCardPile()->cardInfront(item); | 128 | item = (CanvasCard *)item->getCardPile()->cardInfront(item); |
129 | } | 129 | } |
130 | setVelocity(0,0); | 130 | setVelocity(0,0); |
131 | setAnimated(FALSE); | 131 | setAnimated(FALSE); |
132 | parent->cancelMoving(); | 132 | parent->cancelMoving(); |
133 | hide(); | 133 | hide(); |
134 | move(destX,destY); // exact | 134 | move(destX,destY); // exact |
135 | } | 135 | } |
136 | } | 136 | } |
137 | QCanvasRectangle::advance(stage); | 137 | QCanvasRectangle::advance(stage); |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | void CanvasCardPile::animatedMove(int x2, int y2, int steps ) | 141 | void CanvasCardPile::animatedMove(int x2, int y2, int steps ) |
142 | { | 142 | { |
143 | destX = x2; | 143 | destX = x2; |
144 | destY = y2; | 144 | destY = y2; |
145 | 145 | ||
146 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; | 146 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; |
147 | 147 | ||
148 | // Ensure a good speed | 148 | // Ensure a good speed |
149 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) | 149 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) |
150 | steps--; | 150 | steps--; |
151 | 151 | ||
152 | setAnimated(TRUE); | 152 | setAnimated(TRUE); |
153 | setVelocity(dx/steps, dy/steps); | 153 | setVelocity(dx/steps, dy/steps); |
154 | 154 | ||
155 | animSteps = steps; | 155 | animSteps = steps; |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | void CanvasCardPile::draw( QPainter& p ) | 159 | void CanvasCardPile::draw( QPainter& p ) |
160 | { | 160 | { |
161 | int ix = (int)x(), iy = (int)y(); | 161 | int ix = (int)x(), iy = (int)y(); |
162 | p.drawImage( ix, iy, tempImage32 ); | 162 | p.drawImage( ix, iy, tempImage32 ); |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | CanvasCardGame::~CanvasCardGame() { | 166 | CanvasCardGame::~CanvasCardGame() { |
167 | // the deletion stuff should be fixed now and only deletes | 167 | // the deletion stuff should be fixed now and only deletes |
168 | // items created by this CardGame. I haven't verified there are zero | 168 | // items created by this CardGame. I haven't verified there are zero |
169 | // memory leaks yet | 169 | // memory leaks yet |
170 | if ( alphaCardPile ) | 170 | if ( alphaCardPile ) |
171 | delete alphaCardPile; | 171 | delete alphaCardPile; |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | void CanvasCardGame::gameWon() { | 175 | void CanvasCardGame::gameWon() { |
176 | 176 | ||
177 | srand(time(NULL)); | 177 | srand(time(NULL)); |
178 | 178 | ||
179 | QCanvasItemList list = canvas()->allItems(); | 179 | QCanvasItemList list = canvas()->allItems(); |
180 | QCanvasItemList::Iterator it = list.begin(); | 180 | QCanvasItemList::Iterator it = list.begin(); |
181 | 181 | ||
182 | for (; it != list.end(); ++it) { | 182 | for (; it != list.end(); ++it) { |
183 | if ( (*it)->rtti() == canvasCardId ) { | 183 | if ( (*it)->rtti() == canvasCardId ) { |
184 | // disperse the cards everywhere | 184 | // disperse the cards everywhere |
185 | int x = 300 - rand() % 1000; | 185 | int x = 300 - rand() % 1000; |
186 | int y = 300 + rand() % 200; | 186 | int y = 300 + rand() % 200; |
187 | ((CanvasCard *)*it)->animatedMove( x, y, 50 ); | 187 | ((CanvasCard *)*it)->animatedMove( x, y, 50 ); |
188 | } | 188 | } |
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | 192 | ||
193 | void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) { | 193 | void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) { |
194 | 194 | ||
195 | if ( moving ) | 195 | if ( moving ) |
196 | return; | 196 | return; |
197 | 197 | ||
198 | QCanvasItemList l = canvas()->collisions( e->pos() ); | 198 | QCanvasItemList l = canvas()->collisions( e->pos() ); |
199 | 199 | ||
200 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | 200 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { |
201 | 201 | ||
202 | if ( (*it)->rtti() == canvasCardId ) { | 202 | if ( (*it)->rtti() == canvasCardId ) { |
203 | 203 | ||
204 | moving = (CanvasCard *)*it; | 204 | moving = (CanvasCard *)*it; |
205 | 205 | ||
206 | if ( moving->animated() ) | 206 | if ( moving->animated() ) |
207 | return; | 207 | return; |
208 | 208 | ||
209 | cardXOff = (int)(e->pos().x() - moving->x()); | 209 | cardXOff = (int)(e->pos().x() - moving->x()); |
210 | cardYOff = (int)(e->pos().y() - moving->y()); | 210 | cardYOff = (int)(e->pos().y() - moving->y()); |
211 | 211 | ||
212 | if ( !mousePressCard( moving, e->pos() ) ) { | 212 | if ( !mousePressCard( moving, e->pos() ) ) { |
213 | CanvasCard *card = moving; | 213 | CanvasCard *card = moving; |
214 | 214 | ||
215 | if ( alphaCardPile ) | 215 | if ( alphaCardPile ) |
216 | delete alphaCardPile; | 216 | delete alphaCardPile; |
217 | 217 | ||
218 | alphaCardPile = new CanvasCardPile( this, canvas() ); | 218 | alphaCardPile = new CanvasCardPile( this, canvas() ); |
219 | alphaCardPile->move( card->x(), card->y() ); | 219 | alphaCardPile->move( card->x(), card->y() ); |
220 | alphaCardPile->savePos(); | 220 | alphaCardPile->savePos(); |
221 | alphaCardPile->show(); | 221 | alphaCardPile->show(); |
222 | 222 | ||
223 | while (card) { | 223 | while (card) { |
224 | alphaCardPile->addCard( card ); | 224 | alphaCardPile->addCard( card ); |
225 | card->hide(); | 225 | card->hide(); |
226 | card = (CanvasCard *)card->getCardPile()->cardInfront(card); | 226 | card = (CanvasCard *)card->getCardPile()->cardInfront(card); |
227 | } | 227 | } |
228 | 228 | ||
229 | alphaCardPile->setZ( INT_MAX ); | 229 | alphaCardPile->setZ( INT_MAX ); |
230 | 230 | ||
231 | moved = TRUE; | 231 | moved = TRUE; |
232 | } else { | 232 | } else { |
233 | if ( alphaCardPile ) | 233 | if ( alphaCardPile ) |
234 | alphaCardPile->hide(); | 234 | alphaCardPile->hide(); |
235 | } | 235 | } |
236 | return; | 236 | return; |
237 | } | 237 | } |
238 | } | 238 | } |
239 | 239 | ||
240 | mousePress( e->pos() ); | 240 | mousePress( e->pos() ); |
241 | } | 241 | } |
242 | 242 | ||
243 | /* | 243 | /* |
244 | // | 244 | // |
245 | // Should have some intelligent way to make double clicking on a | 245 | // Should have some intelligent way to make double clicking on a |
246 | // card send it to the most appropriate pile | 246 | // card send it to the most appropriate pile |
247 | // | 247 | // |
248 | void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) { | 248 | void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) { |
249 | QCanvasItemList l = canvas()->collisions( e->pos() ); | 249 | QCanvasItemList l = canvas()->collisions( e->pos() ); |
250 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | 250 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { |
251 | if ( (*it)->rtti() == canvasCardId ) { | 251 | if ( (*it)->rtti() == canvasCardId ) { |
252 | CanvasCard *card = (CanvasCard *)*it; | 252 | CanvasCard *card = (CanvasCard *)*it; |
253 | 253 | ||
254 | if ( card->animated() ) | 254 | if ( card->animated() ) |
255 | return; | 255 | return; |
256 | 256 | ||
257 | if ( card->getCardPile()->isAllowedToBeMoved(card) ) { | 257 | if ( card->getCardPile()->isAllowedToBeMoved(card) ) { |
258 | if (card->getCardPile()->cardInfront(card) == NULL) { | 258 | if (card->getCardPile()->cardInfront(card) == NULL) { |
259 | CardPile *pile = first(); | 259 | CardPile *pile = first(); |
260 | if (pile && pile->isAllowedOnTop(card)) { | 260 | if (pile && pile->isAllowedOnTop(card)) { |
261 | // move card to this pile | 261 | // move card to this pile |
262 | return; | 262 | return; |
263 | } | 263 | } |
264 | } | 264 | } |
265 | } | 265 | } |
266 | } | 266 | } |
267 | } | 267 | } |
268 | } | 268 | } |
269 | */ | 269 | */ |
270 | 270 | ||
271 | void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { | 271 | void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { |
272 | 272 | ||
273 | QPoint p = e->pos(); | 273 | QPoint p = e->pos(); |
274 | 274 | ||
275 | if ( moving ) { | 275 | if ( moving ) { |
276 | 276 | ||
277 | moved = TRUE; | 277 | moved = TRUE; |
278 | 278 | ||
279 | if (moving->isFacing() != TRUE) | 279 | if (moving->isFacing() != TRUE) |
280 | return; | 280 | return; |
281 | 281 | ||
282 | int tx = (int)p.x() - cardXOff; | 282 | int tx = (int)p.x() - cardXOff; |
283 | int ty = (int)p.y() - cardYOff; | 283 | int ty = (int)p.y() - cardYOff; |
284 | 284 | ||
285 | if (snapOn == TRUE) { | 285 | if (snapOn == TRUE) { |
286 | CardPile *pile = closestPile( tx, ty, 50 ); | 286 | CardPile *pile = closestPile( tx, ty, 50 ); |
287 | if ( pile && pile->isAllowedOnTop( moving ) ) { | 287 | if ( pile && pile->isAllowedOnTop( moving ) ) { |
288 | QPoint p = pile->getHypertheticalNextCardPos(); | 288 | QPoint p = pile->getHypertheticalNextCardPos(); |
289 | if ( alphaCardPile ) | 289 | if ( alphaCardPile ) |
290 | alphaCardPile->move( p.x(), p.y() ); | 290 | alphaCardPile->move( p.x(), p.y() ); |
291 | return; | 291 | return; |
292 | } | 292 | } |
293 | } | 293 | } |
294 | 294 | ||
295 | if ( alphaCardPile ) | 295 | if ( alphaCardPile ) |
296 | alphaCardPile->move( tx, ty ); | 296 | alphaCardPile->move( tx, ty ); |
297 | } | 297 | } |
298 | 298 | ||
299 | } | 299 | } |
300 | 300 | ||
301 | 301 | ||
302 | void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) | 302 | void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) |
303 | { | 303 | { |
304 | QPoint p = e->pos(); | 304 | QPoint p = e->pos(); |
305 | 305 | ||
306 | Q_UNUSED(p); | 306 | Q_UNUSED(p); |
307 | 307 | ||
308 | if ( moving ) { | 308 | if ( moving ) { |
309 | 309 | ||
310 | CanvasCard *item = moving; | 310 | CanvasCard *item = moving; |
311 | 311 | ||
312 | if ( item->animated() ) | 312 | if ( item->animated() ) |
313 | return; | 313 | return; |
314 | 314 | ||
315 | if ( alphaCardPile ) | 315 | if ( alphaCardPile ) |
316 | if ( moved ) { | 316 | if ( moved ) { |
317 | 317 | ||
318 | CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30); | 318 | CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30); |
319 | 319 | ||
320 | if (pile && pile->isAllowedOnTop(item)) { | 320 | if (pile && pile->isAllowedOnTop(item)) { |
321 | CardPile *oldPile = item->getCardPile(); | 321 | CardPile *oldPile = item->getCardPile(); |
322 | Card *c = NULL; | 322 | Card *c = NULL; |
323 | if ( oldPile != pile) { | 323 | if ( oldPile != pile) { |
324 | while ( item ) { | 324 | while ( item ) { |
325 | item->show(); | 325 | item->show(); |
326 | if ( oldPile ) { | 326 | if ( oldPile ) { |
327 | c = oldPile->cardInfront(item); | 327 | c = oldPile->cardInfront(item); |
328 | oldPile->removeCard(item); | 328 | oldPile->removeCard(item); |
329 | } | 329 | } |
330 | item->setCardPile(pile); | 330 | item->setCardPile(pile); |
331 | //item->move( pile->getCardPos(item) ); | 331 | //item->move( pile->getCardPos(item) ); |
332 | pile->addCardToTop(item); | 332 | pile->addCardToTop(item); |
333 | QPoint p = pile->getCardPos(item); | 333 | QPoint p = pile->getCardPos(item); |
334 | item->setPos( p.x(), p.y(), highestZ ); | 334 | item->setPos( p.x(), p.y(), highestZ ); |
335 | highestZ++; | 335 | highestZ++; |
336 | checkUnusable(); // added for freecell to move card to discard pile | 336 | checkUnusable(); // added for freecell to move card to discard pile |
337 | 337 | ||
338 | if (item->getValue() == king && haveWeWon()) { | 338 | if (item->getValue() == king && haveWeWon()) { |
339 | alphaCardPile->hide(); | 339 | alphaCardPile->hide(); |
340 | gameWon(); | 340 | gameWon(); |
341 | moving = NULL; | 341 | moving = NULL; |
342 | return; | 342 | return; |
343 | } | 343 | } |
344 | 344 | ||
345 | if (oldPile) { | 345 | if (oldPile) { |
346 | item = (CanvasCard *)c; | 346 | item = (CanvasCard *)c; |
347 | } else { | 347 | } else { |
348 | item = NULL; | 348 | item = NULL; |
349 | } | 349 | } |
350 | } | 350 | } |
351 | alphaCardPile->hide(); | 351 | alphaCardPile->hide(); |
352 | moving = NULL; | 352 | moving = NULL; |
353 | return; | 353 | return; |
354 | } | 354 | } |
355 | } | 355 | } |
356 | 356 | ||
357 | alphaCardPile->animatedMove(); | 357 | alphaCardPile->animatedMove(); |
358 | } | 358 | } |
359 | } | 359 | } |
360 | 360 | ||
361 | moved = FALSE; | 361 | moved = FALSE; |
362 | } | 362 | } |
363 | 363 | ||
364 | 364 | ||
365 | void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ) | 365 | void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ) |
366 | { | 366 | { |
367 | cfg.setGroup( name ); | 367 | cfg.setGroup( name ); |
368 | int numberOfCards = cfg.readNumEntry("NumberOfCards", 0); | 368 | int numberOfCards = cfg.readNumEntry("NumberOfCards", 0); |
369 | Card *card = NULL; | 369 | Card *card = NULL; |
370 | 370 | ||
371 | for ( int i = 0; i < numberOfCards; i++ ) { | 371 | for ( int i = 0; i < numberOfCards; i++ ) { |
372 | QString cardStr; | 372 | QString cardStr; |
373 | cardStr.sprintf( "%i", i ); | 373 | cardStr.sprintf( "%i", i ); |
374 | int val = cfg.readNumEntry( "Card" + cardStr ); | 374 | int val = cfg.readNumEntry( "Card" + cardStr ); |
375 | bool facing = cfg.readBoolEntry( "CardFacing" + cardStr ); | 375 | bool facing = cfg.readBoolEntry( "CardFacing" + cardStr ); |
376 | 376 | ||
377 | card = cards[ val ]; | 377 | card = cards[ val ]; |
378 | card->setFace(facing); | 378 | card->setFace(facing); |
379 | card->setCardPile(pile); // cam: setCardPile has to happen bevor addCardToTop | 379 | card->setCardPile(pile); // cam: setCardPile has to happen bevor addCardToTop |
380 | pile->addCardToTop(card); // due to a empty pointer if you use cardAddedToTop | 380 | pile->addCardToTop(card); // due to a empty pointer if you use cardAddedToTop |
381 | QPoint p = pile->getCardPos( card ); | 381 | QPoint p = pile->getCardPos( card ); |
382 | card->setPos( p.x(), p.y(), highestZ ); | 382 | card->setPos( p.x(), p.y(), highestZ ); |
383 | card->showCard(); | 383 | card->showCard(); |
384 | highestZ++; | 384 | highestZ++; |
385 | } | 385 | } |
386 | } | 386 | } |
387 | 387 | ||
388 | 388 | ||
diff --git a/noncore/games/wordgame/wordgame.cpp b/noncore/games/wordgame/wordgame.cpp index d46e824..c01551d 100644 --- a/noncore/games/wordgame/wordgame.cpp +++ b/noncore/games/wordgame/wordgame.cpp | |||
@@ -1,1519 +1,1519 @@ | |||
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 | #include "wordgame.h" | 22 | #include "wordgame.h" |
23 | 23 | ||
24 | #include <qpe/applnk.h> | 24 | #include <qpe/applnk.h> |
25 | #include <qpe/global.h> | 25 | #include <qpe/global.h> |
26 | #include <qpe/filemanager.h> | 26 | #include <qpe/filemanager.h> |
27 | #include <qpe/resource.h> | 27 | #include <qpe/resource.h> |
28 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
29 | 29 | ||
30 | #include <qapplication.h> | 30 | #include <qapplication.h> |
31 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
32 | #include <qcombobox.h> | 32 | #include <qcombobox.h> |
33 | #include <qdatetime.h> | 33 | #include <qdatetime.h> |
34 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
35 | #include <qfile.h> | 35 | #include <qfile.h> |
36 | #include <qdir.h> | 36 | #include <qdir.h> |
37 | #include <qiconset.h> | 37 | #include <qiconset.h> |
38 | #include <qlabel.h> | 38 | #include <qlabel.h> |
39 | #include <qlineedit.h> | 39 | #include <qlineedit.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qtimer.h> | 42 | #include <qtimer.h> |
43 | #include <qpe/qpetoolbar.h> | 43 | #include <qpe/qpetoolbar.h> |
44 | #include <qtoolbutton.h> | 44 | #include <qtoolbutton.h> |
45 | #include <qvbox.h> | 45 | #include <qvbox.h> |
46 | #include <qwidgetstack.h> | 46 | #include <qwidgetstack.h> |
47 | #include <qpainter.h> | 47 | #include <qpainter.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qregexp.h> | 49 | #include <qregexp.h> |
50 | 50 | ||
51 | #include <stdlib.h> | 51 | #include <stdlib.h> |
52 | #include <unistd.h> | 52 | #include <unistd.h> |
53 | #include <pwd.h> | 53 | #include <pwd.h> |
54 | #include <sys/types.h> | 54 | #include <sys/types.h> |
55 | 55 | ||
56 | enum RuleEffects { | 56 | enum RuleEffects { |
57 | Multiplier=15, | 57 | Multiplier=15, |
58 | MultiplyAll=64, | 58 | MultiplyAll=64, |
59 | Start=128 | 59 | Start=128 |
60 | }; | 60 | }; |
61 | 61 | ||
62 | static int tile_smallw = 16; | 62 | static int tile_smallw = 16; |
63 | static int tile_smallh = 16; | 63 | static int tile_smallh = 16; |
64 | static int tile_bigw = 22; | 64 | static int tile_bigw = 22; |
65 | static int tile_bigh = 22; | 65 | static int tile_bigh = 22; |
66 | static int tile_stweak = -2; | 66 | static int tile_stweak = -2; |
67 | static int tile_btweak = -1; | 67 | static int tile_btweak = -1; |
68 | 68 | ||
69 | static const int rack_tiles=7; | 69 | static const int rack_tiles=7; |
70 | 70 | ||
71 | const char* sampleWGR= | 71 | const char* sampleWGR= |
72 | "wordgame_shapes\n" | 72 | "wordgame_shapes\n" |
73 | "15 15\n" | 73 | "15 15\n" |
74 | "400001040100004\n" | 74 | "400001040100004\n" |
75 | "030000000000030\n" | 75 | "030000000000030\n" |
76 | "002002000200200\n" | 76 | "002002000200200\n" |
77 | "000300020003000\n" | 77 | "000300020003000\n" |
78 | "000020000020000\n" | 78 | "000020000020000\n" |
79 | "102001000100201\n" | 79 | "102001000100201\n" |
80 | "000000202000000\n" | 80 | "000000202000000\n" |
81 | "400200050002004\n" | 81 | "400200050002004\n" |
82 | "000000202000000\n" | 82 | "000000202000000\n" |
83 | "102001000100201\n" | 83 | "102001000100201\n" |
84 | "000020000020000\n" | 84 | "000020000020000\n" |
85 | "000300020003000\n" | 85 | "000300020003000\n" |
86 | "002002000200200\n" | 86 | "002002000200200\n" |
87 | "030000000000030\n" | 87 | "030000000000030\n" |
88 | "400001040100004\n" | 88 | "400001040100004\n" |
89 | "1 2 3 66 67 194 100 0\n" | 89 | "1 2 3 66 67 194 100 0\n" |
90 | "1 j 8\n" | 90 | "1 j 8\n" |
91 | "1 q 7\n" | 91 | "1 q 7\n" |
92 | "1 x 6\n" | 92 | "1 x 6\n" |
93 | "1 z 6\n" | 93 | "1 z 6\n" |
94 | "1 w 4\n" | 94 | "1 w 4\n" |
95 | "1 k 4\n" | 95 | "1 k 4\n" |
96 | "1 v 3\n" | 96 | "1 v 3\n" |
97 | "1 f 3\n" | 97 | "1 f 3\n" |
98 | "2 y 3\n" | 98 | "2 y 3\n" |
99 | "2 h 2\n" | 99 | "2 h 2\n" |
100 | "2 b 2\n" | 100 | "2 b 2\n" |
101 | "2 m 2\n" | 101 | "2 m 2\n" |
102 | "3 p 2\n" | 102 | "3 p 2\n" |
103 | "3 g 2\n" | 103 | "3 g 2\n" |
104 | "3 u 2\n" | 104 | "3 u 2\n" |
105 | "4 d 2\n" | 105 | "4 d 2\n" |
106 | "4 c 2\n" | 106 | "4 c 2\n" |
107 | "5 l 1\n" | 107 | "5 l 1\n" |
108 | "5 o 1\n" | 108 | "5 o 1\n" |
109 | "7 t 1\n" | 109 | "7 t 1\n" |
110 | "7 n 1\n" | 110 | "7 n 1\n" |
111 | "7 a 1\n" | 111 | "7 a 1\n" |
112 | "7 r 1\n" | 112 | "7 r 1\n" |
113 | "8 s 1\n" | 113 | "8 s 1\n" |
114 | "8 i 1\n" | 114 | "8 i 1\n" |
115 | "11 e 1\n" | 115 | "11 e 1\n" |
116 | "0\n"; | 116 | "0\n"; |
117 | 117 | ||
118 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : | 118 | WordGame::WordGame( QWidget* parent, const char* name, WFlags fl ) : |
119 | QMainWindow(parent, name, fl) | 119 | QMainWindow(parent, name, fl) |
120 | { | 120 | { |
121 | if ( qApp->desktop()->width() < 240 ) { | 121 | if ( qApp->desktop()->width() < 240 ) { |
122 | tile_smallw = 10; | 122 | tile_smallw = 10; |
123 | tile_smallh = 10; | 123 | tile_smallh = 10; |
124 | tile_bigw = 16; | 124 | tile_bigw = 16; |
125 | tile_bigh = 16; | 125 | tile_bigh = 16; |
126 | tile_stweak = 0; | 126 | tile_stweak = 0; |
127 | tile_btweak = 0; | 127 | tile_btweak = 0; |
128 | } | 128 | } |
129 | 129 | ||
130 | setIcon( Resource::loadPixmap( "wordgame/WordGame.png" ) ); | 130 | setIcon( Resource::loadPixmap( "wordgame/WordGame.png" ) ); |
131 | setCaption( tr("Word Game") ); | 131 | setCaption( tr("Word Game") ); |
132 | 132 | ||
133 | setToolBarsMovable( FALSE ); | 133 | setToolBarsMovable( FALSE ); |
134 | vbox = new QVBox(this); | 134 | vbox = new QVBox(this); |
135 | 135 | ||
136 | setCentralWidget(vbox); | 136 | setCentralWidget(vbox); |
137 | toolbar = new QPEToolBar(this); | 137 | toolbar = new QToolBar(this); |
138 | addToolBar(toolbar, Bottom); | 138 | addToolBar(toolbar, Bottom); |
139 | reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar); | 139 | reset = new QToolButton(Resource::loadPixmap("back"), tr("Back"), "", this, SLOT(resetTurn()), toolbar); |
140 | done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar); | 140 | done = new QToolButton(Resource::loadPixmap("done"), tr("Done"), "", this, SLOT(endTurn()), toolbar); |
141 | scoreinfo = new ScoreInfo(toolbar); | 141 | scoreinfo = new ScoreInfo(toolbar); |
142 | scoreinfo->setFont(QFont("Helvetica",10)); | 142 | scoreinfo->setFont(QFont("Helvetica",10)); |
143 | new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar); | 143 | new QToolButton(Resource::loadPixmap("finish"), tr("Close"), "", this, SLOT(endGame()), toolbar); |
144 | toolbar->setStretchableWidget(scoreinfo); | 144 | toolbar->setStretchableWidget(scoreinfo); |
145 | 145 | ||
146 | cpu = 0; | 146 | cpu = 0; |
147 | board = 0; | 147 | board = 0; |
148 | bag = 0; | 148 | bag = 0; |
149 | racks = 0; | 149 | racks = 0; |
150 | 150 | ||
151 | aiheart = new QTimer(this); | 151 | aiheart = new QTimer(this); |
152 | connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); | 152 | connect(aiheart, SIGNAL(timeout()), this, SLOT(think())); |
153 | 153 | ||
154 | readConfig(); | 154 | readConfig(); |
155 | } | 155 | } |
156 | 156 | ||
157 | WordGame::~WordGame() | 157 | WordGame::~WordGame() |
158 | { | 158 | { |
159 | writeConfig(); | 159 | writeConfig(); |
160 | } | 160 | } |
161 | 161 | ||
162 | void WordGame::writeConfig() | 162 | void WordGame::writeConfig() |
163 | { | 163 | { |
164 | Config cfg("WordGame"); | 164 | Config cfg("WordGame"); |
165 | cfg.setGroup("Game"); | 165 | cfg.setGroup("Game"); |
166 | cfg.writeEntry("NameList",namelist,';'); | 166 | cfg.writeEntry("NameList",namelist,';'); |
167 | cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1); | 167 | cfg.writeEntry("CurrentPlayer",gameover ? 0 : player+1); |
168 | if ( !gameover ) { | 168 | if ( !gameover ) { |
169 | cfg.writeEntry("Rules",rules); | 169 | cfg.writeEntry("Rules",rules); |
170 | bag->writeConfig(cfg); | 170 | bag->writeConfig(cfg); |
171 | board->writeConfig(cfg); | 171 | board->writeConfig(cfg); |
172 | scoreinfo->writeConfig(cfg); | 172 | scoreinfo->writeConfig(cfg); |
173 | } | 173 | } |
174 | for (int p=0; p<nplayers; p++) { | 174 | for (int p=0; p<nplayers; p++) { |
175 | cfg.setGroup("Player"+QString::number(p+1)); | 175 | cfg.setGroup("Player"+QString::number(p+1)); |
176 | if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg); | 176 | if ( gameover ) cfg.clearGroup(); else rack(p)->writeConfig(cfg); |
177 | } | 177 | } |
178 | } | 178 | } |
179 | 179 | ||
180 | void WordGame::readConfig() | 180 | void WordGame::readConfig() |
181 | { | 181 | { |
182 | Config cfg("WordGame"); | 182 | Config cfg("WordGame"); |
183 | cfg.setGroup("Game"); | 183 | cfg.setGroup("Game"); |
184 | int currentplayer = cfg.readNumEntry("CurrentPlayer",0); | 184 | int currentplayer = cfg.readNumEntry("CurrentPlayer",0); |
185 | QStringList pnames = cfg.readListEntry("NameList",';'); | 185 | QStringList pnames = cfg.readListEntry("NameList",';'); |
186 | if ( currentplayer ) { | 186 | if ( currentplayer ) { |
187 | gameover = FALSE; | 187 | gameover = FALSE; |
188 | rules = cfg.readEntry("Rules"); | 188 | rules = cfg.readEntry("Rules"); |
189 | if ( rules.find("x-wordgamerules") >= 0 ) { | 189 | if ( rules.find("x-wordgamerules") >= 0 ) { |
190 | // rules files moved | 190 | // rules files moved |
191 | rules = "Sample.rules"; | 191 | rules = "Sample.rules"; |
192 | } | 192 | } |
193 | if ( loadRules(rules) ) { | 193 | if ( loadRules(rules) ) { |
194 | startGame(pnames); | 194 | startGame(pnames); |
195 | bag->readConfig(cfg); | 195 | bag->readConfig(cfg); |
196 | board->readConfig(cfg); | 196 | board->readConfig(cfg); |
197 | scoreinfo->readConfig(cfg); | 197 | scoreinfo->readConfig(cfg); |
198 | for (int p=0; p<nplayers; p++) { | 198 | for (int p=0; p<nplayers; p++) { |
199 | cfg.setGroup("Player"+QString::number(p+1)); | 199 | cfg.setGroup("Player"+QString::number(p+1)); |
200 | rack(p)->readConfig(cfg); | 200 | rack(p)->readConfig(cfg); |
201 | } | 201 | } |
202 | player=currentplayer-1; | 202 | player=currentplayer-1; |
203 | readyRack(player); | 203 | readyRack(player); |
204 | return; | 204 | return; |
205 | } | 205 | } |
206 | } | 206 | } |
207 | // fall-back | 207 | // fall-back |
208 | openGameSelector(pnames); | 208 | openGameSelector(pnames); |
209 | } | 209 | } |
210 | 210 | ||
211 | void WordGame::openGameSelector(const QStringList& initnames) | 211 | void WordGame::openGameSelector(const QStringList& initnames) |
212 | { | 212 | { |
213 | toolbar->hide(); | 213 | toolbar->hide(); |
214 | gameover = FALSE; | 214 | gameover = FALSE; |
215 | 215 | ||
216 | delete board; | 216 | delete board; |
217 | board = 0; | 217 | board = 0; |
218 | delete racks; | 218 | delete racks; |
219 | racks = 0; | 219 | racks = 0; |
220 | 220 | ||
221 | delete cpu; | 221 | delete cpu; |
222 | cpu = 0; | 222 | cpu = 0; |
223 | 223 | ||
224 | newgame = new NewGame(vbox); | 224 | newgame = new NewGame(vbox); |
225 | 225 | ||
226 | //Rules rules(this); | 226 | //Rules rules(this); |
227 | //connect(game.editrules, SIGNAL(clicked()), &rules, SLOT(editRules())); | 227 | //connect(game.editrules, SIGNAL(clicked()), &rules, SLOT(editRules())); |
228 | //connect(&rules, SIGNAL(rulesChanged()), &game, SLOT(updateRuleSets())); | 228 | //connect(&rules, SIGNAL(rulesChanged()), &game, SLOT(updateRuleSets())); |
229 | struct passwd* n = getpwuid(getuid()); | 229 | struct passwd* n = getpwuid(getuid()); |
230 | QString playername = n ? n->pw_name : ""; | 230 | QString playername = n ? n->pw_name : ""; |
231 | if ( playername.isEmpty() ) { | 231 | if ( playername.isEmpty() ) { |
232 | playername = "Player"; | 232 | playername = "Player"; |
233 | } | 233 | } |
234 | newgame->player0->changeItem(playername,0); | 234 | newgame->player0->changeItem(playername,0); |
235 | newgame->player1->setCurrentItem(1); | 235 | newgame->player1->setCurrentItem(1); |
236 | newgame->updateRuleSets(); | 236 | newgame->updateRuleSets(); |
237 | newgame->show(); | 237 | newgame->show(); |
238 | 238 | ||
239 | connect(newgame->buttonOk, SIGNAL(clicked()), this, SLOT(startGame())); | 239 | connect(newgame->buttonOk, SIGNAL(clicked()), this, SLOT(startGame())); |
240 | } | 240 | } |
241 | 241 | ||
242 | void WordGame::startGame() | 242 | void WordGame::startGame() |
243 | { | 243 | { |
244 | rules = newgame->ruleslist[newgame->rules->currentItem()]; | 244 | rules = newgame->ruleslist[newgame->rules->currentItem()]; |
245 | if ( loadRules(rules) ) { | 245 | if ( loadRules(rules) ) { |
246 | QStringList names; | 246 | QStringList names; |
247 | names.append(newgame->player0->currentText()); | 247 | names.append(newgame->player0->currentText()); |
248 | names.append(newgame->player1->currentText()); | 248 | names.append(newgame->player1->currentText()); |
249 | names.append(newgame->player2->currentText()); | 249 | names.append(newgame->player2->currentText()); |
250 | names.append(newgame->player3->currentText()); | 250 | names.append(newgame->player3->currentText()); |
251 | names.append(newgame->player4->currentText()); | 251 | names.append(newgame->player4->currentText()); |
252 | names.append(newgame->player5->currentText()); | 252 | names.append(newgame->player5->currentText()); |
253 | delete newgame; | 253 | delete newgame; |
254 | startGame(names); | 254 | startGame(names); |
255 | } else { | 255 | } else { |
256 | // error... | 256 | // error... |
257 | delete newgame; | 257 | delete newgame; |
258 | close(); | 258 | close(); |
259 | } | 259 | } |
260 | } | 260 | } |
261 | 261 | ||
262 | void WordGame::startGame(const QStringList& playerlist) | 262 | void WordGame::startGame(const QStringList& playerlist) |
263 | { | 263 | { |
264 | toolbar->show(); | 264 | toolbar->show(); |
265 | racks = new QWidgetStack(vbox); | 265 | racks = new QWidgetStack(vbox); |
266 | racks->setFixedHeight(TileItem::bigHeight()+2); | 266 | racks->setFixedHeight(TileItem::bigHeight()+2); |
267 | namelist.clear(); | 267 | namelist.clear(); |
268 | nplayers=0; | 268 | nplayers=0; |
269 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) | 269 | for (QStringList::ConstIterator it=playerlist.begin(); it!=playerlist.end(); ++it) |
270 | addPlayer(*it); | 270 | addPlayer(*it); |
271 | scoreinfo->init(namelist); | 271 | scoreinfo->init(namelist); |
272 | 272 | ||
273 | if ( nplayers ) { | 273 | if ( nplayers ) { |
274 | player=0; | 274 | player=0; |
275 | readyRack(player); | 275 | readyRack(player); |
276 | } | 276 | } |
277 | 277 | ||
278 | board->show(); | 278 | board->show(); |
279 | racks->show(); | 279 | racks->show(); |
280 | } | 280 | } |
281 | 281 | ||
282 | bool WordGame::loadRules(const QString &name) | 282 | bool WordGame::loadRules(const QString &name) |
283 | { | 283 | { |
284 | QString filename = Global::applicationFileName( "wordgame", name ); | 284 | QString filename = Global::applicationFileName( "wordgame", name ); |
285 | QFile file( filename ); | 285 | QFile file( filename ); |
286 | if ( !file.open( IO_ReadOnly ) ) | 286 | if ( !file.open( IO_ReadOnly ) ) |
287 | return FALSE; | 287 | return FALSE; |
288 | 288 | ||
289 | QTextStream ts( &file ); | 289 | QTextStream ts( &file ); |
290 | 290 | ||
291 | QString title = name; | 291 | QString title = name; |
292 | title.truncate( title.length() - 6 ); | 292 | title.truncate( title.length() - 6 ); |
293 | //setCaption( title ); | 293 | //setCaption( title ); |
294 | 294 | ||
295 | QString shapepixmap; | 295 | QString shapepixmap; |
296 | ts >> shapepixmap; | 296 | ts >> shapepixmap; |
297 | int htiles,vtiles; | 297 | int htiles,vtiles; |
298 | ts >> htiles >> vtiles; | 298 | ts >> htiles >> vtiles; |
299 | 299 | ||
300 | if ( htiles < 3 || vtiles < 3 ) | 300 | if ( htiles < 3 || vtiles < 3 ) |
301 | return FALSE; | 301 | return FALSE; |
302 | 302 | ||
303 | QString rule_shapes; | 303 | QString rule_shapes; |
304 | for (int i=0; i<vtiles; i++) { | 304 | for (int i=0; i<vtiles; i++) { |
305 | QString line; | 305 | QString line; |
306 | ts >> line; | 306 | ts >> line; |
307 | rule_shapes += line; | 307 | rule_shapes += line; |
308 | } | 308 | } |
309 | static int rule_effects[12]; | 309 | static int rule_effects[12]; |
310 | int re=0,e; | 310 | int re=0,e; |
311 | ts >> e; | 311 | ts >> e; |
312 | while ( e && re < 10 ) { | 312 | while ( e && re < 10 ) { |
313 | rule_effects[re] = e; | 313 | rule_effects[re] = e; |
314 | if ( re++ < 10 ) ts >> e; | 314 | if ( re++ < 10 ) ts >> e; |
315 | } | 315 | } |
316 | 316 | ||
317 | QImage shim = Resource::loadImage("wordgame/wordgame_shapes"); | 317 | QImage shim = Resource::loadImage("wordgame/wordgame_shapes"); |
318 | shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); | 318 | shim = shim.smoothScale((re-1)*TileItem::smallWidth(),TileItem::smallHeight()); |
319 | QPixmap bgshapes; | 319 | QPixmap bgshapes; |
320 | bgshapes.convertFromImage(shim); | 320 | bgshapes.convertFromImage(shim); |
321 | 321 | ||
322 | rule_effects[re++] = 100; // default bonus | 322 | rule_effects[re++] = 100; // default bonus |
323 | board = new Board(bgshapes, htiles, vtiles, vbox); | 323 | board = new Board(bgshapes, htiles, vtiles, vbox); |
324 | board->setRules(rule_shapes, rule_effects); | 324 | board->setRules(rule_shapes, rule_effects); |
325 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); | 325 | connect(board, SIGNAL(temporaryScore(int)), scoreinfo, SLOT(showTemporaryScore(int))); |
326 | 326 | ||
327 | bag = new Bag; | 327 | bag = new Bag; |
328 | 328 | ||
329 | int count; | 329 | int count; |
330 | ts >> count; | 330 | ts >> count; |
331 | while ( count ) { | 331 | while ( count ) { |
332 | QString text; | 332 | QString text; |
333 | int value; | 333 | int value; |
334 | ts >> text >> value; | 334 | ts >> text >> value; |
335 | if ( text == "_" ) | 335 | if ( text == "_" ) |
336 | text = ""; | 336 | text = ""; |
337 | 337 | ||
338 | Tile t(text, value); | 338 | Tile t(text, value); |
339 | for (int n=count; n--; ) | 339 | for (int n=count; n--; ) |
340 | bag->add(t); | 340 | bag->add(t); |
341 | 341 | ||
342 | ts >> count; | 342 | ts >> count; |
343 | } | 343 | } |
344 | 344 | ||
345 | return TRUE; | 345 | return TRUE; |
346 | } | 346 | } |
347 | 347 | ||
348 | 348 | ||
349 | NewGame::NewGame(QWidget* parent) : | 349 | NewGame::NewGame(QWidget* parent) : |
350 | NewGameBase(parent) | 350 | NewGameBase(parent) |
351 | { | 351 | { |
352 | } | 352 | } |
353 | 353 | ||
354 | void NewGame::updateRuleSets() | 354 | void NewGame::updateRuleSets() |
355 | { | 355 | { |
356 | rules->clear(); | 356 | rules->clear(); |
357 | 357 | ||
358 | QString rulesDir = Global::applicationFileName( "wordgame", "" ); | 358 | QString rulesDir = Global::applicationFileName( "wordgame", "" ); |
359 | QDir dir( rulesDir, "*.rules" ); | 359 | QDir dir( rulesDir, "*.rules" ); |
360 | ruleslist = dir.entryList(); | 360 | ruleslist = dir.entryList(); |
361 | if ( ruleslist.isEmpty() ) { | 361 | if ( ruleslist.isEmpty() ) { |
362 | // Provide a sample | 362 | // Provide a sample |
363 | QFile file( rulesDir + "Sample.rules" ); | 363 | QFile file( rulesDir + "Sample.rules" ); |
364 | if ( file.open( IO_WriteOnly ) ) { | 364 | if ( file.open( IO_WriteOnly ) ) { |
365 | file.writeBlock( sampleWGR, strlen(sampleWGR) ); | 365 | file.writeBlock( sampleWGR, strlen(sampleWGR) ); |
366 | file.close(); | 366 | file.close(); |
367 | updateRuleSets(); | 367 | updateRuleSets(); |
368 | } | 368 | } |
369 | return; | 369 | return; |
370 | } | 370 | } |
371 | int newest=0; | 371 | int newest=0; |
372 | int newest_age=INT_MAX; | 372 | int newest_age=INT_MAX; |
373 | QDateTime now = QDateTime::currentDateTime(); | 373 | QDateTime now = QDateTime::currentDateTime(); |
374 | QStringList::Iterator it; | 374 | QStringList::Iterator it; |
375 | for ( it = ruleslist.begin(); it != ruleslist.end(); ++it ) { | 375 | for ( it = ruleslist.begin(); it != ruleslist.end(); ++it ) { |
376 | QFileInfo fi((*it)); | 376 | QFileInfo fi((*it)); |
377 | int age = fi.lastModified().secsTo(now); | 377 | int age = fi.lastModified().secsTo(now); |
378 | QString name = *it; | 378 | QString name = *it; |
379 | name.truncate( name.length()-6 ); // remove extension | 379 | name.truncate( name.length()-6 ); // remove extension |
380 | rules->insertItem( name ); | 380 | rules->insertItem( name ); |
381 | if ( age < newest_age ) { | 381 | if ( age < newest_age ) { |
382 | newest_age = age; | 382 | newest_age = age; |
383 | newest = rules->count()-1; | 383 | newest = rules->count()-1; |
384 | } | 384 | } |
385 | } | 385 | } |
386 | rules->setCurrentItem(newest); | 386 | rules->setCurrentItem(newest); |
387 | } | 387 | } |
388 | 388 | ||
389 | Rules::Rules(QWidget* parent) : | 389 | Rules::Rules(QWidget* parent) : |
390 | RulesBase(parent,0,TRUE) | 390 | RulesBase(parent,0,TRUE) |
391 | { | 391 | { |
392 | } | 392 | } |
393 | 393 | ||
394 | void Rules::editRules() | 394 | void Rules::editRules() |
395 | { | 395 | { |
396 | if ( exec() ) { | 396 | if ( exec() ) { |
397 | // ### create a new set of rules | 397 | // ### create a new set of rules |
398 | emit rulesChanged(); | 398 | emit rulesChanged(); |
399 | } | 399 | } |
400 | } | 400 | } |
401 | 401 | ||
402 | void Rules::deleteRuleSet() | 402 | void Rules::deleteRuleSet() |
403 | { | 403 | { |
404 | // ### delete existing rule set | 404 | // ### delete existing rule set |
405 | emit rulesChanged(); | 405 | emit rulesChanged(); |
406 | } | 406 | } |
407 | 407 | ||
408 | void WordGame::addPlayer(const QString& name) | 408 | void WordGame::addPlayer(const QString& name) |
409 | { | 409 | { |
410 | if ( !name.isEmpty() ) { | 410 | if ( !name.isEmpty() ) { |
411 | int colon = name.find(':'); | 411 | int colon = name.find(':'); |
412 | int cpu = (colon >=0 && name.left(2) == "AI") ? name.mid(2,1).toInt() : 0; | 412 | int cpu = (colon >=0 && name.left(2) == "AI") ? name.mid(2,1).toInt() : 0; |
413 | addPlayer(name,cpu); | 413 | addPlayer(name,cpu); |
414 | } | 414 | } |
415 | } | 415 | } |
416 | 416 | ||
417 | void WordGame::addPlayer(const QString& name, int cpu) | 417 | void WordGame::addPlayer(const QString& name, int cpu) |
418 | { | 418 | { |
419 | Rack* r = new Rack(rack_tiles,racks); | 419 | Rack* r = new Rack(rack_tiles,racks); |
420 | r->setPlayerName(name); | 420 | r->setPlayerName(name); |
421 | r->setComputerization(cpu); | 421 | r->setComputerization(cpu); |
422 | racks->addWidget(r, nplayers); | 422 | racks->addWidget(r, nplayers); |
423 | refillRack(nplayers); | 423 | refillRack(nplayers); |
424 | namelist.append(name); | 424 | namelist.append(name); |
425 | 425 | ||
426 | ++nplayers; | 426 | ++nplayers; |
427 | } | 427 | } |
428 | 428 | ||
429 | void WordGame::nextPlayer() | 429 | void WordGame::nextPlayer() |
430 | { | 430 | { |
431 | if ( !refillRack(player) ) { | 431 | if ( !refillRack(player) ) { |
432 | endGame(); | 432 | endGame(); |
433 | } else { | 433 | } else { |
434 | player = (player+1)%nplayers; | 434 | player = (player+1)%nplayers; |
435 | scoreinfo->setBoldOne(player); | 435 | scoreinfo->setBoldOne(player); |
436 | readyRack(player); | 436 | readyRack(player); |
437 | } | 437 | } |
438 | } | 438 | } |
439 | 439 | ||
440 | bool WordGame::mayEndGame() | 440 | bool WordGame::mayEndGame() |
441 | { | 441 | { |
442 | int out=-1; | 442 | int out=-1; |
443 | int i; | 443 | int i; |
444 | for (i=0; i<nplayers; i++) | 444 | for (i=0; i<nplayers; i++) |
445 | if ( !rack(i)->count() ) | 445 | if ( !rack(i)->count() ) |
446 | out = i; | 446 | out = i; |
447 | if ( out<0 ) { | 447 | if ( out<0 ) { |
448 | if ( QMessageBox::warning(this,tr("End game"), | 448 | if ( QMessageBox::warning(this,tr("End game"), |
449 | tr("Do you want to end the game early?"), | 449 | tr("Do you want to end the game early?"), |
450 | tr("Yes"), tr("No") )!=0 ) | 450 | tr("Yes"), tr("No") )!=0 ) |
451 | { | 451 | { |
452 | return FALSE; | 452 | return FALSE; |
453 | } | 453 | } |
454 | } | 454 | } |
455 | return TRUE; | 455 | return TRUE; |
456 | } | 456 | } |
457 | 457 | ||
458 | void WordGame::endGame() | 458 | void WordGame::endGame() |
459 | { | 459 | { |
460 | if ( gameover ) { | 460 | if ( gameover ) { |
461 | close(); | 461 | close(); |
462 | return; | 462 | return; |
463 | } | 463 | } |
464 | 464 | ||
465 | if ( !mayEndGame() ) | 465 | if ( !mayEndGame() ) |
466 | return; | 466 | return; |
467 | int out=-1; | 467 | int out=-1; |
468 | int totalleft=0; | 468 | int totalleft=0; |
469 | int i; | 469 | int i; |
470 | for (i=0; i<nplayers; i++) { | 470 | for (i=0; i<nplayers; i++) { |
471 | Rack* r = rack(i); | 471 | Rack* r = rack(i); |
472 | int c = r->count(); | 472 | int c = r->count(); |
473 | if ( c ) { | 473 | if ( c ) { |
474 | int lose=0; | 474 | int lose=0; |
475 | for ( int j=0; j<c; j++ ) | 475 | for ( int j=0; j<c; j++ ) |
476 | lose += r->tileRef(j)->value(); | 476 | lose += r->tileRef(j)->value(); |
477 | totalleft += lose; | 477 | totalleft += lose; |
478 | scoreinfo->addScore(i,-lose); | 478 | scoreinfo->addScore(i,-lose); |
479 | } else { | 479 | } else { |
480 | out = i; | 480 | out = i; |
481 | } | 481 | } |
482 | } | 482 | } |
483 | int highest=0; | 483 | int highest=0; |
484 | int winner=0; | 484 | int winner=0; |
485 | for (i=0; i<nplayers; i++) { | 485 | for (i=0; i<nplayers; i++) { |
486 | int s = scoreinfo->playerScore(i); | 486 | int s = scoreinfo->playerScore(i); |
487 | if ( s > highest ) { | 487 | if ( s > highest ) { |
488 | highest = s; | 488 | highest = s; |
489 | winner = i; | 489 | winner = i; |
490 | } | 490 | } |
491 | } | 491 | } |
492 | if ( out >= 0 ) | 492 | if ( out >= 0 ) |
493 | scoreinfo->addScore(out,totalleft); | 493 | scoreinfo->addScore(out,totalleft); |
494 | scoreinfo->setBoldOne(winner); | 494 | scoreinfo->setBoldOne(winner); |
495 | gameover = TRUE; | 495 | gameover = TRUE; |
496 | done->setEnabled(TRUE); | 496 | done->setEnabled(TRUE); |
497 | reset->setEnabled(FALSE); | 497 | reset->setEnabled(FALSE); |
498 | } | 498 | } |
499 | 499 | ||
500 | void WordGame::endTurn() | 500 | void WordGame::endTurn() |
501 | { | 501 | { |
502 | if ( gameover ) { | 502 | if ( gameover ) { |
503 | openGameSelector(namelist); | 503 | openGameSelector(namelist); |
504 | } else { | 504 | } else { |
505 | if ( board->checkTurn() ) { | 505 | if ( board->checkTurn() ) { |
506 | if ( board->turnScore() >= 0 ) { | 506 | if ( board->turnScore() >= 0 ) { |
507 | scoreinfo->addScore(player,board->turnScore()); | 507 | scoreinfo->addScore(player,board->turnScore()); |
508 | board->finalizeTurn(); | 508 | board->finalizeTurn(); |
509 | } else { | 509 | } else { |
510 | QApplication::beep(); | 510 | QApplication::beep(); |
511 | } | 511 | } |
512 | nextPlayer(); | 512 | nextPlayer(); |
513 | } | 513 | } |
514 | } | 514 | } |
515 | } | 515 | } |
516 | 516 | ||
517 | void WordGame::resetTurn() | 517 | void WordGame::resetTurn() |
518 | { | 518 | { |
519 | board->resetRack(); | 519 | board->resetRack(); |
520 | } | 520 | } |
521 | 521 | ||
522 | void WordGame::passTurn() | 522 | void WordGame::passTurn() |
523 | { | 523 | { |
524 | // ######## trade? | 524 | // ######## trade? |
525 | nextPlayer(); | 525 | nextPlayer(); |
526 | } | 526 | } |
527 | 527 | ||
528 | bool WordGame::refillRack(int i) | 528 | bool WordGame::refillRack(int i) |
529 | { | 529 | { |
530 | Rack* r = rack(i); | 530 | Rack* r = rack(i); |
531 | while ( !bag->isEmpty() && !r->isFull() ) { | 531 | while ( !bag->isEmpty() && !r->isFull() ) { |
532 | r->addTile(bag->takeRandom()); | 532 | r->addTile(bag->takeRandom()); |
533 | } | 533 | } |
534 | return r->count() != 0; | 534 | return r->count() != 0; |
535 | } | 535 | } |
536 | 536 | ||
537 | void WordGame::readyRack(int i) | 537 | void WordGame::readyRack(int i) |
538 | { | 538 | { |
539 | Rack* r = rack(i); | 539 | Rack* r = rack(i); |
540 | racks->raiseWidget(i); | 540 | racks->raiseWidget(i); |
541 | board->setCurrentRack(r); | 541 | board->setCurrentRack(r); |
542 | 542 | ||
543 | done->setEnabled( !r->computerized() ); | 543 | done->setEnabled( !r->computerized() ); |
544 | reset->setEnabled( !r->computerized() ); | 544 | reset->setEnabled( !r->computerized() ); |
545 | 545 | ||
546 | if ( r->computerized() ) { | 546 | if ( r->computerized() ) { |
547 | cpu = new ComputerPlayer(board, r); | 547 | cpu = new ComputerPlayer(board, r); |
548 | aiheart->start(0); | 548 | aiheart->start(0); |
549 | } | 549 | } |
550 | } | 550 | } |
551 | 551 | ||
552 | Rack* WordGame::rack(int i) const | 552 | Rack* WordGame::rack(int i) const |
553 | { | 553 | { |
554 | return (Rack*)racks->widget(i); | 554 | return (Rack*)racks->widget(i); |
555 | } | 555 | } |
556 | 556 | ||
557 | void WordGame::think() | 557 | void WordGame::think() |
558 | { | 558 | { |
559 | if ( !cpu->step() ) { | 559 | if ( !cpu->step() ) { |
560 | delete cpu; | 560 | delete cpu; |
561 | cpu = 0; | 561 | cpu = 0; |
562 | aiheart->stop(); | 562 | aiheart->stop(); |
563 | if ( board->turnScore() < 0 ) | 563 | if ( board->turnScore() < 0 ) |
564 | passTurn(); | 564 | passTurn(); |
565 | else | 565 | else |
566 | endTurn(); | 566 | endTurn(); |
567 | } | 567 | } |
568 | } | 568 | } |
569 | 569 | ||
570 | ComputerPlayer::ComputerPlayer(Board* b, Rack* r) : | 570 | ComputerPlayer::ComputerPlayer(Board* b, Rack* r) : |
571 | board(b), rack(r), best(new const Tile*[rack_tiles]), | 571 | board(b), rack(r), best(new const Tile*[rack_tiles]), |
572 | best_blankvalues(new Tile[rack_tiles]) | 572 | best_blankvalues(new Tile[rack_tiles]) |
573 | { | 573 | { |
574 | best_score = -1; | 574 | best_score = -1; |
575 | across=FALSE; | 575 | across=FALSE; |
576 | dict=0; | 576 | dict=0; |
577 | } | 577 | } |
578 | 578 | ||
579 | ComputerPlayer::~ComputerPlayer() | 579 | ComputerPlayer::~ComputerPlayer() |
580 | { | 580 | { |
581 | delete [] best; | 581 | delete [] best; |
582 | delete [] best_blankvalues; | 582 | delete [] best_blankvalues; |
583 | } | 583 | } |
584 | 584 | ||
585 | bool ComputerPlayer::step() | 585 | bool ComputerPlayer::step() |
586 | { | 586 | { |
587 | const QDawg::Node* root = dict ? Global::dawg("WordGame").root() | 587 | const QDawg::Node* root = dict ? Global::dawg("WordGame").root() |
588 | : Global::fixedDawg().root(); | 588 | : Global::fixedDawg().root(); |
589 | QPoint d = across ? QPoint(1,0) : QPoint(0,1); | 589 | QPoint d = across ? QPoint(1,0) : QPoint(0,1); |
590 | const Tile* tiles[99]; // ### max board size | 590 | const Tile* tiles[99]; // ### max board size |
591 | uchar nletter[4095]; // QDawg only handles 0..4095 | 591 | uchar nletter[4095]; // QDawg only handles 0..4095 |
592 | memset(nletter,0,4096); | 592 | memset(nletter,0,4096); |
593 | for (int i=0; i<rack->count(); i++) { | 593 | for (int i=0; i<rack->count(); i++) { |
594 | const Tile* r = rack->tileRef(i); | 594 | const Tile* r = rack->tileRef(i); |
595 | if ( r->isBlank() ) | 595 | if ( r->isBlank() ) |
596 | nletter[0]++; | 596 | nletter[0]++; |
597 | else | 597 | else |
598 | nletter[r->text()[0].unicode()]++; | 598 | nletter[r->text()[0].unicode()]++; |
599 | } | 599 | } |
600 | Tile blankvalues[99]; // ### max blanks | 600 | Tile blankvalues[99]; // ### max blanks |
601 | findBest(current, d, root, 0, nletter, tiles, 0, blankvalues, 0); | 601 | findBest(current, d, root, 0, nletter, tiles, 0, blankvalues, 0); |
602 | if ( ++current.rx() == board->xTiles() ) { | 602 | if ( ++current.rx() == board->xTiles() ) { |
603 | current.rx() = 0; | 603 | current.rx() = 0; |
604 | if ( ++current.ry() == board->yTiles() ) { | 604 | if ( ++current.ry() == board->yTiles() ) { |
605 | if ( across ) { | 605 | if ( across ) { |
606 | if ( dict == 1 ) { | 606 | if ( dict == 1 ) { |
607 | if ( best_score >= 0 ) { | 607 | if ( best_score >= 0 ) { |
608 | rack->arrangeTiles(best,best_n); | 608 | rack->arrangeTiles(best,best_n); |
609 | rack->setBlanks(best_blankvalues); | 609 | rack->setBlanks(best_blankvalues); |
610 | board->scoreTurn(best_start, best_n, best_dir); | 610 | board->scoreTurn(best_start, best_n, best_dir); |
611 | board->showTurn(); | 611 | board->showTurn(); |
612 | } | 612 | } |
613 | return FALSE; | 613 | return FALSE; |
614 | } | 614 | } |
615 | dict++; | 615 | dict++; |
616 | across = FALSE; | 616 | across = FALSE; |
617 | current = QPoint(0,0); | 617 | current = QPoint(0,0); |
618 | } else { | 618 | } else { |
619 | across = TRUE; | 619 | across = TRUE; |
620 | current = QPoint(0,0); | 620 | current = QPoint(0,0); |
621 | } | 621 | } |
622 | } | 622 | } |
623 | } | 623 | } |
624 | return TRUE; | 624 | return TRUE; |
625 | } | 625 | } |
626 | 626 | ||
627 | void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar* nletter, const Tile** tiles, int n, Tile* blankvalues, int blused) | 627 | void ComputerPlayer::findBest(QPoint at, const QPoint& d, const QDawg::Node* node, ulong used, uchar* nletter, const Tile** tiles, int n, Tile* blankvalues, int blused) |
628 | { | 628 | { |
629 | if ( !node ) | 629 | if ( !node ) |
630 | return; | 630 | return; |
631 | QChar l = node->letter(); | 631 | QChar l = node->letter(); |
632 | const Tile* cur = board->tile(at); | 632 | const Tile* cur = board->tile(at); |
633 | if ( cur ) { | 633 | if ( cur ) { |
634 | if ( cur->text()[0] == l ) { | 634 | if ( cur->text()[0] == l ) { |
635 | bool nextok = board->contains(at+d); | 635 | bool nextok = board->contains(at+d); |
636 | if ( node->isWord() && n && (!nextok || !board->tile(at+d)) ) | 636 | if ( node->isWord() && n && (!nextok || !board->tile(at+d)) ) |
637 | noteChoice(tiles,n,d,blankvalues,blused); | 637 | noteChoice(tiles,n,d,blankvalues,blused); |
638 | if ( nextok ) | 638 | if ( nextok ) |
639 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); | 639 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); |
640 | // #### text()[1]... | 640 | // #### text()[1]... |
641 | } | 641 | } |
642 | } else { | 642 | } else { |
643 | if ( nletter[l.unicode()] || nletter[0] ) { | 643 | if ( nletter[l.unicode()] || nletter[0] ) { |
644 | int rc = rack->count(); | 644 | int rc = rack->count(); |
645 | ulong msk = 1; | 645 | ulong msk = 1; |
646 | for ( int x=0; x<rc; x++ ) { | 646 | for ( int x=0; x<rc; x++ ) { |
647 | if ( !(used&msk) ) { | 647 | if ( !(used&msk) ) { |
648 | const Tile* t = rack->tileRef(x); | 648 | const Tile* t = rack->tileRef(x); |
649 | if ( t->isBlank() || t->text() == l ) { // #### multi-char value()s | 649 | if ( t->isBlank() || t->text() == l ) { // #### multi-char value()s |
650 | bool nextok = board->contains(at+d); | 650 | bool nextok = board->contains(at+d); |
651 | tiles[n++] = t; | 651 | tiles[n++] = t; |
652 | if ( t->isBlank() ) | 652 | if ( t->isBlank() ) |
653 | blankvalues[blused++] = Tile(l,0); | 653 | blankvalues[blused++] = Tile(l,0); |
654 | if ( node->isWord() && (!nextok || !board->tile(at+d)) ) | 654 | if ( node->isWord() && (!nextok || !board->tile(at+d)) ) |
655 | noteChoice(tiles,n,d,blankvalues,blused); | 655 | noteChoice(tiles,n,d,blankvalues,blused); |
656 | used |= msk; // mark | 656 | used |= msk; // mark |
657 | nletter[t->text()[0].unicode()]--; | 657 | nletter[t->text()[0].unicode()]--; |
658 | if ( nextok ) | 658 | if ( nextok ) |
659 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); | 659 | findBest(at+d, d, node->jump(), used, nletter, tiles, n, blankvalues, blused); |
660 | n--; | 660 | n--; |
661 | nletter[t->text()[0].unicode()]++; | 661 | nletter[t->text()[0].unicode()]++; |
662 | if ( t->isBlank() ) { | 662 | if ( t->isBlank() ) { |
663 | // keep looking | 663 | // keep looking |
664 | blused--; | 664 | blused--; |
665 | used &= ~msk; // unmark | 665 | used &= ~msk; // unmark |
666 | } else { | 666 | } else { |
667 | break; | 667 | break; |
668 | } | 668 | } |
669 | } | 669 | } |
670 | } | 670 | } |
671 | msk <<= 1; | 671 | msk <<= 1; |
672 | } | 672 | } |
673 | } | 673 | } |
674 | // #### text()[1]... | 674 | // #### text()[1]... |
675 | } | 675 | } |
676 | findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused); | 676 | findBest(at, d, node->next(), used, nletter, tiles, n, blankvalues, blused); |
677 | } | 677 | } |
678 | 678 | ||
679 | void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused) | 679 | void ComputerPlayer::noteChoice(const Tile** tiles, int n, const QPoint& d, const Tile* blankvalues, int blused) |
680 | { | 680 | { |
681 | int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0); | 681 | int s = board->score(current, tiles, n, blankvalues, d, TRUE, 0); |
682 | /* | 682 | /* |
683 | if (s>0 || current==QPoint(5,1)){ | 683 | if (s>0 || current==QPoint(5,1)){ |
684 | QString st; | 684 | QString st; |
685 | for ( int i=0; i<n; i++ ) | 685 | for ( int i=0; i<n; i++ ) |
686 | st += tiles[i]->text(); | 686 | st += tiles[i]->text(); |
687 | qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s); | 687 | qDebug("%d,%d: %s (%d) for %d",current.x(),current.y(),st.latin1(),n,s); |
688 | } | 688 | } |
689 | */ | 689 | */ |
690 | if ( s > best_score ) { | 690 | if ( s > best_score ) { |
691 | int i; | 691 | int i; |
692 | for ( i=0; i<n; i++ ) | 692 | for ( i=0; i<n; i++ ) |
693 | best[i] = tiles[i]; | 693 | best[i] = tiles[i]; |
694 | for ( i=0; i<blused; i++ ) | 694 | for ( i=0; i<blused; i++ ) |
695 | best_blankvalues[i] = blankvalues[i]; | 695 | best_blankvalues[i] = blankvalues[i]; |
696 | best_n = n; | 696 | best_n = n; |
697 | best_blused = blused; | 697 | best_blused = blused; |
698 | best_score = s; | 698 | best_score = s; |
699 | best_dir = d; | 699 | best_dir = d; |
700 | best_start = current; | 700 | best_start = current; |
701 | } | 701 | } |
702 | } | 702 | } |
703 | 703 | ||
704 | int TileItem::smallWidth() | 704 | int TileItem::smallWidth() |
705 | { | 705 | { |
706 | return tile_smallw; | 706 | return tile_smallw; |
707 | } | 707 | } |
708 | 708 | ||
709 | int TileItem::smallHeight() | 709 | int TileItem::smallHeight() |
710 | { | 710 | { |
711 | return tile_smallh; | 711 | return tile_smallh; |
712 | } | 712 | } |
713 | 713 | ||
714 | int TileItem::bigWidth() | 714 | int TileItem::bigWidth() |
715 | { | 715 | { |
716 | return tile_bigw; | 716 | return tile_bigw; |
717 | } | 717 | } |
718 | 718 | ||
719 | int TileItem::bigHeight() | 719 | int TileItem::bigHeight() |
720 | { | 720 | { |
721 | return tile_bigh; | 721 | return tile_bigh; |
722 | } | 722 | } |
723 | 723 | ||
724 | void TileItem::setState( State state ) | 724 | void TileItem::setState( State state ) |
725 | { | 725 | { |
726 | hide(); | 726 | hide(); |
727 | s = state; | 727 | s = state; |
728 | show(); // ### use update() in Qt 3.0 | 728 | show(); // ### use update() in Qt 3.0 |
729 | } | 729 | } |
730 | 730 | ||
731 | void TileItem::setTile(const Tile& tile) | 731 | void TileItem::setTile(const Tile& tile) |
732 | { | 732 | { |
733 | hide(); | 733 | hide(); |
734 | t = tile; | 734 | t = tile; |
735 | show(); // ### use update() in Qt 3.0 | 735 | show(); // ### use update() in Qt 3.0 |
736 | } | 736 | } |
737 | 737 | ||
738 | void TileItem::setBig(bool b) | 738 | void TileItem::setBig(bool b) |
739 | { | 739 | { |
740 | big = b; | 740 | big = b; |
741 | } | 741 | } |
742 | 742 | ||
743 | void TileItem::drawShape(QPainter& p) | 743 | void TileItem::drawShape(QPainter& p) |
744 | { | 744 | { |
745 | static QFont *value_font=0; | 745 | static QFont *value_font=0; |
746 | static QFont *big_font=0; | 746 | static QFont *big_font=0; |
747 | static QFont *small_font=0; | 747 | static QFont *small_font=0; |
748 | if ( !value_font ) { | 748 | if ( !value_font ) { |
749 | value_font = new QFont("helvetica",8); | 749 | value_font = new QFont("helvetica",8); |
750 | if ( TileItem::bigWidth() < 20 ) { | 750 | if ( TileItem::bigWidth() < 20 ) { |
751 | big_font = new QFont("helvetica",12); | 751 | big_font = new QFont("helvetica",12); |
752 | small_font = new QFont("helvetica",8); | 752 | small_font = new QFont("helvetica",8); |
753 | } else { | 753 | } else { |
754 | big_font = new QFont("smoothtimes",17); | 754 | big_font = new QFont("smoothtimes",17); |
755 | small_font = new QFont("smoothtimes",10); | 755 | small_font = new QFont("smoothtimes",10); |
756 | } | 756 | } |
757 | } | 757 | } |
758 | 758 | ||
759 | QRect area(x(),y(),width(),height()); | 759 | QRect area(x(),y(),width(),height()); |
760 | p.setBrush(s == Floating ? yellow/*lightGray*/ : white); | 760 | p.setBrush(s == Floating ? yellow/*lightGray*/ : white); |
761 | p.drawRect(area); | 761 | p.drawRect(area); |
762 | if ( big ) { | 762 | if ( big ) { |
763 | p.setFont(*value_font); | 763 | p.setFont(*value_font); |
764 | QString n = QString::number(t.value()); | 764 | QString n = QString::number(t.value()); |
765 | int w = p.fontMetrics().width('1'); | 765 | int w = p.fontMetrics().width('1'); |
766 | int h = p.fontMetrics().height(); | 766 | int h = p.fontMetrics().height(); |
767 | w *= n.length(); | 767 | w *= n.length(); |
768 | QRect valuearea(x()+width()-w-1,y()+height()-h,w,h); | 768 | QRect valuearea(x()+width()-w-1,y()+height()-h,w,h); |
769 | p.drawText(valuearea,AlignCenter,n); | 769 | p.drawText(valuearea,AlignCenter,n); |
770 | p.setFont(*big_font); | 770 | p.setFont(*big_font); |
771 | area = QRect(x(),y()+tile_btweak,width()-4,height()-1); | 771 | area = QRect(x(),y()+tile_btweak,width()-4,height()-1); |
772 | } else { | 772 | } else { |
773 | p.setFont(*small_font); | 773 | p.setFont(*small_font); |
774 | area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3); | 774 | area = QRect(x()+1+tile_stweak,y()+1,width(),height()-3); |
775 | } | 775 | } |
776 | if ( t.value() == 0 ) | 776 | if ( t.value() == 0 ) |
777 | p.setPen(darkGray); | 777 | p.setPen(darkGray); |
778 | p.drawText(area,AlignCenter,t.text().upper()); | 778 | p.drawText(area,AlignCenter,t.text().upper()); |
779 | } | 779 | } |
780 | 780 | ||
781 | Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : | 781 | Board::Board(QPixmap bgshapes, int w, int h, QWidget* parent) : |
782 | QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), | 782 | QCanvasView(new QCanvas(bgshapes,w,h, TileItem::smallWidth(), TileItem::smallHeight()), |
783 | parent) | 783 | parent) |
784 | { | 784 | { |
785 | setFixedSize(w*TileItem::smallWidth(),h*TileItem::smallHeight()); | 785 | setFixedSize(w*TileItem::smallWidth(),h*TileItem::smallHeight()); |
786 | grid = new TileItem*[w*h]; | 786 | grid = new TileItem*[w*h]; |
787 | memset(grid,0,w*h*sizeof(TileItem*)); | 787 | memset(grid,0,w*h*sizeof(TileItem*)); |
788 | setFrameStyle(0); | 788 | setFrameStyle(0); |
789 | setHScrollBarMode(AlwaysOff); | 789 | setHScrollBarMode(AlwaysOff); |
790 | setVScrollBarMode(AlwaysOff); | 790 | setVScrollBarMode(AlwaysOff); |
791 | current_rack = 0; | 791 | current_rack = 0; |
792 | shown_n = 0; | 792 | shown_n = 0; |
793 | } | 793 | } |
794 | 794 | ||
795 | Board::~Board() | 795 | Board::~Board() |
796 | { | 796 | { |
797 | delete canvas(); | 797 | delete canvas(); |
798 | } | 798 | } |
799 | 799 | ||
800 | QSize Board::sizeHint() const | 800 | QSize Board::sizeHint() const |
801 | { | 801 | { |
802 | return QSize(canvas()->width(),canvas()->height()); | 802 | return QSize(canvas()->width(),canvas()->height()); |
803 | } | 803 | } |
804 | 804 | ||
805 | void Board::writeConfig(Config& cfg) | 805 | void Board::writeConfig(Config& cfg) |
806 | { | 806 | { |
807 | QStringList t; | 807 | QStringList t; |
808 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); | 808 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); |
809 | for (int i=0; i<n; i++) | 809 | for (int i=0; i<n; i++) |
810 | t.append( grid[i] ? grid[i]->tile().key() : QString(".") ); | 810 | t.append( grid[i] ? grid[i]->tile().key() : QString(".") ); |
811 | cfg.writeEntry("Board",t,';'); | 811 | cfg.writeEntry("Board",t,';'); |
812 | } | 812 | } |
813 | 813 | ||
814 | void Board::readConfig(Config& cfg) | 814 | void Board::readConfig(Config& cfg) |
815 | { | 815 | { |
816 | clear(); | 816 | clear(); |
817 | QStringList t = cfg.readListEntry("Board",';'); | 817 | QStringList t = cfg.readListEntry("Board",';'); |
818 | int i=0; | 818 | int i=0; |
819 | int h=canvas()->tilesHorizontally(); | 819 | int h=canvas()->tilesHorizontally(); |
820 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it) { | 820 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it) { |
821 | if ( *it != "." ) { | 821 | if ( *it != "." ) { |
822 | QPoint p(i%h,i/h); | 822 | QPoint p(i%h,i/h); |
823 | setTile(p,Tile(*it)); | 823 | setTile(p,Tile(*it)); |
824 | } | 824 | } |
825 | i++; | 825 | i++; |
826 | } | 826 | } |
827 | canvas()->update(); | 827 | canvas()->update(); |
828 | } | 828 | } |
829 | 829 | ||
830 | void Board::clear() | 830 | void Board::clear() |
831 | { | 831 | { |
832 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); | 832 | int n=canvas()->tilesHorizontally()*canvas()->tilesVertically(); |
833 | for (int i=0; i<n; i++) { | 833 | for (int i=0; i<n; i++) { |
834 | delete grid[i]; | 834 | delete grid[i]; |
835 | grid[i]=0; | 835 | grid[i]=0; |
836 | } | 836 | } |
837 | } | 837 | } |
838 | 838 | ||
839 | 839 | ||
840 | void Board::setCurrentRack(Rack* r) | 840 | void Board::setCurrentRack(Rack* r) |
841 | { | 841 | { |
842 | turn_score = -1; | 842 | turn_score = -1; |
843 | current_rack = r; | 843 | current_rack = r; |
844 | } | 844 | } |
845 | 845 | ||
846 | void Board::resetRack() | 846 | void Board::resetRack() |
847 | { | 847 | { |
848 | unshowTurn(); | 848 | unshowTurn(); |
849 | canvas()->update(); | 849 | canvas()->update(); |
850 | } | 850 | } |
851 | 851 | ||
852 | void Board::contentsMousePressEvent(QMouseEvent* e) | 852 | void Board::contentsMousePressEvent(QMouseEvent* e) |
853 | { | 853 | { |
854 | dragstart = e->pos(); | 854 | dragstart = e->pos(); |
855 | } | 855 | } |
856 | 856 | ||
857 | void Board::contentsMouseMoveEvent(QMouseEvent* e) | 857 | void Board::contentsMouseMoveEvent(QMouseEvent* e) |
858 | { | 858 | { |
859 | if ( current_rack && !current_rack->computerized() ) { | 859 | if ( current_rack && !current_rack->computerized() ) { |
860 | QPoint d = e->pos() - dragstart; | 860 | QPoint d = e->pos() - dragstart; |
861 | if ( d.x() <= 0 && d.y() <= 0 ) { | 861 | if ( d.x() <= 0 && d.y() <= 0 ) { |
862 | // None | 862 | // None |
863 | resetRack(); | 863 | resetRack(); |
864 | } else { | 864 | } else { |
865 | int n; | 865 | int n; |
866 | QPoint start=boardPos(dragstart); | 866 | QPoint start=boardPos(dragstart); |
867 | QPoint end=boardPos(e->pos()); | 867 | QPoint end=boardPos(e->pos()); |
868 | QPoint diff=end-start; | 868 | QPoint diff=end-start; |
869 | QPoint dir; | 869 | QPoint dir; |
870 | if ( d.x() > d.y() ) { | 870 | if ( d.x() > d.y() ) { |
871 | n = diff.x()+1; | 871 | n = diff.x()+1; |
872 | dir = QPoint(1,0); | 872 | dir = QPoint(1,0); |
873 | } else { | 873 | } else { |
874 | n = diff.y()+1; | 874 | n = diff.y()+1; |
875 | dir = QPoint(0,1); | 875 | dir = QPoint(0,1); |
876 | } | 876 | } |
877 | 877 | ||
878 | unshowTurn(); | 878 | unshowTurn(); |
879 | 879 | ||
880 | // Subtract existing tiles from n | 880 | // Subtract existing tiles from n |
881 | QPoint t = start; | 881 | QPoint t = start; |
882 | for ( int i=n; i--; ) { | 882 | for ( int i=n; i--; ) { |
883 | if ( contains(t) && tile(t) ) | 883 | if ( contains(t) && tile(t) ) |
884 | n--; | 884 | n--; |
885 | t += dir; | 885 | t += dir; |
886 | } | 886 | } |
887 | 887 | ||
888 | // Move start back to real start | 888 | // Move start back to real start |
889 | while (contains(start-dir) && tile(start-dir)) | 889 | while (contains(start-dir) && tile(start-dir)) |
890 | start -= dir; | 890 | start -= dir; |
891 | 891 | ||
892 | scoreTurn(start, n, dir); | 892 | scoreTurn(start, n, dir); |
893 | showTurn(); | 893 | showTurn(); |
894 | } | 894 | } |
895 | } | 895 | } |
896 | } | 896 | } |
897 | 897 | ||
898 | void Board::finalizeTurn() | 898 | void Board::finalizeTurn() |
899 | { | 899 | { |
900 | int i=0; | 900 | int i=0; |
901 | QPoint at = shown_at; | 901 | QPoint at = shown_at; |
902 | while ( i<shown_n && contains(at) ) { | 902 | while ( i<shown_n && contains(at) ) { |
903 | if ( item(at) && item(at)->state() == TileItem::Floating ) { | 903 | if ( item(at) && item(at)->state() == TileItem::Floating ) { |
904 | current_rack->remove(item(at)->tile()); | 904 | current_rack->remove(item(at)->tile()); |
905 | setTileState(at,TileItem::Firm); | 905 | setTileState(at,TileItem::Firm); |
906 | i++; | 906 | i++; |
907 | } | 907 | } |
908 | at += shown_step; | 908 | at += shown_step; |
909 | } | 909 | } |
910 | canvas()->update(); | 910 | canvas()->update(); |
911 | } | 911 | } |
912 | 912 | ||
913 | void Board::unshowTurn() | 913 | void Board::unshowTurn() |
914 | { | 914 | { |
915 | int i=0; | 915 | int i=0; |
916 | QPoint at = shown_at; | 916 | QPoint at = shown_at; |
917 | while ( i<shown_n && i<current_rack->count() && contains(at) ) { | 917 | while ( i<shown_n && i<current_rack->count() && contains(at) ) { |
918 | if ( item(at) && item(at)->state() == TileItem::Floating ) { | 918 | if ( item(at) && item(at)->state() == TileItem::Floating ) { |
919 | unsetTile(at); | 919 | unsetTile(at); |
920 | i++; | 920 | i++; |
921 | } | 921 | } |
922 | at += shown_step; | 922 | at += shown_step; |
923 | } | 923 | } |
924 | } | 924 | } |
925 | 925 | ||
926 | void Board::showTurn() | 926 | void Board::showTurn() |
927 | { | 927 | { |
928 | unshowTurn(); | 928 | unshowTurn(); |
929 | QPoint at = shown_at; | 929 | QPoint at = shown_at; |
930 | int i=0; | 930 | int i=0; |
931 | while ( i<shown_n && i<current_rack->count() && contains(at) ) { | 931 | while ( i<shown_n && i<current_rack->count() && contains(at) ) { |
932 | if ( !tile(at) ) { | 932 | if ( !tile(at) ) { |
933 | Tile t = current_rack->tile(i); | 933 | Tile t = current_rack->tile(i); |
934 | setTile(at,t); | 934 | setTile(at,t); |
935 | setTileState(at,TileItem::Floating); | 935 | setTileState(at,TileItem::Floating); |
936 | i++; | 936 | i++; |
937 | } | 937 | } |
938 | at += shown_step; | 938 | at += shown_step; |
939 | } | 939 | } |
940 | canvas()->update(); | 940 | canvas()->update(); |
941 | } | 941 | } |
942 | 942 | ||
943 | int Board::bonussedValue(const QPoint& at, int base, int& all_mult) const | 943 | int Board::bonussedValue(const QPoint& at, int base, int& all_mult) const |
944 | { | 944 | { |
945 | int rule = rule_shape[idx(at)]-'0'; | 945 | int rule = rule_shape[idx(at)]-'0'; |
946 | int effect = rule_effect[rule]; | 946 | int effect = rule_effect[rule]; |
947 | int mult = effect&Multiplier; | 947 | int mult = effect&Multiplier; |
948 | if ( effect & MultiplyAll ) { | 948 | if ( effect & MultiplyAll ) { |
949 | all_mult *= mult; | 949 | all_mult *= mult; |
950 | return base; | 950 | return base; |
951 | } else { | 951 | } else { |
952 | return base * mult; | 952 | return base * mult; |
953 | } | 953 | } |
954 | } | 954 | } |
955 | 955 | ||
956 | bool Board::isStart(const QPoint& at) const | 956 | bool Board::isStart(const QPoint& at) const |
957 | { | 957 | { |
958 | int rule = rule_shape[idx(at)]-'0'; | 958 | int rule = rule_shape[idx(at)]-'0'; |
959 | int effect = rule_effect[rule]; | 959 | int effect = rule_effect[rule]; |
960 | return effect&Start; | 960 | return effect&Start; |
961 | } | 961 | } |
962 | 962 | ||
963 | bool Board::checkTurn() | 963 | bool Board::checkTurn() |
964 | { | 964 | { |
965 | if ( current_rack->computerized() ) | 965 | if ( current_rack->computerized() ) |
966 | return TRUE; // computer doesn't cheat, and has already set blanks. | 966 | return TRUE; // computer doesn't cheat, and has already set blanks. |
967 | 967 | ||
968 | QPoint at = shown_at; | 968 | QPoint at = shown_at; |
969 | int n = shown_n; | 969 | int n = shown_n; |
970 | QPoint d = shown_step; | 970 | QPoint d = shown_step; |
971 | const Tile* tiles[99]; | 971 | const Tile* tiles[99]; |
972 | Tile blankvalues[99]; | 972 | Tile blankvalues[99]; |
973 | if ( n > current_rack->count() ) | 973 | if ( n > current_rack->count() ) |
974 | n = current_rack->count(); | 974 | n = current_rack->count(); |
975 | 975 | ||
976 | QDialog check(this,0,TRUE); | 976 | QDialog check(this,0,TRUE); |
977 | (new QVBoxLayout(&check))->setAutoAdd(TRUE); | 977 | (new QVBoxLayout(&check))->setAutoAdd(TRUE); |
978 | 978 | ||
979 | QHBox mw(&check); | 979 | QHBox mw(&check); |
980 | new QLabel(tr("Blanks: "),&mw); | 980 | new QLabel(tr("Blanks: "),&mw); |
981 | 981 | ||
982 | int bl=0; | 982 | int bl=0; |
983 | QLineEdit* le[99]; | 983 | QLineEdit* le[99]; |
984 | for (int i=0; i<n; i++) { | 984 | for (int i=0; i<n; i++) { |
985 | tiles[i] = current_rack->tileRef(i); | 985 | tiles[i] = current_rack->tileRef(i); |
986 | if ( tiles[i]->isBlank() ) { | 986 | if ( tiles[i]->isBlank() ) { |
987 | QLineEdit *l = new QLineEdit(&mw); | 987 | QLineEdit *l = new QLineEdit(&mw); |
988 | le[bl++] = l; | 988 | le[bl++] = l; |
989 | l->setMaxLength(1); | 989 | l->setMaxLength(1); |
990 | l->setFixedSize(l->minimumSizeHint()); | 990 | l->setFixedSize(l->minimumSizeHint()); |
991 | } | 991 | } |
992 | } | 992 | } |
993 | 993 | ||
994 | QHBox btns(&check); | 994 | QHBox btns(&check); |
995 | connect(new QPushButton(tr("OK"),&btns), SIGNAL(clicked()), &check, SLOT(accept())); | 995 | connect(new QPushButton(tr("OK"),&btns), SIGNAL(clicked()), &check, SLOT(accept())); |
996 | connect(new QPushButton(tr("Cancel"),&btns), SIGNAL(clicked()), &check, SLOT(reject())); | 996 | connect(new QPushButton(tr("Cancel"),&btns), SIGNAL(clicked()), &check, SLOT(reject())); |
997 | 997 | ||
998 | if ( bl ) { | 998 | if ( bl ) { |
999 | retry: | 999 | retry: |
1000 | if ( !check.exec() ) { | 1000 | if ( !check.exec() ) { |
1001 | unshowTurn(); | 1001 | unshowTurn(); |
1002 | canvas()->update(); | 1002 | canvas()->update(); |
1003 | return FALSE; | 1003 | return FALSE; |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | for (int b=0; b<bl; b++) { | 1006 | for (int b=0; b<bl; b++) { |
1007 | QString v = le[b]->text(); | 1007 | QString v = le[b]->text(); |
1008 | blankvalues[b]=Tile(v,0); | 1008 | blankvalues[b]=Tile(v,0); |
1009 | if ( v.length() != 1 ) | 1009 | if ( v.length() != 1 ) |
1010 | goto retry; | 1010 | goto retry; |
1011 | } | 1011 | } |
1012 | } | 1012 | } |
1013 | 1013 | ||
1014 | QStringList words; | 1014 | QStringList words; |
1015 | unshowTurn(); | 1015 | unshowTurn(); |
1016 | turn_score = score(at,tiles,n,blankvalues,d,FALSE,&words); | 1016 | turn_score = score(at,tiles,n,blankvalues,d,FALSE,&words); |
1017 | showTurn(); | 1017 | showTurn(); |
1018 | QStringList to_add; | 1018 | QStringList to_add; |
1019 | for (QStringList::Iterator it=words.begin(); it!=words.end(); ++it) { | 1019 | for (QStringList::Iterator it=words.begin(); it!=words.end(); ++it) { |
1020 | if ( !Global::fixedDawg().contains(*it) | 1020 | if ( !Global::fixedDawg().contains(*it) |
1021 | && !Global::dawg("WordGame").contains(*it) ) { | 1021 | && !Global::dawg("WordGame").contains(*it) ) { |
1022 | switch (QMessageBox::warning(this, tr("Unknown word"), | 1022 | switch (QMessageBox::warning(this, tr("Unknown word"), |
1023 | tr("<p>The word \"%1\" is not in the dictionary.").arg(*it), | 1023 | tr("<p>The word \"%1\" is not in the dictionary.").arg(*it), |
1024 | tr("Add"), tr("Ignore"), tr("Cancel"))) | 1024 | tr("Add"), tr("Ignore"), tr("Cancel"))) |
1025 | { | 1025 | { |
1026 | case 0: | 1026 | case 0: |
1027 | // ####### add to wordgame dictionary | 1027 | // ####### add to wordgame dictionary |
1028 | to_add.append(*it); | 1028 | to_add.append(*it); |
1029 | break; | 1029 | break; |
1030 | case 1: | 1030 | case 1: |
1031 | break; | 1031 | break; |
1032 | case 2: | 1032 | case 2: |
1033 | unshowTurn(); | 1033 | unshowTurn(); |
1034 | canvas()->update(); | 1034 | canvas()->update(); |
1035 | return FALSE; | 1035 | return FALSE; |
1036 | } | 1036 | } |
1037 | } | 1037 | } |
1038 | } | 1038 | } |
1039 | if ( to_add.count() ) | 1039 | if ( to_add.count() ) |
1040 | Global::addWords("WordGame",to_add); | 1040 | Global::addWords("WordGame",to_add); |
1041 | return TRUE; | 1041 | return TRUE; |
1042 | } | 1042 | } |
1043 | 1043 | ||
1044 | void Board::scoreTurn(const QPoint& at, int n, const QPoint& d) | 1044 | void Board::scoreTurn(const QPoint& at, int n, const QPoint& d) |
1045 | { | 1045 | { |
1046 | unshowTurn(); | 1046 | unshowTurn(); |
1047 | shown_at = at; | 1047 | shown_at = at; |
1048 | shown_n = n; | 1048 | shown_n = n; |
1049 | shown_step = d; | 1049 | shown_step = d; |
1050 | const Tile* tiles[99]; | 1050 | const Tile* tiles[99]; |
1051 | if ( n > current_rack->count() ) | 1051 | if ( n > current_rack->count() ) |
1052 | n = current_rack->count(); | 1052 | n = current_rack->count(); |
1053 | for (int i=0; i<n; i++) | 1053 | for (int i=0; i<n; i++) |
1054 | tiles[i] = current_rack->tileRef(i); | 1054 | tiles[i] = current_rack->tileRef(i); |
1055 | turn_score = score(at,tiles,n,0,d,FALSE,0); | 1055 | turn_score = score(at,tiles,n,0,d,FALSE,0); |
1056 | emit temporaryScore(turn_score); | 1056 | emit temporaryScore(turn_score); |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | int Board::score(QPoint at, const Tile** tiles, int n, const Tile* blankvalue, const QPoint& d, bool checkdict, QStringList* words) const | 1059 | int Board::score(QPoint at, const Tile** tiles, int n, const Tile* blankvalue, const QPoint& d, bool checkdict, QStringList* words) const |
1060 | { | 1060 | { |
1061 | int total=0; | 1061 | int total=0; |
1062 | int totalsidetotal=0; | 1062 | int totalsidetotal=0; |
1063 | 1063 | ||
1064 | // words gets filled with words made | 1064 | // words gets filled with words made |
1065 | 1065 | ||
1066 | // mainword==0 -> | 1066 | // mainword==0 -> |
1067 | // Checks side words, but not main word | 1067 | // Checks side words, but not main word |
1068 | 1068 | ||
1069 | // -1 means words not in dict, or illegally positioned (eg. not connected) | 1069 | // -1 means words not in dict, or illegally positioned (eg. not connected) |
1070 | 1070 | ||
1071 | // text is assumed to fit on board. | 1071 | // text is assumed to fit on board. |
1072 | 1072 | ||
1073 | if ( words ) *words=QStringList(); | 1073 | if ( words ) *words=QStringList(); |
1074 | 1074 | ||
1075 | QPoint otherd(d.y(), d.x()); | 1075 | QPoint otherd(d.y(), d.x()); |
1076 | 1076 | ||
1077 | int all_mult = 1; | 1077 | int all_mult = 1; |
1078 | int bl=0; | 1078 | int bl=0; |
1079 | 1079 | ||
1080 | bool connected = FALSE; | 1080 | bool connected = FALSE; |
1081 | 1081 | ||
1082 | QString mainword=""; | 1082 | QString mainword=""; |
1083 | 1083 | ||
1084 | if ( contains(at-d) && tile(at-d) ) { | 1084 | if ( contains(at-d) && tile(at-d) ) { |
1085 | return -1; // preceeding tiles | 1085 | return -1; // preceeding tiles |
1086 | } | 1086 | } |
1087 | 1087 | ||
1088 | const Tile* t; | 1088 | const Tile* t; |
1089 | for (int i=0; contains(at) && ((t=tile(at)) || i<n); ) { | 1089 | for (int i=0; contains(at) && ((t=tile(at)) || i<n); ) { |
1090 | if ( t ) { | 1090 | if ( t ) { |
1091 | if ( checkdict || words ) mainword += t->text(); | 1091 | if ( checkdict || words ) mainword += t->text(); |
1092 | total += t->value(); | 1092 | total += t->value(); |
1093 | connected = TRUE; | 1093 | connected = TRUE; |
1094 | } else { | 1094 | } else { |
1095 | QString sideword; | 1095 | QString sideword; |
1096 | QString tt; | 1096 | QString tt; |
1097 | if ( tiles[i]->isBlank() ) { | 1097 | if ( tiles[i]->isBlank() ) { |
1098 | if ( blankvalue ) | 1098 | if ( blankvalue ) |
1099 | tt = blankvalue[bl++].text(); | 1099 | tt = blankvalue[bl++].text(); |
1100 | } else { | 1100 | } else { |
1101 | tt = tiles[i]->text(); | 1101 | tt = tiles[i]->text(); |
1102 | } | 1102 | } |
1103 | sideword=tt; | 1103 | sideword=tt; |
1104 | if ( checkdict || words ) mainword += tt; | 1104 | if ( checkdict || words ) mainword += tt; |
1105 | int side_mult = 1; | 1105 | int side_mult = 1; |
1106 | int tilevalue = bonussedValue(at,tiles[i]->value(),side_mult); | 1106 | int tilevalue = bonussedValue(at,tiles[i]->value(),side_mult); |
1107 | all_mult *= side_mult; | 1107 | all_mult *= side_mult; |
1108 | if ( !connected && isStart(at) ) | 1108 | if ( !connected && isStart(at) ) |
1109 | connected = TRUE; | 1109 | connected = TRUE; |
1110 | total += tilevalue; | 1110 | total += tilevalue; |
1111 | int sidetotal = tilevalue; | 1111 | int sidetotal = tilevalue; |
1112 | { | 1112 | { |
1113 | QPoint side = at-otherd; | 1113 | QPoint side = at-otherd; |
1114 | 1114 | ||
1115 | while ( contains(side) && (t=tile(side)) ) { | 1115 | while ( contains(side) && (t=tile(side)) ) { |
1116 | sidetotal += t->value(); | 1116 | sidetotal += t->value(); |
1117 | sideword.prepend(t->text()); | 1117 | sideword.prepend(t->text()); |
1118 | side -= otherd; | 1118 | side -= otherd; |
1119 | } | 1119 | } |
1120 | } | 1120 | } |
1121 | { | 1121 | { |
1122 | QPoint side = at+otherd; | 1122 | QPoint side = at+otherd; |
1123 | while ( contains(side) && (t=tile(side)) ) { | 1123 | while ( contains(side) && (t=tile(side)) ) { |
1124 | sidetotal += t->value(); | 1124 | sidetotal += t->value(); |
1125 | sideword.append(t->text()); | 1125 | sideword.append(t->text()); |
1126 | side += otherd; | 1126 | side += otherd; |
1127 | } | 1127 | } |
1128 | } | 1128 | } |
1129 | if ( sideword.length() > 1 ) { | 1129 | if ( sideword.length() > 1 ) { |
1130 | if ( words ) | 1130 | if ( words ) |
1131 | words->append(sideword); | 1131 | words->append(sideword); |
1132 | if ( checkdict && !Global::fixedDawg().contains(sideword) | 1132 | if ( checkdict && !Global::fixedDawg().contains(sideword) |
1133 | && !Global::dawg("WordGame").contains(sideword) ) | 1133 | && !Global::dawg("WordGame").contains(sideword) ) |
1134 | return -1; | 1134 | return -1; |
1135 | totalsidetotal += sidetotal * side_mult; | 1135 | totalsidetotal += sidetotal * side_mult; |
1136 | connected = TRUE; | 1136 | connected = TRUE; |
1137 | } | 1137 | } |
1138 | i++; | 1138 | i++; |
1139 | } | 1139 | } |
1140 | at += d; | 1140 | at += d; |
1141 | } | 1141 | } |
1142 | 1142 | ||
1143 | if ( words ) | 1143 | if ( words ) |
1144 | words->append(mainword); | 1144 | words->append(mainword); |
1145 | if ( checkdict && !Global::fixedDawg().contains(mainword) | 1145 | if ( checkdict && !Global::fixedDawg().contains(mainword) |
1146 | && !Global::dawg("WordGame").contains(mainword) ) | 1146 | && !Global::dawg("WordGame").contains(mainword) ) |
1147 | return -1; | 1147 | return -1; |
1148 | 1148 | ||
1149 | if ( n == rack_tiles ) | 1149 | if ( n == rack_tiles ) |
1150 | totalsidetotal += rack_tiles_bonus; | 1150 | totalsidetotal += rack_tiles_bonus; |
1151 | 1151 | ||
1152 | return connected ? totalsidetotal + total * all_mult : -1; | 1152 | return connected ? totalsidetotal + total * all_mult : -1; |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | QPoint Board::boardPos(const QPoint& p) const | 1155 | QPoint Board::boardPos(const QPoint& p) const |
1156 | { | 1156 | { |
1157 | return QPoint(p.x()/canvas()->tileWidth(), p.y()/canvas()->tileHeight()); | 1157 | return QPoint(p.x()/canvas()->tileWidth(), p.y()/canvas()->tileHeight()); |
1158 | } | 1158 | } |
1159 | 1159 | ||
1160 | void Board::contentsMouseReleaseEvent(QMouseEvent*) | 1160 | void Board::contentsMouseReleaseEvent(QMouseEvent*) |
1161 | { | 1161 | { |
1162 | if ( current_rack ) { | 1162 | if ( current_rack ) { |
1163 | } | 1163 | } |
1164 | } | 1164 | } |
1165 | 1165 | ||
1166 | 1166 | ||
1167 | void Board::setRules(const QString& shapes, const int* effects) | 1167 | void Board::setRules(const QString& shapes, const int* effects) |
1168 | { | 1168 | { |
1169 | rule_shape=shapes; rule_effect=effects; | 1169 | rule_shape=shapes; rule_effect=effects; |
1170 | int i=0; | 1170 | int i=0; |
1171 | int maxre=0; | 1171 | int maxre=0; |
1172 | for (int y=0; y<yTiles(); y++) { | 1172 | for (int y=0; y<yTiles(); y++) { |
1173 | for (int x=0; x<xTiles(); x++) { | 1173 | for (int x=0; x<xTiles(); x++) { |
1174 | int re = shapes[i++]-'0'; | 1174 | int re = shapes[i++]-'0'; |
1175 | if ( re > maxre ) maxre = re; | 1175 | if ( re > maxre ) maxre = re; |
1176 | canvas()->setTile(x,y,re); | 1176 | canvas()->setTile(x,y,re); |
1177 | } | 1177 | } |
1178 | } | 1178 | } |
1179 | rack_tiles_bonus=effects[maxre+1]; | 1179 | rack_tiles_bonus=effects[maxre+1]; |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | void Board::unsetTile(const QPoint& p) | 1182 | void Board::unsetTile(const QPoint& p) |
1183 | { | 1183 | { |
1184 | delete item(p); | 1184 | delete item(p); |
1185 | grid[idx(p)] = 0; | 1185 | grid[idx(p)] = 0; |
1186 | } | 1186 | } |
1187 | 1187 | ||
1188 | void Board::setTile(const QPoint& p, const Tile& t) | 1188 | void Board::setTile(const QPoint& p, const Tile& t) |
1189 | { | 1189 | { |
1190 | TileItem* it=item(p); | 1190 | TileItem* it=item(p); |
1191 | if ( !it ) { | 1191 | if ( !it ) { |
1192 | it = grid[idx(p)] = new TileItem(t,FALSE,canvas()); | 1192 | it = grid[idx(p)] = new TileItem(t,FALSE,canvas()); |
1193 | it->move(p.x()*canvas()->tileWidth(), p.y()*canvas()->tileHeight()); | 1193 | it->move(p.x()*canvas()->tileWidth(), p.y()*canvas()->tileHeight()); |
1194 | it->show(); | 1194 | it->show(); |
1195 | } else { | 1195 | } else { |
1196 | it->setTile(t); | 1196 | it->setTile(t); |
1197 | } | 1197 | } |
1198 | } | 1198 | } |
1199 | 1199 | ||
1200 | Rack::Rack(int ntiles, QWidget* parent) : QCanvasView( | 1200 | Rack::Rack(int ntiles, QWidget* parent) : QCanvasView( |
1201 | new QCanvas(ntiles*TileItem::bigWidth(),TileItem::bigHeight()), | 1201 | new QCanvas(ntiles*TileItem::bigWidth(),TileItem::bigHeight()), |
1202 | parent), | 1202 | parent), |
1203 | item(ntiles) | 1203 | item(ntiles) |
1204 | { | 1204 | { |
1205 | setLineWidth(1); | 1205 | setLineWidth(1); |
1206 | setFixedHeight(sizeHint().height()); | 1206 | setFixedHeight(sizeHint().height()); |
1207 | n = 0; | 1207 | n = 0; |
1208 | for (int i=0; i<ntiles; i++) | 1208 | for (int i=0; i<ntiles; i++) |
1209 | item[i]=0; | 1209 | item[i]=0; |
1210 | setHScrollBarMode(AlwaysOff); | 1210 | setHScrollBarMode(AlwaysOff); |
1211 | setVScrollBarMode(AlwaysOff); | 1211 | setVScrollBarMode(AlwaysOff); |
1212 | canvas()->setBackgroundColor(gray); | 1212 | canvas()->setBackgroundColor(gray); |
1213 | dragging = 0; | 1213 | dragging = 0; |
1214 | } | 1214 | } |
1215 | 1215 | ||
1216 | Rack::~Rack() | 1216 | Rack::~Rack() |
1217 | { | 1217 | { |
1218 | clear(); | 1218 | clear(); |
1219 | delete canvas(); | 1219 | delete canvas(); |
1220 | } | 1220 | } |
1221 | 1221 | ||
1222 | QSize Rack::sizeHint() const | 1222 | QSize Rack::sizeHint() const |
1223 | { | 1223 | { |
1224 | return QSize(-1,TileItem::bigHeight()+2); | 1224 | return QSize(-1,TileItem::bigHeight()+2); |
1225 | } | 1225 | } |
1226 | 1226 | ||
1227 | void Rack::clear() | 1227 | void Rack::clear() |
1228 | { | 1228 | { |
1229 | for (int i=0; i<n; i++) | 1229 | for (int i=0; i<n; i++) |
1230 | delete item[i]; | 1230 | delete item[i]; |
1231 | n=0; | 1231 | n=0; |
1232 | } | 1232 | } |
1233 | 1233 | ||
1234 | void Rack::writeConfig(Config& cfg) | 1234 | void Rack::writeConfig(Config& cfg) |
1235 | { | 1235 | { |
1236 | QStringList l; | 1236 | QStringList l; |
1237 | for (int i=0; i<n; i++) | 1237 | for (int i=0; i<n; i++) |
1238 | l.append(tile(i).key()); | 1238 | l.append(tile(i).key()); |
1239 | cfg.writeEntry("Tiles",l,';'); | 1239 | cfg.writeEntry("Tiles",l,';'); |
1240 | } | 1240 | } |
1241 | 1241 | ||
1242 | void Rack::readConfig(Config& cfg) | 1242 | void Rack::readConfig(Config& cfg) |
1243 | { | 1243 | { |
1244 | clear(); | 1244 | clear(); |
1245 | int x=0; | 1245 | int x=0; |
1246 | QStringList l = cfg.readListEntry("Tiles",';'); | 1246 | QStringList l = cfg.readListEntry("Tiles",';'); |
1247 | for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { | 1247 | for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) { |
1248 | TileItem *i = new TileItem(Tile(*it),TRUE,canvas()); | 1248 | TileItem *i = new TileItem(Tile(*it),TRUE,canvas()); |
1249 | i->move(x++,0); | 1249 | i->move(x++,0); |
1250 | i->show(); | 1250 | i->show(); |
1251 | item[n++] = i; | 1251 | item[n++] = i; |
1252 | } | 1252 | } |
1253 | layoutTiles(); | 1253 | layoutTiles(); |
1254 | } | 1254 | } |
1255 | 1255 | ||
1256 | static int cmp_tileitem(const void *a, const void *b) | 1256 | static int cmp_tileitem(const void *a, const void *b) |
1257 | { | 1257 | { |
1258 | const TileItem* ia = *(TileItem**)a; | 1258 | const TileItem* ia = *(TileItem**)a; |
1259 | const TileItem* ib = *(TileItem**)b; | 1259 | const TileItem* ib = *(TileItem**)b; |
1260 | return int(ia->x() - ib->x()); | 1260 | return int(ia->x() - ib->x()); |
1261 | } | 1261 | } |
1262 | 1262 | ||
1263 | void Rack::layoutTiles() | 1263 | void Rack::layoutTiles() |
1264 | { | 1264 | { |
1265 | int w = TileItem::bigWidth()+2; | 1265 | int w = TileItem::bigWidth()+2; |
1266 | 1266 | ||
1267 | if ( dragging ) dragging->moveBy(dragging_adj,0); | 1267 | if ( dragging ) dragging->moveBy(dragging_adj,0); |
1268 | qsort(item.data(), n, sizeof(TileItem*), cmp_tileitem); | 1268 | qsort(item.data(), n, sizeof(TileItem*), cmp_tileitem); |
1269 | if ( dragging ) dragging->moveBy(-dragging_adj,0); | 1269 | if ( dragging ) dragging->moveBy(-dragging_adj,0); |
1270 | 1270 | ||
1271 | for (int i=0; i<n ;i++) | 1271 | for (int i=0; i<n ;i++) |
1272 | if ( item[i] == dragging ) { | 1272 | if ( item[i] == dragging ) { |
1273 | item[i]->setZ(1); | 1273 | item[i]->setZ(1); |
1274 | } else { | 1274 | } else { |
1275 | item[i]->move(i*w, 0); | 1275 | item[i]->move(i*w, 0); |
1276 | item[i]->setZ(0); | 1276 | item[i]->setZ(0); |
1277 | } | 1277 | } |
1278 | canvas()->update(); | 1278 | canvas()->update(); |
1279 | } | 1279 | } |
1280 | 1280 | ||
1281 | void Rack::setBlanks(const Tile* bv) | 1281 | void Rack::setBlanks(const Tile* bv) |
1282 | { | 1282 | { |
1283 | for (int j=0; j<n; j++) { | 1283 | for (int j=0; j<n; j++) { |
1284 | Tile tt = item[j]->tile(); | 1284 | Tile tt = item[j]->tile(); |
1285 | if ( tt.isBlank() ) { | 1285 | if ( tt.isBlank() ) { |
1286 | tt.setText(bv->text()); | 1286 | tt.setText(bv->text()); |
1287 | item[j]->setTile(tt); | 1287 | item[j]->setTile(tt); |
1288 | bv++; | 1288 | bv++; |
1289 | } | 1289 | } |
1290 | } | 1290 | } |
1291 | } | 1291 | } |
1292 | 1292 | ||
1293 | bool Rack::arrangeTiles(const Tile** s, int sn) | 1293 | bool Rack::arrangeTiles(const Tile** s, int sn) |
1294 | { | 1294 | { |
1295 | bool could = TRUE; | 1295 | bool could = TRUE; |
1296 | for (int j=0; j<n; j++) { | 1296 | for (int j=0; j<n; j++) { |
1297 | Tile tt = item[j]->tile(); | 1297 | Tile tt = item[j]->tile(); |
1298 | int f=-1; | 1298 | int f=-1; |
1299 | for (int i=0; i<sn && f<0; i++) { | 1299 | for (int i=0; i<sn && f<0; i++) { |
1300 | if (s[i] && *s[i] == tt ) { | 1300 | if (s[i] && *s[i] == tt ) { |
1301 | s[i]=0; | 1301 | s[i]=0; |
1302 | f=i; | 1302 | f=i; |
1303 | } | 1303 | } |
1304 | } | 1304 | } |
1305 | if ( f >= 0 ) { | 1305 | if ( f >= 0 ) { |
1306 | item[j]->move(f-999,0); | 1306 | item[j]->move(f-999,0); |
1307 | } else { | 1307 | } else { |
1308 | could = FALSE; | 1308 | could = FALSE; |
1309 | } | 1309 | } |
1310 | } | 1310 | } |
1311 | layoutTiles(); | 1311 | layoutTiles(); |
1312 | return could; | 1312 | return could; |
1313 | } | 1313 | } |
1314 | 1314 | ||
1315 | void Rack::addTile(const Tile& t) | 1315 | void Rack::addTile(const Tile& t) |
1316 | { | 1316 | { |
1317 | TileItem *i = new TileItem(t,TRUE,canvas()); | 1317 | TileItem *i = new TileItem(t,TRUE,canvas()); |
1318 | i->show(); | 1318 | i->show(); |
1319 | item[n++] = i; | 1319 | item[n++] = i; |
1320 | layoutTiles(); | 1320 | layoutTiles(); |
1321 | } | 1321 | } |
1322 | 1322 | ||
1323 | void Rack::remove(Tile t) | 1323 | void Rack::remove(Tile t) |
1324 | { | 1324 | { |
1325 | for (int i=0; i<n ;i++) | 1325 | for (int i=0; i<n ;i++) |
1326 | if ( item[i]->tile() == t ) { | 1326 | if ( item[i]->tile() == t ) { |
1327 | remove(i); | 1327 | remove(i); |
1328 | return; | 1328 | return; |
1329 | } | 1329 | } |
1330 | } | 1330 | } |
1331 | 1331 | ||
1332 | void Rack::remove(int i) | 1332 | void Rack::remove(int i) |
1333 | { | 1333 | { |
1334 | delete item[i]; | 1334 | delete item[i]; |
1335 | n--; | 1335 | n--; |
1336 | for (;i<n;i++) | 1336 | for (;i<n;i++) |
1337 | item[i]=item[i+1]; | 1337 | item[i]=item[i+1]; |
1338 | layoutTiles(); | 1338 | layoutTiles(); |
1339 | } | 1339 | } |
1340 | 1340 | ||
1341 | void Rack::resizeEvent(QResizeEvent* e) | 1341 | void Rack::resizeEvent(QResizeEvent* e) |
1342 | { | 1342 | { |
1343 | canvas()->resize(width()-frameWidth()*2,height()-frameWidth()*2); | 1343 | canvas()->resize(width()-frameWidth()*2,height()-frameWidth()*2); |
1344 | QCanvasView::resizeEvent(e); | 1344 | QCanvasView::resizeEvent(e); |
1345 | } | 1345 | } |
1346 | 1346 | ||
1347 | void Rack::contentsMousePressEvent(QMouseEvent* e) | 1347 | void Rack::contentsMousePressEvent(QMouseEvent* e) |
1348 | { | 1348 | { |
1349 | if ( computerized() ) | 1349 | if ( computerized() ) |
1350 | return; | 1350 | return; |
1351 | QCanvasItemList list = canvas()->collisions(e->pos()); | 1351 | QCanvasItemList list = canvas()->collisions(e->pos()); |
1352 | if (list.count()) { | 1352 | if (list.count()) { |
1353 | dragging = list.first(); | 1353 | dragging = list.first(); |
1354 | dragstart = e->pos()-QPoint(int(dragging->x()),int(dragging->y())); | 1354 | dragstart = e->pos()-QPoint(int(dragging->x()),int(dragging->y())); |
1355 | } else { | 1355 | } else { |
1356 | dragging = 0; | 1356 | dragging = 0; |
1357 | } | 1357 | } |
1358 | } | 1358 | } |
1359 | 1359 | ||
1360 | void Rack::contentsMouseMoveEvent(QMouseEvent* e) | 1360 | void Rack::contentsMouseMoveEvent(QMouseEvent* e) |
1361 | { | 1361 | { |
1362 | if ( computerized() ) | 1362 | if ( computerized() ) |
1363 | return; | 1363 | return; |
1364 | //int w = TileItem::bigWidth()+2; | 1364 | //int w = TileItem::bigWidth()+2; |
1365 | if ( dragging ) { | 1365 | if ( dragging ) { |
1366 | dragging_adj = TileItem::bigWidth()/2; | 1366 | dragging_adj = TileItem::bigWidth()/2; |
1367 | if ( dragging->x() > e->x()-dragstart.x() ) | 1367 | if ( dragging->x() > e->x()-dragstart.x() ) |
1368 | dragging_adj = -dragging_adj; | 1368 | dragging_adj = -dragging_adj; |
1369 | dragging->move(e->x()-dragstart.x(),0); | 1369 | dragging->move(e->x()-dragstart.x(),0); |
1370 | layoutTiles(); | 1370 | layoutTiles(); |
1371 | } | 1371 | } |
1372 | } | 1372 | } |
1373 | 1373 | ||
1374 | void Rack::contentsMouseReleaseEvent(QMouseEvent* e) | 1374 | void Rack::contentsMouseReleaseEvent(QMouseEvent* e) |
1375 | { | 1375 | { |
1376 | if ( computerized() ) | 1376 | if ( computerized() ) |
1377 | return; | 1377 | return; |
1378 | if ( dragging ) { | 1378 | if ( dragging ) { |
1379 | dragging=0; | 1379 | dragging=0; |
1380 | layoutTiles(); | 1380 | layoutTiles(); |
1381 | } | 1381 | } |
1382 | } | 1382 | } |
1383 | 1383 | ||
1384 | Tile::Tile(const QString& key) | 1384 | Tile::Tile(const QString& key) |
1385 | { | 1385 | { |
1386 | int a=key.find('@'); | 1386 | int a=key.find('@'); |
1387 | txt = key.left(a); | 1387 | txt = key.left(a); |
1388 | val = key.mid(a+1).toInt(); | 1388 | val = key.mid(a+1).toInt(); |
1389 | blank = txt.isEmpty(); | 1389 | blank = txt.isEmpty(); |
1390 | } | 1390 | } |
1391 | 1391 | ||
1392 | QString Tile::key() const | 1392 | QString Tile::key() const |
1393 | { | 1393 | { |
1394 | return txt+"@"+QString::number(val); | 1394 | return txt+"@"+QString::number(val); |
1395 | } | 1395 | } |
1396 | 1396 | ||
1397 | Bag::Bag() | 1397 | Bag::Bag() |
1398 | { | 1398 | { |
1399 | tiles.setAutoDelete(TRUE); | 1399 | tiles.setAutoDelete(TRUE); |
1400 | } | 1400 | } |
1401 | 1401 | ||
1402 | void Bag::writeConfig(Config& cfg) | 1402 | void Bag::writeConfig(Config& cfg) |
1403 | { | 1403 | { |
1404 | QStringList t; | 1404 | QStringList t; |
1405 | for (QListIterator<Tile> it(tiles); it; ++it) | 1405 | for (QListIterator<Tile> it(tiles); it; ++it) |
1406 | t.append((*it)->key()); | 1406 | t.append((*it)->key()); |
1407 | cfg.writeEntry("Tiles",t,';'); | 1407 | cfg.writeEntry("Tiles",t,';'); |
1408 | } | 1408 | } |
1409 | 1409 | ||
1410 | void Bag::readConfig(Config& cfg) | 1410 | void Bag::readConfig(Config& cfg) |
1411 | { | 1411 | { |
1412 | tiles.clear(); | 1412 | tiles.clear(); |
1413 | QStringList t = cfg.readListEntry("Tiles",';'); | 1413 | QStringList t = cfg.readListEntry("Tiles",';'); |
1414 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it ) | 1414 | for (QStringList::ConstIterator it=t.begin(); it!=t.end(); ++it ) |
1415 | add(Tile(*it)); | 1415 | add(Tile(*it)); |
1416 | } | 1416 | } |
1417 | 1417 | ||
1418 | void Bag::add(const Tile& t) | 1418 | void Bag::add(const Tile& t) |
1419 | { | 1419 | { |
1420 | tiles.append(new Tile(t)); | 1420 | tiles.append(new Tile(t)); |
1421 | } | 1421 | } |
1422 | 1422 | ||
1423 | Tile Bag::takeRandom() | 1423 | Tile Bag::takeRandom() |
1424 | { | 1424 | { |
1425 | Tile* rp = tiles.take(random()%tiles.count()); | 1425 | Tile* rp = tiles.take(random()%tiles.count()); |
1426 | Tile r=*rp; | 1426 | Tile r=*rp; |
1427 | return r; | 1427 | return r; |
1428 | } | 1428 | } |
1429 | 1429 | ||
1430 | ScoreInfo::ScoreInfo( QWidget* parent, const char* name, WFlags fl ) : | 1430 | ScoreInfo::ScoreInfo( QWidget* parent, const char* name, WFlags fl ) : |
1431 | QLabel("<P>",parent,name,fl) | 1431 | QLabel("<P>",parent,name,fl) |
1432 | { | 1432 | { |
1433 | score=0; | 1433 | score=0; |
1434 | msgtimer = new QTimer(this); | 1434 | msgtimer = new QTimer(this); |
1435 | connect(msgtimer, SIGNAL(timeout()), this, SLOT(showScores())); | 1435 | connect(msgtimer, SIGNAL(timeout()), this, SLOT(showScores())); |
1436 | setBackgroundMode( PaletteButton ); | 1436 | setBackgroundMode( PaletteButton ); |
1437 | } | 1437 | } |
1438 | 1438 | ||
1439 | ScoreInfo::~ScoreInfo() | 1439 | ScoreInfo::~ScoreInfo() |
1440 | { | 1440 | { |
1441 | if ( score ) delete [] score; | 1441 | if ( score ) delete [] score; |
1442 | } | 1442 | } |
1443 | 1443 | ||
1444 | void ScoreInfo::writeConfig(Config& cfg) | 1444 | void ScoreInfo::writeConfig(Config& cfg) |
1445 | { | 1445 | { |
1446 | QStringList l; | 1446 | QStringList l; |
1447 | for (int i=0; i<(int)names.count(); i++) | 1447 | for (int i=0; i<(int)names.count(); i++) |
1448 | l.append(QString::number(score[i])); | 1448 | l.append(QString::number(score[i])); |
1449 | cfg.writeEntry("Scores",l,';'); | 1449 | cfg.writeEntry("Scores",l,';'); |
1450 | } | 1450 | } |
1451 | 1451 | ||
1452 | void ScoreInfo::readConfig(Config& cfg) | 1452 | void ScoreInfo::readConfig(Config& cfg) |
1453 | { | 1453 | { |
1454 | QStringList l = cfg.readListEntry("Scores",';'); | 1454 | QStringList l = cfg.readListEntry("Scores",';'); |
1455 | int i=0; | 1455 | int i=0; |
1456 | for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it ) | 1456 | for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it ) |
1457 | score[i++]=(*it).toInt(); | 1457 | score[i++]=(*it).toInt(); |
1458 | showScores(); | 1458 | showScores(); |
1459 | } | 1459 | } |
1460 | 1460 | ||
1461 | 1461 | ||
1462 | QSize ScoreInfo::sizeHint() const | 1462 | QSize ScoreInfo::sizeHint() const |
1463 | { | 1463 | { |
1464 | return QSize(QLabel::sizeHint().width(),fontMetrics().height()); | 1464 | return QSize(QLabel::sizeHint().width(),fontMetrics().height()); |
1465 | } | 1465 | } |
1466 | 1466 | ||
1467 | void ScoreInfo::init(const QStringList& namelist) | 1467 | void ScoreInfo::init(const QStringList& namelist) |
1468 | { | 1468 | { |
1469 | names = namelist; | 1469 | names = namelist; |
1470 | if ( score ) delete [] score; | 1470 | if ( score ) delete [] score; |
1471 | score = new int[names.count()]; | 1471 | score = new int[names.count()]; |
1472 | memset(score,0,sizeof(int)*names.count()); | 1472 | memset(score,0,sizeof(int)*names.count()); |
1473 | boldone = -1; | 1473 | boldone = -1; |
1474 | showScores(); | 1474 | showScores(); |
1475 | } | 1475 | } |
1476 | 1476 | ||
1477 | void ScoreInfo::addScore(int player, int change) | 1477 | void ScoreInfo::addScore(int player, int change) |
1478 | { | 1478 | { |
1479 | score[player] += change; | 1479 | score[player] += change; |
1480 | showScores(); | 1480 | showScores(); |
1481 | } | 1481 | } |
1482 | 1482 | ||
1483 | void ScoreInfo::setBoldOne(int b) | 1483 | void ScoreInfo::setBoldOne(int b) |
1484 | { | 1484 | { |
1485 | boldone=b; | 1485 | boldone=b; |
1486 | showScores(); | 1486 | showScores(); |
1487 | } | 1487 | } |
1488 | 1488 | ||
1489 | void ScoreInfo::showScores() | 1489 | void ScoreInfo::showScores() |
1490 | { | 1490 | { |
1491 | QString r="<p>"; | 1491 | QString r="<p>"; |
1492 | int i=0; | 1492 | int i=0; |
1493 | //int spl=(names.count()+1)/2; // 2 lines | 1493 | //int spl=(names.count()+1)/2; // 2 lines |
1494 | for (QStringList::ConstIterator it=names.begin(); it!=names.end(); ) { | 1494 | for (QStringList::ConstIterator it=names.begin(); it!=names.end(); ) { |
1495 | if ( i==boldone ) r += "<b>"; | 1495 | if ( i==boldone ) r += "<b>"; |
1496 | QString n = *it; | 1496 | QString n = *it; |
1497 | n.replace(QRegExp(":.*"),""); | 1497 | n.replace(QRegExp(":.*"),""); |
1498 | r += n; | 1498 | r += n; |
1499 | r += ":"; | 1499 | r += ":"; |
1500 | r += QString::number(score[i]); | 1500 | r += QString::number(score[i]); |
1501 | if ( i==boldone ) r += "</b>"; | 1501 | if ( i==boldone ) r += "</b>"; |
1502 | 1502 | ||
1503 | ++i; | 1503 | ++i; |
1504 | ++it; | 1504 | ++it; |
1505 | if ( it != names.end() ) | 1505 | if ( it != names.end() ) |
1506 | r += " "; | 1506 | r += " "; |
1507 | } | 1507 | } |
1508 | setText(r); | 1508 | setText(r); |
1509 | } | 1509 | } |
1510 | 1510 | ||
1511 | void ScoreInfo::showTemporaryScore(int amount) | 1511 | void ScoreInfo::showTemporaryScore(int amount) |
1512 | { | 1512 | { |
1513 | if ( amount < 0 ) | 1513 | if ( amount < 0 ) |
1514 | setText(tr("<P>Invalid move")); | 1514 | setText(tr("<P>Invalid move")); |
1515 | else | 1515 | else |
1516 | setText(tr("<P>Score: ")+QString::number(amount)); | 1516 | setText(tr("<P>Score: ")+QString::number(amount)); |
1517 | msgtimer->start(3000,TRUE); | 1517 | msgtimer->start(3000,TRUE); |
1518 | } | 1518 | } |
1519 | 1519 | ||
diff --git a/noncore/graphics/drawpad/drawpad.cpp b/noncore/graphics/drawpad/drawpad.cpp index feae237..86a10a5 100644 --- a/noncore/graphics/drawpad/drawpad.cpp +++ b/noncore/graphics/drawpad/drawpad.cpp | |||
@@ -1,668 +1,668 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * DrawPad - a drawing program for Opie Environment * | 3 | * DrawPad - a drawing program for Opie Environment * |
4 | * * | 4 | * * |
5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * | 5 | * (C) 2002 by S. Prud'homme <prudhomme@laposte.net> * |
6 | * * | 6 | * * |
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 | 13 | ||
14 | #include "drawpad.h" | 14 | #include "drawpad.h" |
15 | 15 | ||
16 | #include "drawpadcanvas.h" | 16 | #include "drawpadcanvas.h" |
17 | #include "ellipsetool.h" | 17 | #include "ellipsetool.h" |
18 | #include "erasetool.h" | 18 | #include "erasetool.h" |
19 | #include "exportdialog.h" | 19 | #include "exportdialog.h" |
20 | #include "filledellipsetool.h" | 20 | #include "filledellipsetool.h" |
21 | #include "filledrectangletool.h" | 21 | #include "filledrectangletool.h" |
22 | #include "filltool.h" | 22 | #include "filltool.h" |
23 | #include "importdialog.h" | 23 | #include "importdialog.h" |
24 | #include "linetool.h" | 24 | #include "linetool.h" |
25 | #include "newpagedialog.h" | 25 | #include "newpagedialog.h" |
26 | #include "page.h" | 26 | #include "page.h" |
27 | #include "pageinformationdialog.h" | 27 | #include "pageinformationdialog.h" |
28 | #include "pointtool.h" | 28 | #include "pointtool.h" |
29 | #include "rectangletool.h" | 29 | #include "rectangletool.h" |
30 | #include "texttool.h" | 30 | #include "texttool.h" |
31 | #include "thumbnailview.h" | 31 | #include "thumbnailview.h" |
32 | 32 | ||
33 | #include <opie/colordialog.h> | 33 | #include <opie/colordialog.h> |
34 | #include <opie/colorpopupmenu.h> | 34 | #include <opie/colorpopupmenu.h> |
35 | 35 | ||
36 | #include <qpe/applnk.h> | 36 | #include <qpe/applnk.h> |
37 | #include <qpe/config.h> | 37 | #include <qpe/config.h> |
38 | #include <qpe/global.h> | 38 | #include <qpe/global.h> |
39 | #include <qpe/qpemenubar.h> | 39 | #include <qmenubar.h> |
40 | #include <qpe/qpetoolbar.h> | 40 | #include <qpe/qpetoolbar.h> |
41 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
42 | 42 | ||
43 | #include <qaction.h> | 43 | #include <qaction.h> |
44 | #include <qfile.h> | 44 | #include <qfile.h> |
45 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
46 | #include <qpainter.h> | 46 | #include <qpainter.h> |
47 | #include <qspinbox.h> | 47 | #include <qspinbox.h> |
48 | #include <qtoolbutton.h> | 48 | #include <qtoolbutton.h> |
49 | #include <qtooltip.h> | 49 | #include <qtooltip.h> |
50 | #include <qwhatsthis.h> | 50 | #include <qwhatsthis.h> |
51 | 51 | ||
52 | DrawPad::DrawPad(QWidget* parent, const char* name, WFlags fl ) | 52 | DrawPad::DrawPad(QWidget* parent, const char* name, WFlags fl ) |
53 | : QMainWindow(parent, name, WStyle_ContextHelp) | 53 | : QMainWindow(parent, name, WStyle_ContextHelp) |
54 | { | 54 | { |
55 | // init members | 55 | // init members |
56 | 56 | ||
57 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); | 57 | m_pDrawPadCanvas = new DrawPadCanvas(this, this); |
58 | 58 | ||
59 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateView())); | 59 | connect(m_pDrawPadCanvas, SIGNAL(pagesChanged()), this, SLOT(updateView())); |
60 | 60 | ||
61 | setCentralWidget(m_pDrawPadCanvas); | 61 | setCentralWidget(m_pDrawPadCanvas); |
62 | 62 | ||
63 | // init menu | 63 | // init menu |
64 | 64 | ||
65 | setToolBarsMovable(false); | 65 | setToolBarsMovable(false); |
66 | 66 | ||
67 | QPEToolBar* menuToolBar = new QPEToolBar(this); | 67 | QToolBar* menuToolBar = new QToolBar(this); |
68 | QMenuBar* menuBar = new QMenuBar(menuToolBar); | 68 | QMenuBar* menuBar = new QMenuBar(menuToolBar); |
69 | 69 | ||
70 | QPopupMenu* toolsPopupMenu = new QPopupMenu(menuBar); | 70 | QPopupMenu* toolsPopupMenu = new QPopupMenu(menuBar); |
71 | 71 | ||
72 | QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); | 72 | QAction* deleteAllAction = new QAction(tr("Delete All"), QString::null, 0, this); |
73 | connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll())); | 73 | connect(deleteAllAction, SIGNAL(activated()), this, SLOT(deleteAll())); |
74 | deleteAllAction->addTo(toolsPopupMenu); | 74 | deleteAllAction->addTo(toolsPopupMenu); |
75 | 75 | ||
76 | toolsPopupMenu->insertSeparator(); | 76 | toolsPopupMenu->insertSeparator(); |
77 | 77 | ||
78 | QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); | 78 | QAction* importPageAction = new QAction(tr("Import"), tr("Import..."), 0, this); |
79 | connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); | 79 | connect(importPageAction, SIGNAL(activated()), this, SLOT(importPage())); |
80 | importPageAction->addTo(toolsPopupMenu); | 80 | importPageAction->addTo(toolsPopupMenu); |
81 | 81 | ||
82 | QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); | 82 | QAction* exportPageAction = new QAction(tr("Export"), tr("Export..."), 0, this); |
83 | connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); | 83 | connect(exportPageAction, SIGNAL(activated()), this, SLOT(exportPage())); |
84 | exportPageAction->addTo(toolsPopupMenu); | 84 | exportPageAction->addTo(toolsPopupMenu); |
85 | 85 | ||
86 | toolsPopupMenu->insertSeparator(); | 86 | toolsPopupMenu->insertSeparator(); |
87 | 87 | ||
88 | QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this); | 88 | QAction* thumbnailViewAction = new QAction(tr("Thumbnail View"), tr("Thumbnail View..."), 0, this); |
89 | connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView())); | 89 | connect(thumbnailViewAction, SIGNAL(activated()), this, SLOT(thumbnailView())); |
90 | thumbnailViewAction->addTo(toolsPopupMenu); | 90 | thumbnailViewAction->addTo(toolsPopupMenu); |
91 | 91 | ||
92 | QAction* pageInformationAction = new QAction(tr("Page Information"), tr("Page Information..."), 0, this); | 92 | QAction* pageInformationAction = new QAction(tr("Page Information"), tr("Page Information..."), 0, this); |
93 | connect(pageInformationAction, SIGNAL(activated()), this, SLOT(pageInformation())); | 93 | connect(pageInformationAction, SIGNAL(activated()), this, SLOT(pageInformation())); |
94 | pageInformationAction->addTo(toolsPopupMenu); | 94 | pageInformationAction->addTo(toolsPopupMenu); |
95 | 95 | ||
96 | toolsPopupMenu->insertSeparator(); | 96 | toolsPopupMenu->insertSeparator(); |
97 | 97 | ||
98 | m_pAntiAliasingAction = new QAction(tr("Anti-Aliasing"), QString::null, 0, this); | 98 | m_pAntiAliasingAction = new QAction(tr("Anti-Aliasing"), QString::null, 0, this); |
99 | m_pAntiAliasingAction->setToggleAction(true); | 99 | m_pAntiAliasingAction->setToggleAction(true); |
100 | m_pAntiAliasingAction->addTo(toolsPopupMenu); | 100 | m_pAntiAliasingAction->addTo(toolsPopupMenu); |
101 | 101 | ||
102 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); | 102 | menuBar->insertItem(tr("Tools"), toolsPopupMenu); |
103 | 103 | ||
104 | // init page toolbar | 104 | // init page toolbar |
105 | 105 | ||
106 | QPEToolBar* pageToolBar = new QPEToolBar(this); | 106 | QToolBar* pageToolBar = new QToolBar(this); |
107 | 107 | ||
108 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadPixmap("new"), QString::null, 0, this); | 108 | QAction* newPageAction = new QAction(tr("New Page"), Resource::loadPixmap("new"), QString::null, 0, this); |
109 | connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage())); | 109 | connect(newPageAction, SIGNAL(activated()), this, SLOT(newPage())); |
110 | newPageAction->addTo(pageToolBar); | 110 | newPageAction->addTo(pageToolBar); |
111 | newPageAction->setWhatsThis( tr( "Click here to add a new sheet." ) ); | 111 | newPageAction->setWhatsThis( tr( "Click here to add a new sheet." ) ); |
112 | 112 | ||
113 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadPixmap("drawpad/clear"), QString::null, 0, this); | 113 | QAction* clearPageAction = new QAction(tr("Clear Page"), Resource::loadPixmap("drawpad/clear"), QString::null, 0, this); |
114 | connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage())); | 114 | connect(clearPageAction, SIGNAL(activated()), this, SLOT(clearPage())); |
115 | clearPageAction->addTo(pageToolBar); | 115 | clearPageAction->addTo(pageToolBar); |
116 | clearPageAction->setWhatsThis( tr( "Click here to erase the current sheet." ) ); | 116 | clearPageAction->setWhatsThis( tr( "Click here to erase the current sheet." ) ); |
117 | 117 | ||
118 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadPixmap("trash"), QString::null, 0, this); | 118 | QAction* deletePageAction = new QAction(tr("Delete Page"), Resource::loadPixmap("trash"), QString::null, 0, this); |
119 | connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage())); | 119 | connect(deletePageAction, SIGNAL(activated()), this, SLOT(deletePage())); |
120 | deletePageAction->addTo(pageToolBar); | 120 | deletePageAction->addTo(pageToolBar); |
121 | deletePageAction->setWhatsThis( tr( "Click here to remove the current sheet." ) ); | 121 | deletePageAction->setWhatsThis( tr( "Click here to remove the current sheet." ) ); |
122 | 122 | ||
123 | QPEToolBar* emptyToolBar = new QPEToolBar(this); | 123 | QToolBar* emptyToolBar = new QToolBar(this); |
124 | emptyToolBar->setHorizontalStretchable(true); | 124 | emptyToolBar->setHorizontalStretchable(true); |
125 | 125 | ||
126 | // init navigation toolbar | 126 | // init navigation toolbar |
127 | 127 | ||
128 | QPEToolBar* navigationToolBar = new QPEToolBar(this); | 128 | QToolBar* navigationToolBar = new QToolBar(this); |
129 | 129 | ||
130 | m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("undo"), QString::null, 0, this); | 130 | m_pUndoAction = new QAction(tr("Undo"), Resource::loadIconSet("undo"), QString::null, 0, this); |
131 | connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); | 131 | connect(m_pUndoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(undo())); |
132 | m_pUndoAction->addTo(navigationToolBar); | 132 | m_pUndoAction->addTo(navigationToolBar); |
133 | m_pUndoAction->setWhatsThis( tr( "Click here to undo the last action." ) ); | 133 | m_pUndoAction->setWhatsThis( tr( "Click here to undo the last action." ) ); |
134 | 134 | ||
135 | m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("redo"), QString::null, 0, this); | 135 | m_pRedoAction = new QAction(tr("Redo"), Resource::loadIconSet("redo"), QString::null, 0, this); |
136 | connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); | 136 | connect(m_pRedoAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(redo())); |
137 | m_pRedoAction->addTo(navigationToolBar); | 137 | m_pRedoAction->addTo(navigationToolBar); |
138 | m_pRedoAction->setWhatsThis( tr( "Click here to re-perform the last action." ) ); | 138 | m_pRedoAction->setWhatsThis( tr( "Click here to re-perform the last action." ) ); |
139 | 139 | ||
140 | m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); | 140 | m_pFirstPageAction = new QAction(tr("First Page"), Resource::loadIconSet("fastback"), QString::null, 0, this); |
141 | connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage())); | 141 | connect(m_pFirstPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goFirstPage())); |
142 | m_pFirstPageAction->addTo(navigationToolBar); | 142 | m_pFirstPageAction->addTo(navigationToolBar); |
143 | m_pFirstPageAction->setWhatsThis( tr( "Click here to view the first page." ) ); | 143 | m_pFirstPageAction->setWhatsThis( tr( "Click here to view the first page." ) ); |
144 | 144 | ||
145 | m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); | 145 | m_pPreviousPageAction = new QAction(tr("Previous Page"), Resource::loadIconSet("back"), QString::null, 0, this); |
146 | connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage())); | 146 | connect(m_pPreviousPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goPreviousPage())); |
147 | m_pPreviousPageAction->addTo(navigationToolBar); | 147 | m_pPreviousPageAction->addTo(navigationToolBar); |
148 | m_pPreviousPageAction->setWhatsThis( tr( "Click here to view the previous page." ) ); | 148 | m_pPreviousPageAction->setWhatsThis( tr( "Click here to view the previous page." ) ); |
149 | 149 | ||
150 | m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); | 150 | m_pNextPageAction = new QAction(tr("Next Page"), Resource::loadIconSet("forward"), QString::null, 0, this); |
151 | connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage())); | 151 | connect(m_pNextPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goNextPage())); |
152 | m_pNextPageAction->addTo(navigationToolBar); | 152 | m_pNextPageAction->addTo(navigationToolBar); |
153 | m_pNextPageAction->setWhatsThis( tr( "Click here to view the next page." ) ); | 153 | m_pNextPageAction->setWhatsThis( tr( "Click here to view the next page." ) ); |
154 | 154 | ||
155 | m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); | 155 | m_pLastPageAction = new QAction(tr("Last Page"), Resource::loadIconSet("fastforward"), QString::null, 0, this); |
156 | connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage())); | 156 | connect(m_pLastPageAction, SIGNAL(activated()), m_pDrawPadCanvas, SLOT(goLastPage())); |
157 | m_pLastPageAction->addTo(navigationToolBar); | 157 | m_pLastPageAction->addTo(navigationToolBar); |
158 | m_pLastPageAction->setWhatsThis( tr( "Click here to view the last page." ) ); | 158 | m_pLastPageAction->setWhatsThis( tr( "Click here to view the last page." ) ); |
159 | 159 | ||
160 | // init draw mode toolbar | 160 | // init draw mode toolbar |
161 | 161 | ||
162 | QPEToolBar* drawModeToolBar = new QPEToolBar(this); | 162 | QToolBar* drawModeToolBar = new QToolBar(this); |
163 | 163 | ||
164 | m_pLineToolButton = new QToolButton(drawModeToolBar); | 164 | m_pLineToolButton = new QToolButton(drawModeToolBar); |
165 | m_pLineToolButton->setToggleButton(true); | 165 | m_pLineToolButton->setToggleButton(true); |
166 | QWhatsThis::add( m_pLineToolButton, tr( "Click here to select one of the available tools to draw lines." ) ); | 166 | QWhatsThis::add( m_pLineToolButton, tr( "Click here to select one of the available tools to draw lines." ) ); |
167 | 167 | ||
168 | 168 | ||
169 | QPopupMenu* linePopupMenu = new QPopupMenu(m_pLineToolButton); | 169 | QPopupMenu* linePopupMenu = new QPopupMenu(m_pLineToolButton); |
170 | 170 | ||
171 | m_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadPixmap("drawpad/point"), "", 0, this); | 171 | m_pPointToolAction = new QAction(tr("Draw Point"), Resource::loadPixmap("drawpad/point"), "", 0, this); |
172 | connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool())); | 172 | connect(m_pPointToolAction, SIGNAL(activated()), this, SLOT(setPointTool())); |
173 | m_pPointToolAction->addTo(linePopupMenu); | 173 | m_pPointToolAction->addTo(linePopupMenu); |
174 | 174 | ||
175 | m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadPixmap("drawpad/line"), "", 0, this); | 175 | m_pLineToolAction = new QAction(tr("Draw Line"), Resource::loadPixmap("drawpad/line"), "", 0, this); |
176 | connect(m_pLineToolAction, SIGNAL(activated()), this, SLOT(setLineTool())); | 176 | connect(m_pLineToolAction, SIGNAL(activated()), this, SLOT(setLineTool())); |
177 | m_pLineToolAction->addTo(linePopupMenu); | 177 | m_pLineToolAction->addTo(linePopupMenu); |
178 | 178 | ||
179 | m_pLineToolButton->setPopup(linePopupMenu); | 179 | m_pLineToolButton->setPopup(linePopupMenu); |
180 | m_pLineToolButton->setPopupDelay(0); | 180 | m_pLineToolButton->setPopupDelay(0); |
181 | 181 | ||
182 | m_pRectangleToolButton = new QToolButton(drawModeToolBar); | 182 | m_pRectangleToolButton = new QToolButton(drawModeToolBar); |
183 | m_pRectangleToolButton->setToggleButton(true); | 183 | m_pRectangleToolButton->setToggleButton(true); |
184 | QWhatsThis::add( m_pRectangleToolButton, tr( "Click here to select one of the available tools to draw rectangles." ) ); | 184 | QWhatsThis::add( m_pRectangleToolButton, tr( "Click here to select one of the available tools to draw rectangles." ) ); |
185 | 185 | ||
186 | QPopupMenu* rectanglePopupMenu = new QPopupMenu(m_pRectangleToolButton); | 186 | QPopupMenu* rectanglePopupMenu = new QPopupMenu(m_pRectangleToolButton); |
187 | 187 | ||
188 | m_pRectangleToolAction = new QAction(tr("Draw Rectangle"), Resource::loadPixmap("drawpad/rectangle"), "", 0, this); | 188 | m_pRectangleToolAction = new QAction(tr("Draw Rectangle"), Resource::loadPixmap("drawpad/rectangle"), "", 0, this); |
189 | connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool())); | 189 | connect(m_pRectangleToolAction, SIGNAL(activated()), this, SLOT(setRectangleTool())); |
190 | m_pRectangleToolAction->addTo(rectanglePopupMenu); | 190 | m_pRectangleToolAction->addTo(rectanglePopupMenu); |
191 | 191 | ||
192 | m_pFilledRectangleToolAction = new QAction(tr("Draw Filled Rectangle"), Resource::loadPixmap("drawpad/filledrectangle"), "", 0, this); | 192 | m_pFilledRectangleToolAction = new QAction(tr("Draw Filled Rectangle"), Resource::loadPixmap("drawpad/filledrectangle"), "", 0, this); |
193 | connect(m_pFilledRectangleToolAction, SIGNAL(activated()), this, SLOT(setFilledRectangleTool())); | 193 | connect(m_pFilledRectangleToolAction, SIGNAL(activated()), this, SLOT(setFilledRectangleTool())); |
194 | m_pFilledRectangleToolAction->addTo(rectanglePopupMenu); | 194 | m_pFilledRectangleToolAction->addTo(rectanglePopupMenu); |
195 | 195 | ||
196 | m_pRectangleToolButton->setPopup(rectanglePopupMenu); | 196 | m_pRectangleToolButton->setPopup(rectanglePopupMenu); |
197 | m_pRectangleToolButton->setPopupDelay(0); | 197 | m_pRectangleToolButton->setPopupDelay(0); |
198 | 198 | ||
199 | m_pEllipseToolButton = new QToolButton(drawModeToolBar); | 199 | m_pEllipseToolButton = new QToolButton(drawModeToolBar); |
200 | m_pEllipseToolButton->setToggleButton(true); | 200 | m_pEllipseToolButton->setToggleButton(true); |
201 | QWhatsThis::add( m_pEllipseToolButton, tr( "Click here to select one of the available tools to draw ellipses." ) ); | 201 | QWhatsThis::add( m_pEllipseToolButton, tr( "Click here to select one of the available tools to draw ellipses." ) ); |
202 | 202 | ||
203 | QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton); | 203 | QPopupMenu* ellipsePopupMenu = new QPopupMenu(m_pEllipseToolButton); |
204 | 204 | ||
205 | m_pEllipseToolAction = new QAction(tr("Draw Ellipse"), Resource::loadPixmap("drawpad/ellipse"), "", 0, this); | 205 | m_pEllipseToolAction = new QAction(tr("Draw Ellipse"), Resource::loadPixmap("drawpad/ellipse"), "", 0, this); |
206 | connect(m_pEllipseToolAction, SIGNAL(activated()), this, SLOT(setEllipseTool())); | 206 | connect(m_pEllipseToolAction, SIGNAL(activated()), this, SLOT(setEllipseTool())); |
207 | m_pEllipseToolAction->addTo(ellipsePopupMenu); | 207 | m_pEllipseToolAction->addTo(ellipsePopupMenu); |
208 | 208 | ||
209 | m_pFilledEllipseToolAction = new QAction(tr("Draw Filled Ellipse"), Resource::loadPixmap("drawpad/filledellipse"), "", 0, this); | 209 | m_pFilledEllipseToolAction = new QAction(tr("Draw Filled Ellipse"), Resource::loadPixmap("drawpad/filledellipse"), "", 0, this); |
210 | connect(m_pFilledEllipseToolAction, SIGNAL(activated()), this, SLOT(setFilledEllipseTool())); | 210 | connect(m_pFilledEllipseToolAction, SIGNAL(activated()), this, SLOT(setFilledEllipseTool())); |
211 | m_pFilledEllipseToolAction->addTo(ellipsePopupMenu); | 211 | m_pFilledEllipseToolAction->addTo(ellipsePopupMenu); |
212 | 212 | ||
213 | m_pEllipseToolButton->setPopup(ellipsePopupMenu); | 213 | m_pEllipseToolButton->setPopup(ellipsePopupMenu); |
214 | m_pEllipseToolButton->setPopupDelay(0); | 214 | m_pEllipseToolButton->setPopupDelay(0); |
215 | 215 | ||
216 | m_pTextToolAction = new QAction(tr("Insert Text"), Resource::loadPixmap("drawpad/text"), QString::null, 0, this); | 216 | m_pTextToolAction = new QAction(tr("Insert Text"), Resource::loadPixmap("drawpad/text"), QString::null, 0, this); |
217 | m_pTextToolAction->setToggleAction(true); | 217 | m_pTextToolAction->setToggleAction(true); |
218 | connect(m_pTextToolAction, SIGNAL(activated()), this, SLOT(setTextTool())); | 218 | connect(m_pTextToolAction, SIGNAL(activated()), this, SLOT(setTextTool())); |
219 | m_pTextToolAction->addTo(drawModeToolBar); | 219 | m_pTextToolAction->addTo(drawModeToolBar); |
220 | m_pTextToolAction->setWhatsThis( tr( "Click here to select the text drawing tool." ) ); | 220 | m_pTextToolAction->setWhatsThis( tr( "Click here to select the text drawing tool." ) ); |
221 | 221 | ||
222 | m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadPixmap("drawpad/fill"), QString::null, 0, this); | 222 | m_pFillToolAction = new QAction(tr("Fill Region"), Resource::loadPixmap("drawpad/fill"), QString::null, 0, this); |
223 | m_pFillToolAction->setToggleAction(true); | 223 | m_pFillToolAction->setToggleAction(true); |
224 | connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool())); | 224 | connect(m_pFillToolAction, SIGNAL(activated()), this, SLOT(setFillTool())); |
225 | m_pFillToolAction->addTo(drawModeToolBar); | 225 | m_pFillToolAction->addTo(drawModeToolBar); |
226 | m_pFillToolAction->setWhatsThis( tr( "Click here to select the fill tool." ) ); | 226 | m_pFillToolAction->setWhatsThis( tr( "Click here to select the fill tool." ) ); |
227 | 227 | ||
228 | m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadPixmap("drawpad/erase"), QString::null, 0, this); | 228 | m_pEraseToolAction = new QAction(tr("Erase Point"), Resource::loadPixmap("drawpad/erase"), QString::null, 0, this); |
229 | m_pEraseToolAction->setToggleAction(true); | 229 | m_pEraseToolAction->setToggleAction(true); |
230 | connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool())); | 230 | connect(m_pEraseToolAction, SIGNAL(activated()), this, SLOT(setEraseTool())); |
231 | m_pEraseToolAction->addTo(drawModeToolBar); | 231 | m_pEraseToolAction->addTo(drawModeToolBar); |
232 | m_pEraseToolAction->setWhatsThis( tr( "Click here to select the eraser tool." ) ); | 232 | m_pEraseToolAction->setWhatsThis( tr( "Click here to select the eraser tool." ) ); |
233 | 233 | ||
234 | m_pTool = 0; | 234 | m_pTool = 0; |
235 | setRectangleTool(); | 235 | setRectangleTool(); |
236 | setEllipseTool(); | 236 | setEllipseTool(); |
237 | setPointTool(); | 237 | setPointTool(); |
238 | 238 | ||
239 | emptyToolBar = new QPEToolBar(this); | 239 | emptyToolBar = new QToolBar(this); |
240 | emptyToolBar->setHorizontalStretchable(true); | 240 | emptyToolBar->setHorizontalStretchable(true); |
241 | emptyToolBar->addSeparator(); | 241 | emptyToolBar->addSeparator(); |
242 | 242 | ||
243 | // init draw parameters toolbar | 243 | // init draw parameters toolbar |
244 | 244 | ||
245 | QPEToolBar* drawParametersToolBar = new QPEToolBar(this); | 245 | QToolBar* drawParametersToolBar = new QToolBar(this); |
246 | 246 | ||
247 | m_pPenWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); | 247 | m_pPenWidthSpinBox = new QSpinBox(1, 9, 1, drawParametersToolBar); |
248 | connect(m_pPenWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); | 248 | connect(m_pPenWidthSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changePenWidth(int))); |
249 | 249 | ||
250 | QToolTip::add(m_pPenWidthSpinBox, tr("Pen Width")); | 250 | QToolTip::add(m_pPenWidthSpinBox, tr("Pen Width")); |
251 | m_pPenWidthSpinBox->setValue(1); | 251 | m_pPenWidthSpinBox->setValue(1); |
252 | m_pPenWidthSpinBox->setFocusPolicy(QWidget::NoFocus); | 252 | m_pPenWidthSpinBox->setFocusPolicy(QWidget::NoFocus); |
253 | QWhatsThis::add( m_pPenWidthSpinBox, tr( "Click here to select the width of the drawing pen." ) ); | 253 | QWhatsThis::add( m_pPenWidthSpinBox, tr( "Click here to select the width of the drawing pen." ) ); |
254 | 254 | ||
255 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); | 255 | m_pPenColorToolButton = new QToolButton(drawParametersToolBar); |
256 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor")); | 256 | m_pPenColorToolButton->setPixmap(Resource::loadPixmap("drawpad/pencolor")); |
257 | QWhatsThis::add( m_pPenColorToolButton, tr( "Click here to select the color used when drawing." ) ); | 257 | QWhatsThis::add( m_pPenColorToolButton, tr( "Click here to select the color used when drawing." ) ); |
258 | 258 | ||
259 | OColorPopupMenu* penColorPopupMenu = new OColorPopupMenu(Qt::black, m_pPenColorToolButton); | 259 | OColorPopupMenu* penColorPopupMenu = new OColorPopupMenu(Qt::black, m_pPenColorToolButton); |
260 | connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); | 260 | connect(penColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changePenColor(const QColor&))); |
261 | 261 | ||
262 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); | 262 | QToolTip::add(m_pPenColorToolButton, tr("Pen Color")); |
263 | m_pPenColorToolButton->setPopup(penColorPopupMenu); | 263 | m_pPenColorToolButton->setPopup(penColorPopupMenu); |
264 | m_pPenColorToolButton->setPopupDelay(0); | 264 | m_pPenColorToolButton->setPopupDelay(0); |
265 | 265 | ||
266 | changePenColor(Qt::black); | 266 | changePenColor(Qt::black); |
267 | 267 | ||
268 | m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); | 268 | m_pBrushColorToolButton = new QToolButton(drawParametersToolBar); |
269 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor")); | 269 | m_pBrushColorToolButton->setPixmap(Resource::loadPixmap("drawpad/brushcolor")); |
270 | QWhatsThis::add( m_pBrushColorToolButton, tr( "Click here to select the color used when filling in areas." ) ); | 270 | QWhatsThis::add( m_pBrushColorToolButton, tr( "Click here to select the color used when filling in areas." ) ); |
271 | 271 | ||
272 | OColorPopupMenu* brushColorPopupMenu = new OColorPopupMenu(Qt::white, m_pBrushColorToolButton); | 272 | OColorPopupMenu* brushColorPopupMenu = new OColorPopupMenu(Qt::white, m_pBrushColorToolButton); |
273 | connect(brushColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); | 273 | connect(brushColorPopupMenu, SIGNAL(colorSelected(const QColor&)), this, SLOT(changeBrushColor(const QColor&))); |
274 | 274 | ||
275 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); | 275 | QToolTip::add(m_pBrushColorToolButton, tr("Fill Color")); |
276 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); | 276 | m_pBrushColorToolButton->setPopup(brushColorPopupMenu); |
277 | m_pBrushColorToolButton->setPopupDelay(0); | 277 | m_pBrushColorToolButton->setPopupDelay(0); |
278 | 278 | ||
279 | changeBrushColor(Qt::white); | 279 | changeBrushColor(Qt::white); |
280 | 280 | ||
281 | finishStartup(); | 281 | finishStartup(); |
282 | } | 282 | } |
283 | 283 | ||
284 | 284 | ||
285 | void DrawPad::finishStartup() | 285 | void DrawPad::finishStartup() |
286 | { | 286 | { |
287 | // init pages | 287 | // init pages |
288 | 288 | ||
289 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 289 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
290 | 290 | ||
291 | if (file.open(IO_ReadOnly)) { | 291 | if (file.open(IO_ReadOnly)) { |
292 | m_pDrawPadCanvas->load(&file); | 292 | m_pDrawPadCanvas->load(&file); |
293 | file.close(); | 293 | file.close(); |
294 | } else { | 294 | } else { |
295 | m_pDrawPadCanvas->initialPage(); | 295 | m_pDrawPadCanvas->initialPage(); |
296 | } | 296 | } |
297 | 297 | ||
298 | loadConfig(); | 298 | loadConfig(); |
299 | 299 | ||
300 | } | 300 | } |
301 | 301 | ||
302 | DrawPad::~DrawPad() | 302 | DrawPad::~DrawPad() |
303 | { | 303 | { |
304 | saveConfig(); | 304 | saveConfig(); |
305 | 305 | ||
306 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); | 306 | QFile file(Global::applicationFileName("drawpad", "drawpad.xml")); |
307 | 307 | ||
308 | if (file.open(IO_WriteOnly)) { | 308 | if (file.open(IO_WriteOnly)) { |
309 | m_pDrawPadCanvas->save(&file); | 309 | m_pDrawPadCanvas->save(&file); |
310 | file.close(); | 310 | file.close(); |
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | bool DrawPad::antiAliasing() | 314 | bool DrawPad::antiAliasing() |
315 | { | 315 | { |
316 | return (m_pAntiAliasingAction->isOn()); | 316 | return (m_pAntiAliasingAction->isOn()); |
317 | } | 317 | } |
318 | 318 | ||
319 | void DrawPad::newPage() | 319 | void DrawPad::newPage() |
320 | { | 320 | { |
321 | QRect rect = m_pDrawPadCanvas->contentsRect(); | 321 | QRect rect = m_pDrawPadCanvas->contentsRect(); |
322 | 322 | ||
323 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this); | 323 | NewPageDialog newPageDialog(rect.width(), rect.height(), m_pen.color(), m_brush.color(), this); |
324 | 324 | ||
325 | if (newPageDialog.exec() == QDialog::Accepted) { | 325 | if (newPageDialog.exec() == QDialog::Accepted) { |
326 | m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(), | 326 | m_pDrawPadCanvas->newPage(newPageDialog.selectedTitle(), newPageDialog.selectedWidth(), |
327 | newPageDialog.selectedHeight(), newPageDialog.selectedColor()); | 327 | newPageDialog.selectedHeight(), newPageDialog.selectedColor()); |
328 | } | 328 | } |
329 | } | 329 | } |
330 | 330 | ||
331 | void DrawPad::clearPage() | 331 | void DrawPad::clearPage() |
332 | { | 332 | { |
333 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), | 333 | QMessageBox messageBox(tr("Clear Page"), tr("Do you want to clear\nthe current page?"), |
334 | QMessageBox::Information, QMessageBox::Yes, | 334 | QMessageBox::Information, QMessageBox::Yes, |
335 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 335 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
336 | QMessageBox::NoButton, this); | 336 | QMessageBox::NoButton, this); |
337 | 337 | ||
338 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | 338 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); |
339 | messageBox.setButtonText(QMessageBox::No, tr("No")); | 339 | messageBox.setButtonText(QMessageBox::No, tr("No")); |
340 | 340 | ||
341 | if (messageBox.exec() == QMessageBox::Yes) { | 341 | if (messageBox.exec() == QMessageBox::Yes) { |
342 | m_pDrawPadCanvas->clearPage(); | 342 | m_pDrawPadCanvas->clearPage(); |
343 | } | 343 | } |
344 | } | 344 | } |
345 | 345 | ||
346 | void DrawPad::deletePage() | 346 | void DrawPad::deletePage() |
347 | { | 347 | { |
348 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), | 348 | QMessageBox messageBox(tr("Delete Page"), tr("Do you want to delete\nthe current page?"), |
349 | QMessageBox::Information, QMessageBox::Yes, | 349 | QMessageBox::Information, QMessageBox::Yes, |
350 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 350 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
351 | QMessageBox::NoButton, this); | 351 | QMessageBox::NoButton, this); |
352 | 352 | ||
353 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | 353 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); |
354 | messageBox.setButtonText(QMessageBox::No, tr("No")); | 354 | messageBox.setButtonText(QMessageBox::No, tr("No")); |
355 | 355 | ||
356 | if (messageBox.exec() == QMessageBox::Yes) { | 356 | if (messageBox.exec() == QMessageBox::Yes) { |
357 | m_pDrawPadCanvas->deletePage(); | 357 | m_pDrawPadCanvas->deletePage(); |
358 | } | 358 | } |
359 | } | 359 | } |
360 | 360 | ||
361 | void DrawPad::setPointTool() | 361 | void DrawPad::setPointTool() |
362 | { | 362 | { |
363 | if (m_pTool) { | 363 | if (m_pTool) { |
364 | delete m_pTool; | 364 | delete m_pTool; |
365 | } | 365 | } |
366 | 366 | ||
367 | m_pTool = new PointTool(this, m_pDrawPadCanvas); | 367 | m_pTool = new PointTool(this, m_pDrawPadCanvas); |
368 | 368 | ||
369 | m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet()); | 369 | m_pLineToolButton->setIconSet(m_pPointToolAction->iconSet()); |
370 | QToolTip::add(m_pLineToolButton, m_pPointToolAction->text()); | 370 | QToolTip::add(m_pLineToolButton, m_pPointToolAction->text()); |
371 | 371 | ||
372 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); | 372 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); |
373 | connect(m_pLineToolButton, SIGNAL(clicked()), m_pPointToolAction, SIGNAL(activated())); | 373 | connect(m_pLineToolButton, SIGNAL(clicked()), m_pPointToolAction, SIGNAL(activated())); |
374 | 374 | ||
375 | m_pLineToolButton->setOn(true); | 375 | m_pLineToolButton->setOn(true); |
376 | m_pRectangleToolButton->setOn(false); | 376 | m_pRectangleToolButton->setOn(false); |
377 | m_pEllipseToolButton->setOn(false); | 377 | m_pEllipseToolButton->setOn(false); |
378 | m_pTextToolAction->setOn(false); | 378 | m_pTextToolAction->setOn(false); |
379 | m_pFillToolAction->setOn(false); | 379 | m_pFillToolAction->setOn(false); |
380 | m_pEraseToolAction->setOn(false); | 380 | m_pEraseToolAction->setOn(false); |
381 | } | 381 | } |
382 | 382 | ||
383 | void DrawPad::setLineTool() | 383 | void DrawPad::setLineTool() |
384 | { | 384 | { |
385 | if (m_pTool) { | 385 | if (m_pTool) { |
386 | delete m_pTool; | 386 | delete m_pTool; |
387 | } | 387 | } |
388 | 388 | ||
389 | m_pTool = new LineTool(this, m_pDrawPadCanvas); | 389 | m_pTool = new LineTool(this, m_pDrawPadCanvas); |
390 | 390 | ||
391 | m_pLineToolButton->setIconSet(m_pLineToolAction->iconSet()); | 391 | m_pLineToolButton->setIconSet(m_pLineToolAction->iconSet()); |
392 | QToolTip::add(m_pLineToolButton, m_pLineToolAction->text()); | 392 | QToolTip::add(m_pLineToolButton, m_pLineToolAction->text()); |
393 | 393 | ||
394 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); | 394 | disconnect(m_pLineToolButton, SIGNAL(clicked()), 0, 0); |
395 | connect(m_pLineToolButton, SIGNAL(clicked()), m_pLineToolAction, SIGNAL(activated())); | 395 | connect(m_pLineToolButton, SIGNAL(clicked()), m_pLineToolAction, SIGNAL(activated())); |
396 | 396 | ||
397 | m_pLineToolButton->setOn(true); | 397 | m_pLineToolButton->setOn(true); |
398 | m_pRectangleToolButton->setOn(false); | 398 | m_pRectangleToolButton->setOn(false); |
399 | m_pEllipseToolButton->setOn(false); | 399 | m_pEllipseToolButton->setOn(false); |
400 | m_pTextToolAction->setOn(false); | 400 | m_pTextToolAction->setOn(false); |
401 | m_pFillToolAction->setOn(false); | 401 | m_pFillToolAction->setOn(false); |
402 | m_pEraseToolAction->setOn(false); | 402 | m_pEraseToolAction->setOn(false); |
403 | } | 403 | } |
404 | 404 | ||
405 | void DrawPad::setRectangleTool() | 405 | void DrawPad::setRectangleTool() |
406 | { | 406 | { |
407 | if (m_pTool) { | 407 | if (m_pTool) { |
408 | delete m_pTool; | 408 | delete m_pTool; |
409 | } | 409 | } |
410 | 410 | ||
411 | m_pTool = new RectangleTool(this, m_pDrawPadCanvas); | 411 | m_pTool = new RectangleTool(this, m_pDrawPadCanvas); |
412 | 412 | ||
413 | m_pRectangleToolButton->setIconSet(m_pRectangleToolAction->iconSet()); | 413 | m_pRectangleToolButton->setIconSet(m_pRectangleToolAction->iconSet()); |
414 | QToolTip::add(m_pRectangleToolButton, m_pRectangleToolAction->text()); | 414 | QToolTip::add(m_pRectangleToolButton, m_pRectangleToolAction->text()); |
415 | 415 | ||
416 | disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); | 416 | disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); |
417 | connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pRectangleToolAction, SIGNAL(activated())); | 417 | connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pRectangleToolAction, SIGNAL(activated())); |
418 | 418 | ||
419 | m_pLineToolButton->setOn(false); | 419 | m_pLineToolButton->setOn(false); |
420 | m_pRectangleToolButton->setOn(true); | 420 | m_pRectangleToolButton->setOn(true); |
421 | m_pEllipseToolButton->setOn(false); | 421 | m_pEllipseToolButton->setOn(false); |
422 | m_pTextToolAction->setOn(false); | 422 | m_pTextToolAction->setOn(false); |
423 | m_pFillToolAction->setOn(false); | 423 | m_pFillToolAction->setOn(false); |
424 | m_pEraseToolAction->setOn(false); | 424 | m_pEraseToolAction->setOn(false); |
425 | } | 425 | } |
426 | 426 | ||
427 | void DrawPad::setFilledRectangleTool() | 427 | void DrawPad::setFilledRectangleTool() |
428 | { | 428 | { |
429 | if (m_pTool) { | 429 | if (m_pTool) { |
430 | delete m_pTool; | 430 | delete m_pTool; |
431 | } | 431 | } |
432 | 432 | ||
433 | m_pTool = new FilledRectangleTool(this, m_pDrawPadCanvas); | 433 | m_pTool = new FilledRectangleTool(this, m_pDrawPadCanvas); |
434 | 434 | ||
435 | m_pRectangleToolButton->setIconSet(m_pFilledRectangleToolAction->iconSet()); | 435 | m_pRectangleToolButton->setIconSet(m_pFilledRectangleToolAction->iconSet()); |
436 | QToolTip::add(m_pRectangleToolButton, m_pFilledRectangleToolAction->text()); | 436 | QToolTip::add(m_pRectangleToolButton, m_pFilledRectangleToolAction->text()); |
437 | 437 | ||
438 | disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); | 438 | disconnect(m_pRectangleToolButton, SIGNAL(clicked()), 0, 0); |
439 | connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pFilledRectangleToolAction, SIGNAL(activated())); | 439 | connect(m_pRectangleToolButton, SIGNAL(clicked()), m_pFilledRectangleToolAction, SIGNAL(activated())); |
440 | 440 | ||
441 | m_pLineToolButton->setOn(false); | 441 | m_pLineToolButton->setOn(false); |
442 | m_pRectangleToolButton->setOn(true); | 442 | m_pRectangleToolButton->setOn(true); |
443 | m_pEllipseToolButton->setOn(false); | 443 | m_pEllipseToolButton->setOn(false); |
444 | m_pTextToolAction->setOn(false); | 444 | m_pTextToolAction->setOn(false); |
445 | m_pFillToolAction->setOn(false); | 445 | m_pFillToolAction->setOn(false); |
446 | m_pEraseToolAction->setOn(false); | 446 | m_pEraseToolAction->setOn(false); |
447 | } | 447 | } |
448 | 448 | ||
449 | void DrawPad::setEllipseTool() | 449 | void DrawPad::setEllipseTool() |
450 | { | 450 | { |
451 | if (m_pTool) { | 451 | if (m_pTool) { |
452 | delete m_pTool; | 452 | delete m_pTool; |
453 | } | 453 | } |
454 | 454 | ||
455 | m_pTool = new EllipseTool(this, m_pDrawPadCanvas); | 455 | m_pTool = new EllipseTool(this, m_pDrawPadCanvas); |
456 | 456 | ||
457 | m_pEllipseToolButton->setIconSet(m_pEllipseToolAction->iconSet()); | 457 | m_pEllipseToolButton->setIconSet(m_pEllipseToolAction->iconSet()); |
458 | QToolTip::add(m_pEllipseToolButton, m_pEllipseToolAction->text()); | 458 | QToolTip::add(m_pEllipseToolButton, m_pEllipseToolAction->text()); |
459 | 459 | ||
460 | disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); | 460 | disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); |
461 | connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pEllipseToolAction, SIGNAL(activated())); | 461 | connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pEllipseToolAction, SIGNAL(activated())); |
462 | 462 | ||
463 | m_pLineToolButton->setOn(false); | 463 | m_pLineToolButton->setOn(false); |
464 | m_pRectangleToolButton->setOn(false); | 464 | m_pRectangleToolButton->setOn(false); |
465 | m_pEllipseToolButton->setOn(true); | 465 | m_pEllipseToolButton->setOn(true); |
466 | m_pTextToolAction->setOn(false); | 466 | m_pTextToolAction->setOn(false); |
467 | m_pFillToolAction->setOn(false); | 467 | m_pFillToolAction->setOn(false); |
468 | m_pEraseToolAction->setOn(false); | 468 | m_pEraseToolAction->setOn(false); |
469 | } | 469 | } |
470 | 470 | ||
471 | void DrawPad::setFilledEllipseTool() | 471 | void DrawPad::setFilledEllipseTool() |
472 | { | 472 | { |
473 | if (m_pTool) { | 473 | if (m_pTool) { |
474 | delete m_pTool; | 474 | delete m_pTool; |
475 | } | 475 | } |
476 | 476 | ||
477 | m_pTool = new FilledEllipseTool(this, m_pDrawPadCanvas); | 477 | m_pTool = new FilledEllipseTool(this, m_pDrawPadCanvas); |
478 | 478 | ||
479 | m_pEllipseToolButton->setIconSet(m_pFilledEllipseToolAction->iconSet()); | 479 | m_pEllipseToolButton->setIconSet(m_pFilledEllipseToolAction->iconSet()); |
480 | QToolTip::add(m_pEllipseToolButton, m_pFilledEllipseToolAction->text()); | 480 | QToolTip::add(m_pEllipseToolButton, m_pFilledEllipseToolAction->text()); |
481 | 481 | ||
482 | disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); | 482 | disconnect(m_pEllipseToolButton, SIGNAL(clicked()), 0, 0); |
483 | connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pFilledEllipseToolAction, SIGNAL(activated())); | 483 | connect(m_pEllipseToolButton, SIGNAL(clicked()), m_pFilledEllipseToolAction, SIGNAL(activated())); |
484 | 484 | ||
485 | m_pLineToolButton->setOn(false); | 485 | m_pLineToolButton->setOn(false); |
486 | m_pRectangleToolButton->setOn(false); | 486 | m_pRectangleToolButton->setOn(false); |
487 | m_pEllipseToolButton->setOn(true); | 487 | m_pEllipseToolButton->setOn(true); |
488 | m_pTextToolAction->setOn(false); | 488 | m_pTextToolAction->setOn(false); |
489 | m_pFillToolAction->setOn(false); | 489 | m_pFillToolAction->setOn(false); |
490 | m_pEraseToolAction->setOn(false); | 490 | m_pEraseToolAction->setOn(false); |
491 | } | 491 | } |
492 | 492 | ||
493 | void DrawPad::setTextTool() | 493 | void DrawPad::setTextTool() |
494 | { | 494 | { |
495 | if (m_pTool) { | 495 | if (m_pTool) { |
496 | delete m_pTool; | 496 | delete m_pTool; |
497 | } | 497 | } |
498 | 498 | ||
499 | m_pTool = new TextTool(this, m_pDrawPadCanvas); | 499 | m_pTool = new TextTool(this, m_pDrawPadCanvas); |
500 | 500 | ||
501 | m_pLineToolButton->setOn(false); | 501 | m_pLineToolButton->setOn(false); |
502 | m_pRectangleToolButton->setOn(false); | 502 | m_pRectangleToolButton->setOn(false); |
503 | m_pEllipseToolButton->setOn(false); | 503 | m_pEllipseToolButton->setOn(false); |
504 | m_pTextToolAction->setOn(true); | 504 | m_pTextToolAction->setOn(true); |
505 | m_pFillToolAction->setOn(false); | 505 | m_pFillToolAction->setOn(false); |
506 | m_pEraseToolAction->setOn(false); | 506 | m_pEraseToolAction->setOn(false); |
507 | } | 507 | } |
508 | 508 | ||
509 | void DrawPad::setFillTool() | 509 | void DrawPad::setFillTool() |
510 | { | 510 | { |
511 | if (m_pTool) { | 511 | if (m_pTool) { |
512 | delete m_pTool; | 512 | delete m_pTool; |
513 | } | 513 | } |
514 | 514 | ||
515 | m_pTool = new FillTool(this, m_pDrawPadCanvas); | 515 | m_pTool = new FillTool(this, m_pDrawPadCanvas); |
516 | 516 | ||
517 | m_pLineToolButton->setOn(false); | 517 | m_pLineToolButton->setOn(false); |
518 | m_pRectangleToolButton->setOn(false); | 518 | m_pRectangleToolButton->setOn(false); |
519 | m_pEllipseToolButton->setOn(false); | 519 | m_pEllipseToolButton->setOn(false); |
520 | m_pTextToolAction->setOn(false); | 520 | m_pTextToolAction->setOn(false); |
521 | m_pFillToolAction->setOn(true); | 521 | m_pFillToolAction->setOn(true); |
522 | m_pEraseToolAction->setOn(false); | 522 | m_pEraseToolAction->setOn(false); |
523 | } | 523 | } |
524 | 524 | ||
525 | void DrawPad::setEraseTool() | 525 | void DrawPad::setEraseTool() |
526 | { | 526 | { |
527 | if (m_pTool) { | 527 | if (m_pTool) { |
528 | delete m_pTool; | 528 | delete m_pTool; |
529 | } | 529 | } |
530 | 530 | ||
531 | m_pTool = new EraseTool(this, m_pDrawPadCanvas); | 531 | m_pTool = new EraseTool(this, m_pDrawPadCanvas); |
532 | 532 | ||
533 | m_pLineToolButton->setOn(false); | 533 | m_pLineToolButton->setOn(false); |
534 | m_pRectangleToolButton->setOn(false); | 534 | m_pRectangleToolButton->setOn(false); |
535 | m_pEllipseToolButton->setOn(false); | 535 | m_pEllipseToolButton->setOn(false); |
536 | m_pTextToolAction->setOn(false); | 536 | m_pTextToolAction->setOn(false); |
537 | m_pFillToolAction->setOn(false); | 537 | m_pFillToolAction->setOn(false); |
538 | m_pEraseToolAction->setOn(true); | 538 | m_pEraseToolAction->setOn(true); |
539 | } | 539 | } |
540 | 540 | ||
541 | void DrawPad::changePenWidth(int value) | 541 | void DrawPad::changePenWidth(int value) |
542 | { | 542 | { |
543 | m_pen.setWidth(value); | 543 | m_pen.setWidth(value); |
544 | } | 544 | } |
545 | 545 | ||
546 | void DrawPad::changePenColor(const QColor& color) | 546 | void DrawPad::changePenColor(const QColor& color) |
547 | { | 547 | { |
548 | m_pen.setColor(color); | 548 | m_pen.setColor(color); |
549 | 549 | ||
550 | QPainter painter; | 550 | QPainter painter; |
551 | painter.begin(m_pPenColorToolButton->pixmap()); | 551 | painter.begin(m_pPenColorToolButton->pixmap()); |
552 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); | 552 | painter.fillRect(QRect(0, 12, 14, 2), m_pen.color()); |
553 | painter.end(); | 553 | painter.end(); |
554 | 554 | ||
555 | m_pPenColorToolButton->popup()->hide(); | 555 | m_pPenColorToolButton->popup()->hide(); |
556 | } | 556 | } |
557 | 557 | ||
558 | void DrawPad::changeBrushColor(const QColor& color) | 558 | void DrawPad::changeBrushColor(const QColor& color) |
559 | { | 559 | { |
560 | m_brush = QBrush(color); | 560 | m_brush = QBrush(color); |
561 | 561 | ||
562 | QPainter painter; | 562 | QPainter painter; |
563 | painter.begin(m_pBrushColorToolButton->pixmap()); | 563 | painter.begin(m_pBrushColorToolButton->pixmap()); |
564 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); | 564 | painter.fillRect(QRect(0, 12, 14, 2), m_brush.color()); |
565 | painter.end(); | 565 | painter.end(); |
566 | 566 | ||
567 | m_pBrushColorToolButton->popup()->hide(); | 567 | m_pBrushColorToolButton->popup()->hide(); |
568 | } | 568 | } |
569 | 569 | ||
570 | void DrawPad::updateView() | 570 | void DrawPad::updateView() |
571 | { | 571 | { |
572 | uint pagePosition = m_pDrawPadCanvas->pagePosition(); | 572 | uint pagePosition = m_pDrawPadCanvas->pagePosition(); |
573 | uint pageCount = m_pDrawPadCanvas->pageCount(); | 573 | uint pageCount = m_pDrawPadCanvas->pageCount(); |
574 | 574 | ||
575 | setCaption( tr( "DrawPad - Page %1/%2" ).arg( pagePosition ).arg( pageCount ) ); | 575 | setCaption( tr( "DrawPad - Page %1/%2" ).arg( pagePosition ).arg( pageCount ) ); |
576 | 576 | ||
577 | m_pUndoAction->setEnabled(m_pDrawPadCanvas->currentPage()->undoEnabled()); | 577 | m_pUndoAction->setEnabled(m_pDrawPadCanvas->currentPage()->undoEnabled()); |
578 | m_pRedoAction->setEnabled(m_pDrawPadCanvas->currentPage()->redoEnabled()); | 578 | m_pRedoAction->setEnabled(m_pDrawPadCanvas->currentPage()->redoEnabled()); |
579 | 579 | ||
580 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 580 | m_pFirstPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |
581 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); | 581 | m_pPreviousPageAction->setEnabled(m_pDrawPadCanvas->goPreviousPageEnabled()); |
582 | m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | 582 | m_pNextPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); |
583 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); | 583 | m_pLastPageAction->setEnabled(m_pDrawPadCanvas->goNextPageEnabled()); |
584 | } | 584 | } |
585 | 585 | ||
586 | void DrawPad::deleteAll() | 586 | void DrawPad::deleteAll() |
587 | { | 587 | { |
588 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), | 588 | QMessageBox messageBox(tr("Delete All"), tr("Do you want to delete\nall the pages?"), |
589 | QMessageBox::Information, QMessageBox::Yes, | 589 | QMessageBox::Information, QMessageBox::Yes, |
590 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, | 590 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default, |
591 | QMessageBox::NoButton, this); | 591 | QMessageBox::NoButton, this); |
592 | 592 | ||
593 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); | 593 | messageBox.setButtonText(QMessageBox::Yes, tr("Yes")); |
594 | messageBox.setButtonText(QMessageBox::No, tr("No")); | 594 | messageBox.setButtonText(QMessageBox::No, tr("No")); |
595 | 595 | ||
596 | if (messageBox.exec() == QMessageBox::Yes) { | 596 | if (messageBox.exec() == QMessageBox::Yes) { |
597 | m_pDrawPadCanvas->deleteAll(); | 597 | m_pDrawPadCanvas->deleteAll(); |
598 | } | 598 | } |
599 | } | 599 | } |
600 | 600 | ||
601 | void DrawPad::importPage() | 601 | void DrawPad::importPage() |
602 | { | 602 | { |
603 | ImportDialog importDialog(this); | 603 | ImportDialog importDialog(this); |
604 | 604 | ||
605 | importDialog.showMaximized(); | 605 | importDialog.showMaximized(); |
606 | 606 | ||
607 | if (importDialog.exec() == QDialog::Accepted) { | 607 | if (importDialog.exec() == QDialog::Accepted) { |
608 | const DocLnk* docLnk = importDialog.selected(); | 608 | const DocLnk* docLnk = importDialog.selected(); |
609 | 609 | ||
610 | if (docLnk) { | 610 | if (docLnk) { |
611 | m_pDrawPadCanvas->importPage(docLnk->file()); | 611 | m_pDrawPadCanvas->importPage(docLnk->file()); |
612 | delete docLnk; | 612 | delete docLnk; |
613 | } | 613 | } |
614 | } | 614 | } |
615 | } | 615 | } |
616 | 616 | ||
617 | void DrawPad::exportPage() | 617 | void DrawPad::exportPage() |
618 | { | 618 | { |
619 | ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); | 619 | ExportDialog exportDialog(m_pDrawPadCanvas->pagePosition(), m_pDrawPadCanvas->pageCount(), this); |
620 | 620 | ||
621 | exportDialog.showMaximized(); | 621 | exportDialog.showMaximized(); |
622 | 622 | ||
623 | if (exportDialog.exec() == QDialog::Accepted) { | 623 | if (exportDialog.exec() == QDialog::Accepted) { |
624 | m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), | 624 | m_pDrawPadCanvas->exportPage(exportDialog.selectedFromPage(), exportDialog.selectedToPage(), |
625 | exportDialog.selectedName(), exportDialog.selectedFormat()); | 625 | exportDialog.selectedName(), exportDialog.selectedFormat()); |
626 | } | 626 | } |
627 | } | 627 | } |
628 | 628 | ||
629 | void DrawPad::thumbnailView() | 629 | void DrawPad::thumbnailView() |
630 | { | 630 | { |
631 | ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this); | 631 | ThumbnailView thumbnailView(this, m_pDrawPadCanvas, this); |
632 | 632 | ||
633 | thumbnailView.showMaximized(); | 633 | thumbnailView.showMaximized(); |
634 | thumbnailView.exec(); | 634 | thumbnailView.exec(); |
635 | } | 635 | } |
636 | 636 | ||
637 | void DrawPad::pageInformation() | 637 | void DrawPad::pageInformation() |
638 | { | 638 | { |
639 | PageInformationDialog pageInformationDialog(m_pDrawPadCanvas->currentPage()); | 639 | PageInformationDialog pageInformationDialog(m_pDrawPadCanvas->currentPage()); |
640 | 640 | ||
641 | if (pageInformationDialog.exec() == QDialog::Accepted) { | 641 | if (pageInformationDialog.exec() == QDialog::Accepted) { |
642 | m_pDrawPadCanvas->currentPage()->setTitle(pageInformationDialog.selectedTitle()); | 642 | m_pDrawPadCanvas->currentPage()->setTitle(pageInformationDialog.selectedTitle()); |
643 | } | 643 | } |
644 | } | 644 | } |
645 | 645 | ||
646 | void DrawPad::loadConfig() | 646 | void DrawPad::loadConfig() |
647 | { | 647 | { |
648 | Config config("drawpad"); | 648 | Config config("drawpad"); |
649 | config.setGroup("General"); | 649 | config.setGroup("General"); |
650 | 650 | ||
651 | m_pAntiAliasingAction->setOn(config.readBoolEntry("AntiAliasing", false)); | 651 | m_pAntiAliasingAction->setOn(config.readBoolEntry("AntiAliasing", false)); |
652 | m_pPenWidthSpinBox->setValue(config.readNumEntry("PenWidth", 1)); | 652 | m_pPenWidthSpinBox->setValue(config.readNumEntry("PenWidth", 1)); |
653 | changePenColor(QColor(config.readEntry("PenColor", Qt::black.name()))); | 653 | changePenColor(QColor(config.readEntry("PenColor", Qt::black.name()))); |
654 | changeBrushColor(QColor(config.readEntry("BrushColor", Qt::white.name()))); | 654 | changeBrushColor(QColor(config.readEntry("BrushColor", Qt::white.name()))); |
655 | m_pDrawPadCanvas->selectPage(config.readNumEntry("PagePosition", 1)); | 655 | m_pDrawPadCanvas->selectPage(config.readNumEntry("PagePosition", 1)); |
656 | } | 656 | } |
657 | 657 | ||
658 | void DrawPad::saveConfig() | 658 | void DrawPad::saveConfig() |
659 | { | 659 | { |
660 | Config config("drawpad"); | 660 | Config config("drawpad"); |
661 | config.setGroup("General"); | 661 | config.setGroup("General"); |
662 | 662 | ||
663 | config.writeEntry("PagePosition", (int)m_pDrawPadCanvas->pagePosition()); | 663 | config.writeEntry("PagePosition", (int)m_pDrawPadCanvas->pagePosition()); |
664 | config.writeEntry("AntiAliasing", antiAliasing()); | 664 | config.writeEntry("AntiAliasing", antiAliasing()); |
665 | config.writeEntry("PenWidth", (int)m_pen.width()); | 665 | config.writeEntry("PenWidth", (int)m_pen.width()); |
666 | config.writeEntry("PenColor", m_pen.color().name()); | 666 | config.writeEntry("PenColor", m_pen.color().name()); |
667 | config.writeEntry("BrushColor", m_brush.color().name()); | 667 | config.writeEntry("BrushColor", m_brush.color().name()); |
668 | } | 668 | } |
diff --git a/noncore/multimedia/opierec/helpwindow.cpp b/noncore/multimedia/opierec/helpwindow.cpp index 1ab6510..a3b29fa 100644 --- a/noncore/multimedia/opierec/helpwindow.cpp +++ b/noncore/multimedia/opierec/helpwindow.cpp | |||
@@ -1,196 +1,196 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 4 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. |
5 | ** | 5 | ** |
6 | ** This file is part of an example program for Qt. This example | 6 | ** This file is part of an example program for Qt. This example |
7 | ** program may be used, distributed and modified without limitation. | 7 | ** program may be used, distributed and modified without limitation. |
8 | ** | 8 | ** |
9 | *****************************************************************************/ | 9 | *****************************************************************************/ |
10 | 10 | ||
11 | #include "helpwindow.h" | 11 | #include "helpwindow.h" |
12 | #include <qlayout.h> | 12 | #include <qlayout.h> |
13 | 13 | ||
14 | #include <qpe/qpetoolbar.h> | 14 | #include <qpe/qpetoolbar.h> |
15 | #include <qpe/resource.h> | 15 | #include <qpe/resource.h> |
16 | 16 | ||
17 | #include <qaction.h> | 17 | #include <qaction.h> |
18 | #include <qmenubar.h> | 18 | #include <qmenubar.h> |
19 | 19 | ||
20 | #include <ctype.h> | 20 | #include <ctype.h> |
21 | 21 | ||
22 | HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* parent, const char *name ) | 22 | HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* parent, const char *name ) |
23 | : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL() | 23 | : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL() |
24 | { | 24 | { |
25 | QGridLayout *layout = new QGridLayout( this ); | 25 | QGridLayout *layout = new QGridLayout( this ); |
26 | layout->setSpacing( 2); | 26 | layout->setSpacing( 2); |
27 | layout->setMargin( 2); | 27 | layout->setMargin( 2); |
28 | qDebug(_path); | 28 | qDebug(_path); |
29 | browser = new QTextBrowser( this ); | 29 | browser = new QTextBrowser( this ); |
30 | QStringList Strlist; | 30 | QStringList Strlist; |
31 | Strlist.append( home_); | 31 | Strlist.append( home_); |
32 | browser->mimeSourceFactory()->setFilePath( Strlist ); | 32 | browser->mimeSourceFactory()->setFilePath( Strlist ); |
33 | browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 33 | browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
34 | 34 | ||
35 | connect( browser, SIGNAL( textChanged() ), this, SLOT( textChanged() ) ); | 35 | connect( browser, SIGNAL( textChanged() ), this, SLOT( textChanged() ) ); |
36 | 36 | ||
37 | if ( !home_.isEmpty() ) | 37 | if ( !home_.isEmpty() ) |
38 | browser->setSource( home_ ); | 38 | browser->setSource( home_ ); |
39 | QPEToolBar *toolbar = new QPEToolBar( this ); | 39 | QToolBar *toolbar = new QToolBar( this ); |
40 | 40 | ||
41 | QAction *a = new QAction( tr( "Backward" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); | 41 | QAction *a = new QAction( tr( "Backward" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); |
42 | connect( a, SIGNAL( activated() ), browser, SLOT( backward() ) ); | 42 | connect( a, SIGNAL( activated() ), browser, SLOT( backward() ) ); |
43 | a->addTo( toolbar ); | 43 | a->addTo( toolbar ); |
44 | 44 | ||
45 | a = new QAction( tr( "Forward" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); | 45 | a = new QAction( tr( "Forward" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 ); |
46 | connect( a, SIGNAL( activated() ), browser, SLOT( forward() ) ); | 46 | connect( a, SIGNAL( activated() ), browser, SLOT( forward() ) ); |
47 | a->addTo( toolbar ); | 47 | a->addTo( toolbar ); |
48 | 48 | ||
49 | 49 | ||
50 | layout->addMultiCellWidget( toolbar, 0, 0, 0, 0); | 50 | layout->addMultiCellWidget( toolbar, 0, 0, 0, 0); |
51 | 51 | ||
52 | layout->addMultiCellWidget( browser, 1, 2, 0, 2); | 52 | layout->addMultiCellWidget( browser, 1, 2, 0, 2); |
53 | 53 | ||
54 | browser->setFocus(); | 54 | browser->setFocus(); |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | void HelpWindow::setBackwardAvailable( bool b) | 58 | void HelpWindow::setBackwardAvailable( bool b) |
59 | { | 59 | { |
60 | menuBar()->setItemEnabled( backwardId, b); | 60 | menuBar()->setItemEnabled( backwardId, b); |
61 | } | 61 | } |
62 | 62 | ||
63 | void HelpWindow::setForwardAvailable( bool b) | 63 | void HelpWindow::setForwardAvailable( bool b) |
64 | { | 64 | { |
65 | menuBar()->setItemEnabled( forwardId, b); | 65 | menuBar()->setItemEnabled( forwardId, b); |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
69 | void HelpWindow::textChanged() | 69 | void HelpWindow::textChanged() |
70 | { | 70 | { |
71 | if ( browser->documentTitle().isNull() ) { | 71 | if ( browser->documentTitle().isNull() ) { |
72 | setCaption( "QpeRec - Helpviewer - " + browser->context() ); | 72 | setCaption( "QpeRec - Helpviewer - " + browser->context() ); |
73 | selectedURL = browser->context(); | 73 | selectedURL = browser->context(); |
74 | } | 74 | } |
75 | else { | 75 | else { |
76 | setCaption( "QpeRec - Helpviewer - " + browser->documentTitle() ) ; | 76 | setCaption( "QpeRec - Helpviewer - " + browser->documentTitle() ) ; |
77 | selectedURL = browser->documentTitle(); | 77 | selectedURL = browser->documentTitle(); |
78 | } | 78 | } |
79 | 79 | ||
80 | // if ( !selectedURL.isEmpty() && pathCombo ) { | 80 | // if ( !selectedURL.isEmpty() && pathCombo ) { |
81 | // bool exists = FALSE; | 81 | // bool exists = FALSE; |
82 | // int i; | 82 | // int i; |
83 | // for ( i = 0; i < pathCombo->count(); ++i ) { | 83 | // for ( i = 0; i < pathCombo->count(); ++i ) { |
84 | // if ( pathCombo->text( i ) == selectedURL ) { | 84 | // if ( pathCombo->text( i ) == selectedURL ) { |
85 | // exists = TRUE; | 85 | // exists = TRUE; |
86 | // break; | 86 | // break; |
87 | // } | 87 | // } |
88 | // } | 88 | // } |
89 | // if ( !exists ) { | 89 | // if ( !exists ) { |
90 | // pathCombo->insertItem( selectedURL, 0 ); | 90 | // pathCombo->insertItem( selectedURL, 0 ); |
91 | // pathCombo->setCurrentItem( 0 ); | 91 | // pathCombo->setCurrentItem( 0 ); |
92 | // mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; | 92 | // mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; |
93 | // } else | 93 | // } else |
94 | // pathCombo->setCurrentItem( i ); | 94 | // pathCombo->setCurrentItem( i ); |
95 | // selectedURL = QString::null; | 95 | // selectedURL = QString::null; |
96 | // } | 96 | // } |
97 | } | 97 | } |
98 | 98 | ||
99 | HelpWindow::~HelpWindow() | 99 | HelpWindow::~HelpWindow() |
100 | { | 100 | { |
101 | history.clear(); | 101 | history.clear(); |
102 | QMap<int, QString>::Iterator it = mHistory.begin(); | 102 | QMap<int, QString>::Iterator it = mHistory.begin(); |
103 | for ( ; it != mHistory.end(); ++it ) | 103 | for ( ; it != mHistory.end(); ++it ) |
104 | history.append( *it ); | 104 | history.append( *it ); |
105 | 105 | ||
106 | QFile f( QDir::currentDirPath() + "/.history" ); | 106 | QFile f( QDir::currentDirPath() + "/.history" ); |
107 | f.open( IO_WriteOnly ); | 107 | f.open( IO_WriteOnly ); |
108 | QDataStream s( &f ); | 108 | QDataStream s( &f ); |
109 | s << history; | 109 | s << history; |
110 | f.close(); | 110 | f.close(); |
111 | 111 | ||
112 | bookmarks.clear(); | 112 | bookmarks.clear(); |
113 | QMap<int, QString>::Iterator it2 = mBookmarks.begin(); | 113 | QMap<int, QString>::Iterator it2 = mBookmarks.begin(); |
114 | for ( ; it2 != mBookmarks.end(); ++it2 ) | 114 | for ( ; it2 != mBookmarks.end(); ++it2 ) |
115 | bookmarks.append( *it2 ); | 115 | bookmarks.append( *it2 ); |
116 | 116 | ||
117 | QFile f2( QDir::currentDirPath() + "/.bookmarks" ); | 117 | QFile f2( QDir::currentDirPath() + "/.bookmarks" ); |
118 | f2.open( IO_WriteOnly ); | 118 | f2.open( IO_WriteOnly ); |
119 | QDataStream s2( &f2 ); | 119 | QDataStream s2( &f2 ); |
120 | s2 << bookmarks; | 120 | s2 << bookmarks; |
121 | f2.close(); | 121 | f2.close(); |
122 | } | 122 | } |
123 | 123 | ||
124 | void HelpWindow::openFile() | 124 | void HelpWindow::openFile() |
125 | { | 125 | { |
126 | #ifndef QT_NO_FILEDIALOG | 126 | #ifndef QT_NO_FILEDIALOG |
127 | #endif | 127 | #endif |
128 | } | 128 | } |
129 | 129 | ||
130 | void HelpWindow::newWindow() | 130 | void HelpWindow::newWindow() |
131 | { | 131 | { |
132 | ( new HelpWindow(browser->source(), "qbrowser") )->show(); | 132 | ( new HelpWindow(browser->source(), "qbrowser") )->show(); |
133 | } | 133 | } |
134 | 134 | ||
135 | void HelpWindow::print() | 135 | void HelpWindow::print() |
136 | { | 136 | { |
137 | #ifndef QT_NO_PRINTER | 137 | #ifndef QT_NO_PRINTER |
138 | #endif | 138 | #endif |
139 | } | 139 | } |
140 | 140 | ||
141 | void HelpWindow::pathSelected( const QString &_path ) | 141 | void HelpWindow::pathSelected( const QString &_path ) |
142 | { | 142 | { |
143 | browser->setSource( _path ); | 143 | browser->setSource( _path ); |
144 | QMap<int, QString>::Iterator it = mHistory.begin(); | 144 | QMap<int, QString>::Iterator it = mHistory.begin(); |
145 | bool exists = FALSE; | 145 | bool exists = FALSE; |
146 | for ( ; it != mHistory.end(); ++it ) { | 146 | for ( ; it != mHistory.end(); ++it ) { |
147 | if ( *it == _path ) { | 147 | if ( *it == _path ) { |
148 | exists = TRUE; | 148 | exists = TRUE; |
149 | break; | 149 | break; |
150 | } | 150 | } |
151 | } | 151 | } |
152 | if ( !exists ) | 152 | if ( !exists ) |
153 | mHistory[ hist->insertItem( _path ) ] = _path; | 153 | mHistory[ hist->insertItem( _path ) ] = _path; |
154 | } | 154 | } |
155 | 155 | ||
156 | void HelpWindow::readHistory() | 156 | void HelpWindow::readHistory() |
157 | { | 157 | { |
158 | if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { | 158 | if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { |
159 | QFile f( QDir::currentDirPath() + "/.history" ); | 159 | QFile f( QDir::currentDirPath() + "/.history" ); |
160 | f.open( IO_ReadOnly ); | 160 | f.open( IO_ReadOnly ); |
161 | QDataStream s( &f ); | 161 | QDataStream s( &f ); |
162 | s >> history; | 162 | s >> history; |
163 | f.close(); | 163 | f.close(); |
164 | while ( history.count() > 20 ) | 164 | while ( history.count() > 20 ) |
165 | history.remove( history.begin() ); | 165 | history.remove( history.begin() ); |
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | void HelpWindow::readBookmarks() | 169 | void HelpWindow::readBookmarks() |
170 | { | 170 | { |
171 | if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { | 171 | if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { |
172 | QFile f( QDir::currentDirPath() + "/.bookmarks" ); | 172 | QFile f( QDir::currentDirPath() + "/.bookmarks" ); |
173 | f.open( IO_ReadOnly ); | 173 | f.open( IO_ReadOnly ); |
174 | QDataStream s( &f ); | 174 | QDataStream s( &f ); |
175 | s >> bookmarks; | 175 | s >> bookmarks; |
176 | f.close(); | 176 | f.close(); |
177 | } | 177 | } |
178 | } | 178 | } |
179 | 179 | ||
180 | void HelpWindow::histChosen( int i ) | 180 | void HelpWindow::histChosen( int i ) |
181 | { | 181 | { |
182 | if ( mHistory.contains( i ) ) | 182 | if ( mHistory.contains( i ) ) |
183 | browser->setSource( mHistory[ i ] ); | 183 | browser->setSource( mHistory[ i ] ); |
184 | } | 184 | } |
185 | 185 | ||
186 | void HelpWindow::bookmChosen( int i ) | 186 | void HelpWindow::bookmChosen( int i ) |
187 | { | 187 | { |
188 | if ( mBookmarks.contains( i ) ) | 188 | if ( mBookmarks.contains( i ) ) |
189 | browser->setSource( mBookmarks[ i ] ); | 189 | browser->setSource( mBookmarks[ i ] ); |
190 | } | 190 | } |
191 | 191 | ||
192 | void HelpWindow::addBookmark() | 192 | void HelpWindow::addBookmark() |
193 | { | 193 | { |
194 | mBookmarks[ bookm->insertItem( caption() ) ] = caption(); | 194 | mBookmarks[ bookm->insertItem( caption() ) ] = caption(); |
195 | } | 195 | } |
196 | 196 | ||
diff --git a/noncore/multimedia/showimg/showimg.cpp b/noncore/multimedia/showimg/showimg.cpp index b7754f7..ba76e57 100644 --- a/noncore/multimedia/showimg/showimg.cpp +++ b/noncore/multimedia/showimg/showimg.cpp | |||
@@ -1,1251 +1,1251 @@ | |||
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 | // Full-screen and rotation options contributed by Robert Wittams <robert@wittams.com> | 22 | // Full-screen and rotation options contributed by Robert Wittams <robert@wittams.com> |
23 | // | 23 | // |
24 | 24 | ||
25 | #include "showimg.h" | 25 | #include "showimg.h" |
26 | #include "ImageFileSelector.h" | 26 | #include "ImageFileSelector.h" |
27 | #include "settingsdialog.h" | 27 | #include "settingsdialog.h" |
28 | 28 | ||
29 | 29 | ||
30 | #include <opie/ofiledialog.h> | 30 | #include <opie/ofiledialog.h> |
31 | 31 | ||
32 | #include <qpe/qpeapplication.h> | 32 | #include <qpe/qpeapplication.h> |
33 | #include <qpe/config.h> | 33 | #include <qpe/config.h> |
34 | #include <qpe/resource.h> | 34 | #include <qpe/resource.h> |
35 | #include <qpe/fileselector.h> | 35 | #include <qpe/fileselector.h> |
36 | #include <qpe/applnk.h> | 36 | #include <qpe/applnk.h> |
37 | #include <qfileinfo.h> | 37 | #include <qfileinfo.h> |
38 | #include <math.h> | 38 | #include <math.h> |
39 | #include <qpe/qpemenubar.h> | 39 | #include <qmenubar.h> |
40 | #include <qwidgetstack.h> | 40 | #include <qwidgetstack.h> |
41 | #include <qpe/qpetoolbar.h> | 41 | #include <qpe/qpetoolbar.h> |
42 | #include <qaction.h> | 42 | #include <qaction.h> |
43 | #include <qfiledialog.h> | 43 | #include <qfiledialog.h> |
44 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
45 | #include <qpopupmenu.h> | 45 | #include <qpopupmenu.h> |
46 | #include <qscrollview.h> | 46 | #include <qscrollview.h> |
47 | #include <qlabel.h> | 47 | #include <qlabel.h> |
48 | #include <qpainter.h> | 48 | #include <qpainter.h> |
49 | #include <qkeycode.h> | 49 | #include <qkeycode.h> |
50 | #include <qapplication.h> | 50 | #include <qapplication.h> |
51 | #include <qclipboard.h> | 51 | #include <qclipboard.h> |
52 | #include <qtimer.h> | 52 | #include <qtimer.h> |
53 | #include <qspinbox.h> | 53 | #include <qspinbox.h> |
54 | 54 | ||
55 | 55 | ||
56 | 56 | ||
57 | ControlsDialog::ControlsDialog(const QString &caption,QImage image,int *brightness,QWidget *parent) | 57 | ControlsDialog::ControlsDialog(const QString &caption,QImage image,int *brightness,QWidget *parent) |
58 | : QDialog(parent,0,true) | 58 | : QDialog(parent,0,true) |
59 | { | 59 | { |
60 | setCaption(caption); | 60 | setCaption(caption); |
61 | 61 | ||
62 | if ( parent ) { | 62 | if ( parent ) { |
63 | setPalette(parent->palette()); | 63 | setPalette(parent->palette()); |
64 | } | 64 | } |
65 | 65 | ||
66 | b=brightness; | 66 | b=brightness; |
67 | img=image; | 67 | img=image; |
68 | 68 | ||
69 | setMinimumSize(140,80); | 69 | setMinimumSize(140,80); |
70 | 70 | ||
71 | QGridLayout *gl= new QGridLayout(this,2,2,4,4); | 71 | QGridLayout *gl= new QGridLayout(this,2,2,4,4); |
72 | 72 | ||
73 | pixmap =new ImageWidget(this);; | 73 | pixmap =new ImageWidget(this);; |
74 | QPixmap pm; | 74 | QPixmap pm; |
75 | pm.convertFromImage(img); | 75 | pm.convertFromImage(img); |
76 | pixmap->setPixmap(pm); | 76 | pixmap->setPixmap(pm); |
77 | pixmap->setMinimumSize(pm.width(),pm.height()); | 77 | pixmap->setMinimumSize(pm.width(),pm.height()); |
78 | gl->addMultiCellWidget(pixmap,0,0,0,2,AlignCenter); | 78 | gl->addMultiCellWidget(pixmap,0,0,0,2,AlignCenter); |
79 | QLabel *l=new QLabel(tr("Brightness")+":",this); | 79 | QLabel *l=new QLabel(tr("Brightness")+":",this); |
80 | gl->addWidget(l,1,0,AlignLeft); | 80 | gl->addWidget(l,1,0,AlignLeft); |
81 | spb=new QSpinBox(-100,100,2,this); | 81 | spb=new QSpinBox(-100,100,2,this); |
82 | gl->addWidget(spb,1,1,AlignRight); | 82 | gl->addWidget(spb,1,1,AlignRight); |
83 | 83 | ||
84 | spb->setValue(0); | 84 | spb->setValue(0); |
85 | 85 | ||
86 | connect(spb,SIGNAL(valueChanged(int)),this, SLOT(bValueChanged(int))); | 86 | connect(spb,SIGNAL(valueChanged(int)),this, SLOT(bValueChanged(int))); |
87 | 87 | ||
88 | } | 88 | } |
89 | 89 | ||
90 | void ControlsDialog::bValueChanged(int value) | 90 | void ControlsDialog::bValueChanged(int value) |
91 | { | 91 | { |
92 | QImage nImage=img; | 92 | QImage nImage=img; |
93 | nImage.detach(); | 93 | nImage.detach(); |
94 | ImageViewer::intensity(nImage, (float)value/100); | 94 | ImageViewer::intensity(nImage, (float)value/100); |
95 | QPixmap pm; | 95 | QPixmap pm; |
96 | pm.convertFromImage(nImage); | 96 | pm.convertFromImage(nImage); |
97 | pixmap->setPixmap(pm); | 97 | pixmap->setPixmap(pm); |
98 | pixmap->repaint(false); | 98 | pixmap->repaint(false); |
99 | 99 | ||
100 | 100 | ||
101 | } | 101 | } |
102 | 102 | ||
103 | void ControlsDialog::accept() | 103 | void ControlsDialog::accept() |
104 | { | 104 | { |
105 | *b=spb->value(); | 105 | *b=spb->value(); |
106 | done(1); | 106 | done(1); |
107 | } | 107 | } |
108 | 108 | ||
109 | //=========================================================================== | 109 | //=========================================================================== |
110 | 110 | ||
111 | InfoDialog::InfoDialog(const QString &caption, const QStringList text,QWidget *parent) | 111 | InfoDialog::InfoDialog(const QString &caption, const QStringList text,QWidget *parent) |
112 | : QDialog(parent,0,true) | 112 | : QDialog(parent,0,true) |
113 | { | 113 | { |
114 | setCaption(caption); | 114 | setCaption(caption); |
115 | 115 | ||
116 | if ( parent ) | 116 | if ( parent ) |
117 | { | 117 | { |
118 | setPalette(parent->palette()); | 118 | setPalette(parent->palette()); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | 122 | ||
123 | QString labels[]={ tr("File Name"),tr("Format"),tr("File Size"),tr("Size"),tr("Colors"),tr("Alpha") }; | 123 | QString labels[]={ tr("File Name"),tr("Format"),tr("File Size"),tr("Size"),tr("Colors"),tr("Alpha") }; |
124 | 124 | ||
125 | setMinimumSize(180,80); | 125 | setMinimumSize(180,80); |
126 | int num=ImageViewer::LAST+1; | 126 | int num=ImageViewer::LAST+1; |
127 | if ( text[ImageViewer::ALPHA].isEmpty() ) | 127 | if ( text[ImageViewer::ALPHA].isEmpty() ) |
128 | num--; | 128 | num--; |
129 | QGridLayout *gl= new QGridLayout(this,num,2,4,2); | 129 | QGridLayout *gl= new QGridLayout(this,num,2,4,2); |
130 | QLabel *l; | 130 | QLabel *l; |
131 | int count=0; | 131 | int count=0; |
132 | for ( int i=0;i<num;i++ ) | 132 | for ( int i=0;i<num;i++ ) |
133 | { | 133 | { |
134 | if ( i==1 ) | 134 | if ( i==1 ) |
135 | { | 135 | { |
136 | QFrame *frm=new QFrame(this); | 136 | QFrame *frm=new QFrame(this); |
137 | frm->setFrameStyle(QFrame::HLine|QFrame::Sunken); | 137 | frm->setFrameStyle(QFrame::HLine|QFrame::Sunken); |
138 | gl->addMultiCellWidget(frm,i,i,0,1); | 138 | gl->addMultiCellWidget(frm,i,i,0,1); |
139 | } | 139 | } |
140 | else | 140 | else |
141 | { | 141 | { |
142 | l=new QLabel( tr( labels[count] )+":",this); | 142 | l=new QLabel( tr( labels[count] )+":",this); |
143 | gl->addWidget(l,i,0,AlignLeft); | 143 | gl->addWidget(l,i,0,AlignLeft); |
144 | l=new QLabel(text[count],this); | 144 | l=new QLabel(text[count],this); |
145 | gl->addWidget(l,i,1,AlignRight); | 145 | gl->addWidget(l,i,1,AlignRight); |
146 | count++; | 146 | count++; |
147 | } | 147 | } |
148 | 148 | ||
149 | } | 149 | } |
150 | 150 | ||
151 | } | 151 | } |
152 | 152 | ||
153 | void InfoDialog::displayInfo(const QString &caption, const QStringList text, QWidget *parent) | 153 | void InfoDialog::displayInfo(const QString &caption, const QStringList text, QWidget *parent) |
154 | { | 154 | { |
155 | InfoDialog *dlg=new InfoDialog(caption,text,parent); | 155 | InfoDialog *dlg=new InfoDialog(caption,text,parent); |
156 | dlg->exec(); | 156 | dlg->exec(); |
157 | delete dlg; | 157 | delete dlg; |
158 | } | 158 | } |
159 | 159 | ||
160 | //=========================================================================== | 160 | //=========================================================================== |
161 | 161 | ||
162 | 162 | ||
163 | ImagePane::ImagePane( QWidget *parent ) : QWidget( parent ) | 163 | ImagePane::ImagePane( QWidget *parent ) : QWidget( parent ) |
164 | { | 164 | { |
165 | vb = new QVBoxLayout( this ); | 165 | vb = new QVBoxLayout( this ); |
166 | 166 | ||
167 | image = new QScrollView(this,0,WResizeNoErase|WNorthWestGravity); | 167 | image = new QScrollView(this,0,WResizeNoErase|WNorthWestGravity); |
168 | pic=new ImageWidget(image); | 168 | pic=new ImageWidget(image); |
169 | image->addChild(pic); | 169 | image->addChild(pic); |
170 | 170 | ||
171 | connect(pic, SIGNAL( clicked() ), this, SLOT( imageClicked() )); | 171 | connect(pic, SIGNAL( clicked() ), this, SLOT( imageClicked() )); |
172 | 172 | ||
173 | vb->addWidget( image ); | 173 | vb->addWidget( image ); |
174 | 174 | ||
175 | } | 175 | } |
176 | 176 | ||
177 | void ImagePane::setPixmap( const QPixmap &pm ) | 177 | void ImagePane::setPixmap( const QPixmap &pm ) |
178 | { | 178 | { |
179 | pic->setPixmap( pm ); | 179 | pic->setPixmap( pm ); |
180 | pic->resize(pm.width(),pm.height()); | 180 | pic->resize(pm.width(),pm.height()); |
181 | image->updateScrollBars (); | 181 | image->updateScrollBars (); |
182 | pic->repaint(false); | 182 | pic->repaint(false); |
183 | } | 183 | } |
184 | 184 | ||
185 | void ImagePane::imageClicked() | 185 | void ImagePane::imageClicked() |
186 | { | 186 | { |
187 | emit clicked(); | 187 | emit clicked(); |
188 | } | 188 | } |
189 | //=========================================================================== | 189 | //=========================================================================== |
190 | /* | 190 | /* |
191 | Draws the portion of the scaled pixmap that needs to be updated | 191 | Draws the portion of the scaled pixmap that needs to be updated |
192 | */ | 192 | */ |
193 | 193 | ||
194 | void ImageWidget::paintEvent( QPaintEvent *e ) | 194 | void ImageWidget::paintEvent( QPaintEvent *e ) |
195 | { | 195 | { |
196 | QPainter painter(this); | 196 | QPainter painter(this); |
197 | 197 | ||
198 | painter.setClipRect(e->rect()); | 198 | painter.setClipRect(e->rect()); |
199 | painter.fillRect(0,0,width(),height(),QColor(0,0,0)); | 199 | painter.fillRect(0,0,width(),height(),QColor(0,0,0)); |
200 | 200 | ||
201 | if ( pixmap.size() != QSize( 0, 0 ) ) | 201 | if ( pixmap.size() != QSize( 0, 0 ) ) |
202 | { // is an image loaded? | 202 | { // is an image loaded? |
203 | painter.drawPixmap((width() - pixmap.width()) / 2, (height() - pixmap.height()) / 2, pixmap); | 203 | painter.drawPixmap((width() - pixmap.width()) / 2, (height() - pixmap.height()) / 2, pixmap); |
204 | } | 204 | } |
205 | } | 205 | } |
206 | 206 | ||
207 | void ImageWidget::mouseReleaseEvent(QMouseEvent *) | 207 | void ImageWidget::mouseReleaseEvent(QMouseEvent *) |
208 | { | 208 | { |
209 | emit clicked(); | 209 | emit clicked(); |
210 | } | 210 | } |
211 | 211 | ||
212 | //=========================================================================== | 212 | //=========================================================================== |
213 | 213 | ||
214 | ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags ) | 214 | ImageViewer::ImageViewer( QWidget *parent, const char *name, int wFlags ) |
215 | : QMainWindow( parent, name, WResizeNoErase ), filename( 0 ), bFromDocView( FALSE ) | 215 | : QMainWindow( parent, name, WResizeNoErase ), filename( 0 ), bFromDocView( FALSE ) |
216 | { | 216 | { |
217 | setCaption( tr("Image Viewer") ); | 217 | setCaption( tr("Image Viewer") ); |
218 | setIcon( Resource::loadPixmap( "ImageViewer" ) ); | 218 | setIcon( Resource::loadPixmap( "ImageViewer" ) ); |
219 | 219 | ||
220 | 220 | ||
221 | Config cfg("Image Viewer"); | 221 | Config cfg("Image Viewer"); |
222 | cfg.setGroup("Image Viewer"); | 222 | cfg.setGroup("Image Viewer"); |
223 | 223 | ||
224 | showThumbView=cfg.readBoolEntry("ShowThumbnails",false); | 224 | showThumbView=cfg.readBoolEntry("ShowThumbnails",false); |
225 | isSized=cfg.readBoolEntry("SizeToScreen",true); | 225 | isSized=cfg.readBoolEntry("SizeToScreen",true); |
226 | 226 | ||
227 | isFullScreen = FALSE; | 227 | isFullScreen = FALSE; |
228 | 228 | ||
229 | setToolBarsMovable( FALSE ); | 229 | setToolBarsMovable( FALSE ); |
230 | 230 | ||
231 | toolBar = new QPEToolBar( this ); | 231 | toolBar = new QToolBar( this ); |
232 | toolBar->setHorizontalStretchable( TRUE ); | 232 | toolBar->setHorizontalStretchable( TRUE ); |
233 | 233 | ||
234 | menuBar = new QMenuBar( toolBar ); | 234 | menuBar = new QMenuBar( toolBar ); |
235 | 235 | ||
236 | current=menuBar; | 236 | current=menuBar; |
237 | 237 | ||
238 | 238 | ||
239 | 239 | ||
240 | fileMenuFile = new QPopupMenu(this); | 240 | fileMenuFile = new QPopupMenu(this); |
241 | //menuBarmenubarFile->insertItem( tr("File"), fileMenu ); | 241 | //menuBarmenubarFile->insertItem( tr("File"), fileMenu ); |
242 | fileMenuFile->insertItem(tr("Open"), | 242 | fileMenuFile->insertItem(tr("Open"), |
243 | this, SLOT(openFile()), 0); | 243 | this, SLOT(openFile()), 0); |
244 | 244 | ||
245 | viewMenuFile = new QPopupMenu( this ); | 245 | viewMenuFile = new QPopupMenu( this ); |
246 | //menubarFile->insertItem( tr("View"), viewMenu ); | 246 | //menubarFile->insertItem( tr("View"), viewMenu ); |
247 | viewMenuFile->insertItem( tr("Thumbnail View"), | 247 | viewMenuFile->insertItem( tr("Thumbnail View"), |
248 | this, SLOT(switchThumbView()), 0, SHOW_THUMBNAILS ); | 248 | this, SLOT(switchThumbView()), 0, SHOW_THUMBNAILS ); |
249 | 249 | ||
250 | viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView ); | 250 | viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView ); |
251 | 251 | ||
252 | 252 | ||
253 | 253 | ||
254 | 254 | ||
255 | optionsMenuFile = new QPopupMenu( this); | 255 | optionsMenuFile = new QPopupMenu( this); |
256 | //menubarFile->insertItem( tr("Options"),optionsMenu ); | 256 | //menubarFile->insertItem( tr("Options"),optionsMenu ); |
257 | slideAction = new QAction( tr( "Slide show" ), Resource::loadIconSet( "slideshow" ), | 257 | slideAction = new QAction( tr( "Slide show" ), Resource::loadIconSet( "slideshow" ), |
258 | QString::null, 0, this, 0 ); | 258 | QString::null, 0, this, 0 ); |
259 | slideAction->setToggleAction( TRUE ); | 259 | slideAction->setToggleAction( TRUE ); |
260 | connect( slideAction, SIGNAL( toggled(bool) ), this, SLOT( slideShow(bool) ) ); | 260 | connect( slideAction, SIGNAL( toggled(bool) ), this, SLOT( slideShow(bool) ) ); |
261 | slideAction->addTo( optionsMenuFile); | 261 | slideAction->addTo( optionsMenuFile); |
262 | // slideAction->addTo( toolBar ); | 262 | // slideAction->addTo( toolBar ); |
263 | 263 | ||
264 | 264 | ||
265 | // optionsMenuFile->insertItem( tr("Slideshow") ); | 265 | // optionsMenuFile->insertItem( tr("Slideshow") ); |
266 | optionsMenuFile->insertSeparator(); | 266 | optionsMenuFile->insertSeparator(); |
267 | optionsMenuFile->insertItem( tr("Preferences.."), this, SLOT(settings()), 0); | 267 | optionsMenuFile->insertItem( tr("Preferences.."), this, SLOT(settings()), 0); |
268 | // optionsMenuFile->insertItem( tr("Help"), this, SLOT(help()), 0); | 268 | // optionsMenuFile->insertItem( tr("Help"), this, SLOT(help()), 0); |
269 | 269 | ||
270 | QStrList fmt = QImage::outputFormats(); | 270 | QStrList fmt = QImage::outputFormats(); |
271 | 271 | ||
272 | 272 | ||
273 | fileMenuView = new QPopupMenu( this ); | 273 | fileMenuView = new QPopupMenu( this ); |
274 | //menubarView->insertItem( tr("File"),fileMenu ); | 274 | //menubarView->insertItem( tr("File"),fileMenu ); |
275 | fileMenuView->insertItem( tr("Image Info ..."),this, SLOT(displayInfoDialog()),0 ); | 275 | fileMenuView->insertItem( tr("Image Info ..."),this, SLOT(displayInfoDialog()),0 ); |
276 | fileMenuView->insertSeparator(); | 276 | fileMenuView->insertSeparator(); |
277 | 277 | ||
278 | viewMenuView = new QPopupMenu(this ); | 278 | viewMenuView = new QPopupMenu(this ); |
279 | viewMenuView->setCheckable ( true ); | 279 | viewMenuView->setCheckable ( true ); |
280 | 280 | ||
281 | //menubarView->insertItem( tr("View"),viewMenu ); | 281 | //menubarView->insertItem( tr("View"),viewMenu ); |
282 | viewMenuView->insertItem(tr("Horizontal flip"), this, SLOT(hFlip()), 0); | 282 | viewMenuView->insertItem(tr("Horizontal flip"), this, SLOT(hFlip()), 0); |
283 | viewMenuView->insertItem(tr("Vertical flip"), this, SLOT(vFlip()), 0); | 283 | viewMenuView->insertItem(tr("Vertical flip"), this, SLOT(vFlip()), 0); |
284 | 284 | ||
285 | stack = new QWidgetStack( this ); | 285 | stack = new QWidgetStack( this ); |
286 | stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); | 286 | stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); |
287 | setCentralWidget( stack ); | 287 | setCentralWidget( stack ); |
288 | 288 | ||
289 | 289 | ||
290 | imagePanel = new ImagePane( stack ); | 290 | imagePanel = new ImagePane( stack ); |
291 | connect(imagePanel, SIGNAL(clicked()), this, SLOT(normalView())); | 291 | connect(imagePanel, SIGNAL(clicked()), this, SLOT(normalView())); |
292 | 292 | ||
293 | 293 | ||
294 | ImageFileSelector::CURRENT_VIEW cv; | 294 | ImageFileSelector::CURRENT_VIEW cv; |
295 | if(showThumbView) | 295 | if(showThumbView) |
296 | cv=ImageFileSelector::THUMBNAIL; | 296 | cv=ImageFileSelector::THUMBNAIL; |
297 | else | 297 | else |
298 | cv=ImageFileSelector::DETAILED; | 298 | cv=ImageFileSelector::DETAILED; |
299 | 299 | ||
300 | qDebug("cv = %d",cv); | 300 | qDebug("cv = %d",cv); |
301 | 301 | ||
302 | fileSelector = new ImageFileSelector( cv,stack, "fs"); | 302 | fileSelector = new ImageFileSelector( cv,stack, "fs"); |
303 | 303 | ||
304 | //switchThumbView(); | 304 | //switchThumbView(); |
305 | 305 | ||
306 | 306 | ||
307 | //fileSelector = new ImageFileSelector("image/*", stack, "fs"); | 307 | //fileSelector = new ImageFileSelector("image/*", stack, "fs"); |
308 | //fileSelector->setNewVisible(FALSE); | 308 | //fileSelector->setNewVisible(FALSE); |
309 | //fileSelector->setCloseVisible(FALSE); | 309 | //fileSelector->setCloseVisible(FALSE); |
310 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( closeFileSelector() ) ); | 310 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( closeFileSelector() ) ); |
311 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), | 311 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), |
312 | this, SLOT( openFile( const DocLnk & ) ) ); | 312 | this, SLOT( openFile( const DocLnk & ) ) ); |
313 | 313 | ||
314 | imageList = fileSelector->fileList(); | 314 | imageList = fileSelector->fileList(); |
315 | slideAction->setEnabled( imageList.count() != 0); | 315 | slideAction->setEnabled( imageList.count() != 0); |
316 | 316 | ||
317 | iconToolBar = new QPEToolBar(this); | 317 | iconToolBar = new QToolBar(this); |
318 | 318 | ||
319 | QAction *a; | 319 | QAction *a; |
320 | 320 | ||
321 | a = new QAction( tr( "Open ..." ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 321 | a = new QAction( tr( "Open ..." ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
322 | connect( a, SIGNAL( activated() ), this, SLOT( open() ) ); | 322 | connect( a, SIGNAL( activated() ), this, SLOT( open() ) ); |
323 | a->addTo( fileMenuView); | 323 | a->addTo( fileMenuView); |
324 | a->addTo( iconToolBar ); | 324 | a->addTo( iconToolBar ); |
325 | 325 | ||
326 | 326 | ||
327 | a = new QAction( tr( "Rotate 90"), Resource::loadPixmap( "rotate90" ), QString::null, 0, this, 0); | 327 | a = new QAction( tr( "Rotate 90"), Resource::loadPixmap( "rotate90" ), QString::null, 0, this, 0); |
328 | connect( a, SIGNAL( activated() ), this, SLOT( rot90() ) ); | 328 | connect( a, SIGNAL( activated() ), this, SLOT( rot90() ) ); |
329 | a->addTo( iconToolBar ); | 329 | a->addTo( iconToolBar ); |
330 | a->addTo( viewMenuView ); | 330 | a->addTo( viewMenuView ); |
331 | 331 | ||
332 | a = new QAction( tr( "Rotate 180" ), Resource::loadPixmap( "repeat" ), QString::null, 0, this, 0 ); | 332 | a = new QAction( tr( "Rotate 180" ), Resource::loadPixmap( "repeat" ), QString::null, 0, this, 0 ); |
333 | connect( a, SIGNAL( activated() ), this, SLOT( rot180() ) ); | 333 | connect( a, SIGNAL( activated() ), this, SLOT( rot180() ) ); |
334 | a->addTo( iconToolBar ); | 334 | a->addTo( iconToolBar ); |
335 | a->addTo( viewMenuView ); | 335 | a->addTo( viewMenuView ); |
336 | 336 | ||
337 | 337 | ||
338 | a = new QAction( tr( "Rotate 270"), Resource::loadPixmap( "rotate270" ), QString::null, 0, this, 0); | 338 | a = new QAction( tr( "Rotate 270"), Resource::loadPixmap( "rotate270" ), QString::null, 0, this, 0); |
339 | connect( a, SIGNAL( activated() ), this, SLOT( rot270() ) ); | 339 | connect( a, SIGNAL( activated() ), this, SLOT( rot270() ) ); |
340 | //a->addTo( iconToolBar ); | 340 | //a->addTo( iconToolBar ); |
341 | a->addTo( viewMenuView ); | 341 | a->addTo( viewMenuView ); |
342 | 342 | ||
343 | 343 | ||
344 | 344 | ||
345 | viewMenuView->insertSeparator(); | 345 | viewMenuView->insertSeparator(); |
346 | viewMenuView->insertItem(tr("Brightness ..."), this, SLOT(displayControlsDialog()), 0); | 346 | viewMenuView->insertItem(tr("Brightness ..."), this, SLOT(displayControlsDialog()), 0); |
347 | viewMenuView->insertItem(tr("Black And White"), this, SLOT(blackAndWhite()), 0,BLACKANDWHITE); | 347 | viewMenuView->insertItem(tr("Black And White"), this, SLOT(blackAndWhite()), 0,BLACKANDWHITE); |
348 | viewMenuView->insertSeparator(); | 348 | viewMenuView->insertSeparator(); |
349 | 349 | ||
350 | 350 | ||
351 | sss = new QAction( tr( "Scale to Screen"), Resource::loadPixmap( "scale" ), QString::null, 0, this, 0,true); | 351 | sss = new QAction( tr( "Scale to Screen"), Resource::loadPixmap( "scale" ), QString::null, 0, this, 0,true); |
352 | connect( sss, SIGNAL( activated() ), this, SLOT( switchSizeToScreen() ) ); | 352 | connect( sss, SIGNAL( activated() ), this, SLOT( switchSizeToScreen() ) ); |
353 | sss->addTo( iconToolBar ); | 353 | sss->addTo( iconToolBar ); |
354 | sss->addTo( viewMenuView ); | 354 | sss->addTo( viewMenuView ); |
355 | 355 | ||
356 | sss->setOn(isSized); | 356 | sss->setOn(isSized); |
357 | viewMenuView->insertSeparator(); | 357 | viewMenuView->insertSeparator(); |
358 | 358 | ||
359 | 359 | ||
360 | a = new QAction( tr( "Fullscreen" ), Resource::loadPixmap( "fullscreen" ), | 360 | a = new QAction( tr( "Fullscreen" ), Resource::loadPixmap( "fullscreen" ), |
361 | QString::null, 0, this, 0 ); | 361 | QString::null, 0, this, 0 ); |
362 | connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) ); | 362 | connect( a, SIGNAL( activated() ), this, SLOT( fullScreen() ) ); |
363 | a->addTo( iconToolBar ); | 363 | a->addTo( iconToolBar ); |
364 | a->addTo( viewMenuView); | 364 | a->addTo( viewMenuView); |
365 | 365 | ||
366 | a = new QAction( tr( "Stop Slideshow" ), Resource::loadPixmap( "quit_icon" ), | 366 | a = new QAction( tr( "Stop Slideshow" ), Resource::loadPixmap( "quit_icon" ), |
367 | QString::null, 0, this, 0 ); | 367 | QString::null, 0, this, 0 ); |
368 | connect( a, SIGNAL( activated() ), this, SLOT( stopSlideShow() ) ); | 368 | connect( a, SIGNAL( activated() ), this, SLOT( stopSlideShow() ) ); |
369 | a->addTo( iconToolBar ); | 369 | a->addTo( iconToolBar ); |
370 | a->addTo( viewMenuView); | 370 | a->addTo( viewMenuView); |
371 | 371 | ||
372 | 372 | ||
373 | Config config( "ImageViewer" ); | 373 | Config config( "ImageViewer" ); |
374 | config.setGroup( "SlideShow" ); | 374 | config.setGroup( "SlideShow" ); |
375 | slideDelay = config.readNumEntry( "Delay", 2); | 375 | slideDelay = config.readNumEntry( "Delay", 2); |
376 | slideRepeat = config.readBoolEntry( "Repeat", FALSE ); | 376 | slideRepeat = config.readBoolEntry( "Repeat", FALSE ); |
377 | slideReverse = config.readBoolEntry("Reverse", FALSE); | 377 | slideReverse = config.readBoolEntry("Reverse", FALSE); |
378 | 378 | ||
379 | config.setGroup("Default"); | 379 | config.setGroup("Default"); |
380 | rotateOnLoad = config.readBoolEntry("Rotate", FALSE); | 380 | rotateOnLoad = config.readBoolEntry("Rotate", FALSE); |
381 | fastLoad = config.readBoolEntry("FastLoad", TRUE); | 381 | fastLoad = config.readBoolEntry("FastLoad", TRUE); |
382 | slideTimer = new QTimer( this ); | 382 | slideTimer = new QTimer( this ); |
383 | connect( slideTimer, SIGNAL(timeout()), this, SLOT(slideUpdate()) ); | 383 | connect( slideTimer, SIGNAL(timeout()), this, SLOT(slideUpdate()) ); |
384 | 384 | ||
385 | switchToFileSelector(); | 385 | switchToFileSelector(); |
386 | 386 | ||
387 | setMouseTracking( TRUE ); | 387 | setMouseTracking( TRUE ); |
388 | 388 | ||
389 | 389 | ||
390 | } | 390 | } |
391 | 391 | ||
392 | ImageViewer::~ImageViewer() | 392 | ImageViewer::~ImageViewer() |
393 | { | 393 | { |
394 | Config cfg("Image Viewer"); | 394 | Config cfg("Image Viewer"); |
395 | cfg.setGroup("Image Viewer"); | 395 | cfg.setGroup("Image Viewer"); |
396 | 396 | ||
397 | cfg.writeEntry("ShowThumbnails",(int)showThumbView); | 397 | cfg.writeEntry("ShowThumbnails",(int)showThumbView); |
398 | cfg.writeEntry("SizeToScreen",(int)isSized); | 398 | cfg.writeEntry("SizeToScreen",(int)isSized); |
399 | 399 | ||
400 | cfg.setGroup( "SlideShow" ); | 400 | cfg.setGroup( "SlideShow" ); |
401 | cfg.writeEntry( "Delay", slideDelay); | 401 | cfg.writeEntry( "Delay", slideDelay); |
402 | cfg.writeEntry( "Repeat", slideRepeat ); | 402 | cfg.writeEntry( "Repeat", slideRepeat ); |
403 | cfg.writeEntry("Reverse", slideReverse); | 403 | cfg.writeEntry("Reverse", slideReverse); |
404 | 404 | ||
405 | cfg.setGroup("Default"); | 405 | cfg.setGroup("Default"); |
406 | cfg.writeEntry("Rotate", rotateOnLoad); | 406 | cfg.writeEntry("Rotate", rotateOnLoad); |
407 | cfg.writeEntry("FastLoad", fastLoad); | 407 | cfg.writeEntry("FastLoad", fastLoad); |
408 | 408 | ||
409 | delete imagePanel; // in case it is fullscreen | 409 | delete imagePanel; // in case it is fullscreen |
410 | } | 410 | } |
411 | 411 | ||
412 | void ImageViewer::help() { | 412 | void ImageViewer::help() { |
413 | 413 | ||
414 | } | 414 | } |
415 | 415 | ||
416 | 416 | ||
417 | void ImageViewer::settings() | 417 | void ImageViewer::settings() |
418 | { | 418 | { |
419 | SettingsDialog dlg( this, 0, TRUE ); | 419 | SettingsDialog dlg( this, 0, TRUE ); |
420 | dlg.setDelay( slideDelay ); | 420 | dlg.setDelay( slideDelay ); |
421 | dlg.setRepeat( slideRepeat ); | 421 | dlg.setRepeat( slideRepeat ); |
422 | dlg.setReverse( slideReverse ); | 422 | dlg.setReverse( slideReverse ); |
423 | dlg.setRotate(rotateOnLoad); | 423 | dlg.setRotate(rotateOnLoad); |
424 | dlg.setFastLoad(fastLoad); | 424 | dlg.setFastLoad(fastLoad); |
425 | 425 | ||
426 | if ( QPEApplication::execDialog(&dlg) == QDialog::Accepted ) { | 426 | if ( QPEApplication::execDialog(&dlg) == QDialog::Accepted ) { |
427 | qDebug("<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>"); | 427 | qDebug("<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>"); |
428 | slideDelay = dlg.delay(); | 428 | slideDelay = dlg.delay(); |
429 | slideRepeat = dlg.repeat(); | 429 | slideRepeat = dlg.repeat(); |
430 | slideReverse = dlg.reverse(); | 430 | slideReverse = dlg.reverse(); |
431 | rotateOnLoad = dlg.rotate(); | 431 | rotateOnLoad = dlg.rotate(); |
432 | fastLoad = dlg.fastLoad(); | 432 | fastLoad = dlg.fastLoad(); |
433 | 433 | ||
434 | Config config( "ImageViewer" ); | 434 | Config config( "ImageViewer" ); |
435 | config.setGroup( "SlideShow" ); | 435 | config.setGroup( "SlideShow" ); |
436 | config.writeEntry( "Delay", slideDelay ); | 436 | config.writeEntry( "Delay", slideDelay ); |
437 | config.writeEntry( "Repeat", slideRepeat ); | 437 | config.writeEntry( "Repeat", slideRepeat ); |
438 | config.writeEntry("Reverse", slideReverse); | 438 | config.writeEntry("Reverse", slideReverse); |
439 | 439 | ||
440 | config.setGroup("Default"); | 440 | config.setGroup("Default"); |
441 | config.writeEntry("Rotate", rotateOnLoad); | 441 | config.writeEntry("Rotate", rotateOnLoad); |
442 | config.writeEntry("FastLoad", fastLoad); | 442 | config.writeEntry("FastLoad", fastLoad); |
443 | } | 443 | } |
444 | } | 444 | } |
445 | 445 | ||
446 | void ImageViewer::switchSizeToScreen() | 446 | void ImageViewer::switchSizeToScreen() |
447 | { | 447 | { |
448 | isSized=!isSized; | 448 | isSized=!isSized; |
449 | sss->setOn(isSized); | 449 | sss->setOn(isSized); |
450 | updateImage(); | 450 | updateImage(); |
451 | } | 451 | } |
452 | 452 | ||
453 | void ImageViewer::updateImage() | 453 | void ImageViewer::updateImage() |
454 | { | 454 | { |
455 | if ( isSized ) { | 455 | if ( isSized ) { |
456 | imagePanel->setPixmap(pmScaled); | 456 | imagePanel->setPixmap(pmScaled); |
457 | } else { | 457 | } else { |
458 | imagePanel->setPixmap(pm); | 458 | imagePanel->setPixmap(pm); |
459 | } | 459 | } |
460 | } | 460 | } |
461 | 461 | ||
462 | void ImageViewer::switchThumbView() | 462 | void ImageViewer::switchThumbView() |
463 | { | 463 | { |
464 | 464 | ||
465 | showThumbView=!showThumbView; | 465 | showThumbView=!showThumbView; |
466 | viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView ); | 466 | viewMenuFile->setItemChecked ( SHOW_THUMBNAILS, showThumbView ); |
467 | fileSelector->switchView(); | 467 | fileSelector->switchView(); |
468 | 468 | ||
469 | } | 469 | } |
470 | 470 | ||
471 | void ImageViewer::switchToFileSelector() | 471 | void ImageViewer::switchToFileSelector() |
472 | { | 472 | { |
473 | stack->raiseWidget(fileSelector); | 473 | stack->raiseWidget(fileSelector); |
474 | menuBar->clear(); | 474 | menuBar->clear(); |
475 | menuBar->insertItem( tr("File"), fileMenuFile ); | 475 | menuBar->insertItem( tr("File"), fileMenuFile ); |
476 | menuBar->insertItem( tr("View"), viewMenuFile ); | 476 | menuBar->insertItem( tr("View"), viewMenuFile ); |
477 | menuBar->insertItem( tr("Options"), optionsMenuFile ); | 477 | menuBar->insertItem( tr("Options"), optionsMenuFile ); |
478 | iconToolBar->hide(); | 478 | iconToolBar->hide(); |
479 | imagePanel->disable(); | 479 | imagePanel->disable(); |
480 | slideShow(false); | 480 | slideShow(false); |
481 | 481 | ||
482 | } | 482 | } |
483 | 483 | ||
484 | void ImageViewer::switchToImageView() | 484 | void ImageViewer::switchToImageView() |
485 | { | 485 | { |
486 | stack->raiseWidget(imagePanel); | 486 | stack->raiseWidget(imagePanel); |
487 | 487 | ||
488 | menuBar->clear(); | 488 | menuBar->clear(); |
489 | menuBar->insertItem( tr("File"), fileMenuView ); | 489 | menuBar->insertItem( tr("File"), fileMenuView ); |
490 | menuBar->insertItem( tr("View"), viewMenuView ); | 490 | menuBar->insertItem( tr("View"), viewMenuView ); |
491 | viewMenuView->setItemEnabled(BLACKANDWHITE,true); | 491 | viewMenuView->setItemEnabled(BLACKANDWHITE,true); |
492 | iconToolBar->show(); | 492 | iconToolBar->show(); |
493 | 493 | ||
494 | imagePanel->setPosition(0,0); | 494 | imagePanel->setPosition(0,0); |
495 | 495 | ||
496 | } | 496 | } |
497 | 497 | ||
498 | 498 | ||
499 | void ImageViewer::setDocument(const QString& fileref) | 499 | void ImageViewer::setDocument(const QString& fileref) |
500 | { | 500 | { |
501 | delayLoad = fileref; | 501 | delayLoad = fileref; |
502 | switchToImageView(); | 502 | switchToImageView(); |
503 | QTimer::singleShot( 0, this, SLOT(doDelayedLoad()) ); | 503 | QTimer::singleShot( 0, this, SLOT(doDelayedLoad()) ); |
504 | } | 504 | } |
505 | 505 | ||
506 | void ImageViewer::doDelayedLoad() | 506 | void ImageViewer::doDelayedLoad() |
507 | { | 507 | { |
508 | show(delayLoad); | 508 | show(delayLoad); |
509 | } | 509 | } |
510 | 510 | ||
511 | void ImageViewer::show() | 511 | void ImageViewer::show() |
512 | { | 512 | { |
513 | normalView(); | 513 | normalView(); |
514 | QMainWindow::show(); | 514 | QMainWindow::show(); |
515 | } | 515 | } |
516 | 516 | ||
517 | void ImageViewer::show(const QString& fileref) | 517 | void ImageViewer::show(const QString& fileref) |
518 | { | 518 | { |
519 | // qDebug("Show "+fileref); | 519 | // qDebug("Show "+fileref); |
520 | bFromDocView = TRUE; | 520 | bFromDocView = TRUE; |
521 | closeFileSelector(); | 521 | closeFileSelector(); |
522 | DocLnk link(fileref); | 522 | DocLnk link(fileref); |
523 | if ( link.isValid() ) { | 523 | if ( link.isValid() ) { |
524 | openFile(link); | 524 | openFile(link); |
525 | } else { | 525 | } else { |
526 | filename = fileref; | 526 | filename = fileref; |
527 | updateCaption( fileref ); | 527 | updateCaption( fileref ); |
528 | loadImage( fileref ); | 528 | loadImage( fileref ); |
529 | } | 529 | } |
530 | } | 530 | } |
531 | 531 | ||
532 | void ImageViewer::openFile() { | 532 | void ImageViewer::openFile() { |
533 | MimeTypes types; | 533 | MimeTypes types; |
534 | QStringList image; | 534 | QStringList image; |
535 | image << "image/*"; | 535 | image << "image/*"; |
536 | types.insert("Images", image); | 536 | types.insert("Images", image); |
537 | 537 | ||
538 | QString str = OFileDialog::getOpenFileName( 1,QPEApplication::documentDir(),"", types, 0 ); | 538 | QString str = OFileDialog::getOpenFileName( 1,QPEApplication::documentDir(),"", types, 0 ); |
539 | DocLnk link(str); | 539 | DocLnk link(str); |
540 | // if ( link.isValid() ) | 540 | // if ( link.isValid() ) |
541 | openFile(link); | 541 | openFile(link); |
542 | 542 | ||
543 | } | 543 | } |
544 | 544 | ||
545 | void ImageViewer::openFile( const DocLnk &link ) | 545 | void ImageViewer::openFile( const DocLnk &link ) |
546 | { | 546 | { |
547 | closeFileSelector(); | 547 | closeFileSelector(); |
548 | // DocLnk link(file); | 548 | // DocLnk link(file); |
549 | qDebug("open "+link.name()); | 549 | qDebug("open "+link.name()); |
550 | updateCaption( link.name() ); | 550 | updateCaption( link.name() ); |
551 | loadImage( link.file() ); | 551 | loadImage( link.file() ); |
552 | if (slideTimer->isActive()) { | 552 | if (slideTimer->isActive()) { |
553 | slideTimer->start(slideDelay * 1000, FALSE); | 553 | slideTimer->start(slideDelay * 1000, FALSE); |
554 | } | 554 | } |
555 | 555 | ||
556 | } | 556 | } |
557 | 557 | ||
558 | void ImageViewer::open() | 558 | void ImageViewer::open() |
559 | { | 559 | { |
560 | switchToFileSelector(); | 560 | switchToFileSelector(); |
561 | } | 561 | } |
562 | 562 | ||
563 | void ImageViewer::closeFileSelector() | 563 | void ImageViewer::closeFileSelector() |
564 | { | 564 | { |
565 | switchToImageView(); | 565 | switchToImageView(); |
566 | } | 566 | } |
567 | 567 | ||
568 | void ImageViewer::updateCaption( QString name ) | 568 | void ImageViewer::updateCaption( QString name ) |
569 | { | 569 | { |
570 | int sep = name.findRev( '/' ); | 570 | int sep = name.findRev( '/' ); |
571 | if ( sep >= 0 ) | 571 | if ( sep >= 0 ) |
572 | name = name.mid( sep+1 ); | 572 | name = name.mid( sep+1 ); |
573 | setCaption( name + tr(" - Image Viewer") ); | 573 | setCaption( name + tr(" - Image Viewer") ); |
574 | } | 574 | } |
575 | 575 | ||
576 | /* | 576 | /* |
577 | This function loads an image from a file. | 577 | This function loads an image from a file. |
578 | */ | 578 | */ |
579 | 579 | ||
580 | void ImageViewer::loadImage( const char *fileName ) | 580 | void ImageViewer::loadImage( const char *fileName ) |
581 | { | 581 | { |
582 | filename = fileName; | 582 | filename = fileName; |
583 | if ( filename ) { | 583 | if ( filename ) { |
584 | QApplication::setOverrideCursor( waitCursor ); // this might take time | 584 | QApplication::setOverrideCursor( waitCursor ); // this might take time |
585 | //imagePanel->statusLabel()->setText( tr("Loading image...") ); | 585 | //imagePanel->statusLabel()->setText( tr("Loading image...") ); |
586 | qApp->processEvents(); | 586 | qApp->processEvents(); |
587 | bool ok = image.load(filename, 0); | 587 | bool ok = image.load(filename, 0); |
588 | if ( ok ) { | 588 | if ( ok ) { |
589 | ok = reconvertImage(); | 589 | ok = reconvertImage(); |
590 | updateImageInfo(filename); | 590 | updateImageInfo(filename); |
591 | } | 591 | } |
592 | if ( !ok ) { | 592 | if ( !ok ) { |
593 | pm.resize(0,0); // couldn't load image | 593 | pm.resize(0,0); // couldn't load image |
594 | update(); | 594 | update(); |
595 | } | 595 | } |
596 | QApplication::restoreOverrideCursor(); // restore original cursor | 596 | QApplication::restoreOverrideCursor(); // restore original cursor |
597 | } | 597 | } |
598 | 598 | ||
599 | // fastLoad ? ", Fast" : "", | 599 | // fastLoad ? ", Fast" : "", |
600 | // fastLoad ? QMAX(imagewidth/maxsize, imageheight/maxsize) : 1); | 600 | // fastLoad ? QMAX(imagewidth/maxsize, imageheight/maxsize) : 1); |
601 | 601 | ||
602 | 602 | ||
603 | // matrix.reset(); | 603 | // matrix.reset(); |
604 | rotated90 = FALSE; | 604 | rotated90 = FALSE; |
605 | 605 | ||
606 | if (rotateOnLoad) { | 606 | if (rotateOnLoad) { |
607 | rotated90 = TRUE; | 607 | rotated90 = TRUE; |
608 | rot90(); | 608 | rot90(); |
609 | // matrix.rotate( -90.0 ); | 609 | // matrix.rotate( -90.0 ); |
610 | } | 610 | } |
611 | 611 | ||
612 | switchToImageView(); | 612 | switchToImageView(); |
613 | updateImage(); | 613 | updateImage(); |
614 | 614 | ||
615 | } | 615 | } |
616 | 616 | ||
617 | bool ImageViewer::loadSelected() | 617 | bool ImageViewer::loadSelected() |
618 | { | 618 | { |
619 | bool ok = false; | 619 | bool ok = false; |
620 | if ( stack->visibleWidget() == fileSelector ) | 620 | if ( stack->visibleWidget() == fileSelector ) |
621 | { | 621 | { |
622 | const DocLnk *link = fileSelector->selected(); | 622 | const DocLnk *link = fileSelector->selected(); |
623 | if ( link ) | 623 | if ( link ) |
624 | { | 624 | { |
625 | if ( link->file() != filename ) | 625 | if ( link->file() != filename ) |
626 | { | 626 | { |
627 | updateCaption( link->name() ); | 627 | updateCaption( link->name() ); |
628 | filename = link->file(); | 628 | filename = link->file(); |
629 | qApp->processEvents(); | 629 | qApp->processEvents(); |
630 | ok = image.load(filename, 0); | 630 | ok = image.load(filename, 0); |
631 | if ( ok ) | 631 | if ( ok ) |
632 | { | 632 | { |
633 | updateImageInfo(filename); | 633 | updateImageInfo(filename); |
634 | ok = reconvertImage(); | 634 | ok = reconvertImage(); |
635 | } | 635 | } |
636 | if ( !ok ) | 636 | if ( !ok ) |
637 | pm.resize(0,0); | 637 | pm.resize(0,0); |
638 | } | 638 | } |
639 | } | 639 | } |
640 | } | 640 | } |
641 | if ( !image.isNull() ) | 641 | if ( !image.isNull() ) |
642 | { | 642 | { |
643 | ok = true; | 643 | ok = true; |
644 | closeFileSelector(); | 644 | closeFileSelector(); |
645 | } | 645 | } |
646 | 646 | ||
647 | return ok; | 647 | return ok; |
648 | } | 648 | } |
649 | 649 | ||
650 | bool ImageViewer::reconvertImage() | 650 | bool ImageViewer::reconvertImage() |
651 | { | 651 | { |
652 | bool success = FALSE; | 652 | bool success = FALSE; |
653 | 653 | ||
654 | if ( image.isNull() ) return FALSE; | 654 | if ( image.isNull() ) return FALSE; |
655 | 655 | ||
656 | QApplication::setOverrideCursor( waitCursor ); // this might take time | 656 | QApplication::setOverrideCursor( waitCursor ); // this might take time |
657 | if ( pm.convertFromImage(image /*, conversion_flags */ ) ) | 657 | if ( pm.convertFromImage(image /*, conversion_flags */ ) ) |
658 | { | 658 | { |
659 | pmScaled = QPixmap(); | 659 | pmScaled = QPixmap(); |
660 | scale(); | 660 | scale(); |
661 | success = TRUE; // load successful | 661 | success = TRUE; // load successful |
662 | } | 662 | } |
663 | else | 663 | else |
664 | { | 664 | { |
665 | pm.resize(0,0); // couldn't load image | 665 | pm.resize(0,0); // couldn't load image |
666 | } | 666 | } |
667 | QApplication::restoreOverrideCursor(); // restore original cursor | 667 | QApplication::restoreOverrideCursor(); // restore original cursor |
668 | 668 | ||
669 | return success; // TRUE if loaded OK | 669 | return success; // TRUE if loaded OK |
670 | } | 670 | } |
671 | 671 | ||
672 | 672 | ||
673 | int ImageViewer::calcHeight() | 673 | int ImageViewer::calcHeight() |
674 | { | 674 | { |
675 | if ( !isFullScreen ) | 675 | if ( !isFullScreen ) |
676 | return imagePanel->paneHeight(); | 676 | return imagePanel->paneHeight(); |
677 | else | 677 | else |
678 | return qApp->desktop()->height(); | 678 | return qApp->desktop()->height(); |
679 | } | 679 | } |
680 | /* | 680 | /* |
681 | This functions scales the pixmap in the member variable "pm" to fit the | 681 | This functions scales the pixmap in the member variable "pm" to fit the |
682 | widget size and puts the resulting pixmap in the member variable "pmScaled". | 682 | widget size and puts the resulting pixmap in the member variable "pmScaled". |
683 | */ | 683 | */ |
684 | void ImageViewer::scale() | 684 | void ImageViewer::scale() |
685 | { | 685 | { |
686 | int h = calcHeight(); | 686 | int h = calcHeight(); |
687 | if ( image.isNull() ) return; | 687 | if ( image.isNull() ) return; |
688 | 688 | ||
689 | QApplication::setOverrideCursor( waitCursor ); // this might take time | 689 | QApplication::setOverrideCursor( waitCursor ); // this might take time |
690 | if ( imagePanel->paneWidth() == pm.width() && h == pm.height() ) | 690 | if ( imagePanel->paneWidth() == pm.width() && h == pm.height() ) |
691 | { // no need to scale if widget | 691 | { // no need to scale if widget |
692 | pmScaled = pm; // size equals pixmap size | 692 | pmScaled = pm; // size equals pixmap size |
693 | } | 693 | } |
694 | else | 694 | else |
695 | { | 695 | { |
696 | double hs = (double)h / (double)image.height(); | 696 | double hs = (double)h / (double)image.height(); |
697 | double ws = (double)imagePanel->paneWidth() / (double)image.width(); | 697 | double ws = (double)imagePanel->paneWidth() / (double)image.width(); |
698 | double scaleFactor = (hs > ws) ? ws : hs; | 698 | double scaleFactor = (hs > ws) ? ws : hs; |
699 | int smoothW = (int)(scaleFactor * image.width()); | 699 | int smoothW = (int)(scaleFactor * image.width()); |
700 | int smoothH = (int)(scaleFactor * image.height()); | 700 | int smoothH = (int)(scaleFactor * image.height()); |
701 | 701 | ||
702 | pmScaled.convertFromImage( image.smoothScale( smoothW, smoothH ) /*, conversion_flags */ ); | 702 | pmScaled.convertFromImage( image.smoothScale( smoothW, smoothH ) /*, conversion_flags */ ); |
703 | } | 703 | } |
704 | QApplication::restoreOverrideCursor(); // restore original cursor | 704 | QApplication::restoreOverrideCursor(); // restore original cursor |
705 | } | 705 | } |
706 | 706 | ||
707 | /* | 707 | /* |
708 | The resize event handler, if a valid pixmap was loaded it will call | 708 | The resize event handler, if a valid pixmap was loaded it will call |
709 | scale() to fit the pixmap to the new widget size. | 709 | scale() to fit the pixmap to the new widget size. |
710 | */ | 710 | */ |
711 | 711 | ||
712 | void ImageViewer::resizeEvent( QResizeEvent * ) | 712 | void ImageViewer::resizeEvent( QResizeEvent * ) |
713 | { | 713 | { |
714 | 714 | ||
715 | if ( pm.size() == QSize( 0, 0 ) ) // we couldn't load the image | 715 | if ( pm.size() == QSize( 0, 0 ) ) // we couldn't load the image |
716 | return; | 716 | return; |
717 | 717 | ||
718 | int h = calcHeight(); | 718 | int h = calcHeight(); |
719 | 719 | ||
720 | if ( imagePanel->paneWidth() != pmScaled.width() || h != pmScaled.height() ) | 720 | if ( imagePanel->paneWidth() != pmScaled.width() || h != pmScaled.height() ) |
721 | { // if new size, | 721 | { // if new size, |
722 | scale(); // scale pmScaled to window | 722 | scale(); // scale pmScaled to window |
723 | } | 723 | } |
724 | if ( image.hasAlphaBuffer() ) | 724 | if ( image.hasAlphaBuffer() ) |
725 | erase(); | 725 | erase(); |
726 | } | 726 | } |
727 | 727 | ||
728 | 728 | ||
729 | void ImageViewer::hFlip() | 729 | void ImageViewer::hFlip() |
730 | { | 730 | { |
731 | // matrix.scale( -1.0, 1.0 ); | 731 | // matrix.scale( -1.0, 1.0 ); |
732 | 732 | ||
733 | setImage(image.mirror(TRUE,FALSE)); | 733 | setImage(image.mirror(TRUE,FALSE)); |
734 | } | 734 | } |
735 | 735 | ||
736 | void ImageViewer::vFlip() | 736 | void ImageViewer::vFlip() |
737 | { | 737 | { |
738 | // matrix.scale( 1.0, -1.0 ); | 738 | // matrix.scale( 1.0, -1.0 ); |
739 | setImage(image.mirror(FALSE,TRUE)); | 739 | setImage(image.mirror(FALSE,TRUE)); |
740 | } | 740 | } |
741 | 741 | ||
742 | void ImageViewer::rot180() | 742 | void ImageViewer::rot180() |
743 | { | 743 | { |
744 | // matrix.rotate( 180.0 ); | 744 | // matrix.rotate( 180.0 ); |
745 | setImage(image.mirror(TRUE,TRUE)); | 745 | setImage(image.mirror(TRUE,TRUE)); |
746 | } | 746 | } |
747 | 747 | ||
748 | void ImageViewer::rot90() | 748 | void ImageViewer::rot90() |
749 | { | 749 | { |
750 | QImage oldimage; | 750 | QImage oldimage; |
751 | oldimage = image.convertDepth(32); | 751 | oldimage = image.convertDepth(32); |
752 | // matrix.rotate( -90.0 ); | 752 | // matrix.rotate( -90.0 ); |
753 | setImage(rotate(oldimage,Rotate90)); | 753 | setImage(rotate(oldimage,Rotate90)); |
754 | 754 | ||
755 | } | 755 | } |
756 | void ImageViewer::rot270() | 756 | void ImageViewer::rot270() |
757 | { | 757 | { |
758 | 758 | ||
759 | QImage oldimage; | 759 | QImage oldimage; |
760 | oldimage = image.convertDepth(32); | 760 | oldimage = image.convertDepth(32); |
761 | // matrix.rotate(90.0); | 761 | // matrix.rotate(90.0); |
762 | setImage(rotate(oldimage,Rotate270)); | 762 | setImage(rotate(oldimage,Rotate270)); |
763 | 763 | ||
764 | } | 764 | } |
765 | 765 | ||
766 | void ImageViewer::blackAndWhite() | 766 | void ImageViewer::blackAndWhite() |
767 | { | 767 | { |
768 | 768 | ||
769 | viewMenuView->setItemEnabled(BLACKANDWHITE,false); | 769 | viewMenuView->setItemEnabled(BLACKANDWHITE,false); |
770 | setImage(toGray(image,false)); | 770 | setImage(toGray(image,false)); |
771 | } | 771 | } |
772 | 772 | ||
773 | void ImageViewer::displayControlsDialog() | 773 | void ImageViewer::displayControlsDialog() |
774 | { | 774 | { |
775 | int w=80; | 775 | int w=80; |
776 | int h=w; | 776 | int h=w; |
777 | QImage small; | 777 | QImage small; |
778 | 778 | ||
779 | if ( image.width()<w ||image.height()<h ) | 779 | if ( image.width()<w ||image.height()<h ) |
780 | small=image.smoothScale(w,h); | 780 | small=image.smoothScale(w,h); |
781 | else | 781 | else |
782 | small=image.copy(0,0,w,h); | 782 | small=image.copy(0,0,w,h); |
783 | 783 | ||
784 | int newB=0; | 784 | int newB=0; |
785 | ControlsDialog *dlg=new ControlsDialog("Image Viewer",small,&newB,this); | 785 | ControlsDialog *dlg=new ControlsDialog("Image Viewer",small,&newB,this); |
786 | dlg->exec(); | 786 | dlg->exec(); |
787 | if ( newB ) { | 787 | if ( newB ) { |
788 | intensity(image,(float)newB/100); | 788 | intensity(image,(float)newB/100); |
789 | setImage(image); | 789 | setImage(image); |
790 | } | 790 | } |
791 | 791 | ||
792 | } | 792 | } |
793 | 793 | ||
794 | 794 | ||
795 | void ImageViewer::displayInfoDialog() | 795 | void ImageViewer::displayInfoDialog() |
796 | { | 796 | { |
797 | 797 | ||
798 | QStringList ls; | 798 | QStringList ls; |
799 | 799 | ||
800 | for ( int i=0;i<LAST;i++ ) | 800 | for ( int i=0;i<LAST;i++ ) |
801 | ls.append(imageInfo[i]); | 801 | ls.append(imageInfo[i]); |
802 | 802 | ||
803 | InfoDialog::displayInfo("Image Viewer",ls,this); | 803 | InfoDialog::displayInfo("Image Viewer",ls,this); |
804 | } | 804 | } |
805 | void ImageViewer::normalView() | 805 | void ImageViewer::normalView() |
806 | { | 806 | { |
807 | if ( !imagePanel->parentWidget() ) | 807 | if ( !imagePanel->parentWidget() ) |
808 | { | 808 | { |
809 | 809 | ||
810 | isFullScreen = FALSE; | 810 | isFullScreen = FALSE; |
811 | stack->addWidget( imagePanel, 1 ); | 811 | stack->addWidget( imagePanel, 1 ); |
812 | switchToImageView(); | 812 | switchToImageView(); |
813 | if ( isSized ) | 813 | if ( isSized ) |
814 | scale(); | 814 | scale(); |
815 | 815 | ||
816 | updateImage(); | 816 | updateImage(); |
817 | 817 | ||
818 | } | 818 | } |
819 | } | 819 | } |
820 | 820 | ||
821 | void ImageViewer::stopSlideShow() { | 821 | void ImageViewer::stopSlideShow() { |
822 | if (slideTimer->isActive()) | 822 | if (slideTimer->isActive()) |
823 | slideTimer->stop(); | 823 | slideTimer->stop(); |
824 | } | 824 | } |
825 | 825 | ||
826 | void ImageViewer::fullScreen() | 826 | void ImageViewer::fullScreen() |
827 | { | 827 | { |
828 | // Full-screen option | 828 | // Full-screen option |
829 | // contributed by Robert Wittams <robert@wittams.com> | 829 | // contributed by Robert Wittams <robert@wittams.com> |
830 | if ( imagePanel->parentWidget() && loadSelected() ) | 830 | if ( imagePanel->parentWidget() && loadSelected() ) |
831 | { | 831 | { |
832 | isFullScreen = TRUE; | 832 | isFullScreen = TRUE; |
833 | imagePanel->reparent(0,QPoint(0,0)); | 833 | imagePanel->reparent(0,QPoint(0,0)); |
834 | imagePanel->resize(qApp->desktop()->width(), qApp->desktop()->height()); | 834 | imagePanel->resize(qApp->desktop()->width(), qApp->desktop()->height()); |
835 | 835 | ||
836 | if ( isSized ) | 836 | if ( isSized ) |
837 | scale(); | 837 | scale(); |
838 | updateImage(); | 838 | updateImage(); |
839 | imagePanel->showFullScreen(); | 839 | imagePanel->showFullScreen(); |
840 | } | 840 | } |
841 | } | 841 | } |
842 | 842 | ||
843 | void ImageViewer::setImage(const QImage& newimage) | 843 | void ImageViewer::setImage(const QImage& newimage) |
844 | { | 844 | { |
845 | image = newimage; | 845 | image = newimage; |
846 | reconvertImage(); | 846 | reconvertImage(); |
847 | updateImage(); | 847 | updateImage(); |
848 | } | 848 | } |
849 | 849 | ||
850 | void ImageViewer::updateImageInfo(QString &filePath) | 850 | void ImageViewer::updateImageInfo(QString &filePath) |
851 | { | 851 | { |
852 | 852 | ||
853 | for ( int i=0;i<LAST;i++ ) | 853 | for ( int i=0;i<LAST;i++ ) |
854 | { | 854 | { |
855 | imageInfo[i]=""; | 855 | imageInfo[i]=""; |
856 | } | 856 | } |
857 | 857 | ||
858 | imageInfo[FORMAT]=QImage::imageFormat (filePath ); | 858 | imageInfo[FORMAT]=QImage::imageFormat (filePath ); |
859 | QFileInfo fi(filePath); | 859 | QFileInfo fi(filePath); |
860 | imageInfo[PATH]=fi.fileName(); | 860 | imageInfo[PATH]=fi.fileName(); |
861 | imageInfo[FILE_SIZE]=QString::number(fi.size())+" (bytes)"; | 861 | imageInfo[FILE_SIZE]=QString::number(fi.size())+" (bytes)"; |
862 | QString message("%1x%2"); | 862 | QString message("%1x%2"); |
863 | imageInfo[SIZE]=QString("%1x%2"); | 863 | imageInfo[SIZE]=QString("%1x%2"); |
864 | imageInfo[SIZE]=imageInfo[SIZE].arg(image.width()).arg(image.height()); | 864 | imageInfo[SIZE]=imageInfo[SIZE].arg(image.width()).arg(image.height()); |
865 | if ( image.numColors() > 0 ) | 865 | if ( image.numColors() > 0 ) |
866 | { | 866 | { |
867 | imageInfo[COLORS]=tr("%1 colors").arg(image.numColors()); | 867 | imageInfo[COLORS]=tr("%1 colors").arg(image.numColors()); |
868 | } | 868 | } |
869 | else if ( image.depth() >= 16 ) | 869 | else if ( image.depth() >= 16 ) |
870 | { | 870 | { |
871 | imageInfo[COLORS]=tr(" True color"); | 871 | imageInfo[COLORS]=tr(" True color"); |
872 | } | 872 | } |
873 | if ( image.hasAlphaBuffer() ) | 873 | if ( image.hasAlphaBuffer() ) |
874 | { | 874 | { |
875 | if ( image.depth() == 8 ) | 875 | if ( image.depth() == 8 ) |
876 | { | 876 | { |
877 | int i; | 877 | int i; |
878 | bool alpha[256]; | 878 | bool alpha[256]; |
879 | int nalpha=0; | 879 | int nalpha=0; |
880 | 880 | ||
881 | for ( i=0; i<256; i++ ) | 881 | for ( i=0; i<256; i++ ) |
882 | alpha[i] = FALSE; | 882 | alpha[i] = FALSE; |
883 | 883 | ||
884 | for ( i=0; i<image.numColors(); i++ ) | 884 | for ( i=0; i<image.numColors(); i++ ) |
885 | { | 885 | { |
886 | int alevel = image.color(i) >> 24; | 886 | int alevel = image.color(i) >> 24; |
887 | if ( !alpha[alevel] ) | 887 | if ( !alpha[alevel] ) |
888 | { | 888 | { |
889 | alpha[alevel] = TRUE; | 889 | alpha[alevel] = TRUE; |
890 | nalpha++; | 890 | nalpha++; |
891 | } | 891 | } |
892 | } | 892 | } |
893 | imageInfo[ALPHA]=tr("%1 alpha levels").arg(nalpha); | 893 | imageInfo[ALPHA]=tr("%1 alpha levels").arg(nalpha); |
894 | } | 894 | } |
895 | else | 895 | else |
896 | { | 896 | { |
897 | imageInfo[ALPHA]=tr("8-bit alpha channel"); | 897 | imageInfo[ALPHA]=tr("8-bit alpha channel"); |
898 | } | 898 | } |
899 | } | 899 | } |
900 | 900 | ||
901 | } | 901 | } |
902 | 902 | ||
903 | void ImageViewer::closeEvent( QCloseEvent *e ) | 903 | void ImageViewer::closeEvent( QCloseEvent *e ) |
904 | { | 904 | { |
905 | if ( stack->visibleWidget() == imagePanel && !bFromDocView ) | 905 | if ( stack->visibleWidget() == imagePanel && !bFromDocView ) |
906 | { | 906 | { |
907 | e->ignore(); | 907 | e->ignore(); |
908 | open(); | 908 | open(); |
909 | } | 909 | } |
910 | else | 910 | else |
911 | { | 911 | { |
912 | bFromDocView = FALSE; | 912 | bFromDocView = FALSE; |
913 | e->accept(); | 913 | e->accept(); |
914 | } | 914 | } |
915 | } | 915 | } |
916 | 916 | ||
917 | // Intensity,toGray and rotate code courtesy of KDE project. | 917 | // Intensity,toGray and rotate code courtesy of KDE project. |
918 | 918 | ||
919 | 919 | ||
920 | QImage& ImageViewer::intensity(QImage &image, float percent) | 920 | QImage& ImageViewer::intensity(QImage &image, float percent) |
921 | { | 921 | { |
922 | 922 | ||
923 | int segColors = image.depth() > 8 ? 256 : image.numColors(); | 923 | int segColors = image.depth() > 8 ? 256 : image.numColors(); |
924 | unsigned char *segTbl = new unsigned char[segColors]; | 924 | unsigned char *segTbl = new unsigned char[segColors]; |
925 | int pixels = image.depth() > 8 ? image.width()*image.height() : | 925 | int pixels = image.depth() > 8 ? image.width()*image.height() : |
926 | image.numColors(); | 926 | image.numColors(); |
927 | unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() : | 927 | unsigned int *data = image.depth() > 8 ? (unsigned int *)image.bits() : |
928 | (unsigned int *)image.colorTable(); | 928 | (unsigned int *)image.colorTable(); |
929 | 929 | ||
930 | bool brighten = (percent >= 0); | 930 | bool brighten = (percent >= 0); |
931 | if ( percent < 0 ) | 931 | if ( percent < 0 ) |
932 | percent = -percent; | 932 | percent = -percent; |
933 | 933 | ||
934 | if ( brighten ) | 934 | if ( brighten ) |
935 | { // keep overflow check out of loops | 935 | { // keep overflow check out of loops |
936 | for ( int i=0; i < segColors; ++i ) | 936 | for ( int i=0; i < segColors; ++i ) |
937 | { | 937 | { |
938 | int tmp = (int)(i*percent); | 938 | int tmp = (int)(i*percent); |
939 | if ( tmp > 255 ) | 939 | if ( tmp > 255 ) |
940 | tmp = 255; | 940 | tmp = 255; |
941 | segTbl[i] = tmp; | 941 | segTbl[i] = tmp; |
942 | } | 942 | } |
943 | } | 943 | } |
944 | else | 944 | else |
945 | { | 945 | { |
946 | for ( int i=0; i < segColors; ++i ) | 946 | for ( int i=0; i < segColors; ++i ) |
947 | { | 947 | { |
948 | int tmp = (int)(i*percent); | 948 | int tmp = (int)(i*percent); |
949 | if ( tmp < 0 ) | 949 | if ( tmp < 0 ) |
950 | tmp = 0; | 950 | tmp = 0; |
951 | segTbl[i] = tmp; | 951 | segTbl[i] = tmp; |
952 | } | 952 | } |
953 | } | 953 | } |
954 | 954 | ||
955 | if ( brighten ) | 955 | if ( brighten ) |
956 | { // same here | 956 | { // same here |
957 | for ( int i=0; i < pixels; ++i ) | 957 | for ( int i=0; i < pixels; ++i ) |
958 | { | 958 | { |
959 | int r = qRed(data[i]); | 959 | int r = qRed(data[i]); |
960 | int g = qGreen(data[i]); | 960 | int g = qGreen(data[i]); |
961 | int b = qBlue(data[i]); | 961 | int b = qBlue(data[i]); |
962 | int a = qAlpha(data[i]); | 962 | int a = qAlpha(data[i]); |
963 | r = r + segTbl[r] > 255 ? 255 : r + segTbl[r]; | 963 | r = r + segTbl[r] > 255 ? 255 : r + segTbl[r]; |
964 | g = g + segTbl[g] > 255 ? 255 : g + segTbl[g]; | 964 | g = g + segTbl[g] > 255 ? 255 : g + segTbl[g]; |
965 | b = b + segTbl[b] > 255 ? 255 : b + segTbl[b]; | 965 | b = b + segTbl[b] > 255 ? 255 : b + segTbl[b]; |
966 | data[i] = qRgba(r, g, b,a); | 966 | data[i] = qRgba(r, g, b,a); |
967 | } | 967 | } |
968 | } | 968 | } |
969 | else | 969 | else |
970 | { | 970 | { |
971 | for ( int i=0; i < pixels; ++i ) | 971 | for ( int i=0; i < pixels; ++i ) |
972 | { | 972 | { |
973 | int r = qRed(data[i]); | 973 | int r = qRed(data[i]); |
974 | int g = qGreen(data[i]); | 974 | int g = qGreen(data[i]); |
975 | int b = qBlue(data[i]); | 975 | int b = qBlue(data[i]); |
976 | int a = qAlpha(data[i]); | 976 | int a = qAlpha(data[i]); |
977 | r = r - segTbl[r] < 0 ? 0 : r - segTbl[r]; | 977 | r = r - segTbl[r] < 0 ? 0 : r - segTbl[r]; |
978 | g = g - segTbl[g] < 0 ? 0 : g - segTbl[g]; | 978 | g = g - segTbl[g] < 0 ? 0 : g - segTbl[g]; |
979 | b = b - segTbl[b] < 0 ? 0 : b - segTbl[b]; | 979 | b = b - segTbl[b] < 0 ? 0 : b - segTbl[b]; |
980 | data[i] = qRgba(r, g, b, a); | 980 | data[i] = qRgba(r, g, b, a); |
981 | } | 981 | } |
982 | } | 982 | } |
983 | delete [] segTbl; | 983 | delete [] segTbl; |
984 | 984 | ||
985 | return image; | 985 | return image; |
986 | } | 986 | } |
987 | 987 | ||
988 | QImage& ImageViewer::toGray(QImage &img, bool fast) | 988 | QImage& ImageViewer::toGray(QImage &img, bool fast) |
989 | { | 989 | { |
990 | if ( img.width() == 0 || img.height() == 0 ) | 990 | if ( img.width() == 0 || img.height() == 0 ) |
991 | return img; | 991 | return img; |
992 | 992 | ||
993 | if ( fast ) | 993 | if ( fast ) |
994 | { | 994 | { |
995 | if ( img.depth() == 32 ) | 995 | if ( img.depth() == 32 ) |
996 | { | 996 | { |
997 | register uchar * r(img.bits()); | 997 | register uchar * r(img.bits()); |
998 | register uchar * g(img.bits() + 1); | 998 | register uchar * g(img.bits() + 1); |
999 | register uchar * b(img.bits() + 2); | 999 | register uchar * b(img.bits() + 2); |
1000 | 1000 | ||
1001 | uchar * end(img.bits() + img.numBytes()); | 1001 | uchar * end(img.bits() + img.numBytes()); |
1002 | 1002 | ||
1003 | while ( r != end ) | 1003 | while ( r != end ) |
1004 | { | 1004 | { |
1005 | 1005 | ||
1006 | *r = *g = *b = (((*r + *g) >> 1) + *b) >> 1; // (r + b + g) / 3 | 1006 | *r = *g = *b = (((*r + *g) >> 1) + *b) >> 1; // (r + b + g) / 3 |
1007 | 1007 | ||
1008 | r += 4; | 1008 | r += 4; |
1009 | g += 4; | 1009 | g += 4; |
1010 | b += 4; | 1010 | b += 4; |
1011 | } | 1011 | } |
1012 | } | 1012 | } |
1013 | else | 1013 | else |
1014 | { | 1014 | { |
1015 | for ( int i = 0; i < img.numColors(); i++ ) | 1015 | for ( int i = 0; i < img.numColors(); i++ ) |
1016 | { | 1016 | { |
1017 | register uint r = qRed(img.color(i)); | 1017 | register uint r = qRed(img.color(i)); |
1018 | register uint g = qGreen(img.color(i)); | 1018 | register uint g = qGreen(img.color(i)); |
1019 | register uint b = qBlue(img.color(i)); | 1019 | register uint b = qBlue(img.color(i)); |
1020 | 1020 | ||
1021 | register uint gray = (((r + g) >> 1) + b) >> 1; | 1021 | register uint gray = (((r + g) >> 1) + b) >> 1; |
1022 | img.setColor(i, qRgba(gray, gray, gray, qAlpha(img.color(i)))); | 1022 | img.setColor(i, qRgba(gray, gray, gray, qAlpha(img.color(i)))); |
1023 | } | 1023 | } |
1024 | } | 1024 | } |
1025 | } | 1025 | } |
1026 | else | 1026 | else |
1027 | { | 1027 | { |
1028 | int pixels = img.depth() > 8 ? img.width()*img.height() : | 1028 | int pixels = img.depth() > 8 ? img.width()*img.height() : |
1029 | img.numColors(); | 1029 | img.numColors(); |
1030 | unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : | 1030 | unsigned int *data = img.depth() > 8 ? (unsigned int *)img.bits() : |
1031 | (unsigned int *)img.colorTable(); | 1031 | (unsigned int *)img.colorTable(); |
1032 | int val, i; | 1032 | int val, i; |
1033 | for ( i=0; i < pixels; ++i ) | 1033 | for ( i=0; i < pixels; ++i ) |
1034 | { | 1034 | { |
1035 | val = qGray(data[i]); | 1035 | val = qGray(data[i]); |
1036 | data[i] = qRgba(val, val, val, qAlpha(data[i])); | 1036 | data[i] = qRgba(val, val, val, qAlpha(data[i])); |
1037 | } | 1037 | } |
1038 | } | 1038 | } |
1039 | return img; | 1039 | return img; |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | 1042 | ||
1043 | QImage ImageViewer::rotate(QImage &img, RotateDirection r) | 1043 | QImage ImageViewer::rotate(QImage &img, RotateDirection r) |
1044 | { | 1044 | { |
1045 | QImage dest; | 1045 | QImage dest; |
1046 | int x, y; | 1046 | int x, y; |
1047 | if ( img.depth() > 8 ) | 1047 | if ( img.depth() > 8 ) |
1048 | { | 1048 | { |
1049 | unsigned int *srcData, *destData; | 1049 | unsigned int *srcData, *destData; |
1050 | switch ( r ) | 1050 | switch ( r ) |
1051 | { | 1051 | { |
1052 | case Rotate90: | 1052 | case Rotate90: |
1053 | dest.create(img.height(), img.width(), img.depth()); | 1053 | dest.create(img.height(), img.width(), img.depth()); |
1054 | for ( y=0; y < img.height(); ++y ) | 1054 | for ( y=0; y < img.height(); ++y ) |
1055 | { | 1055 | { |
1056 | srcData = (unsigned int *)img.scanLine(y); | 1056 | srcData = (unsigned int *)img.scanLine(y); |
1057 | for ( x=0; x < img.width(); ++x ) | 1057 | for ( x=0; x < img.width(); ++x ) |
1058 | { | 1058 | { |
1059 | destData = (unsigned int *)dest.scanLine(x); | 1059 | destData = (unsigned int *)dest.scanLine(x); |
1060 | destData[img.height()-y-1] = srcData[x]; | 1060 | destData[img.height()-y-1] = srcData[x]; |
1061 | } | 1061 | } |
1062 | } | 1062 | } |
1063 | break; | 1063 | break; |
1064 | case Rotate180: | 1064 | case Rotate180: |
1065 | dest.create(img.width(), img.height(), img.depth()); | 1065 | dest.create(img.width(), img.height(), img.depth()); |
1066 | for ( y=0; y < img.height(); ++y ) | 1066 | for ( y=0; y < img.height(); ++y ) |
1067 | { | 1067 | { |
1068 | srcData = (unsigned int *)img.scanLine(y); | 1068 | srcData = (unsigned int *)img.scanLine(y); |
1069 | destData = (unsigned int *)dest.scanLine(img.height()-y-1); | 1069 | destData = (unsigned int *)dest.scanLine(img.height()-y-1); |
1070 | for ( x=0; x < img.width(); ++x ) | 1070 | for ( x=0; x < img.width(); ++x ) |
1071 | destData[img.width()-x-1] = srcData[x]; | 1071 | destData[img.width()-x-1] = srcData[x]; |
1072 | } | 1072 | } |
1073 | break; | 1073 | break; |
1074 | case Rotate270: | 1074 | case Rotate270: |
1075 | dest.create(img.height(), img.width(), img.depth()); | 1075 | dest.create(img.height(), img.width(), img.depth()); |
1076 | for ( y=0; y < img.height(); ++y ) | 1076 | for ( y=0; y < img.height(); ++y ) |
1077 | { | 1077 | { |
1078 | srcData = (unsigned int *)img.scanLine(y); | 1078 | srcData = (unsigned int *)img.scanLine(y); |
1079 | for ( x=0; x < img.width(); ++x ) | 1079 | for ( x=0; x < img.width(); ++x ) |
1080 | { | 1080 | { |
1081 | destData = (unsigned int *)dest.scanLine(img.width()-x-1); | 1081 | destData = (unsigned int *)dest.scanLine(img.width()-x-1); |
1082 | destData[y] = srcData[x]; | 1082 | destData[y] = srcData[x]; |
1083 | } | 1083 | } |
1084 | } | 1084 | } |
1085 | break; | 1085 | break; |
1086 | default: | 1086 | default: |
1087 | dest = img; | 1087 | dest = img; |
1088 | break; | 1088 | break; |
1089 | } | 1089 | } |
1090 | } | 1090 | } |
1091 | else | 1091 | else |
1092 | { | 1092 | { |
1093 | unsigned char *srcData, *destData; | 1093 | unsigned char *srcData, *destData; |
1094 | unsigned int *srcTable, *destTable; | 1094 | unsigned int *srcTable, *destTable; |
1095 | switch ( r ) | 1095 | switch ( r ) |
1096 | { | 1096 | { |
1097 | case Rotate90: | 1097 | case Rotate90: |
1098 | dest.create(img.height(), img.width(), img.depth()); | 1098 | dest.create(img.height(), img.width(), img.depth()); |
1099 | dest.setNumColors(img.numColors()); | 1099 | dest.setNumColors(img.numColors()); |
1100 | srcTable = (unsigned int *)img.colorTable(); | 1100 | srcTable = (unsigned int *)img.colorTable(); |
1101 | destTable = (unsigned int *)dest.colorTable(); | 1101 | destTable = (unsigned int *)dest.colorTable(); |
1102 | for ( x=0; x < img.numColors(); ++x ) | 1102 | for ( x=0; x < img.numColors(); ++x ) |
1103 | destTable[x] = srcTable[x]; | 1103 | destTable[x] = srcTable[x]; |
1104 | for ( y=0; y < img.height(); ++y ) | 1104 | for ( y=0; y < img.height(); ++y ) |
1105 | { | 1105 | { |
1106 | srcData = (unsigned char *)img.scanLine(y); | 1106 | srcData = (unsigned char *)img.scanLine(y); |
1107 | for ( x=0; x < img.width(); ++x ) | 1107 | for ( x=0; x < img.width(); ++x ) |
1108 | { | 1108 | { |
1109 | destData = (unsigned char *)dest.scanLine(x); | 1109 | destData = (unsigned char *)dest.scanLine(x); |
1110 | destData[img.height()-y-1] = srcData[x]; | 1110 | destData[img.height()-y-1] = srcData[x]; |
1111 | } | 1111 | } |
1112 | } | 1112 | } |
1113 | break; | 1113 | break; |
1114 | case Rotate180: | 1114 | case Rotate180: |
1115 | dest.create(img.width(), img.height(), img.depth()); | 1115 | dest.create(img.width(), img.height(), img.depth()); |
1116 | dest.setNumColors(img.numColors()); | 1116 | dest.setNumColors(img.numColors()); |
1117 | srcTable = (unsigned int *)img.colorTable(); | 1117 | srcTable = (unsigned int *)img.colorTable(); |
1118 | destTable = (unsigned int *)dest.colorTable(); | 1118 | destTable = (unsigned int *)dest.colorTable(); |
1119 | for ( x=0; x < img.numColors(); ++x ) | 1119 | for ( x=0; x < img.numColors(); ++x ) |
1120 | destTable[x] = srcTable[x]; | 1120 | destTable[x] = srcTable[x]; |
1121 | for ( y=0; y < img.height(); ++y ) | 1121 | for ( y=0; y < img.height(); ++y ) |
1122 | { | 1122 | { |
1123 | srcData = (unsigned char *)img.scanLine(y); | 1123 | srcData = (unsigned char *)img.scanLine(y); |
1124 | destData = (unsigned char *)dest.scanLine(img.height()-y-1); | 1124 | destData = (unsigned char *)dest.scanLine(img.height()-y-1); |
1125 | for ( x=0; x < img.width(); ++x ) | 1125 | for ( x=0; x < img.width(); ++x ) |
1126 | destData[img.width()-x-1] = srcData[x]; | 1126 | destData[img.width()-x-1] = srcData[x]; |
1127 | } | 1127 | } |
1128 | break; | 1128 | break; |
1129 | case Rotate270: | 1129 | case Rotate270: |
1130 | dest.create(img.height(), img.width(), img.depth()); | 1130 | dest.create(img.height(), img.width(), img.depth()); |
1131 | dest.setNumColors(img.numColors()); | 1131 | dest.setNumColors(img.numColors()); |
1132 | srcTable = (unsigned int *)img.colorTable(); | 1132 | srcTable = (unsigned int *)img.colorTable(); |
1133 | destTable = (unsigned int *)dest.colorTable(); | 1133 | destTable = (unsigned int *)dest.colorTable(); |
1134 | for ( x=0; x < img.numColors(); ++x ) | 1134 | for ( x=0; x < img.numColors(); ++x ) |
1135 | destTable[x] = srcTable[x]; | 1135 | destTable[x] = srcTable[x]; |
1136 | for ( y=0; y < img.height(); ++y ) | 1136 | for ( y=0; y < img.height(); ++y ) |
1137 | { | 1137 | { |
1138 | srcData = (unsigned char *)img.scanLine(y); | 1138 | srcData = (unsigned char *)img.scanLine(y); |
1139 | for ( x=0; x < img.width(); ++x ) | 1139 | for ( x=0; x < img.width(); ++x ) |
1140 | { | 1140 | { |
1141 | destData = (unsigned char *)dest.scanLine(img.width()-x-1); | 1141 | destData = (unsigned char *)dest.scanLine(img.width()-x-1); |
1142 | destData[y] = srcData[x]; | 1142 | destData[y] = srcData[x]; |
1143 | } | 1143 | } |
1144 | } | 1144 | } |
1145 | break; | 1145 | break; |
1146 | default: | 1146 | default: |
1147 | dest = img; | 1147 | dest = img; |
1148 | break; | 1148 | break; |
1149 | } | 1149 | } |
1150 | 1150 | ||
1151 | } | 1151 | } |
1152 | return (dest); | 1152 | return (dest); |
1153 | } | 1153 | } |
1154 | 1154 | ||
1155 | void ImageViewer::slideShow( bool on ) | 1155 | void ImageViewer::slideShow( bool on ) |
1156 | { | 1156 | { |
1157 | if (on) { | 1157 | if (on) { |
1158 | if (!imageList.isEmpty()) { | 1158 | if (!imageList.isEmpty()) { |
1159 | slideTimer->start(slideDelay * 1000, FALSE); | 1159 | slideTimer->start(slideDelay * 1000, FALSE); |
1160 | filename = ""; // force restart | 1160 | filename = ""; // force restart |
1161 | slideReverse ? prevImage() : nextImage(); | 1161 | slideReverse ? prevImage() : nextImage(); |
1162 | } | 1162 | } |
1163 | } else { | 1163 | } else { |
1164 | slideTimer->stop(); | 1164 | slideTimer->stop(); |
1165 | slideAction->setOn( false); | 1165 | slideAction->setOn( false); |
1166 | } | 1166 | } |
1167 | } | 1167 | } |
1168 | 1168 | ||
1169 | void ImageViewer::slideUpdate() | 1169 | void ImageViewer::slideUpdate() |
1170 | { | 1170 | { |
1171 | bool final_image = slideReverse ? prevImage() : nextImage(); | 1171 | bool final_image = slideReverse ? prevImage() : nextImage(); |
1172 | 1172 | ||
1173 | if (final_image && !slideRepeat) { | 1173 | if (final_image && !slideRepeat) { |
1174 | slideTimer->stop(); | 1174 | slideTimer->stop(); |
1175 | slideAction->setOn(FALSE); | 1175 | slideAction->setOn(FALSE); |
1176 | } | 1176 | } |
1177 | } | 1177 | } |
1178 | 1178 | ||
1179 | // | 1179 | // |
1180 | // Display the image after the current one in the image list. | 1180 | // Display the image after the current one in the image list. |
1181 | // Return TRUE if the next call to nextImage() will wrap around to the | 1181 | // Return TRUE if the next call to nextImage() will wrap around to the |
1182 | // first image in the list (ie. we're now viewing the last image in the list). | 1182 | // first image in the list (ie. we're now viewing the last image in the list). |
1183 | // | 1183 | // |
1184 | bool ImageViewer::nextImage(void) | 1184 | bool ImageViewer::nextImage(void) |
1185 | { | 1185 | { |
1186 | int idx = 0; | 1186 | int idx = 0; |
1187 | 1187 | ||
1188 | if (imageList.count() > 0) { | 1188 | if (imageList.count() > 0) { |
1189 | idx = imageIndex(); | 1189 | idx = imageIndex(); |
1190 | if (idx != -1) { | 1190 | if (idx != -1) { |
1191 | if (idx == int(imageList.count() - 1)) { | 1191 | if (idx == int(imageList.count() - 1)) { |
1192 | idx = 0; | 1192 | idx = 0; |
1193 | } else { | 1193 | } else { |
1194 | idx++; | 1194 | idx++; |
1195 | } | 1195 | } |
1196 | } else { | 1196 | } else { |
1197 | idx = 0; | 1197 | idx = 0; |
1198 | } | 1198 | } |
1199 | openFile(imageList[idx]); | 1199 | openFile(imageList[idx]); |
1200 | } | 1200 | } |
1201 | 1201 | ||
1202 | return idx == int(imageList.count() - 1) ? TRUE : FALSE; | 1202 | return idx == int(imageList.count() - 1) ? TRUE : FALSE; |
1203 | } | 1203 | } |
1204 | 1204 | ||
1205 | // | 1205 | // |
1206 | // Display the image preceeding the current one in the image list. | 1206 | // Display the image preceeding the current one in the image list. |
1207 | // Return TRUE if the next call to prevImage() will wrap around to the last | 1207 | // Return TRUE if the next call to prevImage() will wrap around to the last |
1208 | // image in the list (ie. we're now viewing the first image in the list). | 1208 | // image in the list (ie. we're now viewing the first image in the list). |
1209 | // | 1209 | // |
1210 | bool ImageViewer::prevImage(void) | 1210 | bool ImageViewer::prevImage(void) |
1211 | { | 1211 | { |
1212 | int idx = -1; | 1212 | int idx = -1; |
1213 | 1213 | ||
1214 | if (imageList.count() > 0) { | 1214 | if (imageList.count() > 0) { |
1215 | idx = imageIndex(); | 1215 | idx = imageIndex(); |
1216 | if (idx != -1) { | 1216 | if (idx != -1) { |
1217 | if (idx == 0) { | 1217 | if (idx == 0) { |
1218 | idx = imageList.count() - 1; | 1218 | idx = imageList.count() - 1; |
1219 | } else { | 1219 | } else { |
1220 | idx--; | 1220 | idx--; |
1221 | } | 1221 | } |
1222 | } else { | 1222 | } else { |
1223 | idx = imageList.count() - 1; | 1223 | idx = imageList.count() - 1; |
1224 | } | 1224 | } |
1225 | openFile(imageList[idx]); | 1225 | openFile(imageList[idx]); |
1226 | } | 1226 | } |
1227 | 1227 | ||
1228 | return idx == 0 ? TRUE : FALSE; | 1228 | return idx == 0 ? TRUE : FALSE; |
1229 | } | 1229 | } |
1230 | 1230 | ||
1231 | // | 1231 | // |
1232 | // Return the index into the imageList of the currently viewed | 1232 | // Return the index into the imageList of the currently viewed |
1233 | // image (ie. ImageViewer::filename in ImageViewer::imageList). | 1233 | // image (ie. ImageViewer::filename in ImageViewer::imageList). |
1234 | // | 1234 | // |
1235 | int ImageViewer::imageIndex(void) | 1235 | int ImageViewer::imageIndex(void) |
1236 | { | 1236 | { |
1237 | QValueListConstIterator<DocLnk> i; | 1237 | QValueListConstIterator<DocLnk> i; |
1238 | int index; | 1238 | int index; |
1239 | 1239 | ||
1240 | if (imageList.count() == 0) { | 1240 | if (imageList.count() == 0) { |
1241 | return -1; | 1241 | return -1; |
1242 | } | 1242 | } |
1243 | 1243 | ||
1244 | for (index = 0, i = imageList.begin(); i != imageList.end(); ++i, index++) { | 1244 | for (index = 0, i = imageList.begin(); i != imageList.end(); ++i, index++) { |
1245 | if ((*i).file() == filename) { | 1245 | if ((*i).file() == filename) { |
1246 | return index; | 1246 | return index; |
1247 | } | 1247 | } |
1248 | } | 1248 | } |
1249 | 1249 | ||
1250 | return -1; | 1250 | return -1; |
1251 | } | 1251 | } |
diff --git a/noncore/multimedia/showimg/showimg.h b/noncore/multimedia/showimg/showimg.h index da4c0b6..9cf9bfd 100644 --- a/noncore/multimedia/showimg/showimg.h +++ b/noncore/multimedia/showimg/showimg.h | |||
@@ -1,289 +1,289 @@ | |||
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 | #ifndef SHOWIMG_H | 21 | #ifndef SHOWIMG_H |
22 | #define SHOWIMG_H | 22 | #define SHOWIMG_H |
23 | 23 | ||
24 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | #include <qmainwindow.h> | 25 | #include <qmainwindow.h> |
26 | #include <qimage.h> | 26 | #include <qimage.h> |
27 | #include <qlabel.h> | 27 | #include <qlabel.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qscrollview.h> | 29 | #include <qscrollview.h> |
30 | #include <qdialog.h> | 30 | #include <qdialog.h> |
31 | #include <qstringlist.h> | 31 | #include <qstringlist.h> |
32 | #include <qvaluelist.h> | 32 | #include <qvaluelist.h> |
33 | #include <qwmatrix.h> | 33 | #include <qwmatrix.h> |
34 | 34 | ||
35 | 35 | ||
36 | class QAction; | 36 | class QAction; |
37 | class QPEToolBar; | 37 | class QToolBar; |
38 | class QMenuBar; | 38 | class QMenuBar; |
39 | class QPopupMenu; | 39 | class QPopupMenu; |
40 | class QWidgetStack; | 40 | class QWidgetStack; |
41 | class FileSelector; | 41 | class FileSelector; |
42 | class DocLnk; | 42 | class DocLnk; |
43 | class QLabel; | 43 | class QLabel; |
44 | class QAction; | 44 | class QAction; |
45 | class QSpinBox; | 45 | class QSpinBox; |
46 | class ImageFileSelector; | 46 | class ImageFileSelector; |
47 | class QTimer; | 47 | class QTimer; |
48 | 48 | ||
49 | 49 | ||
50 | class ImageWidget : public QWidget | 50 | class ImageWidget : public QWidget |
51 | { | 51 | { |
52 | Q_OBJECT | 52 | Q_OBJECT |
53 | public: | 53 | public: |
54 | ImageWidget( QWidget *parent=0 ) | 54 | ImageWidget( QWidget *parent=0 ) |
55 | : QWidget( parent ) { | 55 | : QWidget( parent ) { |
56 | setBackgroundMode(NoBackground); | 56 | setBackgroundMode(NoBackground); |
57 | } | 57 | } |
58 | ~ImageWidget() { } | 58 | ~ImageWidget() { } |
59 | 59 | ||
60 | void setPixmap( const QPixmap &pm ) { | 60 | void setPixmap( const QPixmap &pm ) { |
61 | pixmap = pm; | 61 | pixmap = pm; |
62 | show(); | 62 | show(); |
63 | } | 63 | } |
64 | 64 | ||
65 | signals: | 65 | signals: |
66 | void clicked(); | 66 | void clicked(); |
67 | 67 | ||
68 | protected: | 68 | protected: |
69 | void paintEvent( QPaintEvent * ); | 69 | void paintEvent( QPaintEvent * ); |
70 | void mouseReleaseEvent(QMouseEvent* event); | 70 | void mouseReleaseEvent(QMouseEvent* event); |
71 | 71 | ||
72 | private: | 72 | private: |
73 | QPixmap pixmap; | 73 | QPixmap pixmap; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | class InfoDialog:public QDialog | 76 | class InfoDialog:public QDialog |
77 | { | 77 | { |
78 | Q_OBJECT | 78 | Q_OBJECT |
79 | 79 | ||
80 | public: | 80 | public: |
81 | 81 | ||
82 | static void displayInfo(const QString &caption, const QStringList text, QWidget *parent); | 82 | static void displayInfo(const QString &caption, const QStringList text, QWidget *parent); |
83 | 83 | ||
84 | private: | 84 | private: |
85 | 85 | ||
86 | InfoDialog(const QString &caption,const QStringList text, QWidget *parent); | 86 | InfoDialog(const QString &caption,const QStringList text, QWidget *parent); |
87 | 87 | ||
88 | }; | 88 | }; |
89 | 89 | ||
90 | class ControlsDialog:public QDialog | 90 | class ControlsDialog:public QDialog |
91 | { | 91 | { |
92 | Q_OBJECT | 92 | Q_OBJECT |
93 | 93 | ||
94 | public: | 94 | public: |
95 | ControlsDialog(const QString &caption,const QImage image,int *brightness, QWidget *parent); | 95 | ControlsDialog(const QString &caption,const QImage image,int *brightness, QWidget *parent); |
96 | 96 | ||
97 | 97 | ||
98 | private slots: | 98 | private slots: |
99 | 99 | ||
100 | void bValueChanged(int); | 100 | void bValueChanged(int); |
101 | void accept(); | 101 | void accept(); |
102 | 102 | ||
103 | 103 | ||
104 | private: | 104 | private: |
105 | ImageWidget *pixmap; | 105 | ImageWidget *pixmap; |
106 | QSpinBox *spb; | 106 | QSpinBox *spb; |
107 | QImage img; | 107 | QImage img; |
108 | int *b; | 108 | int *b; |
109 | }; | 109 | }; |
110 | 110 | ||
111 | 111 | ||
112 | class ImagePane : public QWidget | 112 | class ImagePane : public QWidget |
113 | { | 113 | { |
114 | Q_OBJECT | 114 | Q_OBJECT |
115 | public: | 115 | public: |
116 | ImagePane( QWidget *parent=0 ); | 116 | ImagePane( QWidget *parent=0 ); |
117 | ~ImagePane() { } | 117 | ~ImagePane() { } |
118 | 118 | ||
119 | //void showStatus(); | 119 | //void showStatus(); |
120 | //void hideStatus(); | 120 | //void hideStatus(); |
121 | //QLabel *statusLabel() | 121 | //QLabel *statusLabel() |
122 | //{ | 122 | //{ |
123 | // return status; | 123 | // return status; |
124 | //} | 124 | //} |
125 | void setPixmap( const QPixmap &pm ); | 125 | void setPixmap( const QPixmap &pm ); |
126 | 126 | ||
127 | 127 | ||
128 | int paneWidth() const { | 128 | int paneWidth() const { |
129 | return image->visibleWidth(); | 129 | return image->visibleWidth(); |
130 | } | 130 | } |
131 | 131 | ||
132 | int paneHeight() const { | 132 | int paneHeight() const { |
133 | return image->visibleHeight(); | 133 | return image->visibleHeight(); |
134 | } | 134 | } |
135 | 135 | ||
136 | void setPosition(int x, int y) { | 136 | void setPosition(int x, int y) { |
137 | image->setContentsPos (x,y ); | 137 | image->setContentsPos (x,y ); |
138 | } | 138 | } |
139 | 139 | ||
140 | void disable() { | 140 | void disable() { |
141 | pic->hide(); | 141 | pic->hide(); |
142 | } | 142 | } |
143 | 143 | ||
144 | signals: | 144 | signals: |
145 | void clicked(); | 145 | void clicked(); |
146 | 146 | ||
147 | private: | 147 | private: |
148 | QScrollView *image; | 148 | QScrollView *image; |
149 | ImageWidget *pic; | 149 | ImageWidget *pic; |
150 | QVBoxLayout *vb; | 150 | QVBoxLayout *vb; |
151 | 151 | ||
152 | private slots: | 152 | private slots: |
153 | void imageClicked(); | 153 | void imageClicked(); |
154 | }; | 154 | }; |
155 | 155 | ||
156 | 156 | ||
157 | class ImageViewer : public QMainWindow | 157 | class ImageViewer : public QMainWindow |
158 | { | 158 | { |
159 | Q_OBJECT | 159 | Q_OBJECT |
160 | public: | 160 | public: |
161 | static QString appName() { return QString::fromLatin1("showimg"); } | 161 | static QString appName() { return QString::fromLatin1("showimg"); } |
162 | ImageViewer( QWidget *parent=0, const char *name=0, int wFlags=0 ); | 162 | ImageViewer( QWidget *parent=0, const char *name=0, int wFlags=0 ); |
163 | ~ImageViewer(); | 163 | ~ImageViewer(); |
164 | 164 | ||
165 | void loadImage( const char *fileName ); | 165 | void loadImage( const char *fileName ); |
166 | void show(const QString& fileref); | 166 | void show(const QString& fileref); |
167 | void show(); | 167 | void show(); |
168 | 168 | ||
169 | 169 | ||
170 | enum INFO_STRINGS { | 170 | enum INFO_STRINGS { |
171 | PATH, | 171 | PATH, |
172 | FORMAT, | 172 | FORMAT, |
173 | FILE_SIZE, | 173 | FILE_SIZE, |
174 | SIZE, | 174 | SIZE, |
175 | COLORS, | 175 | COLORS, |
176 | ALPHA, | 176 | ALPHA, |
177 | LAST | 177 | LAST |
178 | }; | 178 | }; |
179 | 179 | ||
180 | enum RotateDirection { | 180 | enum RotateDirection { |
181 | Rotate90, Rotate180, Rotate270 | 181 | Rotate90, Rotate180, Rotate270 |
182 | }; | 182 | }; |
183 | 183 | ||
184 | 184 | ||
185 | static QImage rotate(QImage &img, RotateDirection r); | 185 | static QImage rotate(QImage &img, RotateDirection r); |
186 | static QImage& intensity(QImage &image, float percent); | 186 | static QImage& intensity(QImage &image, float percent); |
187 | static QImage& toGray(QImage &image, bool fast = false); | 187 | static QImage& toGray(QImage &image, bool fast = false); |
188 | bool showThumbView; // a flag to indicate if FileSelector should be initialized with thumbnail view | 188 | bool showThumbView; // a flag to indicate if FileSelector should be initialized with thumbnail view |
189 | 189 | ||
190 | protected: | 190 | protected: |
191 | void resizeEvent( QResizeEvent * ); | 191 | void resizeEvent( QResizeEvent * ); |
192 | void closeEvent( QCloseEvent * ); | 192 | void closeEvent( QCloseEvent * ); |
193 | 193 | ||
194 | private: | 194 | private: |
195 | int imageIndex(void); | 195 | int imageIndex(void); |
196 | 196 | ||
197 | void updateCaption( QString name ); | 197 | void updateCaption( QString name ); |
198 | bool loadSelected(); | 198 | bool loadSelected(); |
199 | void scale(); | 199 | void scale(); |
200 | bool reconvertImage(); | 200 | bool reconvertImage(); |
201 | int calcHeight(); | 201 | int calcHeight(); |
202 | void setImage(const QImage& newimage); | 202 | void setImage(const QImage& newimage); |
203 | void updateImageInfo(QString &filePath); | 203 | void updateImageInfo(QString &filePath); |
204 | void switchToFileSelector(); | 204 | void switchToFileSelector(); |
205 | void switchToImageView(); | 205 | void switchToImageView(); |
206 | 206 | ||
207 | void updateImage(); | 207 | void updateImage(); |
208 | 208 | ||
209 | private slots: | 209 | private slots: |
210 | 210 | ||
211 | void slideShow( bool on ); | 211 | void slideShow( bool on ); |
212 | void help(); | 212 | void help(); |
213 | void slideUpdate(); | 213 | void slideUpdate(); |
214 | bool nextImage(); | 214 | bool nextImage(); |
215 | bool prevImage(); | 215 | bool prevImage(); |
216 | void settings(); | 216 | void settings(); |
217 | 217 | ||
218 | void switchThumbView(); | 218 | void switchThumbView(); |
219 | void switchSizeToScreen(); | 219 | void switchSizeToScreen(); |
220 | void setDocument(const QString& fileref); | 220 | void setDocument(const QString& fileref); |
221 | void doDelayedLoad(); | 221 | void doDelayedLoad(); |
222 | void openFile( const DocLnk &file ); | 222 | void openFile( const DocLnk &file ); |
223 | void openFile(); | 223 | void openFile(); |
224 | void open(); | 224 | void open(); |
225 | void closeFileSelector(); | 225 | void closeFileSelector(); |
226 | void hFlip(); | 226 | void hFlip(); |
227 | void vFlip(); | 227 | void vFlip(); |
228 | void rot180(); | 228 | void rot180(); |
229 | void rot90(); | 229 | void rot90(); |
230 | void rot270(); | 230 | void rot270(); |
231 | void normalView(); | 231 | void normalView(); |
232 | void fullScreen(); | 232 | void fullScreen(); |
233 | void stopSlideShow(); | 233 | void stopSlideShow(); |
234 | void blackAndWhite(); | 234 | void blackAndWhite(); |
235 | void displayInfoDialog(); | 235 | void displayInfoDialog(); |
236 | void displayControlsDialog(); | 236 | void displayControlsDialog(); |
237 | private: | 237 | private: |
238 | QWMatrix matrix; | 238 | QWMatrix matrix; |
239 | bool rotated90; | 239 | bool rotated90; |
240 | enum MENU_ITEMS { | 240 | enum MENU_ITEMS { |
241 | SHOW_THUMBNAILS, | 241 | SHOW_THUMBNAILS, |
242 | SIZE_TO_SCREEN, | 242 | SIZE_TO_SCREEN, |
243 | BLACKANDWHITE | 243 | BLACKANDWHITE |
244 | }; | 244 | }; |
245 | 245 | ||
246 | QString filename; | 246 | QString filename; |
247 | QString delayLoad; | 247 | QString delayLoad; |
248 | QImage image; // the loaded image | 248 | QImage image; // the loaded image |
249 | QPixmap pm; // the converted pixmap | 249 | QPixmap pm; // the converted pixmap |
250 | QPixmap pmScaled; // the scaled pixmap | 250 | QPixmap pmScaled; // the scaled pixmap |
251 | QPEToolBar *toolBar; | 251 | QToolBar *toolBar; |
252 | QPEToolBar *iconToolBar; | 252 | QToolBar *iconToolBar; |
253 | QMenuBar *menuBar; | 253 | QMenuBar *menuBar; |
254 | QMenuBar *current; | 254 | QMenuBar *current; |
255 | 255 | ||
256 | 256 | ||
257 | QPopupMenu *fileMenuFile; | 257 | QPopupMenu *fileMenuFile; |
258 | QPopupMenu *viewMenuFile; | 258 | QPopupMenu *viewMenuFile; |
259 | QPopupMenu *optionsMenuFile; | 259 | QPopupMenu *optionsMenuFile; |
260 | QPopupMenu *fileMenuView; | 260 | QPopupMenu *fileMenuView; |
261 | QPopupMenu *viewMenuView; | 261 | QPopupMenu *viewMenuView; |
262 | 262 | ||
263 | QAction *sss; // scale to screen size | 263 | QAction *sss; // scale to screen size |
264 | 264 | ||
265 | QLabel *lab; | 265 | QLabel *lab; |
266 | ImagePane *imagePanel; | 266 | ImagePane *imagePanel; |
267 | QWidgetStack *stack; | 267 | QWidgetStack *stack; |
268 | //FileSelector *fileSelector; | 268 | //FileSelector *fileSelector; |
269 | ImageFileSelector *fileSelector; | 269 | ImageFileSelector *fileSelector; |
270 | bool isFullScreen; | 270 | bool isFullScreen; |
271 | bool isSized; // true if image is to be resized to fit the window size | 271 | bool isSized; // true if image is to be resized to fit the window size |
272 | bool bFromDocView; // a flag to indicate whether or not we were | 272 | bool bFromDocView; // a flag to indicate whether or not we were |
273 | // launched from the document view... | 273 | // launched from the document view... |
274 | 274 | ||
275 | int slideDelay; | 275 | int slideDelay; |
276 | bool slideRepeat; | 276 | bool slideRepeat; |
277 | bool slideReverse; // show slideshow in reverse order | 277 | bool slideReverse; // show slideshow in reverse order |
278 | bool rotateOnLoad; // rotate by 90 degrees on loading | 278 | bool rotateOnLoad; // rotate by 90 degrees on loading |
279 | bool fastLoad; | 279 | bool fastLoad; |
280 | QTimer *slideTimer; | 280 | QTimer *slideTimer; |
281 | QValueList<DocLnk> imageList; | 281 | QValueList<DocLnk> imageList; |
282 | QAction *slideAction; | 282 | QAction *slideAction; |
283 | 283 | ||
284 | 284 | ||
285 | QString imageInfo[LAST]; | 285 | QString imageInfo[LAST]; |
286 | }; | 286 | }; |
287 | 287 | ||
288 | 288 | ||
289 | #endif // SHOWIMG_H | 289 | #endif // SHOWIMG_H |
diff --git a/noncore/net/opieftp/opieftp.cpp b/noncore/net/opieftp/opieftp.cpp index 48629bf..3250627 100644 --- a/noncore/net/opieftp/opieftp.cpp +++ b/noncore/net/opieftp/opieftp.cpp | |||
@@ -1,1515 +1,1515 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | opieftp.cpp | 2 | opieftp.cpp |
3 | ------------------- | 3 | ------------------- |
4 | ** Created: Sat Mar 9 23:33:09 2002 | 4 | ** Created: Sat Mar 9 23:33:09 2002 |
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 | //#define DEVELOPERS_VERSION | 12 | //#define DEVELOPERS_VERSION |
13 | 13 | ||
14 | #include "opieftp.h" | 14 | #include "opieftp.h" |
15 | 15 | ||
16 | extern "C" { | 16 | extern "C" { |
17 | #include "../ftplib/ftplib.h" | 17 | #include "../ftplib/ftplib.h" |
18 | } | 18 | } |
19 | 19 | ||
20 | #include "inputDialog.h" | 20 | #include "inputDialog.h" |
21 | 21 | ||
22 | #include <qpe/qpemenubar.h> | 22 | #include <qmenubar.h> |
23 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/config.h> | 25 | #include <qpe/config.h> |
26 | #include <qpe/mimetype.h> | 26 | #include <qpe/mimetype.h> |
27 | 27 | ||
28 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #include <qpushbutton.h> | 29 | #include <qpushbutton.h> |
30 | #include <qtoolbutton.h> | 30 | #include <qtoolbutton.h> |
31 | #include <qcombobox.h> | 31 | #include <qcombobox.h> |
32 | #include <qlistview.h> | 32 | #include <qlistview.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | #include <qprogressbar.h> | 34 | #include <qprogressbar.h> |
35 | #include <qspinbox.h> | 35 | #include <qspinbox.h> |
36 | #include <qtabwidget.h> | 36 | #include <qtabwidget.h> |
37 | #include <qlayout.h> | 37 | #include <qlayout.h> |
38 | #include <qmessagebox.h> | 38 | #include <qmessagebox.h> |
39 | #include <qlineedit.h> | 39 | #include <qlineedit.h> |
40 | #include <qlistbox.h> | 40 | #include <qlistbox.h> |
41 | 41 | ||
42 | #include <unistd.h> | 42 | #include <unistd.h> |
43 | #include <stdlib.h> | 43 | #include <stdlib.h> |
44 | 44 | ||
45 | 45 | ||
46 | QProgressBar *ProgressBar; | 46 | QProgressBar *ProgressBar; |
47 | static netbuf *conn=NULL; | 47 | static netbuf *conn=NULL; |
48 | 48 | ||
49 | static int log_progress(netbuf *, int xfered, void *) | 49 | static int log_progress(netbuf *, int xfered, void *) |
50 | { | 50 | { |
51 | // int fsz = *(int *)arg; | 51 | // int fsz = *(int *)arg; |
52 | // int pct = (xfered * 100) / fsz; | 52 | // int pct = (xfered * 100) / fsz; |
53 | // printf("%3d%%\r", pct); | 53 | // printf("%3d%%\r", pct); |
54 | // fflush(stdout); | 54 | // fflush(stdout); |
55 | ProgressBar->setProgress(xfered); | 55 | ProgressBar->setProgress(xfered); |
56 | qApp->processEvents(); | 56 | qApp->processEvents(); |
57 | return 1; | 57 | return 1; |
58 | } | 58 | } |
59 | 59 | ||
60 | OpieFtp::OpieFtp( QWidget* parent, const char* name, WFlags fl) | 60 | OpieFtp::OpieFtp( QWidget* parent, const char* name, WFlags fl) |
61 | : QMainWindow( parent, name, fl ) | 61 | : QMainWindow( parent, name, fl ) |
62 | { | 62 | { |
63 | setCaption( tr( "OpieFtp" ) ); | 63 | setCaption( tr( "OpieFtp" ) ); |
64 | fuckeduphack=FALSE; | 64 | fuckeduphack=FALSE; |
65 | QGridLayout *layout = new QGridLayout( this ); | 65 | QGridLayout *layout = new QGridLayout( this ); |
66 | layout->setSpacing( 2); | 66 | layout->setSpacing( 2); |
67 | layout->setMargin( 2); | 67 | layout->setMargin( 2); |
68 | 68 | ||
69 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 69 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
70 | 70 | ||
71 | QMenuBar *menuBar = new QMenuBar(this); | 71 | QMenuBar *menuBar = new QMenuBar(this); |
72 | // QPEToolBar *menuBar = new QPEToolBar(this); | 72 | // QToolBar *menuBar = new QToolBar(this); |
73 | // menuBar->setHorizontalStretchable( TRUE ); | 73 | // menuBar->setHorizontalStretchable( TRUE ); |
74 | 74 | ||
75 | QWMatrix matrix; | 75 | QWMatrix matrix; |
76 | QPixmap pix(Resource::loadPixmap( "UnknownDocument" )); | 76 | QPixmap pix(Resource::loadPixmap( "UnknownDocument" )); |
77 | matrix.scale( .4, .4); | 77 | matrix.scale( .4, .4); |
78 | unknownXpm = pix.xForm(matrix); | 78 | unknownXpm = pix.xForm(matrix); |
79 | 79 | ||
80 | connectionMenu = new QPopupMenu( this ); | 80 | connectionMenu = new QPopupMenu( this ); |
81 | localMenu = new QPopupMenu( this ); | 81 | localMenu = new QPopupMenu( this ); |
82 | remoteMenu = new QPopupMenu( this ); | 82 | remoteMenu = new QPopupMenu( this ); |
83 | tabMenu = new QPopupMenu( this ); | 83 | tabMenu = new QPopupMenu( this ); |
84 | 84 | ||
85 | layout->addMultiCellWidget( menuBar, 0, 0, 0, 2 ); | 85 | layout->addMultiCellWidget( menuBar, 0, 0, 0, 2 ); |
86 | 86 | ||
87 | menuBar->insertItem( tr( "Connection" ), connectionMenu); | 87 | menuBar->insertItem( tr( "Connection" ), connectionMenu); |
88 | // menuBar->insertItem( tr( "Local" ), localMenu); | 88 | // menuBar->insertItem( tr( "Local" ), localMenu); |
89 | // menuBar->insertItem( tr( "Remote" ), remoteMenu); | 89 | // menuBar->insertItem( tr( "Remote" ), remoteMenu); |
90 | menuBar->insertItem( tr( "View" ), tabMenu); | 90 | menuBar->insertItem( tr( "View" ), tabMenu); |
91 | 91 | ||
92 | tabMenu->insertItem( tr( "Local" ), localMenu); | 92 | tabMenu->insertItem( tr( "Local" ), localMenu); |
93 | tabMenu->insertItem( tr( "Remote" ), remoteMenu); | 93 | tabMenu->insertItem( tr( "Remote" ), remoteMenu); |
94 | 94 | ||
95 | connectionMenu->insertItem( tr( "New" ), this, SLOT( newConnection() )); | 95 | connectionMenu->insertItem( tr( "New" ), this, SLOT( newConnection() )); |
96 | connectionMenu->insertItem( tr( "Connect" ), this, SLOT( connector() )); | 96 | connectionMenu->insertItem( tr( "Connect" ), this, SLOT( connector() )); |
97 | connectionMenu->insertItem( tr( "Disconnect" ), this, SLOT( disConnector() )); | 97 | connectionMenu->insertItem( tr( "Disconnect" ), this, SLOT( disConnector() )); |
98 | 98 | ||
99 | localMenu->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); | 99 | localMenu->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); |
100 | localMenu->insertSeparator(); | 100 | localMenu->insertSeparator(); |
101 | localMenu->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); | 101 | localMenu->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); |
102 | localMenu->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); | 102 | localMenu->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); |
103 | localMenu->insertItem( tr( "Rename" ), this, SLOT( localRename() )); | 103 | localMenu->insertItem( tr( "Rename" ), this, SLOT( localRename() )); |
104 | localMenu->insertSeparator(); | 104 | localMenu->insertSeparator(); |
105 | localMenu->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | 105 | localMenu->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); |
106 | localMenu->setCheckable(TRUE); | 106 | localMenu->setCheckable(TRUE); |
107 | 107 | ||
108 | remoteMenu->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); | 108 | remoteMenu->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); |
109 | remoteMenu->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); | 109 | remoteMenu->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); |
110 | remoteMenu->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); | 110 | remoteMenu->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); |
111 | remoteMenu->insertSeparator(); | 111 | remoteMenu->insertSeparator(); |
112 | remoteMenu->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); | 112 | remoteMenu->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); |
113 | 113 | ||
114 | tabMenu->insertSeparator(); | 114 | tabMenu->insertSeparator(); |
115 | tabMenu->insertItem( tr( "Switch to Local" ), this, SLOT( switchToLocalTab() )); | 115 | tabMenu->insertItem( tr( "Switch to Local" ), this, SLOT( switchToLocalTab() )); |
116 | tabMenu->insertItem( tr( "Switch to Remote" ), this, SLOT( switchToRemoteTab() )); | 116 | tabMenu->insertItem( tr( "Switch to Remote" ), this, SLOT( switchToRemoteTab() )); |
117 | tabMenu->insertItem( tr( "Switch to Config" ), this, SLOT( switchToConfigTab() )); | 117 | tabMenu->insertItem( tr( "Switch to Config" ), this, SLOT( switchToConfigTab() )); |
118 | tabMenu->insertSeparator(); | 118 | tabMenu->insertSeparator(); |
119 | // tabMenu->insertItem( tr( "About" ), this, SLOT( doAbout() )); | 119 | // tabMenu->insertItem( tr( "About" ), this, SLOT( doAbout() )); |
120 | tabMenu->setCheckable(TRUE); | 120 | tabMenu->setCheckable(TRUE); |
121 | 121 | ||
122 | 122 | ||
123 | 123 | ||
124 | cdUpButton = new QToolButton( this,"cdUpButton"); | 124 | cdUpButton = new QToolButton( this,"cdUpButton"); |
125 | cdUpButton->setPixmap(Resource::loadPixmap("up")); | 125 | cdUpButton->setPixmap(Resource::loadPixmap("up")); |
126 | cdUpButton ->setFixedSize( QSize( 20, 20 ) ); | 126 | cdUpButton ->setFixedSize( QSize( 20, 20 ) ); |
127 | connect( cdUpButton ,SIGNAL(released()),this,SLOT( upDir()) ); | 127 | connect( cdUpButton ,SIGNAL(released()),this,SLOT( upDir()) ); |
128 | layout->addMultiCellWidget( cdUpButton, 0, 0, 3, 3 ); | 128 | layout->addMultiCellWidget( cdUpButton, 0, 0, 3, 3 ); |
129 | cdUpButton->hide(); | 129 | cdUpButton->hide(); |
130 | 130 | ||
131 | // docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); | 131 | // docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); |
132 | // docButton->setFixedSize( QSize( 20, 20 ) ); | 132 | // docButton->setFixedSize( QSize( 20, 20 ) ); |
133 | // connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); | 133 | // connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); |
134 | // docButton->setFlat(TRUE); | 134 | // docButton->setFlat(TRUE); |
135 | // layout->addMultiCellWidget( docButton, 0, 0, 6, 6 ); | 135 | // layout->addMultiCellWidget( docButton, 0, 0, 6, 6 ); |
136 | 136 | ||
137 | homeButton = new QToolButton(this,"homeButton"); | 137 | homeButton = new QToolButton(this,"homeButton"); |
138 | homeButton->setPixmap( Resource::loadPixmap("home")); | 138 | homeButton->setPixmap( Resource::loadPixmap("home")); |
139 | homeButton->setFixedSize( QSize( 20, 20 ) ); | 139 | homeButton->setFixedSize( QSize( 20, 20 ) ); |
140 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); | 140 | connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); |
141 | layout->addMultiCellWidget( homeButton, 0, 0, 4, 4); | 141 | layout->addMultiCellWidget( homeButton, 0, 0, 4, 4); |
142 | homeButton->hide(); | 142 | homeButton->hide(); |
143 | 143 | ||
144 | TabWidget = new QTabWidget( this, "TabWidget" ); | 144 | TabWidget = new QTabWidget( this, "TabWidget" ); |
145 | layout->addMultiCellWidget( TabWidget, 1, 1, 0, 4 ); | 145 | layout->addMultiCellWidget( TabWidget, 1, 1, 0, 4 ); |
146 | 146 | ||
147 | // TabWidget->setTabShape(QTabWidget::Triangular); | 147 | // TabWidget->setTabShape(QTabWidget::Triangular); |
148 | 148 | ||
149 | tab = new QWidget( TabWidget, "tab" ); | 149 | tab = new QWidget( TabWidget, "tab" ); |
150 | tabLayout = new QGridLayout( tab ); | 150 | tabLayout = new QGridLayout( tab ); |
151 | tabLayout->setSpacing( 2); | 151 | tabLayout->setSpacing( 2); |
152 | tabLayout->setMargin( 2); | 152 | tabLayout->setMargin( 2); |
153 | 153 | ||
154 | Local_View = new QListView( tab, "Local_View" ); | 154 | Local_View = new QListView( tab, "Local_View" ); |
155 | // Local_View->setResizePolicy( QListView::AutoOneFit ); | 155 | // Local_View->setResizePolicy( QListView::AutoOneFit ); |
156 | Local_View->addColumn( tr("File"),150); | 156 | Local_View->addColumn( tr("File"),150); |
157 | Local_View->addColumn( tr("Date"),-1); | 157 | Local_View->addColumn( tr("Date"),-1); |
158 | Local_View->setColumnAlignment(1,QListView::AlignRight); | 158 | Local_View->setColumnAlignment(1,QListView::AlignRight); |
159 | Local_View->addColumn( tr("Size"),-1); | 159 | Local_View->addColumn( tr("Size"),-1); |
160 | Local_View->setColumnAlignment(2,QListView::AlignRight); | 160 | Local_View->setColumnAlignment(2,QListView::AlignRight); |
161 | Local_View->setAllColumnsShowFocus(TRUE); | 161 | Local_View->setAllColumnsShowFocus(TRUE); |
162 | 162 | ||
163 | Local_View->setMultiSelection( TRUE); | 163 | Local_View->setMultiSelection( TRUE); |
164 | Local_View->setSelectionMode(QListView::Extended); | 164 | Local_View->setSelectionMode(QListView::Extended); |
165 | Local_View->setFocusPolicy(QWidget::ClickFocus); | 165 | Local_View->setFocusPolicy(QWidget::ClickFocus); |
166 | 166 | ||
167 | QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold); | 167 | QPEApplication::setStylusOperation( Local_View->viewport(),QPEApplication::RightOnHold); |
168 | 168 | ||
169 | tabLayout->addWidget( Local_View, 0, 0 ); | 169 | tabLayout->addWidget( Local_View, 0, 0 ); |
170 | 170 | ||
171 | connect( Local_View, SIGNAL( clicked( QListViewItem*)), | 171 | connect( Local_View, SIGNAL( clicked( QListViewItem*)), |
172 | this,SLOT( localListClicked(QListViewItem *)) ); | 172 | this,SLOT( localListClicked(QListViewItem *)) ); |
173 | // connect( Local_View, SIGNAL( doubleClicked( QListViewItem*)), | 173 | // connect( Local_View, SIGNAL( doubleClicked( QListViewItem*)), |
174 | // this,SLOT( localListClicked(QListViewItem *)) ); | 174 | // this,SLOT( localListClicked(QListViewItem *)) ); |
175 | connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 175 | connect( Local_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
176 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); | 176 | this,SLOT( ListPressed(int, QListViewItem *, const QPoint&, int)) ); |
177 | 177 | ||
178 | TabWidget->insertTab( tab, tr( "Local" ) ); | 178 | TabWidget->insertTab( tab, tr( "Local" ) ); |
179 | 179 | ||
180 | tab_2 = new QWidget( TabWidget, "tab_2" ); | 180 | tab_2 = new QWidget( TabWidget, "tab_2" ); |
181 | tabLayout_2 = new QGridLayout( tab_2 ); | 181 | tabLayout_2 = new QGridLayout( tab_2 ); |
182 | tabLayout_2->setSpacing( 2); | 182 | tabLayout_2->setSpacing( 2); |
183 | tabLayout_2->setMargin( 2); | 183 | tabLayout_2->setMargin( 2); |
184 | 184 | ||
185 | Remote_View = new QListView( tab_2, "Remote_View" ); | 185 | Remote_View = new QListView( tab_2, "Remote_View" ); |
186 | Remote_View->addColumn( tr("File"),150); | 186 | Remote_View->addColumn( tr("File"),150); |
187 | Remote_View->addColumn( tr("Date"),-1); | 187 | Remote_View->addColumn( tr("Date"),-1); |
188 | // Remote_View->setColumnAlignment(1,QListView::AlignRight); | 188 | // Remote_View->setColumnAlignment(1,QListView::AlignRight); |
189 | Remote_View->addColumn( tr("Size"),-1); | 189 | Remote_View->addColumn( tr("Size"),-1); |
190 | Remote_View->setColumnAlignment(2,QListView::AlignRight); | 190 | Remote_View->setColumnAlignment(2,QListView::AlignRight); |
191 | Remote_View->setColumnAlignment(3,QListView::AlignCenter); | 191 | Remote_View->setColumnAlignment(3,QListView::AlignCenter); |
192 | Remote_View->addColumn( tr("Dir"),-1); | 192 | Remote_View->addColumn( tr("Dir"),-1); |
193 | Remote_View->setColumnAlignment(4,QListView::AlignRight); | 193 | Remote_View->setColumnAlignment(4,QListView::AlignRight); |
194 | Remote_View->setAllColumnsShowFocus(TRUE); | 194 | Remote_View->setAllColumnsShowFocus(TRUE); |
195 | 195 | ||
196 | Remote_View->setMultiSelection( FALSE); | 196 | Remote_View->setMultiSelection( FALSE); |
197 | Remote_View->setSelectionMode(QListView::Extended); | 197 | Remote_View->setSelectionMode(QListView::Extended); |
198 | Remote_View->setFocusPolicy(QWidget::ClickFocus); | 198 | Remote_View->setFocusPolicy(QWidget::ClickFocus); |
199 | 199 | ||
200 | QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); | 200 | QPEApplication::setStylusOperation( Remote_View->viewport(),QPEApplication::RightOnHold); |
201 | 201 | ||
202 | connect( Remote_View, SIGNAL( clicked( QListViewItem*)), | 202 | connect( Remote_View, SIGNAL( clicked( QListViewItem*)), |
203 | this,SLOT( remoteListClicked(QListViewItem *)) ); | 203 | this,SLOT( remoteListClicked(QListViewItem *)) ); |
204 | connect( Remote_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), | 204 | connect( Remote_View, SIGNAL( mouseButtonPressed( int, QListViewItem *, const QPoint&, int)), |
205 | this,SLOT( RemoteListPressed(int, QListViewItem *, const QPoint&, int)) ); | 205 | this,SLOT( RemoteListPressed(int, QListViewItem *, const QPoint&, int)) ); |
206 | 206 | ||
207 | tabLayout_2->addWidget( Remote_View, 0, 0 ); | 207 | tabLayout_2->addWidget( Remote_View, 0, 0 ); |
208 | 208 | ||
209 | TabWidget->insertTab( tab_2, tr( "Remote" ) ); | 209 | TabWidget->insertTab( tab_2, tr( "Remote" ) ); |
210 | 210 | ||
211 | tab_3 = new QWidget( TabWidget, "tab_3" ); | 211 | tab_3 = new QWidget( TabWidget, "tab_3" ); |
212 | tabLayout_3 = new QGridLayout( tab_3 ); | 212 | tabLayout_3 = new QGridLayout( tab_3 ); |
213 | tabLayout_3->setSpacing( 2); | 213 | tabLayout_3->setSpacing( 2); |
214 | tabLayout_3->setMargin( 2); | 214 | tabLayout_3->setMargin( 2); |
215 | 215 | ||
216 | TextLabel1 = new QLabel( tab_3, "TextLabel1" ); | 216 | TextLabel1 = new QLabel( tab_3, "TextLabel1" ); |
217 | TextLabel1->setText( tr( "Username" ) ); | 217 | TextLabel1->setText( tr( "Username" ) ); |
218 | tabLayout_3->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 ); | 218 | tabLayout_3->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 ); |
219 | 219 | ||
220 | UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" ); | 220 | UsernameComboBox = new QComboBox( FALSE, tab_3, "UsernameComboBox" ); |
221 | UsernameComboBox->setEditable(TRUE); | 221 | UsernameComboBox->setEditable(TRUE); |
222 | tabLayout_3->addMultiCellWidget( UsernameComboBox, 1, 1, 0, 1 ); | 222 | tabLayout_3->addMultiCellWidget( UsernameComboBox, 1, 1, 0, 1 ); |
223 | 223 | ||
224 | connect( UsernameComboBox,SIGNAL(textChanged(const QString &)),this, | 224 | connect( UsernameComboBox,SIGNAL(textChanged(const QString &)),this, |
225 | SLOT( UsernameComboBoxEdited(const QString & ) )); | 225 | SLOT( UsernameComboBoxEdited(const QString & ) )); |
226 | 226 | ||
227 | TextLabel2 = new QLabel( tab_3, "TextLabel2" ); | 227 | TextLabel2 = new QLabel( tab_3, "TextLabel2" ); |
228 | TextLabel2->setText( tr( "Password" ) ); | 228 | TextLabel2->setText( tr( "Password" ) ); |
229 | tabLayout_3->addMultiCellWidget( TextLabel2, 0, 0, 2, 3 ); | 229 | tabLayout_3->addMultiCellWidget( TextLabel2, 0, 0, 2, 3 ); |
230 | 230 | ||
231 | PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" ); | 231 | PasswordEdit = new QLineEdit( "", tab_3, "PasswordComboBox" ); |
232 | PasswordEdit->setEchoMode(QLineEdit::Password); | 232 | PasswordEdit->setEchoMode(QLineEdit::Password); |
233 | tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 ); | 233 | tabLayout_3->addMultiCellWidget( PasswordEdit, 1, 1, 2, 3 ); |
234 | 234 | ||
235 | connect( PasswordEdit,SIGNAL(textChanged(const QString &)),this, | 235 | connect( PasswordEdit,SIGNAL(textChanged(const QString &)),this, |
236 | SLOT( PasswordEditEdited(const QString & ) )); | 236 | SLOT( PasswordEditEdited(const QString & ) )); |
237 | 237 | ||
238 | //PasswordEdit->setFixedWidth(85); | 238 | //PasswordEdit->setFixedWidth(85); |
239 | TextLabel3 = new QLabel( tab_3, "TextLabel3" ); | 239 | TextLabel3 = new QLabel( tab_3, "TextLabel3" ); |
240 | TextLabel3->setText( tr( "Remote server" ) ); | 240 | TextLabel3->setText( tr( "Remote server" ) ); |
241 | tabLayout_3->addMultiCellWidget( TextLabel3, 2, 2, 0, 1 ); | 241 | tabLayout_3->addMultiCellWidget( TextLabel3, 2, 2, 0, 1 ); |
242 | 242 | ||
243 | ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" ); | 243 | ServerComboBox = new QComboBox( FALSE, tab_3, "ServerComboBox" ); |
244 | ServerComboBox->setEditable(TRUE); | 244 | ServerComboBox->setEditable(TRUE); |
245 | tabLayout_3->addMultiCellWidget( ServerComboBox, 3, 3, 0, 1 ); | 245 | tabLayout_3->addMultiCellWidget( ServerComboBox, 3, 3, 0, 1 ); |
246 | 246 | ||
247 | connect(ServerComboBox,SIGNAL(activated(int)),this,SLOT(serverComboSelected(int ) )); | 247 | connect(ServerComboBox,SIGNAL(activated(int)),this,SLOT(serverComboSelected(int ) )); |
248 | connect(ServerComboBox,SIGNAL(textChanged(const QString &)),this, | 248 | connect(ServerComboBox,SIGNAL(textChanged(const QString &)),this, |
249 | SLOT(serverComboEdited(const QString & ) )); | 249 | SLOT(serverComboEdited(const QString & ) )); |
250 | 250 | ||
251 | QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" ); | 251 | QLabel *TextLabel5 = new QLabel( tab_3, "TextLabel5" ); |
252 | TextLabel5->setText( tr( "Remote path" ) ); | 252 | TextLabel5->setText( tr( "Remote path" ) ); |
253 | tabLayout_3->addMultiCellWidget( TextLabel5, 2, 2, 2, 3 ); | 253 | tabLayout_3->addMultiCellWidget( TextLabel5, 2, 2, 2, 3 ); |
254 | 254 | ||
255 | 255 | ||
256 | remotePath = new QLineEdit( "/", tab_3, "remotePath" ); | 256 | remotePath = new QLineEdit( "/", tab_3, "remotePath" ); |
257 | tabLayout_3->addMultiCellWidget( remotePath, 3, 3, 2, 3 ); | 257 | tabLayout_3->addMultiCellWidget( remotePath, 3, 3, 2, 3 ); |
258 | TextLabel4 = new QLabel( tab_3, "TextLabel4" ); | 258 | TextLabel4 = new QLabel( tab_3, "TextLabel4" ); |
259 | TextLabel4->setText( tr( "Port" ) ); | 259 | TextLabel4->setText( tr( "Port" ) ); |
260 | tabLayout_3->addMultiCellWidget( TextLabel4, 4, 4, 0, 1 ); | 260 | tabLayout_3->addMultiCellWidget( TextLabel4, 4, 4, 0, 1 ); |
261 | 261 | ||
262 | PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" ); | 262 | PortSpinBox = new QSpinBox( tab_3, "PortSpinBox" ); |
263 | PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows ); | 263 | PortSpinBox->setButtonSymbols( QSpinBox::UpDownArrows ); |
264 | PortSpinBox->setMaxValue(32786); | 264 | PortSpinBox->setMaxValue(32786); |
265 | tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1); | 265 | tabLayout_3->addMultiCellWidget( PortSpinBox, 4, 4, 1, 1); |
266 | 266 | ||
267 | serverListView = new QListBox( tab_3, "ServerListView" ); | 267 | serverListView = new QListBox( tab_3, "ServerListView" ); |
268 | tabLayout_3->addMultiCellWidget( serverListView , 5, 5, 0, 5); | 268 | tabLayout_3->addMultiCellWidget( serverListView , 5, 5, 0, 5); |
269 | 269 | ||
270 | connect( serverListView, SIGNAL( highlighted( const QString &)), | 270 | connect( serverListView, SIGNAL( highlighted( const QString &)), |
271 | this,SLOT( serverListClicked( const QString &) ) ); | 271 | this,SLOT( serverListClicked( const QString &) ) ); |
272 | 272 | ||
273 | connectServerBtn = new QPushButton( tr("Connect"), tab_3 , "ConnectButton" ); | 273 | connectServerBtn = new QPushButton( tr("Connect"), tab_3 , "ConnectButton" ); |
274 | tabLayout_3->addMultiCellWidget( connectServerBtn, 6, 6, 0, 1); | 274 | tabLayout_3->addMultiCellWidget( connectServerBtn, 6, 6, 0, 1); |
275 | connectServerBtn->setToggleButton(TRUE); | 275 | connectServerBtn->setToggleButton(TRUE); |
276 | connect(connectServerBtn,SIGNAL( toggled( bool)),SLOT( connectorBtnToggled(bool) )); | 276 | connect(connectServerBtn,SIGNAL( toggled( bool)),SLOT( connectorBtnToggled(bool) )); |
277 | 277 | ||
278 | newServerButton= new QPushButton( tr("Add"), tab_3 , "NewServerButton" ); | 278 | newServerButton= new QPushButton( tr("Add"), tab_3 , "NewServerButton" ); |
279 | tabLayout_3->addMultiCellWidget( newServerButton, 6, 6, 2, 2); | 279 | tabLayout_3->addMultiCellWidget( newServerButton, 6, 6, 2, 2); |
280 | connect( newServerButton,SIGNAL( clicked()),SLOT( NewServer() )); | 280 | connect( newServerButton,SIGNAL( clicked()),SLOT( NewServer() )); |
281 | 281 | ||
282 | QPushButton *deleteServerBtn; | 282 | QPushButton *deleteServerBtn; |
283 | deleteServerBtn = new QPushButton( tr("Delete"), tab_3 , "OpenButton" ); | 283 | deleteServerBtn = new QPushButton( tr("Delete"), tab_3 , "OpenButton" ); |
284 | tabLayout_3->addMultiCellWidget( deleteServerBtn, 6, 6, 3, 3); | 284 | tabLayout_3->addMultiCellWidget( deleteServerBtn, 6, 6, 3, 3); |
285 | 285 | ||
286 | connect(deleteServerBtn,SIGNAL(clicked()),SLOT(deleteServer())); | 286 | connect(deleteServerBtn,SIGNAL(clicked()),SLOT(deleteServer())); |
287 | 287 | ||
288 | 288 | ||
289 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | 289 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); |
290 | tabLayout_3->addItem( spacer, 5, 0 ); | 290 | tabLayout_3->addItem( spacer, 5, 0 ); |
291 | 291 | ||
292 | TabWidget->insertTab( tab_3, tr( "Config" ) ); | 292 | TabWidget->insertTab( tab_3, tr( "Config" ) ); |
293 | 293 | ||
294 | connect(TabWidget,SIGNAL(currentChanged(QWidget *)), | 294 | connect(TabWidget,SIGNAL(currentChanged(QWidget *)), |
295 | this,SLOT(tabChanged(QWidget*))); | 295 | this,SLOT(tabChanged(QWidget*))); |
296 | 296 | ||
297 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 297 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); |
298 | currentDir.setPath( QDir::currentDirPath()); | 298 | currentDir.setPath( QDir::currentDirPath()); |
299 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 299 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
300 | 300 | ||
301 | currentPathCombo = new QComboBox( FALSE, this, "currentPathCombo" ); | 301 | currentPathCombo = new QComboBox( FALSE, this, "currentPathCombo" ); |
302 | layout->addMultiCellWidget( currentPathCombo, 3, 3, 0, 4); | 302 | layout->addMultiCellWidget( currentPathCombo, 3, 3, 0, 4); |
303 | currentPathCombo ->setFixedWidth(220); | 303 | currentPathCombo ->setFixedWidth(220); |
304 | currentPathCombo->setEditable(TRUE); | 304 | currentPathCombo->setEditable(TRUE); |
305 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); | 305 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); |
306 | 306 | ||
307 | connect( currentPathCombo, SIGNAL( activated( const QString & ) ), | 307 | connect( currentPathCombo, SIGNAL( activated( const QString & ) ), |
308 | this, SLOT( currentPathComboActivated( const QString & ) ) ); | 308 | this, SLOT( currentPathComboActivated( const QString & ) ) ); |
309 | 309 | ||
310 | connect( currentPathCombo->lineEdit(),SIGNAL(returnPressed()), | 310 | connect( currentPathCombo->lineEdit(),SIGNAL(returnPressed()), |
311 | this,SLOT(currentPathComboChanged())); | 311 | this,SLOT(currentPathComboChanged())); |
312 | 312 | ||
313 | ProgressBar = new QProgressBar( this, "ProgressBar" ); | 313 | ProgressBar = new QProgressBar( this, "ProgressBar" ); |
314 | layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 4); | 314 | layout->addMultiCellWidget( ProgressBar, 4, 4, 0, 4); |
315 | ProgressBar->setMaximumHeight(10); | 315 | ProgressBar->setMaximumHeight(10); |
316 | filterStr="*"; | 316 | filterStr="*"; |
317 | b=FALSE; | 317 | b=FALSE; |
318 | populateLocalView(); | 318 | populateLocalView(); |
319 | readConfig(); | 319 | readConfig(); |
320 | 320 | ||
321 | // ServerComboBox->setCurrentItem(currentServerConfig); | 321 | // ServerComboBox->setCurrentItem(currentServerConfig); |
322 | 322 | ||
323 | TabWidget->setCurrentPage(2); | 323 | TabWidget->setCurrentPage(2); |
324 | } | 324 | } |
325 | 325 | ||
326 | OpieFtp::~OpieFtp() | 326 | OpieFtp::~OpieFtp() |
327 | { | 327 | { |
328 | } | 328 | } |
329 | 329 | ||
330 | void OpieFtp::cleanUp() | 330 | void OpieFtp::cleanUp() |
331 | { | 331 | { |
332 | if(conn) | 332 | if(conn) |
333 | FtpQuit(conn); | 333 | FtpQuit(conn); |
334 | QString sfile=QDir::homeDirPath(); | 334 | QString sfile=QDir::homeDirPath(); |
335 | if(sfile.right(1) != "/") | 335 | if(sfile.right(1) != "/") |
336 | sfile+="/._temp"; | 336 | sfile+="/._temp"; |
337 | else | 337 | else |
338 | sfile+="._temp"; | 338 | sfile+="._temp"; |
339 | QFile file( sfile); | 339 | QFile file( sfile); |
340 | if(file.exists()) | 340 | if(file.exists()) |
341 | file.remove(); | 341 | file.remove(); |
342 | Config cfg("opieftp"); | 342 | Config cfg("opieftp"); |
343 | cfg.setGroup("Server"); | 343 | cfg.setGroup("Server"); |
344 | cfg.writeEntry("currentServer", currentServerConfig); | 344 | cfg.writeEntry("currentServer", currentServerConfig); |
345 | 345 | ||
346 | exit(0); | 346 | exit(0); |
347 | } | 347 | } |
348 | 348 | ||
349 | void OpieFtp::tabChanged(QWidget *) | 349 | void OpieFtp::tabChanged(QWidget *) |
350 | { | 350 | { |
351 | if (TabWidget->currentPageIndex() == 0) { | 351 | if (TabWidget->currentPageIndex() == 0) { |
352 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); | 352 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); |
353 | tabMenu->setItemChecked(tabMenu->idAt(0),TRUE); | 353 | tabMenu->setItemChecked(tabMenu->idAt(0),TRUE); |
354 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); | 354 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); |
355 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); | 355 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); |
356 | if(cdUpButton->isHidden()) | 356 | if(cdUpButton->isHidden()) |
357 | cdUpButton->show(); | 357 | cdUpButton->show(); |
358 | if(homeButton->isHidden()) | 358 | if(homeButton->isHidden()) |
359 | homeButton->show(); | 359 | homeButton->show(); |
360 | 360 | ||
361 | } | 361 | } |
362 | if (TabWidget->currentPageIndex() == 1) { | 362 | if (TabWidget->currentPageIndex() == 1) { |
363 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); | 363 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); |
364 | tabMenu->setItemChecked(tabMenu->idAt(1),TRUE); | 364 | tabMenu->setItemChecked(tabMenu->idAt(1),TRUE); |
365 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); | 365 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); |
366 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); | 366 | tabMenu->setItemChecked(tabMenu->idAt(2),FALSE); |
367 | if(cdUpButton->isHidden()) | 367 | if(cdUpButton->isHidden()) |
368 | cdUpButton->show(); | 368 | cdUpButton->show(); |
369 | homeButton->hide(); | 369 | homeButton->hide(); |
370 | 370 | ||
371 | } | 371 | } |
372 | if (TabWidget->currentPageIndex() == 2) { | 372 | if (TabWidget->currentPageIndex() == 2) { |
373 | tabMenu->setItemChecked(tabMenu->idAt(2),TRUE); | 373 | tabMenu->setItemChecked(tabMenu->idAt(2),TRUE); |
374 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); | 374 | tabMenu->setItemChecked(tabMenu->idAt(0),FALSE); |
375 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); | 375 | tabMenu->setItemChecked(tabMenu->idAt(1),FALSE); |
376 | cdUpButton->hide(); | 376 | cdUpButton->hide(); |
377 | homeButton->hide(); | 377 | homeButton->hide(); |
378 | } | 378 | } |
379 | } | 379 | } |
380 | 380 | ||
381 | void OpieFtp::newConnection() | 381 | void OpieFtp::newConnection() |
382 | { | 382 | { |
383 | UsernameComboBox->lineEdit()->setText(""); | 383 | UsernameComboBox->lineEdit()->setText(""); |
384 | PasswordEdit->setText( "" ); | 384 | PasswordEdit->setText( "" ); |
385 | ServerComboBox->lineEdit()->setText( ""); | 385 | ServerComboBox->lineEdit()->setText( ""); |
386 | remotePath->setText( currentRemoteDir = "/"); | 386 | remotePath->setText( currentRemoteDir = "/"); |
387 | PortSpinBox->setValue( 21); | 387 | PortSpinBox->setValue( 21); |
388 | TabWidget->setCurrentPage(2); | 388 | TabWidget->setCurrentPage(2); |
389 | } | 389 | } |
390 | 390 | ||
391 | void OpieFtp::serverComboEdited(const QString & ) | 391 | void OpieFtp::serverComboEdited(const QString & ) |
392 | { | 392 | { |
393 | // if( ServerComboBox->text(currentServerConfig) != edit /*edit.isEmpty() */) { | 393 | // if( ServerComboBox->text(currentServerConfig) != edit /*edit.isEmpty() */) { |
394 | // qDebug("ServerComboEdited"); | 394 | // qDebug("ServerComboEdited"); |
395 | // // currentServerConfig = -1; | 395 | // // currentServerConfig = -1; |
396 | // } | 396 | // } |
397 | } | 397 | } |
398 | 398 | ||
399 | void OpieFtp::UsernameComboBoxEdited(const QString &) { | 399 | void OpieFtp::UsernameComboBoxEdited(const QString &) { |
400 | // currentServerConfig = -1; | 400 | // currentServerConfig = -1; |
401 | } | 401 | } |
402 | 402 | ||
403 | void OpieFtp::PasswordEditEdited(const QString & ) { | 403 | void OpieFtp::PasswordEditEdited(const QString & ) { |
404 | // currentServerConfig = -1; | 404 | // currentServerConfig = -1; |
405 | } | 405 | } |
406 | 406 | ||
407 | void OpieFtp::connectorBtnToggled(bool On) | 407 | void OpieFtp::connectorBtnToggled(bool On) |
408 | { | 408 | { |
409 | if(On) { | 409 | if(On) { |
410 | connector(); | 410 | connector(); |
411 | } else { | 411 | } else { |
412 | disConnector(); | 412 | disConnector(); |
413 | } | 413 | } |
414 | 414 | ||
415 | } | 415 | } |
416 | 416 | ||
417 | void OpieFtp::connector() | 417 | void OpieFtp::connector() |
418 | { | 418 | { |
419 | // QCopEnvelope ( "QPE/System", "busy()" ); | 419 | // QCopEnvelope ( "QPE/System", "busy()" ); |
420 | // qApp->processEvents(); | 420 | // qApp->processEvents(); |
421 | currentRemoteDir=remotePath->text(); | 421 | currentRemoteDir=remotePath->text(); |
422 | 422 | ||
423 | if( ServerComboBox->currentText().isEmpty()) { | 423 | if( ServerComboBox->currentText().isEmpty()) { |
424 | 424 | ||
425 | QMessageBox::warning(this,tr("Ftp"),tr("Please set the server info"),tr("Ok"),0,0); | 425 | QMessageBox::warning(this,tr("Ftp"),tr("Please set the server info"),tr("Ok"),0,0); |
426 | TabWidget->setCurrentPage(2); | 426 | TabWidget->setCurrentPage(2); |
427 | ServerComboBox->setFocus(); | 427 | ServerComboBox->setFocus(); |
428 | connectServerBtn->setOn(FALSE); | 428 | connectServerBtn->setOn(FALSE); |
429 | connectServerBtn->setText( tr("Connect")); | 429 | connectServerBtn->setText( tr("Connect")); |
430 | return; | 430 | return; |
431 | } | 431 | } |
432 | 432 | ||
433 | FtpInit(); | 433 | FtpInit(); |
434 | 434 | ||
435 | TabWidget->setCurrentPage(1); | 435 | TabWidget->setCurrentPage(1); |
436 | QString ftp_host = ServerComboBox->currentText(); | 436 | QString ftp_host = ServerComboBox->currentText(); |
437 | QString ftp_user = UsernameComboBox->currentText(); | 437 | QString ftp_user = UsernameComboBox->currentText(); |
438 | QString ftp_pass = PasswordEdit->text(); | 438 | QString ftp_pass = PasswordEdit->text(); |
439 | QString port=PortSpinBox->cleanText(); | 439 | QString port=PortSpinBox->cleanText(); |
440 | port.stripWhiteSpace(); | 440 | port.stripWhiteSpace(); |
441 | 441 | ||
442 | Config cfg("opieftp"); | 442 | Config cfg("opieftp"); |
443 | cfg.setGroup("Server"); | 443 | cfg.setGroup("Server"); |
444 | // int current=cfg.readNumEntry("currentServer", 1); | 444 | // int current=cfg.readNumEntry("currentServer", 1); |
445 | 445 | ||
446 | // if(ftp_host!= cfg.readEntry(QString::number( current))) | 446 | // if(ftp_host!= cfg.readEntry(QString::number( current))) |
447 | // currentServerConfig=-1; | 447 | // currentServerConfig=-1; |
448 | // cfg.setGroup(QString::number(current)); | 448 | // cfg.setGroup(QString::number(current)); |
449 | // if( ftp_user != cfg.readEntry("Username")) | 449 | // if( ftp_user != cfg.readEntry("Username")) |
450 | // currentServerConfig=-1; | 450 | // currentServerConfig=-1; |
451 | // if(ftp_pass != cfg.readEntry(cfg.readEntry("Username"))) | 451 | // if(ftp_pass != cfg.readEntry(cfg.readEntry("Username"))) |
452 | // currentServerConfig=-1; | 452 | // currentServerConfig=-1; |
453 | 453 | ||
454 | 454 | ||
455 | if(ftp_host.find("ftp://",0, TRUE) != -1 ) | 455 | if(ftp_host.find("ftp://",0, TRUE) != -1 ) |
456 | ftp_host=ftp_host.right(ftp_host.length()-6); | 456 | ftp_host=ftp_host.right(ftp_host.length()-6); |
457 | ftp_host+=":"+port; | 457 | ftp_host+=":"+port; |
458 | 458 | ||
459 | if (!FtpConnect( ftp_host.latin1(), &conn)) { | 459 | if (!FtpConnect( ftp_host.latin1(), &conn)) { |
460 | QMessageBox::message(tr("Note"),tr("Unable to connect to\n")+ftp_host); | 460 | QMessageBox::message(tr("Note"),tr("Unable to connect to\n")+ftp_host); |
461 | connectServerBtn->setOn(FALSE); | 461 | connectServerBtn->setOn(FALSE); |
462 | connectServerBtn->setText( tr("Connect")); | 462 | connectServerBtn->setText( tr("Connect")); |
463 | return ; | 463 | return ; |
464 | } | 464 | } |
465 | 465 | ||
466 | if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { | 466 | if (!FtpLogin( ftp_user.latin1(), ftp_pass.latin1(),conn )) { |
467 | QString msg; | 467 | QString msg; |
468 | msg.sprintf(tr("Unable to log in\n")+"%s",FtpLastResponse(conn)); | 468 | msg.sprintf(tr("Unable to log in\n")+"%s",FtpLastResponse(conn)); |
469 | msg.replace(QRegExp(":"),"\n"); | 469 | msg.replace(QRegExp(":"),"\n"); |
470 | QMessageBox::message(tr("Note"),msg); | 470 | QMessageBox::message(tr("Note"),msg); |
471 | if(conn) | 471 | if(conn) |
472 | FtpQuit(conn); | 472 | FtpQuit(conn); |
473 | connectServerBtn->setOn(FALSE); | 473 | connectServerBtn->setOn(FALSE); |
474 | connectServerBtn->setText( tr("Connect")); | 474 | connectServerBtn->setText( tr("Connect")); |
475 | return ; | 475 | return ; |
476 | } | 476 | } |
477 | 477 | ||
478 | remoteDirList("/") ; | 478 | remoteDirList("/") ; |
479 | setCaption(ftp_host); | 479 | setCaption(ftp_host); |
480 | if( currentServerConfig == -1) | 480 | if( currentServerConfig == -1) |
481 | writeConfig(); | 481 | writeConfig(); |
482 | connectServerBtn->setText( tr("Disconnect")); | 482 | connectServerBtn->setText( tr("Disconnect")); |
483 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 483 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
484 | } | 484 | } |
485 | 485 | ||
486 | void OpieFtp::disConnector() | 486 | void OpieFtp::disConnector() |
487 | { | 487 | { |
488 | if(conn) | 488 | if(conn) |
489 | FtpQuit(conn); | 489 | FtpQuit(conn); |
490 | setCaption("OpieFtp"); | 490 | setCaption("OpieFtp"); |
491 | currentRemoteDir="/"; | 491 | currentRemoteDir="/"; |
492 | Remote_View->clear(); | 492 | Remote_View->clear(); |
493 | connectServerBtn->setText( tr("Connect")); | 493 | connectServerBtn->setText( tr("Connect")); |
494 | connectServerBtn->setOn(FALSE); | 494 | connectServerBtn->setOn(FALSE); |
495 | setCaption("OpieFtp"); | 495 | setCaption("OpieFtp"); |
496 | } | 496 | } |
497 | 497 | ||
498 | void OpieFtp::localUpload() | 498 | void OpieFtp::localUpload() |
499 | { | 499 | { |
500 | int fsz; | 500 | int fsz; |
501 | // QCopEnvelope ( "QPE/System", "busy()" ); | 501 | // QCopEnvelope ( "QPE/System", "busy()" ); |
502 | // qApp->processEvents(); | 502 | // qApp->processEvents(); |
503 | QList<QListViewItem> * getSelectedItems( QListView * Local_View ); | 503 | QList<QListViewItem> * getSelectedItems( QListView * Local_View ); |
504 | QListViewItemIterator it( Local_View ); | 504 | QListViewItemIterator it( Local_View ); |
505 | for ( ; it.current(); ++it ) { | 505 | for ( ; it.current(); ++it ) { |
506 | if ( it.current()->isSelected() ) { | 506 | if ( it.current()->isSelected() ) { |
507 | QString strItem = it.current()->text(0); | 507 | QString strItem = it.current()->text(0); |
508 | QString localFile = currentDir.canonicalPath()+"/"+strItem; | 508 | QString localFile = currentDir.canonicalPath()+"/"+strItem; |
509 | QString remoteFile= currentRemoteDir+strItem; | 509 | QString remoteFile= currentRemoteDir+strItem; |
510 | QFileInfo fi(localFile); | 510 | QFileInfo fi(localFile); |
511 | if( !fi.isDir()) { | 511 | if( !fi.isDir()) { |
512 | fsz=fi.size(); | 512 | fsz=fi.size(); |
513 | ProgressBar->setTotalSteps(fsz); | 513 | ProgressBar->setTotalSteps(fsz); |
514 | 514 | ||
515 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); | 515 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); |
516 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); | 516 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); |
517 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); | 517 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); |
518 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); | 518 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); |
519 | qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1()); | 519 | qDebug("Put: %s, %s",localFile.latin1(),remoteFile.latin1()); |
520 | 520 | ||
521 | if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { | 521 | if( !FtpPut( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { |
522 | QString msg; | 522 | QString msg; |
523 | msg.sprintf(tr("Unable to upload\n")+"%s",FtpLastResponse(conn)); | 523 | msg.sprintf(tr("Unable to upload\n")+"%s",FtpLastResponse(conn)); |
524 | msg.replace(QRegExp(":"),"\n"); | 524 | msg.replace(QRegExp(":"),"\n"); |
525 | QMessageBox::message(tr("Note"),msg); | 525 | QMessageBox::message(tr("Note"),msg); |
526 | } | 526 | } |
527 | } else { | 527 | } else { |
528 | QMessageBox::message(tr("Note"),tr("Cannot upload directories")); | 528 | QMessageBox::message(tr("Note"),tr("Cannot upload directories")); |
529 | } | 529 | } |
530 | ProgressBar->reset(); | 530 | ProgressBar->reset(); |
531 | nullifyCallBack(); | 531 | nullifyCallBack(); |
532 | it.current()->setSelected(FALSE); | 532 | it.current()->setSelected(FALSE); |
533 | } //end currentSelected | 533 | } //end currentSelected |
534 | } | 534 | } |
535 | for ( ; it.current(); ++it ) { | 535 | for ( ; it.current(); ++it ) { |
536 | Local_View->clearSelection(); | 536 | Local_View->clearSelection(); |
537 | } | 537 | } |
538 | Local_View->clearFocus(); | 538 | Local_View->clearFocus(); |
539 | TabWidget->setCurrentPage(1); | 539 | TabWidget->setCurrentPage(1); |
540 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 540 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
541 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 541 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
542 | } | 542 | } |
543 | 543 | ||
544 | void OpieFtp::nullifyCallBack() | 544 | void OpieFtp::nullifyCallBack() |
545 | { | 545 | { |
546 | FtpOptions(FTPLIB_CALLBACK, 0, conn); | 546 | FtpOptions(FTPLIB_CALLBACK, 0, conn); |
547 | FtpOptions(FTPLIB_IDLETIME, 0, conn); | 547 | FtpOptions(FTPLIB_IDLETIME, 0, conn); |
548 | FtpOptions(FTPLIB_CALLBACKARG, 0, conn); | 548 | FtpOptions(FTPLIB_CALLBACKARG, 0, conn); |
549 | FtpOptions(FTPLIB_CALLBACKBYTES, 0, conn); | 549 | FtpOptions(FTPLIB_CALLBACKBYTES, 0, conn); |
550 | } | 550 | } |
551 | 551 | ||
552 | void OpieFtp::remoteDownload() | 552 | void OpieFtp::remoteDownload() |
553 | { | 553 | { |
554 | // qApp->processEvents(); | 554 | // qApp->processEvents(); |
555 | int fsz; | 555 | int fsz; |
556 | // QCopEnvelope ( "QPE/System", "busy()" ); | 556 | // QCopEnvelope ( "QPE/System", "busy()" ); |
557 | 557 | ||
558 | QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); | 558 | QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); |
559 | QListViewItemIterator it( Remote_View ); | 559 | QListViewItemIterator it( Remote_View ); |
560 | for ( ; it.current(); ++it ) { | 560 | for ( ; it.current(); ++it ) { |
561 | if ( it.current()->isSelected() ) { | 561 | if ( it.current()->isSelected() ) { |
562 | QString strItem = it.current()->text(0); | 562 | QString strItem = it.current()->text(0); |
563 | // strItem=strItem.right(strItem.length()-1); | 563 | // strItem=strItem.right(strItem.length()-1); |
564 | QString localFile = currentDir.canonicalPath(); | 564 | QString localFile = currentDir.canonicalPath(); |
565 | if(localFile.right(1).find("/",0,TRUE) == -1) | 565 | if(localFile.right(1).find("/",0,TRUE) == -1) |
566 | localFile += "/"; | 566 | localFile += "/"; |
567 | localFile += strItem; | 567 | localFile += strItem; |
568 | // QString localFile = currentDir.canonicalPath()+"/"+strItem; | 568 | // QString localFile = currentDir.canonicalPath()+"/"+strItem; |
569 | QString remoteFile= currentRemoteDir+strItem; | 569 | QString remoteFile= currentRemoteDir+strItem; |
570 | if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn)) | 570 | if (!FtpSize( remoteFile.latin1(), &fsz, FTPLIB_ASCII, conn)) |
571 | fsz = 0; | 571 | fsz = 0; |
572 | QString temp; | 572 | QString temp; |
573 | temp.sprintf( remoteFile+" "+" %dkb", fsz); | 573 | temp.sprintf( remoteFile+" "+" %dkb", fsz); |
574 | 574 | ||
575 | ProgressBar->setTotalSteps(fsz); | 575 | ProgressBar->setTotalSteps(fsz); |
576 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); | 576 | FtpOptions(FTPLIB_CALLBACK, (long) log_progress, conn); |
577 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); | 577 | FtpOptions(FTPLIB_IDLETIME, (long) 1000, conn); |
578 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); | 578 | FtpOptions(FTPLIB_CALLBACKARG, (long) &fsz, conn); |
579 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); | 579 | FtpOptions(FTPLIB_CALLBACKBYTES, (long) fsz/10, conn); |
580 | qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1()); | 580 | qDebug("Get: %s, %s",localFile.latin1(),remoteFile.latin1()); |
581 | 581 | ||
582 | if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { | 582 | if(!FtpGet( localFile.latin1(), remoteFile.latin1(),FTPLIB_IMAGE, conn ) ) { |
583 | QString msg; | 583 | QString msg; |
584 | msg.sprintf(tr("Unable to download \n")+"%s",FtpLastResponse(conn)); | 584 | msg.sprintf(tr("Unable to download \n")+"%s",FtpLastResponse(conn)); |
585 | msg.replace(QRegExp(":"),"\n"); | 585 | msg.replace(QRegExp(":"),"\n"); |
586 | QMessageBox::message(tr("Note"),msg); | 586 | QMessageBox::message(tr("Note"),msg); |
587 | } | 587 | } |
588 | ProgressBar->reset(); | 588 | ProgressBar->reset(); |
589 | nullifyCallBack(); | 589 | nullifyCallBack(); |
590 | it.current()->setSelected(FALSE); | 590 | it.current()->setSelected(FALSE); |
591 | } | 591 | } |
592 | } | 592 | } |
593 | for ( ; it.current(); ++it ) { | 593 | for ( ; it.current(); ++it ) { |
594 | Remote_View->clearSelection(); | 594 | Remote_View->clearSelection(); |
595 | } | 595 | } |
596 | Remote_View->setFocus(); | 596 | Remote_View->setFocus(); |
597 | TabWidget->setCurrentPage(0); | 597 | TabWidget->setCurrentPage(0); |
598 | populateLocalView(); | 598 | populateLocalView(); |
599 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 599 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
600 | } | 600 | } |
601 | 601 | ||
602 | bool OpieFtp::remoteDirList(const QString &dir) | 602 | bool OpieFtp::remoteDirList(const QString &dir) |
603 | { | 603 | { |
604 | QString tmp = QDir::homeDirPath(); | 604 | QString tmp = QDir::homeDirPath(); |
605 | if(tmp.right(1) != "/") | 605 | if(tmp.right(1) != "/") |
606 | tmp+="/._temp"; | 606 | tmp+="/._temp"; |
607 | else | 607 | else |
608 | tmp+="._temp"; | 608 | tmp+="._temp"; |
609 | // qDebug("Listing remote dir "+tmp); | 609 | // qDebug("Listing remote dir "+tmp); |
610 | // QCopEnvelope ( "QPE/System", "busy()" ); | 610 | // QCopEnvelope ( "QPE/System", "busy()" ); |
611 | if (!FtpDir( tmp.latin1(), dir.latin1(), conn) ) { | 611 | if (!FtpDir( tmp.latin1(), dir.latin1(), conn) ) { |
612 | QString msg; | 612 | QString msg; |
613 | msg.sprintf(tr("Unable to list the directory\n")+dir+"\n%s",FtpLastResponse(conn) ); | 613 | msg.sprintf(tr("Unable to list the directory\n")+dir+"\n%s",FtpLastResponse(conn) ); |
614 | msg.replace(QRegExp(":"),"\n"); | 614 | msg.replace(QRegExp(":"),"\n"); |
615 | QMessageBox::message(tr("Note"),msg); | 615 | QMessageBox::message(tr("Note"),msg); |
616 | return false; | 616 | return false; |
617 | } | 617 | } |
618 | populateRemoteView() ; | 618 | populateRemoteView() ; |
619 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 619 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
620 | return true; | 620 | return true; |
621 | } | 621 | } |
622 | 622 | ||
623 | bool OpieFtp::remoteChDir(const QString &dir) | 623 | bool OpieFtp::remoteChDir(const QString &dir) |
624 | { | 624 | { |
625 | // QCopEnvelope ( "QPE/System", "busy()" ); | 625 | // QCopEnvelope ( "QPE/System", "busy()" ); |
626 | if (!FtpChdir( dir.latin1(), conn )) { | 626 | if (!FtpChdir( dir.latin1(), conn )) { |
627 | QString msg; | 627 | QString msg; |
628 | msg.sprintf(tr("Unable to change directories\n")+dir+"\n%s",FtpLastResponse(conn)); | 628 | msg.sprintf(tr("Unable to change directories\n")+dir+"\n%s",FtpLastResponse(conn)); |
629 | msg.replace(QRegExp(":"),"\n"); | 629 | msg.replace(QRegExp(":"),"\n"); |
630 | QMessageBox::message(tr("Note"),msg); | 630 | QMessageBox::message(tr("Note"),msg); |
631 | // qDebug(msg); | 631 | // qDebug(msg); |
632 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 632 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
633 | return FALSE; | 633 | return FALSE; |
634 | } | 634 | } |
635 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 635 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
636 | return TRUE; | 636 | return TRUE; |
637 | } | 637 | } |
638 | 638 | ||
639 | void OpieFtp::populateLocalView() | 639 | void OpieFtp::populateLocalView() |
640 | { | 640 | { |
641 | Local_View->clear(); | 641 | Local_View->clear(); |
642 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 642 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
643 | currentDir.setMatchAllDirs(TRUE); | 643 | currentDir.setMatchAllDirs(TRUE); |
644 | currentDir.setNameFilter(filterStr); | 644 | currentDir.setNameFilter(filterStr); |
645 | QString fileL, fileS, fileDate; | 645 | QString fileL, fileS, fileDate; |
646 | bool isDir=FALSE; | 646 | bool isDir=FALSE; |
647 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); | 647 | const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); |
648 | QFileInfoListIterator it(*list); | 648 | QFileInfoListIterator it(*list); |
649 | QFileInfo *fi; | 649 | QFileInfo *fi; |
650 | while ( (fi=it.current()) ) { | 650 | while ( (fi=it.current()) ) { |
651 | if (fi->isSymLink() ){ | 651 | if (fi->isSymLink() ){ |
652 | QString symLink=fi->readLink(); | 652 | QString symLink=fi->readLink(); |
653 | // qDebug("Symlink detected "+symLink); | 653 | // qDebug("Symlink detected "+symLink); |
654 | QFileInfo sym( symLink); | 654 | QFileInfo sym( symLink); |
655 | fileS.sprintf( "%10i", sym.size() ); | 655 | fileS.sprintf( "%10i", sym.size() ); |
656 | fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.absFilePath().data() ); | 656 | fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.absFilePath().data() ); |
657 | fileDate = sym.lastModified().toString(); | 657 | fileDate = sym.lastModified().toString(); |
658 | } else { | 658 | } else { |
659 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 659 | // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
660 | fileS.sprintf( "%10i", fi->size() ); | 660 | fileS.sprintf( "%10i", fi->size() ); |
661 | fileL.sprintf( "%s",fi->fileName().data() ); | 661 | fileL.sprintf( "%s",fi->fileName().data() ); |
662 | fileDate= fi->lastModified().toString(); | 662 | fileDate= fi->lastModified().toString(); |
663 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | 663 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { |
664 | fileL+="/"; | 664 | fileL+="/"; |
665 | isDir=TRUE; | 665 | isDir=TRUE; |
666 | // qDebug( fileL); | 666 | // qDebug( fileL); |
667 | } | 667 | } |
668 | } | 668 | } |
669 | if(fileL !="./" && fi->exists()) { | 669 | if(fileL !="./" && fi->exists()) { |
670 | item = new QListViewItem( Local_View,fileL, fileDate, fileS ); | 670 | item = new QListViewItem( Local_View,fileL, fileDate, fileS ); |
671 | QPixmap pm; | 671 | QPixmap pm; |
672 | 672 | ||
673 | if(isDir || fileL.find("/",0,TRUE) != -1) { | 673 | if(isDir || fileL.find("/",0,TRUE) != -1) { |
674 | if( !QDir( fi->filePath() ).isReadable()) | 674 | if( !QDir( fi->filePath() ).isReadable()) |
675 | pm = Resource::loadPixmap( "lockedfolder" ); | 675 | pm = Resource::loadPixmap( "lockedfolder" ); |
676 | else | 676 | else |
677 | pm= Resource::loadPixmap( "folder" ); | 677 | pm= Resource::loadPixmap( "folder" ); |
678 | item->setPixmap( 0,pm ); | 678 | item->setPixmap( 0,pm ); |
679 | } else { | 679 | } else { |
680 | if( !fi->isReadable() ) | 680 | if( !fi->isReadable() ) |
681 | pm = Resource::loadPixmap( "locked" ); | 681 | pm = Resource::loadPixmap( "locked" ); |
682 | else { | 682 | else { |
683 | MimeType mt(fi->filePath()); | 683 | MimeType mt(fi->filePath()); |
684 | pm=mt.pixmap(); //sets the correct pixmap for mimetype | 684 | pm=mt.pixmap(); //sets the correct pixmap for mimetype |
685 | if(pm.isNull()) | 685 | if(pm.isNull()) |
686 | pm = unknownXpm; | 686 | pm = unknownXpm; |
687 | } | 687 | } |
688 | } | 688 | } |
689 | if( fileL.find("->",0,TRUE) != -1) { | 689 | if( fileL.find("->",0,TRUE) != -1) { |
690 | // overlay link image | 690 | // overlay link image |
691 | pm= Resource::loadPixmap( "folder" ); | 691 | pm= Resource::loadPixmap( "folder" ); |
692 | QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); | 692 | QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); |
693 | QPainter painter( &pm ); | 693 | QPainter painter( &pm ); |
694 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | 694 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); |
695 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | 695 | pm.setMask( pm.createHeuristicMask( FALSE ) ); |
696 | } | 696 | } |
697 | item->setPixmap( 0,pm); | 697 | item->setPixmap( 0,pm); |
698 | } | 698 | } |
699 | isDir=FALSE; | 699 | isDir=FALSE; |
700 | ++it; | 700 | ++it; |
701 | } | 701 | } |
702 | Local_View->setSorting( 3,FALSE); | 702 | Local_View->setSorting( 3,FALSE); |
703 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath() ); | 703 | currentPathCombo->lineEdit()->setText( currentDir.canonicalPath() ); |
704 | fillCombo( (const QString &)currentDir); | 704 | fillCombo( (const QString &)currentDir); |
705 | } | 705 | } |
706 | 706 | ||
707 | bool OpieFtp::populateRemoteView( ) | 707 | bool OpieFtp::populateRemoteView( ) |
708 | { | 708 | { |
709 | // qDebug("populate remoteview"); | 709 | // qDebug("populate remoteview"); |
710 | QString sfile=QDir::homeDirPath(); | 710 | QString sfile=QDir::homeDirPath(); |
711 | if(sfile.right(1) != "/") | 711 | if(sfile.right(1) != "/") |
712 | sfile+="/._temp"; | 712 | sfile+="/._temp"; |
713 | else | 713 | else |
714 | sfile+="._temp"; | 714 | sfile+="._temp"; |
715 | QFile file( sfile); | 715 | QFile file( sfile); |
716 | Remote_View->clear(); | 716 | Remote_View->clear(); |
717 | QString s, File_Name; | 717 | QString s, File_Name; |
718 | QListViewItem *itemDir=NULL, *itemFile=NULL; | 718 | QListViewItem *itemDir=NULL, *itemFile=NULL; |
719 | QRegExp monthRe(" [JFMASOND][eapuecoe][brynlgptvc] [ 0-9][0-9] [ 0-9][0-9][:0-9][0-9][0-9] "); | 719 | QRegExp monthRe(" [JFMASOND][eapuecoe][brynlgptvc] [ 0-9][0-9] [ 0-9][0-9][:0-9][0-9][0-9] "); |
720 | QString fileL, fileS, fileDate; | 720 | QString fileL, fileS, fileDate; |
721 | if ( file.open(IO_ReadOnly)) { | 721 | if ( file.open(IO_ReadOnly)) { |
722 | QTextStream t( &file ); // use a text stream | 722 | QTextStream t( &file ); // use a text stream |
723 | while ( !t.eof()) { | 723 | while ( !t.eof()) { |
724 | s = t.readLine(); | 724 | s = t.readLine(); |
725 | 725 | ||
726 | if(s.find("total",0,TRUE) == 0) | 726 | if(s.find("total",0,TRUE) == 0) |
727 | continue; | 727 | continue; |
728 | 728 | ||
729 | int len, month = monthRe.match(s, 0, &len); | 729 | int len, month = monthRe.match(s, 0, &len); |
730 | fileDate = s.mid(month + 1, len - 2); // minus spaces | 730 | fileDate = s.mid(month + 1, len - 2); // minus spaces |
731 | fileL = s.right(s.length() - month - len); | 731 | fileL = s.right(s.length() - month - len); |
732 | if(s.left(1) == "d") | 732 | if(s.left(1) == "d") |
733 | fileL = fileL+"/"; | 733 | fileL = fileL+"/"; |
734 | fileS = s.mid(month - 8, 8); // FIXME | 734 | fileS = s.mid(month - 8, 8); // FIXME |
735 | fileS = fileS.stripWhiteSpace(); | 735 | fileS = fileS.stripWhiteSpace(); |
736 | 736 | ||
737 | if(s.left(1) == "d" || fileL.find("/",0,TRUE) != -1) { | 737 | if(s.left(1) == "d" || fileL.find("/",0,TRUE) != -1) { |
738 | QListViewItem * item = new QListViewItem( Remote_View, fileL, fileDate, fileS,"d"); | 738 | QListViewItem * item = new QListViewItem( Remote_View, fileL, fileDate, fileS,"d"); |
739 | item->setPixmap( 0, Resource::loadPixmap( "folder" )); | 739 | item->setPixmap( 0, Resource::loadPixmap( "folder" )); |
740 | // if(itemDir) | 740 | // if(itemDir) |
741 | item->moveItem(itemDir); | 741 | item->moveItem(itemDir); |
742 | itemDir=item; | 742 | itemDir=item; |
743 | } else { | 743 | } else { |
744 | QListViewItem * item = new QListViewItem( Remote_View, fileL, fileDate, fileS,"f"); | 744 | QListViewItem * item = new QListViewItem( Remote_View, fileL, fileDate, fileS,"f"); |
745 | item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); | 745 | item->setPixmap( 0, Resource::loadPixmap( "fileopen" )); |
746 | // if(itemFile) | 746 | // if(itemFile) |
747 | item->moveItem(itemDir); | 747 | item->moveItem(itemDir); |
748 | item->moveItem(itemFile); | 748 | item->moveItem(itemFile); |
749 | itemFile=item; | 749 | itemFile=item; |
750 | } | 750 | } |
751 | } | 751 | } |
752 | QListViewItem * item1 = new QListViewItem( Remote_View, "../"); | 752 | QListViewItem * item1 = new QListViewItem( Remote_View, "../"); |
753 | item1->setPixmap( 0, Resource::loadPixmap( "folder" )); | 753 | item1->setPixmap( 0, Resource::loadPixmap( "folder" )); |
754 | file.close(); | 754 | file.close(); |
755 | if( file.exists()) | 755 | if( file.exists()) |
756 | file. remove(); | 756 | file. remove(); |
757 | } else | 757 | } else |
758 | qDebug("temp file not opened successfullly "+sfile); | 758 | qDebug("temp file not opened successfullly "+sfile); |
759 | Remote_View->setSorting( 4,TRUE); | 759 | Remote_View->setSorting( 4,TRUE); |
760 | return true; | 760 | return true; |
761 | } | 761 | } |
762 | 762 | ||
763 | void OpieFtp::remoteListClicked(QListViewItem *selectedItem) | 763 | void OpieFtp::remoteListClicked(QListViewItem *selectedItem) |
764 | { | 764 | { |
765 | if( selectedItem) { | 765 | if( selectedItem) { |
766 | // if(selectedItem!= NULL) { | 766 | // if(selectedItem!= NULL) { |
767 | // QCopEnvelope ( "QPE/System", "busy()" ); | 767 | // QCopEnvelope ( "QPE/System", "busy()" ); |
768 | QString oldRemoteCurrentDir = currentRemoteDir; | 768 | QString oldRemoteCurrentDir = currentRemoteDir; |
769 | QString strItem=selectedItem->text(0); | 769 | QString strItem=selectedItem->text(0); |
770 | strItem=strItem.simplifyWhiteSpace(); | 770 | strItem=strItem.simplifyWhiteSpace(); |
771 | if(strItem == "../") { // the user wants to go ^ | 771 | if(strItem == "../") { // the user wants to go ^ |
772 | if( FtpCDUp( conn) == 0) { | 772 | if( FtpCDUp( conn) == 0) { |
773 | QString msg; | 773 | QString msg; |
774 | msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); | 774 | msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); |
775 | msg.replace(QRegExp(":"),"\n"); | 775 | msg.replace(QRegExp(":"),"\n"); |
776 | QMessageBox::message(tr("Note"),msg); | 776 | QMessageBox::message(tr("Note"),msg); |
777 | // qDebug(msg); | 777 | // qDebug(msg); |
778 | } | 778 | } |
779 | char path[256]; | 779 | char path[256]; |
780 | if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string | 780 | if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string |
781 | QString msg; | 781 | QString msg; |
782 | msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); | 782 | msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); |
783 | msg.replace(QRegExp(":"),"\n"); | 783 | msg.replace(QRegExp(":"),"\n"); |
784 | QMessageBox::message(tr("Note"),msg); | 784 | QMessageBox::message(tr("Note"),msg); |
785 | // qDebug(msg); | 785 | // qDebug(msg); |
786 | } | 786 | } |
787 | currentRemoteDir=path; | 787 | currentRemoteDir=path; |
788 | } else { | 788 | } else { |
789 | if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers | 789 | if(strItem.find("->",0,TRUE) != -1) { //symlink on some servers |
790 | strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 ); | 790 | strItem=strItem.right( strItem.length() - strItem.find("->",0,TRUE) - 2 ); |
791 | strItem = strItem.stripWhiteSpace(); | 791 | strItem = strItem.stripWhiteSpace(); |
792 | currentRemoteDir = strItem; | 792 | currentRemoteDir = strItem; |
793 | if( !remoteChDir( (const QString &)strItem)) { | 793 | if( !remoteChDir( (const QString &)strItem)) { |
794 | currentRemoteDir = oldRemoteCurrentDir; | 794 | currentRemoteDir = oldRemoteCurrentDir; |
795 | strItem=""; | 795 | strItem=""; |
796 | // qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); | 796 | // qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); |
797 | } | 797 | } |
798 | } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory | 798 | } else if(strItem.find("/",0,TRUE) != -1) { // this is a directory |
799 | if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) { | 799 | if( !remoteChDir( (const QString &)currentRemoteDir + strItem)) { |
800 | currentRemoteDir = oldRemoteCurrentDir; | 800 | currentRemoteDir = oldRemoteCurrentDir; |
801 | strItem=""; | 801 | strItem=""; |
802 | // qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); | 802 | // qDebug("RemoteCurrentDir1 "+oldRemoteCurrentDir); |
803 | 803 | ||
804 | } else { | 804 | } else { |
805 | currentRemoteDir = currentRemoteDir+strItem; | 805 | currentRemoteDir = currentRemoteDir+strItem; |
806 | } | 806 | } |
807 | } else { | 807 | } else { |
808 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 808 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
809 | return; | 809 | return; |
810 | } | 810 | } |
811 | } | 811 | } |
812 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 812 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
813 | if(currentRemoteDir.right(1) !="/") | 813 | if(currentRemoteDir.right(1) !="/") |
814 | currentRemoteDir +="/"; | 814 | currentRemoteDir +="/"; |
815 | currentPathCombo->lineEdit()->setText( currentRemoteDir); | 815 | currentPathCombo->lineEdit()->setText( currentRemoteDir); |
816 | fillRemoteCombo( (const QString &)currentRemoteDir); | 816 | fillRemoteCombo( (const QString &)currentRemoteDir); |
817 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 817 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
818 | Remote_View->ensureItemVisible(Remote_View->firstChild()); | 818 | Remote_View->ensureItemVisible(Remote_View->firstChild()); |
819 | 819 | ||
820 | } | 820 | } |
821 | } | 821 | } |
822 | 822 | ||
823 | void OpieFtp::localListClicked(QListViewItem *selectedItem) | 823 | void OpieFtp::localListClicked(QListViewItem *selectedItem) |
824 | { | 824 | { |
825 | if(selectedItem!= NULL) { | 825 | if(selectedItem!= NULL) { |
826 | 826 | ||
827 | QString strItem=selectedItem->text(0); | 827 | QString strItem=selectedItem->text(0); |
828 | QString strSize=selectedItem->text(1); | 828 | QString strSize=selectedItem->text(1); |
829 | strSize=strSize.stripWhiteSpace(); | 829 | strSize=strSize.stripWhiteSpace(); |
830 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | 830 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink |
831 | // is symlink | 831 | // is symlink |
832 | QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); | 832 | QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); |
833 | if(QDir(strItem2).exists() ) { | 833 | if(QDir(strItem2).exists() ) { |
834 | currentDir.cd(strItem2, TRUE); | 834 | currentDir.cd(strItem2, TRUE); |
835 | populateLocalView(); | 835 | populateLocalView(); |
836 | } | 836 | } |
837 | } else { // not a symlink | 837 | } else { // not a symlink |
838 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | 838 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { |
839 | 839 | ||
840 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { | 840 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { |
841 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 841 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
842 | currentDir.cd(strItem,FALSE); | 842 | currentDir.cd(strItem,FALSE); |
843 | populateLocalView(); | 843 | populateLocalView(); |
844 | } else { | 844 | } else { |
845 | currentDir.cdUp(); | 845 | currentDir.cdUp(); |
846 | populateLocalView(); | 846 | populateLocalView(); |
847 | } | 847 | } |
848 | if(QDir(strItem).exists()){ | 848 | if(QDir(strItem).exists()){ |
849 | currentDir.cd(strItem, TRUE); | 849 | currentDir.cd(strItem, TRUE); |
850 | populateLocalView(); | 850 | populateLocalView(); |
851 | } | 851 | } |
852 | } else { | 852 | } else { |
853 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 853 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
854 | if( QFile::exists(strItem ) ) { | 854 | if( QFile::exists(strItem ) ) { |
855 | // qDebug("upload "+strItem); | 855 | // qDebug("upload "+strItem); |
856 | return; | 856 | return; |
857 | } | 857 | } |
858 | } //end not symlink | 858 | } //end not symlink |
859 | chdir(strItem.latin1()); | 859 | chdir(strItem.latin1()); |
860 | } | 860 | } |
861 | Local_View->ensureItemVisible(Local_View->firstChild()); | 861 | Local_View->ensureItemVisible(Local_View->firstChild()); |
862 | } | 862 | } |
863 | } | 863 | } |
864 | 864 | ||
865 | void OpieFtp::doLocalCd() | 865 | void OpieFtp::doLocalCd() |
866 | { | 866 | { |
867 | localListClicked( Local_View->currentItem()); | 867 | localListClicked( Local_View->currentItem()); |
868 | } | 868 | } |
869 | 869 | ||
870 | void OpieFtp:: doRemoteCd() | 870 | void OpieFtp:: doRemoteCd() |
871 | { | 871 | { |
872 | remoteListClicked( Remote_View->currentItem()); | 872 | remoteListClicked( Remote_View->currentItem()); |
873 | 873 | ||
874 | } | 874 | } |
875 | 875 | ||
876 | void OpieFtp::showHidden() | 876 | void OpieFtp::showHidden() |
877 | { | 877 | { |
878 | if (!b) { | 878 | if (!b) { |
879 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | 879 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); |
880 | localMenu->setItemChecked(localMenu->idAt(0),TRUE); | 880 | localMenu->setItemChecked(localMenu->idAt(0),TRUE); |
881 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 881 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
882 | b=TRUE; | 882 | b=TRUE; |
883 | 883 | ||
884 | } else { | 884 | } else { |
885 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 885 | currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); |
886 | localMenu->setItemChecked(localMenu->idAt(0),FALSE); | 886 | localMenu->setItemChecked(localMenu->idAt(0),FALSE); |
887 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 887 | // currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
888 | b=FALSE; | 888 | b=FALSE; |
889 | } | 889 | } |
890 | populateLocalView(); | 890 | populateLocalView(); |
891 | } | 891 | } |
892 | 892 | ||
893 | void OpieFtp::ListPressed( int mouse, QListViewItem *item, const QPoint &, int) | 893 | void OpieFtp::ListPressed( int mouse, QListViewItem *item, const QPoint &, int) |
894 | { | 894 | { |
895 | // if(item) | 895 | // if(item) |
896 | if (mouse == 2) { | 896 | if (mouse == 2) { |
897 | showLocalMenu(item); | 897 | showLocalMenu(item); |
898 | } | 898 | } |
899 | } | 899 | } |
900 | 900 | ||
901 | void OpieFtp::RemoteListPressed( int mouse, QListViewItem *item, const QPoint &, int ) | 901 | void OpieFtp::RemoteListPressed( int mouse, QListViewItem *item, const QPoint &, int ) |
902 | { | 902 | { |
903 | if(mouse == 2) { | 903 | if(mouse == 2) { |
904 | showRemoteMenu(item); | 904 | showRemoteMenu(item); |
905 | } | 905 | } |
906 | } | 906 | } |
907 | 907 | ||
908 | void OpieFtp::showRemoteMenu(QListViewItem * item) | 908 | void OpieFtp::showRemoteMenu(QListViewItem * item) |
909 | { | 909 | { |
910 | QPopupMenu * m;// = new QPopupMenu( Local_View ); | 910 | QPopupMenu * m;// = new QPopupMenu( Local_View ); |
911 | m = new QPopupMenu(this); | 911 | m = new QPopupMenu(this); |
912 | if(item != NULL ) { | 912 | if(item != NULL ) { |
913 | if( item->text(0).find("/",0,TRUE) != -1) | 913 | if( item->text(0).find("/",0,TRUE) != -1) |
914 | m->insertItem( tr( "Change Directory" ), this, SLOT( doRemoteCd() )); | 914 | m->insertItem( tr( "Change Directory" ), this, SLOT( doRemoteCd() )); |
915 | else | 915 | else |
916 | m->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); | 916 | m->insertItem( tr( "Download" ), this, SLOT( remoteDownload() )); |
917 | } | 917 | } |
918 | m->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); | 918 | m->insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); |
919 | m->insertItem( tr("Rescan"), this, SLOT( populateLocalView() )); | 919 | m->insertItem( tr("Rescan"), this, SLOT( populateLocalView() )); |
920 | m->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); | 920 | m->insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); |
921 | m->insertSeparator(); | 921 | m->insertSeparator(); |
922 | m->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); | 922 | m->insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); |
923 | m->exec( QCursor::pos() ); | 923 | m->exec( QCursor::pos() ); |
924 | delete m; | 924 | delete m; |
925 | } | 925 | } |
926 | 926 | ||
927 | void OpieFtp::showLocalMenu(QListViewItem * item) | 927 | void OpieFtp::showLocalMenu(QListViewItem * item) |
928 | { | 928 | { |
929 | 929 | ||
930 | QPopupMenu *m; | 930 | QPopupMenu *m; |
931 | m = new QPopupMenu( this); | 931 | m = new QPopupMenu( this); |
932 | m->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); | 932 | m->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); |
933 | m->insertSeparator(); | 933 | m->insertSeparator(); |
934 | if(item != NULL ) { | 934 | if(item != NULL ) { |
935 | if( item->text(0).find("/",0,TRUE) !=-1) | 935 | if( item->text(0).find("/",0,TRUE) !=-1) |
936 | m->insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); | 936 | m->insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); |
937 | else | 937 | else |
938 | m->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); | 938 | m->insertItem( tr( "Upload" ), this, SLOT( localUpload() )); |
939 | } | 939 | } |
940 | m->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); | 940 | m->insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); |
941 | m->insertItem( tr("Rescan"), this, SLOT( populateRemoteView() )); | 941 | m->insertItem( tr("Rescan"), this, SLOT( populateRemoteView() )); |
942 | m->insertItem( tr( "Rename" ), this, SLOT( localRename() )); | 942 | m->insertItem( tr( "Rename" ), this, SLOT( localRename() )); |
943 | m->insertSeparator(); | 943 | m->insertSeparator(); |
944 | m->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); | 944 | m->insertItem( tr( "Delete" ), this, SLOT( localDelete() )); |
945 | m->setCheckable(TRUE); | 945 | m->setCheckable(TRUE); |
946 | if (b) | 946 | if (b) |
947 | m->setItemChecked(m->idAt(0),TRUE); | 947 | m->setItemChecked(m->idAt(0),TRUE); |
948 | else | 948 | else |
949 | m->setItemChecked(m->idAt(0),FALSE); | 949 | m->setItemChecked(m->idAt(0),FALSE); |
950 | 950 | ||
951 | m->exec( QCursor::pos() ); | 951 | m->exec( QCursor::pos() ); |
952 | delete m; | 952 | delete m; |
953 | } | 953 | } |
954 | 954 | ||
955 | void OpieFtp::localMakDir() | 955 | void OpieFtp::localMakDir() |
956 | { | 956 | { |
957 | InputDialog *fileDlg; | 957 | InputDialog *fileDlg; |
958 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); | 958 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); |
959 | fileDlg->exec(); | 959 | fileDlg->exec(); |
960 | if( fileDlg->result() == 1 ) { | 960 | if( fileDlg->result() == 1 ) { |
961 | QString filename = fileDlg->LineEdit1->text(); | 961 | QString filename = fileDlg->LineEdit1->text(); |
962 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); | 962 | currentDir.mkdir( currentDir.canonicalPath()+"/"+filename); |
963 | } | 963 | } |
964 | populateLocalView(); | 964 | populateLocalView(); |
965 | } | 965 | } |
966 | 966 | ||
967 | void OpieFtp::localDelete() | 967 | void OpieFtp::localDelete() |
968 | { | 968 | { |
969 | QList<QListViewItem> * getSelectedItems( QListView * Local_View ); | 969 | QList<QListViewItem> * getSelectedItems( QListView * Local_View ); |
970 | QListViewItemIterator it( Local_View ); | 970 | QListViewItemIterator it( Local_View ); |
971 | for ( ; it.current(); ++it ) { | 971 | for ( ; it.current(); ++it ) { |
972 | if ( it.current()->isSelected() ) { | 972 | if ( it.current()->isSelected() ) { |
973 | QString f = it.current()->text(0); | 973 | QString f = it.current()->text(0); |
974 | it.current()->setSelected(FALSE); | 974 | it.current()->setSelected(FALSE); |
975 | 975 | ||
976 | // QString f = Local_View->currentItem()->text(0); | 976 | // QString f = Local_View->currentItem()->text(0); |
977 | if(QDir(f).exists() ) { | 977 | if(QDir(f).exists() ) { |
978 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+ | 978 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+ |
979 | tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) { | 979 | tr(" ?\nIt must be empty"),tr("Yes"),tr("No"),0,0,1) ) { |
980 | case 0: { | 980 | case 0: { |
981 | f=currentDir.canonicalPath()+"/"+f; | 981 | f=currentDir.canonicalPath()+"/"+f; |
982 | QString cmd="rmdir "+f; | 982 | QString cmd="rmdir "+f; |
983 | system( cmd.latin1()); | 983 | system( cmd.latin1()); |
984 | } | 984 | } |
985 | break; | 985 | break; |
986 | case 1: | 986 | case 1: |
987 | // exit | 987 | // exit |
988 | break; | 988 | break; |
989 | }; | 989 | }; |
990 | 990 | ||
991 | } else { | 991 | } else { |
992 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f | 992 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f |
993 | +" ?",tr("Yes"),tr("No"),0,0,1) ) { | 993 | +" ?",tr("Yes"),tr("No"),0,0,1) ) { |
994 | case 0: { | 994 | case 0: { |
995 | f=currentDir.canonicalPath()+"/"+f; | 995 | f=currentDir.canonicalPath()+"/"+f; |
996 | QString cmd="rm "+f; | 996 | QString cmd="rm "+f; |
997 | system( cmd.latin1()); | 997 | system( cmd.latin1()); |
998 | } | 998 | } |
999 | break; | 999 | break; |
1000 | case 1: | 1000 | case 1: |
1001 | // exit | 1001 | // exit |
1002 | break; | 1002 | break; |
1003 | }; | 1003 | }; |
1004 | } | 1004 | } |
1005 | } | 1005 | } |
1006 | } | 1006 | } |
1007 | populateLocalView(); | 1007 | populateLocalView(); |
1008 | 1008 | ||
1009 | } | 1009 | } |
1010 | 1010 | ||
1011 | void OpieFtp::remoteMakDir() | 1011 | void OpieFtp::remoteMakDir() |
1012 | { | 1012 | { |
1013 | InputDialog *fileDlg; | 1013 | InputDialog *fileDlg; |
1014 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); | 1014 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); |
1015 | fileDlg->exec(); | 1015 | fileDlg->exec(); |
1016 | if( fileDlg->result() == 1 ) { | 1016 | if( fileDlg->result() == 1 ) { |
1017 | QString filename = fileDlg->LineEdit1->text();//+".playlist"; | 1017 | QString filename = fileDlg->LineEdit1->text();//+".playlist"; |
1018 | QString tmp=currentRemoteDir+filename; | 1018 | QString tmp=currentRemoteDir+filename; |
1019 | // QCopEnvelope ( "QPE/System", "busy()" ); | 1019 | // QCopEnvelope ( "QPE/System", "busy()" ); |
1020 | if(FtpMkdir( tmp.latin1(), conn) == 0) { | 1020 | if(FtpMkdir( tmp.latin1(), conn) == 0) { |
1021 | QString msg; | 1021 | QString msg; |
1022 | msg.sprintf(tr("Unable to make directory\n")+"%s",FtpLastResponse(conn)); | 1022 | msg.sprintf(tr("Unable to make directory\n")+"%s",FtpLastResponse(conn)); |
1023 | msg.replace(QRegExp(":"),"\n"); | 1023 | msg.replace(QRegExp(":"),"\n"); |
1024 | QMessageBox::message(tr("Note"),msg); | 1024 | QMessageBox::message(tr("Note"),msg); |
1025 | } | 1025 | } |
1026 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 1026 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
1027 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 1027 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
1028 | } | 1028 | } |
1029 | } | 1029 | } |
1030 | 1030 | ||
1031 | void OpieFtp::remoteDelete() | 1031 | void OpieFtp::remoteDelete() |
1032 | { | 1032 | { |
1033 | QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); | 1033 | QList<QListViewItem> * getSelectedItems( QListView * Remote_View ); |
1034 | QListViewItemIterator it( Remote_View ); | 1034 | QListViewItemIterator it( Remote_View ); |
1035 | for ( ; it.current(); ++it ) { | 1035 | for ( ; it.current(); ++it ) { |
1036 | if ( it.current()->isSelected() ) { | 1036 | if ( it.current()->isSelected() ) { |
1037 | QString f = it.current()->text(0); | 1037 | QString f = it.current()->text(0); |
1038 | // QString f = Remote_View->currentItem()->text(0); | 1038 | // QString f = Remote_View->currentItem()->text(0); |
1039 | // QCopEnvelope ( "QPE/System", "busy()" ); | 1039 | // QCopEnvelope ( "QPE/System", "busy()" ); |
1040 | if( f.right(1) =="/") { | 1040 | if( f.right(1) =="/") { |
1041 | QString path= currentRemoteDir+f; | 1041 | QString path= currentRemoteDir+f; |
1042 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" | 1042 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" |
1043 | ,tr("Yes"),tr("No"),0,0,1) ) { | 1043 | ,tr("Yes"),tr("No"),0,0,1) ) { |
1044 | case 0: { | 1044 | case 0: { |
1045 | f=currentDir.canonicalPath()+"/"+f; | 1045 | f=currentDir.canonicalPath()+"/"+f; |
1046 | if(FtpRmdir( path.latin1(), conn) ==0) { | 1046 | if(FtpRmdir( path.latin1(), conn) ==0) { |
1047 | QString msg; | 1047 | QString msg; |
1048 | msg.sprintf(tr("Unable to remove directory\n")+"%s",FtpLastResponse(conn)); | 1048 | msg.sprintf(tr("Unable to remove directory\n")+"%s",FtpLastResponse(conn)); |
1049 | msg.replace(QRegExp(":"),"\n"); | 1049 | msg.replace(QRegExp(":"),"\n"); |
1050 | QMessageBox::message(tr("Note"),msg); | 1050 | QMessageBox::message(tr("Note"),msg); |
1051 | } | 1051 | } |
1052 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 1052 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
1053 | } | 1053 | } |
1054 | break; | 1054 | break; |
1055 | }; | 1055 | }; |
1056 | } else { | 1056 | } else { |
1057 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" | 1057 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+"?" |
1058 | ,tr("Yes"),tr("No"),0,0,1) ) { | 1058 | ,tr("Yes"),tr("No"),0,0,1) ) { |
1059 | case 0: { | 1059 | case 0: { |
1060 | QString path= currentRemoteDir+f; | 1060 | QString path= currentRemoteDir+f; |
1061 | if(FtpDelete( path.latin1(), conn)==0) { | 1061 | if(FtpDelete( path.latin1(), conn)==0) { |
1062 | QString msg; | 1062 | QString msg; |
1063 | msg.sprintf(tr("Unable to delete file\n")+"%s",FtpLastResponse(conn)); | 1063 | msg.sprintf(tr("Unable to delete file\n")+"%s",FtpLastResponse(conn)); |
1064 | msg.replace(QRegExp(":"),"\n"); | 1064 | msg.replace(QRegExp(":"),"\n"); |
1065 | QMessageBox::message(tr("Note"),msg); | 1065 | QMessageBox::message(tr("Note"),msg); |
1066 | } | 1066 | } |
1067 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 1067 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
1068 | } | 1068 | } |
1069 | break; | 1069 | break; |
1070 | }; | 1070 | }; |
1071 | } | 1071 | } |
1072 | } | 1072 | } |
1073 | } | 1073 | } |
1074 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 1074 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | void OpieFtp::remoteRename() | 1077 | void OpieFtp::remoteRename() |
1078 | { | 1078 | { |
1079 | QString curFile = Remote_View->currentItem()->text(0); | 1079 | QString curFile = Remote_View->currentItem()->text(0); |
1080 | InputDialog *fileDlg; | 1080 | InputDialog *fileDlg; |
1081 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | 1081 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); |
1082 | fileDlg->setTextEdit((const QString &)curFile); | 1082 | fileDlg->setTextEdit((const QString &)curFile); |
1083 | fileDlg->exec(); | 1083 | fileDlg->exec(); |
1084 | if( fileDlg->result() == 1 ) { | 1084 | if( fileDlg->result() == 1 ) { |
1085 | QString oldName = currentRemoteDir +"/"+ curFile; | 1085 | QString oldName = currentRemoteDir +"/"+ curFile; |
1086 | QString newName = currentRemoteDir +"/"+ fileDlg->LineEdit1->text();//+".playlist"; | 1086 | QString newName = currentRemoteDir +"/"+ fileDlg->LineEdit1->text();//+".playlist"; |
1087 | // QCopEnvelope ( "QPE/System", "busy()" ); | 1087 | // QCopEnvelope ( "QPE/System", "busy()" ); |
1088 | if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) { | 1088 | if(FtpRename( oldName.latin1(), newName.latin1(),conn) == 0) { |
1089 | QString msg; | 1089 | QString msg; |
1090 | msg.sprintf(tr("Unable to rename file\n")+"%s",FtpLastResponse(conn)); | 1090 | msg.sprintf(tr("Unable to rename file\n")+"%s",FtpLastResponse(conn)); |
1091 | msg.replace(QRegExp(":"),"\n"); | 1091 | msg.replace(QRegExp(":"),"\n"); |
1092 | QMessageBox::message(tr("Note"),msg); | 1092 | QMessageBox::message(tr("Note"),msg); |
1093 | } | 1093 | } |
1094 | // QCopEnvelope ( "QPE/System", "notBusy()" ); | 1094 | // QCopEnvelope ( "QPE/System", "notBusy()" ); |
1095 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 1095 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
1096 | } | 1096 | } |
1097 | } | 1097 | } |
1098 | 1098 | ||
1099 | void OpieFtp::localRename() | 1099 | void OpieFtp::localRename() |
1100 | { | 1100 | { |
1101 | QString curFile = Local_View->currentItem()->text(0); | 1101 | QString curFile = Local_View->currentItem()->text(0); |
1102 | InputDialog *fileDlg; | 1102 | InputDialog *fileDlg; |
1103 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | 1103 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); |
1104 | fileDlg->setTextEdit((const QString &)curFile); | 1104 | fileDlg->setTextEdit((const QString &)curFile); |
1105 | fileDlg->exec(); | 1105 | fileDlg->exec(); |
1106 | if( fileDlg->result() == 1 ) { | 1106 | if( fileDlg->result() == 1 ) { |
1107 | QString oldname = currentDir.canonicalPath() + "/" + curFile; | 1107 | QString oldname = currentDir.canonicalPath() + "/" + curFile; |
1108 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; | 1108 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();//+".playlist"; |
1109 | if( rename(oldname.latin1(), newName.latin1())== -1) | 1109 | if( rename(oldname.latin1(), newName.latin1())== -1) |
1110 | QMessageBox::message(tr("Note"),tr("Could not rename")); | 1110 | QMessageBox::message(tr("Note"),tr("Could not rename")); |
1111 | } | 1111 | } |
1112 | populateLocalView(); | 1112 | populateLocalView(); |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | void OpieFtp::currentPathComboActivated(const QString & currentPath) { | 1115 | void OpieFtp::currentPathComboActivated(const QString & currentPath) { |
1116 | if (TabWidget->currentPageIndex() == 0) { | 1116 | if (TabWidget->currentPageIndex() == 0) { |
1117 | chdir( currentPath.latin1() ); | 1117 | chdir( currentPath.latin1() ); |
1118 | currentDir.cd( currentPath, TRUE); | 1118 | currentDir.cd( currentPath, TRUE); |
1119 | populateLocalView(); | 1119 | populateLocalView(); |
1120 | update(); | 1120 | update(); |
1121 | } else { | 1121 | } else { |
1122 | // chdir( currentPath.latin1() ); | 1122 | // chdir( currentPath.latin1() ); |
1123 | // currentDir.cd( currentPath, TRUE); | 1123 | // currentDir.cd( currentPath, TRUE); |
1124 | // populateList(); | 1124 | // populateList(); |
1125 | // update(); | 1125 | // update(); |
1126 | 1126 | ||
1127 | } | 1127 | } |
1128 | } | 1128 | } |
1129 | 1129 | ||
1130 | void OpieFtp::fillCombo(const QString ¤tPath) { | 1130 | void OpieFtp::fillCombo(const QString ¤tPath) { |
1131 | 1131 | ||
1132 | currentPathCombo->lineEdit()->setText(currentPath); | 1132 | currentPathCombo->lineEdit()->setText(currentPath); |
1133 | if( localDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | 1133 | if( localDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { |
1134 | currentPathCombo->clear(); | 1134 | currentPathCombo->clear(); |
1135 | localDirPathStringList.prepend(currentPath ); | 1135 | localDirPathStringList.prepend(currentPath ); |
1136 | currentPathCombo->insertStringList( localDirPathStringList,-1); | 1136 | currentPathCombo->insertStringList( localDirPathStringList,-1); |
1137 | } | 1137 | } |
1138 | currentPathCombo->lineEdit()->setText(currentPath); | 1138 | currentPathCombo->lineEdit()->setText(currentPath); |
1139 | if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | 1139 | if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { |
1140 | currentPathCombo->clear(); | 1140 | currentPathCombo->clear(); |
1141 | remoteDirPathStringList.prepend(currentPath ); | 1141 | remoteDirPathStringList.prepend(currentPath ); |
1142 | currentPathCombo->insertStringList( remoteDirPathStringList,-1); | 1142 | currentPathCombo->insertStringList( remoteDirPathStringList,-1); |
1143 | } | 1143 | } |
1144 | } | 1144 | } |
1145 | 1145 | ||
1146 | void OpieFtp::fillRemoteCombo(const QString ¤tPath) { | 1146 | void OpieFtp::fillRemoteCombo(const QString ¤tPath) { |
1147 | 1147 | ||
1148 | currentPathCombo->lineEdit()->setText(currentPath); | 1148 | currentPathCombo->lineEdit()->setText(currentPath); |
1149 | if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { | 1149 | if( remoteDirPathStringList.grep(currentPath,TRUE).isEmpty() ) { |
1150 | currentPathCombo->clear(); | 1150 | currentPathCombo->clear(); |
1151 | remoteDirPathStringList.prepend(currentPath ); | 1151 | remoteDirPathStringList.prepend(currentPath ); |
1152 | currentPathCombo->insertStringList( remoteDirPathStringList,-1); | 1152 | currentPathCombo->insertStringList( remoteDirPathStringList,-1); |
1153 | } | 1153 | } |
1154 | } | 1154 | } |
1155 | 1155 | ||
1156 | void OpieFtp::currentPathComboChanged() | 1156 | void OpieFtp::currentPathComboChanged() |
1157 | { | 1157 | { |
1158 | QString oldRemoteCurrentDir = currentRemoteDir; | 1158 | QString oldRemoteCurrentDir = currentRemoteDir; |
1159 | // qDebug("oldRemoteCurrentDir "+oldRemoteCurrentDir); | 1159 | // qDebug("oldRemoteCurrentDir "+oldRemoteCurrentDir); |
1160 | if (TabWidget->currentPageIndex() == 0) { | 1160 | if (TabWidget->currentPageIndex() == 0) { |
1161 | if(QDir( currentPathCombo->lineEdit()->text()).exists()) { | 1161 | if(QDir( currentPathCombo->lineEdit()->text()).exists()) { |
1162 | currentDir.setPath( currentPathCombo->lineEdit()->text() ); | 1162 | currentDir.setPath( currentPathCombo->lineEdit()->text() ); |
1163 | populateLocalView(); | 1163 | populateLocalView(); |
1164 | } else { | 1164 | } else { |
1165 | QMessageBox::message(tr("Note"),tr("That directory does not exist")); | 1165 | QMessageBox::message(tr("Note"),tr("That directory does not exist")); |
1166 | } | 1166 | } |
1167 | } | 1167 | } |
1168 | if (TabWidget->currentPageIndex() == 1) { | 1168 | if (TabWidget->currentPageIndex() == 1) { |
1169 | currentRemoteDir = currentPathCombo->lineEdit()->text(); | 1169 | currentRemoteDir = currentPathCombo->lineEdit()->text(); |
1170 | if(currentRemoteDir.right(1) !="/") { | 1170 | if(currentRemoteDir.right(1) !="/") { |
1171 | currentRemoteDir = currentRemoteDir +"/"; | 1171 | currentRemoteDir = currentRemoteDir +"/"; |
1172 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); | 1172 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); |
1173 | } | 1173 | } |
1174 | if( !remoteChDir( (const QString &)currentRemoteDir) ) { | 1174 | if( !remoteChDir( (const QString &)currentRemoteDir) ) { |
1175 | currentRemoteDir = oldRemoteCurrentDir; | 1175 | currentRemoteDir = oldRemoteCurrentDir; |
1176 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); | 1176 | currentPathCombo->lineEdit()->setText( currentRemoteDir ); |
1177 | } | 1177 | } |
1178 | 1178 | ||
1179 | remoteDirList( (const QString &)currentRemoteDir); | 1179 | remoteDirList( (const QString &)currentRemoteDir); |
1180 | } | 1180 | } |
1181 | } | 1181 | } |
1182 | 1182 | ||
1183 | void OpieFtp::switchToLocalTab() | 1183 | void OpieFtp::switchToLocalTab() |
1184 | { | 1184 | { |
1185 | TabWidget->setCurrentPage(0); | 1185 | TabWidget->setCurrentPage(0); |
1186 | } | 1186 | } |
1187 | 1187 | ||
1188 | void OpieFtp::switchToRemoteTab() | 1188 | void OpieFtp::switchToRemoteTab() |
1189 | { | 1189 | { |
1190 | TabWidget->setCurrentPage(1); | 1190 | TabWidget->setCurrentPage(1); |
1191 | } | 1191 | } |
1192 | 1192 | ||
1193 | void OpieFtp::switchToConfigTab() | 1193 | void OpieFtp::switchToConfigTab() |
1194 | { | 1194 | { |
1195 | TabWidget->setCurrentPage(2); | 1195 | TabWidget->setCurrentPage(2); |
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | void OpieFtp::readConfig() | 1198 | void OpieFtp::readConfig() |
1199 | { | 1199 | { |
1200 | fillCombos(); | 1200 | fillCombos(); |
1201 | Config cfg("opieftp"); | 1201 | Config cfg("opieftp"); |
1202 | cfg.setGroup("Server"); | 1202 | cfg.setGroup("Server"); |
1203 | currentServerConfig = cfg.readNumEntry("currentServer", -1); | 1203 | currentServerConfig = cfg.readNumEntry("currentServer", -1); |
1204 | 1204 | ||
1205 | // qDebug("Reading %d", currentServerConfig); | 1205 | // qDebug("Reading %d", currentServerConfig); |
1206 | serverComboSelected( currentServerConfig-1); | 1206 | serverComboSelected( currentServerConfig-1); |
1207 | 1207 | ||
1208 | } | 1208 | } |
1209 | 1209 | ||
1210 | void OpieFtp::writeConfig() | 1210 | void OpieFtp::writeConfig() |
1211 | { | 1211 | { |
1212 | qDebug("write config"); | 1212 | qDebug("write config"); |
1213 | Config cfg("opieftp"); | 1213 | Config cfg("opieftp"); |
1214 | cfg.setGroup("Server"); | 1214 | cfg.setGroup("Server"); |
1215 | 1215 | ||
1216 | QString username, remoteServerStr, remotePathStr, password, port, temp; | 1216 | QString username, remoteServerStr, remotePathStr, password, port, temp; |
1217 | 1217 | ||
1218 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1218 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1219 | 1219 | ||
1220 | if( currentServerConfig == -1) { | 1220 | if( currentServerConfig == -1) { |
1221 | 1221 | ||
1222 | for (int i = 1; i <= numberOfEntries; i++) { | 1222 | for (int i = 1; i <= numberOfEntries; i++) { |
1223 | temp.setNum(i); | 1223 | temp.setNum(i); |
1224 | cfg.setGroup("Server"); | 1224 | cfg.setGroup("Server"); |
1225 | QString tempStr = cfg.readEntry( temp,""); | 1225 | QString tempStr = cfg.readEntry( temp,""); |
1226 | } | 1226 | } |
1227 | 1227 | ||
1228 | temp.setNum( numberOfEntries + 1); | 1228 | temp.setNum( numberOfEntries + 1); |
1229 | cfg.setGroup("Server"); | 1229 | cfg.setGroup("Server"); |
1230 | 1230 | ||
1231 | remoteServerStr = cfg.readEntry( temp,""); | 1231 | remoteServerStr = cfg.readEntry( temp,""); |
1232 | 1232 | ||
1233 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); | 1233 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); |
1234 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); | 1234 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); |
1235 | 1235 | ||
1236 | temp.setNum(numberOfEntries+1); | 1236 | temp.setNum(numberOfEntries+1); |
1237 | cfg.setGroup("Server"); | 1237 | cfg.setGroup("Server"); |
1238 | 1238 | ||
1239 | cfg.writeEntry( temp, ServerComboBox->currentText() +":"+PortSpinBox->cleanText() ); | 1239 | cfg.writeEntry( temp, ServerComboBox->currentText() +":"+PortSpinBox->cleanText() ); |
1240 | cfg.writeEntry("currentServer", numberOfEntries+1); | 1240 | cfg.writeEntry("currentServer", numberOfEntries+1); |
1241 | 1241 | ||
1242 | currentServerConfig = numberOfEntries+1; | 1242 | currentServerConfig = numberOfEntries+1; |
1243 | qDebug("setting currentserverconfig to %d", currentServerConfig); | 1243 | qDebug("setting currentserverconfig to %d", currentServerConfig); |
1244 | 1244 | ||
1245 | cfg.setGroup(temp); | 1245 | cfg.setGroup(temp); |
1246 | if(!newServerName.isEmpty()) | 1246 | if(!newServerName.isEmpty()) |
1247 | cfg.writeEntry("ServerName", newServerName); | 1247 | cfg.writeEntry("ServerName", newServerName); |
1248 | 1248 | ||
1249 | cfg.writeEntry("RemotePath", remotePath->text()); | 1249 | cfg.writeEntry("RemotePath", remotePath->text()); |
1250 | 1250 | ||
1251 | cfg.writeEntry("Username", UsernameComboBox->currentText()); | 1251 | cfg.writeEntry("Username", UsernameComboBox->currentText()); |
1252 | 1252 | ||
1253 | cfg.writeEntryCrypt( UsernameComboBox->currentText(), PasswordEdit->text()); | 1253 | cfg.writeEntryCrypt( UsernameComboBox->currentText(), PasswordEdit->text()); |
1254 | cfg.setGroup("Server"); | 1254 | cfg.setGroup("Server"); |
1255 | 1255 | ||
1256 | cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries + 1 )); | 1256 | cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries + 1 )); |
1257 | 1257 | ||
1258 | } | 1258 | } |
1259 | } | 1259 | } |
1260 | 1260 | ||
1261 | void OpieFtp::clearCombos() { | 1261 | void OpieFtp::clearCombos() { |
1262 | qDebug("clearing"); | 1262 | qDebug("clearing"); |
1263 | ServerComboBox->clear(); | 1263 | ServerComboBox->clear(); |
1264 | UsernameComboBox->clear(); | 1264 | UsernameComboBox->clear(); |
1265 | PasswordEdit->clear(); | 1265 | PasswordEdit->clear(); |
1266 | serverListView->clear(); | 1266 | serverListView->clear(); |
1267 | } | 1267 | } |
1268 | 1268 | ||
1269 | 1269 | ||
1270 | void OpieFtp::fillCombos() | 1270 | void OpieFtp::fillCombos() |
1271 | { | 1271 | { |
1272 | clearCombos(); | 1272 | clearCombos(); |
1273 | 1273 | ||
1274 | Config cfg("opieftp"); | 1274 | Config cfg("opieftp"); |
1275 | cfg.setGroup("Server"); | 1275 | cfg.setGroup("Server"); |
1276 | QString username, remoteServerStr, remotePathStr, password, port, temp; | 1276 | QString username, remoteServerStr, remotePathStr, password, port, temp; |
1277 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1277 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1278 | 1278 | ||
1279 | for (int i = 1; i <= numberOfEntries; i++) { | 1279 | for (int i = 1; i <= numberOfEntries; i++) { |
1280 | temp.setNum(i); | 1280 | temp.setNum(i); |
1281 | qDebug(temp); | 1281 | qDebug(temp); |
1282 | cfg.setGroup("Server"); | 1282 | cfg.setGroup("Server"); |
1283 | remoteServerStr = cfg.readEntry( temp,""); | 1283 | remoteServerStr = cfg.readEntry( temp,""); |
1284 | qDebug( remoteServerStr); | 1284 | qDebug( remoteServerStr); |
1285 | 1285 | ||
1286 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); | 1286 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); |
1287 | port = remoteServerStr.right( divider - 1); | 1287 | port = remoteServerStr.right( divider - 1); |
1288 | bool ok; | 1288 | bool ok; |
1289 | PortSpinBox->setValue( port.toInt(&ok,10)); | 1289 | PortSpinBox->setValue( port.toInt(&ok,10)); |
1290 | 1290 | ||
1291 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); | 1291 | remoteServerStr = remoteServerStr.left(remoteServerStr.length()-divider); |
1292 | qDebug( "remote server string "+remoteServerStr); | 1292 | qDebug( "remote server string "+remoteServerStr); |
1293 | ServerComboBox->insertItem( remoteServerStr ); | 1293 | ServerComboBox->insertItem( remoteServerStr ); |
1294 | 1294 | ||
1295 | cfg.setGroup(temp); | 1295 | cfg.setGroup(temp); |
1296 | 1296 | ||
1297 | username = cfg.readEntry(temp); | 1297 | username = cfg.readEntry(temp); |
1298 | UsernameComboBox->insertItem(username); | 1298 | UsernameComboBox->insertItem(username); |
1299 | password = cfg.readEntryCrypt(username,""); | 1299 | password = cfg.readEntryCrypt(username,""); |
1300 | PasswordEdit->setText(password); | 1300 | PasswordEdit->setText(password); |
1301 | 1301 | ||
1302 | serverListView->insertItem( cfg.readEntry("ServerName")); | 1302 | serverListView->insertItem( cfg.readEntry("ServerName")); |
1303 | } | 1303 | } |
1304 | } | 1304 | } |
1305 | 1305 | ||
1306 | 1306 | ||
1307 | void OpieFtp::serverComboSelected(int index) | 1307 | void OpieFtp::serverComboSelected(int index) |
1308 | { | 1308 | { |
1309 | currentServerConfig = index+1; | 1309 | currentServerConfig = index+1; |
1310 | qDebug("server combo selected %d", index+1); | 1310 | qDebug("server combo selected %d", index+1); |
1311 | QString username, remoteServerStr, remotePathStr, password, port, temp; | 1311 | QString username, remoteServerStr, remotePathStr, password, port, temp; |
1312 | // remoteServerStr = ServerComboBox->text(index); | 1312 | // remoteServerStr = ServerComboBox->text(index); |
1313 | 1313 | ||
1314 | Config cfg("opieftp"); | 1314 | Config cfg("opieftp"); |
1315 | cfg.setGroup("Server"); | 1315 | cfg.setGroup("Server"); |
1316 | // int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1316 | // int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1317 | 1317 | ||
1318 | temp.setNum(index+1); | 1318 | temp.setNum(index+1); |
1319 | remoteServerStr = cfg.readEntry( temp,""); | 1319 | remoteServerStr = cfg.readEntry( temp,""); |
1320 | 1320 | ||
1321 | qDebug("Group" +temp); | 1321 | qDebug("Group" +temp); |
1322 | cfg.setGroup(temp); | 1322 | cfg.setGroup(temp); |
1323 | // qDebug(temp); | 1323 | // qDebug(temp); |
1324 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); | 1324 | int divider = remoteServerStr.length() - remoteServerStr.find(":",0,TRUE); |
1325 | port = remoteServerStr.right( divider - 1); | 1325 | port = remoteServerStr.right( divider - 1); |
1326 | bool ok; | 1326 | bool ok; |
1327 | int portInt = port.toInt(&ok,10); | 1327 | int portInt = port.toInt(&ok,10); |
1328 | if( portInt == 0) portInt = 21; | 1328 | if( portInt == 0) portInt = 21; |
1329 | 1329 | ||
1330 | ServerComboBox->lineEdit()->setText(remoteServerStr.left( remoteServerStr.find(":",0,TRUE))); | 1330 | ServerComboBox->lineEdit()->setText(remoteServerStr.left( remoteServerStr.find(":",0,TRUE))); |
1331 | 1331 | ||
1332 | PortSpinBox->setValue( portInt); | 1332 | PortSpinBox->setValue( portInt); |
1333 | 1333 | ||
1334 | remotePath->setText(cfg.readEntry("RemotePath", "/")); | 1334 | remotePath->setText(cfg.readEntry("RemotePath", "/")); |
1335 | 1335 | ||
1336 | username = cfg.readEntry("Username", "anonymous"); | 1336 | username = cfg.readEntry("Username", "anonymous"); |
1337 | UsernameComboBox->lineEdit()->setText(username); | 1337 | UsernameComboBox->lineEdit()->setText(username); |
1338 | qDebug(username); | 1338 | qDebug(username); |
1339 | // qDebug("Password is "+cfg.readEntryCrypt(username, "me@opieftp.org")); | 1339 | // qDebug("Password is "+cfg.readEntryCrypt(username, "me@opieftp.org")); |
1340 | PasswordEdit->setText(cfg.readEntryCrypt(username, "me@opieftp.org")); | 1340 | PasswordEdit->setText(cfg.readEntryCrypt(username, "me@opieftp.org")); |
1341 | // UsernameComboBox | 1341 | // UsernameComboBox |
1342 | // PasswordEdit | 1342 | // PasswordEdit |
1343 | 1343 | ||
1344 | cfg.setGroup("Server"); | 1344 | cfg.setGroup("Server"); |
1345 | temp.sprintf("%d",currentServerConfig); | 1345 | temp.sprintf("%d",currentServerConfig); |
1346 | cfg.writeEntry("currentServer", temp); | 1346 | cfg.writeEntry("currentServer", temp); |
1347 | 1347 | ||
1348 | fuckeduphack = TRUE; | 1348 | fuckeduphack = TRUE; |
1349 | serverListView->setCurrentItem( index); | 1349 | serverListView->setCurrentItem( index); |
1350 | fuckeduphack=FALSE; | 1350 | fuckeduphack=FALSE; |
1351 | qDebug("server list set selected %d",index); | 1351 | qDebug("server list set selected %d",index); |
1352 | update(); | 1352 | update(); |
1353 | } | 1353 | } |
1354 | 1354 | ||
1355 | void OpieFtp::deleteServer() | 1355 | void OpieFtp::deleteServer() |
1356 | { | 1356 | { |
1357 | QString username, remoteServerStr, remotePathStr, password, port, temp, servername; | 1357 | QString username, remoteServerStr, remotePathStr, password, port, temp, servername; |
1358 | remoteServerStr = ServerComboBox->currentText( ); | 1358 | remoteServerStr = ServerComboBox->currentText( ); |
1359 | username = UsernameComboBox->currentText(); | 1359 | username = UsernameComboBox->currentText(); |
1360 | servername=serverListView->currentText(); | 1360 | servername=serverListView->currentText(); |
1361 | 1361 | ||
1362 | Config cfg("opieftp"); | 1362 | Config cfg("opieftp"); |
1363 | cfg.setGroup("Server"); | 1363 | cfg.setGroup("Server"); |
1364 | QString tempname; | 1364 | QString tempname; |
1365 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1365 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1366 | 1366 | ||
1367 | for (int i = 1; i <= numberOfEntries; i++) { | 1367 | for (int i = 1; i <= numberOfEntries; i++) { |
1368 | temp.setNum(i); | 1368 | temp.setNum(i); |
1369 | // cfg.setGroup("Server"); | 1369 | // cfg.setGroup("Server"); |
1370 | cfg.setGroup(QString::number(i)); | 1370 | cfg.setGroup(QString::number(i)); |
1371 | tempname=cfg.readEntry( "ServerName",""); | 1371 | tempname=cfg.readEntry( "ServerName",""); |
1372 | 1372 | ||
1373 | if( tempname.find( servername,0,TRUE) != -1 ) { | 1373 | if( tempname.find( servername,0,TRUE) != -1 ) { |
1374 | // servername.find( cfg.readEntry("ServerName")) != -1 && | 1374 | // servername.find( cfg.readEntry("ServerName")) != -1 && |
1375 | // remoteServerStr.find( cfg.readEntry("RemotePath")) != -1 && | 1375 | // remoteServerStr.find( cfg.readEntry("RemotePath")) != -1 && |
1376 | // username.find( cfg.readEntry("Username")) != -1) { | 1376 | // username.find( cfg.readEntry("Username")) != -1) { |
1377 | 1377 | ||
1378 | serverListView->removeItem(i); | 1378 | serverListView->removeItem(i); |
1379 | 1379 | ||
1380 | qDebug("OK DELETE "+tempname); | 1380 | qDebug("OK DELETE "+tempname); |
1381 | cfg.removeEntry(QString::number(i)); | 1381 | cfg.removeEntry(QString::number(i)); |
1382 | for ( ; i <= numberOfEntries; i++) { | 1382 | for ( ; i <= numberOfEntries; i++) { |
1383 | cfg.setGroup("Server"); | 1383 | cfg.setGroup("Server"); |
1384 | cfg.writeEntry("Server", QString::number(numberOfEntries + 1 )); | 1384 | cfg.writeEntry("Server", QString::number(numberOfEntries + 1 )); |
1385 | 1385 | ||
1386 | cfg.setGroup(QString::number(i+1)); //get next server config | 1386 | cfg.setGroup(QString::number(i+1)); //get next server config |
1387 | servername=cfg.readEntry("ServerName"); | 1387 | servername=cfg.readEntry("ServerName"); |
1388 | remoteServerStr=cfg.readEntry("RemotePath"); | 1388 | remoteServerStr=cfg.readEntry("RemotePath"); |
1389 | username=cfg.readEntry("Username"); | 1389 | username=cfg.readEntry("Username"); |
1390 | password=cfg.readEntryCrypt( username); | 1390 | password=cfg.readEntryCrypt( username); |
1391 | 1391 | ||
1392 | cfg.setGroup(QString::number(i)); | 1392 | cfg.setGroup(QString::number(i)); |
1393 | 1393 | ||
1394 | cfg.writeEntry("RemotePath", remoteServerStr); | 1394 | cfg.writeEntry("RemotePath", remoteServerStr); |
1395 | cfg.writeEntry("ServerName", servername); | 1395 | cfg.writeEntry("ServerName", servername); |
1396 | cfg.writeEntry("Username", username); | 1396 | cfg.writeEntry("Username", username); |
1397 | cfg.writeEntryCrypt( username, password); | 1397 | cfg.writeEntryCrypt( username, password); |
1398 | 1398 | ||
1399 | } | 1399 | } |
1400 | cfg.setGroup("Server"); | 1400 | cfg.setGroup("Server"); |
1401 | cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries - 1 )); | 1401 | cfg.writeEntry("numberOfEntries", QString::number(numberOfEntries - 1 )); |
1402 | } | 1402 | } |
1403 | } | 1403 | } |
1404 | cfg.setGroup(QString::number(numberOfEntries)); | 1404 | cfg.setGroup(QString::number(numberOfEntries)); |
1405 | cfg.removeEntry("Server"); | 1405 | cfg.removeEntry("Server"); |
1406 | cfg.removeEntry("RemotePath"); | 1406 | cfg.removeEntry("RemotePath"); |
1407 | cfg.removeEntry("ServerName"); | 1407 | cfg.removeEntry("ServerName"); |
1408 | username=cfg.readEntry("Username"); | 1408 | username=cfg.readEntry("Username"); |
1409 | cfg.removeEntry("Username"); | 1409 | cfg.removeEntry("Username"); |
1410 | cfg.removeEntry(username); | 1410 | cfg.removeEntry(username); |
1411 | 1411 | ||
1412 | currentServerConfig=currentServerConfig-1; | 1412 | currentServerConfig=currentServerConfig-1; |
1413 | 1413 | ||
1414 | fillCombos(); | 1414 | fillCombos(); |
1415 | update(); | 1415 | update(); |
1416 | } | 1416 | } |
1417 | 1417 | ||
1418 | void OpieFtp::upDir() | 1418 | void OpieFtp::upDir() |
1419 | { | 1419 | { |
1420 | if (TabWidget->currentPageIndex() == 0) { | 1420 | if (TabWidget->currentPageIndex() == 0) { |
1421 | QString current = currentDir.canonicalPath(); | 1421 | QString current = currentDir.canonicalPath(); |
1422 | QDir dir(current); | 1422 | QDir dir(current); |
1423 | dir.cdUp(); | 1423 | dir.cdUp(); |
1424 | current = dir.canonicalPath(); | 1424 | current = dir.canonicalPath(); |
1425 | chdir( current.latin1() ); | 1425 | chdir( current.latin1() ); |
1426 | currentDir.cd( current, TRUE); | 1426 | currentDir.cd( current, TRUE); |
1427 | populateLocalView(); | 1427 | populateLocalView(); |
1428 | update(); | 1428 | update(); |
1429 | } else { | 1429 | } else { |
1430 | if( FtpCDUp( conn) == 0) { | 1430 | if( FtpCDUp( conn) == 0) { |
1431 | QString msg; | 1431 | QString msg; |
1432 | msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); | 1432 | msg.sprintf(tr("Unable to cd up\n")+"%s",FtpLastResponse(conn)); |
1433 | msg.replace(QRegExp(":"),"\n"); | 1433 | msg.replace(QRegExp(":"),"\n"); |
1434 | QMessageBox::message(tr("Note"),msg); | 1434 | QMessageBox::message(tr("Note"),msg); |
1435 | // qDebug(msg); | 1435 | // qDebug(msg); |
1436 | } | 1436 | } |
1437 | char path[256]; | 1437 | char path[256]; |
1438 | if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string | 1438 | if( FtpPwd( path,sizeof(path),conn) == 0) { //this is easier than fudging the string |
1439 | QString msg; | 1439 | QString msg; |
1440 | msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); | 1440 | msg.sprintf(tr("Unable to get working dir\n")+"%s",FtpLastResponse(conn)); |
1441 | msg.replace(QRegExp(":"),"\n"); | 1441 | msg.replace(QRegExp(":"),"\n"); |
1442 | QMessageBox::message(tr("Note"),msg); | 1442 | QMessageBox::message(tr("Note"),msg); |
1443 | // qDebug(msg); | 1443 | // qDebug(msg); |
1444 | } | 1444 | } |
1445 | currentRemoteDir=path; | 1445 | currentRemoteDir=path; |
1446 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate | 1446 | remoteDirList( (const QString &)currentRemoteDir); //this also calls populate |
1447 | if(currentRemoteDir.right(1) !="/") | 1447 | if(currentRemoteDir.right(1) !="/") |
1448 | currentRemoteDir +="/"; | 1448 | currentRemoteDir +="/"; |
1449 | currentPathCombo->lineEdit()->setText( currentRemoteDir); | 1449 | currentPathCombo->lineEdit()->setText( currentRemoteDir); |
1450 | fillRemoteCombo( (const QString &)currentRemoteDir); | 1450 | fillRemoteCombo( (const QString &)currentRemoteDir); |
1451 | 1451 | ||
1452 | } | 1452 | } |
1453 | } | 1453 | } |
1454 | 1454 | ||
1455 | void OpieFtp::docButtonPushed() { | 1455 | void OpieFtp::docButtonPushed() { |
1456 | QString current = QPEApplication::documentDir(); | 1456 | QString current = QPEApplication::documentDir(); |
1457 | chdir( current.latin1() ); | 1457 | chdir( current.latin1() ); |
1458 | currentDir.cd( current, TRUE); | 1458 | currentDir.cd( current, TRUE); |
1459 | populateLocalView(); | 1459 | populateLocalView(); |
1460 | update(); | 1460 | update(); |
1461 | 1461 | ||
1462 | } | 1462 | } |
1463 | 1463 | ||
1464 | void OpieFtp::homeButtonPushed() { | 1464 | void OpieFtp::homeButtonPushed() { |
1465 | QString current = QDir::homeDirPath(); | 1465 | QString current = QDir::homeDirPath(); |
1466 | chdir( current.latin1() ); | 1466 | chdir( current.latin1() ); |
1467 | currentDir.cd( current, TRUE); | 1467 | currentDir.cd( current, TRUE); |
1468 | populateLocalView(); | 1468 | populateLocalView(); |
1469 | update(); | 1469 | update(); |
1470 | } | 1470 | } |
1471 | 1471 | ||
1472 | void OpieFtp::doAbout() { | 1472 | void OpieFtp::doAbout() { |
1473 | QMessageBox::message("OpieFtp","Opie ftp client is copyright 2002 by\n" | 1473 | QMessageBox::message("OpieFtp","Opie ftp client is copyright 2002 by\n" |
1474 | "L.J.Potter<llornkcor@handhelds.org>\n" | 1474 | "L.J.Potter<llornkcor@handhelds.org>\n" |
1475 | "and uses ftplib copyright 1996-2000\n" | 1475 | "and uses ftplib copyright 1996-2000\n" |
1476 | "by Thomas Pfau, pfau@cnj.digex.net\n\n" | 1476 | "by Thomas Pfau, pfau@cnj.digex.net\n\n" |
1477 | "and is licensed by the GPL"); | 1477 | "and is licensed by the GPL"); |
1478 | } | 1478 | } |
1479 | 1479 | ||
1480 | void OpieFtp::NewServer() { | 1480 | void OpieFtp::NewServer() { |
1481 | InputDialog *fileDlg; | 1481 | InputDialog *fileDlg; |
1482 | fileDlg = new InputDialog(this,tr("New Server name"),TRUE, 0); | 1482 | fileDlg = new InputDialog(this,tr("New Server name"),TRUE, 0); |
1483 | fileDlg->exec(); | 1483 | fileDlg->exec(); |
1484 | Config cfg("opieftp"); | 1484 | Config cfg("opieftp"); |
1485 | if( fileDlg->result() == 1 ) { | 1485 | if( fileDlg->result() == 1 ) { |
1486 | newServerName = fileDlg->LineEdit1->text(); | 1486 | newServerName = fileDlg->LineEdit1->text(); |
1487 | for(int i=1;i<serverListView->count();i++) { | 1487 | for(int i=1;i<serverListView->count();i++) { |
1488 | cfg.setGroup( QString::number(i)); | 1488 | cfg.setGroup( QString::number(i)); |
1489 | if(cfg.readEntry("ServerName").find(newServerName,0,TRUE) != -1) { | 1489 | if(cfg.readEntry("ServerName").find(newServerName,0,TRUE) != -1) { |
1490 | QMessageBox::message(tr("OpieFtp"),tr("Sorry name already taken")); | 1490 | QMessageBox::message(tr("OpieFtp"),tr("Sorry name already taken")); |
1491 | return; | 1491 | return; |
1492 | } | 1492 | } |
1493 | } | 1493 | } |
1494 | currentServerConfig =-1; | 1494 | currentServerConfig =-1; |
1495 | writeConfig(); | 1495 | writeConfig(); |
1496 | serverListView->insertItem( newServerName ); | 1496 | serverListView->insertItem( newServerName ); |
1497 | serverListView->setCurrentItem( serverListView->count()); | 1497 | serverListView->setCurrentItem( serverListView->count()); |
1498 | } | 1498 | } |
1499 | } | 1499 | } |
1500 | 1500 | ||
1501 | void OpieFtp::serverListClicked( const QString &item) { | 1501 | void OpieFtp::serverListClicked( const QString &item) { |
1502 | if(item.isEmpty()) return; | 1502 | if(item.isEmpty()) return; |
1503 | Config cfg("opieftp"); | 1503 | Config cfg("opieftp"); |
1504 | qDebug("highltined "+item); | 1504 | qDebug("highltined "+item); |
1505 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); | 1505 | int numberOfEntries = cfg.readNumEntry("numberOfEntries",0); |
1506 | for (int i = 1; i <= numberOfEntries; i++) { | 1506 | for (int i = 1; i <= numberOfEntries; i++) { |
1507 | cfg.setGroup(QString::number(i)); | 1507 | cfg.setGroup(QString::number(i)); |
1508 | if(cfg.readEntry( "ServerName").find(item) != -1 && !fuckeduphack) | 1508 | if(cfg.readEntry( "ServerName").find(item) != -1 && !fuckeduphack) |
1509 | serverComboSelected(i-1); | 1509 | serverComboSelected(i-1); |
1510 | } | 1510 | } |
1511 | } | 1511 | } |
1512 | 1512 | ||
1513 | void OpieFtp::timerOut() { | 1513 | void OpieFtp::timerOut() { |
1514 | 1514 | ||
1515 | } | 1515 | } |
diff --git a/noncore/net/opieftp/opieftp.h b/noncore/net/opieftp/opieftp.h index f58778a..076a906 100644 --- a/noncore/net/opieftp/opieftp.h +++ b/noncore/net/opieftp/opieftp.h | |||
@@ -1,143 +1,143 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | opieftp.h | 2 | opieftp.h |
3 | ------------------- | 3 | ------------------- |
4 | ** Created: Sat Mar 9 23:33:09 2002 | 4 | ** Created: Sat Mar 9 23:33:09 2002 |
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 | #ifndef OPIEFTP_H | 12 | #ifndef OPIEFTP_H |
13 | #define OPIEFTP_H | 13 | #define OPIEFTP_H |
14 | 14 | ||
15 | #include <qvariant.h> | 15 | #include <qvariant.h> |
16 | #include <qdialog.h> | 16 | #include <qdialog.h> |
17 | #include <qmainwindow.h> | 17 | #include <qmainwindow.h> |
18 | #include <qdir.h> | 18 | #include <qdir.h> |
19 | #include <qstring.h> | 19 | #include <qstring.h> |
20 | #include <qpoint.h> | 20 | #include <qpoint.h> |
21 | #include <qpixmap.h> | 21 | #include <qpixmap.h> |
22 | 22 | ||
23 | class QVBoxLayout; | 23 | class QVBoxLayout; |
24 | class QHBoxLayout; | 24 | class QHBoxLayout; |
25 | class QGridLayout; | 25 | class QGridLayout; |
26 | class QComboBox; | 26 | class QComboBox; |
27 | class QListView; | 27 | class QListView; |
28 | class QListViewItem; | 28 | class QListViewItem; |
29 | class QLabel; | 29 | class QLabel; |
30 | class QProgressBar; | 30 | class QProgressBar; |
31 | class QSpinBox; | 31 | class QSpinBox; |
32 | class QTabWidget; | 32 | class QTabWidget; |
33 | class QWidget; | 33 | class QWidget; |
34 | class QPEToolBar; | 34 | class QToolBar; |
35 | class QMenuBar; | 35 | class QMenuBar; |
36 | class QPopupMenu; | 36 | class QPopupMenu; |
37 | class QFile; | 37 | class QFile; |
38 | class QLineEdit; | 38 | class QLineEdit; |
39 | class QPushButton; | 39 | class QPushButton; |
40 | class QToolButton; | 40 | class QToolButton; |
41 | class QStringList; | 41 | class QStringList; |
42 | class QListBox; | 42 | class QListBox; |
43 | class QTimer; | 43 | class QTimer; |
44 | 44 | ||
45 | class OpieFtp : public QMainWindow | 45 | class OpieFtp : public QMainWindow |
46 | { | 46 | { |
47 | Q_OBJECT | 47 | Q_OBJECT |
48 | 48 | ||
49 | public: | 49 | public: |
50 | OpieFtp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 50 | OpieFtp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
51 | ~OpieFtp(); | 51 | ~OpieFtp(); |
52 | 52 | ||
53 | static QString appName() { return QString::fromLatin1("opieftp"); } | 53 | static QString appName() { return QString::fromLatin1("opieftp"); } |
54 | QTabWidget *TabWidget; | 54 | QTabWidget *TabWidget; |
55 | QWidget *tab, *tab_2, *tab_3; | 55 | QWidget *tab, *tab_2, *tab_3; |
56 | QListView *Local_View, *Remote_View; | 56 | QListView *Local_View, *Remote_View; |
57 | QListBox *serverListView; | 57 | QListBox *serverListView; |
58 | 58 | ||
59 | QComboBox *UsernameComboBox, *ServerComboBox, *currentPathCombo; | 59 | QComboBox *UsernameComboBox, *ServerComboBox, *currentPathCombo; |
60 | QLineEdit *PasswordEdit, *remotePath; | 60 | QLineEdit *PasswordEdit, *remotePath; |
61 | QLabel *TextLabel2, *TextLabel1, *TextLabel3, *TextLabel4;; | 61 | QLabel *TextLabel2, *TextLabel1, *TextLabel3, *TextLabel4;; |
62 | QSpinBox* PortSpinBox; | 62 | QSpinBox* PortSpinBox; |
63 | QPopupMenu *connectionMenu, *localMenu, *remoteMenu, *tabMenu, *aboutMenu; | 63 | QPopupMenu *connectionMenu, *localMenu, *remoteMenu, *tabMenu, *aboutMenu; |
64 | QDir currentDir; | 64 | QDir currentDir; |
65 | QString currentRemoteDir; | 65 | QString currentRemoteDir; |
66 | QString filterStr; | 66 | QString filterStr; |
67 | QListViewItem * item; | 67 | QListViewItem * item; |
68 | QPushButton *connectServerBtn, *newServerButton;// | 68 | QPushButton *connectServerBtn, *newServerButton;// |
69 | QToolButton *cdUpButton, *homeButton, *docButton; | 69 | QToolButton *cdUpButton, *homeButton, *docButton; |
70 | bool b; | 70 | bool b; |
71 | int currentServerConfig; | 71 | int currentServerConfig; |
72 | protected slots: | 72 | protected slots: |
73 | void timerOut(); | 73 | void timerOut(); |
74 | void upDir(); | 74 | void upDir(); |
75 | void homeButtonPushed(); | 75 | void homeButtonPushed(); |
76 | void docButtonPushed(); | 76 | void docButtonPushed(); |
77 | void doAbout(); | 77 | void doAbout(); |
78 | 78 | ||
79 | void serverComboEdited(const QString & ); | 79 | void serverComboEdited(const QString & ); |
80 | void UsernameComboBoxEdited(const QString & ); | 80 | void UsernameComboBoxEdited(const QString & ); |
81 | void PasswordEditEdited(const QString & ); | 81 | void PasswordEditEdited(const QString & ); |
82 | 82 | ||
83 | void showLocalMenu( QListViewItem *); | 83 | void showLocalMenu( QListViewItem *); |
84 | void showRemoteMenu( QListViewItem *); | 84 | void showRemoteMenu( QListViewItem *); |
85 | void doLocalCd(); | 85 | void doLocalCd(); |
86 | void doRemoteCd(); | 86 | void doRemoteCd(); |
87 | void localUpload(); | 87 | void localUpload(); |
88 | void remoteDownload(); | 88 | void remoteDownload(); |
89 | void newConnection(); | 89 | void newConnection(); |
90 | void connector(); | 90 | void connector(); |
91 | void disConnector(); | 91 | void disConnector(); |
92 | void populateLocalView(); | 92 | void populateLocalView(); |
93 | bool populateRemoteView(); | 93 | bool populateRemoteView(); |
94 | void showHidden(); | 94 | void showHidden(); |
95 | void writeConfig(); | 95 | void writeConfig(); |
96 | void readConfig(); | 96 | void readConfig(); |
97 | void localListClicked(QListViewItem *); | 97 | void localListClicked(QListViewItem *); |
98 | void remoteListClicked(QListViewItem *); | 98 | void remoteListClicked(QListViewItem *); |
99 | void ListPressed( int, QListViewItem *, const QPoint&, int); | 99 | void ListPressed( int, QListViewItem *, const QPoint&, int); |
100 | void RemoteListPressed( int, QListViewItem *, const QPoint&, int); | 100 | void RemoteListPressed( int, QListViewItem *, const QPoint&, int); |
101 | void localMakDir(); | 101 | void localMakDir(); |
102 | void localDelete(); | 102 | void localDelete(); |
103 | void remoteMakDir(); | 103 | void remoteMakDir(); |
104 | void remoteDelete(); | 104 | void remoteDelete(); |
105 | 105 | ||
106 | bool remoteDirList(const QString &); | 106 | bool remoteDirList(const QString &); |
107 | bool remoteChDir(const QString &); | 107 | bool remoteChDir(const QString &); |
108 | 108 | ||
109 | void tabChanged(QWidget*); | 109 | void tabChanged(QWidget*); |
110 | void cleanUp(); | 110 | void cleanUp(); |
111 | 111 | ||
112 | void remoteRename(); | 112 | void remoteRename(); |
113 | void localRename(); | 113 | void localRename(); |
114 | 114 | ||
115 | void currentPathComboChanged(); | 115 | void currentPathComboChanged(); |
116 | void currentPathComboActivated(const QString &); | 116 | void currentPathComboActivated(const QString &); |
117 | void switchToLocalTab(); | 117 | void switchToLocalTab(); |
118 | void switchToRemoteTab(); | 118 | void switchToRemoteTab(); |
119 | void switchToConfigTab(); | 119 | void switchToConfigTab(); |
120 | 120 | ||
121 | void fillCombos(); | 121 | void fillCombos(); |
122 | void clearCombos(); | 122 | void clearCombos(); |
123 | void fillRemoteCombo(const QString&); | 123 | void fillRemoteCombo(const QString&); |
124 | void fillCombo(const QString &); | 124 | void fillCombo(const QString &); |
125 | void serverComboSelected(int); | 125 | void serverComboSelected(int); |
126 | void deleteServer(); | 126 | void deleteServer(); |
127 | void connectorBtnToggled(bool); | 127 | void connectorBtnToggled(bool); |
128 | void NewServer(); | 128 | void NewServer(); |
129 | void serverListClicked( const QString &); | 129 | void serverListClicked( const QString &); |
130 | 130 | ||
131 | protected: | 131 | protected: |
132 | QPixmap unknownXpm; | 132 | QPixmap unknownXpm; |
133 | bool fuckeduphack; | 133 | bool fuckeduphack; |
134 | QStringList remoteDirPathStringList, localDirPathStringList; | 134 | QStringList remoteDirPathStringList, localDirPathStringList; |
135 | QString newServerName; | 135 | QString newServerName; |
136 | void nullifyCallBack(); | 136 | void nullifyCallBack(); |
137 | QGridLayout* tabLayout; | 137 | QGridLayout* tabLayout; |
138 | QGridLayout* tabLayout_2; | 138 | QGridLayout* tabLayout_2; |
139 | QGridLayout* tabLayout_3; | 139 | QGridLayout* tabLayout_3; |
140 | 140 | ||
141 | }; | 141 | }; |
142 | 142 | ||
143 | #endif // OPIEFTP_H | 143 | #endif // OPIEFTP_H |
diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp index 95fbdcd..be6f8ed 100644 --- a/noncore/net/opieirc/mainwindow.cpp +++ b/noncore/net/opieirc/mainwindow.cpp | |||
@@ -1,93 +1,93 @@ | |||
1 | #include <qpe/qpemenubar.h> | 1 | #include <qmenubar.h> |
2 | #include <qpe/resource.h> | 2 | #include <qpe/resource.h> |
3 | #include <qpe/config.h> | 3 | #include <qpe/config.h> |
4 | #include <qpopupmenu.h> | 4 | #include <qpopupmenu.h> |
5 | #include <qwhatsthis.h> | 5 | #include <qwhatsthis.h> |
6 | 6 | ||
7 | #include "mainwindow.h" | 7 | #include "mainwindow.h" |
8 | #include "ircservertab.h" | 8 | #include "ircservertab.h" |
9 | #include "ircserverlist.h" | 9 | #include "ircserverlist.h" |
10 | #include "ircsettings.h" | 10 | #include "ircsettings.h" |
11 | 11 | ||
12 | MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { | 12 | MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { |
13 | setCaption(tr("IRC Client")); | 13 | setCaption(tr("IRC Client")); |
14 | m_tabWidget = new IRCTabWidget(this); | 14 | m_tabWidget = new IRCTabWidget(this); |
15 | QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here")); | 15 | QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here")); |
16 | connect(m_tabWidget, SIGNAL(currentChanged(QWidget *)), this, SLOT(selected(QWidget *))); | 16 | connect(m_tabWidget, SIGNAL(currentChanged(QWidget *)), this, SLOT(selected(QWidget *))); |
17 | setCentralWidget(m_tabWidget); | 17 | setCentralWidget(m_tabWidget); |
18 | setToolBarsMovable(FALSE); | 18 | setToolBarsMovable(FALSE); |
19 | QMenuBar *menuBar = new QMenuBar(this); | 19 | QMenuBar *menuBar = new QMenuBar(this); |
20 | QPopupMenu *irc = new QPopupMenu(this); | 20 | QPopupMenu *irc = new QPopupMenu(this); |
21 | menuBar->insertItem(tr("IRC"), irc); | 21 | menuBar->insertItem(tr("IRC"), irc); |
22 | QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0); | 22 | QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0); |
23 | connect(a, SIGNAL(activated()), this, SLOT(newConnection())); | 23 | connect(a, SIGNAL(activated()), this, SLOT(newConnection())); |
24 | a->setWhatsThis(tr("Create a new connection to an IRC server")); | 24 | a->setWhatsThis(tr("Create a new connection to an IRC server")); |
25 | a->addTo(irc); | 25 | a->addTo(irc); |
26 | a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0); | 26 | a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0); |
27 | a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance")); | 27 | a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance")); |
28 | connect(a, SIGNAL(activated()), this, SLOT(settings())); | 28 | connect(a, SIGNAL(activated()), this, SLOT(settings())); |
29 | a->addTo(irc); | 29 | a->addTo(irc); |
30 | loadSettings(); | 30 | loadSettings(); |
31 | } | 31 | } |
32 | 32 | ||
33 | /*IRCTabWidget MainWindow::getTabWidget(){ | 33 | /*IRCTabWidget MainWindow::getTabWidget(){ |
34 | return m_tabWidget; | 34 | return m_tabWidget; |
35 | } */ | 35 | } */ |
36 | 36 | ||
37 | void MainWindow::loadSettings() { | 37 | void MainWindow::loadSettings() { |
38 | Config config("OpieIRC"); | 38 | Config config("OpieIRC"); |
39 | config.setGroup("OpieIRC"); | 39 | config.setGroup("OpieIRC"); |
40 | IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF"); | 40 | IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF"); |
41 | IRCTab::m_textColor = config.readEntry("TextColor", "#000000"); | 41 | IRCTab::m_textColor = config.readEntry("TextColor", "#000000"); |
42 | IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000"); | 42 | IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000"); |
43 | IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000"); | 43 | IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000"); |
44 | IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB"); | 44 | IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB"); |
45 | IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF"); | 45 | IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF"); |
46 | IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300"); | 46 | IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300"); |
47 | IRCTab::m_maxLines = config.readNumEntry("Lines", 100); | 47 | IRCTab::m_maxLines = config.readNumEntry("Lines", 100); |
48 | } | 48 | } |
49 | 49 | ||
50 | void MainWindow::selected(QWidget *) { | 50 | void MainWindow::selected(QWidget *) { |
51 | m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black); | 51 | m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black); |
52 | emit updateScroll(); | 52 | emit updateScroll(); |
53 | } | 53 | } |
54 | 54 | ||
55 | void MainWindow::addTab(IRCTab *tab) { | 55 | void MainWindow::addTab(IRCTab *tab) { |
56 | connect(tab, SIGNAL(changed(IRCTab *)), this, SLOT(changeEvent(IRCTab *))); | 56 | connect(tab, SIGNAL(changed(IRCTab *)), this, SLOT(changeEvent(IRCTab *))); |
57 | m_tabWidget->addTab(tab, tab->title()); | 57 | m_tabWidget->addTab(tab, tab->title()); |
58 | m_tabWidget->showPage(tab); | 58 | m_tabWidget->showPage(tab); |
59 | tab->setID(m_tabWidget->currentPageIndex()); | 59 | tab->setID(m_tabWidget->currentPageIndex()); |
60 | m_tabs.append(tab); | 60 | m_tabs.append(tab); |
61 | } | 61 | } |
62 | 62 | ||
63 | void MainWindow::changeEvent(IRCTab *tab) { | 63 | void MainWindow::changeEvent(IRCTab *tab) { |
64 | if (tab->id() != m_tabWidget->currentPageIndex()) | 64 | if (tab->id() != m_tabWidget->currentPageIndex()) |
65 | m_tabWidget->setTabColor(tab->id(), blue); | 65 | m_tabWidget->setTabColor(tab->id(), blue); |
66 | } | 66 | } |
67 | 67 | ||
68 | void MainWindow::killTab(IRCTab *tab) { | 68 | void MainWindow::killTab(IRCTab *tab) { |
69 | m_tabWidget->removePage(tab); | 69 | m_tabWidget->removePage(tab); |
70 | m_tabs.remove(tab); | 70 | m_tabs.remove(tab); |
71 | /* there might be nicer ways to do this .. */ | 71 | /* there might be nicer ways to do this .. */ |
72 | delete tab; | 72 | delete tab; |
73 | } | 73 | } |
74 | 74 | ||
75 | void MainWindow::newConnection() { | 75 | void MainWindow::newConnection() { |
76 | IRCServerList list(this, "ServerList", TRUE); | 76 | IRCServerList list(this, "ServerList", TRUE); |
77 | if (list.exec() == QDialog::Accepted && list.hasServer()) { | 77 | if (list.exec() == QDialog::Accepted && list.hasServer()) { |
78 | IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget); | 78 | IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget); |
79 | addTab(serverTab); | 79 | addTab(serverTab); |
80 | serverTab->doConnect(); | 80 | serverTab->doConnect(); |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | void MainWindow::settings() { | 84 | void MainWindow::settings() { |
85 | IRCSettings settings(this, "Settings", TRUE); | 85 | IRCSettings settings(this, "Settings", TRUE); |
86 | if (settings.exec() == QDialog::Accepted) { | 86 | if (settings.exec() == QDialog::Accepted) { |
87 | QListIterator<IRCTab> it(m_tabs); | 87 | QListIterator<IRCTab> it(m_tabs); |
88 | for (; it.current(); ++it) { | 88 | for (; it.current(); ++it) { |
89 | /* Inform all tabs about the new settings */ | 89 | /* Inform all tabs about the new settings */ |
90 | it.current()->settingsChanged(); | 90 | it.current()->settingsChanged(); |
91 | } | 91 | } |
92 | } | 92 | } |
93 | } | 93 | } |
diff --git a/noncore/net/ubrowser/mainview.cpp b/noncore/net/ubrowser/mainview.cpp index 0d3f171..f299b54 100644 --- a/noncore/net/ubrowser/mainview.cpp +++ b/noncore/net/ubrowser/mainview.cpp | |||
@@ -1,121 +1,121 @@ | |||
1 | /* | 1 | /* |
2 | Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing | 2 | Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing |
3 | Copyright (C) 2002 Thomas Stephens | 3 | Copyright (C) 2002 Thomas Stephens |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | 5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public |
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | 6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
7 | version. | 7 | version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | 9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | 10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11 | Public License for more details. | 11 | Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | 13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free |
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 | */ | 15 | */ |
16 | 16 | ||
17 | 17 | ||
18 | #include "mainview.h" | 18 | #include "mainview.h" |
19 | 19 | ||
20 | MainView::MainView(QWidget *parent, const char *name, WFlags fl) : QMainWindow(parent, name, fl) | 20 | MainView::MainView(QWidget *parent, const char *name, WFlags fl) : QMainWindow(parent, name, fl) |
21 | { | 21 | { |
22 | setIcon( Resource::loadPixmap( "remote" ) ); | 22 | setIcon( Resource::loadPixmap( "remote" ) ); |
23 | setCaption(tr("uBrowser")); | 23 | setCaption(tr("uBrowser")); |
24 | 24 | ||
25 | setToolBarsMovable( false ); | 25 | setToolBarsMovable( false ); |
26 | 26 | ||
27 | QPEToolBar *toolbar = new QPEToolBar(this, "toolbar"); | 27 | QToolBar *toolbar = new QToolBar(this, "toolbar"); |
28 | back = new QToolButton(Resource::loadPixmap("ubrowser/back"), 0, 0, 0, 0, toolbar, "back"); | 28 | back = new QToolButton(Resource::loadPixmap("ubrowser/back"), 0, 0, 0, 0, toolbar, "back"); |
29 | forward = new QToolButton(Resource::loadPixmap("ubrowser/forward"), 0, 0, 0, 0, toolbar, "forward"); | 29 | forward = new QToolButton(Resource::loadPixmap("ubrowser/forward"), 0, 0, 0, 0, toolbar, "forward"); |
30 | home = new QToolButton(Resource::loadPixmap("ubrowser/home"), 0, 0, 0, 0, toolbar, "home"); | 30 | home = new QToolButton(Resource::loadPixmap("ubrowser/home"), 0, 0, 0, 0, toolbar, "home"); |
31 | location = new QComboBox(true, toolbar, "location"); | 31 | location = new QComboBox(true, toolbar, "location"); |
32 | go = new QToolButton(Resource::loadPixmap("ubrowser/go"), 0, 0, 0, 0, toolbar, "go"); | 32 | go = new QToolButton(Resource::loadPixmap("ubrowser/go"), 0, 0, 0, 0, toolbar, "go"); |
33 | 33 | ||
34 | toolbar->setStretchableWidget(location); | 34 | toolbar->setStretchableWidget(location); |
35 | toolbar->setHorizontalStretchable(true); | 35 | toolbar->setHorizontalStretchable(true); |
36 | location->setAutoCompletion( true ); | 36 | location->setAutoCompletion( true ); |
37 | 37 | ||
38 | addToolBar(toolbar); | 38 | addToolBar(toolbar); |
39 | 39 | ||
40 | browser = new QTextBrowser(this, "browser"); | 40 | browser = new QTextBrowser(this, "browser"); |
41 | setCentralWidget(browser); | 41 | setCentralWidget(browser); |
42 | 42 | ||
43 | //make the button take you to the location | 43 | //make the button take you to the location |
44 | connect(go, SIGNAL(clicked()), this, SLOT(goClicked()) ); | 44 | connect(go, SIGNAL(clicked()), this, SLOT(goClicked()) ); |
45 | connect(location->lineEdit(), SIGNAL(returnPressed()), this, SLOT(goClicked()) ); | 45 | connect(location->lineEdit(), SIGNAL(returnPressed()), this, SLOT(goClicked()) ); |
46 | 46 | ||
47 | //make back, forward and home do their thing (isnt QTextBrowser great?) | 47 | //make back, forward and home do their thing (isnt QTextBrowser great?) |
48 | connect(back, SIGNAL(clicked()), browser, SLOT(backward()) ); | 48 | connect(back, SIGNAL(clicked()), browser, SLOT(backward()) ); |
49 | connect(forward, SIGNAL(clicked()), browser, SLOT(forward()) ); | 49 | connect(forward, SIGNAL(clicked()), browser, SLOT(forward()) ); |
50 | connect(home, SIGNAL(clicked()), browser, SLOT(home()) ); | 50 | connect(home, SIGNAL(clicked()), browser, SLOT(home()) ); |
51 | 51 | ||
52 | //make back and forward buttons be enabled, only when you can go back or forward (again, i love QTextBrowser) | 52 | //make back and forward buttons be enabled, only when you can go back or forward (again, i love QTextBrowser) |
53 | //this doesnt seem to work, but doesnt break anything either... | 53 | //this doesnt seem to work, but doesnt break anything either... |
54 | connect(browser, SIGNAL(backwardAvailable(bool)), back, SLOT(setOn(bool)) ); | 54 | connect(browser, SIGNAL(backwardAvailable(bool)), back, SLOT(setOn(bool)) ); |
55 | connect(browser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setOn(bool)) ); | 55 | connect(browser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setOn(bool)) ); |
56 | 56 | ||
57 | //notify me when the text of the browser has changed (like when the user clicks a link) | 57 | //notify me when the text of the browser has changed (like when the user clicks a link) |
58 | connect(browser, SIGNAL(textChanged()), this, SLOT(textChanged()) ); | 58 | connect(browser, SIGNAL(textChanged()), this, SLOT(textChanged()) ); |
59 | 59 | ||
60 | http = new HttpFactory(browser); | 60 | http = new HttpFactory(browser); |
61 | 61 | ||
62 | if( qApp->argc() > 1 ) | 62 | if( qApp->argc() > 1 ) |
63 | { | 63 | { |
64 | char **argv = qApp->argv(); | 64 | char **argv = qApp->argv(); |
65 | int i = 0; | 65 | int i = 0; |
66 | QString *openfile = new QString( argv[0] ); | 66 | QString *openfile = new QString( argv[0] ); |
67 | while( openfile->contains( "ubrowser" ) == 0 && i < qApp->argc() ) | 67 | while( openfile->contains( "ubrowser" ) == 0 && i < qApp->argc() ) |
68 | { | 68 | { |
69 | i++; | 69 | i++; |
70 | *openfile = argv[i]; | 70 | *openfile = argv[i]; |
71 | } | 71 | } |
72 | *openfile = argv[i+1]; | 72 | *openfile = argv[i+1]; |
73 | if( !openfile->startsWith( "http://" ) && !openfile->startsWith( "/" ) ) | 73 | if( !openfile->startsWith( "http://" ) && !openfile->startsWith( "/" ) ) |
74 | { | 74 | { |
75 | openfile->insert( 0, QDir::currentDirPath()+"/" ); | 75 | openfile->insert( 0, QDir::currentDirPath()+"/" ); |
76 | } | 76 | } |
77 | location->setEditText( *openfile ); | 77 | location->setEditText( *openfile ); |
78 | goClicked(); | 78 | goClicked(); |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | void MainView::goClicked() | 82 | void MainView::goClicked() |
83 | { | 83 | { |
84 | location->insertItem( location->currentText() ); | 84 | location->insertItem( location->currentText() ); |
85 | 85 | ||
86 | if(location->currentText().startsWith("http://") ) | 86 | if(location->currentText().startsWith("http://") ) |
87 | { | 87 | { |
88 | location->setEditText(location->currentText().lower()); | 88 | location->setEditText(location->currentText().lower()); |
89 | browser->setMimeSourceFactory(http); | 89 | browser->setMimeSourceFactory(http); |
90 | printf("MainView::goClicked: using http source factory\n"); | 90 | printf("MainView::goClicked: using http source factory\n"); |
91 | } | 91 | } |
92 | else | 92 | else |
93 | { | 93 | { |
94 | browser->setMimeSourceFactory(QMimeSourceFactory::defaultFactory()); | 94 | browser->setMimeSourceFactory(QMimeSourceFactory::defaultFactory()); |
95 | printf("MainView::goClicked: using default source factory\n"); | 95 | printf("MainView::goClicked: using default source factory\n"); |
96 | } | 96 | } |
97 | 97 | ||
98 | browser->setSource(location->currentText()); | 98 | browser->setSource(location->currentText()); |
99 | } | 99 | } |
100 | 100 | ||
101 | void MainView::textChanged() | 101 | void MainView::textChanged() |
102 | { | 102 | { |
103 | if(browser->documentTitle().isNull()) | 103 | if(browser->documentTitle().isNull()) |
104 | { | 104 | { |
105 | setCaption( tr("%1 - uBrowser").arg( browser->source() ) ); | 105 | setCaption( tr("%1 - uBrowser").arg( browser->source() ) ); |
106 | } | 106 | } |
107 | else | 107 | else |
108 | { | 108 | { |
109 | setCaption(tr(" - uBrowser").arg( browser->documentTitle() )); | 109 | setCaption(tr(" - uBrowser").arg( browser->documentTitle() )); |
110 | } | 110 | } |
111 | 111 | ||
112 | location->setEditText(browser->source()); | 112 | location->setEditText(browser->source()); |
113 | } | 113 | } |
114 | 114 | ||
115 | void MainView::setDocument( const QString& applnk_filename ) | 115 | void MainView::setDocument( const QString& applnk_filename ) |
116 | { | 116 | { |
117 | DocLnk *file = new DocLnk( applnk_filename ); | 117 | DocLnk *file = new DocLnk( applnk_filename ); |
118 | 118 | ||
119 | location->setEditText( file->file() ); | 119 | location->setEditText( file->file() ); |
120 | goClicked(); | 120 | goClicked(); |
121 | } | 121 | } |
diff --git a/noncore/net/ubrowser/mainview.h b/noncore/net/ubrowser/mainview.h index cc63729..7ce890c 100644 --- a/noncore/net/ubrowser/mainview.h +++ b/noncore/net/ubrowser/mainview.h | |||
@@ -1,53 +1,53 @@ | |||
1 | /* | 1 | /* |
2 | Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing | 2 | Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing |
3 | Copyright (C) 2002 Thomas Stephens | 3 | Copyright (C) 2002 Thomas Stephens |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | 5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public |
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | 6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later |
7 | version. | 7 | version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | 9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | 10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11 | Public License for more details. | 11 | Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | 13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free |
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <qpe/resource.h> | 17 | #include <qpe/resource.h> |
18 | #include <qpe/qpetoolbar.h> | 18 | #include <qtoolbar.h> |
19 | #include <qpe/applnk.h> | 19 | #include <qpe/applnk.h> |
20 | 20 | ||
21 | #include <qapplication.h> | 21 | #include <qapplication.h> |
22 | #include <qmainwindow.h> | 22 | #include <qmainwindow.h> |
23 | #include <qwidget.h> | 23 | #include <qwidget.h> |
24 | #include <qtextbrowser.h> | 24 | #include <qtextbrowser.h> |
25 | #include <qtoolbutton.h> | 25 | #include <qtoolbutton.h> |
26 | #include <qcombobox.h> | 26 | #include <qcombobox.h> |
27 | #include <qlayout.h> | 27 | #include <qlayout.h> |
28 | #include <qlineedit.h> | 28 | #include <qlineedit.h> |
29 | #include <qdir.h> | 29 | #include <qdir.h> |
30 | 30 | ||
31 | #include <stdio.h> | 31 | #include <stdio.h> |
32 | 32 | ||
33 | #include "httpfactory.h" | 33 | #include "httpfactory.h" |
34 | 34 | ||
35 | class MainView : public QMainWindow | 35 | class MainView : public QMainWindow |
36 | { | 36 | { |
37 | Q_OBJECT | 37 | Q_OBJECT |
38 | public: | 38 | public: |
39 | static QString appName() { return QString::fromLatin1("ubrowser"); } | 39 | static QString appName() { return QString::fromLatin1("ubrowser"); } |
40 | MainView(QWidget *parent=0, const char *name=0, WFlags fl = 0); | 40 | MainView(QWidget *parent=0, const char *name=0, WFlags fl = 0); |
41 | public slots: | 41 | public slots: |
42 | void goClicked(); | 42 | void goClicked(); |
43 | void textChanged(); | 43 | void textChanged(); |
44 | void setDocument( const QString& applnk_filename ); | 44 | void setDocument( const QString& applnk_filename ); |
45 | private: | 45 | private: |
46 | QToolButton *back; | 46 | QToolButton *back; |
47 | QToolButton *forward; | 47 | QToolButton *forward; |
48 | QToolButton *home; | 48 | QToolButton *home; |
49 | QToolButton *go; | 49 | QToolButton *go; |
50 | QComboBox *location; | 50 | QComboBox *location; |
51 | QTextBrowser *browser; | 51 | QTextBrowser *browser; |
52 | HttpFactory *http; | 52 | HttpFactory *http; |
53 | }; | 53 | }; |
diff --git a/noncore/settings/usermanager/usermanager.cpp b/noncore/settings/usermanager/usermanager.cpp index 65bbd8b..5c90525 100644 --- a/noncore/settings/usermanager/usermanager.cpp +++ b/noncore/settings/usermanager/usermanager.cpp | |||
@@ -1,258 +1,258 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | #include "usermanager.h" | 10 | #include "usermanager.h" |
11 | 11 | ||
12 | #include <qlayout.h> | 12 | #include <qlayout.h> |
13 | #include <stdio.h> | 13 | #include <stdio.h> |
14 | 14 | ||
15 | #include <qmessagebox.h> | 15 | #include <qmessagebox.h> |
16 | #include <qfile.h> | 16 | #include <qfile.h> |
17 | #include <qpe/resource.h> | 17 | #include <qpe/resource.h> |
18 | 18 | ||
19 | #include <qregexp.h> | 19 | #include <qregexp.h> |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * The mainwindow constructor. | 22 | * The mainwindow constructor. |
23 | * | 23 | * |
24 | * @param QWidget *parent | 24 | * @param QWidget *parent |
25 | * @param const char *name | 25 | * @param const char *name |
26 | * @ param WFlags fl | 26 | * @ param WFlags fl |
27 | * | 27 | * |
28 | */ | 28 | */ |
29 | UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { | 29 | UserConfig::UserConfig(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { |
30 | setCaption(tr("Opie User Manager")); | 30 | setCaption(tr("Opie User Manager")); |
31 | 31 | ||
32 | // Create an instance of the global object 'accounts'. This holds all user/group info, and functions to modify them. | 32 | // Create an instance of the global object 'accounts'. This holds all user/group info, and functions to modify them. |
33 | accounts=new Passwd(); | 33 | accounts=new Passwd(); |
34 | accounts->open();// This actually loads the files /etc/passwd & /etc/group into memory. | 34 | accounts->open();// This actually loads the files /etc/passwd & /etc/group into memory. |
35 | 35 | ||
36 | // Create the toolbar. | 36 | // Create the toolbar. |
37 | QPEToolBar *toolbar = new QPEToolBar(this,"Toolbar"); | 37 | QToolBar *toolbar = new QToolBar(this,"Toolbar"); |
38 | toolbar->setHorizontalStretchable(1); // Is there any other way to get the toolbar to stretch of the full screen!? | 38 | toolbar->setHorizontalStretchable(1); // Is there any other way to get the toolbar to stretch of the full screen!? |
39 | adduserToolButton = new QToolButton(Resource::loadPixmap("usermanager/adduser"),"Add User",0,this,SLOT(addUser()),toolbar,"Add User"); | 39 | adduserToolButton = new QToolButton(Resource::loadPixmap("usermanager/adduser"),"Add User",0,this,SLOT(addUser()),toolbar,"Add User"); |
40 | edituserToolButton = new QToolButton(Resource::loadPixmap("usermanager/edituser"),"Edit User",0,this,SLOT(editUser()),toolbar,"Edit User"); | 40 | edituserToolButton = new QToolButton(Resource::loadPixmap("usermanager/edituser"),"Edit User",0,this,SLOT(editUser()),toolbar,"Edit User"); |
41 | deleteuserToolButton = new QToolButton(Resource::loadPixmap("usermanager/deleteuser"),"Delete User",0,this,SLOT(delUser()),toolbar,"Delete User"); | 41 | deleteuserToolButton = new QToolButton(Resource::loadPixmap("usermanager/deleteuser"),"Delete User",0,this,SLOT(delUser()),toolbar,"Delete User"); |
42 | QToolButton *userstext = new QToolButton(0,"User",0,0,0,toolbar,"User"); | 42 | QToolButton *userstext = new QToolButton(0,"User",0,0,0,toolbar,"User"); |
43 | userstext->setUsesTextLabel(true); | 43 | userstext->setUsesTextLabel(true); |
44 | toolbar->addSeparator(); | 44 | toolbar->addSeparator(); |
45 | addgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/addgroup"),"Add Group",0,this,SLOT(addGroup()),toolbar,"Add Group"); | 45 | addgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/addgroup"),"Add Group",0,this,SLOT(addGroup()),toolbar,"Add Group"); |
46 | editgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/editgroup"),"Edit Group",0,this,SLOT(editGroup()),toolbar,"Edit Group"); | 46 | editgroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/editgroup"),"Edit Group",0,this,SLOT(editGroup()),toolbar,"Edit Group"); |
47 | deletegroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/deletegroup"),"Delete Group",0,this,SLOT(delGroup()),toolbar,"Delete Group"); | 47 | deletegroupToolButton = new QToolButton(Resource::loadPixmap("usermanager/deletegroup"),"Delete Group",0,this,SLOT(delGroup()),toolbar,"Delete Group"); |
48 | QToolButton *groupstext = new QToolButton(0,"Group",0,0,0,toolbar,"Group"); | 48 | QToolButton *groupstext = new QToolButton(0,"Group",0,0,0,toolbar,"Group"); |
49 | groupstext->setUsesTextLabel(true); | 49 | groupstext->setUsesTextLabel(true); |
50 | addToolBar(toolbar,"myToolBar"); | 50 | addToolBar(toolbar,"myToolBar"); |
51 | 51 | ||
52 | // Add a tabwidget and all the tabs. | 52 | // Add a tabwidget and all the tabs. |
53 | myTabWidget = new QTabWidget(this,"My Tab Widget"); | 53 | myTabWidget = new QTabWidget(this,"My Tab Widget"); |
54 | setupTabAccounts(); | 54 | setupTabAccounts(); |
55 | setupTabAllUsers(); | 55 | setupTabAllUsers(); |
56 | setupTabAllGroups(); | 56 | setupTabAllGroups(); |
57 | userPopupMenu.insertItem("Copy",0); | 57 | userPopupMenu.insertItem("Copy",0); |
58 | 58 | ||
59 | getUsers(); // Fill out the iconview & listview with all users. | 59 | getUsers(); // Fill out the iconview & listview with all users. |
60 | getGroups(); // Fill out the group listview with all groups. | 60 | getGroups(); // Fill out the group listview with all groups. |
61 | 61 | ||
62 | setCentralWidget(myTabWidget); | 62 | setCentralWidget(myTabWidget); |
63 | } | 63 | } |
64 | 64 | ||
65 | UserConfig::~UserConfig() { | 65 | UserConfig::~UserConfig() { |
66 | accounts->close(); | 66 | accounts->close(); |
67 | delete accounts; | 67 | delete accounts; |
68 | } | 68 | } |
69 | 69 | ||
70 | void UserConfig::setupTabAccounts() { | 70 | void UserConfig::setupTabAccounts() { |
71 | QWidget *tabpage = new QWidget(this); | 71 | QWidget *tabpage = new QWidget(this); |
72 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 72 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
73 | layout->setMargin(5); | 73 | layout->setMargin(5); |
74 | 74 | ||
75 | usersIconView=new QListView(tabpage,"users"); | 75 | usersIconView=new QListView(tabpage,"users"); |
76 | usersIconView->addColumn("Icon"); | 76 | usersIconView->addColumn("Icon"); |
77 | usersIconView->addColumn("Username"); | 77 | usersIconView->addColumn("Username"); |
78 | usersIconView->setAllColumnsShowFocus(true); | 78 | usersIconView->setAllColumnsShowFocus(true); |
79 | layout->addWidget(usersIconView); | 79 | layout->addWidget(usersIconView); |
80 | 80 | ||
81 | connect(usersIconView,SIGNAL(returnPressed(QListViewItem *)),this,SLOT(showUserMenu(QListViewItem *))); | 81 | connect(usersIconView,SIGNAL(returnPressed(QListViewItem *)),this,SLOT(showUserMenu(QListViewItem *))); |
82 | 82 | ||
83 | myTabWidget->addTab(tabpage,"Users"); | 83 | myTabWidget->addTab(tabpage,"Users"); |
84 | } | 84 | } |
85 | 85 | ||
86 | void UserConfig::setupTabAllUsers() { | 86 | void UserConfig::setupTabAllUsers() { |
87 | QWidget *tabpage = new QWidget(this); | 87 | QWidget *tabpage = new QWidget(this); |
88 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 88 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
89 | layout->setMargin(5); | 89 | layout->setMargin(5); |
90 | 90 | ||
91 | usersListView=new QListView(tabpage,"allusers"); | 91 | usersListView=new QListView(tabpage,"allusers"); |
92 | usersListView->addColumn("UID"); | 92 | usersListView->addColumn("UID"); |
93 | usersListView->addColumn("Login"); | 93 | usersListView->addColumn("Login"); |
94 | usersListView->addColumn("Username"); | 94 | usersListView->addColumn("Username"); |
95 | layout->addWidget(usersListView); | 95 | layout->addWidget(usersListView); |
96 | usersListView->setSorting(1,1); | 96 | usersListView->setSorting(1,1); |
97 | usersListView->setAllColumnsShowFocus(true); | 97 | usersListView->setAllColumnsShowFocus(true); |
98 | 98 | ||
99 | myTabWidget->addTab(tabpage,"All Users"); | 99 | myTabWidget->addTab(tabpage,"All Users"); |
100 | } | 100 | } |
101 | 101 | ||
102 | void UserConfig::setupTabAllGroups() { | 102 | void UserConfig::setupTabAllGroups() { |
103 | QWidget *tabpage = new QWidget(this); | 103 | QWidget *tabpage = new QWidget(this); |
104 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 104 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
105 | layout->setMargin(5); | 105 | layout->setMargin(5); |
106 | 106 | ||
107 | groupsListView=new QListView(tabpage,"groups"); | 107 | groupsListView=new QListView(tabpage,"groups"); |
108 | groupsListView->addColumn("GID"); | 108 | groupsListView->addColumn("GID"); |
109 | groupsListView->addColumn("Groupname"); | 109 | groupsListView->addColumn("Groupname"); |
110 | layout->addWidget(groupsListView); | 110 | layout->addWidget(groupsListView); |
111 | groupsListView->setSorting(1,1); | 111 | groupsListView->setSorting(1,1); |
112 | groupsListView->setAllColumnsShowFocus(true); | 112 | groupsListView->setAllColumnsShowFocus(true); |
113 | 113 | ||
114 | myTabWidget->addTab(tabpage,"All Groups"); | 114 | myTabWidget->addTab(tabpage,"All Groups"); |
115 | } | 115 | } |
116 | void UserConfig::getUsers() { | 116 | void UserConfig::getUsers() { |
117 | QString mytext; | 117 | QString mytext; |
118 | QPixmap mypixmap; | 118 | QPixmap mypixmap; |
119 | QListViewItem *listviewitem; | 119 | QListViewItem *listviewitem; |
120 | 120 | ||
121 | // Empty the iconview & the listview. | 121 | // Empty the iconview & the listview. |
122 | usersIconView->clear(); | 122 | usersIconView->clear(); |
123 | usersListView->clear(); | 123 | usersListView->clear(); |
124 | 124 | ||
125 | // availableUID is used as a deposite for the next available UID on the system, this should start at an ID over 500. | 125 | // availableUID is used as a deposite for the next available UID on the system, this should start at an ID over 500. |
126 | availableUID=500; | 126 | availableUID=500; |
127 | for(QStringList::Iterator it=accounts->passwdStringList.begin(); it!=accounts->passwdStringList.end(); ++it) { | 127 | for(QStringList::Iterator it=accounts->passwdStringList.begin(); it!=accounts->passwdStringList.end(); ++it) { |
128 | accounts->splitPasswdEntry(*it); // Split the string into it's components and store in variables in the accounts object. ("pr_name" and so on.) | 128 | accounts->splitPasswdEntry(*it); // Split the string into it's components and store in variables in the accounts object. ("pr_name" and so on.) |
129 | if(accounts->pw_name.find(QRegExp("^#"),0)) {// Skip commented lines. | 129 | if(accounts->pw_name.find(QRegExp("^#"),0)) {// Skip commented lines. |
130 | new QListViewItem(usersListView,QString::number(accounts->pw_uid),accounts->pw_name,accounts->pw_gecos); | 130 | new QListViewItem(usersListView,QString::number(accounts->pw_uid),accounts->pw_name,accounts->pw_gecos); |
131 | if((accounts->pw_uid>=500) && (accounts->pw_uid<65000)) {// Is this user a "normal" user ? | 131 | if((accounts->pw_uid>=500) && (accounts->pw_uid<65000)) {// Is this user a "normal" user ? |
132 | mytext=QString(accounts->pw_name)+" - ("+QString(accounts->pw_gecos)+")"; // The string displayed next to the icon. | 132 | mytext=QString(accounts->pw_name)+" - ("+QString(accounts->pw_gecos)+")"; // The string displayed next to the icon. |
133 | if(!(mypixmap.load("/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"))) { // Is there an icon for this user? Resource::loadPixmap is caching, doesn't work. | 133 | if(!(mypixmap.load("/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"))) { // Is there an icon for this user? Resource::loadPixmap is caching, doesn't work. |
134 | mypixmap=Resource::loadPixmap(QString("usermanager/usericon"));// If this user has no icon, load the default icon. | 134 | mypixmap=Resource::loadPixmap(QString("usermanager/usericon"));// If this user has no icon, load the default icon. |
135 | } | 135 | } |
136 | listviewitem=new QListViewItem(usersIconView,"",mytext);// Add the icon+text to the qiconview. | 136 | listviewitem=new QListViewItem(usersIconView,"",mytext);// Add the icon+text to the qiconview. |
137 | listviewitem->setPixmap(0,mypixmap); | 137 | listviewitem->setPixmap(0,mypixmap); |
138 | } | 138 | } |
139 | if((accounts->pw_uid>=availableUID) && (accounts->pw_uid<65000)) availableUID=accounts->pw_uid+1; // Increase 1 to the latest know UID to get a free uid. | 139 | if((accounts->pw_uid>=availableUID) && (accounts->pw_uid<65000)) availableUID=accounts->pw_uid+1; // Increase 1 to the latest know UID to get a free uid. |
140 | } | 140 | } |
141 | } | 141 | } |
142 | usersIconView->sort(); | 142 | usersIconView->sort(); |
143 | } | 143 | } |
144 | 144 | ||
145 | void UserConfig::addUser() { | 145 | void UserConfig::addUser() { |
146 | if(UserDialog::addUser(availableUID,availableGID)) {// Add the user to the system, also send next available UID and GID. | 146 | if(UserDialog::addUser(availableUID,availableGID)) {// Add the user to the system, also send next available UID and GID. |
147 | getUsers(); // Update users views. | 147 | getUsers(); // Update users views. |
148 | getGroups(); // Update groups view. | 148 | getGroups(); // Update groups view. |
149 | } | 149 | } |
150 | } | 150 | } |
151 | 151 | ||
152 | void UserConfig::editUser() { | 152 | void UserConfig::editUser() { |
153 | QString username; | 153 | QString username; |
154 | if(myTabWidget->currentPageIndex()==0) {// Users | 154 | if(myTabWidget->currentPageIndex()==0) {// Users |
155 | if(usersIconView->currentItem()) {// Any icon selected? | 155 | if(usersIconView->currentItem()) {// Any icon selected? |
156 | username=usersIconView->currentItem()->text(1);// Get the text associated with the icon. | 156 | username=usersIconView->currentItem()->text(1);// Get the text associated with the icon. |
157 | username=username.left(username.find(" - (",0,true));// Strip out the username. | 157 | username=username.left(username.find(" - (",0,true));// Strip out the username. |
158 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. | 158 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. |
159 | // If there were any changed also update the views. | 159 | // If there were any changed also update the views. |
160 | getUsers(); | 160 | getUsers(); |
161 | getGroups(); | 161 | getGroups(); |
162 | } | 162 | } |
163 | } else { | 163 | } else { |
164 | QMessageBox::information(this,"No selection.","No user has been selected."); | 164 | QMessageBox::information(this,"No selection.","No user has been selected."); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | if(myTabWidget->currentPageIndex()==1) {// All users | 167 | if(myTabWidget->currentPageIndex()==1) {// All users |
168 | if(usersListView->currentItem()) {// Anything changed!? | 168 | if(usersListView->currentItem()) {// Anything changed!? |
169 | username=usersListView->currentItem()->text(1);// Get the username. | 169 | username=usersListView->currentItem()->text(1);// Get the username. |
170 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. | 170 | if(UserDialog::editUser(username)) {// Bring up the userinfo dialog. |
171 | // And again update the views if there were any changes. | 171 | // And again update the views if there were any changes. |
172 | getUsers(); | 172 | getUsers(); |
173 | getGroups(); | 173 | getGroups(); |
174 | } | 174 | } |
175 | } else { | 175 | } else { |
176 | QMessageBox::information(this,"No selection.","No user has been selected."); | 176 | QMessageBox::information(this,"No selection.","No user has been selected."); |
177 | } | 177 | } |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | void UserConfig::delUser() { | 181 | void UserConfig::delUser() { |
182 | QString username; | 182 | QString username; |
183 | 183 | ||
184 | if(myTabWidget->currentPageIndex()==0) {// Users, Iconview. | 184 | if(myTabWidget->currentPageIndex()==0) {// Users, Iconview. |
185 | if(usersIconView->currentItem()) {// Anything selected? | 185 | if(usersIconView->currentItem()) {// Anything selected? |
186 | username=usersIconView->currentItem()->text(1);// Get string associated with icon. | 186 | username=usersIconView->currentItem()->text(1);// Get string associated with icon. |
187 | username=username.left(username.find(" - (",0,true));// Strip out the username. | 187 | username=username.left(username.find(" - (",0,true));// Strip out the username. |
188 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { | 188 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { |
189 | if(UserDialog::delUser(username)) {// Delete the user if possible. | 189 | if(UserDialog::delUser(username)) {// Delete the user if possible. |
190 | // Update views. | 190 | // Update views. |
191 | getUsers(); | 191 | getUsers(); |
192 | getGroups(); | 192 | getGroups(); |
193 | } | 193 | } |
194 | } | 194 | } |
195 | } else { | 195 | } else { |
196 | QMessageBox::information(this,"No selection","No user has been selected."); | 196 | QMessageBox::information(this,"No selection","No user has been selected."); |
197 | } | 197 | } |
198 | } | 198 | } |
199 | if(myTabWidget->currentPageIndex()==1) {// All users | 199 | if(myTabWidget->currentPageIndex()==1) {// All users |
200 | if(usersListView->currentItem()) {// Anything changed!? | 200 | if(usersListView->currentItem()) {// Anything changed!? |
201 | username=usersListView->currentItem()->text(1);// Get the username. | 201 | username=usersListView->currentItem()->text(1);// Get the username. |
202 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { | 202 | if(QMessageBox::warning(this,"Delete user","Are you sure you want to\ndelete this user? \""+QString(username)+"\" ?","&No","&Yes",0,0,1)) { |
203 | if(UserDialog::delUser(username)) {// Try to delete the user. | 203 | if(UserDialog::delUser(username)) {// Try to delete the user. |
204 | // Update views. | 204 | // Update views. |
205 | getUsers(); | 205 | getUsers(); |
206 | getGroups(); | 206 | getGroups(); |
207 | } | 207 | } |
208 | } | 208 | } |
209 | } else { | 209 | } else { |
210 | QMessageBox::information(this,"No selection","No user has been selected."); | 210 | QMessageBox::information(this,"No selection","No user has been selected."); |
211 | } | 211 | } |
212 | } | 212 | } |
213 | 213 | ||
214 | } | 214 | } |
215 | 215 | ||
216 | void UserConfig::getGroups() { | 216 | void UserConfig::getGroups() { |
217 | groupsListView->clear();// Empty the listview. | 217 | groupsListView->clear();// Empty the listview. |
218 | availableGID=500;// We need to find the next free GID, and are only interested in values between 500 & 65000. | 218 | availableGID=500;// We need to find the next free GID, and are only interested in values between 500 & 65000. |
219 | for(QStringList::Iterator it=accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {// Split the list into lines. | 219 | for(QStringList::Iterator it=accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {// Split the list into lines. |
220 | accounts->splitGroupEntry(*it);// Split the line into its components and fill the variables of 'accounts'. (gr_name, gr_uid & gr_mem). | 220 | accounts->splitGroupEntry(*it);// Split the line into its components and fill the variables of 'accounts'. (gr_name, gr_uid & gr_mem). |
221 | if(accounts->gr_name.find(QRegExp("^#"),0)) {// Skip commented lines. | 221 | if(accounts->gr_name.find(QRegExp("^#"),0)) {// Skip commented lines. |
222 | new QListViewItem(groupsListView,QString::number(accounts->gr_gid),accounts->gr_name); | 222 | new QListViewItem(groupsListView,QString::number(accounts->gr_gid),accounts->gr_name); |
223 | if((accounts->gr_gid>=availableGID) && (accounts->gr_gid<65000)) availableGID=accounts->gr_gid+1;// Maybe a new free GID. | 223 | if((accounts->gr_gid>=availableGID) && (accounts->gr_gid<65000)) availableGID=accounts->gr_gid+1;// Maybe a new free GID. |
224 | } | 224 | } |
225 | } | 225 | } |
226 | } | 226 | } |
227 | 227 | ||
228 | void UserConfig::addGroup() { | 228 | void UserConfig::addGroup() { |
229 | if(GroupDialog::addGroup(availableGID)) getGroups();// Bring up the add group dialog. | 229 | if(GroupDialog::addGroup(availableGID)) getGroups();// Bring up the add group dialog. |
230 | } | 230 | } |
231 | 231 | ||
232 | void UserConfig::editGroup() { | 232 | void UserConfig::editGroup() { |
233 | int gid; | 233 | int gid; |
234 | if(groupsListView->currentItem()) {// Any group selected? | 234 | if(groupsListView->currentItem()) {// Any group selected? |
235 | gid=groupsListView->currentItem()->text(0).toInt();// Get the GID from the listview. | 235 | gid=groupsListView->currentItem()->text(0).toInt();// Get the GID from the listview. |
236 | if(GroupDialog::editGroup(gid)) getGroups();// Bring up the edit group dialog. | 236 | if(GroupDialog::editGroup(gid)) getGroups();// Bring up the edit group dialog. |
237 | } else { | 237 | } else { |
238 | QMessageBox::information(this,"No selection","No group has been selected."); | 238 | QMessageBox::information(this,"No selection","No group has been selected."); |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | void UserConfig::delGroup() { | 242 | void UserConfig::delGroup() { |
243 | const char *groupname; | 243 | const char *groupname; |
244 | if(groupsListView->currentItem()) {// Any group selected? | 244 | if(groupsListView->currentItem()) {// Any group selected? |
245 | groupname=groupsListView->currentItem()->text(1);// Get the groupname from the listview. | 245 | groupname=groupsListView->currentItem()->text(1);// Get the groupname from the listview. |
246 | if(QMessageBox::warning(this,"Delete group","Are you sure you want to\ndelete the group \""+QString(groupname)+"\" ?","&No","&Yes",0,0,1)) { | 246 | if(QMessageBox::warning(this,"Delete group","Are you sure you want to\ndelete the group \""+QString(groupname)+"\" ?","&No","&Yes",0,0,1)) { |
247 | // If confirmed, try to delete the group. | 247 | // If confirmed, try to delete the group. |
248 | if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted. | 248 | if(GroupDialog::delGroup(groupname)) getGroups(); // And also update the view afterwards if the user was deleted. |
249 | } | 249 | } |
250 | } else { | 250 | } else { |
251 | QMessageBox::information(this,"No selection","No group has been selected."); | 251 | QMessageBox::information(this,"No selection","No group has been selected."); |
252 | } | 252 | } |
253 | } | 253 | } |
254 | 254 | ||
255 | void UserConfig::showUserMenu(QListViewItem *item) { | 255 | void UserConfig::showUserMenu(QListViewItem *item) { |
256 | //userPopupMenu.exec(item->mapToGlobal(QPoint(0,0))); | 256 | //userPopupMenu.exec(item->mapToGlobal(QPoint(0,0))); |
257 | qWarning("Pressed!"); | 257 | qWarning("Pressed!"); |
258 | } | 258 | } |
diff --git a/noncore/settings/usermanager/usermanager.h b/noncore/settings/usermanager/usermanager.h index d7c25b8..678d1f9 100644 --- a/noncore/settings/usermanager/usermanager.h +++ b/noncore/settings/usermanager/usermanager.h | |||
@@ -1,67 +1,67 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | 9 | ||
10 | #ifndef USERCONFIG_H | 10 | #ifndef USERCONFIG_H |
11 | #define USERCONFIG_H | 11 | #define USERCONFIG_H |
12 | 12 | ||
13 | #include <qmainwindow.h> | 13 | #include <qmainwindow.h> |
14 | #include <qtabwidget.h> | 14 | #include <qtabwidget.h> |
15 | #include <qlistview.h> | 15 | #include <qlistview.h> |
16 | #include <qpopupmenu.h> | 16 | #include <qpopupmenu.h> |
17 | #include <qtoolbutton.h> | 17 | #include <qtoolbutton.h> |
18 | 18 | ||
19 | #include <qpe/qpetoolbar.h> | 19 | #include <qtoolbar.h> |
20 | 20 | ||
21 | #include "userdialog.h" | 21 | #include "userdialog.h" |
22 | #include "groupdialog.h" | 22 | #include "groupdialog.h" |
23 | #include "passwd.h" | 23 | #include "passwd.h" |
24 | 24 | ||
25 | class UserConfig : public QMainWindow | 25 | class UserConfig : public QMainWindow |
26 | { | 26 | { |
27 | Q_OBJECT | 27 | Q_OBJECT |
28 | 28 | ||
29 | public: | 29 | public: |
30 | static QString appName() { return QString::fromLatin1("usermanager"); } | 30 | static QString appName() { return QString::fromLatin1("usermanager"); } |
31 | UserConfig( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 31 | UserConfig( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
32 | ~UserConfig(); | 32 | ~UserConfig(); |
33 | 33 | ||
34 | private: | 34 | private: |
35 | QToolButton *adduserToolButton; | 35 | QToolButton *adduserToolButton; |
36 | QToolButton *edituserToolButton; | 36 | QToolButton *edituserToolButton; |
37 | QToolButton *deleteuserToolButton; | 37 | QToolButton *deleteuserToolButton; |
38 | QToolButton *addgroupToolButton; | 38 | QToolButton *addgroupToolButton; |
39 | QToolButton *editgroupToolButton; | 39 | QToolButton *editgroupToolButton; |
40 | QToolButton *deletegroupToolButton; | 40 | QToolButton *deletegroupToolButton; |
41 | QTabWidget *myTabWidget; | 41 | QTabWidget *myTabWidget; |
42 | QListView *usersIconView; | 42 | QListView *usersIconView; |
43 | QListView *usersListView; | 43 | QListView *usersListView; |
44 | QListView *groupsListView; | 44 | QListView *groupsListView; |
45 | QPopupMenu userPopupMenu; | 45 | QPopupMenu userPopupMenu; |
46 | QPopupMenu groupPopupMenu; | 46 | QPopupMenu groupPopupMenu; |
47 | int availableUID; | 47 | int availableUID; |
48 | int availableGID; | 48 | int availableGID; |
49 | void setupTabAccounts(); | 49 | void setupTabAccounts(); |
50 | void setupTabAllUsers(); | 50 | void setupTabAllUsers(); |
51 | void setupTabAllGroups(); | 51 | void setupTabAllGroups(); |
52 | void setupTabPrefs(); | 52 | void setupTabPrefs(); |
53 | void setupTabAbout(); | 53 | void setupTabAbout(); |
54 | void getUsers(); | 54 | void getUsers(); |
55 | void getGroups(); | 55 | void getGroups(); |
56 | 56 | ||
57 | private slots: | 57 | private slots: |
58 | void addUser(); | 58 | void addUser(); |
59 | void editUser(); | 59 | void editUser(); |
60 | void delUser(); | 60 | void delUser(); |
61 | void addGroup(); | 61 | void addGroup(); |
62 | void editGroup(); | 62 | void editGroup(); |
63 | void delGroup(); | 63 | void delGroup(); |
64 | void showUserMenu(QListViewItem *item); | 64 | void showUserMenu(QListViewItem *item); |
65 | }; | 65 | }; |
66 | 66 | ||
67 | #endif // USERCONFIG_H | 67 | #endif // USERCONFIG_H |
diff --git a/noncore/tools/formatter/formatter.cpp b/noncore/tools/formatter/formatter.cpp index a8dd11c..532ee40 100644 --- a/noncore/tools/formatter/formatter.cpp +++ b/noncore/tools/formatter/formatter.cpp | |||
@@ -1,584 +1,584 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** formatter.cpp | 2 | ** formatter.cpp |
3 | ** | 3 | ** |
4 | ** Copyright: Thu Apr 11 11:01:13 2002 | 4 | ** Copyright: Thu Apr 11 11:01:13 2002 |
5 | ** by: L. J. Potter | 5 | ** by: L. J. Potter |
6 | ** | 6 | ** |
7 | ****************************************************************************/ | 7 | ****************************************************************************/ |
8 | 8 | ||
9 | #include "formatter.h" | 9 | #include "formatter.h" |
10 | #include "inputDialog.h" | 10 | #include "inputDialog.h" |
11 | #include "output.h" | 11 | #include "output.h" |
12 | 12 | ||
13 | #include <qpe/qpemenubar.h> | 13 | #include <qmenubar.h> |
14 | #include <qpe/qpetoolbar.h> | 14 | #include <qpe/qpetoolbar.h> |
15 | #include <qpe/qpeapplication.h> | 15 | #include <qpe/qpeapplication.h> |
16 | #include <qpe/resource.h> | 16 | #include <qpe/resource.h> |
17 | #include <qpe/config.h> | 17 | #include <qpe/config.h> |
18 | #include <qpe/mimetype.h> | 18 | #include <qpe/mimetype.h> |
19 | #include <qpe/qcopenvelope_qws.h> | 19 | #include <qpe/qcopenvelope_qws.h> |
20 | #include <qpe/storage.h> | 20 | #include <qpe/storage.h> |
21 | 21 | ||
22 | #include <qmultilineedit.h> | 22 | #include <qmultilineedit.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qlist.h> | 24 | #include <qlist.h> |
25 | #include <qstringlist.h> | 25 | #include <qstringlist.h> |
26 | #include <qdir.h> | 26 | #include <qdir.h> |
27 | #include <qfile.h> | 27 | #include <qfile.h> |
28 | 28 | ||
29 | #include <qtstream.h> | 29 | #include <qtstream.h> |
30 | 30 | ||
31 | #include <qcombobox.h> | 31 | #include <qcombobox.h> |
32 | #include <qpopupmenu.h> | 32 | #include <qpopupmenu.h> |
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | #include <qregexp.h> | 34 | #include <qregexp.h> |
35 | 35 | ||
36 | #include <qlabel.h> | 36 | #include <qlabel.h> |
37 | #include <qlineedit.h> | 37 | #include <qlineedit.h> |
38 | #include <qpushbutton.h> | 38 | #include <qpushbutton.h> |
39 | #include <qtabwidget.h> | 39 | #include <qtabwidget.h> |
40 | #include <qwidget.h> | 40 | #include <qwidget.h> |
41 | #include <qlayout.h> | 41 | #include <qlayout.h> |
42 | #include <qvariant.h> | 42 | #include <qvariant.h> |
43 | 43 | ||
44 | #include <unistd.h> | 44 | #include <unistd.h> |
45 | #include <stdio.h> | 45 | #include <stdio.h> |
46 | #include <stdlib.h> | 46 | #include <stdlib.h> |
47 | #include <sys/vfs.h> | 47 | #include <sys/vfs.h> |
48 | #include <mntent.h> | 48 | #include <mntent.h> |
49 | #include <string.h> | 49 | #include <string.h> |
50 | #include <errno.h> | 50 | #include <errno.h> |
51 | 51 | ||
52 | #define BLANK ' ' | 52 | #define BLANK ' ' |
53 | #define DELIMITER '#' | 53 | #define DELIMITER '#' |
54 | 54 | ||
55 | /* | 55 | /* |
56 | Blah blah blah blah */ | 56 | Blah blah blah blah */ |
57 | FormatterApp::FormatterApp( QWidget* parent, const char* name, WFlags fl, bool modal ) | 57 | FormatterApp::FormatterApp( QWidget* parent, const char* name, WFlags fl, bool modal ) |
58 | : QMainWindow( parent, name, fl ) | 58 | : QMainWindow( parent, name, fl ) |
59 | // : QDialog( parent, name, modal, fl ) | 59 | // : QDialog( parent, name, modal, fl ) |
60 | { | 60 | { |
61 | if ( !name ) | 61 | if ( !name ) |
62 | setName( "FormatterApp" ); | 62 | setName( "FormatterApp" ); |
63 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 63 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
64 | 64 | ||
65 | setCaption( tr( "Formatter" ) ); | 65 | setCaption( tr( "Formatter" ) ); |
66 | FormatterAppLayout = new QGridLayout( this ); | 66 | FormatterAppLayout = new QGridLayout( this ); |
67 | FormatterAppLayout->setSpacing( 2); | 67 | FormatterAppLayout->setSpacing( 2); |
68 | FormatterAppLayout->setMargin( 2 ); | 68 | FormatterAppLayout->setMargin( 2 ); |
69 | 69 | ||
70 | TabWidget = new QTabWidget( this, "TabWidget" ); | 70 | TabWidget = new QTabWidget( this, "TabWidget" ); |
71 | 71 | ||
72 | tab = new QWidget( TabWidget, "tab" ); | 72 | tab = new QWidget( TabWidget, "tab" ); |
73 | tabLayout = new QGridLayout( tab ); | 73 | tabLayout = new QGridLayout( tab ); |
74 | tabLayout->setSpacing( 3); | 74 | tabLayout->setSpacing( 3); |
75 | tabLayout->setMargin( 2); | 75 | tabLayout->setMargin( 2); |
76 | 76 | ||
77 | storageComboBox = new QComboBox( FALSE, tab, "storageComboBox" ); | 77 | storageComboBox = new QComboBox( FALSE, tab, "storageComboBox" ); |
78 | storageComboBox->setMaximumWidth(220); | 78 | storageComboBox->setMaximumWidth(220); |
79 | 79 | ||
80 | tabLayout->addMultiCellWidget( storageComboBox, 0, 0, 0, 1); | 80 | tabLayout->addMultiCellWidget( storageComboBox, 0, 0, 0, 1); |
81 | 81 | ||
82 | TextLabel4 = new QLabel( tab, "TextLabel4" ); | 82 | TextLabel4 = new QLabel( tab, "TextLabel4" ); |
83 | TextLabel4->setText( tr( "Storage Type" ) ); | 83 | TextLabel4->setText( tr( "Storage Type" ) ); |
84 | 84 | ||
85 | tabLayout->addMultiCellWidget( TextLabel4, 1, 1, 0, 1); | 85 | tabLayout->addMultiCellWidget( TextLabel4, 1, 1, 0, 1); |
86 | 86 | ||
87 | TextLabel2 = new QLabel( tab, "TextLabel2" ); | 87 | TextLabel2 = new QLabel( tab, "TextLabel2" ); |
88 | TextLabel2->setText( tr( "File Systems" ) ); | 88 | TextLabel2->setText( tr( "File Systems" ) ); |
89 | 89 | ||
90 | tabLayout->addMultiCellWidget( TextLabel2, 4, 4, 0, 1); | 90 | tabLayout->addMultiCellWidget( TextLabel2, 4, 4, 0, 1); |
91 | 91 | ||
92 | fileSystemsCombo = new QComboBox( FALSE, tab, "fileSystemsCombo" ); | 92 | fileSystemsCombo = new QComboBox( FALSE, tab, "fileSystemsCombo" ); |
93 | fileSystemsCombo->setMaximumWidth(220); | 93 | fileSystemsCombo->setMaximumWidth(220); |
94 | 94 | ||
95 | tabLayout->addMultiCellWidget( fileSystemsCombo, 3, 3, 0, 1); | 95 | tabLayout->addMultiCellWidget( fileSystemsCombo, 3, 3, 0, 1); |
96 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum ); | 96 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum ); |
97 | tabLayout->addItem( spacer, 2, 0 ); | 97 | tabLayout->addItem( spacer, 2, 0 ); |
98 | 98 | ||
99 | formatPushButton = new QPushButton( tab, "formatPushButton" ); | 99 | formatPushButton = new QPushButton( tab, "formatPushButton" ); |
100 | formatPushButton->setText( tr( "Format" ) ); | 100 | formatPushButton->setText( tr( "Format" ) ); |
101 | formatPushButton->setMaximumWidth(170); | 101 | formatPushButton->setMaximumWidth(170); |
102 | 102 | ||
103 | tabLayout->addMultiCellWidget( formatPushButton, 6, 6, 0, 1); | 103 | tabLayout->addMultiCellWidget( formatPushButton, 6, 6, 0, 1); |
104 | QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum ); | 104 | QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Minimum ); |
105 | tabLayout->addItem( spacer_2, 5, 0 ); | 105 | tabLayout->addItem( spacer_2, 5, 0 ); |
106 | 106 | ||
107 | TabWidget->insertTab( tab, tr( "Main" ) ); | 107 | TabWidget->insertTab( tab, tr( "Main" ) ); |
108 | 108 | ||
109 | tab_2 = new QWidget( TabWidget, "tab_2" ); | 109 | tab_2 = new QWidget( TabWidget, "tab_2" ); |
110 | tabLayout_2 = new QGridLayout( tab_2 ); | 110 | tabLayout_2 = new QGridLayout( tab_2 ); |
111 | tabLayout_2->setSpacing(3); | 111 | tabLayout_2->setSpacing(3); |
112 | tabLayout_2->setMargin(2); | 112 | tabLayout_2->setMargin(2); |
113 | 113 | ||
114 | mountPointLineEdit = new QLineEdit( tab_2, "mountPointLineEdit" ); | 114 | mountPointLineEdit = new QLineEdit( tab_2, "mountPointLineEdit" ); |
115 | 115 | ||
116 | tabLayout_2->addMultiCellWidget( mountPointLineEdit, 0, 0, 0, 1); | 116 | tabLayout_2->addMultiCellWidget( mountPointLineEdit, 0, 0, 0, 1); |
117 | 117 | ||
118 | deviceComboBox = new QComboBox( FALSE, tab_2, "deviceComboBox" ); | 118 | deviceComboBox = new QComboBox( FALSE, tab_2, "deviceComboBox" ); |
119 | 119 | ||
120 | tabLayout_2->addMultiCellWidget( deviceComboBox, 3, 3, 0, 1); | 120 | tabLayout_2->addMultiCellWidget( deviceComboBox, 3, 3, 0, 1); |
121 | 121 | ||
122 | TextLabel5 = new QLabel( tab_2, "TextLabel5" ); | 122 | TextLabel5 = new QLabel( tab_2, "TextLabel5" ); |
123 | TextLabel5->setText( tr( "CAUTION:\n" | 123 | TextLabel5->setText( tr( "CAUTION:\n" |
124 | "Changing parameters on this\n" | 124 | "Changing parameters on this\n" |
125 | "page may cause your system\n" | 125 | "page may cause your system\n" |
126 | "to stop functioning properly!" ) );//idiot message | 126 | "to stop functioning properly!" ) );//idiot message |
127 | 127 | ||
128 | tabLayout_2->addMultiCellWidget( TextLabel5, 6, 6, 0, 1); | 128 | tabLayout_2->addMultiCellWidget( TextLabel5, 6, 6, 0, 1); |
129 | 129 | ||
130 | editPushButton = new QPushButton( tab_2, "editPushButton" ); | 130 | editPushButton = new QPushButton( tab_2, "editPushButton" ); |
131 | editPushButton->setText( tr( "Edit fstab" ) ); | 131 | editPushButton->setText( tr( "Edit fstab" ) ); |
132 | editPushButton->setMaximumWidth(100); | 132 | editPushButton->setMaximumWidth(100); |
133 | 133 | ||
134 | tabLayout_2->addMultiCellWidget( editPushButton, 7, 7, 0, 0 ); | 134 | tabLayout_2->addMultiCellWidget( editPushButton, 7, 7, 0, 0 ); |
135 | 135 | ||
136 | fsckButton = new QPushButton( tab_2, "fsckPushButton" ); | 136 | fsckButton = new QPushButton( tab_2, "fsckPushButton" ); |
137 | fsckButton->setText( tr( "Check Disk" ) ); | 137 | fsckButton->setText( tr( "Check Disk" ) ); |
138 | fsckButton->setMaximumWidth(100); | 138 | fsckButton->setMaximumWidth(100); |
139 | 139 | ||
140 | tabLayout_2->addMultiCellWidget( fsckButton, 7, 7, 1, 1); | 140 | tabLayout_2->addMultiCellWidget( fsckButton, 7, 7, 1, 1); |
141 | 141 | ||
142 | TextLabel3 = new QLabel( tab_2, "TextLabel3" ); | 142 | TextLabel3 = new QLabel( tab_2, "TextLabel3" ); |
143 | TextLabel3->setText( tr( "Device" ) ); | 143 | TextLabel3->setText( tr( "Device" ) ); |
144 | 144 | ||
145 | tabLayout_2->addMultiCellWidget( TextLabel3, 4, 4, 0, 1 ); | 145 | tabLayout_2->addMultiCellWidget( TextLabel3, 4, 4, 0, 1 ); |
146 | QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | 146 | QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); |
147 | tabLayout_2->addItem( spacer_3, 5, 0 ); | 147 | tabLayout_2->addItem( spacer_3, 5, 0 ); |
148 | 148 | ||
149 | TextLabel1 = new QLabel( tab_2, "TextLabel1" ); | 149 | TextLabel1 = new QLabel( tab_2, "TextLabel1" ); |
150 | TextLabel1->setText( tr( "Mount Point" ) ); | 150 | TextLabel1->setText( tr( "Mount Point" ) ); |
151 | 151 | ||
152 | tabLayout_2->addMultiCellWidget( TextLabel1, 1, 1, 0, 1 ); | 152 | tabLayout_2->addMultiCellWidget( TextLabel1, 1, 1, 0, 1 ); |
153 | QSpacerItem* spacer_4 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | 153 | QSpacerItem* spacer_4 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); |
154 | tabLayout_2->addItem( spacer_4, 2, 1 ); | 154 | tabLayout_2->addItem( spacer_4, 2, 1 ); |
155 | TabWidget->insertTab( tab_2, tr( "Advanced" ) ); | 155 | TabWidget->insertTab( tab_2, tr( "Advanced" ) ); |
156 | 156 | ||
157 | FormatterAppLayout->addWidget( TabWidget, 0, 1 ); | 157 | FormatterAppLayout->addWidget( TabWidget, 0, 1 ); |
158 | 158 | ||
159 | connect( formatPushButton ,SIGNAL(released()),this,SLOT( doFormat()) ); | 159 | connect( formatPushButton ,SIGNAL(released()),this,SLOT( doFormat()) ); |
160 | connect( editPushButton ,SIGNAL(released()),this,SLOT( editFstab()) ); | 160 | connect( editPushButton ,SIGNAL(released()),this,SLOT( editFstab()) ); |
161 | connect( fsckButton ,SIGNAL(released()),this,SLOT( doFsck()) ); | 161 | connect( fsckButton ,SIGNAL(released()),this,SLOT( doFsck()) ); |
162 | 162 | ||
163 | connect( fileSystemsCombo,SIGNAL(activated(int)),this,SLOT( fsComboSelected(int ) )); | 163 | connect( fileSystemsCombo,SIGNAL(activated(int)),this,SLOT( fsComboSelected(int ) )); |
164 | connect( storageComboBox,SIGNAL(activated(int)),this,SLOT( storageComboSelected(int ) )); | 164 | connect( storageComboBox,SIGNAL(activated(int)),this,SLOT( storageComboSelected(int ) )); |
165 | connect( deviceComboBox,SIGNAL(activated(int)),this,SLOT( deviceComboSelected(int ) )); | 165 | connect( deviceComboBox,SIGNAL(activated(int)),this,SLOT( deviceComboSelected(int ) )); |
166 | 166 | ||
167 | 167 | ||
168 | fillCombos(); | 168 | fillCombos(); |
169 | } | 169 | } |
170 | 170 | ||
171 | FormatterApp::~FormatterApp() { | 171 | FormatterApp::~FormatterApp() { |
172 | 172 | ||
173 | } | 173 | } |
174 | 174 | ||
175 | void FormatterApp::doFormat() { | 175 | void FormatterApp::doFormat() { |
176 | int err=0; | 176 | int err=0; |
177 | Output *outDlg; | 177 | Output *outDlg; |
178 | QString umountS, remountS; | 178 | QString umountS, remountS; |
179 | QString text = storageComboBox->currentText(); | 179 | QString text = storageComboBox->currentText(); |
180 | QString currentText = storageComboBox->currentText(); | 180 | QString currentText = storageComboBox->currentText(); |
181 | QString cmd; | 181 | QString cmd; |
182 | QString diskDevice = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4); | 182 | QString diskDevice = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4); |
183 | QString diskName = currentText.left(currentText.find(" -> ",0,TRUE)); | 183 | QString diskName = currentText.left(currentText.find(" -> ",0,TRUE)); |
184 | QString fs = fileSystemsCombo->currentText(); | 184 | QString fs = fileSystemsCombo->currentText(); |
185 | 185 | ||
186 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) // lets test on something cheap | 186 | #if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) // lets test on something cheap |
187 | #else | 187 | #else |
188 | currentText = diskDevice = "/dev/fd0"; | 188 | currentText = diskDevice = "/dev/fd0"; |
189 | umountS = "umount -v /floppy 2>&1"; | 189 | umountS = "umount -v /floppy 2>&1"; |
190 | remountS = "mount -v /floppy 2>&1"; | 190 | remountS = "mount -v /floppy 2>&1"; |
191 | #endif | 191 | #endif |
192 | 192 | ||
193 | if( currentText.find("CF",0,TRUE) != -1) { | 193 | if( currentText.find("CF",0,TRUE) != -1) { |
194 | umountS = "umount "; | 194 | umountS = "umount "; |
195 | remountS = "mount "; | 195 | remountS = "mount "; |
196 | 196 | ||
197 | // umountS = "/sbin/cardctl eject"; | 197 | // umountS = "/sbin/cardctl eject"; |
198 | // remountS = "/sbin/cardctl insert"; | 198 | // remountS = "/sbin/cardctl insert"; |
199 | } | 199 | } |
200 | if( currentText.find("SD",0,TRUE) != -1) { | 200 | if( currentText.find("SD",0,TRUE) != -1) { |
201 | umountS = "umount "; | 201 | umountS = "umount "; |
202 | remountS = "mount "; | 202 | remountS = "mount "; |
203 | // umountS = "/etc/sdcontrol compeject"; | 203 | // umountS = "/etc/sdcontrol compeject"; |
204 | // remountS = "/etc/sdcontrol insert"; | 204 | // remountS = "/etc/sdcontrol insert"; |
205 | } | 205 | } |
206 | 206 | ||
207 | switch ( QMessageBox::warning(this,tr("Format?") | 207 | switch ( QMessageBox::warning(this,tr("Format?") |
208 | , tr("Really format\n") +diskName+" "+ currentText + | 208 | , tr("Really format\n") +diskName+" "+ currentText + |
209 | tr("\nwith %1 filesystem?\nYou will loose all data!!").arg( fs ) | 209 | tr("\nwith %1 filesystem?\nYou will loose all data!!").arg( fs ) |
210 | ,tr("Yes") | 210 | ,tr("Yes") |
211 | ,tr("No") | 211 | ,tr("No") |
212 | ,0 | 212 | ,0 |
213 | ,1 | 213 | ,1 |
214 | ,1) ) { | 214 | ,1) ) { |
215 | case 0: { | 215 | case 0: { |
216 | if(fs == "vfat") | 216 | if(fs == "vfat") |
217 | cmd = "mkdosfs -v " + diskDevice+" 2>&1"; | 217 | cmd = "mkdosfs -v " + diskDevice+" 2>&1"; |
218 | else if(fs == "ext2") | 218 | else if(fs == "ext2") |
219 | cmd = "mke2fs -v " + diskDevice+" 2>&1"; | 219 | cmd = "mke2fs -v " + diskDevice+" 2>&1"; |
220 | else { | 220 | else { |
221 | QMessageBox::warning(this, tr("Formatter"),tr("Could not format.\nUnknown type"), tr("Ok")); | 221 | QMessageBox::warning(this, tr("Formatter"),tr("Could not format.\nUnknown type"), tr("Ok")); |
222 | break; | 222 | break; |
223 | } | 223 | } |
224 | // cmd = "ls -l"; | 224 | // cmd = "ls -l"; |
225 | outDlg = new Output(this, tr("Formatter Output"),FALSE); | 225 | outDlg = new Output(this, tr("Formatter Output"),FALSE); |
226 | outDlg->showMaximized(); | 226 | outDlg->showMaximized(); |
227 | outDlg->show(); | 227 | outDlg->show(); |
228 | qApp->processEvents(); | 228 | qApp->processEvents(); |
229 | FILE *fp; | 229 | FILE *fp; |
230 | char line[130]; | 230 | char line[130]; |
231 | 231 | ||
232 | 232 | ||
233 | outDlg->OutputEdit->append( tr("Trying to umount %1.").arg( currentText) ); | 233 | outDlg->OutputEdit->append( tr("Trying to umount %1.").arg( currentText) ); |
234 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 234 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
235 | 235 | ||
236 | sleep(1); | 236 | sleep(1); |
237 | qDebug("Command is "+umountS); | 237 | qDebug("Command is "+umountS); |
238 | fp = popen( (const char *) umountS, "r"); | 238 | fp = popen( (const char *) umountS, "r"); |
239 | // qDebug("%d", fp); | 239 | // qDebug("%d", fp); |
240 | if ( !fp ) { | 240 | if ( !fp ) { |
241 | qDebug("Could not execute '" + umountS + "'! err=%d\n" +(QString)strerror(errno), err); | 241 | qDebug("Could not execute '" + umountS + "'! err=%d\n" +(QString)strerror(errno), err); |
242 | QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); | 242 | QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); |
243 | pclose(fp); | 243 | pclose(fp); |
244 | return; | 244 | return; |
245 | } else { | 245 | } else { |
246 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); | 246 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); |
247 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 247 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
248 | while ( fgets( line, sizeof line, fp)) { | 248 | while ( fgets( line, sizeof line, fp)) { |
249 | if( ((QString)line).find("busy",0,TRUE) != -1) { | 249 | if( ((QString)line).find("busy",0,TRUE) != -1) { |
250 | qDebug("Could not find '" + umountS); | 250 | qDebug("Could not find '" + umountS); |
251 | QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") ); | 251 | QMessageBox::warning( this, tr("Formatter"), tr("Could not umount.\nDevice is busy!"), tr("&OK") ); |
252 | pclose(fp); | 252 | pclose(fp); |
253 | return; | 253 | return; |
254 | } else { | 254 | } else { |
255 | QString lineStr = line; | 255 | QString lineStr = line; |
256 | lineStr=lineStr.left(lineStr.length()-1); | 256 | lineStr=lineStr.left(lineStr.length()-1); |
257 | outDlg->OutputEdit->append(lineStr); | 257 | outDlg->OutputEdit->append(lineStr); |
258 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 258 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
259 | } | 259 | } |
260 | } | 260 | } |
261 | } | 261 | } |
262 | pclose(fp); | 262 | pclose(fp); |
263 | 263 | ||
264 | qDebug("Command would be: "+cmd); | 264 | qDebug("Command would be: "+cmd); |
265 | outDlg->OutputEdit->append( tr("Trying to format.") ); | 265 | outDlg->OutputEdit->append( tr("Trying to format.") ); |
266 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 266 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
267 | 267 | ||
268 | fp = popen( (const char *) cmd, "r"); | 268 | fp = popen( (const char *) cmd, "r"); |
269 | while ( fgets( line, sizeof line, fp)) { | 269 | while ( fgets( line, sizeof line, fp)) { |
270 | if( ((QString)line).find("No such device",0,TRUE) != -1) { | 270 | if( ((QString)line).find("No such device",0,TRUE) != -1) { |
271 | qDebug("No such device '" + umountS); | 271 | qDebug("No such device '" + umountS); |
272 | QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); | 272 | QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); |
273 | pclose(fp); | 273 | pclose(fp); |
274 | // outDlg->OutputEdit->append("No such device"); | 274 | // outDlg->OutputEdit->append("No such device"); |
275 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 275 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
276 | return; | 276 | return; |
277 | } else { | 277 | } else { |
278 | QString lineStr = line; | 278 | QString lineStr = line; |
279 | lineStr=lineStr.left(lineStr.length()-1); | 279 | lineStr=lineStr.left(lineStr.length()-1); |
280 | outDlg->OutputEdit->append(lineStr); | 280 | outDlg->OutputEdit->append(lineStr); |
281 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 281 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
282 | } | 282 | } |
283 | } | 283 | } |
284 | outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); | 284 | outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); |
285 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 285 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
286 | pclose(fp); | 286 | pclose(fp); |
287 | 287 | ||
288 | outDlg->OutputEdit->append( tr("Trying to mount %1.").arg( currentText) ); | 288 | outDlg->OutputEdit->append( tr("Trying to mount %1.").arg( currentText) ); |
289 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 289 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
290 | fp = popen( (const char *) remountS, "r"); | 290 | fp = popen( (const char *) remountS, "r"); |
291 | if ( !fp) { | 291 | if ( !fp) { |
292 | qDebug("Could not execute '" + remountS + "'! err=%d\n" +(QString)strerror(errno), err); | 292 | qDebug("Could not execute '" + remountS + "'! err=%d\n" +(QString)strerror(errno), err); |
293 | QMessageBox::warning( this, tr("Formatter"), tr("Card mount failed!"), tr("&OK") ); | 293 | QMessageBox::warning( this, tr("Formatter"), tr("Card mount failed!"), tr("&OK") ); |
294 | 294 | ||
295 | } else { | 295 | } else { |
296 | outDlg->OutputEdit->append(tr("%1\nhas been successfully mounted.").arg( currentText )); | 296 | outDlg->OutputEdit->append(tr("%1\nhas been successfully mounted.").arg( currentText )); |
297 | while ( fgets( line, sizeof line, fp)) { | 297 | while ( fgets( line, sizeof line, fp)) { |
298 | QString lineStr = line; | 298 | QString lineStr = line; |
299 | lineStr=lineStr.left(lineStr.length()-1); | 299 | lineStr=lineStr.left(lineStr.length()-1); |
300 | outDlg->OutputEdit->append(lineStr); | 300 | outDlg->OutputEdit->append(lineStr); |
301 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 301 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
302 | } | 302 | } |
303 | } | 303 | } |
304 | pclose(fp); | 304 | pclose(fp); |
305 | sleep(1); | 305 | sleep(1); |
306 | 306 | ||
307 | outDlg->OutputEdit->append(tr("You can now close the output window.")); | 307 | outDlg->OutputEdit->append(tr("You can now close the output window.")); |
308 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 308 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
309 | // outDlg->close(); | 309 | // outDlg->close(); |
310 | // if(outDlg) | 310 | // if(outDlg) |
311 | // delete outDlg; | 311 | // delete outDlg; |
312 | } | 312 | } |
313 | break; | 313 | break; |
314 | }; | 314 | }; |
315 | } | 315 | } |
316 | 316 | ||
317 | bool FormatterApp::doFdisk() { | 317 | bool FormatterApp::doFdisk() { |
318 | return FALSE; | 318 | return FALSE; |
319 | 319 | ||
320 | } | 320 | } |
321 | 321 | ||
322 | void FormatterApp::fillCombos() { | 322 | void FormatterApp::fillCombos() { |
323 | 323 | ||
324 | StorageInfo storageInfo; | 324 | StorageInfo storageInfo; |
325 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 325 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
326 | QListIterator<FileSystem> it ( fs ); | 326 | QListIterator<FileSystem> it ( fs ); |
327 | QString storage; | 327 | QString storage; |
328 | for( ; it.current(); ++it ){ | 328 | for( ; it.current(); ++it ){ |
329 | const QString name = (*it)->name(); | 329 | const QString name = (*it)->name(); |
330 | const QString path = (*it)->path(); | 330 | const QString path = (*it)->path(); |
331 | const QString disk = (*it)->disk(); | 331 | const QString disk = (*it)->disk(); |
332 | const QString options = (*it)->options(); | 332 | const QString options = (*it)->options(); |
333 | if( name.find( tr("Internal"),0,TRUE) == -1) { | 333 | if( name.find( tr("Internal"),0,TRUE) == -1) { |
334 | storageComboBox->insertItem(name +" -> "+disk); | 334 | storageComboBox->insertItem(name +" -> "+disk); |
335 | } | 335 | } |
336 | // deviceComboBox->insertItem(disk); | 336 | // deviceComboBox->insertItem(disk); |
337 | } | 337 | } |
338 | parsetab("/etc/mtab"); | 338 | parsetab("/etc/mtab"); |
339 | // parsetab("/etc/fstab"); | 339 | // parsetab("/etc/fstab"); |
340 | fileSystemsCombo->insertStringList( fsList,-1); | 340 | fileSystemsCombo->insertStringList( fsList,-1); |
341 | deviceComboBox->insertStringList( deviceList,-1); | 341 | deviceComboBox->insertStringList( deviceList,-1); |
342 | storageComboSelected(0); | 342 | storageComboSelected(0); |
343 | deviceComboSelected(0); | 343 | deviceComboSelected(0); |
344 | } | 344 | } |
345 | 345 | ||
346 | 346 | ||
347 | void FormatterApp::fsComboSelected(int ) { | 347 | void FormatterApp::fsComboSelected(int ) { |
348 | 348 | ||
349 | } | 349 | } |
350 | 350 | ||
351 | void FormatterApp::storageComboSelected(int index ) { | 351 | void FormatterApp::storageComboSelected(int index ) { |
352 | 352 | ||
353 | QString currentText = storageComboBox->text(index); | 353 | QString currentText = storageComboBox->text(index); |
354 | QString nameS = currentText.left( currentText.find("->",0,TRUE)); | 354 | QString nameS = currentText.left( currentText.find("->",0,TRUE)); |
355 | 355 | ||
356 | TextLabel4->setText( tr( "Storage Type: %1").arg( nameS) ); | 356 | TextLabel4->setText( tr( "Storage Type: %1").arg( nameS) ); |
357 | currentText = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4); | 357 | currentText = currentText.right( currentText.length() - currentText.find(" -> ",0,TRUE) - 4); |
358 | 358 | ||
359 | QString fsType = getFileSystemType((const QString &) currentText); | 359 | QString fsType = getFileSystemType((const QString &) currentText); |
360 | // qDebug(fsType); | 360 | // qDebug(fsType); |
361 | for(int i = 0; i < fileSystemsCombo->count(); i++) { | 361 | for(int i = 0; i < fileSystemsCombo->count(); i++) { |
362 | if( fsType == fileSystemsCombo->text(i)) | 362 | if( fsType == fileSystemsCombo->text(i)) |
363 | fileSystemsCombo->setCurrentItem(i); | 363 | fileSystemsCombo->setCurrentItem(i); |
364 | } | 364 | } |
365 | // deviceComboSelected(index); | 365 | // deviceComboSelected(index); |
366 | } | 366 | } |
367 | 367 | ||
368 | void FormatterApp::deviceComboSelected(int index) { | 368 | void FormatterApp::deviceComboSelected(int index) { |
369 | 369 | ||
370 | StorageInfo storageInfo; | 370 | StorageInfo storageInfo; |
371 | QString totalS, usedS, avS, diskS, nameS, fsType, selectedText; | 371 | QString totalS, usedS, avS, diskS, nameS, fsType, selectedText; |
372 | 372 | ||
373 | selectedText = deviceComboBox->text(index); | 373 | selectedText = deviceComboBox->text(index); |
374 | 374 | ||
375 | const QList<FileSystem> &fs = storageInfo.fileSystems(); | 375 | const QList<FileSystem> &fs = storageInfo.fileSystems(); |
376 | QListIterator<FileSystem> it ( fs ); | 376 | QListIterator<FileSystem> it ( fs ); |
377 | QString storage; | 377 | QString storage; |
378 | for( ; it.current(); ++it ){ | 378 | for( ; it.current(); ++it ){ |
379 | const QString name = (*it)->name(); | 379 | const QString name = (*it)->name(); |
380 | const QString path = (*it)->path(); | 380 | const QString path = (*it)->path(); |
381 | const QString disk = (*it)->disk(); | 381 | const QString disk = (*it)->disk(); |
382 | // const QString options = (*it)->options(); | 382 | // const QString options = (*it)->options(); |
383 | if( selectedText == disk) { | 383 | if( selectedText == disk) { |
384 | diskS = disk; nameS= name; | 384 | diskS = disk; nameS= name; |
385 | mountPointLineEdit->setText(path); | 385 | mountPointLineEdit->setText(path); |
386 | long mult = (*it)->blockSize() / 1024; | 386 | long mult = (*it)->blockSize() / 1024; |
387 | long div = 1024 / (*it)->blockSize(); | 387 | long div = 1024 / (*it)->blockSize(); |
388 | if ( !mult ) mult = 1; | 388 | if ( !mult ) mult = 1; |
389 | if ( !div ) div = 1; | 389 | if ( !div ) div = 1; |
390 | long total = (*it)->totalBlocks() * mult / div; | 390 | long total = (*it)->totalBlocks() * mult / div; |
391 | long totalMb = total/1024; | 391 | long totalMb = total/1024; |
392 | long avail = (*it)->availBlocks() * mult / div; | 392 | long avail = (*it)->availBlocks() * mult / div; |
393 | long availMb = avail/1024; | 393 | long availMb = avail/1024; |
394 | long used = total - avail; | 394 | long used = total - avail; |
395 | long usedMb = used/1024; | 395 | long usedMb = used/1024; |
396 | totalS.sprintf(tr("Total: %1 kB ( %d mB)\n").arg( total ), totalMb ); | 396 | totalS.sprintf(tr("Total: %1 kB ( %d mB)\n").arg( total ), totalMb ); |
397 | usedS.sprintf(tr("Used: %1 kB ( %d mB)\n").arg(used) ,usedMb); | 397 | usedS.sprintf(tr("Used: %1 kB ( %d mB)\n").arg(used) ,usedMb); |
398 | avS.sprintf( tr("Available: %1 kB ( %d mB)").arg(avail), availMb ); | 398 | avS.sprintf( tr("Available: %1 kB ( %d mB)").arg(avail), availMb ); |
399 | } | 399 | } |
400 | } | 400 | } |
401 | fsType = getFileSystemType((const QString &)selectedText); | 401 | fsType = getFileSystemType((const QString &)selectedText); |
402 | 402 | ||
403 | TextLabel5->setText(tr("Type: %1\nFormatted with %2\n%3, %4, %5").arg( nameS).arg( fsType).arg(totalS).arg( usedS).arg( avS )); | 403 | TextLabel5->setText(tr("Type: %1\nFormatted with %2\n%3, %4, %5").arg( nameS).arg( fsType).arg(totalS).arg( usedS).arg( avS )); |
404 | TextLabel5->setTextFormat( Qt::RichText ); | 404 | TextLabel5->setTextFormat( Qt::RichText ); |
405 | // storageComboSelected(0); | 405 | // storageComboSelected(0); |
406 | } | 406 | } |
407 | 407 | ||
408 | void FormatterApp::cleanUp() { | 408 | void FormatterApp::cleanUp() { |
409 | 409 | ||
410 | } | 410 | } |
411 | 411 | ||
412 | 412 | ||
413 | void FormatterApp::editFstab() { | 413 | void FormatterApp::editFstab() { |
414 | QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); | 414 | QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); |
415 | e << (const QString &)"/etc/fstab"; | 415 | e << (const QString &)"/etc/fstab"; |
416 | } | 416 | } |
417 | 417 | ||
418 | void FormatterApp::parsetab(const QString &fileName) { | 418 | void FormatterApp::parsetab(const QString &fileName) { |
419 | 419 | ||
420 | fileSystemTypeList.clear(); | 420 | fileSystemTypeList.clear(); |
421 | fsList.clear(); | 421 | fsList.clear(); |
422 | struct mntent *me; | 422 | struct mntent *me; |
423 | // if(fileName == "/etc/mtab") { | 423 | // if(fileName == "/etc/mtab") { |
424 | FILE *mntfp = setmntent( fileName.latin1(), "r" ); | 424 | FILE *mntfp = setmntent( fileName.latin1(), "r" ); |
425 | if ( mntfp ) { | 425 | if ( mntfp ) { |
426 | while ( (me = getmntent( mntfp )) != 0 ) { | 426 | while ( (me = getmntent( mntfp )) != 0 ) { |
427 | QString deviceName = me->mnt_fsname; | 427 | QString deviceName = me->mnt_fsname; |
428 | QString filesystemType = me->mnt_type; | 428 | QString filesystemType = me->mnt_type; |
429 | if(deviceName != "none") { | 429 | if(deviceName != "none") { |
430 | if( fsList.contains(filesystemType) == 0 | 430 | if( fsList.contains(filesystemType) == 0 |
431 | & filesystemType.find("proc",0,TRUE) == -1 | 431 | & filesystemType.find("proc",0,TRUE) == -1 |
432 | & filesystemType.find("cramfs",0,TRUE) == -1 | 432 | & filesystemType.find("cramfs",0,TRUE) == -1 |
433 | & filesystemType.find("auto",0,TRUE) == -1) | 433 | & filesystemType.find("auto",0,TRUE) == -1) |
434 | fsList << filesystemType; | 434 | fsList << filesystemType; |
435 | deviceList << deviceName; | 435 | deviceList << deviceName; |
436 | qDebug(deviceName+"::"+filesystemType); | 436 | qDebug(deviceName+"::"+filesystemType); |
437 | fileSystemTypeList << deviceName+"::"+filesystemType; | 437 | fileSystemTypeList << deviceName+"::"+filesystemType; |
438 | } | 438 | } |
439 | } | 439 | } |
440 | } | 440 | } |
441 | endmntent( mntfp ); | 441 | endmntent( mntfp ); |
442 | // } else if(fileName == "/etc/fstab") { | 442 | // } else if(fileName == "/etc/fstab") { |
443 | // QFile f("/etc/fstab"); | 443 | // QFile f("/etc/fstab"); |
444 | // if ( f.open(IO_ReadOnly) ) { | 444 | // if ( f.open(IO_ReadOnly) ) { |
445 | // QTextStream t (&f); | 445 | // QTextStream t (&f); |
446 | // QString s; | 446 | // QString s; |
447 | // while (! t.eof()) { | 447 | // while (! t.eof()) { |
448 | // s=t.readLine(); | 448 | // s=t.readLine(); |
449 | // s=s.simplifyWhiteSpace(); | 449 | // s=s.simplifyWhiteSpace(); |
450 | // if ( (!s.isEmpty() ) && (s.find(" ")!=0) ) { | 450 | // if ( (!s.isEmpty() ) && (s.find(" ")!=0) ) { |
451 | // // = me->mnt_fsname; | 451 | // // = me->mnt_fsname; |
452 | // QString filesystemType = me->mnt_type; | 452 | // QString filesystemType = me->mnt_type; |
453 | // QString deviceName = s.left(0,s.find(BLANK) ); | 453 | // QString deviceName = s.left(0,s.find(BLANK) ); |
454 | // s=s.remove(0,s.find(BLANK)+1 ); // devicename | 454 | // s=s.remove(0,s.find(BLANK)+1 ); // devicename |
455 | 455 | ||
456 | // s=s.remove(0,s.find(BLANK)+1 ); // mountpoint | 456 | // s=s.remove(0,s.find(BLANK)+1 ); // mountpoint |
457 | // QStringt mountPoint= s.left(0,s.find(BLANK) ); | 457 | // QStringt mountPoint= s.left(0,s.find(BLANK) ); |
458 | // s=s.remove(0,s.find(BLANK)+1 ); // fs | 458 | // s=s.remove(0,s.find(BLANK)+1 ); // fs |
459 | // QString filesystemType= s.left(0,s.find(BLANK) ); | 459 | // QString filesystemType= s.left(0,s.find(BLANK) ); |
460 | // } | 460 | // } |
461 | // } | 461 | // } |
462 | // } | 462 | // } |
463 | // f.close(); | 463 | // f.close(); |
464 | // } | 464 | // } |
465 | } | 465 | } |
466 | 466 | ||
467 | QString FormatterApp::getFileSystemType(const QString ¤tText) { | 467 | QString FormatterApp::getFileSystemType(const QString ¤tText) { |
468 | 468 | ||
469 | parsetab("/etc/mtab"); //why did TT forget filesystem type? | 469 | parsetab("/etc/mtab"); //why did TT forget filesystem type? |
470 | 470 | ||
471 | for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) { | 471 | for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) { |
472 | QString temp = (*it); | 472 | QString temp = (*it); |
473 | if( temp.find( currentText,0,TRUE) != -1) { | 473 | if( temp.find( currentText,0,TRUE) != -1) { |
474 | return temp.right( temp.length() - temp.find("::",0,TRUE) - 2); | 474 | return temp.right( temp.length() - temp.find("::",0,TRUE) - 2); |
475 | // qDebug(fsType); | 475 | // qDebug(fsType); |
476 | } | 476 | } |
477 | } | 477 | } |
478 | return ""; | 478 | return ""; |
479 | } | 479 | } |
480 | 480 | ||
481 | bool FormatterApp::doFsck() { | 481 | bool FormatterApp::doFsck() { |
482 | 482 | ||
483 | Output *outDlg; | 483 | Output *outDlg; |
484 | QString selectedDevice; | 484 | QString selectedDevice; |
485 | // #if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) | 485 | // #if defined(QT_QWS_IPAQ) || defined(QT_QWS_SL5XXX) |
486 | selectedDevice = deviceComboBox->currentText(); | 486 | selectedDevice = deviceComboBox->currentText(); |
487 | QString mountPoint = mountPointLineEdit->text(); | 487 | QString mountPoint = mountPointLineEdit->text(); |
488 | QString umountS = "umount -v "+mountPoint+" 2>&1"; | 488 | QString umountS = "umount -v "+mountPoint+" 2>&1"; |
489 | QString remountS = "mount -v "+mountPoint+" 2>&1"; | 489 | QString remountS = "mount -v "+mountPoint+" 2>&1"; |
490 | // #else | 490 | // #else |
491 | // // for testing | 491 | // // for testing |
492 | // // currentText = diskDevice = "/dev/fd0"; | 492 | // // currentText = diskDevice = "/dev/fd0"; |
493 | // QString umountS = "umount -v /floppy 2>&1"; | 493 | // QString umountS = "umount -v /floppy 2>&1"; |
494 | // QString remountS = "mount -v /floppy 2>&1"; | 494 | // QString remountS = "mount -v /floppy 2>&1"; |
495 | // selectedDevice ="/dev/fd0"; | 495 | // selectedDevice ="/dev/fd0"; |
496 | 496 | ||
497 | // #endif | 497 | // #endif |
498 | 498 | ||
499 | QString fsType = getFileSystemType((const QString &)selectedDevice); | 499 | QString fsType = getFileSystemType((const QString &)selectedDevice); |
500 | QString cmd; | 500 | QString cmd; |
501 | qDebug( selectedDevice +" "+ fsType); | 501 | qDebug( selectedDevice +" "+ fsType); |
502 | if(fsType == "vfat") cmd = "dosfsck -vy "; | 502 | if(fsType == "vfat") cmd = "dosfsck -vy "; |
503 | if(fsType == "ext2") cmd = "e2fsck -cpvy "; | 503 | if(fsType == "ext2") cmd = "e2fsck -cpvy "; |
504 | cmd += selectedDevice + " 2>&1"; | 504 | cmd += selectedDevice + " 2>&1"; |
505 | 505 | ||
506 | outDlg = new Output(this, tr("Formatter Output"),FALSE); | 506 | outDlg = new Output(this, tr("Formatter Output"),FALSE); |
507 | outDlg->showMaximized(); | 507 | outDlg->showMaximized(); |
508 | outDlg->show(); | 508 | outDlg->show(); |
509 | qApp->processEvents(); | 509 | qApp->processEvents(); |
510 | FILE *fp; | 510 | FILE *fp; |
511 | char line[130]; | 511 | char line[130]; |
512 | outDlg->OutputEdit->append( tr("Trying to umount.")); | 512 | outDlg->OutputEdit->append( tr("Trying to umount.")); |
513 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 513 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
514 | 514 | ||
515 | sleep(1); | 515 | sleep(1); |
516 | // qDebug("Command is "+umountS); | 516 | // qDebug("Command is "+umountS); |
517 | fp = popen( (const char *) umountS, "r"); | 517 | fp = popen( (const char *) umountS, "r"); |
518 | // qDebug("%d", fp); | 518 | // qDebug("%d", fp); |
519 | if ( !fp ) { | 519 | if ( !fp ) { |
520 | qDebug("Could not execute '" + umountS + "'!\n" +(QString)strerror(errno)); | 520 | qDebug("Could not execute '" + umountS + "'!\n" +(QString)strerror(errno)); |
521 | QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); | 521 | QMessageBox::warning( this, tr("Formatter"), tr("umount failed!"), tr("&OK") ); |
522 | pclose(fp); | 522 | pclose(fp); |
523 | return false; | 523 | return false; |
524 | } else { | 524 | } else { |
525 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); | 525 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully umounted.")); |
526 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 526 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
527 | while ( fgets( line, sizeof line, fp)) { | 527 | while ( fgets( line, sizeof line, fp)) { |
528 | if( ((QString)line).find("busy",0,TRUE) != -1) { | 528 | if( ((QString)line).find("busy",0,TRUE) != -1) { |
529 | qDebug("Could not find '" + umountS); | 529 | qDebug("Could not find '" + umountS); |
530 | QMessageBox::warning( this, tr("Formatter"), | 530 | QMessageBox::warning( this, tr("Formatter"), |
531 | tr("Could not umount.\nDevice is busy!"), tr("&OK") ); | 531 | tr("Could not umount.\nDevice is busy!"), tr("&OK") ); |
532 | pclose(fp); | 532 | pclose(fp); |
533 | return false; | 533 | return false; |
534 | } else { | 534 | } else { |
535 | QString lineStr = line; | 535 | QString lineStr = line; |
536 | lineStr=lineStr.left(lineStr.length()-1); | 536 | lineStr=lineStr.left(lineStr.length()-1); |
537 | outDlg->OutputEdit->append(lineStr); | 537 | outDlg->OutputEdit->append(lineStr); |
538 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 538 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
539 | } | 539 | } |
540 | } | 540 | } |
541 | } | 541 | } |
542 | pclose(fp); | 542 | pclose(fp); |
543 | ///////////////////////////////////// | 543 | ///////////////////////////////////// |
544 | fp = popen( (const char *) cmd, "r"); | 544 | fp = popen( (const char *) cmd, "r"); |
545 | while ( fgets( line, sizeof line, fp)) { | 545 | while ( fgets( line, sizeof line, fp)) { |
546 | if( ((QString)line).find("No such device",0,TRUE) != -1) { | 546 | if( ((QString)line).find("No such device",0,TRUE) != -1) { |
547 | qDebug("No such device '" + umountS); | 547 | qDebug("No such device '" + umountS); |
548 | QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); | 548 | QMessageBox::warning( this, tr("Formatter"), tr("No such device!"), tr("&OK") ); |
549 | pclose(fp); | 549 | pclose(fp); |
550 | // outDlg->OutputEdit->append("No such device"); | 550 | // outDlg->OutputEdit->append("No such device"); |
551 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 551 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
552 | return false; | 552 | return false; |
553 | } else { | 553 | } else { |
554 | QString lineStr = line; | 554 | QString lineStr = line; |
555 | lineStr=lineStr.left(lineStr.length()-1); | 555 | lineStr=lineStr.left(lineStr.length()-1); |
556 | outDlg->OutputEdit->append(lineStr); | 556 | outDlg->OutputEdit->append(lineStr); |
557 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 557 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
558 | } | 558 | } |
559 | } | 559 | } |
560 | outDlg->OutputEdit->append(tr("You can now close the output window.")); | 560 | outDlg->OutputEdit->append(tr("You can now close the output window.")); |
561 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 561 | outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
562 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); | 562 | // outDlg->OutputEdit->append( currentText + tr("\nhas been successfully formatted.")); |
563 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); | 563 | // outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); |
564 | pclose(fp); | 564 | pclose(fp); |
565 | 565 | ||
566 | ///////////////////////////////////////// | 566 | ///////////////////////////////////////// |
567 | 567 | ||
568 | return true; | 568 | return true; |
569 | } | 569 | } |
570 | 570 | ||
571 | bool FormatterApp::doFsckCheck() { | 571 | bool FormatterApp::doFsckCheck() { |
572 | 572 | ||
573 | return FALSE; | 573 | return FALSE; |
574 | } | 574 | } |
575 | 575 | ||
576 | int FormatterApp::formatCheck(const QString &) { | 576 | int FormatterApp::formatCheck(const QString &) { |
577 | 577 | ||
578 | return -1; | 578 | return -1; |
579 | } | 579 | } |
580 | 580 | ||
581 | int FormatterApp::runCommand(const QString &) { | 581 | int FormatterApp::runCommand(const QString &) { |
582 | 582 | ||
583 | return -1; | 583 | return -1; |
584 | } | 584 | } |
diff --git a/noncore/unsupported/filebrowser/filebrowser.cpp b/noncore/unsupported/filebrowser/filebrowser.cpp index 114ebfa..8cf8a60 100644 --- a/noncore/unsupported/filebrowser/filebrowser.cpp +++ b/noncore/unsupported/filebrowser/filebrowser.cpp | |||
@@ -1,1091 +1,1091 @@ | |||
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 | #include "inlineedit.h" | 22 | #include "inlineedit.h" |
23 | #include "filebrowser.h" | 23 | #include "filebrowser.h" |
24 | #include "filePermissions.h" | 24 | #include "filePermissions.h" |
25 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
26 | #include <qpe/global.h> | 26 | #include <qpe/global.h> |
27 | #include <qpe/mimetype.h> | 27 | #include <qpe/mimetype.h> |
28 | #include <qpe/applnk.h> | 28 | #include <qpe/applnk.h> |
29 | #include <qpe/config.h> | 29 | #include <qpe/config.h> |
30 | 30 | ||
31 | #include <qcopchannel_qws.h> | 31 | #include <qcopchannel_qws.h> |
32 | #include <qpe/qcopenvelope_qws.h> | 32 | #include <qpe/qcopenvelope_qws.h> |
33 | 33 | ||
34 | #include <qmessagebox.h> | 34 | #include <qmessagebox.h> |
35 | #include <qdir.h> | 35 | #include <qdir.h> |
36 | #include <qregexp.h> | 36 | #include <qregexp.h> |
37 | #include <qheader.h> | 37 | #include <qheader.h> |
38 | #include <qpe/qpetoolbar.h> | 38 | #include <qtoolbar.h> |
39 | #include <qpopupmenu.h> | 39 | #include <qpopupmenu.h> |
40 | #include <qmenubar.h> | 40 | #include <qmenubar.h> |
41 | #include <qaction.h> | 41 | #include <qaction.h> |
42 | #include <qstringlist.h> | 42 | #include <qstringlist.h> |
43 | #include <qcursor.h> | 43 | #include <qcursor.h> |
44 | #include <qmultilineedit.h> | 44 | #include <qmultilineedit.h> |
45 | #include <qfont.h> | 45 | #include <qfont.h> |
46 | #include <qpainter.h> | 46 | #include <qpainter.h> |
47 | #include <qprogressbar.h> | 47 | #include <qprogressbar.h> |
48 | 48 | ||
49 | #include <unistd.h> | 49 | #include <unistd.h> |
50 | #include <stdlib.h> | 50 | #include <stdlib.h> |
51 | #include <sys/stat.h> | 51 | #include <sys/stat.h> |
52 | #include <qpe/qpeapplication.h> | 52 | #include <qpe/qpeapplication.h> |
53 | 53 | ||
54 | // | 54 | // |
55 | // FileItem | 55 | // FileItem |
56 | // | 56 | // |
57 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) | 57 | FileItem::FileItem( QListView * parent, const QFileInfo & fi ) |
58 | : QListViewItem( parent ), | 58 | : QListViewItem( parent ), |
59 | fileInfo( fi ) | 59 | fileInfo( fi ) |
60 | { | 60 | { |
61 | QDate d = fi.lastModified().date(); | 61 | QDate d = fi.lastModified().date(); |
62 | 62 | ||
63 | setText( 0, fi.fileName() ); | 63 | setText( 0, fi.fileName() ); |
64 | setText( 1, sizeString( fi.size() ) + " " ); | 64 | setText( 1, sizeString( fi.size() ) + " " ); |
65 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); | 65 | setText( 2, QString().sprintf("%4d-%02d-%02d",d.year(), d.month(), d.day() ) ); |
66 | 66 | ||
67 | MimeType mt(fi.filePath()); | 67 | MimeType mt(fi.filePath()); |
68 | 68 | ||
69 | if ( fi.isSymLink() ) | 69 | if ( fi.isSymLink() ) |
70 | setText( 3, "symlink" ); | 70 | setText( 3, "symlink" ); |
71 | else if( fi.isDir() ) | 71 | else if( fi.isDir() ) |
72 | setText( 3, "directory" ); | 72 | setText( 3, "directory" ); |
73 | else if( isLib() ) | 73 | else if( isLib() ) |
74 | setText( 3, "library" ); | 74 | setText( 3, "library" ); |
75 | else | 75 | else |
76 | setText( 3, mt.description() ); | 76 | setText( 3, mt.description() ); |
77 | 77 | ||
78 | QPixmap pm; | 78 | QPixmap pm; |
79 | if( fi.isDir() ){ | 79 | if( fi.isDir() ){ |
80 | if( !QDir( fi.filePath() ).isReadable() ) | 80 | if( !QDir( fi.filePath() ).isReadable() ) |
81 | pm = Resource::loadPixmap( "lockedfolder" ); | 81 | pm = Resource::loadPixmap( "lockedfolder" ); |
82 | else | 82 | else |
83 | pm = Resource::loadPixmap( "folder" ); | 83 | pm = Resource::loadPixmap( "folder" ); |
84 | } | 84 | } |
85 | else if( !fi.isReadable() ) | 85 | else if( !fi.isReadable() ) |
86 | pm = Resource::loadPixmap( "locked" ); | 86 | pm = Resource::loadPixmap( "locked" ); |
87 | else if( isLib() ) | 87 | else if( isLib() ) |
88 | pm = Resource::loadPixmap( "library" ); | 88 | pm = Resource::loadPixmap( "library" ); |
89 | else if( ((FileView* )parent)->getShowThumbnails() && mt.id().contains(QRegExp("^image/", FALSE, FALSE)) ) | 89 | else if( ((FileView* )parent)->getShowThumbnails() && mt.id().contains(QRegExp("^image/", FALSE, FALSE)) ) |
90 | pm = drawThumbnail(fi); | 90 | pm = drawThumbnail(fi); |
91 | else | 91 | else |
92 | pm = mt.pixmap(); | 92 | pm = mt.pixmap(); |
93 | if ( pm.isNull() ) | 93 | if ( pm.isNull() ) |
94 | pm = Resource::loadPixmap("UnknownDocument-14"); | 94 | pm = Resource::loadPixmap("UnknownDocument-14"); |
95 | 95 | ||
96 | if( fi.isSymLink() ){ | 96 | if( fi.isSymLink() ){ |
97 | // overlay link image | 97 | // overlay link image |
98 | QPixmap lnk = Resource::loadPixmap( "filebrowser/symlink" ); | 98 | QPixmap lnk = Resource::loadPixmap( "filebrowser/symlink" ); |
99 | QPainter painter( &pm ); | 99 | QPainter painter( &pm ); |
100 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); | 100 | painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); |
101 | pm.setMask( pm.createHeuristicMask( FALSE ) ); | 101 | pm.setMask( pm.createHeuristicMask( FALSE ) ); |
102 | } | 102 | } |
103 | setPixmap(0,pm); | 103 | setPixmap(0,pm); |
104 | } | 104 | } |
105 | 105 | ||
106 | QString FileItem::sizeString( unsigned int s ) | 106 | QString FileItem::sizeString( unsigned int s ) |
107 | { | 107 | { |
108 | double size = s; | 108 | double size = s; |
109 | 109 | ||
110 | if ( size > 1024 * 1024 * 1024 ) | 110 | if ( size > 1024 * 1024 * 1024 ) |
111 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; | 111 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 * 1024 ) ) + "G"; |
112 | else if ( size > 1024 * 1024 ) | 112 | else if ( size > 1024 * 1024 ) |
113 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; | 113 | return QString().sprintf( "%.1f", size / ( 1024 * 1024 ) ) + "M"; |
114 | else if ( size > 1024 ) | 114 | else if ( size > 1024 ) |
115 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; | 115 | return QString().sprintf( "%.1f", size / ( 1024 ) ) + "K"; |
116 | else | 116 | else |
117 | return QString::number( size ) + "B"; | 117 | return QString::number( size ) + "B"; |
118 | } | 118 | } |
119 | 119 | ||
120 | QString FileItem::key( int column, bool ascending ) const | 120 | QString FileItem::key( int column, bool ascending ) const |
121 | { | 121 | { |
122 | QString tmp; | 122 | QString tmp; |
123 | 123 | ||
124 | ascending = ascending; | 124 | ascending = ascending; |
125 | 125 | ||
126 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name | 126 | if( (column == 0) && fileInfo.isDir() ){ // Sort by name |
127 | // We want the directories to appear at the top of the list | 127 | // We want the directories to appear at the top of the list |
128 | tmp = (char) 0; | 128 | tmp = (char) 0; |
129 | return (tmp + text( column ).lower()); | 129 | return (tmp + text( column ).lower()); |
130 | } | 130 | } |
131 | else if( column == 2 ) { // Sort by date | 131 | else if( column == 2 ) { // Sort by date |
132 | QDateTime epoch( QDate( 1980, 1, 1 ) ); | 132 | QDateTime epoch( QDate( 1980, 1, 1 ) ); |
133 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); | 133 | tmp.sprintf( "%08d", epoch.secsTo( fileInfo.lastModified() ) ); |
134 | return tmp; | 134 | return tmp; |
135 | } | 135 | } |
136 | else if( column == 1 ) { // Sort by size | 136 | else if( column == 1 ) { // Sort by size |
137 | return tmp.sprintf( "%08d", fileInfo.size() ); | 137 | return tmp.sprintf( "%08d", fileInfo.size() ); |
138 | } | 138 | } |
139 | 139 | ||
140 | return text( column ).lower(); | 140 | return text( column ).lower(); |
141 | } | 141 | } |
142 | 142 | ||
143 | bool FileItem::isLib() | 143 | bool FileItem::isLib() |
144 | { | 144 | { |
145 | // This is of course not foolproof | 145 | // This is of course not foolproof |
146 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && | 146 | if( !qstrncmp("lib", fileInfo.baseName(), 3) && |
147 | ( fileInfo.extension().contains( "so" ) || | 147 | ( fileInfo.extension().contains( "so" ) || |
148 | fileInfo.extension().contains( "a" ) ) ) | 148 | fileInfo.extension().contains( "a" ) ) ) |
149 | return TRUE; | 149 | return TRUE; |
150 | else | 150 | else |
151 | return FALSE; | 151 | return FALSE; |
152 | } | 152 | } |
153 | 153 | ||
154 | int FileItem::launch() | 154 | int FileItem::launch() |
155 | { | 155 | { |
156 | DocLnk doc( fileInfo.filePath(), FALSE ); | 156 | DocLnk doc( fileInfo.filePath(), FALSE ); |
157 | doc.execute(); | 157 | doc.execute(); |
158 | listView()->clearSelection(); | 158 | listView()->clearSelection(); |
159 | return 1; | 159 | return 1; |
160 | } | 160 | } |
161 | 161 | ||
162 | bool FileItem::rename( const QString & name ) | 162 | bool FileItem::rename( const QString & name ) |
163 | { | 163 | { |
164 | QString oldpath, newpath; | 164 | QString oldpath, newpath; |
165 | 165 | ||
166 | if ( name.isEmpty() ) | 166 | if ( name.isEmpty() ) |
167 | return FALSE; | 167 | return FALSE; |
168 | 168 | ||
169 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) | 169 | if ( name.contains( QRegExp("[/\\$\"\'\\*\\?]") ) ) |
170 | return FALSE; | 170 | return FALSE; |
171 | 171 | ||
172 | oldpath = fileInfo.filePath(); | 172 | oldpath = fileInfo.filePath(); |
173 | newpath = fileInfo.dirPath() + "/" + name; | 173 | newpath = fileInfo.dirPath() + "/" + name; |
174 | 174 | ||
175 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) | 175 | if ( ::rename( (const char *) oldpath, (const char *) newpath ) != 0 ) |
176 | return FALSE; | 176 | return FALSE; |
177 | else | 177 | else |
178 | return TRUE; | 178 | return TRUE; |
179 | } | 179 | } |
180 | 180 | ||
181 | QPixmap FileItem::drawThumbnail(const QFileInfo &file) { | 181 | QPixmap FileItem::drawThumbnail(const QFileInfo &file) { |
182 | 182 | ||
183 | /* | 183 | /* |
184 | * this thing is sloooooow, and it also doesn't load | 184 | * this thing is sloooooow, and it also doesn't load |
185 | * dynamicly (like a web browser). if anyone knows how to | 185 | * dynamicly (like a web browser). if anyone knows how to |
186 | * do that, please do! | 186 | * do that, please do! |
187 | */ | 187 | */ |
188 | QString cacheDir = "/tmp/filebrowserThumbnailCache"; | 188 | QString cacheDir = "/tmp/filebrowserThumbnailCache"; |
189 | QFileInfo cachedFile (cacheDir + file.filePath()); | 189 | QFileInfo cachedFile (cacheDir + file.filePath()); |
190 | 190 | ||
191 | if (cachedFile.exists() && cachedFile.lastModified() == file.lastModified()) { | 191 | if (cachedFile.exists() && cachedFile.lastModified() == file.lastModified()) { |
192 | 192 | ||
193 | QPixmap cachedImage (cachedFile.filePath()); | 193 | QPixmap cachedImage (cachedFile.filePath()); |
194 | return cachedImage; | 194 | return cachedImage; |
195 | } | 195 | } |
196 | else { | 196 | else { |
197 | 197 | ||
198 | QImage image (file.filePath()); | 198 | QImage image (file.filePath()); |
199 | 199 | ||
200 | // if inside of cache dir, don't render thumbnails! recursive error! | 200 | // if inside of cache dir, don't render thumbnails! recursive error! |
201 | if (image.isNull() || file.filePath().contains(QRegExp("^" + cacheDir))) { | 201 | if (image.isNull() || file.filePath().contains(QRegExp("^" + cacheDir))) { |
202 | DocLnk doc (file.filePath()); | 202 | DocLnk doc (file.filePath()); |
203 | return doc.pixmap(); | 203 | return doc.pixmap(); |
204 | } | 204 | } |
205 | Config cfg("Filebrowser"); | 205 | Config cfg("Filebrowser"); |
206 | cfg.setGroup("View"); | 206 | cfg.setGroup("View"); |
207 | int size; | 207 | int size; |
208 | size =cfg.readNumEntry("ThumbSize", 72); | 208 | size =cfg.readNumEntry("ThumbSize", 72); |
209 | QPixmap thumb (size, size); | 209 | QPixmap thumb (size, size); |
210 | 210 | ||
211 | double scale = (double)image.height() / (double)image.width(); | 211 | double scale = (double)image.height() / (double)image.width(); |
212 | int newHeight = int(size * scale); | 212 | int newHeight = int(size * scale); |
213 | thumb.convertFromImage (image.smoothScale(size, newHeight)); | 213 | thumb.convertFromImage (image.smoothScale(size, newHeight)); |
214 | 214 | ||
215 | if (!cachedFile.dir().exists()) { | 215 | if (!cachedFile.dir().exists()) { |
216 | QString cmd = "/bin/mkdir -p \"" + cachedFile.dirPath() +"\""; | 216 | QString cmd = "/bin/mkdir -p \"" + cachedFile.dirPath() +"\""; |
217 | system( (const char *) cmd ); | 217 | system( (const char *) cmd ); |
218 | } | 218 | } |
219 | 219 | ||
220 | if (thumb.save(cachedFile.filePath(), QPixmap::imageFormat(file.filePath()), 70)) { | 220 | if (thumb.save(cachedFile.filePath(), QPixmap::imageFormat(file.filePath()), 70)) { |
221 | // make thumbnail modify time the same as the image | 221 | // make thumbnail modify time the same as the image |
222 | QString cmd = "/bin/touch -r \"" + file.filePath() +"\" " + | 222 | QString cmd = "/bin/touch -r \"" + file.filePath() +"\" " + |
223 | "\"" + cachedFile.filePath() + "\""; | 223 | "\"" + cachedFile.filePath() + "\""; |
224 | system( (const char *) cmd ); | 224 | system( (const char *) cmd ); |
225 | 225 | ||
226 | } | 226 | } |
227 | 227 | ||
228 | return thumb; | 228 | return thumb; |
229 | } | 229 | } |
230 | } | 230 | } |
231 | 231 | ||
232 | // | 232 | // |
233 | // FileView | 233 | // FileView |
234 | // | 234 | // |
235 | FileView::FileView( const QString & dir, QWidget * parent, | 235 | FileView::FileView( const QString & dir, QWidget * parent, |
236 | const char * name, | 236 | const char * name, |
237 | bool hidden, bool symlinks, bool thumbnails ) | 237 | bool hidden, bool symlinks, bool thumbnails ) |
238 | : QListView( parent, name ), | 238 | : QListView( parent, name ), |
239 | menuTimer( this ), | 239 | menuTimer( this ), |
240 | le( NULL ), | 240 | le( NULL ), |
241 | itemToRename( NULL ), | 241 | itemToRename( NULL ), |
242 | showHidden( hidden ), | 242 | showHidden( hidden ), |
243 | showSymlinks( symlinks ), | 243 | showSymlinks( symlinks ), |
244 | showThumbnails( thumbnails ), | 244 | showThumbnails( thumbnails ), |
245 | menuKeepsOpen( FALSE ) | 245 | menuKeepsOpen( FALSE ) |
246 | { | 246 | { |
247 | addColumn( "Name" ); | 247 | addColumn( "Name" ); |
248 | addColumn( "Size" ); | 248 | addColumn( "Size" ); |
249 | addColumn( "Date" ); | 249 | addColumn( "Date" ); |
250 | addColumn( "Type" ); | 250 | addColumn( "Type" ); |
251 | 251 | ||
252 | setMultiSelection( TRUE ); | 252 | setMultiSelection( TRUE ); |
253 | //header()->hide(); | 253 | //header()->hide(); |
254 | 254 | ||
255 | setColumnWidthMode( 0, Manual ); | 255 | setColumnWidthMode( 0, Manual ); |
256 | setColumnWidthMode( 3, Manual ); | 256 | setColumnWidthMode( 3, Manual ); |
257 | 257 | ||
258 | // right align yize column | 258 | // right align yize column |
259 | setColumnAlignment( 1, AlignRight ); | 259 | setColumnAlignment( 1, AlignRight ); |
260 | 260 | ||
261 | generateDir( dir ); | 261 | generateDir( dir ); |
262 | 262 | ||
263 | connect( this, SIGNAL( clicked( QListViewItem * )), | 263 | connect( this, SIGNAL( clicked( QListViewItem * )), |
264 | SLOT( itemClicked( QListViewItem * )) ); | 264 | SLOT( itemClicked( QListViewItem * )) ); |
265 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), | 265 | connect( this, SIGNAL( doubleClicked( QListViewItem * )), |
266 | SLOT( itemDblClicked( QListViewItem * )) ); | 266 | SLOT( itemDblClicked( QListViewItem * )) ); |
267 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); | 267 | connect( this, SIGNAL( selectionChanged() ), SLOT( cancelMenuTimer() ) ); |
268 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); | 268 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showFileMenu() ) ); |
269 | } | 269 | } |
270 | 270 | ||
271 | void FileView::resizeEvent( QResizeEvent *e ) | 271 | void FileView::resizeEvent( QResizeEvent *e ) |
272 | { | 272 | { |
273 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); | 273 | setColumnWidth( 0, width() - 2 * lineWidth() - 20 - columnWidth( 1 ) - columnWidth( 2 ) ); |
274 | 274 | ||
275 | // hide type column, we use it for "sort by type" only | 275 | // hide type column, we use it for "sort by type" only |
276 | //setColumnWidth( 3, 0 ); | 276 | //setColumnWidth( 3, 0 ); |
277 | QListView::resizeEvent( e ); | 277 | QListView::resizeEvent( e ); |
278 | } | 278 | } |
279 | 279 | ||
280 | void FileView::updateDir() | 280 | void FileView::updateDir() |
281 | { | 281 | { |
282 | generateDir( currentDir ); | 282 | generateDir( currentDir ); |
283 | } | 283 | } |
284 | 284 | ||
285 | void FileView::setDir( const QString & dir ) | 285 | void FileView::setDir( const QString & dir ) |
286 | { | 286 | { |
287 | if ( dir.startsWith( "/dev" ) ) { | 287 | if ( dir.startsWith( "/dev" ) ) { |
288 | QMessageBox::warning( this, tr( "File Manager" ), | 288 | QMessageBox::warning( this, tr( "File Manager" ), |
289 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); | 289 | tr( "Can't show /dev/ directory." ), tr( "&Ok" ) ); |
290 | return; | 290 | return; |
291 | } | 291 | } |
292 | dirHistory += currentDir; | 292 | dirHistory += currentDir; |
293 | generateDir( dir ); | 293 | generateDir( dir ); |
294 | } | 294 | } |
295 | 295 | ||
296 | void FileView::generateDir( const QString & dir ) | 296 | void FileView::generateDir( const QString & dir ) |
297 | { | 297 | { |
298 | if(menuKeepsOpen){ | 298 | if(menuKeepsOpen){ |
299 | cancelMenuTimer(); | 299 | cancelMenuTimer(); |
300 | } | 300 | } |
301 | QDir d( dir ); | 301 | QDir d( dir ); |
302 | 302 | ||
303 | if( d.exists() && !d.isReadable() ) return; | 303 | if( d.exists() && !d.isReadable() ) return; |
304 | 304 | ||
305 | currentDir = d.canonicalPath(); | 305 | currentDir = d.canonicalPath(); |
306 | 306 | ||
307 | if( !showHidden) | 307 | if( !showHidden) |
308 | d.setFilter( QDir::Dirs | QDir::Files ); | 308 | d.setFilter( QDir::Dirs | QDir::Files ); |
309 | else | 309 | else |
310 | d.setFilter( QDir::Dirs | QDir::Files |QDir::Hidden | QDir::All); | 310 | d.setFilter( QDir::Dirs | QDir::Files |QDir::Hidden | QDir::All); |
311 | 311 | ||
312 | d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::Reversed ); | 312 | d.setSorting( QDir::Name | QDir::DirsFirst | QDir::IgnoreCase | QDir::Reversed ); |
313 | 313 | ||
314 | const QFileInfoList * list = d.entryInfoList(); | 314 | const QFileInfoList * list = d.entryInfoList(); |
315 | QFileInfoListIterator it( *list ); | 315 | QFileInfoListIterator it( *list ); |
316 | QFileInfo *fi; | 316 | QFileInfo *fi; |
317 | 317 | ||
318 | QProgressBar *thumbProgress = 0; | 318 | QProgressBar *thumbProgress = 0; |
319 | if (showThumbnails) { | 319 | if (showThumbnails) { |
320 | 320 | ||
321 | thumbProgress = new QProgressBar(it.count(), this); | 321 | thumbProgress = new QProgressBar(it.count(), this); |
322 | thumbProgress->show(); | 322 | thumbProgress->show(); |
323 | } | 323 | } |
324 | 324 | ||
325 | clear(); | 325 | clear(); |
326 | 326 | ||
327 | int fileCount = 1; // used in the thumbnail progress meter | 327 | int fileCount = 1; // used in the thumbnail progress meter |
328 | while( (fi = it.current()) ){ | 328 | while( (fi = it.current()) ){ |
329 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ | 329 | if( (fi->fileName() == ".") || (fi->fileName() == "..") ){ |
330 | ++it; | 330 | ++it; |
331 | continue; | 331 | continue; |
332 | } | 332 | } |
333 | if(!showSymlinks && fi->isSymLink()){ | 333 | if(!showSymlinks && fi->isSymLink()){ |
334 | ++it; | 334 | ++it; |
335 | continue; | 335 | continue; |
336 | } | 336 | } |
337 | // thumbnail progress | 337 | // thumbnail progress |
338 | if (showThumbnails) { | 338 | if (showThumbnails) { |
339 | 339 | ||
340 | thumbProgress->setProgress(fileCount); | 340 | thumbProgress->setProgress(fileCount); |
341 | } | 341 | } |
342 | (void) new FileItem( (QListView *) this, *fi ); | 342 | (void) new FileItem( (QListView *) this, *fi ); |
343 | 343 | ||
344 | ++it; | 344 | ++it; |
345 | ++fileCount; | 345 | ++fileCount; |
346 | } | 346 | } |
347 | 347 | ||
348 | if (showThumbnails) { | 348 | if (showThumbnails) { |
349 | thumbProgress->close(); | 349 | thumbProgress->close(); |
350 | } | 350 | } |
351 | emit dirChanged(); | 351 | emit dirChanged(); |
352 | 352 | ||
353 | } | 353 | } |
354 | 354 | ||
355 | void FileView::rename() | 355 | void FileView::rename() |
356 | { | 356 | { |
357 | itemToRename = (FileItem *) currentItem(); | 357 | itemToRename = (FileItem *) currentItem(); |
358 | const QPixmap * pm; | 358 | const QPixmap * pm; |
359 | int pmw; | 359 | int pmw; |
360 | 360 | ||
361 | if( itemToRename == NULL ) return; | 361 | if( itemToRename == NULL ) return; |
362 | 362 | ||
363 | if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) | 363 | if( ( pm = itemToRename->pixmap( 0 ) ) == NULL ) |
364 | pmw = 0; | 364 | pmw = 0; |
365 | else | 365 | else |
366 | pmw = pm->width(); | 366 | pmw = pm->width(); |
367 | 367 | ||
368 | ensureItemVisible( itemToRename ); | 368 | ensureItemVisible( itemToRename ); |
369 | horizontalScrollBar()->setValue( 0 ); | 369 | horizontalScrollBar()->setValue( 0 ); |
370 | horizontalScrollBar()->setEnabled( FALSE ); | 370 | horizontalScrollBar()->setEnabled( FALSE ); |
371 | verticalScrollBar()->setEnabled( FALSE ); | 371 | verticalScrollBar()->setEnabled( FALSE ); |
372 | 372 | ||
373 | selected = isSelected( itemToRename ); | 373 | selected = isSelected( itemToRename ); |
374 | setSelected( itemToRename, FALSE ); | 374 | setSelected( itemToRename, FALSE ); |
375 | 375 | ||
376 | if( le == NULL ){ | 376 | if( le == NULL ){ |
377 | le = new InlineEdit( this ); | 377 | le = new InlineEdit( this ); |
378 | le->setFrame( FALSE ); | 378 | le->setFrame( FALSE ); |
379 | connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); | 379 | connect( le, SIGNAL( lostFocus() ), SLOT( endRenaming() ) ); |
380 | } | 380 | } |
381 | 381 | ||
382 | QRect r = itemRect( itemToRename ); | 382 | QRect r = itemRect( itemToRename ); |
383 | r.setTop( r.top() + frameWidth() + 1 ); | 383 | r.setTop( r.top() + frameWidth() + 1 ); |
384 | r.setLeft( r.left() + frameWidth() + pmw ); | 384 | r.setLeft( r.left() + frameWidth() + pmw ); |
385 | r.setBottom( r.bottom() + frameWidth() ); | 385 | r.setBottom( r.bottom() + frameWidth() ); |
386 | r.setWidth( columnWidth( 0 ) - pmw ); | 386 | r.setWidth( columnWidth( 0 ) - pmw ); |
387 | 387 | ||
388 | le->setGeometry( r ); | 388 | le->setGeometry( r ); |
389 | le->setText( itemToRename->text( 0 ) ); | 389 | le->setText( itemToRename->text( 0 ) ); |
390 | le->selectAll(); | 390 | le->selectAll(); |
391 | le->show(); | 391 | le->show(); |
392 | le->setFocus(); | 392 | le->setFocus(); |
393 | } | 393 | } |
394 | 394 | ||
395 | void FileView::endRenaming() | 395 | void FileView::endRenaming() |
396 | { | 396 | { |
397 | if( le && itemToRename ){ | 397 | if( le && itemToRename ){ |
398 | le->hide(); | 398 | le->hide(); |
399 | setSelected( itemToRename, selected ); | 399 | setSelected( itemToRename, selected ); |
400 | 400 | ||
401 | if( !itemToRename->rename( le->text() ) ){ | 401 | if( !itemToRename->rename( le->text() ) ){ |
402 | QMessageBox::warning( this, tr( "Rename file" ), | 402 | QMessageBox::warning( this, tr( "Rename file" ), |
403 | tr( "Rename failed!" ), tr( "&Ok" ) ); | 403 | tr( "Rename failed!" ), tr( "&Ok" ) ); |
404 | } else { | 404 | } else { |
405 | updateDir(); | 405 | updateDir(); |
406 | } | 406 | } |
407 | itemToRename = NULL; | 407 | itemToRename = NULL; |
408 | horizontalScrollBar()->setEnabled( TRUE ); | 408 | horizontalScrollBar()->setEnabled( TRUE ); |
409 | verticalScrollBar()->setEnabled( TRUE ); | 409 | verticalScrollBar()->setEnabled( TRUE ); |
410 | } | 410 | } |
411 | } | 411 | } |
412 | 412 | ||
413 | void FileView::copy() | 413 | void FileView::copy() |
414 | { | 414 | { |
415 | // dont keep cut files any longer than necessary | 415 | // dont keep cut files any longer than necessary |
416 | // ##### a better inmplementation might be to rename the CUT file | 416 | // ##### a better inmplementation might be to rename the CUT file |
417 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. | 417 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. |
418 | system ( "rm -rf /tmp/qpemoving" ); | 418 | system ( "rm -rf /tmp/qpemoving" ); |
419 | 419 | ||
420 | FileItem * i; | 420 | FileItem * i; |
421 | 421 | ||
422 | if((i = (FileItem *) firstChild()) == 0) return; | 422 | if((i = (FileItem *) firstChild()) == 0) return; |
423 | 423 | ||
424 | flist.clear(); | 424 | flist.clear(); |
425 | while( i ){ | 425 | while( i ){ |
426 | if( i->isSelected() /*&& !i->isDir()*/ ){ | 426 | if( i->isSelected() /*&& !i->isDir()*/ ){ |
427 | flist += i->getFilePath(); | 427 | flist += i->getFilePath(); |
428 | } | 428 | } |
429 | i = (FileItem *) i->nextSibling(); | 429 | i = (FileItem *) i->nextSibling(); |
430 | } | 430 | } |
431 | } | 431 | } |
432 | 432 | ||
433 | void FileView::paste() | 433 | void FileView::paste() |
434 | { | 434 | { |
435 | int i, err; | 435 | int i, err; |
436 | QString cmd, dest, basename, cd = currentDir; | 436 | QString cmd, dest, basename, cd = currentDir; |
437 | 437 | ||
438 | if(cd == "/") cd = ""; | 438 | if(cd == "/") cd = ""; |
439 | 439 | ||
440 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { | 440 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { |
441 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); | 441 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); |
442 | 442 | ||
443 | dest = cd + "/" + basename; | 443 | dest = cd + "/" + basename; |
444 | if( QFile( dest ).exists() ){ | 444 | if( QFile( dest ).exists() ){ |
445 | i = 1; | 445 | i = 1; |
446 | dest = cd + "/Copy of " + basename; | 446 | dest = cd + "/Copy of " + basename; |
447 | while( QFile( dest ).exists() ){ | 447 | while( QFile( dest ).exists() ){ |
448 | dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++, | 448 | dest.sprintf( "%s/Copy (%d) of %s", (const char *) cd, i++, |
449 | (const char *) basename ); | 449 | (const char *) basename ); |
450 | } | 450 | } |
451 | } | 451 | } |
452 | 452 | ||
453 | // | 453 | // |
454 | // Copy a directory recursively using the "cp" command - | 454 | // Copy a directory recursively using the "cp" command - |
455 | // may have to be changed | 455 | // may have to be changed |
456 | // | 456 | // |
457 | if( QFileInfo( (*it) ).isDir() ){ | 457 | if( QFileInfo( (*it) ).isDir() ){ |
458 | cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\""; | 458 | cmd = "/bin/cp -fpR \"" + (*it) +"\" " + "\"" + dest + "\""; |
459 | err = system( (const char *) cmd ); | 459 | err = system( (const char *) cmd ); |
460 | } else if( !copyFile( dest, (*it) ) ){ | 460 | } else if( !copyFile( dest, (*it) ) ){ |
461 | err = -1; | 461 | err = -1; |
462 | } else { | 462 | } else { |
463 | err = 0; | 463 | err = 0; |
464 | } | 464 | } |
465 | 465 | ||
466 | if ( err != 0 ) { | 466 | if ( err != 0 ) { |
467 | QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), | 467 | QMessageBox::warning( this, tr("Paste file"), tr("Paste failed!"), |
468 | tr("Ok") ); | 468 | tr("Ok") ); |
469 | break; | 469 | break; |
470 | } else { | 470 | } else { |
471 | updateDir(); | 471 | updateDir(); |
472 | QListViewItem * i = firstChild(); | 472 | QListViewItem * i = firstChild(); |
473 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); | 473 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); |
474 | 474 | ||
475 | while( i ){ | 475 | while( i ){ |
476 | if( i->text(0) == basename ){ | 476 | if( i->text(0) == basename ){ |
477 | setCurrentItem( i ); | 477 | setCurrentItem( i ); |
478 | ensureItemVisible( i ); | 478 | ensureItemVisible( i ); |
479 | break; | 479 | break; |
480 | } | 480 | } |
481 | i = i->nextSibling(); | 481 | i = i->nextSibling(); |
482 | } | 482 | } |
483 | } | 483 | } |
484 | } | 484 | } |
485 | } | 485 | } |
486 | 486 | ||
487 | bool FileView::copyFile( const QString & dest, const QString & src ) | 487 | bool FileView::copyFile( const QString & dest, const QString & src ) |
488 | { | 488 | { |
489 | char bf[ 50000 ]; | 489 | char bf[ 50000 ]; |
490 | int bytesRead; | 490 | int bytesRead; |
491 | bool success = TRUE; | 491 | bool success = TRUE; |
492 | struct stat status; | 492 | struct stat status; |
493 | 493 | ||
494 | QFile s( src ); | 494 | QFile s( src ); |
495 | QFile d( dest ); | 495 | QFile d( dest ); |
496 | 496 | ||
497 | if( s.open( IO_ReadOnly | IO_Raw ) && | 497 | if( s.open( IO_ReadOnly | IO_Raw ) && |
498 | d.open( IO_WriteOnly | IO_Raw ) ) | 498 | d.open( IO_WriteOnly | IO_Raw ) ) |
499 | { | 499 | { |
500 | while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == | 500 | while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == |
501 | sizeof( bf ) ) | 501 | sizeof( bf ) ) |
502 | { | 502 | { |
503 | if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ | 503 | if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ |
504 | success = FALSE; | 504 | success = FALSE; |
505 | break; | 505 | break; |
506 | } | 506 | } |
507 | } | 507 | } |
508 | if( success && (bytesRead > 0) ){ | 508 | if( success && (bytesRead > 0) ){ |
509 | d.writeBlock( bf, bytesRead ); | 509 | d.writeBlock( bf, bytesRead ); |
510 | } | 510 | } |
511 | } else { | 511 | } else { |
512 | success = FALSE; | 512 | success = FALSE; |
513 | } | 513 | } |
514 | 514 | ||
515 | // Set file permissions | 515 | // Set file permissions |
516 | if( stat( (const char *) src, &status ) == 0 ){ | 516 | if( stat( (const char *) src, &status ) == 0 ){ |
517 | chmod( (const char *) dest, status.st_mode ); | 517 | chmod( (const char *) dest, status.st_mode ); |
518 | } | 518 | } |
519 | 519 | ||
520 | return success; | 520 | return success; |
521 | } | 521 | } |
522 | 522 | ||
523 | void FileView::cut() | 523 | void FileView::cut() |
524 | { | 524 | { |
525 | int err; | 525 | int err; |
526 | // ##### a better inmplementation might be to rename the CUT file | 526 | // ##### a better inmplementation might be to rename the CUT file |
527 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. | 527 | // ##### to ".QPE-FILEBROWSER-MOVING" rather than copying it. |
528 | QString cmd, dest, basename, cd = "/tmp/qpemoving"; | 528 | QString cmd, dest, basename, cd = "/tmp/qpemoving"; |
529 | QStringList newflist; | 529 | QStringList newflist; |
530 | newflist.clear(); | 530 | newflist.clear(); |
531 | 531 | ||
532 | cmd = "rm -rf " + cd; | 532 | cmd = "rm -rf " + cd; |
533 | system ( (const char *) cmd ); | 533 | system ( (const char *) cmd ); |
534 | cmd = "mkdir " + cd; | 534 | cmd = "mkdir " + cd; |
535 | system( (const char *) cmd ); | 535 | system( (const char *) cmd ); |
536 | 536 | ||
537 | // get the names of the files to cut | 537 | // get the names of the files to cut |
538 | FileItem * item; | 538 | FileItem * item; |
539 | 539 | ||
540 | if((item = (FileItem *) firstChild()) == 0) return; | 540 | if((item = (FileItem *) firstChild()) == 0) return; |
541 | 541 | ||
542 | flist.clear(); | 542 | flist.clear(); |
543 | while( item ){ | 543 | while( item ){ |
544 | if( item->isSelected() /*&& !item->isDir()*/ ){ | 544 | if( item->isSelected() /*&& !item->isDir()*/ ){ |
545 | flist += item->getFilePath(); | 545 | flist += item->getFilePath(); |
546 | } | 546 | } |
547 | item = (FileItem *) item->nextSibling(); | 547 | item = (FileItem *) item->nextSibling(); |
548 | } | 548 | } |
549 | 549 | ||
550 | // move these files into a tmp dir | 550 | // move these files into a tmp dir |
551 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { | 551 | for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) { |
552 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); | 552 | basename = (*it).mid((*it).findRev("/") + 1, (*it).length()); |
553 | 553 | ||
554 | dest = cd + "/" + basename; | 554 | dest = cd + "/" + basename; |
555 | 555 | ||
556 | newflist += dest; | 556 | newflist += dest; |
557 | 557 | ||
558 | cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; | 558 | cmd = "/bin/mv -f \"" + (*it) +"\" " + "\"" + dest + "\""; |
559 | err = system( (const char *) cmd ); | 559 | err = system( (const char *) cmd ); |
560 | 560 | ||
561 | if ( err != 0 ) { | 561 | if ( err != 0 ) { |
562 | QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), | 562 | QMessageBox::warning( this, tr("Cut file"), tr("Cut failed!"), |
563 | tr("Ok") ); | 563 | tr("Ok") ); |
564 | break; | 564 | break; |
565 | } else { | 565 | } else { |
566 | updateDir(); | 566 | updateDir(); |
567 | QListViewItem * im = firstChild(); | 567 | QListViewItem * im = firstChild(); |
568 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); | 568 | basename = dest.mid( dest.findRev("/") + 1, dest.length() ); |
569 | 569 | ||
570 | while( im ){ | 570 | while( im ){ |
571 | if( im->text(0) == basename ){ | 571 | if( im->text(0) == basename ){ |
572 | setCurrentItem( im ); | 572 | setCurrentItem( im ); |
573 | ensureItemVisible( im ); | 573 | ensureItemVisible( im ); |
574 | break; | 574 | break; |
575 | } | 575 | } |
576 | im = im->nextSibling(); | 576 | im = im->nextSibling(); |
577 | } | 577 | } |
578 | } | 578 | } |
579 | } | 579 | } |
580 | 580 | ||
581 | // update the filelist to point to tmp dir so paste works nicely | 581 | // update the filelist to point to tmp dir so paste works nicely |
582 | flist = newflist; | 582 | flist = newflist; |
583 | } | 583 | } |
584 | 584 | ||
585 | void FileView::del() | 585 | void FileView::del() |
586 | { | 586 | { |
587 | FileItem * i; | 587 | FileItem * i; |
588 | QStringList fl; | 588 | QStringList fl; |
589 | QString cmd; | 589 | QString cmd; |
590 | int err; | 590 | int err; |
591 | 591 | ||
592 | if((i = (FileItem *) firstChild()) == 0) return; | 592 | if((i = (FileItem *) firstChild()) == 0) return; |
593 | 593 | ||
594 | while( i ){ | 594 | while( i ){ |
595 | if( i->isSelected() ){ | 595 | if( i->isSelected() ){ |
596 | fl += i->getFilePath(); | 596 | fl += i->getFilePath(); |
597 | } | 597 | } |
598 | i = (FileItem *) i->nextSibling(); | 598 | i = (FileItem *) i->nextSibling(); |
599 | } | 599 | } |
600 | if( fl.count() < 1 ) return; | 600 | if( fl.count() < 1 ) return; |
601 | 601 | ||
602 | if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), | 602 | if( QMessageBox::warning( this, tr("Delete"), tr("Are you sure?"), |
603 | tr("Yes"), tr("No") ) == 0) | 603 | tr("Yes"), tr("No") ) == 0) |
604 | { | 604 | { |
605 | // | 605 | // |
606 | // Dependant upon the "rm" command - will probably have to be replaced | 606 | // Dependant upon the "rm" command - will probably have to be replaced |
607 | // | 607 | // |
608 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { | 608 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { |
609 | cmd = "/bin/rm -rf \"" + (*it) + "\""; | 609 | cmd = "/bin/rm -rf \"" + (*it) + "\""; |
610 | err = system( (const char *) cmd ); | 610 | err = system( (const char *) cmd ); |
611 | if ( err != 0 ) { | 611 | if ( err != 0 ) { |
612 | QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), | 612 | QMessageBox::warning( this, tr("Delete"), tr("Delete failed!"), |
613 | tr("Ok") ); | 613 | tr("Ok") ); |
614 | break; | 614 | break; |
615 | } | 615 | } |
616 | } | 616 | } |
617 | updateDir(); | 617 | updateDir(); |
618 | } | 618 | } |
619 | } | 619 | } |
620 | 620 | ||
621 | void FileView::newFolder() | 621 | void FileView::newFolder() |
622 | { | 622 | { |
623 | int t = 1; | 623 | int t = 1; |
624 | FileItem * i; | 624 | FileItem * i; |
625 | QString nd = currentDir + "/NewFolder"; | 625 | QString nd = currentDir + "/NewFolder"; |
626 | 626 | ||
627 | while( QFile( nd ).exists() ){ | 627 | while( QFile( nd ).exists() ){ |
628 | nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); | 628 | nd.sprintf( "%s/NewFolder (%d)", (const char *) currentDir, t++ ); |
629 | } | 629 | } |
630 | 630 | ||
631 | if( mkdir( (const char *) nd, 0777 ) != 0){ | 631 | if( mkdir( (const char *) nd, 0777 ) != 0){ |
632 | QMessageBox::warning( this, tr( "New folder" ), | 632 | QMessageBox::warning( this, tr( "New folder" ), |
633 | tr( "Folder creation failed!" ), | 633 | tr( "Folder creation failed!" ), |
634 | tr( "Ok" ) ); | 634 | tr( "Ok" ) ); |
635 | return; | 635 | return; |
636 | } | 636 | } |
637 | updateDir(); | 637 | updateDir(); |
638 | 638 | ||
639 | if((i = (FileItem *) firstChild()) == 0) return; | 639 | if((i = (FileItem *) firstChild()) == 0) return; |
640 | 640 | ||
641 | while( i ){ | 641 | while( i ){ |
642 | if( i->isDir() && ( i->getFilePath() == nd ) ){ | 642 | if( i->isDir() && ( i->getFilePath() == nd ) ){ |
643 | setCurrentItem( i ); | 643 | setCurrentItem( i ); |
644 | rename(); | 644 | rename(); |
645 | break; | 645 | break; |
646 | } | 646 | } |
647 | i = (FileItem *) i->nextSibling(); | 647 | i = (FileItem *) i->nextSibling(); |
648 | } | 648 | } |
649 | } | 649 | } |
650 | 650 | ||
651 | void FileView::viewAsText() | 651 | void FileView::viewAsText() |
652 | { | 652 | { |
653 | FileItem * i = (FileItem *) currentItem(); | 653 | FileItem * i = (FileItem *) currentItem(); |
654 | QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); | 654 | QCopEnvelope e("QPE/Application/textedit","setDocument(QString)"); |
655 | e << i->getFilePath(); | 655 | e << i->getFilePath(); |
656 | // Global::execute( "textedit -f ", i->getFilePath() ); | 656 | // Global::execute( "textedit -f ", i->getFilePath() ); |
657 | } | 657 | } |
658 | 658 | ||
659 | void FileView::itemClicked( QListViewItem * i) | 659 | void FileView::itemClicked( QListViewItem * i) |
660 | { | 660 | { |
661 | FileItem * t = (FileItem *) i; | 661 | FileItem * t = (FileItem *) i; |
662 | 662 | ||
663 | if( t == NULL ) return; | 663 | if( t == NULL ) return; |
664 | if( t->isDir() ){ | 664 | if( t->isDir() ){ |
665 | setDir( t->getFilePath() ); | 665 | setDir( t->getFilePath() ); |
666 | } | 666 | } |
667 | } | 667 | } |
668 | 668 | ||
669 | void FileView::itemDblClicked( QListViewItem * i) | 669 | void FileView::itemDblClicked( QListViewItem * i) |
670 | { | 670 | { |
671 | if(menuKeepsOpen){ | 671 | if(menuKeepsOpen){ |
672 | cancelMenuTimer(); | 672 | cancelMenuTimer(); |
673 | } | 673 | } |
674 | 674 | ||
675 | FileItem * t = (FileItem *) i; | 675 | FileItem * t = (FileItem *) i; |
676 | 676 | ||
677 | if(t == NULL) return; | 677 | if(t == NULL) return; |
678 | if(t->launch() == -1){ | 678 | if(t->launch() == -1){ |
679 | QMessageBox::warning( this, tr( "Launch Application" ), | 679 | QMessageBox::warning( this, tr( "Launch Application" ), |
680 | tr( "Launch failed!" ), tr( "Ok" ) ); | 680 | tr( "Launch failed!" ), tr( "Ok" ) ); |
681 | } | 681 | } |
682 | } | 682 | } |
683 | 683 | ||
684 | void FileView::parentDir() | 684 | void FileView::parentDir() |
685 | { | 685 | { |
686 | setDir( currentDir + "./.." ); | 686 | setDir( currentDir + "./.." ); |
687 | } | 687 | } |
688 | 688 | ||
689 | void FileView::lastDir() | 689 | void FileView::lastDir() |
690 | { | 690 | { |
691 | if( dirHistory.count() == 0 ) return; | 691 | if( dirHistory.count() == 0 ) return; |
692 | 692 | ||
693 | QString newDir = dirHistory.last(); | 693 | QString newDir = dirHistory.last(); |
694 | dirHistory.remove( dirHistory.last() ); | 694 | dirHistory.remove( dirHistory.last() ); |
695 | generateDir( newDir ); | 695 | generateDir( newDir ); |
696 | } | 696 | } |
697 | 697 | ||
698 | void FileView::contentsMousePressEvent( QMouseEvent * e ) | 698 | void FileView::contentsMousePressEvent( QMouseEvent * e ) |
699 | { | 699 | { |
700 | QListView::contentsMousePressEvent( e ); | 700 | QListView::contentsMousePressEvent( e ); |
701 | menuTimer.start( 750, TRUE ); | 701 | menuTimer.start( 750, TRUE ); |
702 | } | 702 | } |
703 | 703 | ||
704 | void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) | 704 | void FileView::contentsMouseReleaseEvent( QMouseEvent * e ) |
705 | { | 705 | { |
706 | QListView::contentsMouseReleaseEvent( e ); | 706 | QListView::contentsMouseReleaseEvent( e ); |
707 | if(!menuKeepsOpen){ | 707 | if(!menuKeepsOpen){ |
708 | menuTimer.stop(); | 708 | menuTimer.stop(); |
709 | } | 709 | } |
710 | 710 | ||
711 | } | 711 | } |
712 | 712 | ||
713 | void FileView::cancelMenuTimer() | 713 | void FileView::cancelMenuTimer() |
714 | { | 714 | { |
715 | if( menuTimer.isActive() ) | 715 | if( menuTimer.isActive() ) |
716 | menuTimer.stop(); | 716 | menuTimer.stop(); |
717 | } | 717 | } |
718 | 718 | ||
719 | void FileView::addToDocuments() | 719 | void FileView::addToDocuments() |
720 | { | 720 | { |
721 | FileItem * i = (FileItem *) currentItem(); | 721 | FileItem * i = (FileItem *) currentItem(); |
722 | DocLnk f; | 722 | DocLnk f; |
723 | QString n = i->text(0); | 723 | QString n = i->text(0); |
724 | n.replace(QRegExp("\\..*"),""); | 724 | n.replace(QRegExp("\\..*"),""); |
725 | f.setName( n ); | 725 | f.setName( n ); |
726 | f.setFile( i->getFilePath() ); | 726 | f.setFile( i->getFilePath() ); |
727 | f.writeLink(); | 727 | f.writeLink(); |
728 | } | 728 | } |
729 | 729 | ||
730 | void FileView::run() | 730 | void FileView::run() |
731 | { | 731 | { |
732 | FileItem * i = (FileItem *) currentItem(); | 732 | FileItem * i = (FileItem *) currentItem(); |
733 | i->launch(); | 733 | i->launch(); |
734 | } | 734 | } |
735 | 735 | ||
736 | void FileView::showFileMenu() | 736 | void FileView::showFileMenu() |
737 | { | 737 | { |
738 | FileItem * i = (FileItem *) currentItem(); | 738 | FileItem * i = (FileItem *) currentItem(); |
739 | if ( !i ) | 739 | if ( !i ) |
740 | return; | 740 | return; |
741 | 741 | ||
742 | QPopupMenu * m = new QPopupMenu( this ); | 742 | QPopupMenu * m = new QPopupMenu( this ); |
743 | 743 | ||
744 | if ( !i->isDir() ) { | 744 | if ( !i->isDir() ) { |
745 | m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); | 745 | m->insertItem( tr( "Add to Documents" ), this, SLOT( addToDocuments() ) ); |
746 | m->insertSeparator(); | 746 | m->insertSeparator(); |
747 | } | 747 | } |
748 | 748 | ||
749 | MimeType mt(i->getFilePath()); | 749 | MimeType mt(i->getFilePath()); |
750 | const AppLnk* app = mt.application(); | 750 | const AppLnk* app = mt.application(); |
751 | 751 | ||
752 | if ( !i->isDir() ) { | 752 | if ( !i->isDir() ) { |
753 | if ( app ) | 753 | if ( app ) |
754 | m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); | 754 | m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( run() ) ); |
755 | else if( i->isExecutable() ) | 755 | else if( i->isExecutable() ) |
756 | m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); | 756 | m->insertItem( Resource::loadPixmap( i->text( 0 ) ), tr( "Run" ), this, SLOT( run() ) ); |
757 | 757 | ||
758 | m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), | 758 | m->insertItem( Resource::loadPixmap( "txt" ), tr( "View as text" ), |
759 | this, SLOT( viewAsText() ) ); | 759 | this, SLOT( viewAsText() ) ); |
760 | 760 | ||
761 | m->insertSeparator(); | 761 | m->insertSeparator(); |
762 | } | 762 | } |
763 | 763 | ||
764 | m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); | 764 | m->insertItem( tr( "Rename" ), this, SLOT( rename() ) ); |
765 | m->insertItem( Resource::loadPixmap("cut"), | 765 | m->insertItem( Resource::loadPixmap("cut"), |
766 | tr( "Cut" ), this, SLOT( cut() ) ); | 766 | tr( "Cut" ), this, SLOT( cut() ) ); |
767 | m->insertItem( Resource::loadPixmap("copy"), | 767 | m->insertItem( Resource::loadPixmap("copy"), |
768 | 768 | ||
769 | tr( "Copy" ), this, SLOT( copy() ) ); | 769 | tr( "Copy" ), this, SLOT( copy() ) ); |
770 | m->insertItem( Resource::loadPixmap("paste"), | 770 | m->insertItem( Resource::loadPixmap("paste"), |
771 | tr( "Paste" ), this, SLOT( paste() ) ); | 771 | tr( "Paste" ), this, SLOT( paste() ) ); |
772 | m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) ); | 772 | m->insertItem( tr( "Change Permissions" ), this, SLOT( chPerm() ) ); |
773 | m->insertItem(Resource::loadPixmap( "close" ), tr( "Delete" ), this, SLOT( del() ) ); | 773 | m->insertItem(Resource::loadPixmap( "close" ), tr( "Delete" ), this, SLOT( del() ) ); |
774 | m->insertSeparator(); | 774 | m->insertSeparator(); |
775 | m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); | 775 | m->insertItem( tr( "Select all" ), this, SLOT( selectAll() ) ); |
776 | m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); | 776 | m->insertItem( tr( "Deselect all" ), this, SLOT( deselectAll() ) ); |
777 | m->popup( QCursor::pos() ); | 777 | m->popup( QCursor::pos() ); |
778 | } | 778 | } |
779 | 779 | ||
780 | // | 780 | // |
781 | // FileBrowser | 781 | // FileBrowser |
782 | // | 782 | // |
783 | 783 | ||
784 | void FileView::setShowHidden(bool hidden) | 784 | void FileView::setShowHidden(bool hidden) |
785 | { | 785 | { |
786 | showHidden=hidden; | 786 | showHidden=hidden; |
787 | } | 787 | } |
788 | 788 | ||
789 | void FileView::setShowSymlinks(bool symlinks) | 789 | void FileView::setShowSymlinks(bool symlinks) |
790 | { | 790 | { |
791 | showSymlinks=symlinks; | 791 | showSymlinks=symlinks; |
792 | } | 792 | } |
793 | 793 | ||
794 | void FileView::setShowThumbnails(bool thumbnails) | 794 | void FileView::setShowThumbnails(bool thumbnails) |
795 | { | 795 | { |
796 | showThumbnails=thumbnails; | 796 | showThumbnails=thumbnails; |
797 | } | 797 | } |
798 | 798 | ||
799 | void FileView::setMenuKeepsOpen(bool keepOpen) | 799 | void FileView::setMenuKeepsOpen(bool keepOpen) |
800 | { | 800 | { |
801 | menuKeepsOpen=keepOpen; | 801 | menuKeepsOpen=keepOpen; |
802 | } | 802 | } |
803 | 803 | ||
804 | FileBrowser::FileBrowser( QWidget * parent, | 804 | FileBrowser::FileBrowser( QWidget * parent, |
805 | const char * name, WFlags f ) : | 805 | const char * name, WFlags f ) : |
806 | QMainWindow( parent, name, f ) | 806 | QMainWindow( parent, name, f ) |
807 | { | 807 | { |
808 | init( QDir::current().canonicalPath() ); | 808 | init( QDir::current().canonicalPath() ); |
809 | } | 809 | } |
810 | 810 | ||
811 | FileBrowser::FileBrowser( const QString & dir, QWidget * parent, | 811 | FileBrowser::FileBrowser( const QString & dir, QWidget * parent, |
812 | const char * name, WFlags f ) : | 812 | const char * name, WFlags f ) : |
813 | QMainWindow( parent, name, f ) | 813 | QMainWindow( parent, name, f ) |
814 | { | 814 | { |
815 | init( dir ); | 815 | init( dir ); |
816 | } | 816 | } |
817 | 817 | ||
818 | void FileBrowser::init(const QString & dir) | 818 | void FileBrowser::init(const QString & dir) |
819 | { | 819 | { |
820 | setCaption( tr("File Manager") ); | 820 | setCaption( tr("File Manager") ); |
821 | setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); | 821 | setIcon( Resource::loadPixmap( "filebrowser_icon" ) ); |
822 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 822 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
823 | 823 | ||
824 | 824 | ||
825 | Config cfg("Filebrowser"); | 825 | Config cfg("Filebrowser"); |
826 | cfg.setGroup("View"); | 826 | cfg.setGroup("View"); |
827 | bool showHidden=(cfg.readEntry("Hidden","FALSE") == "TRUE"); | 827 | bool showHidden=(cfg.readEntry("Hidden","FALSE") == "TRUE"); |
828 | bool showSymlinks=(cfg.readEntry("Symlinks","FALSE") == "TRUE"); | 828 | bool showSymlinks=(cfg.readEntry("Symlinks","FALSE") == "TRUE"); |
829 | bool showThumbnails=(cfg.readEntry("Thumbnails","FALSE") == "TRUE"); | 829 | bool showThumbnails=(cfg.readEntry("Thumbnails","FALSE") == "TRUE"); |
830 | 830 | ||
831 | cfg.setGroup("Menu"); | 831 | cfg.setGroup("Menu"); |
832 | bool menuKeepsOpen=(cfg.readEntry("KeepOpen", "FALSE") == "TRUE"); | 832 | bool menuKeepsOpen=(cfg.readEntry("KeepOpen", "FALSE") == "TRUE"); |
833 | 833 | ||
834 | 834 | ||
835 | fileView = new FileView( dir, this, 0, showHidden, showSymlinks, showThumbnails ); | 835 | fileView = new FileView( dir, this, 0, showHidden, showSymlinks, showThumbnails ); |
836 | fileView->setAllColumnsShowFocus( TRUE ); | 836 | fileView->setAllColumnsShowFocus( TRUE ); |
837 | fileView->setMenuKeepsOpen(menuKeepsOpen); | 837 | fileView->setMenuKeepsOpen(menuKeepsOpen); |
838 | 838 | ||
839 | setCentralWidget( fileView ); | 839 | setCentralWidget( fileView ); |
840 | setToolBarsMovable( FALSE ); | 840 | setToolBarsMovable( FALSE ); |
841 | 841 | ||
842 | QPEToolBar* toolBar = new QPEToolBar( this ); | 842 | QToolBar* toolBar = new QToolBar( this ); |
843 | toolBar->setHorizontalStretchable( TRUE ); | 843 | toolBar->setHorizontalStretchable( TRUE ); |
844 | 844 | ||
845 | QMenuBar* menuBar = new QMenuBar( toolBar ); | 845 | QMenuBar* menuBar = new QMenuBar( toolBar ); |
846 | 846 | ||
847 | dirMenu = new QPopupMenu( this ); | 847 | dirMenu = new QPopupMenu( this ); |
848 | menuBar->insertItem( tr( "Dir" ), dirMenu ); | 848 | menuBar->insertItem( tr( "Dir" ), dirMenu ); |
849 | 849 | ||
850 | sortMenu = new QPopupMenu( this ); | 850 | sortMenu = new QPopupMenu( this ); |
851 | menuBar->insertItem( tr( "Sort" ), sortMenu ); | 851 | menuBar->insertItem( tr( "Sort" ), sortMenu ); |
852 | sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) ); | 852 | sortMenu->insertItem( tr( "by Name "), this, SLOT( sortName() ) ); |
853 | sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) ); | 853 | sortMenu->insertItem( tr( "by Size "), this, SLOT( sortSize() ) ); |
854 | sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) ); | 854 | sortMenu->insertItem( tr( "by Date "), this, SLOT( sortDate() ) ); |
855 | sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) ); | 855 | sortMenu->insertItem( tr( "by Type "), this, SLOT( sortType() ) ); |
856 | sortMenu->insertSeparator(); | 856 | sortMenu->insertSeparator(); |
857 | sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) ); | 857 | sortMenu->insertItem( tr( "Ascending" ), this, SLOT( updateSorting() ) ); |
858 | 858 | ||
859 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE ); | 859 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), TRUE ); |
860 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); | 860 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); |
861 | 861 | ||
862 | viewMenu = new QPopupMenu( this); | 862 | viewMenu = new QPopupMenu( this); |
863 | viewMenu->insertItem( tr( "Hidden"), this, SLOT( updateShowHidden() ) ); | 863 | viewMenu->insertItem( tr( "Hidden"), this, SLOT( updateShowHidden() ) ); |
864 | viewMenu->insertItem( tr( "Symlinks"), this, SLOT( updateShowSymlinks() ) ); | 864 | viewMenu->insertItem( tr( "Symlinks"), this, SLOT( updateShowSymlinks() ) ); |
865 | viewMenu->insertItem( tr( "Thumbnails"), this, SLOT( updateShowThumbnails() ) ); | 865 | viewMenu->insertItem( tr( "Thumbnails"), this, SLOT( updateShowThumbnails() ) ); |
866 | viewMenu->setItemChecked( viewMenu->idAt( 0 ), showHidden ); | 866 | viewMenu->setItemChecked( viewMenu->idAt( 0 ), showHidden ); |
867 | viewMenu->setItemChecked( viewMenu->idAt( 1 ), showSymlinks ); | 867 | viewMenu->setItemChecked( viewMenu->idAt( 1 ), showSymlinks ); |
868 | viewMenu->setItemChecked( viewMenu->idAt( 2 ), showThumbnails ); | 868 | viewMenu->setItemChecked( viewMenu->idAt( 2 ), showThumbnails ); |
869 | 869 | ||
870 | menuBar->insertItem( tr("View"), viewMenu ); | 870 | menuBar->insertItem( tr("View"), viewMenu ); |
871 | 871 | ||
872 | toolBar = new QPEToolBar( this ); | 872 | toolBar = new QToolBar( this ); |
873 | 873 | ||
874 | lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ), | 874 | lastAction = new QAction( tr("Previous dir"), Resource::loadIconSet( "back" ), |
875 | QString::null, 0, this, 0 ); | 875 | QString::null, 0, this, 0 ); |
876 | connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) ); | 876 | connect( lastAction, SIGNAL( activated() ), fileView, SLOT( lastDir() ) ); |
877 | lastAction->addTo( toolBar ); | 877 | lastAction->addTo( toolBar ); |
878 | lastAction->setEnabled( FALSE ); | 878 | lastAction->setEnabled( FALSE ); |
879 | 879 | ||
880 | upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ), | 880 | upAction = new QAction( tr("Parent dir"), Resource::loadIconSet( "up" ), |
881 | QString::null, 0, this, 0 ); | 881 | QString::null, 0, this, 0 ); |
882 | connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) ); | 882 | connect( upAction, SIGNAL( activated() ), fileView, SLOT( parentDir() ) ); |
883 | upAction->addTo( toolBar ); | 883 | upAction->addTo( toolBar ); |
884 | 884 | ||
885 | QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ), | 885 | QAction *a = new QAction( tr("New folder"), Resource::loadPixmap( "newfolder" ), |
886 | QString::null, 0, this, 0 ); | 886 | QString::null, 0, this, 0 ); |
887 | connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) ); | 887 | connect( a, SIGNAL( activated() ), fileView, SLOT( newFolder() ) ); |
888 | a->addTo( toolBar ); | 888 | a->addTo( toolBar ); |
889 | 889 | ||
890 | a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ), | 890 | a = new QAction( tr("Cut"), Resource::loadPixmap( "cut" ), |
891 | QString::null, 0, this, 0 ); | 891 | QString::null, 0, this, 0 ); |
892 | connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) ); | 892 | connect( a, SIGNAL( activated() ), fileView, SLOT( cut() ) ); |
893 | a->addTo( toolBar ); | 893 | a->addTo( toolBar ); |
894 | 894 | ||
895 | a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ), | 895 | a = new QAction( tr("Copy"), Resource::loadPixmap( "copy" ), |
896 | QString::null, 0, this, 0 ); | 896 | QString::null, 0, this, 0 ); |
897 | connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) ); | 897 | connect( a, SIGNAL( activated() ), fileView, SLOT( copy() ) ); |
898 | a->addTo( toolBar ); | 898 | a->addTo( toolBar ); |
899 | 899 | ||
900 | pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), | 900 | pasteAction = new QAction( tr("Paste"), Resource::loadPixmap( "paste" ), |
901 | QString::null, 0, this, 0 ); | 901 | QString::null, 0, this, 0 ); |
902 | connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) ); | 902 | connect( pasteAction, SIGNAL( activated() ), fileView, SLOT( paste() ) ); |
903 | pasteAction->addTo( toolBar ); | 903 | pasteAction->addTo( toolBar ); |
904 | 904 | ||
905 | // dirLabel = new QLabel(this, "DirLabel"); | 905 | // dirLabel = new QLabel(this, "DirLabel"); |
906 | 906 | ||
907 | connect( fileView, SIGNAL( dirChanged() ), SLOT( updateDirMenu() ) ); | 907 | connect( fileView, SIGNAL( dirChanged() ), SLOT( updateDirMenu() ) ); |
908 | updateDirMenu(); | 908 | updateDirMenu(); |
909 | 909 | ||
910 | QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); | 910 | QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); |
911 | connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), | 911 | connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), |
912 | this, SLOT(pcmciaMessage( const QCString &, const QByteArray &)) ); | 912 | this, SLOT(pcmciaMessage( const QCString &, const QByteArray &)) ); |
913 | } | 913 | } |
914 | 914 | ||
915 | void FileBrowser::pcmciaMessage( const QCString &msg, const QByteArray &) | 915 | void FileBrowser::pcmciaMessage( const QCString &msg, const QByteArray &) |
916 | { | 916 | { |
917 | if ( msg == "mtabChanged()" ) { | 917 | if ( msg == "mtabChanged()" ) { |
918 | // ## Only really needed if current dir is on a card | 918 | // ## Only really needed if current dir is on a card |
919 | fileView->updateDir(); | 919 | fileView->updateDir(); |
920 | } | 920 | } |
921 | } | 921 | } |
922 | 922 | ||
923 | void FileBrowser::changeCaption(const QString & dir) { | 923 | void FileBrowser::changeCaption(const QString & dir) { |
924 | setCaption( dir); | 924 | setCaption( dir); |
925 | } | 925 | } |
926 | 926 | ||
927 | void FileBrowser::dirSelected( int id ) | 927 | void FileBrowser::dirSelected( int id ) |
928 | { | 928 | { |
929 | int i = 0, j; | 929 | int i = 0, j; |
930 | QString dir; | 930 | QString dir; |
931 | 931 | ||
932 | // Bulid target dir from menu | 932 | // Bulid target dir from menu |
933 | while( (j = dirMenu->idAt( i )) != id ){ | 933 | while( (j = dirMenu->idAt( i )) != id ){ |
934 | dir += dirMenu->text( j ).stripWhiteSpace(); | 934 | dir += dirMenu->text( j ).stripWhiteSpace(); |
935 | if( dirMenu->text( j ) != "/" ) dir += "/"; | 935 | if( dirMenu->text( j ) != "/" ) dir += "/"; |
936 | i++; | 936 | i++; |
937 | } | 937 | } |
938 | dir += dirMenu->text( dirMenu->idAt( i ) ).stripWhiteSpace(); | 938 | dir += dirMenu->text( dirMenu->idAt( i ) ).stripWhiteSpace(); |
939 | 939 | ||
940 | fileView->setDir( dir ); | 940 | fileView->setDir( dir ); |
941 | } | 941 | } |
942 | 942 | ||
943 | void FileBrowser::updateDirMenu() | 943 | void FileBrowser::updateDirMenu() |
944 | { | 944 | { |
945 | QString spc, cd = fileView->cd(); | 945 | QString spc, cd = fileView->cd(); |
946 | QStringList l = QStringList::split( "/", cd ); | 946 | QStringList l = QStringList::split( "/", cd ); |
947 | int i = 0; | 947 | int i = 0; |
948 | 948 | ||
949 | dirMenu->clear(); | 949 | dirMenu->clear(); |
950 | dirMenu->insertItem( tr( "/" ), this, SLOT( dirSelected(int) ) ); | 950 | dirMenu->insertItem( tr( "/" ), this, SLOT( dirSelected(int) ) ); |
951 | 951 | ||
952 | for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { | 952 | for ( QStringList::Iterator it = l.begin(); it != l.end(); ++it ) { |
953 | spc.fill( ' ', i++); | 953 | spc.fill( ' ', i++); |
954 | dirMenu->insertItem( spc + (*it), this, | 954 | dirMenu->insertItem( spc + (*it), this, |
955 | SLOT( dirSelected(int) ) ); | 955 | SLOT( dirSelected(int) ) ); |
956 | } | 956 | } |
957 | dirMenu->setItemChecked( dirMenu->idAt( l.count() ), TRUE ); | 957 | dirMenu->setItemChecked( dirMenu->idAt( l.count() ), TRUE ); |
958 | 958 | ||
959 | lastAction->setEnabled( fileView->history().count() != 0 ); | 959 | lastAction->setEnabled( fileView->history().count() != 0 ); |
960 | upAction->setEnabled( cd != "/" ); | 960 | upAction->setEnabled( cd != "/" ); |
961 | } | 961 | } |
962 | 962 | ||
963 | void FileBrowser::sortName() | 963 | void FileBrowser::sortName() |
964 | { | 964 | { |
965 | fileView->setSorting( 0, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | 965 | fileView->setSorting( 0, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); |
966 | fileView->sort(); | 966 | fileView->sort(); |
967 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); | 967 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), TRUE ); |
968 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); | 968 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); |
969 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); | 969 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); |
970 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); | 970 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); |
971 | } | 971 | } |
972 | 972 | ||
973 | void FileBrowser::sortSize() | 973 | void FileBrowser::sortSize() |
974 | { | 974 | { |
975 | fileView->setSorting( 1, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | 975 | fileView->setSorting( 1, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); |
976 | fileView->sort(); | 976 | fileView->sort(); |
977 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); | 977 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); |
978 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), TRUE ); | 978 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), TRUE ); |
979 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); | 979 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); |
980 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); | 980 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); |
981 | } | 981 | } |
982 | 982 | ||
983 | void FileBrowser::sortDate() | 983 | void FileBrowser::sortDate() |
984 | { | 984 | { |
985 | fileView->setSorting( 2, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | 985 | fileView->setSorting( 2, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); |
986 | fileView->sort(); | 986 | fileView->sort(); |
987 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); | 987 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); |
988 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); | 988 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); |
989 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), TRUE ); | 989 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), TRUE ); |
990 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); | 990 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), FALSE ); |
991 | } | 991 | } |
992 | 992 | ||
993 | void FileBrowser::sortType() | 993 | void FileBrowser::sortType() |
994 | { | 994 | { |
995 | fileView->setSorting( 3, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | 995 | fileView->setSorting( 3, sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); |
996 | fileView->sort(); | 996 | fileView->sort(); |
997 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); | 997 | sortMenu->setItemChecked( sortMenu->idAt( 0 ), FALSE ); |
998 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); | 998 | sortMenu->setItemChecked( sortMenu->idAt( 1 ), FALSE ); |
999 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); | 999 | sortMenu->setItemChecked( sortMenu->idAt( 2 ), FALSE ); |
1000 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), TRUE ); | 1000 | sortMenu->setItemChecked( sortMenu->idAt( 3 ), TRUE ); |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | void FileBrowser::updateSorting() | 1003 | void FileBrowser::updateSorting() |
1004 | { | 1004 | { |
1005 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), !sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); | 1005 | sortMenu->setItemChecked( sortMenu->idAt( 5 ), !sortMenu->isItemChecked( sortMenu->idAt( 5 ) ) ); |
1006 | 1006 | ||
1007 | if ( sortMenu->isItemChecked( sortMenu->idAt( 0 ) ) ) | 1007 | if ( sortMenu->isItemChecked( sortMenu->idAt( 0 ) ) ) |
1008 | sortName(); | 1008 | sortName(); |
1009 | else if ( sortMenu->isItemChecked( sortMenu->idAt( 1 ) ) ) | 1009 | else if ( sortMenu->isItemChecked( sortMenu->idAt( 1 ) ) ) |
1010 | sortSize(); | 1010 | sortSize(); |
1011 | else if ( sortMenu->isItemChecked( sortMenu->idAt( 2 ) ) ) | 1011 | else if ( sortMenu->isItemChecked( sortMenu->idAt( 2 ) ) ) |
1012 | sortDate(); | 1012 | sortDate(); |
1013 | else | 1013 | else |
1014 | sortType(); | 1014 | sortType(); |
1015 | } | 1015 | } |
1016 | 1016 | ||
1017 | void FileView::chPerm() { | 1017 | void FileView::chPerm() { |
1018 | FileItem * i; | 1018 | FileItem * i; |
1019 | QStringList fl; | 1019 | QStringList fl; |
1020 | QString cmd; | 1020 | QString cmd; |
1021 | 1021 | ||
1022 | if((i = (FileItem *) firstChild()) == 0) return; | 1022 | if((i = (FileItem *) firstChild()) == 0) return; |
1023 | 1023 | ||
1024 | while( i ){ | 1024 | while( i ){ |
1025 | if( i->isSelected() ){ | 1025 | if( i->isSelected() ){ |
1026 | fl += i->getFilePath(); | 1026 | fl += i->getFilePath(); |
1027 | } | 1027 | } |
1028 | i = (FileItem *) i->nextSibling(); | 1028 | i = (FileItem *) i->nextSibling(); |
1029 | } | 1029 | } |
1030 | if( fl.count() < 1 ) return; | 1030 | if( fl.count() < 1 ) return; |
1031 | if( QMessageBox::warning( this, tr("Change permissions"), tr("Are you sure?"), | 1031 | if( QMessageBox::warning( this, tr("Change permissions"), tr("Are you sure?"), |
1032 | tr("Yes"), tr("No") ) == 0) { | 1032 | tr("Yes"), tr("No") ) == 0) { |
1033 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { | 1033 | for ( QStringList::Iterator it = fl.begin(); it != fl.end(); ++it ) { |
1034 | filePermissions *filePerm; | 1034 | filePermissions *filePerm; |
1035 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(*it)); | 1035 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(*it)); |
1036 | filePerm->exec(); | 1036 | filePerm->exec(); |
1037 | if( filePerm) | 1037 | if( filePerm) |
1038 | delete filePerm; | 1038 | delete filePerm; |
1039 | break; | 1039 | break; |
1040 | } | 1040 | } |
1041 | updateDir(); | 1041 | updateDir(); |
1042 | } | 1042 | } |
1043 | } | 1043 | } |
1044 | 1044 | ||
1045 | void FileBrowser::updateShowHidden() | 1045 | void FileBrowser::updateShowHidden() |
1046 | { | 1046 | { |
1047 | bool valShowHidden=viewMenu->isItemChecked( viewMenu->idAt( 0 ) ); | 1047 | bool valShowHidden=viewMenu->isItemChecked( viewMenu->idAt( 0 ) ); |
1048 | valShowHidden=!valShowHidden; | 1048 | valShowHidden=!valShowHidden; |
1049 | viewMenu->setItemChecked( viewMenu->idAt( 0 ), valShowHidden ); | 1049 | viewMenu->setItemChecked( viewMenu->idAt( 0 ), valShowHidden ); |
1050 | fileView->setShowHidden(valShowHidden); | 1050 | fileView->setShowHidden(valShowHidden); |
1051 | 1051 | ||
1052 | Config cfg("Filebrowser"); | 1052 | Config cfg("Filebrowser"); |
1053 | cfg.setGroup("View"); | 1053 | cfg.setGroup("View"); |
1054 | cfg.writeEntry("Hidden",valShowHidden?"TRUE":"FALSE"); | 1054 | cfg.writeEntry("Hidden",valShowHidden?"TRUE":"FALSE"); |
1055 | 1055 | ||
1056 | fileView->updateDir(); | 1056 | fileView->updateDir(); |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | void FileBrowser::updateShowSymlinks() | 1059 | void FileBrowser::updateShowSymlinks() |
1060 | { | 1060 | { |
1061 | bool valShowSymlinks=viewMenu->isItemChecked( viewMenu->idAt( 1 ) ); | 1061 | bool valShowSymlinks=viewMenu->isItemChecked( viewMenu->idAt( 1 ) ); |
1062 | valShowSymlinks=!valShowSymlinks; | 1062 | valShowSymlinks=!valShowSymlinks; |
1063 | viewMenu->setItemChecked( viewMenu->idAt( 1 ), valShowSymlinks ); | 1063 | viewMenu->setItemChecked( viewMenu->idAt( 1 ), valShowSymlinks ); |
1064 | fileView->setShowSymlinks(valShowSymlinks); | 1064 | fileView->setShowSymlinks(valShowSymlinks); |
1065 | 1065 | ||
1066 | Config cfg("Filebrowser"); | 1066 | Config cfg("Filebrowser"); |
1067 | cfg.setGroup("View"); | 1067 | cfg.setGroup("View"); |
1068 | cfg.writeEntry("Symlinks",valShowSymlinks?"TRUE":"FALSE"); | 1068 | cfg.writeEntry("Symlinks",valShowSymlinks?"TRUE":"FALSE"); |
1069 | 1069 | ||
1070 | fileView->updateDir(); | 1070 | fileView->updateDir(); |
1071 | } | 1071 | } |
1072 | 1072 | ||
1073 | void FileBrowser::updateShowThumbnails() | 1073 | void FileBrowser::updateShowThumbnails() |
1074 | { | 1074 | { |
1075 | bool valShowThumbnails=viewMenu->isItemChecked( viewMenu->idAt( 2 ) ); | 1075 | bool valShowThumbnails=viewMenu->isItemChecked( viewMenu->idAt( 2 ) ); |
1076 | valShowThumbnails=!valShowThumbnails; | 1076 | valShowThumbnails=!valShowThumbnails; |
1077 | viewMenu->setItemChecked( viewMenu->idAt( 2 ), valShowThumbnails ); | 1077 | viewMenu->setItemChecked( viewMenu->idAt( 2 ), valShowThumbnails ); |
1078 | fileView->setShowThumbnails(valShowThumbnails); | 1078 | fileView->setShowThumbnails(valShowThumbnails); |
1079 | 1079 | ||
1080 | Config cfg("Filebrowser"); | 1080 | Config cfg("Filebrowser"); |
1081 | cfg.setGroup("View"); | 1081 | cfg.setGroup("View"); |
1082 | cfg.writeEntry("Thumbnails",valShowThumbnails?"TRUE":"FALSE"); | 1082 | cfg.writeEntry("Thumbnails",valShowThumbnails?"TRUE":"FALSE"); |
1083 | 1083 | ||
1084 | fileView->updateDir(); | 1084 | fileView->updateDir(); |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | void FileBrowser::cleanUp() { | 1087 | void FileBrowser::cleanUp() { |
1088 | QString cmdr = "rm -rf /tmp/filebrowserThumbnailCache"; | 1088 | QString cmdr = "rm -rf /tmp/filebrowserThumbnailCache"; |
1089 | // qDebug("exit"); | 1089 | // qDebug("exit"); |
1090 | system(cmdr.latin1()); | 1090 | system(cmdr.latin1()); |
1091 | } | 1091 | } |
diff --git a/noncore/unsupported/mail2/composerbase.cpp b/noncore/unsupported/mail2/composerbase.cpp index 34d6eb6..94de15c 100644 --- a/noncore/unsupported/mail2/composerbase.cpp +++ b/noncore/unsupported/mail2/composerbase.cpp | |||
@@ -1,205 +1,205 @@ | |||
1 | #include <qmultilineedit.h> | 1 | #include <qmultilineedit.h> |
2 | #include <qpopupmenu.h> | 2 | #include <qpopupmenu.h> |
3 | #include <qcombobox.h> | 3 | #include <qcombobox.h> |
4 | #include <qlineedit.h> | 4 | #include <qlineedit.h> |
5 | #include <qlayout.h> | 5 | #include <qlayout.h> |
6 | #include <qaction.h> | 6 | #include <qaction.h> |
7 | #include <qlabel.h> | 7 | #include <qlabel.h> |
8 | #include <qvbox.h> | 8 | #include <qvbox.h> |
9 | 9 | ||
10 | #include <qpe/qpetoolbar.h> | 10 | #include <qpe/qpetoolbar.h> |
11 | #include <qpe/qpemenubar.h> | 11 | #include <qmenubar.h> |
12 | #include <qpe/resource.h> | 12 | #include <qpe/resource.h> |
13 | 13 | ||
14 | #include "mailstatusbar.h" | 14 | #include "mailstatusbar.h" |
15 | #include "listviewplus.h" | 15 | #include "listviewplus.h" |
16 | #include "composerbase.h" | 16 | #include "composerbase.h" |
17 | 17 | ||
18 | ComposerBase::ComposerBase(QWidget *parent, const char *name, WFlags fl) | 18 | ComposerBase::ComposerBase(QWidget *parent, const char *name, WFlags fl) |
19 | : QMainWindow(parent, name, fl) | 19 | : QMainWindow(parent, name, fl) |
20 | { | 20 | { |
21 | setCaption(tr("Compose Message")); | 21 | setCaption(tr("Compose Message")); |
22 | setToolBarsMovable(false); | 22 | setToolBarsMovable(false); |
23 | 23 | ||
24 | toolbar = new QPEToolBar(this); | 24 | toolbar = new QToolBar(this); |
25 | menubar = new QMenuBar( toolbar ); | 25 | menubar = new QMenuBar( toolbar ); |
26 | mailmenu = new QPopupMenu( menubar ); | 26 | mailmenu = new QPopupMenu( menubar ); |
27 | menubar->insertItem( tr( "Mail" ), mailmenu ); | 27 | menubar->insertItem( tr( "Mail" ), mailmenu ); |
28 | addToolBar(toolbar); | 28 | addToolBar(toolbar); |
29 | toolbar->setHorizontalStretchable(true); | 29 | toolbar->setHorizontalStretchable(true); |
30 | 30 | ||
31 | QLabel *spacer = new QLabel(toolbar); | 31 | QLabel *spacer = new QLabel(toolbar); |
32 | spacer->setBackgroundMode(QWidget::PaletteButton); | 32 | spacer->setBackgroundMode(QWidget::PaletteButton); |
33 | toolbar->setStretchableWidget(spacer); | 33 | toolbar->setStretchableWidget(spacer); |
34 | 34 | ||
35 | sendmail = new QAction(tr("Send the mail"), QIconSet(Resource::loadPixmap("mail/sendmail")), 0, 0, this); | 35 | sendmail = new QAction(tr("Send the mail"), QIconSet(Resource::loadPixmap("mail/sendmail")), 0, 0, this); |
36 | sendmail->addTo(toolbar); | 36 | sendmail->addTo(toolbar); |
37 | sendmail->addTo(mailmenu); | 37 | sendmail->addTo(mailmenu); |
38 | 38 | ||
39 | queuemail = new QAction(tr("Queue the mail"), QIconSet(Resource::loadPixmap("mail/sendall")), 0, 0, this); | 39 | queuemail = new QAction(tr("Queue the mail"), QIconSet(Resource::loadPixmap("mail/sendall")), 0, 0, this); |
40 | queuemail->addTo(toolbar); | 40 | queuemail->addTo(toolbar); |
41 | queuemail->addTo(mailmenu); | 41 | queuemail->addTo(mailmenu); |
42 | 42 | ||
43 | attachfile = new QAction(tr("Attach a file"), QIconSet(Resource::loadPixmap("mail/attach")), 0, 0, this, 0, true); | 43 | attachfile = new QAction(tr("Attach a file"), QIconSet(Resource::loadPixmap("mail/attach")), 0, 0, this, 0, true); |
44 | attachfile->addTo(toolbar); | 44 | attachfile->addTo(toolbar); |
45 | attachfile->addTo(mailmenu); | 45 | attachfile->addTo(mailmenu); |
46 | connect(attachfile, SIGNAL(toggled(bool)), SLOT(slotAttachfileChanged(bool))); | 46 | connect(attachfile, SIGNAL(toggled(bool)), SLOT(slotAttachfileChanged(bool))); |
47 | 47 | ||
48 | addressbook = new QAction(tr("Addressbook"), QIconSet(Resource::loadPixmap("mail/addbook")), 0, 0, this); | 48 | addressbook = new QAction(tr("Addressbook"), QIconSet(Resource::loadPixmap("mail/addbook")), 0, 0, this); |
49 | addressbook->addTo(toolbar); | 49 | addressbook->addTo(toolbar); |
50 | addressbook->addTo(mailmenu); | 50 | addressbook->addTo(mailmenu); |
51 | 51 | ||
52 | QWidget *main = new QWidget(this); | 52 | QWidget *main = new QWidget(this); |
53 | setCentralWidget(main); | 53 | setCentralWidget(main); |
54 | 54 | ||
55 | QGridLayout *layout = new QGridLayout(main); | 55 | QGridLayout *layout = new QGridLayout(main); |
56 | 56 | ||
57 | fromBox = new QComboBox(main); | 57 | fromBox = new QComboBox(main); |
58 | fromBox->insertItem(tr("From"), POPUP_FROM_FROM); | 58 | fromBox->insertItem(tr("From"), POPUP_FROM_FROM); |
59 | fromBox->insertItem(tr("Reply"), POPUP_FROM_REPLYTO); | 59 | fromBox->insertItem(tr("Reply"), POPUP_FROM_REPLYTO); |
60 | layout->addWidget(fromBox, 0, 0); | 60 | layout->addWidget(fromBox, 0, 0); |
61 | 61 | ||
62 | connect(fromBox, SIGNAL(activated(int)), SLOT(slotFromMenuChanged(int))); | 62 | connect(fromBox, SIGNAL(activated(int)), SLOT(slotFromMenuChanged(int))); |
63 | 63 | ||
64 | QHBoxLayout *fromLayout = new QHBoxLayout(); | 64 | QHBoxLayout *fromLayout = new QHBoxLayout(); |
65 | layout->addLayout(fromLayout, 0, 1); | 65 | layout->addLayout(fromLayout, 0, 1); |
66 | 66 | ||
67 | from = new QComboBox(main); | 67 | from = new QComboBox(main); |
68 | fromLayout->addWidget(from); | 68 | fromLayout->addWidget(from); |
69 | 69 | ||
70 | replyto = new QLineEdit(main); | 70 | replyto = new QLineEdit(main); |
71 | replyto->hide(); | 71 | replyto->hide(); |
72 | fromLayout->addWidget(replyto); | 72 | fromLayout->addWidget(replyto); |
73 | 73 | ||
74 | receiversBox = new QComboBox(main); | 74 | receiversBox = new QComboBox(main); |
75 | receiversBox->insertItem(tr("To"), POPUP_RECV_TO); | 75 | receiversBox->insertItem(tr("To"), POPUP_RECV_TO); |
76 | receiversBox->insertItem(tr("Cc"), POPUP_RECV_CC); | 76 | receiversBox->insertItem(tr("Cc"), POPUP_RECV_CC); |
77 | receiversBox->insertItem(tr("Bcc"), POPUP_RECV_BCC); | 77 | receiversBox->insertItem(tr("Bcc"), POPUP_RECV_BCC); |
78 | layout->addWidget(receiversBox, 1, 0); | 78 | layout->addWidget(receiversBox, 1, 0); |
79 | 79 | ||
80 | connect(receiversBox, SIGNAL(activated(int)), SLOT(slotReceiverMenuChanged(int))); | 80 | connect(receiversBox, SIGNAL(activated(int)), SLOT(slotReceiverMenuChanged(int))); |
81 | 81 | ||
82 | QHBoxLayout *receiverLayout = new QHBoxLayout(); | 82 | QHBoxLayout *receiverLayout = new QHBoxLayout(); |
83 | layout->addLayout(receiverLayout, 1, 1); | 83 | layout->addLayout(receiverLayout, 1, 1); |
84 | 84 | ||
85 | to = new QLineEdit(main); | 85 | to = new QLineEdit(main); |
86 | receiverLayout->addWidget(to); | 86 | receiverLayout->addWidget(to); |
87 | 87 | ||
88 | cc = new QLineEdit(main); | 88 | cc = new QLineEdit(main); |
89 | cc->hide(); | 89 | cc->hide(); |
90 | receiverLayout->addWidget(cc); | 90 | receiverLayout->addWidget(cc); |
91 | 91 | ||
92 | bcc = new QLineEdit(main); | 92 | bcc = new QLineEdit(main); |
93 | bcc->hide(); | 93 | bcc->hide(); |
94 | receiverLayout->addWidget(bcc); | 94 | receiverLayout->addWidget(bcc); |
95 | 95 | ||
96 | subjectBox = new QComboBox(main); | 96 | subjectBox = new QComboBox(main); |
97 | subjectBox->insertItem(tr("Subj."), POPUP_SUBJ_SUBJECT); | 97 | subjectBox->insertItem(tr("Subj."), POPUP_SUBJ_SUBJECT); |
98 | subjectBox->insertItem(tr("Prio."), POPUP_SUBJ_PRIORITY); | 98 | subjectBox->insertItem(tr("Prio."), POPUP_SUBJ_PRIORITY); |
99 | layout->addWidget(subjectBox, 2, 0); | 99 | layout->addWidget(subjectBox, 2, 0); |
100 | connect(subjectBox, SIGNAL(activated(int)), SLOT(slotSubjectMenuChanged(int))); | 100 | connect(subjectBox, SIGNAL(activated(int)), SLOT(slotSubjectMenuChanged(int))); |
101 | 101 | ||
102 | QHBoxLayout *subjectLayout = new QHBoxLayout(); | 102 | QHBoxLayout *subjectLayout = new QHBoxLayout(); |
103 | layout->addLayout(subjectLayout, 2, 1); | 103 | layout->addLayout(subjectLayout, 2, 1); |
104 | 104 | ||
105 | subject = new QLineEdit(main); | 105 | subject = new QLineEdit(main); |
106 | subjectLayout->addWidget(subject); | 106 | subjectLayout->addWidget(subject); |
107 | 107 | ||
108 | priority = new QComboBox(main); | 108 | priority = new QComboBox(main); |
109 | priority->insertItem(tr("Low"), POPUP_PRIO_LOW); | 109 | priority->insertItem(tr("Low"), POPUP_PRIO_LOW); |
110 | priority->insertItem(tr("Normal"), POPUP_PRIO_NORMAL); | 110 | priority->insertItem(tr("Normal"), POPUP_PRIO_NORMAL); |
111 | priority->insertItem(tr("High"), POPUP_PRIO_HIGH); | 111 | priority->insertItem(tr("High"), POPUP_PRIO_HIGH); |
112 | priority->setCurrentItem(POPUP_PRIO_NORMAL); | 112 | priority->setCurrentItem(POPUP_PRIO_NORMAL); |
113 | priority->hide(); | 113 | priority->hide(); |
114 | subjectLayout->addWidget(priority); | 114 | subjectLayout->addWidget(priority); |
115 | 115 | ||
116 | QVBox *view = new QVBox(main); | 116 | QVBox *view = new QVBox(main); |
117 | layout->addMultiCellWidget(view, 3, 3, 0, 1); | 117 | layout->addMultiCellWidget(view, 3, 3, 0, 1); |
118 | 118 | ||
119 | message = new QMultiLineEdit(view); | 119 | message = new QMultiLineEdit(view); |
120 | message->setMinimumHeight(30); | 120 | message->setMinimumHeight(30); |
121 | 121 | ||
122 | attachWindow = new QMainWindow(view, 0, 0); | 122 | attachWindow = new QMainWindow(view, 0, 0); |
123 | attachWindow->setMinimumHeight(80); | 123 | attachWindow->setMinimumHeight(80); |
124 | attachWindow->setMaximumHeight(80); | 124 | attachWindow->setMaximumHeight(80); |
125 | attachWindow->setToolBarsMovable(false); | 125 | attachWindow->setToolBarsMovable(false); |
126 | attachWindow->hide(); | 126 | attachWindow->hide(); |
127 | 127 | ||
128 | attachToolbar = new QPEToolBar(attachWindow); | 128 | attachToolbar = new QToolBar(attachWindow); |
129 | attachToolbar->setVerticalStretchable(true); | 129 | attachToolbar->setVerticalStretchable(true); |
130 | 130 | ||
131 | addattach = new QAction(tr("Add an Attachement"), QIconSet(Resource::loadPixmap("mail/newmail")), 0, 0, this); | 131 | addattach = new QAction(tr("Add an Attachement"), QIconSet(Resource::loadPixmap("mail/newmail")), 0, 0, this); |
132 | addattach->addTo(attachToolbar); | 132 | addattach->addTo(attachToolbar); |
133 | 133 | ||
134 | delattach = new QAction(tr("Remove Attachement"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this); | 134 | delattach = new QAction(tr("Remove Attachement"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this); |
135 | delattach->addTo(attachToolbar); | 135 | delattach->addTo(attachToolbar); |
136 | 136 | ||
137 | QLabel *attachSpacer = new QLabel(attachToolbar); | 137 | QLabel *attachSpacer = new QLabel(attachToolbar); |
138 | attachSpacer->setBackgroundMode(QWidget::PaletteButton); | 138 | attachSpacer->setBackgroundMode(QWidget::PaletteButton); |
139 | attachToolbar->setStretchableWidget(attachSpacer); | 139 | attachToolbar->setStretchableWidget(attachSpacer); |
140 | 140 | ||
141 | attachWindow->addToolBar(attachToolbar, QMainWindow::Left); | 141 | attachWindow->addToolBar(attachToolbar, QMainWindow::Left); |
142 | 142 | ||
143 | attachView = new ListViewPlus(attachWindow); | 143 | attachView = new ListViewPlus(attachWindow); |
144 | attachView->addColumn(tr("Name"), 80); | 144 | attachView->addColumn(tr("Name"), 80); |
145 | attachView->addColumn(tr("Description"), 110); | 145 | attachView->addColumn(tr("Description"), 110); |
146 | attachView->setAllColumnsShowFocus(true); | 146 | attachView->setAllColumnsShowFocus(true); |
147 | attachWindow->setCentralWidget(attachView); | 147 | attachWindow->setCentralWidget(attachView); |
148 | 148 | ||
149 | attachPopup = new QPopupMenu(attachView); | 149 | attachPopup = new QPopupMenu(attachView); |
150 | attachPopup->insertItem(tr("Rename"), POPUP_ATTACH_RENAME); | 150 | attachPopup->insertItem(tr("Rename"), POPUP_ATTACH_RENAME); |
151 | attachPopup->insertItem(tr("Change Description"), POPUP_ATTACH_DESC); | 151 | attachPopup->insertItem(tr("Change Description"), POPUP_ATTACH_DESC); |
152 | attachPopup->insertSeparator(); | 152 | attachPopup->insertSeparator(); |
153 | attachPopup->insertItem(tr("Remove"), POPUP_ATTACH_REMOVE); | 153 | attachPopup->insertItem(tr("Remove"), POPUP_ATTACH_REMOVE); |
154 | attachView->setPopup(attachPopup); | 154 | attachView->setPopup(attachPopup); |
155 | 155 | ||
156 | status = new MailStatusBar(view); | 156 | status = new MailStatusBar(view); |
157 | } | 157 | } |
158 | 158 | ||
159 | void ComposerBase::slotAttachfileChanged(bool toggled) | 159 | void ComposerBase::slotAttachfileChanged(bool toggled) |
160 | { | 160 | { |
161 | if (toggled) { | 161 | if (toggled) { |
162 | if (attachWindow->isHidden()) attachWindow->show(); | 162 | if (attachWindow->isHidden()) attachWindow->show(); |
163 | } else { | 163 | } else { |
164 | if (!attachWindow->isHidden()) attachWindow->hide(); | 164 | if (!attachWindow->isHidden()) attachWindow->hide(); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | 167 | ||
168 | void ComposerBase::slotFromMenuChanged(int id) | 168 | void ComposerBase::slotFromMenuChanged(int id) |
169 | { | 169 | { |
170 | if (POPUP_FROM_FROM == id) { | 170 | if (POPUP_FROM_FROM == id) { |
171 | if (from->isHidden()) from->show(); | 171 | if (from->isHidden()) from->show(); |
172 | if (!replyto->isHidden()) replyto->hide(); | 172 | if (!replyto->isHidden()) replyto->hide(); |
173 | } else if (POPUP_FROM_REPLYTO == id) { | 173 | } else if (POPUP_FROM_REPLYTO == id) { |
174 | if (!from->isHidden()) from->hide(); | 174 | if (!from->isHidden()) from->hide(); |
175 | if (replyto->isHidden()) replyto->show(); | 175 | if (replyto->isHidden()) replyto->show(); |
176 | } | 176 | } |
177 | } | 177 | } |
178 | 178 | ||
179 | void ComposerBase::slotReceiverMenuChanged(int id) | 179 | void ComposerBase::slotReceiverMenuChanged(int id) |
180 | { | 180 | { |
181 | if (POPUP_RECV_TO == id) { | 181 | if (POPUP_RECV_TO == id) { |
182 | if (to->isHidden()) to->show(); | 182 | if (to->isHidden()) to->show(); |
183 | if (!cc->isHidden()) cc->hide(); | 183 | if (!cc->isHidden()) cc->hide(); |
184 | if (!bcc->isHidden()) bcc->hide(); | 184 | if (!bcc->isHidden()) bcc->hide(); |
185 | } else if (POPUP_RECV_CC == id) { | 185 | } else if (POPUP_RECV_CC == id) { |
186 | if (!to->isHidden()) to->hide(); | 186 | if (!to->isHidden()) to->hide(); |
187 | if (cc->isHidden()) cc->show(); | 187 | if (cc->isHidden()) cc->show(); |
188 | if (!bcc->isHidden()) bcc->hide(); | 188 | if (!bcc->isHidden()) bcc->hide(); |
189 | } else if (POPUP_RECV_BCC == id) { | 189 | } else if (POPUP_RECV_BCC == id) { |
190 | if (!to->isHidden()) to->hide(); | 190 | if (!to->isHidden()) to->hide(); |
191 | if (!cc->isHidden()) cc->hide(); | 191 | if (!cc->isHidden()) cc->hide(); |
192 | if (bcc->isHidden()) bcc->show(); | 192 | if (bcc->isHidden()) bcc->show(); |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | void ComposerBase::slotSubjectMenuChanged(int id) | 196 | void ComposerBase::slotSubjectMenuChanged(int id) |
197 | { | 197 | { |
198 | if (POPUP_SUBJ_SUBJECT == id) { | 198 | if (POPUP_SUBJ_SUBJECT == id) { |
199 | if (subject->isHidden()) subject->show(); | 199 | if (subject->isHidden()) subject->show(); |
200 | if (!priority->isHidden()) priority->hide(); | 200 | if (!priority->isHidden()) priority->hide(); |
201 | } else if (POPUP_SUBJ_PRIORITY == id) { | 201 | } else if (POPUP_SUBJ_PRIORITY == id) { |
202 | if (!subject->isHidden()) subject->hide(); | 202 | if (!subject->isHidden()) subject->hide(); |
203 | if (priority->isHidden()) priority->show(); | 203 | if (priority->isHidden()) priority->show(); |
204 | } | 204 | } |
205 | } | 205 | } |
diff --git a/noncore/unsupported/mail2/composerbase.h b/noncore/unsupported/mail2/composerbase.h index 2c832d6..c14144b 100644 --- a/noncore/unsupported/mail2/composerbase.h +++ b/noncore/unsupported/mail2/composerbase.h | |||
@@ -1,61 +1,61 @@ | |||
1 | #ifndef COMPOSERBASE_H | 1 | #ifndef COMPOSERBASE_H |
2 | #define COMPOSERBASE_H | 2 | #define COMPOSERBASE_H |
3 | 3 | ||
4 | #include <qmainwindow.h> | 4 | #include <qmainwindow.h> |
5 | 5 | ||
6 | class QMultiLineEdit; | 6 | class QMultiLineEdit; |
7 | class MailStatusBar; | 7 | class MailStatusBar; |
8 | class ListViewPlus; | 8 | class ListViewPlus; |
9 | class QPopupMenu; | 9 | class QPopupMenu; |
10 | class QPEToolBar; | 10 | class QToolBar; |
11 | class QMenuBar; | 11 | class QMenuBar; |
12 | class QPopupMenu; | 12 | class QPopupMenu; |
13 | class QComboBox; | 13 | class QComboBox; |
14 | class QLineEdit; | 14 | class QLineEdit; |
15 | class QAction; | 15 | class QAction; |
16 | class QLabel; | 16 | class QLabel; |
17 | 17 | ||
18 | class ComposerBase : public QMainWindow | 18 | class ComposerBase : public QMainWindow |
19 | { | 19 | { |
20 | Q_OBJECT | 20 | Q_OBJECT |
21 | 21 | ||
22 | public: | 22 | public: |
23 | ComposerBase(QWidget *parent = 0, const char *name = 0, WFlags fl = 0); | 23 | ComposerBase(QWidget *parent = 0, const char *name = 0, WFlags fl = 0); |
24 | 24 | ||
25 | protected: | 25 | protected: |
26 | static const int POPUP_FROM_FROM = 0; | 26 | static const int POPUP_FROM_FROM = 0; |
27 | static const int POPUP_FROM_REPLYTO = 1; | 27 | static const int POPUP_FROM_REPLYTO = 1; |
28 | static const int POPUP_RECV_TO = 0; | 28 | static const int POPUP_RECV_TO = 0; |
29 | static const int POPUP_RECV_CC = 1; | 29 | static const int POPUP_RECV_CC = 1; |
30 | static const int POPUP_RECV_BCC = 2; | 30 | static const int POPUP_RECV_BCC = 2; |
31 | static const int POPUP_SUBJ_SUBJECT = 0; | 31 | static const int POPUP_SUBJ_SUBJECT = 0; |
32 | static const int POPUP_SUBJ_PRIORITY = 1; | 32 | static const int POPUP_SUBJ_PRIORITY = 1; |
33 | static const int POPUP_PRIO_LOW = 0; | 33 | static const int POPUP_PRIO_LOW = 0; |
34 | static const int POPUP_PRIO_NORMAL = 1; | 34 | static const int POPUP_PRIO_NORMAL = 1; |
35 | static const int POPUP_PRIO_HIGH = 2; | 35 | static const int POPUP_PRIO_HIGH = 2; |
36 | static const int POPUP_ATTACH_RENAME = 0; | 36 | static const int POPUP_ATTACH_RENAME = 0; |
37 | static const int POPUP_ATTACH_DESC = 1; | 37 | static const int POPUP_ATTACH_DESC = 1; |
38 | static const int POPUP_ATTACH_REMOVE = 2; | 38 | static const int POPUP_ATTACH_REMOVE = 2; |
39 | 39 | ||
40 | QMultiLineEdit *message; | 40 | QMultiLineEdit *message; |
41 | MailStatusBar *status; | 41 | MailStatusBar *status; |
42 | ListViewPlus *attachView; | 42 | ListViewPlus *attachView; |
43 | QMainWindow *attachWindow; | 43 | QMainWindow *attachWindow; |
44 | QPopupMenu *attachPopup; | 44 | QPopupMenu *attachPopup; |
45 | QPEToolBar *toolbar, *attachToolbar; | 45 | QToolBar *toolbar, *attachToolbar; |
46 | QMenuBar *menubar; | 46 | QMenuBar *menubar; |
47 | QPopupMenu *mailmenu; | 47 | QPopupMenu *mailmenu; |
48 | QComboBox *fromBox, *from, *receiversBox, *subjectBox, *priority; | 48 | QComboBox *fromBox, *from, *receiversBox, *subjectBox, *priority; |
49 | QLineEdit *replyto, *to, *cc, *bcc, *subject; | 49 | QLineEdit *replyto, *to, *cc, *bcc, *subject; |
50 | QAction *sendmail, *queuemail, *attachfile, *addressbook, *abort, *addattach, *delattach; | 50 | QAction *sendmail, *queuemail, *attachfile, *addressbook, *abort, *addattach, *delattach; |
51 | QLabel *fromLabel; | 51 | QLabel *fromLabel; |
52 | 52 | ||
53 | protected slots: | 53 | protected slots: |
54 | void slotAttachfileChanged(bool toggled); | 54 | void slotAttachfileChanged(bool toggled); |
55 | void slotFromMenuChanged(int id); | 55 | void slotFromMenuChanged(int id); |
56 | void slotReceiverMenuChanged(int id); | 56 | void slotReceiverMenuChanged(int id); |
57 | void slotSubjectMenuChanged(int id); | 57 | void slotSubjectMenuChanged(int id); |
58 | 58 | ||
59 | }; | 59 | }; |
60 | 60 | ||
61 | #endif | 61 | #endif |
diff --git a/noncore/unsupported/mail2/mainwindowbase.cpp b/noncore/unsupported/mail2/mainwindowbase.cpp index 119acfb..4e804c2 100644 --- a/noncore/unsupported/mail2/mainwindowbase.cpp +++ b/noncore/unsupported/mail2/mainwindowbase.cpp | |||
@@ -1,75 +1,75 @@ | |||
1 | #include <qpopupmenu.h> | 1 | #include <qpopupmenu.h> |
2 | #include <qaction.h> | 2 | #include <qaction.h> |
3 | #include <qheader.h> | 3 | #include <qheader.h> |
4 | #include <qlabel.h> | 4 | #include <qlabel.h> |
5 | #include <qvbox.h> | 5 | #include <qvbox.h> |
6 | 6 | ||
7 | #include <qpe/qpetoolbar.h> | 7 | #include <qpe/qpetoolbar.h> |
8 | #include <qpe/qpemenubar.h> | 8 | #include <qmenubar.h> |
9 | #include <qpe/resource.h> | 9 | #include <qpe/resource.h> |
10 | 10 | ||
11 | #include "mainwindowbase.h" | 11 | #include "mainwindowbase.h" |
12 | #include "mailstatusbar.h" | 12 | #include "mailstatusbar.h" |
13 | #include "folderwidget.h" | 13 | #include "folderwidget.h" |
14 | #include "mailtable.h" | 14 | #include "mailtable.h" |
15 | 15 | ||
16 | MainWindowBase::MainWindowBase(QWidget *parent, const char *name, WFlags fl) | 16 | MainWindowBase::MainWindowBase(QWidget *parent, const char *name, WFlags fl) |
17 | : QMainWindow(parent, name, fl) | 17 | : QMainWindow(parent, name, fl) |
18 | { | 18 | { |
19 | setCaption(tr("E-Mail")); | 19 | setCaption(tr("E-Mail")); |
20 | setToolBarsMovable(false); | 20 | setToolBarsMovable(false); |
21 | 21 | ||
22 | toolbar = new QPEToolBar(this); | 22 | toolbar = new QToolBar(this); |
23 | menubar = new QMenuBar( toolbar ); | 23 | menubar = new QMenuBar( toolbar ); |
24 | mailmenu = new QPopupMenu( menubar ); | 24 | mailmenu = new QPopupMenu( menubar ); |
25 | servermenu = new QPopupMenu( menubar ); | 25 | servermenu = new QPopupMenu( menubar ); |
26 | menubar->insertItem( tr( "Mail" ), mailmenu ); | 26 | menubar->insertItem( tr( "Mail" ), mailmenu ); |
27 | menubar->insertItem( tr( "Servers" ), servermenu ); | 27 | menubar->insertItem( tr( "Servers" ), servermenu ); |
28 | 28 | ||
29 | addToolBar(toolbar); | 29 | addToolBar(toolbar); |
30 | toolbar->setHorizontalStretchable(true); | 30 | toolbar->setHorizontalStretchable(true); |
31 | 31 | ||
32 | QLabel *spacer = new QLabel(toolbar); | 32 | QLabel *spacer = new QLabel(toolbar); |
33 | spacer->setBackgroundMode(QWidget::PaletteButton); | 33 | spacer->setBackgroundMode(QWidget::PaletteButton); |
34 | toolbar->setStretchableWidget(spacer); | 34 | toolbar->setStretchableWidget(spacer); |
35 | 35 | ||
36 | compose = new QAction(tr("Compose new mail"), QIconSet(Resource::loadPixmap("mail/newmail")), 0, 0, this); | 36 | compose = new QAction(tr("Compose new mail"), QIconSet(Resource::loadPixmap("mail/newmail")), 0, 0, this); |
37 | compose->addTo(toolbar); | 37 | compose->addTo(toolbar); |
38 | compose->addTo(mailmenu); | 38 | compose->addTo(mailmenu); |
39 | 39 | ||
40 | sendQueue = new QAction(tr("Send queued mails"), QIconSet(Resource::loadPixmap("mail/sendqueue")), 0, 0, this); | 40 | sendQueue = new QAction(tr("Send queued mails"), QIconSet(Resource::loadPixmap("mail/sendqueue")), 0, 0, this); |
41 | sendQueue->addTo(toolbar); | 41 | sendQueue->addTo(toolbar); |
42 | sendQueue->addTo(mailmenu); | 42 | sendQueue->addTo(mailmenu); |
43 | 43 | ||
44 | folders = new QAction(tr("Show/hide folders"), QIconSet(Resource::loadPixmap("mail/folder")), 0, 0, this, 0, true); | 44 | folders = new QAction(tr("Show/hide folders"), QIconSet(Resource::loadPixmap("mail/folder")), 0, 0, this, 0, true); |
45 | folders->addTo(toolbar); | 45 | folders->addTo(toolbar); |
46 | folders->addTo(servermenu); | 46 | folders->addTo(servermenu); |
47 | connect(folders, SIGNAL(toggled(bool)), SLOT(slotFoldersToggled(bool))); | 47 | connect(folders, SIGNAL(toggled(bool)), SLOT(slotFoldersToggled(bool))); |
48 | 48 | ||
49 | findmails = new QAction(tr("Search mails"), QIconSet(Resource::loadPixmap("mail/find")), 0, 0, this); | 49 | findmails = new QAction(tr("Search mails"), QIconSet(Resource::loadPixmap("mail/find")), 0, 0, this); |
50 | findmails->addTo(toolbar); | 50 | findmails->addTo(toolbar); |
51 | findmails->addTo(mailmenu); | 51 | findmails->addTo(mailmenu); |
52 | 52 | ||
53 | configure = new QAction(tr("Configuration"), QIconSet(Resource::loadPixmap("mail/configure")), 0, 0, this); | 53 | configure = new QAction(tr("Configuration"), QIconSet(Resource::loadPixmap("mail/configure")), 0, 0, this); |
54 | configure->addTo(servermenu); | 54 | configure->addTo(servermenu); |
55 | 55 | ||
56 | QVBox *view = new QVBox(this); | 56 | QVBox *view = new QVBox(this); |
57 | setCentralWidget(view); | 57 | setCentralWidget(view); |
58 | 58 | ||
59 | folderView = new FolderWidget(view); | 59 | folderView = new FolderWidget(view); |
60 | folderView->setMinimumHeight(90); | 60 | folderView->setMinimumHeight(90); |
61 | folderView->setMaximumHeight(90); | 61 | folderView->setMaximumHeight(90); |
62 | folderView->hide(); | 62 | folderView->hide(); |
63 | 63 | ||
64 | mailView = new MailTable(view); | 64 | mailView = new MailTable(view); |
65 | mailView->setMinimumHeight(50); | 65 | mailView->setMinimumHeight(50); |
66 | 66 | ||
67 | status = new MailStatusBar(view); | 67 | status = new MailStatusBar(view); |
68 | } | 68 | } |
69 | 69 | ||
70 | void MainWindowBase::slotFoldersToggled(bool toggled) | 70 | void MainWindowBase::slotFoldersToggled(bool toggled) |
71 | { | 71 | { |
72 | if (folderView->isHidden() && toggled) folderView->show(); | 72 | if (folderView->isHidden() && toggled) folderView->show(); |
73 | if (!folderView->isHidden() && !toggled) folderView->hide(); | 73 | if (!folderView->isHidden() && !toggled) folderView->hide(); |
74 | } | 74 | } |
75 | 75 | ||
diff --git a/noncore/unsupported/mail2/mainwindowbase.h b/noncore/unsupported/mail2/mainwindowbase.h index b2e1dc5..c1d6371 100644 --- a/noncore/unsupported/mail2/mainwindowbase.h +++ b/noncore/unsupported/mail2/mainwindowbase.h | |||
@@ -1,37 +1,37 @@ | |||
1 | #ifndef MAINWINDOWBASE_H | 1 | #ifndef MAINWINDOWBASE_H |
2 | #define MAINWINDOWBASE_H | 2 | #define MAINWINDOWBASE_H |
3 | 3 | ||
4 | #include <qmainwindow.h> | 4 | #include <qmainwindow.h> |
5 | 5 | ||
6 | class ServerConnection; | 6 | class ServerConnection; |
7 | class MailStatusBar; | 7 | class MailStatusBar; |
8 | class FolderWidget; | 8 | class FolderWidget; |
9 | class QPEToolBar; | 9 | class QToolBar; |
10 | class QMenuBar; | 10 | class QMenuBar; |
11 | class QPopupMenu; | 11 | class QPopupMenu; |
12 | class MailTable; | 12 | class MailTable; |
13 | class QAction; | 13 | class QAction; |
14 | 14 | ||
15 | class MainWindowBase : public QMainWindow | 15 | class MainWindowBase : public QMainWindow |
16 | { | 16 | { |
17 | Q_OBJECT | 17 | Q_OBJECT |
18 | 18 | ||
19 | public: | 19 | public: |
20 | MainWindowBase(QWidget *parent = 0, const char *name = 0, WFlags fl = 0); | 20 | MainWindowBase(QWidget *parent = 0, const char *name = 0, WFlags fl = 0); |
21 | 21 | ||
22 | protected slots: | 22 | protected slots: |
23 | void slotFoldersToggled(bool toggled); | 23 | void slotFoldersToggled(bool toggled); |
24 | 24 | ||
25 | protected: | 25 | protected: |
26 | ServerConnection *serverConnection; | 26 | ServerConnection *serverConnection; |
27 | MailStatusBar *status; | 27 | MailStatusBar *status; |
28 | FolderWidget *folderView; | 28 | FolderWidget *folderView; |
29 | QPEToolBar *toolbar; | 29 | QToolBar *toolbar; |
30 | QMenuBar *menubar; | 30 | QMenuBar *menubar; |
31 | QPopupMenu *mailmenu, *servermenu; | 31 | QPopupMenu *mailmenu, *servermenu; |
32 | MailTable *mailView; | 32 | MailTable *mailView; |
33 | QAction *compose, *sendQueue, *folders, *findmails, *configure; | 33 | QAction *compose, *sendQueue, *folders, *findmails, *configure; |
34 | 34 | ||
35 | }; | 35 | }; |
36 | 36 | ||
37 | #endif | 37 | #endif |
diff --git a/noncore/unsupported/mail2/viewmailbase.cpp b/noncore/unsupported/mail2/viewmailbase.cpp index 10aa14d..f72026f 100644 --- a/noncore/unsupported/mail2/viewmailbase.cpp +++ b/noncore/unsupported/mail2/viewmailbase.cpp | |||
@@ -1,75 +1,75 @@ | |||
1 | #include <qtextbrowser.h> | 1 | #include <qtextbrowser.h> |
2 | #include <qlistview.h> | 2 | #include <qlistview.h> |
3 | #include <qaction.h> | 3 | #include <qaction.h> |
4 | #include <qlabel.h> | 4 | #include <qlabel.h> |
5 | #include <qvbox.h> | 5 | #include <qvbox.h> |
6 | #include <qpopupmenu.h> | 6 | #include <qpopupmenu.h> |
7 | 7 | ||
8 | #include <qpe/qpetoolbar.h> | 8 | #include <qpe/qpetoolbar.h> |
9 | #include <qpe/qpemenubar.h> | 9 | #include <qmenubar.h> |
10 | #include <qpe/resource.h> | 10 | #include <qpe/resource.h> |
11 | 11 | ||
12 | #include "viewmailbase.h" | 12 | #include "viewmailbase.h" |
13 | #include "opendiag.h" | 13 | #include "opendiag.h" |
14 | 14 | ||
15 | ViewMailBase::ViewMailBase(QWidget *parent, const char *name, WFlags fl) | 15 | ViewMailBase::ViewMailBase(QWidget *parent, const char *name, WFlags fl) |
16 | : QMainWindow(parent, name, fl) | 16 | : QMainWindow(parent, name, fl) |
17 | { | 17 | { |
18 | setCaption(tr("E-Mail by %1")); | 18 | setCaption(tr("E-Mail by %1")); |
19 | setToolBarsMovable(false); | 19 | setToolBarsMovable(false); |
20 | 20 | ||
21 | toolbar = new QPEToolBar(this); | 21 | toolbar = new QToolBar(this); |
22 | menubar = new QMenuBar( toolbar ); | 22 | menubar = new QMenuBar( toolbar ); |
23 | mailmenu = new QPopupMenu( menubar ); | 23 | mailmenu = new QPopupMenu( menubar ); |
24 | menubar->insertItem( tr( "Mail" ), mailmenu ); | 24 | menubar->insertItem( tr( "Mail" ), mailmenu ); |
25 | 25 | ||
26 | toolbar->setHorizontalStretchable(true); | 26 | toolbar->setHorizontalStretchable(true); |
27 | addToolBar(toolbar); | 27 | addToolBar(toolbar); |
28 | 28 | ||
29 | QLabel *spacer = new QLabel(toolbar); | 29 | QLabel *spacer = new QLabel(toolbar); |
30 | spacer->setBackgroundMode(QWidget::PaletteButton); | 30 | spacer->setBackgroundMode(QWidget::PaletteButton); |
31 | toolbar->setStretchableWidget(spacer); | 31 | toolbar->setStretchableWidget(spacer); |
32 | 32 | ||
33 | reply = new QAction(tr("Reply"), QIconSet(Resource::loadPixmap("mail/reply")), 0, 0, this); | 33 | reply = new QAction(tr("Reply"), QIconSet(Resource::loadPixmap("mail/reply")), 0, 0, this); |
34 | reply->addTo(toolbar); | 34 | reply->addTo(toolbar); |
35 | reply->addTo(mailmenu); | 35 | reply->addTo(mailmenu); |
36 | 36 | ||
37 | forward = new QAction(tr("Forward"), QIconSet(Resource::loadPixmap("mail/forward")), 0, 0, this); | 37 | forward = new QAction(tr("Forward"), QIconSet(Resource::loadPixmap("mail/forward")), 0, 0, this); |
38 | forward->addTo(toolbar); | 38 | forward->addTo(toolbar); |
39 | forward->addTo(mailmenu); | 39 | forward->addTo(mailmenu); |
40 | 40 | ||
41 | attachbutton = new QAction(tr("Attachments"), QIconSet(Resource::loadPixmap("mail/attach")), 0, 0, this, 0, true); | 41 | attachbutton = new QAction(tr("Attachments"), QIconSet(Resource::loadPixmap("mail/attach")), 0, 0, this, 0, true); |
42 | attachbutton->addTo(toolbar); | 42 | attachbutton->addTo(toolbar); |
43 | attachbutton->addTo(mailmenu); | 43 | attachbutton->addTo(mailmenu); |
44 | connect(attachbutton, SIGNAL(toggled(bool)), SLOT(slotChangeAttachview(bool))); | 44 | connect(attachbutton, SIGNAL(toggled(bool)), SLOT(slotChangeAttachview(bool))); |
45 | 45 | ||
46 | deleteMail = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this); | 46 | deleteMail = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this); |
47 | deleteMail->addTo(toolbar); | 47 | deleteMail->addTo(toolbar); |
48 | deleteMail->addTo(mailmenu); | 48 | deleteMail->addTo(mailmenu); |
49 | 49 | ||
50 | QVBox *view = new QVBox(this); | 50 | QVBox *view = new QVBox(this); |
51 | setCentralWidget(view); | 51 | setCentralWidget(view); |
52 | 52 | ||
53 | attachments = new QListView(view); | 53 | attachments = new QListView(view); |
54 | attachments->setMinimumHeight(90); | 54 | attachments->setMinimumHeight(90); |
55 | attachments->setMaximumHeight(90); | 55 | attachments->setMaximumHeight(90); |
56 | attachments->setAllColumnsShowFocus(true); | 56 | attachments->setAllColumnsShowFocus(true); |
57 | attachments->addColumn("Mime Type", 100); | 57 | attachments->addColumn("Mime Type", 100); |
58 | attachments->addColumn("Filename", 100); | 58 | attachments->addColumn("Filename", 100); |
59 | attachments->addColumn("Description", 100); | 59 | attachments->addColumn("Description", 100); |
60 | attachments->hide(); | 60 | attachments->hide(); |
61 | 61 | ||
62 | browser = new QTextBrowser(view); | 62 | browser = new QTextBrowser(view); |
63 | 63 | ||
64 | openDiag = new OpenDiag(view); | 64 | openDiag = new OpenDiag(view); |
65 | openDiag->hide(); | 65 | openDiag->hide(); |
66 | 66 | ||
67 | } | 67 | } |
68 | 68 | ||
69 | void ViewMailBase::slotChangeAttachview(bool state) | 69 | void ViewMailBase::slotChangeAttachview(bool state) |
70 | { | 70 | { |
71 | if (state) attachments->show(); | 71 | if (state) attachments->show(); |
72 | else attachments->hide(); | 72 | else attachments->hide(); |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
diff --git a/noncore/unsupported/mail2/viewmailbase.h b/noncore/unsupported/mail2/viewmailbase.h index 6e55021..898522e 100644 --- a/noncore/unsupported/mail2/viewmailbase.h +++ b/noncore/unsupported/mail2/viewmailbase.h | |||
@@ -1,36 +1,36 @@ | |||
1 | #ifndef VIEWMAILBASE_H | 1 | #ifndef VIEWMAILBASE_H |
2 | #define VIEWMAILBASE_H | 2 | #define VIEWMAILBASE_H |
3 | 3 | ||
4 | #include <qmainwindow.h> | 4 | #include <qmainwindow.h> |
5 | 5 | ||
6 | class QAction; | 6 | class QAction; |
7 | class OpenDiag; | 7 | class OpenDiag; |
8 | class QListView; | 8 | class QListView; |
9 | class QPEToolBar; | 9 | class QToolBar; |
10 | class QTextBrowser; | 10 | class QTextBrowser; |
11 | class QMenuBar; | 11 | class QMenuBar; |
12 | class QPopupMenu; | 12 | class QPopupMenu; |
13 | 13 | ||
14 | class ViewMailBase : public QMainWindow | 14 | class ViewMailBase : public QMainWindow |
15 | { | 15 | { |
16 | Q_OBJECT | 16 | Q_OBJECT |
17 | 17 | ||
18 | public: | 18 | public: |
19 | ViewMailBase(QWidget *parent = 0, const char *name = 0, WFlags fl = 0); | 19 | ViewMailBase(QWidget *parent = 0, const char *name = 0, WFlags fl = 0); |
20 | 20 | ||
21 | protected: | 21 | protected: |
22 | QAction *reply, *forward, *attachbutton, *deleteMail; | 22 | QAction *reply, *forward, *attachbutton, *deleteMail; |
23 | QListView *attachments; | 23 | QListView *attachments; |
24 | QPEToolBar *toolbar; | 24 | QToolBar *toolbar; |
25 | QTextBrowser *browser; | 25 | QTextBrowser *browser; |
26 | OpenDiag *openDiag; | 26 | OpenDiag *openDiag; |
27 | QMenuBar *menubar; | 27 | QMenuBar *menubar; |
28 | QPopupMenu *mailmenu; | 28 | QPopupMenu *mailmenu; |
29 | 29 | ||
30 | protected slots: | 30 | protected slots: |
31 | void slotChangeAttachview(bool state); | 31 | void slotChangeAttachview(bool state); |
32 | 32 | ||
33 | }; | 33 | }; |
34 | 34 | ||
35 | #endif | 35 | #endif |
36 | 36 | ||
diff --git a/noncore/unsupported/oipkg/mainwindow.cpp b/noncore/unsupported/oipkg/mainwindow.cpp index 6930d60..a09bc30 100644 --- a/noncore/unsupported/oipkg/mainwindow.cpp +++ b/noncore/unsupported/oipkg/mainwindow.cpp | |||
@@ -1,515 +1,515 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | // Copyright (C) 2000 Trolltech AS. | 9 | // Copyright (C) 2000 Trolltech AS. |
10 | // adadpted form qpe/qipkg | 10 | // adadpted form qpe/qipkg |
11 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | 11 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> |
12 | 12 | ||
13 | 13 | ||
14 | #include "mainwindow.h" | 14 | #include "mainwindow.h" |
15 | 15 | ||
16 | #include <qmenubar.h> | 16 | #include <qmenubar.h> |
17 | #include <qpe/qpemessagebox.h> | 17 | #include <qpe/qpemessagebox.h> |
18 | #include <qpe/resource.h> | 18 | #include <qpe/resource.h> |
19 | #include <qpe/config.h> | 19 | #include <qpe/config.h> |
20 | #include <qpe/qpetoolbar.h> | 20 | #include <qtoolbar.h> |
21 | #include <qpe/qcopenvelope_qws.h> | 21 | #include <qpe/qcopenvelope_qws.h> |
22 | #include <qaction.h> | 22 | #include <qaction.h> |
23 | #include <qmessagebox.h> | 23 | #include <qmessagebox.h> |
24 | #include <qpopupmenu.h> | 24 | #include <qpopupmenu.h> |
25 | #include <qtoolbutton.h> | 25 | #include <qtoolbutton.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qlabel.h> | 27 | #include <qlabel.h> |
28 | #include <qfile.h> | 28 | #include <qfile.h> |
29 | #include <qlistview.h> | 29 | #include <qlistview.h> |
30 | #include <qtextview.h> | 30 | #include <qtextview.h> |
31 | #include <qcheckbox.h> | 31 | #include <qcheckbox.h> |
32 | #include <qlineedit.h> | 32 | #include <qlineedit.h> |
33 | #include <qtabwidget.h> | 33 | #include <qtabwidget.h> |
34 | #include <qcombobox.h> | 34 | #include <qcombobox.h> |
35 | #include <qmessagebox.h> | 35 | #include <qmessagebox.h> |
36 | #include <qpushbutton.h> | 36 | #include <qpushbutton.h> |
37 | #include <qlayout.h> | 37 | #include <qlayout.h> |
38 | 38 | ||
39 | #include "pksettingsbase.h" | 39 | #include "pksettingsbase.h" |
40 | #include "utils.h" | 40 | #include "utils.h" |
41 | #include "packagelistitem.h" | 41 | #include "packagelistitem.h" |
42 | 42 | ||
43 | 43 | ||
44 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : | 44 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) : |
45 | QMainWindow( parent, name, f ) | 45 | QMainWindow( parent, name, f ) |
46 | // packageListServers( QObject(parent), name ), | 46 | // packageListServers( QObject(parent), name ), |
47 | // packageListSearch( parent, name ), | 47 | // packageListSearch( parent, name ), |
48 | // packageListDocLnk( parent, name ) | 48 | // packageListDocLnk( parent, name ) |
49 | { | 49 | { |
50 | setCaption( tr("Package Manager") ); | 50 | setCaption( tr("Package Manager") ); |
51 | settings = new PackageManagerSettings(this,0,TRUE); | 51 | settings = new PackageManagerSettings(this,0,TRUE); |
52 | listViewPackages = new PackageListView( this,"listViewPackages",settings ); | 52 | listViewPackages = new PackageListView( this,"listViewPackages",settings ); |
53 | setCentralWidget( listViewPackages ); | 53 | setCentralWidget( listViewPackages ); |
54 | listViewPackages->addList( tr("feeds"), &packageListServers ); | 54 | listViewPackages->addList( tr("feeds"), &packageListServers ); |
55 | listViewPackages->addList( tr("ipkgfind&killefiz"), &packageListSearch ); | 55 | listViewPackages->addList( tr("ipkgfind&killefiz"), &packageListSearch ); |
56 | listViewPackages->addList( tr("documents"), &packageListDocLnk ); | 56 | listViewPackages->addList( tr("documents"), &packageListDocLnk ); |
57 | ipkg = new PmIpkg( settings, this ); | 57 | ipkg = new PmIpkg( settings, this ); |
58 | packageListServers.setSettings( settings ); | 58 | packageListServers.setSettings( settings ); |
59 | packageListSearch.setSettings( settings ); | 59 | packageListSearch.setSettings( settings ); |
60 | packageListDocLnk.setSettings( settings ); | 60 | packageListDocLnk.setSettings( settings ); |
61 | pvDebug(9,"packageListServers.update"); | 61 | pvDebug(9,"packageListServers.update"); |
62 | packageListServers.update(); | 62 | packageListServers.update(); |
63 | pvDebug(9,"packageListDocLnk.update"); | 63 | pvDebug(9,"packageListDocLnk.update"); |
64 | packageListDocLnk.update(); | 64 | packageListDocLnk.update(); |
65 | pvDebug(9,"makeMenu"); | 65 | pvDebug(9,"makeMenu"); |
66 | makeMenu(); | 66 | makeMenu(); |
67 | makeChannel(); | 67 | makeChannel(); |
68 | 68 | ||
69 | 69 | ||
70 | connect( section, SIGNAL(activated(int)), SLOT(sectionChanged()) ); | 70 | connect( section, SIGNAL(activated(int)), SLOT(sectionChanged()) ); |
71 | connect( subsection, SIGNAL(activated(int)), SLOT(subSectionChanged()) ); | 71 | connect( subsection, SIGNAL(activated(int)), SLOT(subSectionChanged()) ); |
72 | 72 | ||
73 | connect( settings->removeLinksButton, SIGNAL( clicked()), | 73 | connect( settings->removeLinksButton, SIGNAL( clicked()), |
74 | SLOT(removeLinks()) ); | 74 | SLOT(removeLinks()) ); |
75 | connect( settings->createLinksButton, SIGNAL( clicked()), | 75 | connect( settings->createLinksButton, SIGNAL( clicked()), |
76 | SLOT(createLinks()) ); | 76 | SLOT(createLinks()) ); |
77 | 77 | ||
78 | pvDebug(9,"displayList"); | 78 | pvDebug(9,"displayList"); |
79 | displayList(); | 79 | displayList(); |
80 | } | 80 | } |
81 | 81 | ||
82 | void MainWindow::makeMenu() | 82 | void MainWindow::makeMenu() |
83 | { | 83 | { |
84 | 84 | ||
85 | QPEToolBar *toolBar = new QPEToolBar( this ); | 85 | QToolBar *toolBar = new QToolBar( this ); |
86 | QMenuBar *menuBar = new QMenuBar( toolBar ); | 86 | QMenuBar *menuBar = new QMenuBar( toolBar ); |
87 | QPopupMenu *srvMenu = new QPopupMenu( menuBar ); | 87 | QPopupMenu *srvMenu = new QPopupMenu( menuBar ); |
88 | QPopupMenu *viewMenu = new QPopupMenu( menuBar ); | 88 | QPopupMenu *viewMenu = new QPopupMenu( menuBar ); |
89 | QPopupMenu *cfgMenu = new QPopupMenu( menuBar ); | 89 | QPopupMenu *cfgMenu = new QPopupMenu( menuBar ); |
90 | QPopupMenu *helpMenu = new QPopupMenu( menuBar ); | 90 | QPopupMenu *helpMenu = new QPopupMenu( menuBar ); |
91 | 91 | ||
92 | setToolBarsMovable( false ); | 92 | setToolBarsMovable( false ); |
93 | toolBar->setHorizontalStretchable( true ); | 93 | toolBar->setHorizontalStretchable( true ); |
94 | menuBar->insertItem( tr( "Package" ), srvMenu ); | 94 | menuBar->insertItem( tr( "Package" ), srvMenu ); |
95 | menuBar->insertItem( tr( "View" ), viewMenu ); | 95 | menuBar->insertItem( tr( "View" ), viewMenu ); |
96 | menuBar->insertItem( tr( "Settings" ), cfgMenu ); | 96 | menuBar->insertItem( tr( "Settings" ), cfgMenu ); |
97 | menuBar->insertItem( tr( "Help" ), helpMenu ); | 97 | menuBar->insertItem( tr( "Help" ), helpMenu ); |
98 | 98 | ||
99 | // QLabel *spacer; | 99 | // QLabel *spacer; |
100 | // spacer = new QLabel( "", toolBar ); | 100 | // spacer = new QLabel( "", toolBar ); |
101 | // spacer->setBackgroundColor( toolBar->backgroundColor() ); | 101 | // spacer->setBackgroundColor( toolBar->backgroundColor() ); |
102 | // toolBar->setStretchableWidget( spacer ); | 102 | // toolBar->setStretchableWidget( spacer ); |
103 | 103 | ||
104 | 104 | ||
105 | runAction = new QAction( tr( "Apply" ), | 105 | runAction = new QAction( tr( "Apply" ), |
106 | Resource::loadPixmap( "oipkg/install" ), | 106 | Resource::loadPixmap( "oipkg/install" ), |
107 | QString::null, 0, this, 0 ); | 107 | QString::null, 0, this, 0 ); |
108 | connect( runAction, SIGNAL( activated() ), | 108 | connect( runAction, SIGNAL( activated() ), |
109 | this, SLOT( runIpkg() ) ); | 109 | this, SLOT( runIpkg() ) ); |
110 | runAction->addTo( toolBar ); | 110 | runAction->addTo( toolBar ); |
111 | runAction->addTo( srvMenu ); | 111 | runAction->addTo( srvMenu ); |
112 | 112 | ||
113 | srvMenu->insertSeparator(); | 113 | srvMenu->insertSeparator(); |
114 | 114 | ||
115 | updateAction = new QAction( tr( "Update" ), | 115 | updateAction = new QAction( tr( "Update" ), |
116 | Resource::loadIconSet( "oipkg/update" ), | 116 | Resource::loadIconSet( "oipkg/update" ), |
117 | QString::null, 0, this, 0 ); | 117 | QString::null, 0, this, 0 ); |
118 | connect( updateAction, SIGNAL( activated() ), | 118 | connect( updateAction, SIGNAL( activated() ), |
119 | this , SLOT( updateList() ) ); | 119 | this , SLOT( updateList() ) ); |
120 | updateAction->addTo( toolBar ); | 120 | updateAction->addTo( toolBar ); |
121 | updateAction->addTo( srvMenu ); | 121 | updateAction->addTo( srvMenu ); |
122 | 122 | ||
123 | QAction *cfgact; | 123 | QAction *cfgact; |
124 | 124 | ||
125 | cfgact = new QAction( tr( "Setups" ), | 125 | cfgact = new QAction( tr( "Setups" ), |
126 | QString::null, 0, this, 0 ); | 126 | QString::null, 0, this, 0 ); |
127 | connect( cfgact, SIGNAL( activated() ), | 127 | connect( cfgact, SIGNAL( activated() ), |
128 | SLOT( showSettingsSetup() ) ); | 128 | SLOT( showSettingsSetup() ) ); |
129 | cfgact->addTo( cfgMenu ); | 129 | cfgact->addTo( cfgMenu ); |
130 | 130 | ||
131 | cfgact = new QAction( tr( "Servers" ), | 131 | cfgact = new QAction( tr( "Servers" ), |
132 | QString::null, 0, this, 0 ); | 132 | QString::null, 0, this, 0 ); |
133 | connect( cfgact, SIGNAL( activated() ), | 133 | connect( cfgact, SIGNAL( activated() ), |
134 | SLOT( showSettingsSrv() ) ); | 134 | SLOT( showSettingsSrv() ) ); |
135 | cfgact->addTo( cfgMenu ); | 135 | cfgact->addTo( cfgMenu ); |
136 | cfgact = new QAction( tr( "Destinations" ), | 136 | cfgact = new QAction( tr( "Destinations" ), |
137 | QString::null, 0, this, 0 ); | 137 | QString::null, 0, this, 0 ); |
138 | connect( cfgact, SIGNAL( activated() ), | 138 | connect( cfgact, SIGNAL( activated() ), |
139 | SLOT( showSettingsDst() ) ); | 139 | SLOT( showSettingsDst() ) ); |
140 | cfgact->addTo( cfgMenu ); | 140 | cfgact->addTo( cfgMenu ); |
141 | 141 | ||
142 | QAction *a; | 142 | QAction *a; |
143 | 143 | ||
144 | // SECTIONS | 144 | // SECTIONS |
145 | sectionBar = new QPEToolBar( this ); | 145 | sectionBar = new QToolBar( this ); |
146 | addToolBar( sectionBar, "Section", QMainWindow::Top, TRUE ); | 146 | addToolBar( sectionBar, "Section", QMainWindow::Top, TRUE ); |
147 | sectionBar->setHorizontalStretchable( true ); | 147 | sectionBar->setHorizontalStretchable( true ); |
148 | QLabel *label = new QLabel( sectionBar, "section" ); | 148 | QLabel *label = new QLabel( sectionBar, "section" ); |
149 | // label->setBackgroundMode( NoBackground ); | 149 | // label->setBackgroundMode( NoBackground ); |
150 | label->font().setPointSize( 8 ); | 150 | label->font().setPointSize( 8 ); |
151 | label->setText( tr( "Section:" ) ); | 151 | label->setText( tr( "Section:" ) ); |
152 | sectionBar->setStretchableWidget( label ); | 152 | sectionBar->setStretchableWidget( label ); |
153 | section = new QComboBox( false, sectionBar ); | 153 | section = new QComboBox( false, sectionBar ); |
154 | section->font().setPointSize( 8 ); | 154 | section->font().setPointSize( 8 ); |
155 | label = new QLabel( " / ", sectionBar ); | 155 | label = new QLabel( " / ", sectionBar ); |
156 | label->font().setPointSize( 8 ); | 156 | label->font().setPointSize( 8 ); |
157 | // label->setBackgroundMode( PaletteForeground ); | 157 | // label->setBackgroundMode( PaletteForeground ); |
158 | subsection = new QComboBox( false, sectionBar ); | 158 | subsection = new QComboBox( false, sectionBar ); |
159 | subsection->font().setPointSize( 8 ); | 159 | subsection->font().setPointSize( 8 ); |
160 | a = new QAction( tr( "Close Section" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 160 | a = new QAction( tr( "Close Section" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
161 | connect( a, SIGNAL( activated() ), this, SLOT( sectionClose() ) ); | 161 | connect( a, SIGNAL( activated() ), this, SLOT( sectionClose() ) ); |
162 | a->addTo( sectionBar ); | 162 | a->addTo( sectionBar ); |
163 | setSections(); | 163 | setSections(); |
164 | setSubSections(); | 164 | setSubSections(); |
165 | sectionAction = new QAction( tr( "Sections" ), QString::null, 0, this, 0 ); | 165 | sectionAction = new QAction( tr( "Sections" ), QString::null, 0, this, 0 ); |
166 | connect( sectionAction, SIGNAL( toggled(bool) ), this, SLOT( sectionShow(bool) ) ); | 166 | connect( sectionAction, SIGNAL( toggled(bool) ), this, SLOT( sectionShow(bool) ) ); |
167 | sectionAction->setToggleAction( true ); | 167 | sectionAction->setToggleAction( true ); |
168 | sectionAction->addTo( viewMenu ); | 168 | sectionAction->addTo( viewMenu ); |
169 | // sectionBar->setStretchableWidget( section ); | 169 | // sectionBar->setStretchableWidget( section ); |
170 | 170 | ||
171 | //FIND | 171 | //FIND |
172 | findBar = new QPEToolBar(this); | 172 | findBar = new QToolBar(this); |
173 | addToolBar( findBar, "Filter", QMainWindow::Top, TRUE ); | 173 | addToolBar( findBar, "Filter", QMainWindow::Top, TRUE ); |
174 | label = new QLabel( tr("Filter: "), findBar ); | 174 | label = new QLabel( tr("Filter: "), findBar ); |
175 | // label->setBackgroundMode( PaletteForeground ); | 175 | // label->setBackgroundMode( PaletteForeground ); |
176 | findBar->setHorizontalStretchable( TRUE ); | 176 | findBar->setHorizontalStretchable( TRUE ); |
177 | findEdit = new QLineEdit( findBar, "findEdit" ); | 177 | findEdit = new QLineEdit( findBar, "findEdit" ); |
178 | findBar->setStretchableWidget( findEdit ); | 178 | findBar->setStretchableWidget( findEdit ); |
179 | connect( findEdit, SIGNAL( textChanged( const QString & ) ), | 179 | connect( findEdit, SIGNAL( textChanged( const QString & ) ), |
180 | this, SLOT( displayList() ) ); | 180 | this, SLOT( displayList() ) ); |
181 | a = new QAction( tr( "Clear Find" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); | 181 | a = new QAction( tr( "Clear Find" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); |
182 | connect( a, SIGNAL( activated() ), findEdit, SLOT( clear() ) ); | 182 | connect( a, SIGNAL( activated() ), findEdit, SLOT( clear() ) ); |
183 | a->addTo( findBar ); | 183 | a->addTo( findBar ); |
184 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 184 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
185 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 185 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
186 | a->addTo( findBar ); | 186 | a->addTo( findBar ); |
187 | findAction = new QAction( tr( "Filter" ), QString::null, 0, this, 0 ); | 187 | findAction = new QAction( tr( "Filter" ), QString::null, 0, this, 0 ); |
188 | connect( findAction, SIGNAL( toggled(bool) ), this, SLOT( findShow(bool) ) ); | 188 | connect( findAction, SIGNAL( toggled(bool) ), this, SLOT( findShow(bool) ) ); |
189 | findAction->setToggleAction( true ); | 189 | findAction->setToggleAction( true ); |
190 | findAction->addTo( viewMenu ); | 190 | findAction->addTo( viewMenu ); |
191 | 191 | ||
192 | //SEARCH | 192 | //SEARCH |
193 | searchBar = new QPEToolBar(this); | 193 | searchBar = new QToolBar(this); |
194 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 194 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
195 | label = new QLabel( tr("Search: "), searchBar ); | 195 | label = new QLabel( tr("Search: "), searchBar ); |
196 | // label->setBackgroundMode( PaletteForeground ); | 196 | // label->setBackgroundMode( PaletteForeground ); |
197 | searchBar->setHorizontalStretchable( TRUE ); | 197 | searchBar->setHorizontalStretchable( TRUE ); |
198 | searchEdit = new QLineEdit( searchBar, "seachEdit" ); | 198 | searchEdit = new QLineEdit( searchBar, "seachEdit" ); |
199 | searchBar->setStretchableWidget( searchEdit ); | 199 | searchBar->setStretchableWidget( searchEdit ); |
200 | // connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 200 | // connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
201 | // this, SLOT( displayList() ) ); | 201 | // this, SLOT( displayList() ) ); |
202 | a = new QAction( tr( "Clear Search" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); | 202 | a = new QAction( tr( "Clear Search" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 ); |
203 | connect( a, SIGNAL( activated() ), searchEdit, SLOT( clear() ) ); | 203 | connect( a, SIGNAL( activated() ), searchEdit, SLOT( clear() ) ); |
204 | a->addTo( searchBar ); | 204 | a->addTo( searchBar ); |
205 | searchCommit = new QAction( tr( "Do Search" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 205 | searchCommit = new QAction( tr( "Do Search" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
206 | connect( searchCommit, SIGNAL( activated() ), SLOT( remotePackageQuery() ) ); | 206 | connect( searchCommit, SIGNAL( activated() ), SLOT( remotePackageQuery() ) ); |
207 | searchCommit->addTo( searchBar ); | 207 | searchCommit->addTo( searchBar ); |
208 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 208 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
209 | connect( a, SIGNAL( activated() ), this, SLOT( searchClose() ) ); | 209 | connect( a, SIGNAL( activated() ), this, SLOT( searchClose() ) ); |
210 | a->addTo( searchBar ); | 210 | a->addTo( searchBar ); |
211 | searchAction = new QAction( tr( "Search" ), QString::null, 0, this, 0 ); | 211 | searchAction = new QAction( tr( "Search" ), QString::null, 0, this, 0 ); |
212 | connect( searchAction, SIGNAL( toggled(bool) ), this, SLOT( searchShow(bool) ) ); | 212 | connect( searchAction, SIGNAL( toggled(bool) ), this, SLOT( searchShow(bool) ) ); |
213 | searchAction->setToggleAction( true ); | 213 | searchAction->setToggleAction( true ); |
214 | searchAction->addTo( viewMenu ); | 214 | searchAction->addTo( viewMenu ); |
215 | 215 | ||
216 | //DEST | 216 | //DEST |
217 | destBar = new QPEToolBar(this); | 217 | destBar = new QToolBar(this); |
218 | addToolBar( destBar, "Destination", QMainWindow::Top, TRUE ); | 218 | addToolBar( destBar, "Destination", QMainWindow::Top, TRUE ); |
219 | label = new QLabel( tr("Destination: "), destBar ); | 219 | label = new QLabel( tr("Destination: "), destBar ); |
220 | // label->setBackgroundMode( PaletteForeground ); | 220 | // label->setBackgroundMode( PaletteForeground ); |
221 | destBar->setHorizontalStretchable( TRUE ); | 221 | destBar->setHorizontalStretchable( TRUE ); |
222 | destination = new QComboBox( false, destBar ); | 222 | destination = new QComboBox( false, destBar ); |
223 | destination->insertStringList( settings->getDestinationNames() ); | 223 | destination->insertStringList( settings->getDestinationNames() ); |
224 | setComboName(destination,settings->getDestinationName()); | 224 | setComboName(destination,settings->getDestinationName()); |
225 | connect( destination, SIGNAL(activated(int)), | 225 | connect( destination, SIGNAL(activated(int)), |
226 | settings, SLOT(activeDestinationChange(int)) ); | 226 | settings, SLOT(activeDestinationChange(int)) ); |
227 | // space->setBackgroundMode( PaletteForeground ); | 227 | // space->setBackgroundMode( PaletteForeground ); |
228 | CheckBoxLink = new QCheckBox( tr("Link"), destBar); | 228 | CheckBoxLink = new QCheckBox( tr("Link"), destBar); |
229 | // CheckBoxLink->setBackgroundMode( PaletteForeground ); | 229 | // CheckBoxLink->setBackgroundMode( PaletteForeground ); |
230 | CheckBoxLink->setChecked( settings->createLinks() ); | 230 | CheckBoxLink->setChecked( settings->createLinks() ); |
231 | connect( CheckBoxLink, SIGNAL(toggled(bool)), | 231 | connect( CheckBoxLink, SIGNAL(toggled(bool)), |
232 | settings, SLOT(linkEnabled(bool)) ); | 232 | settings, SLOT(linkEnabled(bool)) ); |
233 | destAction = new QAction( tr( "Destinations" ), QString::null, 0, this, 0 ); | 233 | destAction = new QAction( tr( "Destinations" ), QString::null, 0, this, 0 ); |
234 | connect( destAction, SIGNAL( toggled(bool) ), SLOT( destShow(bool) ) ); | 234 | connect( destAction, SIGNAL( toggled(bool) ), SLOT( destShow(bool) ) ); |
235 | a = new QAction( tr( "Close Destinations" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 235 | a = new QAction( tr( "Close Destinations" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
236 | connect( a, SIGNAL( activated() ), SLOT( destClose() ) ); | 236 | connect( a, SIGNAL( activated() ), SLOT( destClose() ) ); |
237 | a->addTo( destBar ); | 237 | a->addTo( destBar ); |
238 | destBar->setStretchableWidget( CheckBoxLink ); | 238 | destBar->setStretchableWidget( CheckBoxLink ); |
239 | destAction->setToggleAction( true ); | 239 | destAction->setToggleAction( true ); |
240 | destAction->addTo( viewMenu ); | 240 | destAction->addTo( viewMenu ); |
241 | 241 | ||
242 | // helpMenu | 242 | // helpMenu |
243 | helpMenu->insertSeparator(); | 243 | helpMenu->insertSeparator(); |
244 | a = new QAction( tr( "Package Actions" ), QString::null, 0, this, 0 ); | 244 | a = new QAction( tr( "Package Actions" ), QString::null, 0, this, 0 ); |
245 | a->addTo( helpMenu ); | 245 | a->addTo( helpMenu ); |
246 | helpMenu->insertSeparator(); | 246 | helpMenu->insertSeparator(); |
247 | a = new QAction( tr( "Install" ), | 247 | a = new QAction( tr( "Install" ), |
248 | Resource::loadPixmap( "oipkg/install" ), QString::null, 0, this, 0 ); | 248 | Resource::loadPixmap( "oipkg/install" ), QString::null, 0, this, 0 ); |
249 | a->addTo( helpMenu ); | 249 | a->addTo( helpMenu ); |
250 | a = new QAction( tr( "Remove" ), | 250 | a = new QAction( tr( "Remove" ), |
251 | Resource::loadPixmap( "oipkg/uninstall" ), QString::null, 0, this, 0 ); | 251 | Resource::loadPixmap( "oipkg/uninstall" ), QString::null, 0, this, 0 ); |
252 | a->addTo( helpMenu ); | 252 | a->addTo( helpMenu ); |
253 | helpMenu->insertSeparator(); | 253 | helpMenu->insertSeparator(); |
254 | a = new QAction( tr( "Package Status" ), QString::null, 0, this, 0 ); | 254 | a = new QAction( tr( "Package Status" ), QString::null, 0, this, 0 ); |
255 | a->addTo( helpMenu ); | 255 | a->addTo( helpMenu ); |
256 | helpMenu->insertSeparator(); | 256 | helpMenu->insertSeparator(); |
257 | a = new QAction( tr( "New version, installed" ), | 257 | a = new QAction( tr( "New version, installed" ), |
258 | Resource::loadPixmap( "oipkg/installed" ), QString::null, 0, this, 0 ); | 258 | Resource::loadPixmap( "oipkg/installed" ), QString::null, 0, this, 0 ); |
259 | a->addTo( helpMenu ); | 259 | a->addTo( helpMenu ); |
260 | a = new QAction( tr( "New version, not installed" ), | 260 | a = new QAction( tr( "New version, not installed" ), |
261 | Resource::loadPixmap( "oipkg/uninstalled" ), QString::null, 0, this, 0 ); | 261 | Resource::loadPixmap( "oipkg/uninstalled" ), QString::null, 0, this, 0 ); |
262 | a->addTo( helpMenu ); | 262 | a->addTo( helpMenu ); |
263 | a = new QAction( tr( "Old version, installed" ), | 263 | a = new QAction( tr( "Old version, installed" ), |
264 | Resource::loadPixmap( "oipkg/installedOld" ), QString::null, 0, this, 0 ); | 264 | Resource::loadPixmap( "oipkg/installedOld" ), QString::null, 0, this, 0 ); |
265 | a->addTo( helpMenu ); | 265 | a->addTo( helpMenu ); |
266 | a = new QAction( tr( "Old version, not installed" ), | 266 | a = new QAction( tr( "Old version, not installed" ), |
267 | Resource::loadPixmap( "oipkg/uninstalledOld" ), QString::null, 0, this, 0 ); | 267 | Resource::loadPixmap( "oipkg/uninstalledOld" ), QString::null, 0, this, 0 ); |
268 | a->addTo( helpMenu ); | 268 | a->addTo( helpMenu ); |
269 | a = new QAction( tr( "Old version, new version installed" ), | 269 | a = new QAction( tr( "Old version, new version installed" ), |
270 | Resource::loadPixmap( "oipkg/uninstalledOldinstalledNew" ), QString::null, 0, this, 0 ); | 270 | Resource::loadPixmap( "oipkg/uninstalledOldinstalledNew" ), QString::null, 0, this, 0 ); |
271 | a->addTo( helpMenu ); | 271 | a->addTo( helpMenu ); |
272 | a = new QAction( tr( "New version, old version installed" ), | 272 | a = new QAction( tr( "New version, old version installed" ), |
273 | Resource::loadPixmap( "oipkg/uninstalledInstalledOld" ), QString::null, 0, this, 0 ); | 273 | Resource::loadPixmap( "oipkg/uninstalledInstalledOld" ), QString::null, 0, this, 0 ); |
274 | a->addTo( helpMenu ); | 274 | a->addTo( helpMenu ); |
275 | //a = new QAction( tr( "" ), | 275 | //a = new QAction( tr( "" ), |
276 | // Resource::loadPixmap( "oipkg/" ), QString::null, 0, this, 0 ); | 276 | // Resource::loadPixmap( "oipkg/" ), QString::null, 0, this, 0 ); |
277 | // a->addTo( helpMenu ); | 277 | // a->addTo( helpMenu ); |
278 | 278 | ||
279 | // configure the menus | 279 | // configure the menus |
280 | Config cfg( "oipkg", Config::User ); | 280 | Config cfg( "oipkg", Config::User ); |
281 | cfg.setGroup( "gui" ); | 281 | cfg.setGroup( "gui" ); |
282 | 282 | ||
283 | findShow( cfg.readBoolEntry( "findBar", true ) ); | 283 | findShow( cfg.readBoolEntry( "findBar", true ) ); |
284 | searchShow( cfg.readBoolEntry( "searchBar", true ) ); | 284 | searchShow( cfg.readBoolEntry( "searchBar", true ) ); |
285 | sectionShow( cfg.readBoolEntry( "sectionBar", true ) ); | 285 | sectionShow( cfg.readBoolEntry( "sectionBar", true ) ); |
286 | destShow( cfg.readBoolEntry( "destBar", false ) ); | 286 | destShow( cfg.readBoolEntry( "destBar", false ) ); |
287 | setComboName(section,cfg.readEntry("default_section")); | 287 | setComboName(section,cfg.readEntry("default_section")); |
288 | sectionChanged(); | 288 | sectionChanged(); |
289 | } | 289 | } |
290 | 290 | ||
291 | MainWindow::~MainWindow() | 291 | MainWindow::~MainWindow() |
292 | { | 292 | { |
293 | Config cfg( "oipkg", Config::User ); | 293 | Config cfg( "oipkg", Config::User ); |
294 | cfg.setGroup( "gui" ); | 294 | cfg.setGroup( "gui" ); |
295 | cfg.writeEntry( "findBar", !findBar->isHidden() ); | 295 | cfg.writeEntry( "findBar", !findBar->isHidden() ); |
296 | cfg.writeEntry( "searchBar", !searchBar->isHidden() ); | 296 | cfg.writeEntry( "searchBar", !searchBar->isHidden() ); |
297 | cfg.writeEntry( "sectionBar", !sectionBar->isHidden() ); | 297 | cfg.writeEntry( "sectionBar", !sectionBar->isHidden() ); |
298 | cfg.writeEntry( "destBar", !destBar->isHidden() ); | 298 | cfg.writeEntry( "destBar", !destBar->isHidden() ); |
299 | cfg.writeEntry( "default_section", section->currentText() ); | 299 | cfg.writeEntry( "default_section", section->currentText() ); |
300 | 300 | ||
301 | } | 301 | } |
302 | 302 | ||
303 | void MainWindow::runIpkg() | 303 | void MainWindow::runIpkg() |
304 | { | 304 | { |
305 | packageListServers.allPackages(); | 305 | packageListServers.allPackages(); |
306 | ipkg->loadList( &packageListSearch ); | 306 | ipkg->loadList( &packageListSearch ); |
307 | ipkg->loadList( &packageListDocLnk ); | 307 | ipkg->loadList( &packageListDocLnk ); |
308 | ipkg->loadList( &packageListServers ); | 308 | ipkg->loadList( &packageListServers ); |
309 | ipkg->commit(); | 309 | ipkg->commit(); |
310 | ipkg->clearLists(); | 310 | ipkg->clearLists(); |
311 | // ##### If we looked in the list of files, we could send out accurate | 311 | // ##### If we looked in the list of files, we could send out accurate |
312 | // ##### messages. But we don't bother yet, and just do an "all". | 312 | // ##### messages. But we don't bother yet, and just do an "all". |
313 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 313 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
314 | QString lf = QString::null; | 314 | QString lf = QString::null; |
315 | e << lf; | 315 | e << lf; |
316 | displayList(); | 316 | displayList(); |
317 | } | 317 | } |
318 | 318 | ||
319 | void MainWindow::updateList() | 319 | void MainWindow::updateList() |
320 | { | 320 | { |
321 | packageListServers.clear(); | 321 | packageListServers.clear(); |
322 | packageListSearch.clear(); | 322 | packageListSearch.clear(); |
323 | 323 | ||
324 | packageListDocLnk.clear(); | 324 | packageListDocLnk.clear(); |
325 | ipkg->update(); | 325 | ipkg->update(); |
326 | packageListServers.update(); | 326 | packageListServers.update(); |
327 | packageListSearch.update(); | 327 | packageListSearch.update(); |
328 | packageListDocLnk.update(); | 328 | packageListDocLnk.update(); |
329 | } | 329 | } |
330 | 330 | ||
331 | void MainWindow::filterList() | 331 | void MainWindow::filterList() |
332 | { | 332 | { |
333 | QString f = ""; | 333 | QString f = ""; |
334 | if ( findAction->isOn() ) f = findEdit->text(); | 334 | if ( findAction->isOn() ) f = findEdit->text(); |
335 | packageListServers.filterPackages( f ); | 335 | packageListServers.filterPackages( f ); |
336 | } | 336 | } |
337 | 337 | ||
338 | void MainWindow::displayList() | 338 | void MainWindow::displayList() |
339 | { | 339 | { |
340 | filterList(); | 340 | filterList(); |
341 | listViewPackages->display(); | 341 | listViewPackages->display(); |
342 | } | 342 | } |
343 | 343 | ||
344 | void MainWindow::sectionChanged() | 344 | void MainWindow::sectionChanged() |
345 | { | 345 | { |
346 | disconnect( section, SIGNAL( activated(int) ), | 346 | disconnect( section, SIGNAL( activated(int) ), |
347 | this, SLOT( sectionChanged() ) ); | 347 | this, SLOT( sectionChanged() ) ); |
348 | disconnect( subsection, SIGNAL(activated(int) ), | 348 | disconnect( subsection, SIGNAL(activated(int) ), |
349 | this, SLOT( subSectionChanged() ) ); | 349 | this, SLOT( subSectionChanged() ) ); |
350 | subsection->clear(); | 350 | subsection->clear(); |
351 | packageListServers.setSection( section->currentText() ); | 351 | packageListServers.setSection( section->currentText() ); |
352 | setSubSections(); | 352 | setSubSections(); |
353 | connect( section, SIGNAL( activated(int) ), | 353 | connect( section, SIGNAL( activated(int) ), |
354 | this, SLOT( sectionChanged() ) ); | 354 | this, SLOT( sectionChanged() ) ); |
355 | connect( subsection, SIGNAL(activated(int) ), | 355 | connect( subsection, SIGNAL(activated(int) ), |
356 | this, SLOT( subSectionChanged() ) ); | 356 | this, SLOT( subSectionChanged() ) ); |
357 | displayList(); | 357 | displayList(); |
358 | } | 358 | } |
359 | 359 | ||
360 | void MainWindow::subSectionChanged() | 360 | void MainWindow::subSectionChanged() |
361 | { | 361 | { |
362 | disconnect( section, SIGNAL( activated(int) ), | 362 | disconnect( section, SIGNAL( activated(int) ), |
363 | this, SLOT( sectionChanged() ) ); | 363 | this, SLOT( sectionChanged() ) ); |
364 | disconnect( subsection, SIGNAL(activated(int) ), | 364 | disconnect( subsection, SIGNAL(activated(int) ), |
365 | this, SLOT( subSectionChanged() ) ); | 365 | this, SLOT( subSectionChanged() ) ); |
366 | packageListServers.setSubSection( subsection->currentText() ); | 366 | packageListServers.setSubSection( subsection->currentText() ); |
367 | connect( section, SIGNAL( activated(int) ), | 367 | connect( section, SIGNAL( activated(int) ), |
368 | this, SLOT( sectionChanged() ) ); | 368 | this, SLOT( sectionChanged() ) ); |
369 | connect( subsection, SIGNAL(activated(int) ), | 369 | connect( subsection, SIGNAL(activated(int) ), |
370 | this, SLOT( subSectionChanged() ) ); | 370 | this, SLOT( subSectionChanged() ) ); |
371 | displayList(); | 371 | displayList(); |
372 | } | 372 | } |
373 | 373 | ||
374 | void MainWindow::setSections() | 374 | void MainWindow::setSections() |
375 | { | 375 | { |
376 | section->clear(); | 376 | section->clear(); |
377 | section->insertStringList( packageListServers.getSections() ); | 377 | section->insertStringList( packageListServers.getSections() ); |
378 | } | 378 | } |
379 | 379 | ||
380 | void MainWindow::setSubSections() | 380 | void MainWindow::setSubSections() |
381 | { | 381 | { |
382 | subsection->clear(); | 382 | subsection->clear(); |
383 | subsection->insertStringList( packageListServers.getSubSections() ); | 383 | subsection->insertStringList( packageListServers.getSubSections() ); |
384 | } | 384 | } |
385 | 385 | ||
386 | 386 | ||
387 | void MainWindow::showSettings(int i) | 387 | void MainWindow::showSettings(int i) |
388 | { | 388 | { |
389 | if ( settings->showDialog( i ) ) | 389 | if ( settings->showDialog( i ) ) |
390 | { | 390 | { |
391 | updateList(); | 391 | updateList(); |
392 | } | 392 | } |
393 | setComboName(destination,settings->getDestinationName()); | 393 | setComboName(destination,settings->getDestinationName()); |
394 | CheckBoxLink->setChecked( settings->createLinks() ); | 394 | CheckBoxLink->setChecked( settings->createLinks() ); |
395 | } | 395 | } |
396 | void MainWindow::showSettingsSetup() | 396 | void MainWindow::showSettingsSetup() |
397 | { | 397 | { |
398 | showSettings(0); | 398 | showSettings(0); |
399 | } | 399 | } |
400 | void MainWindow::showSettingsSrv() | 400 | void MainWindow::showSettingsSrv() |
401 | { | 401 | { |
402 | showSettings(1); | 402 | showSettings(1); |
403 | } | 403 | } |
404 | void MainWindow::showSettingsDst() | 404 | void MainWindow::showSettingsDst() |
405 | { | 405 | { |
406 | showSettings(2); | 406 | showSettings(2); |
407 | } | 407 | } |
408 | 408 | ||
409 | void MainWindow::sectionShow(bool b) | 409 | void MainWindow::sectionShow(bool b) |
410 | { | 410 | { |
411 | if (b) sectionBar->show(); | 411 | if (b) sectionBar->show(); |
412 | else sectionBar->hide(); | 412 | else sectionBar->hide(); |
413 | sectionAction->setOn( b ); | 413 | sectionAction->setOn( b ); |
414 | } | 414 | } |
415 | 415 | ||
416 | void MainWindow::sectionClose() | 416 | void MainWindow::sectionClose() |
417 | { | 417 | { |
418 | sectionAction->setOn( false ); | 418 | sectionAction->setOn( false ); |
419 | } | 419 | } |
420 | 420 | ||
421 | void MainWindow::findShow(bool b) | 421 | void MainWindow::findShow(bool b) |
422 | { | 422 | { |
423 | if (b) findBar->show(); | 423 | if (b) findBar->show(); |
424 | else findBar->hide(); | 424 | else findBar->hide(); |
425 | findAction->setOn( b ); | 425 | findAction->setOn( b ); |
426 | } | 426 | } |
427 | 427 | ||
428 | void MainWindow::findClose() | 428 | void MainWindow::findClose() |
429 | { | 429 | { |
430 | findAction->setOn( false ); | 430 | findAction->setOn( false ); |
431 | } | 431 | } |
432 | 432 | ||
433 | void MainWindow::searchShow(bool b) | 433 | void MainWindow::searchShow(bool b) |
434 | { | 434 | { |
435 | if (b) searchBar->show(); | 435 | if (b) searchBar->show(); |
436 | else searchBar->hide(); | 436 | else searchBar->hide(); |
437 | searchAction->setOn( b ); | 437 | searchAction->setOn( b ); |
438 | } | 438 | } |
439 | 439 | ||
440 | void MainWindow::searchClose() | 440 | void MainWindow::searchClose() |
441 | { | 441 | { |
442 | searchAction->setOn( false ); | 442 | searchAction->setOn( false ); |
443 | } | 443 | } |
444 | 444 | ||
445 | 445 | ||
446 | void MainWindow::destShow(bool b) | 446 | void MainWindow::destShow(bool b) |
447 | { | 447 | { |
448 | if (b) destBar->show(); | 448 | if (b) destBar->show(); |
449 | else destBar->hide(); | 449 | else destBar->hide(); |
450 | destAction->setOn( b ); | 450 | destAction->setOn( b ); |
451 | } | 451 | } |
452 | 452 | ||
453 | void MainWindow::destClose() | 453 | void MainWindow::destClose() |
454 | { | 454 | { |
455 | destAction->setOn( false ); | 455 | destAction->setOn( false ); |
456 | } | 456 | } |
457 | 457 | ||
458 | void MainWindow::setDocument(const QString &fileName) | 458 | void MainWindow::setDocument(const QString &fileName) |
459 | { | 459 | { |
460 | if ( !QFile::exists( fileName ) ) return; | 460 | if ( !QFile::exists( fileName ) ) return; |
461 | ipkg->installFile( fileName ); | 461 | ipkg->installFile( fileName ); |
462 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 462 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
463 | QString lf = QString::null; | 463 | QString lf = QString::null; |
464 | e << lf; | 464 | e << lf; |
465 | } | 465 | } |
466 | 466 | ||
467 | 467 | ||
468 | void MainWindow::makeChannel() | 468 | void MainWindow::makeChannel() |
469 | { | 469 | { |
470 | channel = new QCopChannel( "QPE/Application/oipkg", this ); | 470 | channel = new QCopChannel( "QPE/Application/oipkg", this ); |
471 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 471 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
472 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 472 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
473 | } | 473 | } |
474 | 474 | ||
475 | 475 | ||
476 | 476 | ||
477 | void MainWindow::receive(const QCString &msg, const QByteArray &arg) | 477 | void MainWindow::receive(const QCString &msg, const QByteArray &arg) |
478 | { | 478 | { |
479 | pvDebug(3, "QCop "+msg+" "+QCString(arg)); | 479 | pvDebug(3, "QCop "+msg+" "+QCString(arg)); |
480 | if ( msg == "installFile(QString)" ) | 480 | if ( msg == "installFile(QString)" ) |
481 | { | 481 | { |
482 | ipkg->installFile( QString(arg) ); | 482 | ipkg->installFile( QString(arg) ); |
483 | }else if( msg == "removeFile(QString)" ) | 483 | }else if( msg == "removeFile(QString)" ) |
484 | { | 484 | { |
485 | ipkg->removeFile( QString(arg) ); | 485 | ipkg->removeFile( QString(arg) ); |
486 | }else if( msg == "createLinks(QString)" ) | 486 | }else if( msg == "createLinks(QString)" ) |
487 | { | 487 | { |
488 | ipkg->createLinks( QString(arg) ); | 488 | ipkg->createLinks( QString(arg) ); |
489 | }else if( msg == "removeLinks(QString)" ) | 489 | }else if( msg == "removeLinks(QString)" ) |
490 | { | 490 | { |
491 | ipkg->removeLinks( QString(arg) ); | 491 | ipkg->removeLinks( QString(arg) ); |
492 | }else{ | 492 | }else{ |
493 | pvDebug(2,"Huh what do ya want") | 493 | pvDebug(2,"Huh what do ya want") |
494 | } | 494 | } |
495 | } | 495 | } |
496 | 496 | ||
497 | 497 | ||
498 | void MainWindow::createLinks() | 498 | void MainWindow::createLinks() |
499 | { | 499 | { |
500 | pvDebug(2,"creating links..."); | 500 | pvDebug(2,"creating links..."); |
501 | ipkg->createLinks( settings->destinationurl->text() ); | 501 | ipkg->createLinks( settings->destinationurl->text() ); |
502 | } | 502 | } |
503 | 503 | ||
504 | void MainWindow::removeLinks() | 504 | void MainWindow::removeLinks() |
505 | { | 505 | { |
506 | pvDebug(2,"removing links..."); | 506 | pvDebug(2,"removing links..."); |
507 | ipkg->removeLinks( settings->destinationurl->text() ); | 507 | ipkg->removeLinks( settings->destinationurl->text() ); |
508 | } | 508 | } |
509 | 509 | ||
510 | void MainWindow::remotePackageQuery() | 510 | void MainWindow::remotePackageQuery() |
511 | { | 511 | { |
512 | packageListSearch.query( searchEdit->text() ); | 512 | packageListSearch.query( searchEdit->text() ); |
513 | packageListSearch.update(); | 513 | packageListSearch.update(); |
514 | displayList(); | 514 | displayList(); |
515 | } | 515 | } |
diff --git a/noncore/unsupported/oipkg/mainwindow.h b/noncore/unsupported/oipkg/mainwindow.h index 7446135..ae9fd0c 100644 --- a/noncore/unsupported/oipkg/mainwindow.h +++ b/noncore/unsupported/oipkg/mainwindow.h | |||
@@ -1,108 +1,108 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * * | 2 | * * |
3 | * This program is free software; you can redistribute it and/or modify * | 3 | * This program is free software; you can redistribute it and/or modify * |
4 | * it under the terms of the GNU General Public License as published by * | 4 | * it under the terms of the GNU General Public License as published by * |
5 | * the Free Software Foundation; either version 2 of the License, or * | 5 | * the Free Software Foundation; either version 2 of the License, or * |
6 | * (at your option) any later version. * | 6 | * (at your option) any later version. * |
7 | * * | 7 | * * |
8 | ***************************************************************************/ | 8 | ***************************************************************************/ |
9 | // Copyright (C) 2000 Trolltech AS. | 9 | // Copyright (C) 2000 Trolltech AS. |
10 | // adadpted form qpe/qipkg | 10 | // adadpted form qpe/qipkg |
11 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> | 11 | // (c) 2002 Patrick S. Vogt <tille@handhelds.org> |
12 | 12 | ||
13 | #ifndef MAINWINDOW_H | 13 | #ifndef MAINWINDOW_H |
14 | #define MAINWINDOW_H | 14 | #define MAINWINDOW_H |
15 | 15 | ||
16 | #include <qmainwindow.h> | 16 | #include <qmainwindow.h> |
17 | #include <qaction.h> | 17 | #include <qaction.h> |
18 | #include <qtimer.h> | 18 | #include <qtimer.h> |
19 | #include <qpopupmenu.h> | 19 | #include <qpopupmenu.h> |
20 | 20 | ||
21 | #include "package.h" | 21 | #include "package.h" |
22 | #include "packagelist.h" | 22 | #include "packagelist.h" |
23 | #include "packagelistremote.h" | 23 | #include "packagelistremote.h" |
24 | #include "packagelistlocal.h" | 24 | #include "packagelistlocal.h" |
25 | #include "packagelistdoclnk.h" | 25 | #include "packagelistdoclnk.h" |
26 | #include "pmipkg.h" | 26 | #include "pmipkg.h" |
27 | #include "pksettings.h" | 27 | #include "pksettings.h" |
28 | #include "packagelistview.h" | 28 | #include "packagelistview.h" |
29 | 29 | ||
30 | class QComboBox; | 30 | class QComboBox; |
31 | class QPEToolBar; | 31 | class QToolBar; |
32 | class QLineEdit; | 32 | class QLineEdit; |
33 | class PackageListItem; | 33 | class PackageListItem; |
34 | class QCopChannel; | 34 | class QCopChannel; |
35 | class QMessageBox; | 35 | class QMessageBox; |
36 | class QCheckBox; | 36 | class QCheckBox; |
37 | 37 | ||
38 | class MainWindow : public QMainWindow | 38 | class MainWindow : public QMainWindow |
39 | { | 39 | { |
40 | Q_OBJECT | 40 | Q_OBJECT |
41 | 41 | ||
42 | 42 | ||
43 | public: | 43 | public: |
44 | MainWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 44 | MainWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
45 | ~MainWindow(); | 45 | ~MainWindow(); |
46 | 46 | ||
47 | QCopChannel *channel; | 47 | QCopChannel *channel; |
48 | 48 | ||
49 | protected slots: | 49 | protected slots: |
50 | void runIpkg(); | 50 | void runIpkg(); |
51 | void updateList(); | 51 | void updateList(); |
52 | void displayList(); | 52 | void displayList(); |
53 | void subSectionChanged(); | 53 | void subSectionChanged(); |
54 | void sectionChanged(); | 54 | void sectionChanged(); |
55 | void showSettings(int); | 55 | void showSettings(int); |
56 | void showSettingsSetup(); | 56 | void showSettingsSetup(); |
57 | void showSettingsSrv(); | 57 | void showSettingsSrv(); |
58 | void showSettingsDst(); | 58 | void showSettingsDst(); |
59 | 59 | ||
60 | public slots: | 60 | public slots: |
61 | void sectionClose(); | 61 | void sectionClose(); |
62 | void sectionShow(bool); | 62 | void sectionShow(bool); |
63 | void findClose(); | 63 | void findClose(); |
64 | void findShow(bool); | 64 | void findShow(bool); |
65 | void searchClose(); | 65 | void searchClose(); |
66 | void searchShow(bool); | 66 | void searchShow(bool); |
67 | void destClose(); | 67 | void destClose(); |
68 | void destShow(bool); | 68 | void destShow(bool); |
69 | void filterList(); | 69 | void filterList(); |
70 | void createLinks(); | 70 | void createLinks(); |
71 | void removeLinks(); | 71 | void removeLinks(); |
72 | void receive (const QCString &, const QByteArray &); | 72 | void receive (const QCString &, const QByteArray &); |
73 | void setDocument (const QString &); | 73 | void setDocument (const QString &); |
74 | void remotePackageQuery(); | 74 | void remotePackageQuery(); |
75 | 75 | ||
76 | private: | 76 | private: |
77 | void makeMenu(); | 77 | void makeMenu(); |
78 | void makeChannel(); | 78 | void makeChannel(); |
79 | void setSections(); | 79 | void setSections(); |
80 | void setSubSections(); | 80 | void setSubSections(); |
81 | bool updateIcon; | 81 | bool updateIcon; |
82 | 82 | ||
83 | PmIpkg* ipkg; | 83 | PmIpkg* ipkg; |
84 | PackageManagerSettings *settings; | 84 | PackageManagerSettings *settings; |
85 | PackageListLocal packageListServers; | 85 | PackageListLocal packageListServers; |
86 | PackageListRemote packageListSearch; | 86 | PackageListRemote packageListSearch; |
87 | PackageListDocLnk packageListDocLnk; | 87 | PackageListDocLnk packageListDocLnk; |
88 | PackageListView *listViewPackages; | 88 | PackageListView *listViewPackages; |
89 | QAction *runAction; | 89 | QAction *runAction; |
90 | QAction *updateAction; | 90 | QAction *updateAction; |
91 | QAction *findAction; | 91 | QAction *findAction; |
92 | QPEToolBar *findBar; | 92 | QToolBar *findBar; |
93 | QLineEdit *findEdit; | 93 | QLineEdit *findEdit; |
94 | QAction *searchAction; | 94 | QAction *searchAction; |
95 | QAction *searchCommit; | 95 | QAction *searchCommit; |
96 | QPEToolBar *searchBar; | 96 | QToolBar *searchBar; |
97 | QLineEdit *searchEdit; | 97 | QLineEdit *searchEdit; |
98 | QAction *sectionAction; | 98 | QAction *sectionAction; |
99 | QPEToolBar *sectionBar; | 99 | QToolBar *sectionBar; |
100 | QComboBox *section; | 100 | QComboBox *section; |
101 | QComboBox *subsection; | 101 | QComboBox *subsection; |
102 | QAction *destAction; | 102 | QAction *destAction; |
103 | QPEToolBar *destBar; | 103 | QToolBar *destBar; |
104 | QComboBox *destination; | 104 | QComboBox *destination; |
105 | QCheckBox* CheckBoxLink; | 105 | QCheckBox* CheckBoxLink; |
106 | }; | 106 | }; |
107 | 107 | ||
108 | #endif | 108 | #endif |
diff --git a/noncore/unsupported/qpdf/qpdf.cpp b/noncore/unsupported/qpdf/qpdf.cpp index de1dcf3..5cdcccf 100644 --- a/noncore/unsupported/qpdf/qpdf.cpp +++ b/noncore/unsupported/qpdf/qpdf.cpp | |||
@@ -1,540 +1,540 @@ | |||
1 | //======================================================================== | 1 | //======================================================================== |
2 | // | 2 | // |
3 | // qpdf.cc | 3 | // qpdf.cc |
4 | // | 4 | // |
5 | // Copyright 2001 Robert Griebl | 5 | // Copyright 2001 Robert Griebl |
6 | // | 6 | // |
7 | //======================================================================== | 7 | //======================================================================== |
8 | 8 | ||
9 | #include "aconf.h" | 9 | #include "aconf.h" |
10 | #include "GString.h" | 10 | #include "GString.h" |
11 | #include "PDFDoc.h" | 11 | #include "PDFDoc.h" |
12 | #include "TextOutputDev.h" | 12 | #include "TextOutputDev.h" |
13 | 13 | ||
14 | #include "QPEOutputDev.h" | 14 | #include "QPEOutputDev.h" |
15 | 15 | ||
16 | #include <qpe/qpeapplication.h> | 16 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/resource.h> | 17 | #include <qpe/resource.h> |
18 | #include <qpe/applnk.h> | 18 | #include <qpe/applnk.h> |
19 | #include <qpe/qcopenvelope_qws.h> | 19 | #include <qpe/qcopenvelope_qws.h> |
20 | 20 | ||
21 | 21 | ||
22 | #include <qclipboard.h> | 22 | #include <qclipboard.h> |
23 | #include <qpe/qpetoolbar.h> | 23 | #include <qpe/qpetoolbar.h> |
24 | #include <qtoolbutton.h> | 24 | #include <qtoolbutton.h> |
25 | #include <qpe/qpemenubar.h> | 25 | #include <qmenubar.h> |
26 | #include <qpopupmenu.h> | 26 | #include <qpopupmenu.h> |
27 | #include <qwidgetstack.h> | 27 | #include <qwidgetstack.h> |
28 | #include <qtimer.h> | 28 | #include <qtimer.h> |
29 | #include <qfileinfo.h> | 29 | #include <qfileinfo.h> |
30 | #include <qstring.h> | 30 | #include <qstring.h> |
31 | #include <qlineedit.h> | 31 | #include <qlineedit.h> |
32 | #include <qspinbox.h> | 32 | #include <qspinbox.h> |
33 | #include <qlayout.h> | 33 | #include <qlayout.h> |
34 | #include <qdialog.h> | 34 | #include <qdialog.h> |
35 | #include <qlabel.h> | 35 | #include <qlabel.h> |
36 | #include <qmessagebox.h> | 36 | #include <qmessagebox.h> |
37 | 37 | ||
38 | #include "qpdf.h" | 38 | #include "qpdf.h" |
39 | 39 | ||
40 | #ifdef QPDF_QPE_ONLY | 40 | #ifdef QPDF_QPE_ONLY |
41 | #include <qpe/fileselector.h> | 41 | #include <qpe/fileselector.h> |
42 | #else | 42 | #else |
43 | #include <opie/ofileselector.h> | 43 | #include <opie/ofileselector.h> |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | 46 | ||
47 | int main ( int argc, char **argv ) | 47 | int main ( int argc, char **argv ) |
48 | { | 48 | { |
49 | QPEApplication app ( argc, argv ); | 49 | QPEApplication app ( argc, argv ); |
50 | 50 | ||
51 | // read config file | 51 | // read config file |
52 | globalParams = new GlobalParams ( "" ); | 52 | globalParams = new GlobalParams ( "" ); |
53 | globalParams-> setErrQuiet ( true ); | 53 | globalParams-> setErrQuiet ( true ); |
54 | 54 | ||
55 | QPdfDlg *dlg = new QPdfDlg ( ); | 55 | QPdfDlg *dlg = new QPdfDlg ( ); |
56 | app. showMainDocumentWidget ( dlg ); | 56 | app. showMainDocumentWidget ( dlg ); |
57 | 57 | ||
58 | if (( app. argc ( ) == 3 ) && ( app. argv ( ) [1] == QCString ( "-f" ))) | 58 | if (( app. argc ( ) == 3 ) && ( app. argv ( ) [1] == QCString ( "-f" ))) |
59 | dlg-> openFile ( app. argv ( ) [2] ); | 59 | dlg-> openFile ( app. argv ( ) [2] ); |
60 | 60 | ||
61 | return app. exec ( ); | 61 | return app. exec ( ); |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
65 | QPdfDlg::QPdfDlg ( ) : QMainWindow ( ) | 65 | QPdfDlg::QPdfDlg ( ) : QMainWindow ( ) |
66 | { | 66 | { |
67 | setCaption ( tr( "QPdf" )); | 67 | setCaption ( tr( "QPdf" )); |
68 | setIcon ( Resource::loadPixmap ( "qpdf_icon" )); | 68 | setIcon ( Resource::loadPixmap ( "qpdf_icon" )); |
69 | 69 | ||
70 | m_busy = false; | 70 | m_busy = false; |
71 | 71 | ||
72 | m_doc = 0; | 72 | m_doc = 0; |
73 | m_pages = 0; | 73 | m_pages = 0; |
74 | m_zoom = 72; | 74 | m_zoom = 72; |
75 | m_currentpage = 0; | 75 | m_currentpage = 0; |
76 | 76 | ||
77 | m_fullscreen = false; | 77 | m_fullscreen = false; |
78 | m_renderok = false; | 78 | m_renderok = false; |
79 | 79 | ||
80 | 80 | ||
81 | setToolBarsMovable ( false ); | 81 | setToolBarsMovable ( false ); |
82 | 82 | ||
83 | m_stack = new QWidgetStack ( this ); | 83 | m_stack = new QWidgetStack ( this ); |
84 | m_stack-> setSizePolicy ( QSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding )); | 84 | m_stack-> setSizePolicy ( QSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding )); |
85 | setCentralWidget ( m_stack ); | 85 | setCentralWidget ( m_stack ); |
86 | 86 | ||
87 | m_outdev = new QPEOutputDev ( m_stack ); | 87 | m_outdev = new QPEOutputDev ( m_stack ); |
88 | connect ( m_outdev, SIGNAL( selectionChanged ( const QRect & )), this, SLOT( copyToClipboard ( const QRect & ))); | 88 | connect ( m_outdev, SIGNAL( selectionChanged ( const QRect & )), this, SLOT( copyToClipboard ( const QRect & ))); |
89 | 89 | ||
90 | #ifdef QPDF_QPE_ONLY | 90 | #ifdef QPDF_QPE_ONLY |
91 | m_filesel = new FileSelector ( "application/pdf", m_stack, "fs", false, true ); | 91 | m_filesel = new FileSelector ( "application/pdf", m_stack, "fs", false, true ); |
92 | #else | 92 | #else |
93 | m_filesel = new OFileSelector ( "application/pdf", m_stack, "fs", false, true ); | 93 | m_filesel = new OFileSelector ( "application/pdf", m_stack, "fs", false, true ); |
94 | #endif | 94 | #endif |
95 | 95 | ||
96 | connect ( m_filesel, SIGNAL( closeMe ( )), this, SLOT( closeFileSelector ( ))); | 96 | connect ( m_filesel, SIGNAL( closeMe ( )), this, SLOT( closeFileSelector ( ))); |
97 | connect ( m_filesel, SIGNAL( fileSelected ( const DocLnk & )), this, SLOT( openFile ( const DocLnk & ))); | 97 | connect ( m_filesel, SIGNAL( fileSelected ( const DocLnk & )), this, SLOT( openFile ( const DocLnk & ))); |
98 | 98 | ||
99 | m_tb_menu = new QToolBar ( this ); | 99 | m_tb_menu = new QToolBar ( this ); |
100 | m_tb_menu-> setHorizontalStretchable ( true ); | 100 | m_tb_menu-> setHorizontalStretchable ( true ); |
101 | 101 | ||
102 | QMenuBar *mb = new QMenuBar ( m_tb_menu ); | 102 | QMenuBar *mb = new QMenuBar ( m_tb_menu ); |
103 | 103 | ||
104 | m_pm_zoom = new QPopupMenu ( mb ); | 104 | m_pm_zoom = new QPopupMenu ( mb ); |
105 | m_pm_zoom-> setCheckable ( true ); | 105 | m_pm_zoom-> setCheckable ( true ); |
106 | 106 | ||
107 | mb-> insertItem ( tr( "Zoom" ), m_pm_zoom ); | 107 | mb-> insertItem ( tr( "Zoom" ), m_pm_zoom ); |
108 | 108 | ||
109 | m_pm_zoom-> insertItem ( tr( "Fit to width" ), 1 ); | 109 | m_pm_zoom-> insertItem ( tr( "Fit to width" ), 1 ); |
110 | m_pm_zoom-> insertItem ( tr( "Fit to page" ), 2 ); | 110 | m_pm_zoom-> insertItem ( tr( "Fit to page" ), 2 ); |
111 | m_pm_zoom-> insertSeparator ( ); | 111 | m_pm_zoom-> insertSeparator ( ); |
112 | m_pm_zoom-> insertItem ( tr( "50%" ), 50 ); | 112 | m_pm_zoom-> insertItem ( tr( "50%" ), 50 ); |
113 | m_pm_zoom-> insertItem ( tr( "75%" ), 75 ); | 113 | m_pm_zoom-> insertItem ( tr( "75%" ), 75 ); |
114 | m_pm_zoom-> insertItem ( tr( "100%" ), 100 ); | 114 | m_pm_zoom-> insertItem ( tr( "100%" ), 100 ); |
115 | m_pm_zoom-> insertItem ( tr( "125%" ), 125 ); | 115 | m_pm_zoom-> insertItem ( tr( "125%" ), 125 ); |
116 | m_pm_zoom-> insertItem ( tr( "150%" ), 150 ); | 116 | m_pm_zoom-> insertItem ( tr( "150%" ), 150 ); |
117 | m_pm_zoom-> insertItem ( tr( "200%" ), 200 ); | 117 | m_pm_zoom-> insertItem ( tr( "200%" ), 200 ); |
118 | 118 | ||
119 | connect ( m_pm_zoom, SIGNAL( activated ( int )), this, SLOT( setZoom ( int ))); | 119 | connect ( m_pm_zoom, SIGNAL( activated ( int )), this, SLOT( setZoom ( int ))); |
120 | 120 | ||
121 | m_tb_tool = new QToolBar ( this ); | 121 | m_tb_tool = new QToolBar ( this ); |
122 | 122 | ||
123 | new QToolButton ( Resource::loadIconSet ( "fileopen" ), tr( "Open..." ), QString::null, this, SLOT( openFile ( )), m_tb_tool, "open" ); | 123 | new QToolButton ( Resource::loadIconSet ( "fileopen" ), tr( "Open..." ), QString::null, this, SLOT( openFile ( )), m_tb_tool, "open" ); |
124 | m_tb_tool-> addSeparator ( ); | 124 | m_tb_tool-> addSeparator ( ); |
125 | m_to_find = new QToolButton ( Resource::loadIconSet ( "find" ), tr( "Find..." ), QString::null, this, SLOT( toggleFindBar ( )), m_tb_tool, "find" ); | 125 | m_to_find = new QToolButton ( Resource::loadIconSet ( "find" ), tr( "Find..." ), QString::null, this, SLOT( toggleFindBar ( )), m_tb_tool, "find" ); |
126 | m_to_find-> setToggleButton ( true ); | 126 | m_to_find-> setToggleButton ( true ); |
127 | m_tb_tool-> addSeparator ( ); | 127 | m_tb_tool-> addSeparator ( ); |
128 | m_to_full = new QToolButton ( Resource::loadIconSet ( "fullscreen" ), tr( "Fullscreen" ), QString::null, this, SLOT( toggleFullscreen ( )), m_tb_tool, "fullscreen" ); | 128 | m_to_full = new QToolButton ( Resource::loadIconSet ( "fullscreen" ), tr( "Fullscreen" ), QString::null, this, SLOT( toggleFullscreen ( )), m_tb_tool, "fullscreen" ); |
129 | m_to_full-> setToggleButton ( true ); | 129 | m_to_full-> setToggleButton ( true ); |
130 | m_tb_tool-> addSeparator ( ); | 130 | m_tb_tool-> addSeparator ( ); |
131 | new QToolButton ( Resource::loadIconSet ( "fastback" ), tr( "First page" ), QString::null, this, SLOT( firstPage ( )), m_tb_tool, "first" ); | 131 | new QToolButton ( Resource::loadIconSet ( "fastback" ), tr( "First page" ), QString::null, this, SLOT( firstPage ( )), m_tb_tool, "first" ); |
132 | new QToolButton ( Resource::loadIconSet ( "back" ), tr( "Previous page" ), QString::null, this, SLOT( prevPage ( )), m_tb_tool, "prev" ); | 132 | new QToolButton ( Resource::loadIconSet ( "back" ), tr( "Previous page" ), QString::null, this, SLOT( prevPage ( )), m_tb_tool, "prev" ); |
133 | new QToolButton ( Resource::loadIconSet ( "down" ), tr( "Goto page..." ), QString::null, this, SLOT( gotoPageDialog ( )), m_tb_tool, "goto" ); | 133 | new QToolButton ( Resource::loadIconSet ( "down" ), tr( "Goto page..." ), QString::null, this, SLOT( gotoPageDialog ( )), m_tb_tool, "goto" ); |
134 | new QToolButton ( Resource::loadIconSet ( "forward" ), tr( "Next page" ), QString::null, this, SLOT( nextPage ( )), m_tb_tool, "next" ); | 134 | new QToolButton ( Resource::loadIconSet ( "forward" ), tr( "Next page" ), QString::null, this, SLOT( nextPage ( )), m_tb_tool, "next" ); |
135 | new QToolButton ( Resource::loadIconSet ( "fastforward" ), tr( "Last page" ), QString::null, this, SLOT( lastPage ( )), m_tb_tool, "last" ); | 135 | new QToolButton ( Resource::loadIconSet ( "fastforward" ), tr( "Last page" ), QString::null, this, SLOT( lastPage ( )), m_tb_tool, "last" ); |
136 | 136 | ||
137 | m_tb_find = new QToolBar ( this ); | 137 | m_tb_find = new QToolBar ( this ); |
138 | addToolBar ( m_tb_find, "Search", QMainWindow::Top, true ); | 138 | addToolBar ( m_tb_find, "Search", QMainWindow::Top, true ); |
139 | m_tb_find-> setHorizontalStretchable ( true ); | 139 | m_tb_find-> setHorizontalStretchable ( true ); |
140 | m_tb_find-> hide ( ); | 140 | m_tb_find-> hide ( ); |
141 | 141 | ||
142 | m_findedit = new QLineEdit ( m_tb_find, "findedit" ); | 142 | m_findedit = new QLineEdit ( m_tb_find, "findedit" ); |
143 | m_tb_find-> setStretchableWidget ( m_findedit ); | 143 | m_tb_find-> setStretchableWidget ( m_findedit ); |
144 | connect ( m_findedit, SIGNAL( textChanged ( const QString & )), this, SLOT( findText ( const QString & ))); | 144 | connect ( m_findedit, SIGNAL( textChanged ( const QString & )), this, SLOT( findText ( const QString & ))); |
145 | 145 | ||
146 | new QToolButton ( Resource::loadIconSet ( "next" ), tr( "Next" ), QString::null, this, SLOT( findText ( )), m_tb_find, "findnext" ); | 146 | new QToolButton ( Resource::loadIconSet ( "next" ), tr( "Next" ), QString::null, this, SLOT( findText ( )), m_tb_find, "findnext" ); |
147 | 147 | ||
148 | openFile ( ); | 148 | openFile ( ); |
149 | } | 149 | } |
150 | 150 | ||
151 | QPdfDlg::~QPdfDlg ( ) | 151 | QPdfDlg::~QPdfDlg ( ) |
152 | { | 152 | { |
153 | delete m_doc; | 153 | delete m_doc; |
154 | } | 154 | } |
155 | 155 | ||
156 | // vv Fullscreen handling (for broken QT-lib) [David Hedbor, www.eongames.com] | 156 | // vv Fullscreen handling (for broken QT-lib) [David Hedbor, www.eongames.com] |
157 | 157 | ||
158 | void QPdfDlg::resizeEvent ( QResizeEvent * ) | 158 | void QPdfDlg::resizeEvent ( QResizeEvent * ) |
159 | { | 159 | { |
160 | if ( m_fullscreen && ( size ( ) != qApp-> desktop ( )-> size ( ))) | 160 | if ( m_fullscreen && ( size ( ) != qApp-> desktop ( )-> size ( ))) |
161 | setFullscreen ( true ); | 161 | setFullscreen ( true ); |
162 | } | 162 | } |
163 | 163 | ||
164 | void QPdfDlg::focusInEvent ( QFocusEvent * ) | 164 | void QPdfDlg::focusInEvent ( QFocusEvent * ) |
165 | { | 165 | { |
166 | if ( m_fullscreen ) | 166 | if ( m_fullscreen ) |
167 | setFullscreen ( true ); | 167 | setFullscreen ( true ); |
168 | } | 168 | } |
169 | 169 | ||
170 | void QPdfDlg::toggleFullscreen ( ) | 170 | void QPdfDlg::toggleFullscreen ( ) |
171 | { | 171 | { |
172 | if ( m_to_full-> isOn ( ) == m_fullscreen ) | 172 | if ( m_to_full-> isOn ( ) == m_fullscreen ) |
173 | m_to_full-> setOn ( !m_fullscreen ); | 173 | m_to_full-> setOn ( !m_fullscreen ); |
174 | 174 | ||
175 | m_fullscreen = !m_fullscreen; | 175 | m_fullscreen = !m_fullscreen; |
176 | setFullscreen ( m_fullscreen ); | 176 | setFullscreen ( m_fullscreen ); |
177 | } | 177 | } |
178 | 178 | ||
179 | void QPdfDlg::setFullscreen ( bool b ) | 179 | void QPdfDlg::setFullscreen ( bool b ) |
180 | { | 180 | { |
181 | static QSize normalsize; | 181 | static QSize normalsize; |
182 | 182 | ||
183 | if ( b ) { | 183 | if ( b ) { |
184 | if ( !normalsize. isValid ( )) | 184 | if ( !normalsize. isValid ( )) |
185 | normalsize = size ( ); | 185 | normalsize = size ( ); |
186 | 186 | ||
187 | setFixedSize ( qApp-> desktop ( )-> size ( )); | 187 | setFixedSize ( qApp-> desktop ( )-> size ( )); |
188 | showNormal ( ); | 188 | showNormal ( ); |
189 | reparent ( 0, WStyle_Customize | WStyle_NoBorder, QPoint ( 0, 0 )); | 189 | reparent ( 0, WStyle_Customize | WStyle_NoBorder, QPoint ( 0, 0 )); |
190 | showFullScreen ( ); | 190 | showFullScreen ( ); |
191 | } | 191 | } |
192 | else { | 192 | else { |
193 | showNormal ( ); | 193 | showNormal ( ); |
194 | reparent ( 0, 0, QPoint ( 0, 0 )); | 194 | reparent ( 0, 0, QPoint ( 0, 0 )); |
195 | resize ( normalsize ); | 195 | resize ( normalsize ); |
196 | showMaximized ( ); | 196 | showMaximized ( ); |
197 | normalsize = QSize ( ); | 197 | normalsize = QSize ( ); |
198 | } | 198 | } |
199 | } | 199 | } |
200 | 200 | ||
201 | // ^^ Fullscreen handling (for broken QT-lib) | 201 | // ^^ Fullscreen handling (for broken QT-lib) |
202 | 202 | ||
203 | void QPdfDlg::setBusy ( bool b ) | 203 | void QPdfDlg::setBusy ( bool b ) |
204 | { | 204 | { |
205 | if ( b != m_busy ) { | 205 | if ( b != m_busy ) { |
206 | m_busy = b; | 206 | m_busy = b; |
207 | 207 | ||
208 | m_outdev-> setBusy ( m_busy ); | 208 | m_outdev-> setBusy ( m_busy ); |
209 | setEnabled ( !m_busy ); | 209 | setEnabled ( !m_busy ); |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
213 | bool QPdfDlg::busy ( ) const | 213 | bool QPdfDlg::busy ( ) const |
214 | { | 214 | { |
215 | return m_busy; | 215 | return m_busy; |
216 | } | 216 | } |
217 | 217 | ||
218 | 218 | ||
219 | void QPdfDlg::updateCaption ( ) | 219 | void QPdfDlg::updateCaption ( ) |
220 | { | 220 | { |
221 | QString cap = ""; | 221 | QString cap = ""; |
222 | 222 | ||
223 | if ( !m_currentdoc. isEmpty ( )) | 223 | if ( !m_currentdoc. isEmpty ( )) |
224 | cap = QString ( "%1 - " ). arg ( m_currentdoc ); | 224 | cap = QString ( "%1 - " ). arg ( m_currentdoc ); |
225 | cap += "QPdf"; | 225 | cap += "QPdf"; |
226 | 226 | ||
227 | setCaption ( cap ); | 227 | setCaption ( cap ); |
228 | } | 228 | } |
229 | 229 | ||
230 | 230 | ||
231 | void QPdfDlg::setZoom ( int id ) | 231 | void QPdfDlg::setZoom ( int id ) |
232 | { | 232 | { |
233 | int dpi = 0; | 233 | int dpi = 0; |
234 | 234 | ||
235 | switch ( id ) { | 235 | switch ( id ) { |
236 | case 1: | 236 | case 1: |
237 | if ( m_doc && m_doc-> isOk ( )) | 237 | if ( m_doc && m_doc-> isOk ( )) |
238 | dpi = m_outdev-> visibleWidth ( ) * 72 / m_doc-> getPageWidth ( m_currentpage ); | 238 | dpi = m_outdev-> visibleWidth ( ) * 72 / m_doc-> getPageWidth ( m_currentpage ); |
239 | break; | 239 | break; |
240 | 240 | ||
241 | case 2: | 241 | case 2: |
242 | if ( m_doc && m_doc-> isOk ( )) | 242 | if ( m_doc && m_doc-> isOk ( )) |
243 | dpi = QMIN( m_outdev-> visibleWidth ( ) * 72 / m_doc-> getPageWidth ( m_currentpage ), \ | 243 | dpi = QMIN( m_outdev-> visibleWidth ( ) * 72 / m_doc-> getPageWidth ( m_currentpage ), \ |
244 | m_outdev-> visibleHeight ( ) * 72 / m_doc-> getPageHeight ( m_currentpage )); | 244 | m_outdev-> visibleHeight ( ) * 72 / m_doc-> getPageHeight ( m_currentpage )); |
245 | break; | 245 | break; |
246 | 246 | ||
247 | default: | 247 | default: |
248 | dpi = id * 72 / 100; | 248 | dpi = id * 72 / 100; |
249 | break; | 249 | break; |
250 | } | 250 | } |
251 | 251 | ||
252 | if ( dpi < 18 ) | 252 | if ( dpi < 18 ) |
253 | dpi = 18; | 253 | dpi = 18; |
254 | if ( dpi > 216 ) | 254 | if ( dpi > 216 ) |
255 | dpi = 216; | 255 | dpi = 216; |
256 | 256 | ||
257 | for ( uint i = 0; i < m_pm_zoom-> count ( ); i++ ) { | 257 | for ( uint i = 0; i < m_pm_zoom-> count ( ); i++ ) { |
258 | int xid = m_pm_zoom-> idAt ( i ); | 258 | int xid = m_pm_zoom-> idAt ( i ); |
259 | m_pm_zoom-> setItemChecked ( xid, xid == id ); | 259 | m_pm_zoom-> setItemChecked ( xid, xid == id ); |
260 | } | 260 | } |
261 | 261 | ||
262 | if ( dpi != m_zoom ) { | 262 | if ( dpi != m_zoom ) { |
263 | m_zoom = dpi; | 263 | m_zoom = dpi; |
264 | 264 | ||
265 | renderPage ( ); | 265 | renderPage ( ); |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | 269 | ||
270 | void QPdfDlg::gotoPageDialog ( ) | 270 | void QPdfDlg::gotoPageDialog ( ) |
271 | { | 271 | { |
272 | QDialog *d = new QDialog ( this, "gotodlg", true ); | 272 | QDialog *d = new QDialog ( this, "gotodlg", true ); |
273 | d-> setCaption ( tr( "Goto page" )); | 273 | d-> setCaption ( tr( "Goto page" )); |
274 | 274 | ||
275 | QBoxLayout *lay = new QVBoxLayout ( d, 4, 4 ); | 275 | QBoxLayout *lay = new QVBoxLayout ( d, 4, 4 ); |
276 | 276 | ||
277 | QLabel *l = new QLabel ( tr( "Select from 1 .. %1:" ). arg ( m_pages ), d ); | 277 | QLabel *l = new QLabel ( tr( "Select from 1 .. %1:" ). arg ( m_pages ), d ); |
278 | lay-> addWidget ( l ); | 278 | lay-> addWidget ( l ); |
279 | 279 | ||
280 | QSpinBox *spin = new QSpinBox ( 1, m_pages, 1, d ); | 280 | QSpinBox *spin = new QSpinBox ( 1, m_pages, 1, d ); |
281 | spin-> setValue ( m_currentpage ); | 281 | spin-> setValue ( m_currentpage ); |
282 | spin-> setWrapping ( true ); | 282 | spin-> setWrapping ( true ); |
283 | spin-> setButtonSymbols ( QSpinBox::PlusMinus ); | 283 | spin-> setButtonSymbols ( QSpinBox::PlusMinus ); |
284 | lay-> addWidget ( spin ); | 284 | lay-> addWidget ( spin ); |
285 | 285 | ||
286 | if ( d-> exec ( ) == QDialog::Accepted ) { | 286 | if ( d-> exec ( ) == QDialog::Accepted ) { |
287 | gotoPage ( spin-> value ( )); | 287 | gotoPage ( spin-> value ( )); |
288 | } | 288 | } |
289 | 289 | ||
290 | delete d; | 290 | delete d; |
291 | } | 291 | } |
292 | 292 | ||
293 | void QPdfDlg::toggleFindBar ( ) | 293 | void QPdfDlg::toggleFindBar ( ) |
294 | { | 294 | { |
295 | if ( m_to_find-> isOn ( ) == m_tb_find-> isVisible ( )) | 295 | if ( m_to_find-> isOn ( ) == m_tb_find-> isVisible ( )) |
296 | m_to_find-> setOn ( !m_tb_find-> isVisible ( )); | 296 | m_to_find-> setOn ( !m_tb_find-> isVisible ( )); |
297 | 297 | ||
298 | if ( m_tb_find-> isVisible ( )) { | 298 | if ( m_tb_find-> isVisible ( )) { |
299 | m_tb_find-> hide ( ); | 299 | m_tb_find-> hide ( ); |
300 | m_outdev-> setFocus ( ); | 300 | m_outdev-> setFocus ( ); |
301 | } | 301 | } |
302 | else { | 302 | else { |
303 | m_tb_find-> show ( ); | 303 | m_tb_find-> show ( ); |
304 | m_findedit-> setFocus ( ); | 304 | m_findedit-> setFocus ( ); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | void QPdfDlg::findText ( const QString &str ) | 308 | void QPdfDlg::findText ( const QString &str ) |
309 | { | 309 | { |
310 | if ( !m_doc || !m_doc-> isOk ( ) || str. isEmpty ( )) | 310 | if ( !m_doc || !m_doc-> isOk ( ) || str. isEmpty ( )) |
311 | return; | 311 | return; |
312 | 312 | ||
313 | TextOutputDev *textOut = 0; | 313 | TextOutputDev *textOut = 0; |
314 | int pg = 0; | 314 | int pg = 0; |
315 | 315 | ||
316 | setBusy ( true ); | 316 | setBusy ( true ); |
317 | 317 | ||
318 | int len = str. length ( ); | 318 | int len = str. length ( ); |
319 | Unicode *u = new Unicode [len]; | 319 | Unicode *u = new Unicode [len]; |
320 | for ( int i = 0; i < len; i++ ) | 320 | for ( int i = 0; i < len; i++ ) |
321 | u [i] = str [i]. unicode ( ); | 321 | u [i] = str [i]. unicode ( ); |
322 | 322 | ||
323 | int xMin = 0, yMin = 0, xMax = 0, yMax = 0; | 323 | int xMin = 0, yMin = 0, xMax = 0, yMax = 0; |
324 | QRect selr = m_outdev-> selection ( ); | 324 | QRect selr = m_outdev-> selection ( ); |
325 | bool fromtop = true; | 325 | bool fromtop = true; |
326 | 326 | ||
327 | if ( selr. isValid ( )) { | 327 | if ( selr. isValid ( )) { |
328 | xMin = selr. right ( ); | 328 | xMin = selr. right ( ); |
329 | yMin = selr. top ( ) + selr. height ( ) / 2; | 329 | yMin = selr. top ( ) + selr. height ( ) / 2; |
330 | fromtop = false; | 330 | fromtop = false; |
331 | } | 331 | } |
332 | 332 | ||
333 | if ( m_outdev-> findText ( u, len, fromtop, true, &xMin, &yMin, &xMax, &yMax )) | 333 | if ( m_outdev-> findText ( u, len, fromtop, true, &xMin, &yMin, &xMax, &yMax )) |
334 | goto found; | 334 | goto found; |
335 | 335 | ||
336 | qApp-> processEvents ( ); | 336 | qApp-> processEvents ( ); |
337 | 337 | ||
338 | // search following pages | 338 | // search following pages |
339 | textOut = new TextOutputDev ( 0, gFalse, gFalse ); | 339 | textOut = new TextOutputDev ( 0, gFalse, gFalse ); |
340 | if ( !textOut-> isOk ( )) | 340 | if ( !textOut-> isOk ( )) |
341 | goto done; | 341 | goto done; |
342 | 342 | ||
343 | qApp-> processEvents ( ); | 343 | qApp-> processEvents ( ); |
344 | 344 | ||
345 | for ( pg = ( m_currentpage % m_pages ) + 1; pg != m_currentpage; pg = ( pg % m_pages ) + 1 ) { | 345 | for ( pg = ( m_currentpage % m_pages ) + 1; pg != m_currentpage; pg = ( pg % m_pages ) + 1 ) { |
346 | m_doc-> displayPage ( textOut, pg, 72, 0, gFalse ); | 346 | m_doc-> displayPage ( textOut, pg, 72, 0, gFalse ); |
347 | 347 | ||
348 | fp_t xMin1, yMin1, xMax1, yMax1; | 348 | fp_t xMin1, yMin1, xMax1, yMax1; |
349 | 349 | ||
350 | qApp-> processEvents ( ); | 350 | qApp-> processEvents ( ); |
351 | 351 | ||
352 | if ( textOut-> findText ( u, len, gTrue, gTrue, &xMin1, &yMin1, &xMax1, &yMax1 )) | 352 | if ( textOut-> findText ( u, len, gTrue, gTrue, &xMin1, &yMin1, &xMax1, &yMax1 )) |
353 | goto foundPage; | 353 | goto foundPage; |
354 | 354 | ||
355 | qApp-> processEvents ( ); | 355 | qApp-> processEvents ( ); |
356 | } | 356 | } |
357 | 357 | ||
358 | // search current page ending at current selection | 358 | // search current page ending at current selection |
359 | if ( selr. isValid ( )) { | 359 | if ( selr. isValid ( )) { |
360 | xMax = selr. left ( ); | 360 | xMax = selr. left ( ); |
361 | yMax = selr. top ( ) + selr. height ( ) / 2; | 361 | yMax = selr. top ( ) + selr. height ( ) / 2; |
362 | 362 | ||
363 | if ( m_outdev-> findText ( u, len, gTrue, gFalse, &xMin, &yMin, &xMax, &yMax )) | 363 | if ( m_outdev-> findText ( u, len, gTrue, gFalse, &xMin, &yMin, &xMax, &yMax )) |
364 | goto found; | 364 | goto found; |
365 | } | 365 | } |
366 | 366 | ||
367 | // not found | 367 | // not found |
368 | QMessageBox::information ( this, tr( "Find..." ), tr( "'%1' could not be found." ). arg ( str )); | 368 | QMessageBox::information ( this, tr( "Find..." ), tr( "'%1' could not be found." ). arg ( str )); |
369 | goto done; | 369 | goto done; |
370 | 370 | ||
371 | foundPage: | 371 | foundPage: |
372 | qApp-> processEvents ( ); | 372 | qApp-> processEvents ( ); |
373 | 373 | ||
374 | gotoPage ( pg ); | 374 | gotoPage ( pg ); |
375 | 375 | ||
376 | if ( !m_outdev-> findText ( u, len, gTrue, gTrue, &xMin, &yMin, &xMax, &yMax )) { | 376 | if ( !m_outdev-> findText ( u, len, gTrue, gTrue, &xMin, &yMin, &xMax, &yMax )) { |
377 | // this can happen if coalescing is bad | 377 | // this can happen if coalescing is bad |
378 | goto done; | 378 | goto done; |
379 | } | 379 | } |
380 | 380 | ||
381 | found: | 381 | found: |
382 | selr. setCoords ( xMin, yMin, xMax, yMax ); | 382 | selr. setCoords ( xMin, yMin, xMax, yMax ); |
383 | m_outdev-> setSelection ( selr, true ); // this will emit QPEOutputDev::selectionChanged ( ) -> copyToClipboard ( ) | 383 | m_outdev-> setSelection ( selr, true ); // this will emit QPEOutputDev::selectionChanged ( ) -> copyToClipboard ( ) |
384 | 384 | ||
385 | done: | 385 | done: |
386 | 386 | ||
387 | delete [] u; | 387 | delete [] u; |
388 | delete textOut; | 388 | delete textOut; |
389 | 389 | ||
390 | setBusy ( false ); | 390 | setBusy ( false ); |
391 | } | 391 | } |
392 | 392 | ||
393 | 393 | ||
394 | void QPdfDlg::findText ( ) | 394 | void QPdfDlg::findText ( ) |
395 | { | 395 | { |
396 | findText ( m_findedit-> text ( )); | 396 | findText ( m_findedit-> text ( )); |
397 | } | 397 | } |
398 | 398 | ||
399 | void QPdfDlg::copyToClipboard ( const QRect &r ) | 399 | void QPdfDlg::copyToClipboard ( const QRect &r ) |
400 | { | 400 | { |
401 | if ( m_doc && m_doc-> isOk ( ) && m_doc-> okToCopy ( )) | 401 | if ( m_doc && m_doc-> isOk ( ) && m_doc-> okToCopy ( )) |
402 | qApp-> clipboard ( )-> setText ( m_outdev-> getText ( r )); | 402 | qApp-> clipboard ( )-> setText ( m_outdev-> getText ( r )); |
403 | } | 403 | } |
404 | 404 | ||
405 | void QPdfDlg::firstPage ( ) | 405 | void QPdfDlg::firstPage ( ) |
406 | { | 406 | { |
407 | gotoPage ( 1 ); | 407 | gotoPage ( 1 ); |
408 | } | 408 | } |
409 | 409 | ||
410 | void QPdfDlg::prevPage ( ) | 410 | void QPdfDlg::prevPage ( ) |
411 | { | 411 | { |
412 | gotoPage ( m_currentpage - 1 ); | 412 | gotoPage ( m_currentpage - 1 ); |
413 | } | 413 | } |
414 | 414 | ||
415 | void QPdfDlg::nextPage ( ) | 415 | void QPdfDlg::nextPage ( ) |
416 | { | 416 | { |
417 | gotoPage ( m_currentpage + 1 ); | 417 | gotoPage ( m_currentpage + 1 ); |
418 | } | 418 | } |
419 | 419 | ||
420 | void QPdfDlg::lastPage ( ) | 420 | void QPdfDlg::lastPage ( ) |
421 | { | 421 | { |
422 | gotoPage ( m_pages ); | 422 | gotoPage ( m_pages ); |
423 | } | 423 | } |
424 | 424 | ||
425 | void QPdfDlg::gotoPage ( int n ) | 425 | void QPdfDlg::gotoPage ( int n ) |
426 | { | 426 | { |
427 | if ( n < 1 ) | 427 | if ( n < 1 ) |
428 | n = 1; | 428 | n = 1; |
429 | if ( n > m_pages ) | 429 | if ( n > m_pages ) |
430 | n = m_pages; | 430 | n = m_pages; |
431 | 431 | ||
432 | if ( n != m_currentpage ) { | 432 | if ( n != m_currentpage ) { |
433 | m_currentpage = n; | 433 | m_currentpage = n; |
434 | 434 | ||
435 | renderPage ( ); | 435 | renderPage ( ); |
436 | } | 436 | } |
437 | } | 437 | } |
438 | 438 | ||
439 | void QPdfDlg::renderPage ( ) | 439 | void QPdfDlg::renderPage ( ) |
440 | { | 440 | { |
441 | if ( m_renderok && m_doc && m_doc-> isOk ( )) { | 441 | if ( m_renderok && m_doc && m_doc-> isOk ( )) { |
442 | m_renderok = false; | 442 | m_renderok = false; |
443 | 443 | ||
444 | setBusy ( true ); | 444 | setBusy ( true ); |
445 | m_doc-> displayPage ( m_outdev, m_currentpage, m_zoom, 0, true ); | 445 | m_doc-> displayPage ( m_outdev, m_currentpage, m_zoom, 0, true ); |
446 | setBusy ( false ); | 446 | setBusy ( false ); |
447 | 447 | ||
448 | m_outdev-> setPageCount ( m_currentpage, m_pages ); | 448 | m_outdev-> setPageCount ( m_currentpage, m_pages ); |
449 | 449 | ||
450 | m_renderok = true; | 450 | m_renderok = true; |
451 | } | 451 | } |
452 | } | 452 | } |
453 | 453 | ||
454 | void QPdfDlg::closeFileSelector ( ) | 454 | void QPdfDlg::closeFileSelector ( ) |
455 | { | 455 | { |
456 | m_tb_menu-> show ( ); | 456 | m_tb_menu-> show ( ); |
457 | m_tb_tool-> show ( ); | 457 | m_tb_tool-> show ( ); |
458 | m_stack-> raiseWidget ( m_outdev ); | 458 | m_stack-> raiseWidget ( m_outdev ); |
459 | } | 459 | } |
460 | 460 | ||
461 | void QPdfDlg::openFile ( ) | 461 | void QPdfDlg::openFile ( ) |
462 | { | 462 | { |
463 | m_tb_menu-> hide ( ); | 463 | m_tb_menu-> hide ( ); |
464 | m_tb_tool-> hide ( ); | 464 | m_tb_tool-> hide ( ); |
465 | m_tb_find-> hide ( ); | 465 | m_tb_find-> hide ( ); |
466 | m_stack-> raiseWidget ( m_filesel ); | 466 | m_stack-> raiseWidget ( m_filesel ); |
467 | } | 467 | } |
468 | 468 | ||
469 | void QPdfDlg::openFile ( const QString &f ) | 469 | void QPdfDlg::openFile ( const QString &f ) |
470 | { | 470 | { |
471 | DocLnk nf; | 471 | DocLnk nf; |
472 | nf. setType ( "application/pdf" ); | 472 | nf. setType ( "application/pdf" ); |
473 | nf. setFile ( f ); | 473 | nf. setFile ( f ); |
474 | QFileInfo fi ( f ); | 474 | QFileInfo fi ( f ); |
475 | nf. setName ( fi. baseName ( )); | 475 | nf. setName ( fi. baseName ( )); |
476 | openFile ( nf ); | 476 | openFile ( nf ); |
477 | } | 477 | } |
478 | 478 | ||
479 | void QPdfDlg::openFile ( const DocLnk &f ) | 479 | void QPdfDlg::openFile ( const DocLnk &f ) |
480 | { | 480 | { |
481 | QString fn = f. file ( ); | 481 | QString fn = f. file ( ); |
482 | QFileInfo fi ( fn ); | 482 | QFileInfo fi ( fn ); |
483 | 483 | ||
484 | if ( fi. exists ( )) { | 484 | if ( fi. exists ( )) { |
485 | delete m_doc; | 485 | delete m_doc; |
486 | 486 | ||
487 | m_doc = new PDFDoc ( new GString ( fn. local8Bit ( )), 0, 0 ); | 487 | m_doc = new PDFDoc ( new GString ( fn. local8Bit ( )), 0, 0 ); |
488 | 488 | ||
489 | if ( m_doc-> isOk ( )) { | 489 | if ( m_doc-> isOk ( )) { |
490 | m_currentdoc = f. name ( ); | 490 | m_currentdoc = f. name ( ); |
491 | int sep = m_currentdoc. findRev ( '/' ); | 491 | int sep = m_currentdoc. findRev ( '/' ); |
492 | if ( sep > 0 ) | 492 | if ( sep > 0 ) |
493 | m_currentdoc = m_currentdoc. mid ( sep + 1 ); | 493 | m_currentdoc = m_currentdoc. mid ( sep + 1 ); |
494 | 494 | ||
495 | m_pages = m_doc-> getNumPages ( ); | 495 | m_pages = m_doc-> getNumPages ( ); |
496 | m_currentpage = 0; | 496 | m_currentpage = 0; |
497 | 497 | ||
498 | QTimer::singleShot ( 0, this, SLOT( delayedInit ( ))); | 498 | QTimer::singleShot ( 0, this, SLOT( delayedInit ( ))); |
499 | } | 499 | } |
500 | else { | 500 | else { |
501 | delete m_doc; | 501 | delete m_doc; |
502 | m_doc = 0; | 502 | m_doc = 0; |
503 | 503 | ||
504 | m_currentdoc = QString::null; | 504 | m_currentdoc = QString::null; |
505 | } | 505 | } |
506 | 506 | ||
507 | updateCaption ( ); | 507 | updateCaption ( ); |
508 | } | 508 | } |
509 | else | 509 | else |
510 | QMessageBox::warning ( this, tr( "Error" ), tr( "File does not exist!" )); | 510 | QMessageBox::warning ( this, tr( "Error" ), tr( "File does not exist!" )); |
511 | } | 511 | } |
512 | 512 | ||
513 | void QPdfDlg::setDocument ( const QString &f ) | 513 | void QPdfDlg::setDocument ( const QString &f ) |
514 | { | 514 | { |
515 | if ( f. find ( ".desktop", 0, true ) == -1 ) | 515 | if ( f. find ( ".desktop", 0, true ) == -1 ) |
516 | openFile ( f ); | 516 | openFile ( f ); |
517 | else | 517 | else |
518 | openFile ( DocLnk ( f )); | 518 | openFile ( DocLnk ( f )); |
519 | 519 | ||
520 | closeFileSelector ( ); | 520 | closeFileSelector ( ); |
521 | } | 521 | } |
522 | 522 | ||
523 | void QPdfDlg::delayedInit ( ) | 523 | void QPdfDlg::delayedInit ( ) |
524 | { | 524 | { |
525 | closeFileSelector ( ); | 525 | closeFileSelector ( ); |
526 | 526 | ||
527 | m_currentpage = 0; | 527 | m_currentpage = 0; |
528 | m_zoom = 0; | 528 | m_zoom = 0; |
529 | m_renderok = false; | 529 | m_renderok = false; |
530 | 530 | ||
531 | setZoom ( 100 ); | 531 | setZoom ( 100 ); |
532 | gotoPage ( 1 ); | 532 | gotoPage ( 1 ); |
533 | 533 | ||
534 | m_renderok = true; | 534 | m_renderok = true; |
535 | 535 | ||
536 | renderPage ( ); | 536 | renderPage ( ); |
537 | 537 | ||
538 | m_outdev-> setFocus ( ); | 538 | m_outdev-> setFocus ( ); |
539 | } | 539 | } |
540 | 540 | ||