00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
#include <qlineedit.h>
00026
#include <qprinter.h>
00027
#include <qprintdialog.h>
00028
#include <qpainter.h>
00029
#include <qpaintdevicemetrics.h>
00030
00031
#include <kglobal.h>
00032
#include <klocale.h>
00033
#include <kiconloader.h>
00034
#include <kmenubar.h>
00035
#include <kkeydialog.h>
00036
#include <kaccel.h>
00037
#include <kio/netaccess.h>
00038
#include <kfiledialog.h>
00039
#include <kconfig.h>
00040
#include <kurl.h>
00041
#include <kurlrequesterdlg.h>
00042
#include <kdebug.h>
00043
#include <kmessagebox.h>
00044
#include <kstandarddirs.h>
00045
#include <kedittoolbar.h>
00046
#include <kstdaccel.h>
00047
#include <kaction.h>
00048
#include <kstdaction.h>
00049
#include <kurldrag.h>
00050
00051
#include "kandyprefsdialog.h"
00052
#include "commandscheduler.h"
00053
#include "kandyprefs.h"
00054
#include "modem.h"
00055
00056
#include "kandy.h"
00057
#include <kstatusbar.h>
00058
#include "kandy.moc"
00059
00060 Kandy::Kandy(CommandScheduler *scheduler)
00061 : KMainWindow( 0, "
Kandy" ),
00062 mPrinter(0)
00063 {
00064 mScheduler = scheduler;
00065
00066 mPreferencesDialog = 0;
00067
00068 mView =
new KandyView(mScheduler,
this);
00069
00070
00071 setAcceptDrops(
true);
00072
00073
00074 setCentralWidget(mView);
00075
00076
00077 setupActions();
00078
00079 statusBar()->insertItem(i18n(
" Disconnected "),0,0,
true);
00080
00081 setAutoSaveSettings();
00082
00083
00084 connect(mView, SIGNAL(signalChangeStatusbar(
const QString&)),
00085
this, SLOT(changeStatusbar(
const QString&)));
00086 connect(mView, SIGNAL(signalChangeCaption(
const QString&)),
00087
this, SLOT(changeCaption(
const QString&)));
00088
00089 connect(mView,SIGNAL(modifiedChanged(
bool)),SLOT(setTitle()));
00090
00091 KConfig *config = KGlobal::config();
00092 config->setGroup(
"General");
00093 QString currentProfile = config->readEntry(
"CurrentProfile",
00094 locate(
"appdata",
"default.kandy"));
00095
if (!currentProfile.isEmpty())
load(currentProfile);
00096 }
00097
00098 Kandy::~Kandy()
00099 {
00100 }
00101
00102 void Kandy::load(
const QString& filename)
00103 {
00104
if (!mView->
loadFile(filename)) {
00105 KMessageBox::error(
this,i18n(
"Could not load file %1").arg(filename));
00106 }
00107
00108 mFilename = filename;
00109 setTitle();
00110 }
00111
00112
void Kandy::save(
const QString & filename)
00113 {
00114
if (!filename.isEmpty()) {
00115
if (!mView->
saveFile(filename)) {
00116 KMessageBox::error(
this,i18n(
"Couldn't save file %1.").arg(filename));
00117 }
else {
00118 mFilename = filename;
00119 setTitle();
00120 }
00121 }
00122 }
00123
00124
void Kandy::setupActions()
00125 {
00126 KStdAction::open(
this, SLOT(fileOpen()), actionCollection());
00127 KStdAction::save(
this, SLOT(fileSave()), actionCollection());
00128 KStdAction::saveAs(
this, SLOT(fileSaveAs()), actionCollection());
00129
00130 KStdAction::quit(
this, SLOT(close()), actionCollection());
00131
00132 createStandardStatusBarAction();
00133 setStandardToolBarMenuEnabled(
true);
00134
00135 KStdAction::keyBindings(
this, SLOT(optionsConfigureKeys()), actionCollection());
00136 KStdAction::configureToolbars(
this, SLOT(optionsConfigureToolbars()), actionCollection());
00137 KStdAction::preferences(
this, SLOT(optionsPreferences()), actionCollection());
00138
00139
new KAction(i18n(
"Mobile GUI"),0,
this,SLOT(showMobileGui()),
00140 actionCollection(),
"show_mobilegui");
00141
00142 mConnectAction =
new KAction(i18n(
"Connect"),0,
this,SLOT(modemConnect()),
00143 actionCollection(),
"modem_connect");
00144 mDisconnectAction =
new KAction(i18n(
"Disconnect"),0,
this,
00145 SLOT(modemDisconnect()),actionCollection(),
00146
"modem_disconnect");
00147
00148 createGUI();
00149 }
00150
00151 void Kandy::saveProperties(KConfig *)
00152 {
00153
00154
00155
00156 }
00157
00158 void Kandy::readProperties(KConfig *)
00159 {
00160
00161
00162
00163
00164 }
00165
00166 void Kandy::dragEnterEvent(QDragEnterEvent *event)
00167 {
00168
00169 KMainWindow::dragEnterEvent(event);
00170
00171
00172
00173 }
00174
00175
void Kandy::dropEvent(QDropEvent *event)
00176 {
00177
00178
00179
00180
00181
00182 KMainWindow::dropEvent(event);
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 }
00200
00201
void Kandy::fileOpen()
00202 {
00203
00204
00205
00206 QString filename = KFileDialog::getOpenFileName();
00207
if (!filename.isEmpty())
load(filename);
00208 }
00209
00210
void Kandy::fileSave()
00211 {
00212
if (mFilename.isEmpty()) fileSaveAs();
00213
else save(mFilename);
00214 }
00215
00216
void Kandy::fileSaveAs()
00217 {
00218 QString filename = KFileDialog::getSaveFileName();
00219 save(filename);
00220 }
00221
00222
void Kandy::filePrint()
00223 {
00224
00225
00226
00227
if (!mPrinter) mPrinter =
new QPrinter;
00228
if (QPrintDialog::getPrinterSetup(mPrinter))
00229 {
00230
00231
00232
00233 QPainter p;
00234 p.begin(mPrinter);
00235
00236
00237 QPaintDeviceMetrics metrics(mPrinter);
00238 mView->
print(&p, metrics.height(), metrics.width());
00239
00240
00241 p.end();
00242 }
00243 }
00244
00245
void Kandy::optionsConfigureKeys()
00246 {
00247 KKeyDialog::configure( actionCollection(),
this );
00248 }
00249
00250
void Kandy::optionsConfigureToolbars()
00251 {
00252
00253 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
00254 KEditToolbar dlg(actionCollection());
00255 connect(&dlg, SIGNAL(newToolbarConfig()),
this, SLOT(newToolbarConfig()));
00256 dlg.exec();
00257 }
00258
00259
void Kandy::newToolbarConfig()
00260 {
00261
00262
00263 createGUI();
00264 applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
00265 }
00266
00267
void Kandy::optionsPreferences()
00268 {
00269
if (!mPreferencesDialog) {
00270 mPreferencesDialog =
new KandyPrefsDialog(
this);
00271 mPreferencesDialog->readConfig();
00272 }
00273
00274 mPreferencesDialog->show();
00275 mPreferencesDialog->raise();
00276 }
00277
00278
void Kandy::changeStatusbar(
const QString& text)
00279 {
00280
00281 statusBar()->message(text);
00282 }
00283
00284
void Kandy::changeCaption(
const QString& text)
00285 {
00286
00287 setCaption(text);
00288 }
00289
00290
void Kandy::setTitle()
00291 {
00292
if (mFilename.isEmpty()) {
00293 setCaption(i18n(
"New Profile"),mView->
isModified());
00294 }
else {
00295 setCaption(mFilename,mView->
isModified());
00296 }
00297 }
00298
00299
bool Kandy::queryClose()
00300 {
00301
if (mView->
isModified()) {
00302
switch (KMessageBox::warningYesNoCancel(
this,
00303 i18n(
"Save changes to profile %1?").arg(mFilename))) {
00304
case KMessageBox::Yes :
00305 fileSave();
00306
return true;
00307
case KMessageBox::No :
00308
return true;
00309
default:
00310
return false;
00311 }
00312 }
else {
00313
return true;
00314 }
00315 }
00316
00317
void Kandy::modemConnect()
00318 {
00319
if (!mScheduler->modem()->open()) {
00320 KMessageBox::sorry(
this,
00321 i18n(
"Cannot open modem device %1.")
00322 .arg(KandyPrefs::serialDevice()), i18n(
"Modem Error"));
00323
return;
00324 }
00325
00326 statusBar()->changeItem(i18n(
" Connected "),0);
00327
00328 emit connectStateChanged(
true);
00329 }
00330
00331
void Kandy::modemDisconnect()
00332 {
00333 mScheduler->modem()->close();
00334
00335 statusBar()->changeItem(i18n(
" Disconnected "),0);
00336
00337 emit connectStateChanged(
false);
00338 }
00339
00340
void Kandy::showMobileGui()
00341 {
00342 emit showMobileWin();
00343 }
00344
00345
void Kandy::showErrorMessage(
const QString &text )
00346 {
00347 KMessageBox::error( 0, text );
00348 }