summaryrefslogtreecommitdiffstats
path: root/src/mainwindow.cpp
blob: 1331ce0f8e7cd47b98b5c435f2356f75885a3f9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/***************************************************************************
 *   Copyright (C) 2003 by S�astien Laot                                 *
 *   [email protected]                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#include <tqtabwidget.h>
#include <tqlayout.h>
#include <tqtooltip.h>
#include <tqcursor.h>
#include <tqwhatsthis.h>
#include <tqvaluelist.h>
#include <tqregexp.h>
#include <tqbuttongroup.h>
#include <kstringhandler.h>

#include <ksqueezedtextlabel.h>
#include <tqpoint.h>
#include <tqpixmap.h>
#include <tqinputdialog.h>
#include <tdepopupmenu.h>
#include <kiconloader.h>
#include <kiconeffect.h>
#include <tqiconset.h>
#include <tdeaction.h>
#include <kapp.h>
#include <tdelocale.h>
#include <tdemenubar.h>
#include <kedittoolbar.h>
#include <kdebug.h>
#include <tqsignalmapper.h>
#include <tqstringlist.h>

#include <tqpainter.h>
#include <tqstyle.h>
#include <tdeglobalsettings.h>
#include <kstandarddirs.h>
#include <tqdir.h>
#include <tqstringlist.h>
#include <tdemessagebox.h>
#include <kstatusbar.h>
#include <tqtimer.h>
#include <tqaction.h>
#include <tdestdaccel.h>
#include <kglobalaccel.h>
#include <kkeydialog.h>
#include <kpassivepopup.h>
#include <tdeconfig.h>
#include <kcolordialog.h>
#include <tdeaboutdata.h>

#include <tdeversion.h>
#include <tqdesktopwidget.h>
#include <twin.h>

#include <kprogress.h>

#include "mainwindow.h"
#include "basket.h"
#include "basketproperties.h"
#include "note.h"
#include "noteedit.h"
#include "settings.h"
#include "global.h"
//#include "addbasketwizard.h"
#include "newbasketdialog.h"
#include "basketfactory.h"
#include "popupmenu.h"
#include "xmlwork.h"
#include "debugwindow.h"
#include "notefactory.h"
#include "notedrag.h"
#include "tools.h"
#include "tag.h"
#include "formatimporter.h"
#include "softwareimporters.h"
#include "regiongrabber.h"
#include "password.h"
#include "bnpview.h"
#include "systemtray.h"
#include "clickablelabel.h"
#include "basketstatusbar.h"
#include <iostream>
#include <ksettings/dialog.h>
#include <kcmultidialog.h>

/** Container */

MainWindow::MainWindow(TQWidget *parent, const char *name)
	: TDEMainWindow(parent, name != 0 ? name : "MainWindow"), m_settings(0), m_quit(false)
{
	BasketStatusBar* bar = new BasketStatusBar(statusBar());
	m_baskets = new BNPView(this, "BNPViewApp", this, actionCollection(), bar);
	setCentralWidget(m_baskets);

	setupActions();
	statusBar()->show();
	statusBar()->setSizeGripEnabled(true);

	setAutoSaveSettings(/*groupName=*/TQString::fromLatin1("MainWindow"), /*saveWindowSize=*//*FIXME:false:Why was it false??*/true);

//	m_actShowToolbar->setChecked(   toolBar()->isShown()   );
	m_actShowStatusbar->setChecked( statusBar()->isShown() );
	connect( m_baskets,      TQT_SIGNAL(setWindowCaption(const TQString &)), this, TQT_SLOT(setCaption(const TQString &)));

//	InlineEditors::instance()->richTextToolBar();
	setStandardToolBarMenuEnabled(true);

	createGUI("basketui.rc");
	applyMainWindowSettings(TDEGlobal::config(), autoSaveGroup());
}

MainWindow::~MainWindow()
{
	saveMainWindowSettings(TDEGlobal::config(), autoSaveGroup());
	delete m_settings;
}

void MainWindow::setupActions()
{
	actQuit         = KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT(quit()), actionCollection() );
	new TDEAction(i18n("Minimize"), "", 0,
				TQT_TQOBJECT(this), TQT_SLOT(minimizeRestore()), actionCollection(), "minimizeRestore" );
	/** Settings : ************************************************************/
//	m_actShowToolbar   = KStdAction::showToolbar(   TQT_TQOBJECT(this), TQT_SLOT(toggleToolBar()),   actionCollection());
	m_actShowStatusbar = KStdAction::showStatusbar( TQT_TQOBJECT(this), TQT_SLOT(toggleStatusBar()), actionCollection());

//	m_actShowToolbar->setCheckedState( KGuiItem(i18n("Hide &Toolbar")) );

	(void) KStdAction::keyBindings( TQT_TQOBJECT(this), TQT_SLOT(showShortcutsSettingsDialog()), actionCollection() );

	(void) KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(configureToolbars()), actionCollection() );

	//TDEAction *actCfgNotifs = KStdAction::configureNotifications(this, TQT_SLOT(configureNotifications()), actionCollection() );
	//actCfgNotifs->setEnabled(false); // Not yet implemented !

	actAppConfig = KStdAction::preferences( TQT_TQOBJECT(this), TQT_SLOT(showSettingsDialog()), actionCollection() );
}

/*void MainWindow::toggleToolBar()
{
	if (toolBar()->isVisible())
		toolBar()->hide();
	else
		toolBar()->show();

	saveMainWindowSettings( TDEGlobal::config(), autoSaveGroup() );
}*/

void MainWindow::toggleStatusBar()
{
	if (statusBar()->isVisible())
		statusBar()->hide();
	else
		statusBar()->show();

	saveMainWindowSettings( TDEGlobal::config(), autoSaveGroup() );
}

void MainWindow::configureToolbars()
{
	saveMainWindowSettings( TDEGlobal::config(), autoSaveGroup() );

	KEditToolbar dlg(actionCollection());
	connect( &dlg, TQT_SIGNAL(newToolbarConfig()), this, TQT_SLOT(slotNewToolbarConfig()) );
	dlg.exec();
}

void MainWindow::configureNotifications()
{
	// TODO
	// KNotifyDialog *dialog = new KNotifyDialog(this, "KNotifyDialog", false);
	// dialog->show();
}

void MainWindow::slotNewToolbarConfig() // This is called when OK or Apply is clicked
{
	// ...if you use any action list, use plugActionList on each here...
	createGUI("basketui.rc"); // TODO: Reconnect tags menu aboutToShow() ??
	if (!Global::bnpView->isPart())
		Global::bnpView->connectTagsMenu(); // The Tags menu was created again!
	plugActionList( TQString::fromLatin1("go_baskets_list"), actBasketsList);
	applyMainWindowSettings( TDEGlobal::config(), autoSaveGroup() );
}

void MainWindow::showSettingsDialog()
{
	if(m_settings == 0)
		m_settings = new KSettings::Dialog(TQT_TQWIDGET(kapp->activeWindow()));
	if (Global::mainWindow()) {
		m_settings->dialog()->showButton(KDialogBase::Help,    false); // Not implemented!
		m_settings->dialog()->showButton(KDialogBase::Default, false); // Not implemented!
		m_settings->dialog()->exec();
	} else
		m_settings->show();
}

void MainWindow::showShortcutsSettingsDialog()
{
	KKeyDialog::configure(actionCollection(), "basketui.rc");
	//.setCaption(..)
	//actionCollection()->writeSettings();
}

void MainWindow::polish()
{
	bool shouldSave = false;

	// If position and size has never been set, set nice ones:
	//  - Set size to sizeHint()
	//  - Keep the window manager placing the window where it want and save this
	if (Settings::mainWindowSize().isEmpty()) {
//		std::cout << "Main Window Position: Initial Set in show()" << std::endl;
		int defaultWidth  = kapp->desktop()->width()  * 5 / 6;
		int defaultHeight = kapp->desktop()->height() * 5 / 6;
		resize(defaultWidth, defaultHeight); // sizeHint() is bad (too small) and we want the user to have a good default area size
		shouldSave = true;
	} else {
//		std::cout << "Main Window Position: Recall in show(x="
//		          << Settings::mainWindowPosition().x() << ", y=" << Settings::mainWindowPosition().y()
//		          << ", width=" << Settings::mainWindowSize().width() << ", height=" << Settings::mainWindowSize().height()
//		          << ")" << std::endl;
		//move(Settings::mainWindowPosition());
		//resize(Settings::mainWindowSize());
	}

	TDEMainWindow::polish();

	if (shouldSave) {
//		std::cout << "Main Window Position: Save size and position in show(x="
//		          << pos().x() << ", y=" << pos().y()
//		          << ", width=" << size().width() << ", height=" << size().height()
//		          << ")" << std::endl;
		Settings::setMainWindowPosition(pos());
		Settings::setMainWindowSize(size());
		Settings::saveConfig();
	}
}

void MainWindow::resizeEvent(TQResizeEvent *event)
{
//	std::cout << "Main Window Position: Save size in resizeEvent(width=" << size().width() << ", height=" << size().height() << ") ; isMaximized="
//	          << (isMaximized() ? "true" : "false") << std::endl;
	Settings::setMainWindowSize(size());
	Settings::saveConfig();

	// Added to make it work (previous lines do not work):
	//saveMainWindowSettings( TDEGlobal::config(), autoSaveGroup() );
	TDEMainWindow::resizeEvent(event);
}

void MainWindow::moveEvent(TQMoveEvent *event)
{
//	std::cout << "Main Window Position: Save position in moveEvent(x=" << pos().x() << ", y=" << pos().y() << ")" << std::endl;
	Settings::setMainWindowPosition(pos());
	Settings::saveConfig();

	// Added to make it work (previous lines do not work):
	//saveMainWindowSettings( TDEGlobal::config(), autoSaveGroup() );
	TDEMainWindow::moveEvent(event);
}

bool MainWindow::queryExit()
{
	hide();
	return true;
}

void MainWindow::quit()
{
	m_quit = true;
	close();
}

bool MainWindow::queryClose()
{
/*	if (m_shuttingDown) // Set in askForQuit(): we don't have to ask again
	return true;*/

	if (kapp->sessionSaving()) {
		Settings::setStartDocked(false); // If queryClose() is called it's because the window is shown
		Settings::saveConfig();
		return true;
	}

	if (Settings::useSystray() && !m_quit) {
		Global::systemTray->displayCloseMessage(i18n("Basket"));
		hide();
		return false;
	} else
		return askForQuit();
}

bool MainWindow::askForQuit()
{
	TQString message = i18n("<p>Do you really want to quit %1?</p>").arg(kapp->aboutData()->programName());
	if (Settings::useSystray())
		message += i18n("<p>Notice that you do not have to quit the application before ending your TDE session. "
				"If you end your session while the application is still running, the application will be reloaded the next time you log in.</p>");

	int really = KMessageBox::warningContinueCancel( this, message, i18n("Quit Confirm"),
			KStdGuiItem::quit(), "confirmQuitAsking" );

	if (really == KMessageBox::Cancel)
	{
		m_quit = false;
		return false;
	}

	return true;
}

void MainWindow::minimizeRestore()
{
	if(isVisible())
		hide();
	else
		show();
}

void MainWindow::changeActive()
{
#if KDE_IS_VERSION( 3, 2, 90 ) // KDE 3.3.x
	kapp->updateUserTimestamp(); // If "activate on mouse hovering systray", or "on drag throught systray"
	Global::systemTray->toggleActive();
#else
	setActive( ! isActiveWindow() );
#endif
}

#include "mainwindow.moc"