1 /***************************************************************************
2 * Copyright (C) 2003 by S�astien Laot *
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. *
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. *
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>
25 #include <q3whatsthis.h>
26 #include <q3valuelist.h>
28 #include <q3buttongroup.h>
31 #include <QResizeEvent>
32 #include <kstringhandler.h>
34 #include <ksqueezedtextlabel.h>
37 #include <qinputdialog.h>
38 #include <kpopupmenu.h>
39 #include <kiconloader.h>
40 #include <kiconeffect.h>
46 #include <kedittoolbar.h>
48 #include <qsignalmapper.h>
49 #include <qstringlist.h>
53 #include <kglobalsettings.h>
54 #include <kstandarddirs.h>
56 #include <qstringlist.h>
57 #include <kmessagebox.h>
58 #include <kstatusbar.h>
61 #include <kstdaccel.h>
62 #include <kglobalaccel.h>
63 #include <kkeydialog.h>
64 #include <kpassivepopup.h>
66 #include <kcolordialog.h>
67 #include <kaboutdata.h>
69 #include <kdeversion.h>
70 #include <qdesktopwidget.h>
73 #include <kprogress.h>
75 #include "mainwindow.h"
77 #include "basketproperties.h"
82 //#include "addbasketwizard.h"
83 #include "newbasketdialog.h"
84 #include "basketfactory.h"
85 #include "popupmenu.h"
87 #include "debugwindow.h"
88 #include "notefactory.h"
92 #include "formatimporter.h"
93 #include "softwareimporters.h"
94 #include "regiongrabber.h"
97 #include "systemtray.h"
98 #include "clickablelabel.h"
99 #include "basketstatusbar.h"
101 #include <ksettings/dialog.h>
102 #include <kcmultidialog.h>
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
);
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());
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())
164 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
167 void MainWindow::toggleStatusBar()
169 if (statusBar()->isVisible())
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()) );
186 void MainWindow::configureNotifications()
189 // KNotifyDialog *dialog = new KNotifyDialog(this, "KNotifyDialog", false);
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()
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();
215 void MainWindow::showShortcutsSettingsDialog()
217 KKeyDialog::configure(actionCollection(), "basketui.rc");
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
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();
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()
286 void MainWindow::quit()
292 bool MainWindow::queryClose()
294 /* if (m_shuttingDown) // Set in askForQuit(): we don't have to ask again
297 if (kapp
->sessionSaving()) {
298 Settings::setStartDocked(false); // If queryClose() is called it's because the window is shown
299 Settings::saveConfig();
303 if (Settings::useSystray() && !m_quit
) {
304 Global::systemTray
->displayCloseMessage(i18n("Basket"));
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
)
330 void MainWindow::minimizeRestore()
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();
344 setActive( ! isActiveWindow() );
348 #include "mainwindow.moc"