48
48
#include <kfiledialog.h>
50
50
#include <kcombobox.h>
51
#include <kselectaction.h>
52
#include <kstandarddirs.h>
52
54
#include <QtGui/QProgressBar>
53
55
#include <QtGui/QHeaderView>
54
56
#include <QApplication>
58
#include <QResizeEvent>
56
60
bool SKGMainPanel::currentActionCanceled=false;
57
SKGMainPanel::SKGMainPanel(KSplashScreen* iSplashScreen, SKGDocument* iDocument, const QStringList& iArguments)
61
SKGMainPanel::SKGMainPanel ( KSplashScreen* iSplashScreen, SKGDocument* iDocument, const QStringList& iArguments )
58
62
: KParts::MainWindow(),
59
tabView(new KTabWidget(this)),
60
spScreen(iSplashScreen),
61
currentBankDocument(iDocument),
62
tipOfDayAction(NULL),closePageAction(NULL), closeAllPagesAction(NULL), closeAllOtherPagesAction(NULL),
63
tabView ( new KTabWidget ( this ) ),
64
spScreen ( iSplashScreen ),
65
currentBankDocument ( iDocument ),
66
tipOfDayAction ( NULL ),closePageAction ( NULL ), closeAllPagesAction ( NULL ), closeAllOtherPagesAction ( NULL ),
68
kSystemTrayIcon ( NULL )
66
SKGTRACEIN(1, "SKGMainPanel::SKGMainPanel");
70
SKGTRACEIN ( 1, "SKGMainPanel::SKGMainPanel" );
73
setAcceptDrops ( true );
73
77
// tell the KXmlGuiWindow that this is indeed the main widget
74
setCentralWidget(tabView);
78
setCentralWidget ( tabView );
76
tabView->setTabReorderingEnabled (true);
77
tabView->setHoverCloseButton (true);
78
tabView->setHoverCloseButtonDelayed( true );
79
tabView->setTabCloseActivatePrevious (true);
80
tabView->setAutomaticResizeTabs (true);
81
tabView->setTabBarHidden (false);
82
tabView->setUsesScrollButtons( true );
80
tabView->setTabReorderingEnabled ( true );
81
tabView->setHoverCloseButton ( true );
82
tabView->setHoverCloseButtonDelayed ( true );
83
tabView->setTabCloseActivatePrevious ( true );
84
tabView->setAutomaticResizeTabs ( true );
85
tabView->setTabBarHidden ( false );
86
tabView->setUsesScrollButtons ( true );
87
if (KSystemTrayIcon::isSystemTrayAvailable()) {
88
kSystemTrayIcon=new KSystemTrayIcon(qApp->windowIcon());
89
KMenu* systemTrayMenu = new KMenu(this);
90
QAction* quit = systemTrayMenu->addAction(KIcon("application-exit"), i18n("Quit"));
91
connect(quit, SIGNAL(triggered(bool)), qApp, SLOT(closeAllWindows()));
91
if ( KSystemTrayIcon::isSystemTrayAvailable() ) {
92
kSystemTrayIcon=new KSystemTrayIcon ( qApp->windowIcon() );
93
KMenu* systemTrayMenu = new KMenu ( this );
94
QAction* quit = systemTrayMenu->addAction ( KIcon ( "application-exit" ), i18n ( "Quit" ) );
95
connect ( quit, SIGNAL ( triggered ( bool ) ), this, SLOT ( onQuitAction() ) );
93
kSystemTrayIcon->setContextMenu(systemTrayMenu);
94
connect( kSystemTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(onTrayActivated(QSystemTrayIcon::ActivationReason)));
95
if (iconInSystemtray()) kSystemTrayIcon->show();
97
kSystemTrayIcon->setContextMenu ( systemTrayMenu );
98
connect ( kSystemTrayIcon, SIGNAL ( activated ( QSystemTrayIcon::ActivationReason ) ), SLOT ( onTrayActivated ( QSystemTrayIcon::ActivationReason ) ) );
99
if ( iconInSystemtray() ) kSystemTrayIcon->show();
98
102
// then, setup our actions
102
KService::List offers=KServiceTypeTrader::self()->query(QLatin1String("Skrooge/Plugin"));
106
KService::List offers=KServiceTypeTrader::self()->query ( QLatin1String ( "Skrooge/Plugin" ) );
104
108
//Create temporary file for tips
105
109
KTemporaryFile tipsFile;
106
tipsFile.setSuffix(".tips");
110
tipsFile.setSuffix ( ".tips" );
108
112
bool tipsFileOpened=tipsFile.open();
109
113
bool tipsFound=false;
111
QTextStream stream(&tipsFile);
115
QTextStream stream ( &tipsFile );
114
118
int nb=offers.count();
115
SKGTRACEL(1) << nb << " plugins found" << endl;
116
if (spScreen) spScreen->showMessage(i18n("Loading plugins ..."), Qt::AlignLeft, QColor(221, 130, 8)); // krazy:exclude=doublequote_chars
119
SKGTRACEL ( 1 ) << nb << " plugins found" << endl;
120
if ( spScreen ) spScreen->showMessage ( i18n ( "Loading plugins ..." ), Qt::AlignLeft, QColor ( 221, 130, 8 ) ); // krazy:exclude=doublequote_chars
118
for (int i=0; i<nb; ++i) {
119
KService::Ptr service = offers.at(i);
122
for ( int i=0; i<nb; ++i ) {
123
KService::Ptr service = offers.at ( i );
120
124
QString name=service->name();
121
QString msg=i18n("Loading plugin %1/%2: %3 ...", i+1, nb, name);
122
SKGTRACEL(1) << msg << endl;
123
if (spScreen) spScreen->showMessage(msg, Qt::AlignLeft, QColor(221, 130, 8));
124
KPluginLoader loader(service->library());
125
QString msg=i18n ( "Loading plugin %1/%2: %3 ...", i+1, nb, name );
126
SKGTRACEL ( 1 ) << msg << endl;
127
if ( spScreen ) spScreen->showMessage ( msg, Qt::AlignLeft, QColor ( 221, 130, 8 ) );
128
KPluginLoader loader ( service->library() );
125
129
KPluginFactory *factory =loader.factory();
127
SKGInterfacePlugin *pluginInterface = factory->create<SKGInterfacePlugin>(this);
128
if (pluginInterface) {
129
if (pluginInterface->isEnabled()) {
130
pluginInterface->setupActions(this, currentBankDocument, iArguments);
131
SKGInterfacePlugin *pluginInterface = factory->create<SKGInterfacePlugin> ( this );
132
if ( pluginInterface ) {
133
if ( pluginInterface->isEnabled() ) {
134
pluginInterface->setupActions ( this, currentBankDocument, iArguments );
133
137
int nbplugin=pluginsList.count();
134
138
int pos=nbplugin;
135
for (int j=nbplugin-1; j>=0; --j) {
136
if (pluginInterface->getOrder()<pluginsList.at(j)->getOrder()) {
139
for ( int j=nbplugin-1; j>=0; --j ) {
140
if ( pluginInterface->getOrder() <pluginsList.at ( j )->getOrder() ) {
141
pluginsList.insert(pos, pluginInterface);
142
pluginInterface->setObjectName(name);
145
pluginsList.insert ( pos, pluginInterface );
146
pluginInterface->setObjectName ( name );
144
148
//Build temporary tips file
145
if (tipsFileOpened) {
149
if ( tipsFileOpened ) {
146
150
QStringList tipsList=pluginInterface->tips();
147
151
int nbtips=tipsList.count();
148
for (int t=0; t<nbtips; ++t) {
152
for ( int t=0; t<nbtips; ++t ) {
150
154
stream << "<tip category=\""
152
<< "\"><html>"<< tipsList.at(t)
156
<< "\"><html>"<< tipsList.at ( t )
153
157
<< "</html></tip>"
159
err.addError(ERR_FAIL, i18n("Plugin's interface %1 not found in %2", name, service->library()));
163
err.addError ( ERR_FAIL, i18n ( "Plugin's interface %1 not found in %2", name, service->library() ) );
162
SKGTRACEL(1) << loader.errorString() << endl;
163
err.addError(ERR_FAIL, loader.errorString());
164
err.addError(ERR_FAIL, i18n("Loading plugin %1 failed because the factory could not be found in %2", name, service->library()));
166
SKGTRACEL ( 1 ) << loader.errorString() << endl;
167
err.addError ( ERR_FAIL, loader.errorString() );
168
err.addError ( ERR_FAIL, i18n ( "Loading plugin %1 failed because the factory could not be found in %2", name, service->library() ) );
170
displayErrorMessage(err);
174
displayErrorMessage ( err );
173
if (!tipDatabase && tipsFound) {
177
if ( !tipDatabase && tipsFound ) {
174
178
//Tip of day is available
175
179
//Creation of the database
176
tipDatabase=new KTipDatabase(tipsFile.fileName());
180
tipDatabase=new KTipDatabase ( tipsFile.fileName() );
179
if (tipsFileOpened) {
183
if ( tipsFileOpened ) {
180
184
tipsFile.close();
184
188
statusBar()->show();
186
// add action to control hide / display of Context Chooser
187
ui.kDockContext->toggleViewAction()->setText(i18n("Context Chooser"));
188
ui.kDockContext->toggleViewAction()->setShortcut(Qt::SHIFT+Qt::Key_F9);
189
actionCollection()->addAction("view_context", ui.kDockContext->toggleViewAction());
190
//Add action to control hide / display of Context Chooser
191
ui.kDockContext->toggleViewAction()->setText ( i18n ( "Context Chooser" ) );
192
ui.kDockContext->toggleViewAction()->setShortcut ( Qt::SHIFT+Qt::Key_F9 );
193
actionCollection()->addAction ( "view_context", ui.kDockContext->toggleViewAction() );
195
//Add style sheet menu
196
QDir dirTheme ( KStandardDirs::locate ( "data", QString::fromLatin1 ( "skrooge/theme/" ) ) );
197
dirTheme.setFilter ( QDir::Files );
200
dirTheme.setNameFilters ( filters );
201
QStringList listThemes = dirTheme.entryList();
202
int nbt=listThemes.size();
204
defaultStyle=styleSheet();
205
KSelectAction* styleSheetMenu = new KSelectAction ( KIcon ( "view-media-visualization" ), i18n ( "Theme" ), this );
206
actionCollection()->addAction ( QLatin1String ( "view_stylesheet" ), styleSheetMenu );
208
KSharedConfigPtr config=KSharedConfig::openConfig ( "skroogerc" );
209
KConfigGroup pref=config->group ( "skrooge" );
210
QString lastTheme=pref.readEntry ( "last_theme", "default" );
212
for ( int i=0; i<nbt ; ++i ) {
213
QString themeName=listThemes.at ( i );
214
themeName.remove ( ".css" );
216
KAction* action=styleSheetMenu->addAction ( themeName );
217
if ( themeName==lastTheme ) styleSheetMenu->setCurrentAction ( action );
219
onChangeStyleSheet ( lastTheme );
220
connect ( styleSheetMenu, SIGNAL ( triggered ( QString ) ), this, SLOT ( onChangeStyleSheet ( QString ) ), Qt::QueuedConnection );
221
} else onChangeStyleSheet ( "default" );
224
KSelectAction* contextMenu = new KSelectAction ( KIcon ( "tab-new" ), i18n ( "Context" ), this );
225
actionCollection()->addAction ( "view_contextmenu" , contextMenu );
191
227
//Add plugin in client in right order
192
229
int nbplugin=pluginsList.count();
193
for (int j=0; j<nbplugin; ++j) {
194
SKGInterfacePlugin *pluginInterface=pluginsList.at(j);
196
//Creation of the item
197
QString title=pluginInterface->title();
198
SKGTRACEL(1) << "Add plugin (" << pluginInterface->getOrder() << ") : " << title << endl;
199
if (title.length()>0) {
200
//Create icon to launch this plugin
201
QListWidgetItem *contextItem = new QListWidgetItem(KIcon(pluginInterface->icon()), title);
202
contextItem->setStatusTip(pluginInterface->statusTip());
203
contextItem->setToolTip(pluginInterface->toolTip());
205
ui.kContextList->addItem(contextItem);
206
ui.kContextList->setItemHidden (contextItem, !pluginInterface->isInContext());
208
//TODO: Add menu item with shortcuts
210
//Create dock if needed
211
QDockWidget* dockWidget=pluginInterface->getDockWidget();
213
this->addDockWidget(Qt::LeftDockWidgetArea, dockWidget);
230
for ( int j=0; j<nbplugin; ++j ) {
231
SKGInterfacePlugin *pluginInterface=pluginsList.at ( j );
232
if ( pluginInterface ) {
233
//Creation of the item
234
QString title=pluginInterface->title();
235
SKGTRACEL ( 1 ) << "Add plugin (" << pluginInterface->getOrder() << ") : " << title << endl;
236
if ( title.length() >0 ) {
237
//Create icon to launch this plugin
238
KIcon icon(pluginInterface->icon());
239
bool visible=pluginInterface->isInContext();
240
QListWidgetItem *contextItem = new QListWidgetItem ( icon, title );
241
contextItem->setStatusTip ( pluginInterface->statusTip() );
242
contextItem->setToolTip ( pluginInterface->toolTip() );
243
contextItem->setData(12, j);
245
ui.kContextList->addItem ( contextItem );
246
ui.kContextList->setItemHidden ( contextItem, !visible );
248
//Add menu item with shortcuts
250
KAction* action=contextMenu->addAction ( icon, title );
251
action->setCheckable(false);
254
action->setShortcut("Ctrl+"+SKGServices::intToString(shortCutIndex));
255
connect(action, SIGNAL(triggered(bool)), this, SLOT(onOpenContext()));
258
//Create dock if needed
259
QDockWidget* dockWidget=pluginInterface->getDockWidget();
260
if ( dockWidget ) this->addDockWidget ( Qt::LeftDockWidgetArea, dockWidget );
220
267
// It also applies the saved mainwindow settings, if any, and ask the
221
268
// mainwindow to automatically save settings if changed: window size,
222
269
// toolbar position, icon size, etc.
223
setupGUI(Default, "skrooge.rc");
225
for (int j=0; j<nbplugin; ++j) {
226
guiFactory()->addClient(pluginsList.at(j));
270
setupGUI ( Default, "skrooge.rc" );
272
for ( int j=0; j<nbplugin; ++j ) {
273
SKGInterfacePlugin *pluginInterface=pluginsList.at ( j );
274
if ( pluginInterface ) {
275
QString title=pluginInterface->title();
276
SKGTRACEL ( 1 ) << "Add plugin client (" << pluginInterface->getOrder() << ") : " << title << endl;
277
guiFactory()->addClient ( pluginInterface );
231
282
QProgressBar *kProgressBar=new QProgressBar();
232
kProgressBar->setObjectName(QString::fromUtf8("kProgressBar"));
233
kProgressBar->setValue(0);
234
kProgressBar->setFixedSize(100, 22);
235
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
236
kProgressBar->setSizePolicy(sizePolicy);
237
kProgressBar->setToolTip(i18n("Progress of the current action"));
238
kProgressBar->setStatusTip(i18n("Progress of the current action"));
239
kProgressBar->setWhatsThis(i18n("Progress of the current action"));
283
kProgressBar->setObjectName ( QString::fromUtf8 ( "kProgressBar" ) );
284
kProgressBar->setValue ( 0 );
285
kProgressBar->setFixedSize ( 100, 22 );
286
QSizePolicy sizePolicy ( QSizePolicy::Fixed, QSizePolicy::Expanding );
287
kProgressBar->setSizePolicy ( sizePolicy );
288
kProgressBar->setToolTip ( i18n ( "Progress of the current action" ) );
289
kProgressBar->setStatusTip ( i18n ( "Progress of the current action" ) );
290
kProgressBar->setWhatsThis ( i18n ( "Progress of the current action" ) );
241
statusBar()->addPermanentWidget(kProgressBar);
292
statusBar()->addPermanentWidget ( kProgressBar );
243
294
//Set Cancel button
244
295
kCancelButton=new KPushButton();
245
kCancelButton->setObjectName(QString::fromUtf8("kCancelButton"));
246
kCancelButton->setIcon(KIcon("process-stop"));
247
kCancelButton->setEnabled(false);
248
kCancelButton->setToolTip(i18n("Cancel the current action"));
249
kCancelButton->setStatusTip(i18n("Cancel the current action"));
250
kCancelButton->setWhatsThis(i18n("Cancel the current action"));
251
connect(kCancelButton, SIGNAL(clicked()), this, SLOT(onCancelCurrentAction()));
296
kCancelButton->setObjectName ( QString::fromUtf8 ( "kCancelButton" ) );
297
kCancelButton->setIcon ( KIcon ( "process-stop" ) );
298
kCancelButton->setEnabled ( false );
299
kCancelButton->setToolTip ( i18n ( "Cancel the current action" ) );
300
kCancelButton->setStatusTip ( i18n ( "Cancel the current action" ) );
301
kCancelButton->setWhatsThis ( i18n ( "Cancel the current action" ) );
302
connect ( kCancelButton, SIGNAL ( clicked() ), this, SLOT ( onCancelCurrentAction() ) );
253
statusBar()->addPermanentWidget(kCancelButton);
304
statusBar()->addPermanentWidget ( kCancelButton );
255
306
//Set progress bar call back
256
if (currentBankDocument) {
257
progressObjects.p1=(void*) kProgressBar;
258
progressObjects.p2=(void*) kCancelButton;
259
currentBankDocument->setProgressCallback(&SKGMainPanel::progressBarCallBack, (void*) &progressObjects);
307
if ( currentBankDocument ) {
308
progressObjects.p1= ( void* ) kProgressBar;
309
progressObjects.p2= ( void* ) kCancelButton;
310
currentBankDocument->setProgressCallback ( &SKGMainPanel::progressBarCallBack, ( void* ) &progressObjects );
263
if (currentBankDocument) {
264
connect((const QObject*) currentBankDocument, SIGNAL(transactionSuccessfullyEnded(int)), this, SLOT(refresh()), Qt::QueuedConnection);
265
connect((const QObject*) currentBankDocument, SIGNAL(transactionSuccessfullyEnded(int)), this, SLOT(notify(int)), Qt::QueuedConnection);
314
if ( currentBankDocument ) {
315
connect ( ( const QObject* ) currentBankDocument, SIGNAL ( transactionSuccessfullyEnded ( int ) ), this, SLOT ( refresh() ), Qt::QueuedConnection );
316
connect ( ( const QObject* ) currentBankDocument, SIGNAL ( transactionSuccessfullyEnded ( int ) ), this, SLOT ( notify ( int ) ), Qt::QueuedConnection );
267
connect(ui.kContextList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(setTabContentFromList(QListWidgetItem*)));
268
connect(tabView, SIGNAL(closeRequest(QWidget*)), this, SLOT(closeTab(QWidget*)));
269
connect(tabView, SIGNAL(mouseMiddleClick(QWidget*)), this, SLOT(closeTab(QWidget*)));
270
connect(tabView, SIGNAL(mouseDoubleClick()), this, SLOT(addTab()));
271
connect(tabView, SIGNAL(currentChanged(int)), this, SLOT(refresh()));
318
connect ( ui.kContextList, SIGNAL ( itemDoubleClicked ( QListWidgetItem* ) ), this, SLOT ( onOpenContext () ) );
319
connect ( tabView, SIGNAL ( closeRequest ( QWidget* ) ), this, SLOT ( closeTab ( QWidget* ) ) );
320
connect ( tabView, SIGNAL ( mouseMiddleClick ( QWidget* ) ), this, SLOT ( closeTab ( QWidget* ) ) );
321
connect ( tabView, SIGNAL ( mouseDoubleClick() ), this, SLOT ( addTab() ) );
322
connect ( tabView, SIGNAL ( currentChanged ( int ) ), this, SLOT ( refresh() ) );
278
329
//Tip of day is available
279
KSharedConfigPtr config=KSharedConfig::openConfig("skroogerc");
280
KConfigGroup pref=config->group("TipOfDay");
281
if (pref.readEntry( "RunOnStart", true )) onTipOfDay();
330
KSharedConfigPtr config=KSharedConfig::openConfig ( "skroogerc" );
331
KConfigGroup pref=config->group ( "TipOfDay" );
332
if ( pref.readEntry ( "RunOnStart", true ) ) onTipOfDay();
283
334
//Remove useless menu
284
335
delete tipOfDayAction;
285
336
tipOfDayAction=NULL;
339
ui.kContextList->installEventFilter ( this );
289
342
SKGMainPanel::~SKGMainPanel()
291
SKGTRACEIN(1, "SKGMainPanel::~SKGMainPanel");
292
disconnect((const QObject*) currentBankDocument, 0, this, 0);
344
SKGTRACEIN ( 1, "SKGMainPanel::~SKGMainPanel" );
345
disconnect ( ( const QObject* ) currentBankDocument, 0, this, 0 );
295
348
int nb=pluginsList.count();
296
for (int i = 0; i < nb; ++i) {
297
getPluginByIndex(i)->close();
349
for ( int i = 0; i < nb; ++i ) {
350
getPluginByIndex ( i )->close();
302
355
delete tipDatabase;
303
356
tipDatabase=NULL;
306
if (currentBankDocument) {
359
if ( currentBankDocument ) {
307
360
currentBankDocument->close();
311
void SKGMainPanel::registedGlobalAction(const QString& iIdentifier, KAction* iAction)
364
void SKGMainPanel::registedGlobalAction ( const QString& iIdentifier, KAction* iAction )
313
366
registeredGlogalAction[iIdentifier]=iAction;
316
KAction* SKGMainPanel::getGlobalAction(const QString& iIdentifier)
369
KAction* SKGMainPanel::getGlobalAction ( const QString& iIdentifier )
318
371
return registeredGlogalAction[iIdentifier];
321
SKGInterfacePlugin * SKGMainPanel::getPluginByIndex(int iIndex)
374
SKGInterfacePlugin * SKGMainPanel::getPluginByIndex ( int iIndex )
323
SKGTRACEIN(10, "SKGMainPanel::getPluginByIndex");
324
SKGTRACEL(10) << "Input parameter [iIndex]=[" << iIndex << ']' << endl;
325
376
SKGInterfacePlugin * output=NULL;
326
if (iIndex>=0 && iIndex<pluginsList.count()) {
377
if ( iIndex>=0 && iIndex<pluginsList.count() ) {
327
378
output=pluginsList[iIndex];
333
SKGInterfacePlugin * SKGMainPanel::getPluginByName(const QString& iName)
384
SKGInterfacePlugin * SKGMainPanel::getPluginByName ( const QString& iName )
335
SKGTRACEIN(10, "SKGMainPanel::getPluginByName");
336
SKGTRACEL(10) << "Input parameter [iName]=[" << iName << ']' << endl;
337
386
SKGInterfacePlugin * output=NULL;
338
387
int nbplugin=pluginsList.count();
339
for (int j=0; !output && j<nbplugin; ++j) {
340
if (pluginsList[j]->objectName()==iName) {
388
for ( int j=0; !output && j<nbplugin; ++j ) {
389
if ( pluginsList[j]->objectName() ==iName ) {
341
390
output=pluginsList[j];
348
397
void SKGMainPanel::setupActions()
350
SKGTRACEIN(1, "SKGMainPanel::setupActions");
399
SKGTRACEIN ( 1, "SKGMainPanel::setupActions" );
353
KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection());
402
KStandardAction::quit ( this, SLOT ( onQuitAction() ), actionCollection() );
356
KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
405
KStandardAction::preferences ( this, SLOT ( optionsPreferences() ), actionCollection() );
359
addTabAction = new KAction(KIcon("tab-new-background"), i18n("New &Tab"), this);
360
actionCollection()->addAction(QLatin1String("new_tab"), addTabAction);
361
addTabAction->setShortcut(Qt::CTRL + Qt::Key_T);
362
connect(addTabAction,SIGNAL(triggered()), this, SLOT(addTab()));
364
registedGlobalAction("tab-new-background", addTabAction);
366
closePageAction = new KAction(KIcon("window-close"), i18n("Close"), this);
367
actionCollection()->addAction(QLatin1String("tab_close"), closePageAction);
368
closePageAction->setShortcut(Qt::CTRL + Qt::Key_W);
369
connect(closePageAction,SIGNAL(triggered()), this, SLOT(closeTab()));
371
registedGlobalAction("tab_close", closePageAction);
373
closeAllPagesAction = new KAction(KIcon("window-close"), i18n("Close All"), this);
374
actionCollection()->addAction(QLatin1String("tab_closeall"), closeAllPagesAction);
375
closeAllPagesAction->setShortcut(Qt::ALT +Qt::Key_W);
376
connect(closeAllPagesAction,SIGNAL(triggered()), this, SLOT(closeAllTabs()));
378
registedGlobalAction("tab_closeall", closeAllPagesAction);
380
closeAllOtherPagesAction = new KAction(KIcon("window-close"), i18n("Close All Other"), this);
381
actionCollection()->addAction(QLatin1String("tab_closeallother"), closeAllOtherPagesAction);
382
closeAllOtherPagesAction->setShortcut(Qt::CTRL + Qt::ALT +Qt::Key_W);
383
connect(closeAllOtherPagesAction,SIGNAL(triggered()), this, SLOT(closeAllOtherTabs()));
385
registedGlobalAction("tab_closeallother", closeAllOtherPagesAction);
387
tipOfDayAction=KStandardAction::tipOfDay(this, SLOT(onTipOfDay()), actionCollection());
408
addTabAction = new KAction ( KIcon ( "tab-new-background" ), i18n ( "New &Tab" ), this );
409
actionCollection()->addAction ( QLatin1String ( "new_tab" ), addTabAction );
410
addTabAction->setShortcut ( Qt::CTRL + Qt::Key_T );
411
connect ( addTabAction,SIGNAL ( triggered() ), this, SLOT ( addTab() ) );
413
registedGlobalAction ( "tab-new-background", addTabAction );
415
closePageAction = new KAction ( KIcon ( "window-close" ), i18n ( "Close" ), this );
416
actionCollection()->addAction ( QLatin1String ( "tab_close" ), closePageAction );
417
closePageAction->setShortcut ( Qt::CTRL + Qt::Key_W );
418
connect ( closePageAction,SIGNAL ( triggered() ), this, SLOT ( closeTab() ) );
420
registedGlobalAction ( "tab_close", closePageAction );
422
closeAllPagesAction = new KAction ( KIcon ( "window-close" ), i18n ( "Close All" ), this );
423
actionCollection()->addAction ( QLatin1String ( "tab_closeall" ), closeAllPagesAction );
424
closeAllPagesAction->setShortcut ( Qt::ALT +Qt::Key_W );
425
connect ( closeAllPagesAction,SIGNAL ( triggered() ), this, SLOT ( closeAllTabs() ) );
427
registedGlobalAction ( "tab_closeall", closeAllPagesAction );
429
closeAllOtherPagesAction = new KAction ( KIcon ( "window-close" ), i18n ( "Close All Other" ), this );
430
actionCollection()->addAction ( QLatin1String ( "tab_closeallother" ), closeAllOtherPagesAction );
431
closeAllOtherPagesAction->setShortcut ( Qt::CTRL + Qt::ALT +Qt::Key_W );
432
connect ( closeAllOtherPagesAction,SIGNAL ( triggered() ), this, SLOT ( closeAllOtherTabs() ) );
434
registedGlobalAction ( "tab_closeallother", closeAllOtherPagesAction );
436
tipOfDayAction=KStandardAction::tipOfDay ( this, SLOT ( onTipOfDay() ), actionCollection() );
389
438
//Contextual menu
390
tabView->setContextMenuPolicy(Qt::ActionsContextMenu);
391
tabView->insertAction(0, getGlobalAction("tab-new-background"));
392
tabView->insertAction(0, getGlobalAction("tab_close"));
393
tabView->insertAction(0, getGlobalAction("tab_closeall"));
394
tabView->insertAction(0, getGlobalAction("tab_closeallother"));
439
tabView->setContextMenuPolicy ( Qt::ActionsContextMenu );
440
tabView->insertAction ( 0, getGlobalAction ( "tab-new-background" ) );
441
tabView->insertAction ( 0, getGlobalAction ( "tab_close" ) );
442
tabView->insertAction ( 0, getGlobalAction ( "tab_closeall" ) );
443
tabView->insertAction ( 0, getGlobalAction ( "tab_closeallother" ) );
508
576
void SKGMainPanel::onSettingsChanged()
511
SKGTRACEINRC(1, "SKGMainPanel::onSettingsChanged", err);
512
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
579
SKGTRACEINRC ( 1, "SKGMainPanel::onSettingsChanged", err );
580
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
514
582
int nb=pluginsList.count();
515
SKGBEGINPROGRESSTRANSACTION(*currentBankDocument, i18n("Save settings"), err, nb);
583
SKGBEGINPROGRESSTRANSACTION ( *currentBankDocument, i18n ( "Save settings" ), err, nb );
517
585
//Refresh plugins
518
for (int i = 0; err.isSucceeded() && i < nb; ++i) {
519
err=getPluginByIndex(i)->savePreferences();
520
if (err.isSucceeded()) err=currentBankDocument->stepForward(i+1);
586
for ( int i = 0; err.isSucceeded() && i < nb; ++i ) {
587
err=getPluginByIndex ( i )->savePreferences();
588
if ( err.isSucceeded() ) err=currentBankDocument->stepForward ( i+1 );
523
591
//Setting for icon
524
if (iconInSystemtray()) kSystemTrayIcon->show();
592
if ( iconInSystemtray() ) kSystemTrayIcon->show();
525
593
else kSystemTrayIcon->hide();
528
KSharedConfigPtr config=KSharedConfig::openConfig("skroogerc");
529
KConfigGroup pref=config->group("skrooge");
530
int option=pref.readEntry("update_modified_bookmarks", 0);
596
KSharedConfigPtr config=KSharedConfig::openConfig ( "skroogerc" );
597
KConfigGroup pref=config->group ( "skrooge" );
598
int option=pref.readEntry ( "update_modified_bookmarks", 0 );
532
KConfigGroup prefNotificationMessages=config->group("Notification Messages");
600
KConfigGroup prefNotificationMessages=config->group ( "Notification Messages" );
534
602
//ASK: remove following setting
535
603
//[Notification Messages]
536
604
//updateBookmarkOnClose=false
537
prefNotificationMessages.deleteEntry("updateBookmarkOnClose");
538
} else if (option==1) {
605
prefNotificationMessages.deleteEntry ( "updateBookmarkOnClose" );
606
} else if ( option==1 ) {
539
607
//ALWAYS: set following setting
540
608
//[Notification Messages]
541
609
//updateBookmarkOnClose=true
542
prefNotificationMessages.writeEntry("updateBookmarkOnClose", true);
610
prefNotificationMessages.writeEntry ( "updateBookmarkOnClose", true );
544
612
//NEVER: set following setting
545
613
//[Notification Messages]
546
614
//updateBookmarkOnClose=false
547
prefNotificationMessages.writeEntry("updateBookmarkOnClose", false);
615
prefNotificationMessages.writeEntry ( "updateBookmarkOnClose", false );
550
618
QApplication::restoreOverrideCursor();
553
displayErrorMessage(err);
621
displayErrorMessage ( err );
556
624
void SKGMainPanel::refresh()
558
SKGTRACEIN(1, "SKGMainPanel::refresh");
626
SKGTRACEIN ( 1, "SKGMainPanel::refresh" );
560
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
628
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
562
630
//Refresh plugins
563
631
int nb=pluginsList.count();
564
for (int i = 0; i < nb; ++i) {
565
getPluginByIndex(i)->refresh();
632
for ( int i = 0; i < nb; ++i ) {
633
getPluginByIndex ( i )->refresh();
568
636
//Enable addTabeAction
569
bool atLeastOnePageOpened=(tabView->count()>0);
570
addTabAction->setEnabled(atLeastOnePageOpened);
571
closePageAction->setEnabled(atLeastOnePageOpened);
572
closeAllPagesAction->setEnabled(atLeastOnePageOpened);
573
closeAllOtherPagesAction->setEnabled(tabView->count()>1);
637
bool atLeastOnePageOpened= ( tabView->count() >0 );
638
addTabAction->setEnabled ( atLeastOnePageOpened );
639
closePageAction->setEnabled ( atLeastOnePageOpened );
640
closeAllPagesAction->setEnabled ( atLeastOnePageOpened );
641
closeAllOtherPagesAction->setEnabled ( tabView->count() >1 );
575
643
//Set window title
576
644
QString modified;
577
if (currentBankDocument->isFileModified()) modified=i18n(" [modified]");
645
if ( currentBankDocument->isFileModified() ) modified=i18n ( " [modified]" );
578
646
QString fileName=currentBankDocument->getCurrentFileName();
579
if (fileName.isEmpty()) fileName=i18n("Untitled");
580
setWindowTitle(i18n("%1%2 - %3", fileName, modified, KGlobal::activeComponent ().componentName ()));
647
if ( fileName.isEmpty() ) fileName=i18n ( "Untitled" );
648
setWindowTitle ( i18n ( "%1%2 - %3", fileName, modified, KGlobal::activeComponent ().componentName () ) );
582
650
QApplication::restoreOverrideCursor();
585
SKGTabWidget* SKGMainPanel::setNewTabContent(SKGInterfacePlugin* plugin, int index, const QString& parameters, const QString& title)
653
SKGTabWidget* SKGMainPanel::setNewTabContent ( SKGInterfacePlugin* plugin, int index, const QString& parameters, const QString& title )
587
SKGTRACEIN(1, "SKGMainPanel::setNewTabContent");
588
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
655
SKGTRACEIN ( 1, "SKGMainPanel::setNewTabContent" );
656
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
589
657
SKGTabWidget* w=NULL;
592
660
int currentIndex=tabView->currentIndex();
593
if (currentIndex>=0) {
594
SKGTabWidget* currentPage=(SKGTabWidget*) tabView->currentWidget();
595
tabView->removeTab(currentIndex);
596
if (currentPage) closeTab(currentPage);
661
if ( currentIndex>=0 ) {
662
SKGTabWidget* currentPage= ( SKGTabWidget* ) tabView->currentWidget();
663
tabView->removeTab ( currentIndex );
664
if ( currentPage ) closeTab ( currentPage );
601
669
w=plugin->getWidget();
604
QString title2=(title.isEmpty() ? plugin->title() : title);
605
w->setObjectName(plugin->objectName());
606
w->setState(parameters);
607
connect(w, SIGNAL(selectionChanged()), SLOT(refresh()));
672
QString title2= ( title.isEmpty() ? plugin->title() : title );
673
w->setObjectName ( plugin->objectName() );
674
w->setState ( parameters );
675
connect ( w, SIGNAL ( selectionChanged() ), SLOT ( refresh() ) );
610
tabView->addTab(w, KIcon(plugin->icon()), title2);
611
tabView->setCurrentWidget(w);
678
tabView->addTab ( w, KIcon ( plugin->icon() ), title2 );
679
tabView->setCurrentWidget ( w );
614
tabView->insertTab(index, w, KIcon(plugin->icon()), title2);
615
tabView->setCurrentWidget(w);
682
tabView->insertTab ( index, w, KIcon ( plugin->icon() ), title2 );
683
tabView->setCurrentWidget ( w );
619
SKGTRACEL(1) << "opening plugin [" << plugin->objectName () << ']' << endl;
687
SKGTRACEL ( 1 ) << "opening plugin [" << plugin->objectName () << ']' << endl;
622
displayErrorMessage(SKGError(10, i18n("Impossible to open the page because the plugin was not found")));
690
displayErrorMessage ( SKGError ( 10, i18n ( "Impossible to open the page because the plugin was not found" ) ) );
624
692
QApplication::restoreOverrideCursor();
679
752
void SKGMainPanel::closeAllTabs()
681
SKGTRACEIN(1, "SKGMainPanel::closeAllTabs");
682
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
754
SKGTRACEIN ( 1, "SKGMainPanel::closeAllTabs" );
755
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
683
756
int nb=tabView->count();
684
for (int i=nb-1; i>=0; --i) {
685
closeTab(tabView->widget(i));
757
for ( int i=nb-1; i>=0; --i ) {
758
closeTab ( tabView->widget ( i ) );
687
760
QApplication::restoreOverrideCursor();
690
void SKGMainPanel::closeAllOtherTabs(QWidget* iWidget)
763
void SKGMainPanel::closeAllOtherTabs ( QWidget* iWidget )
692
SKGTRACEIN(1, "SKGMainPanel::closeAllOtherTabs");
693
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
765
SKGTRACEIN ( 1, "SKGMainPanel::closeAllOtherTabs" );
766
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
694
767
QWidget* toKeep=iWidget;
695
if (toKeep==NULL) toKeep=tabView->currentWidget();
768
if ( toKeep==NULL ) toKeep=tabView->currentWidget();
697
770
int nb=tabView->count();
698
for (int i=nb-1; i>=0; --i) {
699
QWidget* w=tabView->widget(i);
700
if (w!=toKeep) closeTab(w);
771
for ( int i=nb-1; i>=0; --i ) {
772
QWidget* w=tabView->widget ( i );
773
if ( w!=toKeep ) closeTab ( w );
702
775
QApplication::restoreOverrideCursor();
705
778
void SKGMainPanel::addTab()
707
SKGTRACEIN(1, "SKGMainPanel::addTab");
708
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
709
SKGTabWidget* currentPage=(SKGTabWidget*) tabView->currentWidget();
711
setNewTabContent(getPluginByName(currentPage->objectName()));
780
SKGTRACEIN ( 1, "SKGMainPanel::addTab" );
781
QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
782
SKGTabWidget* currentPage= ( SKGTabWidget* ) tabView->currentWidget();
784
setNewTabContent ( getPluginByName ( currentPage->objectName() ) );
713
786
QApplication::restoreOverrideCursor();
789
bool SKGMainPanel::eventFilter ( QObject *object, QEvent *event )
791
if ( event && object ) {
792
QResizeEvent *resizeEvent = dynamic_cast<QResizeEvent*> ( event );
794
QSize newSize=resizeEvent->size ();
797
int s=qMax ( qMin ( newSize.width() /5,64 ),16 );
798
ui.kContextList->setIconSize ( QSize ( s, s ) );
716
804
void SKGMainPanel::onTipOfDay()
718
SKGTRACEIN(1, "SKGMainPanel::onTipOfDay");
806
SKGTRACEIN ( 1, "SKGMainPanel::onTipOfDay" );
720
808
//Tip of day is available
721
809
//Creation of the manu
722
KTipDialog* tipsDialog=new KTipDialog(tipDatabase, this);
723
tipsDialog->setAttribute( Qt::WA_DeleteOnClose );
810
KTipDialog* tipsDialog=new KTipDialog ( tipDatabase, this );
811
tipsDialog->setAttribute ( Qt::WA_DeleteOnClose );
724
812
tipsDialog->show();
728
void SKGMainPanel::onTrayActivated(KSystemTrayIcon::ActivationReason reason)
816
void SKGMainPanel::onTrayActivated ( KSystemTrayIcon::ActivationReason reason )
730
SKGTRACEIN(1, "SKGMainPanel::onTrayActivated");
731
if (reason==KSystemTrayIcon::Trigger) {
732
setVisible(!isVisible());
818
SKGTRACEIN ( 1, "SKGMainPanel::onTrayActivated" );
819
if ( reason==KSystemTrayIcon::Trigger ) {
820
setVisible ( !isVisible() );
736
void SKGMainPanel::notify(int iTransaction)
824
void SKGMainPanel::notify ( int iTransaction )
738
SKGTRACEIN(1, "SKGMainPanel::notify");
826
SKGTRACEIN ( 1, "SKGMainPanel::notify" );
827
SKGTRACEL ( 1 ) << "iTransaction=" << iTransaction << endl;
743
SKGObjectBase transaction(currentBankDocument, "doctransaction", iTransaction);
744
if (transaction.getAttribute("t_mode")!="R") {
830
if ( iTransaction ) {
831
SKGObjectBase transaction ( currentBankDocument, "doctransaction", iTransaction );
832
if ( transaction.getAttribute ( "t_mode" ) !="R" ) {
746
currentBankDocument->getMessages(iTransaction, msg, false);
834
currentBankDocument->getMessages ( iTransaction, msg, false );
747
835
int nbMessages=msg.count();
751
for (int i=0; i<nbMessages; ++i) {
752
if (i!=0) message+='\n';
839
for ( int i=0; i<nbMessages; ++i ) {
840
if ( i!=0 ) message+="<br>";
841
message+=msg.at ( i );
756
KNotification *notify = new KNotification("skrooge_info_event" , this );
757
notify->setText(message);
844
KNotification *notify = new KNotification ( "skrooge_info_event" , this );
845
notify->setText ( message );
758
846
notify->sendEvent();
764
void SKGMainPanel::changeEvent(QEvent * e )
852
void SKGMainPanel::changeEvent ( QEvent * e )
766
KParts::MainWindow::changeEvent(e);
854
KParts::MainWindow::changeEvent ( e );
769
857
bool SKGMainPanel::iconInSystemtray()
771
KSharedConfigPtr config=KSharedConfig::openConfig("skroogerc");
772
KConfigGroup pref=config->group("skrooge");
773
return pref.readEntry("icon_in_system_tray",false);
859
KSharedConfigPtr config=KSharedConfig::openConfig ( "skroogerc" );
860
KConfigGroup pref=config->group ( "skrooge" );
861
return pref.readEntry ( "icon_in_system_tray",false );
776
void SKGMainPanel::displayErrorMessage(const SKGError& iError)
864
void SKGMainPanel::displayErrorMessage ( const SKGError& iError )
778
SKGTRACEIN(1, "SKGMainPanel::displayErrorMessage");
779
QWidget* parent=(SKGMainPanel*) QApplication::activeWindow();
866
SKGTRACEIN ( 1, "SKGMainPanel::displayErrorMessage" );
867
QWidget* parent= ( SKGMainPanel* ) QApplication::activeWindow();
781
if (iError.isFailed()) {
782
QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
783
int rc=KMessageBox::warningContinueCancel (parent, iError.getFullMessage(),
869
if ( iError.isFailed() ) {
870
QApplication::setOverrideCursor ( QCursor ( Qt::ArrowCursor ) );
871
int rc=KMessageBox::warningContinueCancel ( parent, iError.getFullMessage(),
785
873
KStandardGuiItem::cont(),
786
KGuiItem (i18n("History"), KIcon("dialog-information")));
874
KGuiItem ( i18n ( "History" ), KIcon ( "dialog-information" ) ) );
787
875
QApplication::restoreOverrideCursor();
788
if (rc==KMessageBox::Cancel) {
789
KMessageBox::information (parent, iError.getFullMessageWithHistorical(),
876
if ( rc==KMessageBox::Cancel ) {
877
KMessageBox::information ( parent, iError.getFullMessageWithHistorical(),
878
i18n ( "History" ) );
794
SKGMainPanel *parent2 = qobject_cast<SKGMainPanel *>(parent);
795
if (parent2) parent2->statusBar()->showMessage(iError.getMessage());
882
SKGMainPanel *parent2 = qobject_cast<SKGMainPanel *> ( parent );
883
if ( parent2 ) parent2->statusBar()->showMessage ( iError.getMessage() );
801
889
SKGMainPanel::currentActionCanceled=true;
804
int SKGMainPanel::progressBarCallBack(int iPos, void* iProgressBar)
892
void SKGMainPanel::onQuitAction()
894
//Bug 2777697: To be sure that all page modifications are closed
898
qApp->closeAllWindows();
901
void SKGMainPanel::onChangeStyleSheet ( const QString& iNewStryle )
903
QFile file ( KStandardDirs::locate ( "data", QString::fromLatin1 ( "skrooge/theme/" ) +iNewStryle+".css" ) );
904
if ( file.open ( QIODevice::ReadOnly | QIODevice::Text ) ) {
905
QTextStream in ( &file );
906
setStyleSheet ( defaultStyle+'\n'+in.readAll() );
910
KSharedConfigPtr config=KSharedConfig::openConfig ( "skroogerc" );
911
KConfigGroup pref=config->group ( "skrooge" );
912
pref.writeEntry ( "last_theme", iNewStryle );
914
SKGTRACE << "WARNING: " << file.fileName() << " does not exits for language [" << KGlobal::locale()->language() << "]" << endl;
918
int SKGMainPanel::progressBarCallBack ( int iPos, void* iProgressBar )
806
920
QProgressBar* progressBar=NULL;
807
921
QPushButton* button=NULL;
808
doublePointer* pointers=(doublePointer*) iProgressBar;
810
progressBar=(QProgressBar*) pointers->p1;
811
button=(QPushButton*) pointers->p2;
922
doublePointer* pointers= ( doublePointer* ) iProgressBar;
924
progressBar= ( QProgressBar* ) pointers->p1;
925
button= ( QPushButton* ) pointers->p2;
814
if (progressBar) progressBar->setValue(iPos);
815
if (button) button->setEnabled(iPos>0 && iPos<100);
928
if ( progressBar ) progressBar->setValue ( iPos );
929
if ( button ) button->setEnabled ( iPos>0 && iPos<100 );
817
931
SKGMainPanel::currentActionCanceled=false;
818
932
qApp->processEvents();
819
return (SKGMainPanel::currentActionCanceled ? 1 : 0);
933
return ( SKGMainPanel::currentActionCanceled ? 1 : 0 );
822
QString SKGMainPanel::getSaveFileName(const KUrl & startDir, const QString & filter, QWidget * parent, const QString & caption)
936
QString SKGMainPanel::getSaveFileName ( const KUrl & startDir, const QString & filter, QWidget * parent, const QString & caption )
824
QString fileName=KFileDialog::getSaveFileName(startDir, filter , parent, caption);
825
if (fileName.isEmpty()) return "";
827
if ( f.exists() && KMessageBox::warningContinueCancel( parent,
828
i18n("File <b>%1</b> already exists. Do you really want to overwrite it?", fileName),
829
i18n("Warning"))!=KMessageBox::Continue) return "";
938
QString fileName=KFileDialog::getSaveFileName ( startDir, filter , parent, caption );
939
if ( fileName.isEmpty() ) return "";
940
QFile f ( fileName );
941
if ( f.exists() && KMessageBox::warningContinueCancel ( parent,
942
i18n ( "File <b>%1</b> already exists. Do you really want to overwrite it?", fileName ),
943
i18n ( "Warning" ) ) !=KMessageBox::Continue ) return "";
834
void SKGMainPanel::fillComboWithDistinctValue(
948
void SKGMainPanel::fillComboWithDistinctValue (
835
949
KComboBox* iComboBox,
836
950
const SKGDocument* iDoc,
837
951
const QString& iTable,
838
952
const QString& iAttribut,
839
const QString& iWhereClause)
953
const QString& iWhereClause )
841
SKGTRACEIN(10, "SKGMainPanel::fillComboWithDistinctValue");
845
SKGServices::getDistinctValues(iDoc, iTable, iAttribut, iWhereClause, list);
846
if (list.count() && !list.at(0).isEmpty()) list.insert(0, "");
850
iComboBox->addItems(list);
853
KCompletion *comp = iComboBox->completionObject();
855
comp->insertItems(list);
955
SKGTRACEIN ( 10, "SKGMainPanel::fillComboWithDistinctValue" );
960
SKGServices::getDistinctValues ( iDoc, iTable, iAttribut, iWhereClause, list );
961
if ( list.count() && !list.at ( 0 ).isEmpty() ) list.insert ( 0, "" );
965
iComboBox->addItems ( list );
968
KCompletion *comp = iComboBox->completionObject();
970
comp->insertItems ( list );
857
973
#include "skgmainpanel.moc"