Updated the README file with some contributor tips.
[basket4.git] / src / mainwindow.cpp
blob4d25642272c1e008fd352e2919a3711c2d501c56
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 <kmenu.h>
39 #include <kiconloader.h>
40 #include <kiconeffect.h>
41 #include <qicon.h>
42 #include <kaction.h>
43 #include <kapplication.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 <kwindowsystem.h>
73 #include <kprogressdialog.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>
103 #include <KShortcutsDialog>
105 /** Container */
107 MainWindow::MainWindow(QWidget *parent, const char *name)
108 : KMainWindow(parent, name != 0 ? name : "MainWindow"), m_settings(0), m_quit(false)
110 BasketStatusBar* bar = new BasketStatusBar(statusBar());
111 m_baskets = new BNPView(this, "BNPViewApp", this, actionCollection(), bar);
112 setCentralWidget(m_baskets);
114 setupActions();
115 statusBar()->show();
116 statusBar()->setSizeGripEnabled(true);
118 setAutoSaveSettings(/*groupName=*/QString::fromLatin1("MainWindow"), /*saveWindowSize=*//*FIXME:false:Why was it false??*/true);
120 // m_actShowToolbar->setChecked( toolBar()->isShown() );
121 m_actShowStatusbar->setChecked( statusBar()->isShown() );
122 connect( m_baskets, SIGNAL(setWindowCaption(const QString &)), this, SLOT(setCaption(const QString &)));
124 // InlineEditors::instance()->richTextToolBar();
125 setStandardToolBarMenuEnabled(true);
127 createGUI("basketui.rc");
128 applyMainWindowSettings(KGlobal::config(), autoSaveGroup());
131 MainWindow::~MainWindow()
133 saveMainWindowSettings(KGlobal::config(), autoSaveGroup());
134 delete m_settings;
137 void MainWindow::setupActions()
139 actQuit = KStandardAction::quit( this, SLOT(quit()), actionCollection() );
140 new KAction(i18n("Minimize"), "", 0,
141 this, SLOT(minimizeRestore()), actionCollection(), "minimizeRestore" );
142 /** Settings : ************************************************************/
143 // m_actShowToolbar = KStandardAction::showToolbar( this, SLOT(toggleToolBar()), actionCollection());
144 m_actShowStatusbar = KStandardAction::showStatusbar( this, SLOT(toggleStatusBar()), actionCollection());
146 // m_actShowToolbar->setCheckedState( KGuiItem(i18n("Hide &Toolbar")) );
148 (void) KStandardAction::keyBindings( this, SLOT(showShortcutsSettingsDialog()), actionCollection() );
150 (void) KStandardAction::configureToolbars(this, SLOT(configureToolbars()), actionCollection() );
152 //KAction *actCfgNotifs = KStandardAction::configureNotifications(this, SLOT(configureNotifications()), actionCollection() );
153 //actCfgNotifs->setEnabled(false); // Not yet implemented !
155 actAppConfig = KStandardAction::preferences( this, SLOT(showSettingsDialog()), actionCollection() );
158 /*void MainWindow::toggleToolBar()
160 if (toolBar()->isVisible())
161 toolBar()->hide();
162 else
163 toolBar()->show();
165 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
168 void MainWindow::toggleStatusBar()
170 if (statusBar()->isVisible())
171 statusBar()->hide();
172 else
173 statusBar()->show();
175 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
178 void MainWindow::configureToolbars()
180 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
182 KEditToolBar dlg(actionCollection());
183 connect( &dlg, SIGNAL(newToolbarConfig()), this, SLOT(slotNewToolbarConfig()) );
184 dlg.exec();
187 void MainWindow::configureNotifications()
189 // TODO
190 // KNotifyDialog *dialog = new KNotifyDialog(this, "KNotifyDialog", false);
191 // dialog->show();
194 void MainWindow::slotNewToolbarConfig() // This is called when OK or Apply is clicked
196 // ...if you use any action list, use plugActionList on each here...
197 createGUI("basketui.rc"); // TODO: Reconnect tags menu aboutToShow() ??
198 if (!Global::bnpView->isPart())
199 Global::bnpView->connectTagsMenu(); // The Tags menu was created again!
200 plugActionList( QString::fromLatin1("go_baskets_list"), actBasketsList);
201 applyMainWindowSettings( KGlobal::config(), autoSaveGroup() );
204 void MainWindow::showSettingsDialog()
206 if(m_settings == 0)
207 m_settings = new KSettings::Dialog(kapp->activeWindow());
208 if (Global::mainWindow()) {
209 m_settings->dialog()->showButton(KDialog::Help, false); // Not implemented!
210 m_settings->dialog()->showButton(KDialog::Default, false); // Not implemented!
211 m_settings->dialog()->exec();
212 } else
213 m_settings->show();
216 void MainWindow::showShortcutsSettingsDialog()
218 KShortcutsDialog::configure(actionCollection(), "basketui.rc");
219 //.setCaption(..)
220 //actionCollection()->writeSettings();
223 void MainWindow::polish()
225 bool shouldSave = false;
227 // If position and size has never been set, set nice ones:
228 // - Set size to sizeHint()
229 // - Keep the window manager placing the window where it want and save this
230 if (Settings::mainWindowSize().isEmpty()) {
231 // std::cout << "Main Window Position: Initial Set in show()" << std::endl;
232 int defaultWidth = kapp->desktop()->width() * 5 / 6;
233 int defaultHeight = kapp->desktop()->height() * 5 / 6;
234 resize(defaultWidth, defaultHeight); // sizeHint() is bad (too small) and we want the user to have a good default area size
235 shouldSave = true;
236 } else {
237 // std::cout << "Main Window Position: Recall in show(x="
238 // << Settings::mainWindowPosition().x() << ", y=" << Settings::mainWindowPosition().y()
239 // << ", width=" << Settings::mainWindowSize().width() << ", height=" << Settings::mainWindowSize().height()
240 // << ")" << std::endl;
241 //move(Settings::mainWindowPosition());
242 //resize(Settings::mainWindowSize());
245 KMainWindow::polish();
247 if (shouldSave) {
248 // std::cout << "Main Window Position: Save size and position in show(x="
249 // << pos().x() << ", y=" << pos().y()
250 // << ", width=" << size().width() << ", height=" << size().height()
251 // << ")" << std::endl;
252 Settings::setMainWindowPosition(pos());
253 Settings::setMainWindowSize(size());
254 Settings::saveConfig();
258 void MainWindow::resizeEvent(QResizeEvent *event)
260 // std::cout << "Main Window Position: Save size in resizeEvent(width=" << size().width() << ", height=" << size().height() << ") ; isMaximized="
261 // << (isMaximized() ? "true" : "false") << std::endl;
262 Settings::setMainWindowSize(size());
263 Settings::saveConfig();
265 // Added to make it work (previous lines do not work):
266 //saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
267 KMainWindow::resizeEvent(event);
270 void MainWindow::moveEvent(QMoveEvent *event)
272 // std::cout << "Main Window Position: Save position in moveEvent(x=" << pos().x() << ", y=" << pos().y() << ")" << std::endl;
273 Settings::setMainWindowPosition(pos());
274 Settings::saveConfig();
276 // Added to make it work (previous lines do not work):
277 //saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
278 KMainWindow::moveEvent(event);
281 bool MainWindow::queryExit()
283 hide();
284 return true;
287 void MainWindow::quit()
289 m_quit = true;
290 close();
293 bool MainWindow::queryClose()
295 /* if (m_shuttingDown) // Set in askForQuit(): we don't have to ask again
296 return true;*/
298 if (kapp->sessionSaving()) {
299 Settings::setStartDocked(false); // If queryClose() is called it's because the window is shown
300 Settings::saveConfig();
301 return true;
304 if (Settings::useSystray() && !m_quit) {
305 Global::systemTray->displayCloseMessage(i18n("Basket"));
306 hide();
307 return false;
308 } else
309 return askForQuit();
312 bool MainWindow::askForQuit()
314 QString message = i18n("<p>Do you really want to quit %1?</p>").arg(kapp->aboutData()->programName());
315 if (Settings::useSystray())
316 message += i18n("<p>Notice that you do not have to quit the application before ending your KDE session. "
317 "If you end your session while the application is still running, the application will be reloaded the next time you log in.</p>");
319 int really = KMessageBox::warningContinueCancel( this, message, i18n("Quit Confirm"),
320 KStandardGuiItem::quit(), "confirmQuitAsking" );
322 if (really == KMessageBox::Cancel)
324 m_quit = false;
325 return false;
328 return true;
331 void MainWindow::minimizeRestore()
333 if(isVisible())
334 hide();
335 else
336 show();
339 void MainWindow::changeActive()
341 #if KDE_IS_VERSION( 3, 2, 90 ) // KDE 3.3.x
342 kapp->updateUserTimestamp(); // If "activate on mouse hovering systray", or "on drag throught systray"
343 Global::systemTray->toggleActive();
344 #else
345 setActive( ! isActiveWindow() );
346 #endif
349 #include "mainwindow.moc"