25#include <tqlineedit.h>
27#include <tqprintdialog.h>
29#include <tqpaintdevicemetrics.h>
33#include <kiconloader.h>
34#include <tdemenubar.h>
35#include <kkeydialog.h>
37#include <tdeio/netaccess.h>
38#include <tdefiledialog.h>
41#include <kurlrequesterdlg.h>
43#include <tdemessagebox.h>
44#include <tdestandarddirs.h>
45#include <kedittoolbar.h>
46#include <tdestdaccel.h>
48#include <kstdaction.h>
51#include "kandyprefsdialog.h"
52#include "commandscheduler.h"
53#include "kandyprefs.h"
57#include <kstatusbar.h>
61 : TDEMainWindow( 0,
"Kandy" ),
64 mScheduler = scheduler;
66 mPreferencesDialog = 0;
74 setCentralWidget(mView);
79 statusBar()->insertItem(i18n(
" Disconnected "),0,0,
true);
81 setAutoSaveSettings();
84 connect(mView, TQ_SIGNAL(signalChangeStatusbar(
const TQString&)),
85 this, TQ_SLOT(changeStatusbar(
const TQString&)));
86 connect(mView, TQ_SIGNAL(signalChangeCaption(
const TQString&)),
87 this, TQ_SLOT(changeCaption(
const TQString&)));
89 connect(mView,TQ_SIGNAL(modifiedChanged(
bool)),TQ_SLOT(setTitle()));
91 TDEConfig *config = TDEGlobal::config();
92 config->setGroup(
"General");
93 TQString currentProfile = config->readEntry(
"CurrentProfile",
94 locate(
"appdata",
"default.kandy"));
95 if (!currentProfile.isEmpty())
load(currentProfile);
104 if (!mView->loadFile(filename)) {
105 KMessageBox::error(
this,i18n(
"Could not load file %1").arg(filename));
108 mFilename = filename;
112void Kandy::save(
const TQString & filename)
114 if (!filename.isEmpty()) {
115 if (!mView->saveFile(filename)) {
116 KMessageBox::error(
this,i18n(
"Could not save file %1.").arg(filename));
118 mFilename = filename;
124void Kandy::setupActions()
126 KStdAction::open(
this, TQ_SLOT(fileOpen()), actionCollection());
127 KStdAction::save(
this, TQ_SLOT(fileSave()), actionCollection());
128 KStdAction::saveAs(
this, TQ_SLOT(fileSaveAs()), actionCollection());
130 KStdAction::quit(
this, TQ_SLOT(close()), actionCollection());
132 createStandardStatusBarAction();
133 setStandardToolBarMenuEnabled(
true);
135 KStdAction::keyBindings(
this, TQ_SLOT(optionsConfigureKeys()), actionCollection());
136 KStdAction::configureToolbars(
this, TQ_SLOT(optionsConfigureToolbars()), actionCollection());
137 KStdAction::preferences(
this, TQ_SLOT(optionsPreferences()), actionCollection());
139 new TDEAction(i18n(
"Mobile GUI"),0,
this,TQ_SLOT(showMobileGui()),
140 actionCollection(),
"show_mobilegui");
142 mConnectAction =
new TDEAction(i18n(
"Connect"),0,
this,TQ_SLOT(modemConnect()),
143 actionCollection(),
"modem_connect");
144 mDisconnectAction =
new TDEAction(i18n(
"Disconnect"),0,
this,
145 TQ_SLOT(modemDisconnect()),actionCollection(),
169 TDEMainWindow::dragEnterEvent(event);
175void Kandy::dropEvent(TQDropEvent *event)
182 TDEMainWindow::dropEvent(event);
201void Kandy::fileOpen()
206 TQString filename = KFileDialog::getOpenFileName();
207 if (!filename.isEmpty())
load(filename);
210void Kandy::fileSave()
212 if (mFilename.isEmpty()) fileSaveAs();
213 else save(mFilename);
216void Kandy::fileSaveAs()
218 TQString filename = KFileDialog::getSaveFileName();
222void Kandy::filePrint()
227 if (!mPrinter) mPrinter =
new TQPrinter;
228 if (TQPrintDialog::getPrinterSetup(mPrinter))
237 TQPaintDeviceMetrics metrics(mPrinter);
238 mView->
print(&p, metrics.height(), metrics.width());
245void Kandy::optionsConfigureKeys()
247 KKeyDialog::configure( actionCollection(),
this );
250void Kandy::optionsConfigureToolbars()
253 saveMainWindowSettings( TDEGlobal::config(), autoSaveGroup() );
254 KEditToolbar dlg(actionCollection());
255 connect(&dlg, TQ_SIGNAL(newToolbarConfig()),
this, TQ_SLOT(newToolbarConfig()));
259void Kandy::newToolbarConfig()
264 applyMainWindowSettings( TDEGlobal::config(), autoSaveGroup() );
267void Kandy::optionsPreferences()
269 if (!mPreferencesDialog) {
271 mPreferencesDialog->readConfig();
274 mPreferencesDialog->show();
275 mPreferencesDialog->raise();
278void Kandy::changeStatusbar(
const TQString& text)
281 statusBar()->message(text);
284void Kandy::changeCaption(
const TQString& text)
290void Kandy::setTitle()
292 if (mFilename.isEmpty()) {
293 setCaption(i18n(
"New Profile"),mView->isModified());
295 setCaption(mFilename,mView->isModified());
299bool Kandy::queryClose()
301 if (mView->isModified()) {
302 switch (KMessageBox::warningYesNoCancel(
this,
303 i18n(
"Save changes to profile %1?").arg(mFilename), TQString(), KStdGuiItem::save(), KStdGuiItem::discard())) {
304 case KMessageBox::Yes :
307 case KMessageBox::No :
317void Kandy::modemConnect()
319 if (!mScheduler->modem()->open()) {
320 KMessageBox::sorry(
this,
321 i18n(
"Cannot open modem device %1.")
322 .arg(KandyPrefs::serialDevice()), i18n(
"Modem Error"));
326 statusBar()->changeItem(i18n(
" Connected "),0);
328 emit connectStateChanged(
true);
331void Kandy::modemDisconnect()
333 mScheduler->modem()->close();
335 statusBar()->changeItem(i18n(
" Disconnected "),0);
337 emit connectStateChanged(
false);
340void Kandy::showMobileGui()
342 emit showMobileWin();
345void Kandy::showErrorMessage(
const TQString &text )
347 KMessageBox::error( 0, text );
Dialog to change the kandy configuration.
This is the main view class for Kandy.
void print(TQPainter *, int height, int width)
Print this view to any medium – paper or not.
virtual ~Kandy()
Default Destructor.
void saveProperties(TDEConfig *)
This function is called when it is time for the app to save its properties for session management pur...
void load(const TQString &url)
Use this method to load whatever file/URL you have.
Kandy(CommandScheduler *)
Default Constructor.
void readProperties(TDEConfig *)
This function is called when this app is restored.
virtual void dragEnterEvent(TQDragEnterEvent *event)
Overridden virtuals for TQt drag 'n drop (XDND)