Ran am2cmake.
[basket4.git] / src / mainwindow.cpp
blob2284beff0e978578b7ae30c134bc63fc8446df09
1 /***************************************************************************
2 * Copyright (C) 2003 by S�astien Laot *
3 * slaout@linux62.org *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <qtabwidget.h>
22 #include <qlayout.h>
23 #include <qtooltip.h>
24 #include <qcursor.h>
25 #include <q3whatsthis.h>
26 #include <q3valuelist.h>
27 #include <qregexp.h>
28 #include <q3buttongroup.h>
29 //Added by qt3to4:
30 #include <QMoveEvent>
31 #include <QResizeEvent>
32 #include <kstringhandler.h>
34 #include <ksqueezedtextlabel.h>
35 #include <qpoint.h>
36 #include <qpixmap.h>
37 #include <qinputdialog.h>
38 #include <kpopupmenu.h>
39 #include <kiconloader.h>
40 #include <kiconeffect.h>
41 #include <qicon.h>
42 #include <kaction.h>
43 #include <kapp.h>
44 #include <klocale.h>
45 #include <kmenubar.h>
46 #include <kedittoolbar.h>
47 #include <kdebug.h>
48 #include <qsignalmapper.h>
49 #include <qstringlist.h>
51 #include <qpainter.h>
52 #include <qstyle.h>
53 #include <kglobalsettings.h>
54 #include <kstandarddirs.h>
55 #include <qdir.h>
56 #include <qstringlist.h>
57 #include <kmessagebox.h>
58 #include <kstatusbar.h>
59 #include <qtimer.h>
60 #include <qaction.h>
61 #include <kstdaccel.h>
62 #include <kglobalaccel.h>
63 #include <kkeydialog.h>
64 #include <kpassivepopup.h>
65 #include <kconfig.h>
66 #include <kcolordialog.h>
67 #include <kaboutdata.h>
69 #include <kdeversion.h>
70 #include <qdesktopwidget.h>
71 #include <kwin.h>
73 #include <kprogress.h>
75 #include "mainwindow.h"
76 #include "basket.h"
77 #include "basketproperties.h"
78 #include "note.h"
79 #include "noteedit.h"
80 #include "settings.h"
81 #include "global.h"
82 //#include "addbasketwizard.h"
83 #include "newbasketdialog.h"
84 #include "basketfactory.h"
85 #include "popupmenu.h"
86 #include "xmlwork.h"
87 #include "debugwindow.h"
88 #include "notefactory.h"
89 #include "notedrag.h"
90 #include "tools.h"
91 #include "tag.h"
92 #include "formatimporter.h"
93 #include "softwareimporters.h"
94 #include "regiongrabber.h"
95 #include "password.h"
96 #include "bnpview.h"
97 #include "systemtray.h"
98 #include "clickablelabel.h"
99 #include "basketstatusbar.h"
100 #include <iostream>
101 #include <ksettings/dialog.h>
102 #include <kcmultidialog.h>
104 /** Container */
106 MainWindow::MainWindow(QWidget *parent, const char *name)
107 : KMainWindow(parent, name != 0 ? name : "MainWindow"), m_settings(0), m_quit(false)
109 BasketStatusBar* bar = new BasketStatusBar(statusBar());
110 m_baskets = new BNPView(this, "BNPViewApp", this, actionCollection(), bar);
111 setCentralWidget(m_baskets);
113 setupActions();
114 statusBar()->show();
115 statusBar()->setSizeGripEnabled(true);
117 setAutoSaveSettings(/*groupName=*/QString::fromLatin1("MainWindow"), /*saveWindowSize=*//*FIXME:false:Why was it false??*/true);
119 // m_actShowToolbar->setChecked( toolBar()->isShown() );
120 m_actShowStatusbar->setChecked( statusBar()->isShown() );
121 connect( m_baskets, SIGNAL(setWindowCaption(const QString &)), this, SLOT(setCaption(const QString &)));
123 // InlineEditors::instance()->richTextToolBar();
124 setStandardToolBarMenuEnabled(true);
126 createGUI("basketui.rc");
127 applyMainWindowSettings(KGlobal::config(), autoSaveGroup());
130 MainWindow::~MainWindow()
132 saveMainWindowSettings(KGlobal::config(), autoSaveGroup());
133 delete m_settings;
136 void MainWindow::setupActions()
138 actQuit = KStdAction::quit( this, SLOT(quit()), actionCollection() );
139 new KAction(i18n("Minimize"), "", 0,
140 this, SLOT(minimizeRestore()), actionCollection(), "minimizeRestore" );
141 /** Settings : ************************************************************/
142 // m_actShowToolbar = KStdAction::showToolbar( this, SLOT(toggleToolBar()), actionCollection());
143 m_actShowStatusbar = KStdAction::showStatusbar( this, SLOT(toggleStatusBar()), actionCollection());
145 // m_actShowToolbar->setCheckedState( KGuiItem(i18n("Hide &Toolbar")) );
147 (void) KStdAction::keyBindings( this, SLOT(showShortcutsSettingsDialog()), actionCollection() );
149 (void) KStdAction::configureToolbars(this, SLOT(configureToolbars()), actionCollection() );
151 //KAction *actCfgNotifs = KStdAction::configureNotifications(this, SLOT(configureNotifications()), actionCollection() );
152 //actCfgNotifs->setEnabled(false); // Not yet implemented !
154 actAppConfig = KStdAction::preferences( this, SLOT(showSettingsDialog()), actionCollection() );
157 /*void MainWindow::toggleToolBar()
159 if (toolBar()->isVisible())
160 toolBar()->hide();
161 else
162 toolBar()->show();
164 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
167 void MainWindow::toggleStatusBar()
169 if (statusBar()->isVisible())
170 statusBar()->hide();
171 else
172 statusBar()->show();
174 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
177 void MainWindow::configureToolbars()
179 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
181 KEditToolbar dlg(actionCollection());
182 connect( &dlg, SIGNAL(newToolbarConfig()), this, SLOT(slotNewToolbarConfig()) );
183 dlg.exec();
186 void MainWindow::configureNotifications()
188 // TODO
189 // KNotifyDialog *dialog = new KNotifyDialog(this, "KNotifyDialog", false);
190 // dialog->show();
193 void MainWindow::slotNewToolbarConfig() // This is called when OK or Apply is clicked
195 // ...if you use any action list, use plugActionList on each here...
196 createGUI("basketui.rc"); // TODO: Reconnect tags menu aboutToShow() ??
197 if (!Global::bnpView->isPart())
198 Global::bnpView->connectTagsMenu(); // The Tags menu was created again!
199 plugActionList( QString::fromLatin1("go_baskets_list"), actBasketsList);
200 applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
203 void MainWindow::showSettingsDialog()
205 if(m_settings == 0)
206 m_settings = new KSettings::Dialog(kapp->activeWindow());
207 if (Global::mainWindow()) {
208 m_settings->dialog()->showButton(KDialogBase::Help, false); // Not implemented!
209 m_settings->dialog()->showButton(KDialogBase::Default, false); // Not implemented!
210 m_settings->dialog()->exec();
211 } else
212 m_settings->show();
215 void MainWindow::showShortcutsSettingsDialog()
217 KKeyDialog::configure(actionCollection(), "basketui.rc");
218 //.setCaption(..)
219 //actionCollection()->writeSettings();
222 void MainWindow::polish()
224 bool shouldSave = false;
226 // If position and size has never been set, set nice ones:
227 // - Set size to sizeHint()
228 // - Keep the window manager placing the window where it want and save this
229 if (Settings::mainWindowSize().isEmpty()) {
230 // std::cout << "Main Window Position: Initial Set in show()" << std::endl;
231 int defaultWidth = kapp->desktop()->width() * 5 / 6;
232 int defaultHeight = kapp->desktop()->height() * 5 / 6;
233 resize(defaultWidth, defaultHeight); // sizeHint() is bad (too small) and we want the user to have a good default area size
234 shouldSave = true;
235 } else {
236 // std::cout << "Main Window Position: Recall in show(x="
237 // << Settings::mainWindowPosition().x() << ", y=" << Settings::mainWindowPosition().y()
238 // << ", width=" << Settings::mainWindowSize().width() << ", height=" << Settings::mainWindowSize().height()
239 // << ")" << std::endl;
240 //move(Settings::mainWindowPosition());
241 //resize(Settings::mainWindowSize());
244 KMainWindow::polish();
246 if (shouldSave) {
247 // std::cout << "Main Window Position: Save size and position in show(x="
248 // << pos().x() << ", y=" << pos().y()
249 // << ", width=" << size().width() << ", height=" << size().height()
250 // << ")" << std::endl;
251 Settings::setMainWindowPosition(pos());
252 Settings::setMainWindowSize(size());
253 Settings::saveConfig();
257 void MainWindow::resizeEvent(QResizeEvent *event)
259 // std::cout << "Main Window Position: Save size in resizeEvent(width=" << size().width() << ", height=" << size().height() << ") ; isMaximized="
260 // << (isMaximized() ? "true" : "false") << std::endl;
261 Settings::setMainWindowSize(size());
262 Settings::saveConfig();
264 // Added to make it work (previous lines do not work):
265 //saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
266 KMainWindow::resizeEvent(event);
269 void MainWindow::moveEvent(QMoveEvent *event)
271 // std::cout << "Main Window Position: Save position in moveEvent(x=" << pos().x() << ", y=" << pos().y() << ")" << std::endl;
272 Settings::setMainWindowPosition(pos());
273 Settings::saveConfig();
275 // Added to make it work (previous lines do not work):
276 //saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
277 KMainWindow::moveEvent(event);
280 bool MainWindow::queryExit()
282 hide();
283 return true;
286 void MainWindow::quit()
288 m_quit = true;
289 close();
292 bool MainWindow::queryClose()
294 /* if (m_shuttingDown) // Set in askForQuit(): we don't have to ask again
295 return true;*/
297 if (kapp->sessionSaving()) {
298 Settings::setStartDocked(false); // If queryClose() is called it's because the window is shown
299 Settings::saveConfig();
300 return true;
303 if (Settings::useSystray() && !m_quit) {
304 Global::systemTray->displayCloseMessage(i18n("Basket"));
305 hide();
306 return false;
307 } else
308 return askForQuit();
311 bool MainWindow::askForQuit()
313 QString message = i18n("<p>Do you really want to quit %1?</p>").arg(kapp->aboutData()->programName());
314 if (Settings::useSystray())
315 message += i18n("<p>Notice that you do not have to quit the application before ending your KDE session. "
316 "If you end your session while the application is still running, the application will be reloaded the next time you log in.</p>");
318 int really = KMessageBox::warningContinueCancel( this, message, i18n("Quit Confirm"),
319 KStdGuiItem::quit(), "confirmQuitAsking" );
321 if (really == KMessageBox::Cancel)
323 m_quit = false;
324 return false;
327 return true;
330 void MainWindow::minimizeRestore()
332 if(isVisible())
333 hide();
334 else
335 show();
338 void MainWindow::changeActive()
340 #if KDE_IS_VERSION( 3, 2, 90 ) // KDE 3.3.x
341 kapp->updateUserTimestamp(); // If "activate on mouse hovering systray", or "on drag throught systray"
342 Global::systemTray->toggleActive();
343 #else
344 setActive( ! isActiveWindow() );
345 #endif
348 #include "mainwindow.moc"