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>
39 #include <kiconloader.h>
40 #include <kiconeffect.h>
43 #include <kapplication.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>
71 #include <kwindowsystem.h>
73 #include <kprogressdialog.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>
103 #include <KShortcutsDialog>
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
);
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());
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())
165 saveMainWindowSettings( KGlobal::config(), autoSaveGroup() );
168 void MainWindow::toggleStatusBar()
170 if (statusBar()->isVisible())
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()) );
187 void MainWindow::configureNotifications()
190 // KNotifyDialog *dialog = new KNotifyDialog(this, "KNotifyDialog", false);
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()
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();
216 void MainWindow::showShortcutsSettingsDialog()
218 KShortcutsDialog::configure(actionCollection(), "basketui.rc");
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
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();
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()
287 void MainWindow::quit()
293 bool MainWindow::queryClose()
295 /* if (m_shuttingDown) // Set in askForQuit(): we don't have to ask again
298 if (kapp
->sessionSaving()) {
299 Settings::setStartDocked(false); // If queryClose() is called it's because the window is shown
300 Settings::saveConfig();
304 if (Settings::useSystray() && !m_quit
) {
305 Global::systemTray
->displayCloseMessage(i18n("Basket"));
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
)
331 void MainWindow::minimizeRestore()
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();
345 setActive( ! isActiveWindow() );
349 #include "mainwindow.moc"