1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
/*
This file is part of Kandy.
Copyright (c) 2000,2001,2002 Cornelius Schumacher <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
#include <tqlineedit.h>
#include <tqprinter.h>
#include <tqprintdialog.h>
#include <tqpainter.h>
#include <tqpaintdevicemetrics.h>
#include <kglobal.h>
#include <klocale.h>
#include <kiconloader.h>
#include <kmenubar.h>
#include <kkeydialog.h>
#include <kaccel.h>
#include <kio/netaccess.h>
#include <kfiledialog.h>
#include <kconfig.h>
#include <kurl.h>
#include <kurlrequesterdlg.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <kedittoolbar.h>
#include <kstdaccel.h>
#include <kaction.h>
#include <kstdaction.h>
#include <kurldrag.h>
#include "kandyprefsdialog.h"
#include "commandscheduler.h"
#include "kandyprefs.h"
#include "modem.h"
#include "kandy.h"
#include <kstatusbar.h>
#include "kandy.moc"
Kandy::Kandy(CommandScheduler *scheduler)
: KMainWindow( 0, "Kandy" ),
mPrinter(0)
{
mScheduler = scheduler;
mPreferencesDialog = 0;
mView = new KandyView(mScheduler,this);
// accept dnd
setAcceptDrops(true);
// tell the KMainWindow that this is indeed the main widget
setCentralWidget(mView);
// then, setup our actions
setupActions();
statusBar()->insertItem(i18n(" Disconnected "),0,0,true);
setAutoSaveSettings();
// allow the view to change the statusbar and caption
connect(mView, TQT_SIGNAL(signalChangeStatusbar(const TQString&)),
this, TQT_SLOT(changeStatusbar(const TQString&)));
connect(mView, TQT_SIGNAL(signalChangeCaption(const TQString&)),
this, TQT_SLOT(changeCaption(const TQString&)));
connect(mView,TQT_SIGNAL(modifiedChanged(bool)),TQT_SLOT(setTitle()));
KConfig *config = KGlobal::config();
config->setGroup("General");
TQString currentProfile = config->readEntry("CurrentProfile",
locate("appdata","default.kandy"));
if (!currentProfile.isEmpty()) load(currentProfile);
}
Kandy::~Kandy()
{
}
void Kandy::load(const TQString& filename)
{
if (!mView->loadFile(filename)) {
KMessageBox::error(this,i18n("Could not load file %1").arg(filename));
}
mFilename = filename;
setTitle();
}
void Kandy::save(const TQString & filename)
{
if (!filename.isEmpty()) {
if (!mView->saveFile(filename)) {
KMessageBox::error(this,i18n("Could not save file %1.").arg(filename));
} else {
mFilename = filename;
setTitle();
}
}
}
void Kandy::setupActions()
{
KStdAction::open(this, TQT_SLOT(fileOpen()), actionCollection());
KStdAction::save(this, TQT_SLOT(fileSave()), actionCollection());
KStdAction::saveAs(this, TQT_SLOT(fileSaveAs()), actionCollection());
// KStdAction::print(this, TQT_SLOT(filePrint()), actionCollection());
KStdAction::quit(this, TQT_SLOT(close()), actionCollection());
createStandardStatusBarAction();
setStandardToolBarMenuEnabled(true);
KStdAction::keyBindings(this, TQT_SLOT(optionsConfigureKeys()), actionCollection());
KStdAction::configureToolbars(this, TQT_SLOT(optionsConfigureToolbars()), actionCollection());
KStdAction::preferences(this, TQT_SLOT(optionsPreferences()), actionCollection());
new KAction(i18n("Mobile GUI"),0,this,TQT_SLOT(showMobileGui()),
actionCollection(),"show_mobilegui");
mConnectAction = new KAction(i18n("Connect"),0,this,TQT_SLOT(modemConnect()),
actionCollection(),"modem_connect");
mDisconnectAction = new KAction(i18n("Disconnect"),0,this,
TQT_SLOT(modemDisconnect()),actionCollection(),
"modem_disconnect");
createGUI();
}
void Kandy::saveProperties(KConfig */*config*/)
{
// the 'config' object points to the session managed
// config file. anything you write here will be available
// later when this app is restored
}
void Kandy::readProperties(KConfig */*config*/)
{
// the 'config' object points to the session managed
// config file. this function is automatically called whenever
// the app is being restored. read in here whatever you wrote
// in 'saveProperties'
}
void Kandy::dragEnterEvent(TQDragEnterEvent *event)
{
// do nothing
KMainWindow::dragEnterEvent(event);
// accept uri drops only
// event->accept(KURLDrag::canDecode(event));
}
void Kandy::dropEvent(TQDropEvent *event)
{
// this is a very simplistic implementation of a drop event. we
// will only accept a dropped URL. the Qt dnd code can do *much*
// much more, so please read the docs there
// do nothing
KMainWindow::dropEvent(event);
/*
KURL::List list;
// see if we can decode a URI.. if not, just ignore it
if (KURLDrag::decode(event, list) && !list.isEmpty())
{
// okay, we have a URI.. process it
const KURL &url = uri.first();
if (url.isLocalFile())
{
// load in the file
load(url.path());
}
}
*/
}
void Kandy::fileOpen()
{
// this slot is called whenever the File->Open menu is selected,
// the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
// button is clicked
TQString filename = KFileDialog::getOpenFileName();
if (!filename.isEmpty()) load(filename);
}
void Kandy::fileSave()
{
if (mFilename.isEmpty()) fileSaveAs();
else save(mFilename);
}
void Kandy::fileSaveAs()
{
TQString filename = KFileDialog::getSaveFileName();
save(filename);
}
void Kandy::filePrint()
{
// this slot is called whenever the File->Print menu is selected,
// the Print shortcut is pressed (usually CTRL+P) or the Print toolbar
// button is clicked
if (!mPrinter) mPrinter = new QPrinter;
if (TQPrintDialog::getPrinterSetup(mPrinter))
{
// setup the printer. with Qt, you always "print" to a
// TQPainter.. whether the output medium is a pixmap, a screen,
// or paper
TQPainter p;
p.begin(mPrinter);
// we let our view do the actual printing
TQPaintDeviceMetrics metrics(mPrinter);
mView->print(&p, metrics.height(), metrics.width());
// and send the result to the printer
p.end();
}
}
void Kandy::optionsConfigureKeys()
{
KKeyDialog::configure( actionCollection(), this );
}
void Kandy::optionsConfigureToolbars()
{
// use the standard toolbar editor
saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
KEditToolbar dlg(actionCollection());
connect(&dlg, TQT_SIGNAL(newToolbarConfig()), this, TQT_SLOT(newToolbarConfig()));
dlg.exec();
}
void Kandy::newToolbarConfig()
{
// this slot is called when user clicks "Ok" or "Apply" in the toolbar editor.
// recreate our GUI, and re-apply the settings (e.g. "text under icons", etc.)
createGUI();
applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
}
void Kandy::optionsPreferences()
{
if (!mPreferencesDialog) {
mPreferencesDialog = new KandyPrefsDialog(this);
mPreferencesDialog->readConfig();
}
mPreferencesDialog->show();
mPreferencesDialog->raise();
}
void Kandy::changeStatusbar(const TQString& text)
{
// display the text on the statusbar
statusBar()->message(text);
}
void Kandy::changeCaption(const TQString& text)
{
// display the text on the caption
setCaption(text);
}
void Kandy::setTitle()
{
if (mFilename.isEmpty()) {
setCaption(i18n("New Profile"),mView->isModified());
} else {
setCaption(mFilename,mView->isModified());
}
}
bool Kandy::queryClose()
{
if (mView->isModified()) {
switch (KMessageBox::warningYesNoCancel(this,
i18n("Save changes to profile %1?").arg(mFilename), TQString::null, KStdGuiItem::save(), KStdGuiItem::discard())) {
case KMessageBox::Yes :
fileSave();
return true;
case KMessageBox::No :
return true;
default: // cancel
return false;
}
} else {
return true;
}
}
void Kandy::modemConnect()
{
if (!mScheduler->modem()->open()) {
KMessageBox::sorry(this,
i18n("Cannot open modem device %1.")
.arg(KandyPrefs::serialDevice()), i18n("Modem Error"));
return;
}
statusBar()->changeItem(i18n(" Connected "),0);
emit connectStateChanged(true);
}
void Kandy::modemDisconnect()
{
mScheduler->modem()->close();
statusBar()->changeItem(i18n(" Disconnected "),0);
emit connectStateChanged(false);
}
void Kandy::showMobileGui()
{
emit showMobileWin();
}
void Kandy::showErrorMessage( const TQString &text )
{
KMessageBox::error( 0, text );
}
|