ksync Library API Documentation

ksync.cpp

00001 /* 00002 This file is part of ksync. 00003 00004 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 #include <qdir.h> 00023 #include <qprinter.h> 00024 #include <qpainter.h> 00025 00026 #include <kiconloader.h> 00027 #include <kmessagebox.h> 00028 #include <kfiledialog.h> 00029 #include <kmenubar.h> 00030 #include <klocale.h> 00031 #include <kconfig.h> 00032 #include <kstdaction.h> 00033 00034 #include "ksync.h" 00035 #include "ksync.moc" 00036 #include "ksyncview.h" 00037 #include <kstatusbar.h> 00038 00039 #define ID_STATUS_MSG 1 00040 00041 KSync::KSync(QWidget* , const char* name):KMainWindow(0, name) 00042 { 00043 config=kapp->config(); 00044 00045 initStatusBar(); 00046 initActions(); 00047 initView(); 00048 00049 readOptions(); 00050 00051 // disable actions at startup 00052 fileSave->setEnabled(false); 00053 fileSaveAs->setEnabled(false); 00054 filePrint->setEnabled(false); 00055 editCut->setEnabled(false); 00056 editCopy->setEnabled(false); 00057 editPaste->setEnabled(false); 00058 setAutoSaveSettings(); 00059 } 00060 00061 void KSync::initActions() 00062 { 00063 fileNewWindow = new KAction(i18n("New &Window"), 0, 0, this, SLOT(slotFileNewWindow()), actionCollection(),"file_new_window"); 00064 fileNew = KStdAction::openNew(this, SLOT(slotFileNew()), actionCollection()); 00065 fileOpen = KStdAction::open(this, SLOT(slotFileOpen()), actionCollection()); 00066 fileOpenRecent = KStdAction::openRecent(this, SLOT(slotFileOpenRecent(const KURL&)), actionCollection()); 00067 fileSave = KStdAction::save(this, SLOT(slotFileSave()), actionCollection()); 00068 fileSaveAs = KStdAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection()); 00069 fileClose = KStdAction::close(this, SLOT(slotFileClose()), actionCollection()); 00070 filePrint = KStdAction::print(this, SLOT(slotFilePrint()), actionCollection()); 00071 fileQuit = KStdAction::quit(this, SLOT(slotFileQuit()), actionCollection()); 00072 editCut = KStdAction::cut(this, SLOT(slotEditCut()), actionCollection()); 00073 editCopy = KStdAction::copy(this, SLOT(slotEditCopy()), actionCollection()); 00074 editPaste = KStdAction::paste(this, SLOT(slotEditPaste()), actionCollection()); 00075 createStandardStatusBarAction(); 00076 setStandardToolBarMenuEnabled(true); 00077 00078 fileNewWindow->setStatusText(i18n("Opens a new application window")); 00079 fileNew->setStatusText(i18n("Creates a new document")); 00080 fileOpen->setStatusText(i18n("Opens an existing document")); 00081 fileOpenRecent->setStatusText(i18n("Opens a recently used file")); 00082 fileSave->setStatusText(i18n("Saves the actual document")); 00083 fileSaveAs->setStatusText(i18n("Saves the actual document as...")); 00084 fileClose->setStatusText(i18n("Closes the actual document")); 00085 filePrint ->setStatusText(i18n("Prints out the actual document")); 00086 fileQuit->setStatusText(i18n("Quits the application")); 00087 editCut->setStatusText(i18n("Cuts the selected section and puts it to the clipboard")); 00088 editCopy->setStatusText(i18n("Copies the selected section to the clipboard")); 00089 editPaste->setStatusText(i18n("Pastes the clipboard contents to actual position")); 00090 00091 // use the absolute path to your ksyncui.rc file for testing purpose in createGUI(); 00092 createGUI(); 00093 00094 } 00095 00096 00097 void KSync::initStatusBar() 00098 { 00099 statusBar()->insertItem(i18n("Ready."), ID_STATUS_MSG); 00100 } 00101 00102 void KSync::initView() 00103 { 00104 mView = new KSyncView(this); 00105 setCentralWidget(mView); 00106 // setCaption(doc->URL().fileName(),false); 00107 } 00108 00109 void KSync::openDocumentFile(const KURL& url) 00110 { 00111 slotStatusMsg(i18n("Opening file...")); 00112 00113 // doc->openDocument( url); 00114 fileOpenRecent->addURL( url ); 00115 slotStatusMsg(i18n("Ready.")); 00116 } 00117 00118 00119 void KSync::saveOptions() 00120 { 00121 config->setGroup("General Options"); 00122 fileOpenRecent->saveEntries(config,"Recent Files"); 00123 00124 mView->writeConfig(config); 00125 } 00126 00127 00128 void KSync::readOptions() 00129 { 00130 config->setGroup("General Options"); 00131 00132 // initialize the recent file list 00133 fileOpenRecent->loadEntries(config,"Recent Files"); 00134 mView->readConfig(config); 00135 } 00136 00137 void KSync::saveProperties(KConfig *) 00138 { 00139 #if 0 00140 if(doc->URL().fileName()!=i18n("Untitled") && !doc->isModified()) 00141 { 00142 // saving to tempfile not necessary 00143 00144 } 00145 else 00146 { 00147 KURL url=doc->URL(); 00148 _cfg->writePathEntry("filename", url.url()); 00149 _cfg->writeEntry("modified", doc->isModified()); 00150 QString tempname = kapp->tempSaveName(url.url()); 00151 QString tempurl= KURL::encode_string(tempname); 00152 KURL _url(tempurl); 00153 doc->saveDocument(_url); 00154 } 00155 #endif 00156 } 00157 00158 00159 void KSync::readProperties(KConfig *) 00160 { 00161 #if 0 00162 QString filename = _cfg->readPathEntry("filename"); 00163 KURL url(filename); 00164 bool modified = _cfg->readBoolEntry("modified", false); 00165 if(modified) 00166 { 00167 bool canRecover; 00168 QString tempname = kapp->checkRecoverFile(filename, canRecover); 00169 KURL _url(tempname); 00170 00171 if(canRecover) 00172 { 00173 doc->openDocument(_url); 00174 doc->setModified(); 00175 setCaption(_url.fileName(),true); 00176 QFile::remove(tempname); 00177 } 00178 } 00179 else 00180 { 00181 if(!filename.isEmpty()) 00182 { 00183 doc->openDocument(url); 00184 setCaption(url.fileName(),false); 00185 } 00186 } 00187 #endif 00188 } 00189 00190 bool KSync::queryClose() 00191 { 00192 // return doc->saveModified(); 00193 return true; 00194 } 00195 00196 bool KSync::queryExit() 00197 { 00198 saveOptions(); 00199 return true; 00200 } 00201 00202 void KSync::slotFileNewWindow() 00203 { 00204 slotStatusMsg(i18n("Opening a new application window...")); 00205 00206 KSync *new_window= new KSync(); 00207 new_window->show(); 00208 00209 slotStatusMsg(i18n("Ready.")); 00210 } 00211 00212 void KSync::slotFileNew() 00213 { 00214 slotStatusMsg(i18n("Creating new document...")); 00215 00216 #if 0 00217 if(!doc->saveModified()) 00218 { 00219 // here saving wasn't successful 00220 00221 } 00222 else 00223 { 00224 doc->newDocument(); 00225 setCaption(doc->URL().fileName(), false); 00226 } 00227 #endif 00228 00229 slotStatusMsg(i18n("Ready.")); 00230 } 00231 00232 void KSync::slotFileOpen() 00233 { 00234 slotStatusMsg(i18n("Opening file...")); 00235 00236 #if 0 00237 if(!doc->saveModified()) 00238 { 00239 // here saving wasn't successful 00240 00241 } 00242 else 00243 { 00244 KURL url=KFileDialog::getOpenURL(QString::null, 00245 i18n("*|All Files"), this, i18n("Open File")); 00246 if(!url.isEmpty()) 00247 { 00248 doc->openDocument(url); 00249 setCaption(url.fileName(), false); 00250 fileOpenRecent->addURL( url ); 00251 } 00252 } 00253 #endif 00254 00255 slotStatusMsg(i18n("Ready.")); 00256 } 00257 00258 void KSync::slotFileOpenRecent(const KURL&) 00259 { 00260 slotStatusMsg(i18n("Opening file...")); 00261 00262 #if 0 00263 if(!doc->saveModified()) 00264 { 00265 // here saving wasn't successful 00266 } 00267 else 00268 { 00269 doc->openDocument(url); 00270 setCaption(url.fileName(), false); 00271 } 00272 #endif 00273 00274 slotStatusMsg(i18n("Ready.")); 00275 } 00276 00277 void KSync::slotFileSave() 00278 { 00279 slotStatusMsg(i18n("Saving file...")); 00280 00281 // doc->saveDocument(doc->URL()); 00282 00283 slotStatusMsg(i18n("Ready.")); 00284 } 00285 00286 void KSync::slotFileSaveAs() 00287 { 00288 slotStatusMsg(i18n("Saving file with a new filename...")); 00289 00290 KURL url=KFileDialog::getSaveURL(QDir::currentDirPath(), 00291 i18n("*|All Files"), this, i18n("Save As")); 00292 if(!url.isEmpty()) 00293 { 00294 // doc->saveDocument(url); 00295 fileOpenRecent->addURL(url); 00296 // setCaption(url.fileName(),doc->isModified()); 00297 } 00298 00299 slotStatusMsg(i18n("Ready.")); 00300 } 00301 00302 void KSync::slotFileClose() 00303 { 00304 slotStatusMsg(i18n("Closing file...")); 00305 00306 close(); 00307 00308 slotStatusMsg(i18n("Ready.")); 00309 } 00310 00311 void KSync::slotFilePrint() 00312 { 00313 slotStatusMsg(i18n("Printing...")); 00314 00315 QPrinter printer; 00316 if (printer.setup(this)) 00317 { 00318 mView->print(&printer); 00319 } 00320 00321 slotStatusMsg(i18n("Ready.")); 00322 } 00323 00324 void KSync::slotFileQuit() 00325 { 00326 slotStatusMsg(i18n("Exiting...")); 00327 saveOptions(); 00328 // close the first window, the list makes the next one the first again. 00329 // This ensures that queryClose() is called on each window to ask for closing 00330 KMainWindow* w; 00331 if(memberList) 00332 { 00333 for(w=memberList->first(); w!=0; w=memberList->first()) 00334 { 00335 // only close the window if the closeEvent is accepted. If the user presses Cancel on the saveModified() dialog, 00336 // the window and the application stay open. 00337 if(!w->close()) 00338 break; 00339 } 00340 } 00341 slotStatusMsg(i18n("Ready.")); 00342 } 00343 00344 void KSync::slotEditCut() 00345 { 00346 slotStatusMsg(i18n("Cutting selection...")); 00347 00348 slotStatusMsg(i18n("Ready.")); 00349 } 00350 00351 void KSync::slotEditCopy() 00352 { 00353 slotStatusMsg(i18n("Copying selection to clipboard...")); 00354 00355 slotStatusMsg(i18n("Ready.")); 00356 } 00357 00358 void KSync::slotEditPaste() 00359 { 00360 slotStatusMsg(i18n("Inserting clipboard contents...")); 00361 00362 slotStatusMsg(i18n("Ready.")); 00363 } 00364 00365 void KSync::slotStatusMsg(const QString &text) 00366 { 00367 statusBar()->clear(); 00368 statusBar()->changeItem(text, ID_STATUS_MSG); 00369 } 00370
KDE Logo
This file is part of the documentation for ksync Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:50:33 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003