~ubuntu-branches/ubuntu/lucid/skrooge/lucid

« back to all changes in this revision

Viewing changes to skgbasegui/skgmainpanel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-05-02 06:47:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090502064715-b7l4eciitw3asos3
Tags: 0.2.7-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
#include <kfiledialog.h>
49
49
#include <kmenu.h>
50
50
#include <kcombobox.h>
 
51
#include <kselectaction.h>
 
52
#include <kstandarddirs.h>
51
53
 
52
54
#include <QtGui/QProgressBar>
53
55
#include <QtGui/QHeaderView>
54
56
#include <QApplication>
 
57
#include <QDir>
 
58
#include <QResizeEvent>
55
59
 
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
 
                tipDatabase(NULL),
64
 
                kSystemTrayIcon(NULL)
 
63
                tabView ( new KTabWidget ( this ) ),
 
64
                spScreen ( iSplashScreen ),
 
65
                currentBankDocument ( iDocument ),
 
66
                tipOfDayAction ( NULL ),closePageAction ( NULL ), closeAllPagesAction ( NULL ), closeAllOtherPagesAction ( NULL ),
 
67
                tipDatabase ( NULL ),
 
68
                kSystemTrayIcon ( NULL )
65
69
{
66
 
        SKGTRACEIN(1, "SKGMainPanel::SKGMainPanel");
 
70
        SKGTRACEIN ( 1, "SKGMainPanel::SKGMainPanel" );
67
71
 
68
72
        // accept dnd
69
 
        setAcceptDrops(true);
 
73
        setAcceptDrops ( true );
70
74
 
71
 
        ui.setupUi(this);
 
75
        ui.setupUi ( this );
72
76
 
73
77
        // tell the KXmlGuiWindow that this is indeed the main widget
74
 
        setCentralWidget(tabView);
 
78
        setCentralWidget ( tabView );
75
79
 
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 );
83
87
 
84
88
        tabView->show();
85
89
 
86
90
        //System tray
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() ) );
92
96
 
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();
96
100
        }
97
101
 
98
102
        // then, setup our actions
99
103
        setupActions();
100
104
 
101
105
        //Search plugins
102
 
        KService::List offers=KServiceTypeTrader::self()->query(QLatin1String("Skrooge/Plugin"));
 
106
        KService::List offers=KServiceTypeTrader::self()->query ( QLatin1String ( "Skrooge/Plugin" ) );
103
107
 
104
108
        //Create temporary file for tips
105
109
        KTemporaryFile tipsFile;
106
 
        tipsFile.setSuffix(".tips");
 
110
        tipsFile.setSuffix ( ".tips" );
107
111
 
108
112
        bool tipsFileOpened=tipsFile.open();
109
113
        bool tipsFound=false;
110
114
 
111
 
        QTextStream stream(&tipsFile);
 
115
        QTextStream stream ( &tipsFile );
112
116
 
113
117
        //Load plugins
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
117
121
        SKGError err;
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();
126
 
                if (factory) {
127
 
                        SKGInterfacePlugin *pluginInterface = factory->create<SKGInterfacePlugin>(this);
128
 
                        if (pluginInterface) {
129
 
                                if (pluginInterface->isEnabled()) {
130
 
                                        pluginInterface->setupActions(this, currentBankDocument, iArguments);
 
130
                if ( factory ) {
 
131
                        SKGInterfacePlugin *pluginInterface = factory->create<SKGInterfacePlugin> ( this );
 
132
                        if ( pluginInterface ) {
 
133
                                if ( pluginInterface->isEnabled() ) {
 
134
                                        pluginInterface->setupActions ( this, currentBankDocument, iArguments );
131
135
 
132
136
                                        //Store plugin
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() ) {
137
141
                                                        pos=j;
138
142
                                                }
139
143
                                        }
140
144
 
141
 
                                        pluginsList.insert(pos, pluginInterface);
142
 
                                        pluginInterface->setObjectName(name);
 
145
                                        pluginsList.insert ( pos, pluginInterface );
 
146
                                        pluginInterface->setObjectName ( name );
143
147
 
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 ) {
149
153
                                                        tipsFound=true;
150
154
                                                        stream << "<tip category=\""
151
155
                                                        << name
152
 
                                                        << "\"><html>"<< tipsList.at(t)
 
156
                                                        << "\"><html>"<< tipsList.at ( t )
153
157
                                                        << "</html></tip>"
154
158
                                                        << endl;
155
159
                                                }
156
160
                                        }
157
161
                                }
158
162
                        } else {
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() ) );
160
164
                        }
161
165
                } else {
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() ) );
165
169
                }
166
170
        }
167
171
 
168
172
        spScreen=NULL;
169
173
 
170
 
        displayErrorMessage(err);
 
174
        displayErrorMessage ( err );
171
175
 
172
176
        //Display tips
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() );
177
181
        }
178
182
 
179
 
        if (tipsFileOpened) {
 
183
        if ( tipsFileOpened ) {
180
184
                tipsFile.close();
181
185
        }
182
186
 
183
 
        // add a status bar
 
187
        //Add a status bar
184
188
        statusBar()->show();
185
189
 
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() );
 
194
 
 
195
        //Add style sheet menu
 
196
        QDir dirTheme ( KStandardDirs::locate ( "data", QString::fromLatin1 ( "skrooge/theme/" ) ) );
 
197
        dirTheme.setFilter ( QDir::Files );
 
198
        QStringList filters;
 
199
        filters << "*.css";
 
200
        dirTheme.setNameFilters ( filters );
 
201
        QStringList listThemes = dirTheme.entryList();
 
202
        int nbt=listThemes.size();
 
203
        if ( nbt>1 ) {
 
204
                defaultStyle=styleSheet();
 
205
                KSelectAction* styleSheetMenu = new KSelectAction ( KIcon ( "view-media-visualization" ), i18n ( "Theme" ), this );
 
206
                actionCollection()->addAction ( QLatin1String ( "view_stylesheet" ), styleSheetMenu );
 
207
 
 
208
                KSharedConfigPtr config=KSharedConfig::openConfig ( "skroogerc" );
 
209
                KConfigGroup pref=config->group ( "skrooge" );
 
210
                QString lastTheme=pref.readEntry ( "last_theme", "default" );
 
211
 
 
212
                for ( int i=0; i<nbt ; ++i ) {
 
213
                        QString themeName=listThemes.at ( i );
 
214
                        themeName.remove ( ".css" );
 
215
 
 
216
                        KAction* action=styleSheetMenu->addAction ( themeName );
 
217
                        if ( themeName==lastTheme ) styleSheetMenu->setCurrentAction ( action );
 
218
                }
 
219
                onChangeStyleSheet ( lastTheme );
 
220
                connect ( styleSheetMenu, SIGNAL ( triggered ( QString ) ), this, SLOT ( onChangeStyleSheet ( QString ) ), Qt::QueuedConnection );
 
221
        } else onChangeStyleSheet ( "default" );
 
222
 
 
223
 
 
224
        KSelectAction* contextMenu = new KSelectAction ( KIcon ( "tab-new" ), i18n ( "Context" ), this );
 
225
        actionCollection()->addAction ( "view_contextmenu" , contextMenu );
190
226
 
191
227
        //Add plugin in client in right order
 
228
        int shortCutIndex=0;
192
229
        int nbplugin=pluginsList.count();
193
 
        for (int j=0; j<nbplugin; ++j) {
194
 
                SKGInterfacePlugin *pluginInterface=pluginsList.at(j);
195
 
 
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());
204
 
 
205
 
                        ui.kContextList->addItem(contextItem);
206
 
                        ui.kContextList->setItemHidden (contextItem, !pluginInterface->isInContext());
207
 
 
208
 
                        //TODO: Add menu item with shortcuts
209
 
 
210
 
                        //Create dock if needed
211
 
                        QDockWidget* dockWidget=pluginInterface->getDockWidget();
212
 
                        if (dockWidget) {
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);
 
244
 
 
245
                                ui.kContextList->addItem ( contextItem );
 
246
                                ui.kContextList->setItemHidden ( contextItem, !visible );
 
247
 
 
248
                                //Add menu item with shortcuts
 
249
                                if (visible) {
 
250
                                        KAction* action=contextMenu->addAction ( icon, title );
 
251
                                        action->setCheckable(false);
 
252
                                        action->setData(j);
 
253
                                        ++shortCutIndex;
 
254
                                        action->setShortcut("Ctrl+"+SKGServices::intToString(shortCutIndex));
 
255
                                        connect(action, SIGNAL(triggered(bool)), this, SLOT(onOpenContext()));
 
256
                                }
 
257
 
 
258
                                //Create dock if needed
 
259
                                QDockWidget* dockWidget=pluginInterface->getDockWidget();
 
260
                                if ( dockWidget )  this->addDockWidget ( Qt::LeftDockWidgetArea, dockWidget );
214
261
                        }
215
262
                }
216
263
        }
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");
224
 
 
225
 
        for (int j=0; j<nbplugin; ++j) {
226
 
                guiFactory()->addClient(pluginsList.at(j));
227
 
 
 
270
        setupGUI ( Default, "skrooge.rc" );
 
271
 
 
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 );
 
278
                }
228
279
        }
229
280
 
230
281
        //Set status bar
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" ) );
240
291
 
241
 
        statusBar()->addPermanentWidget(kProgressBar);
 
292
        statusBar()->addPermanentWidget ( kProgressBar );
242
293
 
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() ) );
252
303
 
253
 
        statusBar()->addPermanentWidget(kCancelButton);
 
304
        statusBar()->addPermanentWidget ( kCancelButton );
254
305
 
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 );
260
311
        }
261
312
 
262
313
        //Connection
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 );
266
317
        }
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() ) );
272
323
 
273
324
        //Refresh
274
325
        refresh();
275
326
 
276
327
        //Tip of day
277
 
        if (tipDatabase) {
 
328
        if ( tipDatabase ) {
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();
282
333
        } else {
283
334
                //Remove useless menu
284
335
                delete tipOfDayAction;
285
336
                tipOfDayAction=NULL;
286
337
        }
 
338
 
 
339
        ui.kContextList->installEventFilter ( this );
287
340
}
288
341
 
289
342
SKGMainPanel::~SKGMainPanel()
290
343
{
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 );
293
346
 
294
347
        //close plugins
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();
298
351
        }
299
352
 
300
353
 
301
 
        if (tipDatabase) {
 
354
        if ( tipDatabase ) {
302
355
                delete tipDatabase;
303
356
                tipDatabase=NULL;
304
357
        }
305
358
 
306
 
        if (currentBankDocument) {
 
359
        if ( currentBankDocument ) {
307
360
                currentBankDocument->close();
308
361
        }
309
362
}
310
363
 
311
 
void SKGMainPanel::registedGlobalAction(const QString& iIdentifier, KAction* iAction)
 
364
void SKGMainPanel::registedGlobalAction ( const QString& iIdentifier, KAction* iAction )
312
365
{
313
366
        registeredGlogalAction[iIdentifier]=iAction;
314
367
}
315
368
 
316
 
KAction* SKGMainPanel::getGlobalAction(const QString& iIdentifier)
 
369
KAction* SKGMainPanel::getGlobalAction ( const QString& iIdentifier )
317
370
{
318
371
        return registeredGlogalAction[iIdentifier];
319
372
}
320
373
 
321
 
SKGInterfacePlugin * SKGMainPanel::getPluginByIndex(int iIndex)
 
374
SKGInterfacePlugin * SKGMainPanel::getPluginByIndex ( int iIndex )
322
375
{
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];
328
379
        }
329
380
 
330
381
        return output;
331
382
}
332
383
 
333
 
SKGInterfacePlugin * SKGMainPanel::getPluginByName(const QString& iName)
 
384
SKGInterfacePlugin * SKGMainPanel::getPluginByName ( const QString& iName )
334
385
{
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];
342
391
                }
343
392
        }
347
396
 
348
397
void SKGMainPanel::setupActions()
349
398
{
350
 
        SKGTRACEIN(1, "SKGMainPanel::setupActions");
 
399
        SKGTRACEIN ( 1, "SKGMainPanel::setupActions" );
351
400
 
352
401
        //Std File
353
 
        KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection());
 
402
        KStandardAction::quit ( this, SLOT ( onQuitAction() ), actionCollection() );
354
403
 
355
404
        //Preferences
356
 
        KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
 
405
        KStandardAction::preferences ( this, SLOT ( optionsPreferences() ), actionCollection() );
357
406
 
358
407
        // New Tab
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()));
363
 
 
364
 
        registedGlobalAction("tab-new-background", addTabAction);
365
 
 
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()));
370
 
 
371
 
        registedGlobalAction("tab_close", closePageAction);
372
 
 
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()));
377
 
 
378
 
        registedGlobalAction("tab_closeall", closeAllPagesAction);
379
 
 
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()));
384
 
 
385
 
        registedGlobalAction("tab_closeallother", closeAllOtherPagesAction);
386
 
 
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() ) );
 
412
 
 
413
        registedGlobalAction ( "tab-new-background", addTabAction );
 
414
 
 
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() ) );
 
419
 
 
420
        registedGlobalAction ( "tab_close", closePageAction );
 
421
 
 
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() ) );
 
426
 
 
427
        registedGlobalAction ( "tab_closeall", closeAllPagesAction );
 
428
 
 
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() ) );
 
433
 
 
434
        registedGlobalAction ( "tab_closeallother", closeAllOtherPagesAction );
 
435
 
 
436
        tipOfDayAction=KStandardAction::tipOfDay ( this, SLOT ( onTipOfDay() ), actionCollection() );
388
437
 
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" ) );
395
444
 
396
445
        //Refresh
397
446
        refresh();
399
448
 
400
449
bool SKGMainPanel::queryClose()
401
450
{
402
 
        SKGTRACEIN(1, "SKGMainPanel::queryClose");
 
451
        SKGTRACEIN ( 1, "SKGMainPanel::queryClose" );
 
452
        //Bug 2777697: To be sure that all page modifications are closed
 
453
        closeAllTabs();
 
454
        //Bug 2777697:
 
455
 
403
456
        bool output=queryFileClose();
404
457
 
405
 
        if (output && kSystemTrayIcon) {
 
458
        if ( output && kSystemTrayIcon ) {
406
459
                kSystemTrayIcon->hide();
407
460
                delete kSystemTrayIcon;
408
461
                kSystemTrayIcon=NULL;
413
466
 
414
467
bool SKGMainPanel::queryFileClose()
415
468
{
416
 
        SKGTRACEIN(1, "SKGMainPanel::queryFileClose");
 
469
        SKGTRACEIN ( 1, "SKGMainPanel::queryFileClose" );
417
470
        bool output=true;
418
 
        if (currentBankDocument->getCurrentTransaction()) {
419
 
                QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
420
 
                KMessageBox::information(this,i18n("Application can be close until an operation is running."));
 
471
        if ( currentBankDocument->getCurrentTransaction() ) {
 
472
                QApplication::setOverrideCursor ( QCursor ( Qt::ArrowCursor ) );
 
473
                KMessageBox::information ( this,i18n ( "Application can be closed until an operation is running." ) );
421
474
                QApplication::restoreOverrideCursor();
422
475
                output=false;
423
 
        } else if (currentBankDocument->isFileModified() && currentBankDocument->getDatabaseMode()!=SKGDocument::DirectAccess) {
424
 
                QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
425
 
                int code=KMessageBox::questionYesNo(this,i18n("Current modifications will not be saved.\nDo you want to continue ?"));
 
476
        } else if ( currentBankDocument->isFileModified() && currentBankDocument->getDatabaseMode() !=SKGDocument::DirectAccess ) {
 
477
                QApplication::setOverrideCursor ( QCursor ( Qt::ArrowCursor ) );
 
478
                int code=KMessageBox::Cancel;
 
479
                QString fileName=currentBankDocument->getCurrentFileName();
 
480
                KAction* save=getGlobalAction ( fileName.isEmpty() ? "file_save_as" : "file_save" );
 
481
                if ( save ) {
 
482
                        code=KMessageBox::questionYesNoCancel ( this, i18n ( "The document has been modified.\nDo you want to save it before closing ?" ),
 
483
                                                                QString(),
 
484
                                                                KGuiItem ( fileName.isEmpty() ?  i18n ( "Save as" ) : i18n ( "Save" ),
 
485
                                                                           KIcon ( fileName.isEmpty() ?  "document-save-as" : "document-save" ) ),
 
486
                                                                KGuiItem ( i18n ( "Do not save" ) )
 
487
                                                              );
 
488
                        if ( code==KMessageBox::Yes ) save->trigger();
 
489
                        output= ( code==KMessageBox::No || code==KMessageBox::Yes );
 
490
                } else {
 
491
                        code=KMessageBox::questionYesNo ( this,i18n ( "Current modifications will not be saved.\nDo you want to continue ?" ) );
 
492
                        output= ( code==KMessageBox::Yes );
 
493
                }
426
494
                QApplication::restoreOverrideCursor();
427
 
                output=(code==KMessageBox::Yes);
428
495
        }
429
496
 
430
497
        return output;
434
501
{
435
502
        SKGObjectBase::SKGListSKGObjectBase selection;
436
503
 
437
 
        SKGTabWidget* currentPage=(SKGTabWidget*) tabView->currentWidget();
438
 
        if (currentPage) {
 
504
        SKGTabWidget* currentPage= ( SKGTabWidget* ) tabView->currentWidget();
 
505
        if ( currentPage ) {
439
506
                selection=currentPage->getSelectedObjects();
440
507
        }
441
508
        return selection;
445
512
{
446
513
        int nb=0;
447
514
 
448
 
        SKGTabWidget* currentPage=(SKGTabWidget*) tabView->currentWidget();
449
 
        if (currentPage) {
 
515
        SKGTabWidget* currentPage= ( SKGTabWidget* ) tabView->currentWidget();
 
516
        if ( currentPage ) {
450
517
                nb=currentPage->getNbSelectedObjects();
451
518
        }
452
519
        return nb;
454
521
 
455
522
void SKGMainPanel::optionsPreferences()
456
523
{
457
 
        SKGTRACEIN(1, "SKGMainPanel::optionsPreferences");
 
524
        SKGTRACEIN ( 1, "SKGMainPanel::optionsPreferences" );
458
525
        //Synchronize setting with confirmation panel
459
526
        KMessageBox::ButtonCode confirm;
460
 
        int ask=KMessageBox::shouldBeShownYesNo("updateBookmarkOnClose", confirm);
 
527
        int ask=KMessageBox::shouldBeShownYesNo ( "updateBookmarkOnClose", confirm );
461
528
 
462
 
        KSharedConfigPtr config=KSharedConfig::openConfig("skroogerc");
463
 
        KConfigGroup pref=config->group("skrooge");
464
 
        if (ask) {
465
 
                pref.writeEntry("update_modified_bookmarks", 0);
466
 
        } else if (confirm==KMessageBox::Yes) {
467
 
                pref.writeEntry("update_modified_bookmarks", 1);
 
529
        KSharedConfigPtr config=KSharedConfig::openConfig ( "skroogerc" );
 
530
        KConfigGroup pref=config->group ( "skrooge" );
 
531
        if ( ask ) {
 
532
                pref.writeEntry ( "update_modified_bookmarks", 0 );
 
533
        } else if ( confirm==KMessageBox::Yes ) {
 
534
                pref.writeEntry ( "update_modified_bookmarks", 1 );
468
535
        } else {
469
 
                pref.writeEntry("update_modified_bookmarks", 2);
 
536
                pref.writeEntry ( "update_modified_bookmarks", 2 );
470
537
        }
471
538
 
472
539
        skrooge::self()->readConfig();
476
543
        // compare the names of the widgets in the .ui file
477
544
        // to the names of the variables in the .kcfg file
478
545
        //avoid to have 2 dialogs shown
479
 
        if ( KConfigDialog::showDialog( "settings" ) )  {
 
546
        if ( KConfigDialog::showDialog ( "settings" ) )  {
480
547
                return;
481
548
        }
482
 
        KConfigDialog *dialog = new KConfigDialog(this, "settings", skrooge::self());
 
549
        KConfigDialog *dialog = new KConfigDialog ( this, "settings", skrooge::self() );
483
550
 
484
551
        //Add main
485
552
        QWidget* widget=new QWidget();
486
 
        uipref.setupUi(widget);
487
 
        dialog->addPage(widget, skrooge::self(), i18n("General"), "preferences-other");
 
553
        uipref.setupUi ( widget );
 
554
        dialog->addPage ( widget, skrooge::self(), i18n ( "General" ), "preferences-other" );
488
555
 
489
556
        //Add plugin in client in right order
490
557
        int nbplugin=pluginsList.count();
491
 
        for (int j=0; j<nbplugin; ++j) {
492
 
                SKGInterfacePlugin *pluginInterface=getPluginByIndex(j);
493
 
 
494
 
                QWidget* w=pluginInterface->getPreferenceWidget();
495
 
                if (w) {
496
 
                        dialog->addPage(w, pluginInterface->getPreferenceSkeleton(), pluginInterface->title(), pluginInterface->icon());
 
558
        for ( int j=0; j<nbplugin; ++j ) {
 
559
                SKGInterfacePlugin *pluginInterface=getPluginByIndex ( j );
 
560
                if ( pluginInterface ) {
 
561
                        QWidget* w=pluginInterface->getPreferenceWidget();
 
562
                        if ( w ) {
 
563
                                dialog->addPage ( w, pluginInterface->getPreferenceSkeleton(), pluginInterface->title(), pluginInterface->icon() );
 
564
                        }
497
565
                }
498
566
        }
499
 
        connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(onSettingsChanged()));
 
567
        connect ( dialog, SIGNAL ( settingsChanged ( const QString& ) ), this, SLOT ( onSettingsChanged() ) );
500
568
 
501
 
        dialog->setAttribute( Qt::WA_DeleteOnClose );
 
569
        dialog->setAttribute ( Qt::WA_DeleteOnClose );
502
570
        dialog->show();
503
571
 
504
572
        //Refresh
508
576
void SKGMainPanel::onSettingsChanged()
509
577
{
510
578
        SKGError err;
511
 
        SKGTRACEINRC(1, "SKGMainPanel::onSettingsChanged", err);
512
 
        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
 
579
        SKGTRACEINRC ( 1, "SKGMainPanel::onSettingsChanged", err );
 
580
        QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
513
581
        {
514
582
                int nb=pluginsList.count();
515
 
                SKGBEGINPROGRESSTRANSACTION(*currentBankDocument, i18n("Save settings"), err, nb);
 
583
                SKGBEGINPROGRESSTRANSACTION ( *currentBankDocument, i18n ( "Save settings" ), err, nb );
516
584
 
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 );
521
589
                }
522
590
 
523
591
                //Setting for icon
524
 
                if (iconInSystemtray()) kSystemTrayIcon->show();
 
592
                if ( iconInSystemtray() ) kSystemTrayIcon->show();
525
593
                else kSystemTrayIcon->hide();
526
594
 
527
595
                //
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 );
531
599
 
532
 
                KConfigGroup prefNotificationMessages=config->group("Notification Messages");
533
 
                if (option==0) {
 
600
                KConfigGroup prefNotificationMessages=config->group ( "Notification Messages" );
 
601
                if ( option==0 ) {
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 );
543
611
                } else {
544
612
                        //NEVER: set following setting
545
613
                        //[Notification Messages]
546
614
                        //updateBookmarkOnClose=false
547
 
                        prefNotificationMessages.writeEntry("updateBookmarkOnClose", false);
 
615
                        prefNotificationMessages.writeEntry ( "updateBookmarkOnClose", false );
548
616
                }
549
617
        }
550
618
        QApplication::restoreOverrideCursor();
551
619
 
552
620
        //Display error
553
 
        displayErrorMessage(err);
 
621
        displayErrorMessage ( err );
554
622
}
555
623
 
556
624
void SKGMainPanel::refresh()
557
625
{
558
 
        SKGTRACEIN(1, "SKGMainPanel::refresh");
 
626
        SKGTRACEIN ( 1, "SKGMainPanel::refresh" );
559
627
 
560
 
        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
 
628
        QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
561
629
 
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();
566
634
        }
567
635
 
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 );
574
642
 
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 () ) );
581
649
 
582
650
        QApplication::restoreOverrideCursor();
583
651
}
584
652
 
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 )
586
654
{
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;
590
658
 
591
 
        if (index!=-1) {
 
659
        if ( index!=-1 ) {
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 );
597
665
                }
598
666
        }
599
667
 
600
 
        if (plugin) {
 
668
        if ( plugin ) {
601
669
                w=plugin->getWidget();
602
 
                if (w) {
 
670
                if ( w ) {
603
671
                        //Title
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() ) );
608
676
 
609
 
                        if (index==-1) {
610
 
                                tabView->addTab(w, KIcon(plugin->icon()), title2);
611
 
                                tabView->setCurrentWidget(w);
 
677
                        if ( index==-1 ) {
 
678
                                tabView->addTab ( w, KIcon ( plugin->icon() ), title2 );
 
679
                                tabView->setCurrentWidget ( w );
612
680
 
613
681
                        } else {
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 );
616
684
 
617
685
                                refresh();
618
686
                        }
619
 
                        SKGTRACEL(1) << "opening plugin [" << plugin->objectName () << ']' << endl;
 
687
                        SKGTRACEL ( 1 ) << "opening plugin [" << plugin->objectName () << ']' << endl;
620
688
                }
621
689
        } else {
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" ) ) );
623
691
        }
624
692
        QApplication::restoreOverrideCursor();
625
693
        return w;
632
700
 
633
701
SKGTabWidget* SKGMainPanel::currentTab() const
634
702
{
635
 
        return (SKGTabWidget*) tabView->currentWidget();
636
 
}
637
 
 
638
 
KListWidget* SKGMainPanel::contextList() const
639
 
{
640
 
        return ui.kContextList;
 
703
        return ( SKGTabWidget* ) tabView->currentWidget();
641
704
}
642
705
 
643
706
KSplashScreen* SKGMainPanel::splashScreen() const
650
713
        return tabView->count();
651
714
}
652
715
 
653
 
void SKGMainPanel::setCurrentTabIndex(int iIndex)
 
716
void SKGMainPanel::setCurrentTabIndex ( int iIndex )
654
717
{
655
 
        tabView->setCurrentIndex(iIndex);
 
718
        tabView->setCurrentIndex ( iIndex );
656
719
}
657
720
 
658
 
void SKGMainPanel::setTabContentFromList(QListWidgetItem* item)
 
721
void SKGMainPanel::onOpenContext ()
659
722
{
660
 
        SKGTRACEIN(1, "SKGMainPanel::setTabContentFromList");
661
 
        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
662
 
        setNewTabContent(getPluginByIndex(ui.kContextList->row(item)), QApplication::keyboardModifiers()&Qt::ControlModifier ? -1 : tabView->currentIndex());
 
723
        SKGTRACEIN ( 1, "SKGMainPanel::onOpenContext" );
 
724
        QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
 
725
        int index=-1;
 
726
        QAction* sender=dynamic_cast<QAction*> ( this->sender() );
 
727
        if (sender) {
 
728
                index=sender->data().toInt();
 
729
        } else {
 
730
                QList<QListWidgetItem *> selection=ui.kContextList->selectedItems ();
 
731
                if (selection.count()>0) {
 
732
                        index=selection.at(0)->data(12).toInt();
 
733
                }
 
734
        }
 
735
        if (index!=-1) setNewTabContent ( getPluginByIndex ( index ), QApplication::keyboardModifiers() &Qt::ControlModifier ? -1 : tabView->currentIndex() );
663
736
        QApplication::restoreOverrideCursor();
664
737
}
665
738
 
666
 
void SKGMainPanel::closeTab(QWidget* iWidget)
 
739
void SKGMainPanel::closeTab ( QWidget* iWidget )
667
740
{
668
 
        SKGTRACEIN(1, "SKGMainPanel::closeTab");
669
 
        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
 
741
        SKGTRACEIN ( 1, "SKGMainPanel::closeTab" );
 
742
        QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
670
743
        QWidget* toRemove=iWidget;
671
 
        if (toRemove==NULL)  toRemove=tabView->currentWidget();
672
 
        if (toRemove) {
673
 
                ((SKGTabWidget*) toRemove)->close();
 
744
        if ( toRemove==NULL )  toRemove=tabView->currentWidget();
 
745
        if ( toRemove ) {
 
746
                ( ( SKGTabWidget* ) toRemove )->close();
674
747
                delete toRemove;
675
748
        }
676
749
        QApplication::restoreOverrideCursor();
678
751
 
679
752
void SKGMainPanel::closeAllTabs()
680
753
{
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 ) );
686
759
        }
687
760
        QApplication::restoreOverrideCursor();
688
761
}
689
762
 
690
 
void SKGMainPanel::closeAllOtherTabs(QWidget* iWidget)
 
763
void SKGMainPanel::closeAllOtherTabs ( QWidget* iWidget )
691
764
{
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();
696
769
 
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 );
701
774
        }
702
775
        QApplication::restoreOverrideCursor();
703
776
}
704
777
 
705
778
void SKGMainPanel::addTab()
706
779
{
707
 
        SKGTRACEIN(1, "SKGMainPanel::addTab");
708
 
        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
709
 
        SKGTabWidget* currentPage=(SKGTabWidget*) tabView->currentWidget();
710
 
        if (currentPage) {
711
 
                setNewTabContent(getPluginByName(currentPage->objectName()));
 
780
        SKGTRACEIN ( 1, "SKGMainPanel::addTab" );
 
781
        QApplication::setOverrideCursor ( QCursor ( Qt::WaitCursor ) );
 
782
        SKGTabWidget* currentPage= ( SKGTabWidget* ) tabView->currentWidget();
 
783
        if ( currentPage ) {
 
784
                setNewTabContent ( getPluginByName ( currentPage->objectName() ) );
712
785
        }
713
786
        QApplication::restoreOverrideCursor();
714
787
}
715
788
 
 
789
bool SKGMainPanel::eventFilter ( QObject *object, QEvent *event )
 
790
{
 
791
        if ( event && object ) {
 
792
                QResizeEvent *resizeEvent = dynamic_cast<QResizeEvent*> ( event );
 
793
                if ( resizeEvent ) {
 
794
                        QSize newSize=resizeEvent->size ();
 
795
 
 
796
                        //Compute icon size
 
797
                        int s=qMax ( qMin ( newSize.width() /5,64 ),16 );
 
798
                        ui.kContextList->setIconSize ( QSize ( s, s ) );
 
799
                }
 
800
        }
 
801
        return false;
 
802
}
 
803
 
716
804
void SKGMainPanel::onTipOfDay()
717
805
{
718
 
        SKGTRACEIN(1, "SKGMainPanel::onTipOfDay");
719
 
        if (tipDatabase) {
 
806
        SKGTRACEIN ( 1, "SKGMainPanel::onTipOfDay" );
 
807
        if ( tipDatabase ) {
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();
725
813
        }
726
814
}
727
815
 
728
 
void SKGMainPanel::onTrayActivated(KSystemTrayIcon::ActivationReason reason)
 
816
void SKGMainPanel::onTrayActivated ( KSystemTrayIcon::ActivationReason reason )
729
817
{
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() );
733
821
        }
734
822
}
735
823
 
736
 
void SKGMainPanel::notify(int iTransaction)
 
824
void SKGMainPanel::notify ( int iTransaction )
737
825
{
738
 
        SKGTRACEIN(1, "SKGMainPanel::notify");
 
826
        SKGTRACEIN ( 1, "SKGMainPanel::notify" );
 
827
        SKGTRACEL ( 1 ) << "iTransaction=" << iTransaction << endl;
739
828
 
740
829
        //Notify
741
 
        if (iTransaction) {
742
 
 
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" ) {
745
833
                        QStringList msg;
746
 
                        currentBankDocument->getMessages(iTransaction, msg, false);
 
834
                        currentBankDocument->getMessages ( iTransaction, msg, false );
747
835
                        int nbMessages=msg.count();
748
 
                        if (nbMessages) {
 
836
                        if ( nbMessages ) {
749
837
                                //Build message
750
838
                                QString message;
751
 
                                for (int i=0; i<nbMessages; ++i) {
752
 
                                        if (i!=0) message+='\n';
753
 
                                        message+=msg.at(i);
 
839
                                for ( int i=0; i<nbMessages; ++i ) {
 
840
                                        if ( i!=0 ) message+="<br>";
 
841
                                        message+=msg.at ( i );
754
842
                                }
755
843
 
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();
759
847
                        }
760
848
                }
761
849
        }
762
850
}
763
851
 
764
 
void SKGMainPanel::changeEvent(QEvent * e )
 
852
void SKGMainPanel::changeEvent ( QEvent * e )
765
853
{
766
 
        KParts::MainWindow::changeEvent(e);
 
854
        KParts::MainWindow::changeEvent ( e );
767
855
}
768
856
 
769
857
bool SKGMainPanel::iconInSystemtray()
770
858
{
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 );
774
862
}
775
863
 
776
 
void SKGMainPanel::displayErrorMessage(const SKGError& iError)
 
864
void SKGMainPanel::displayErrorMessage ( const SKGError& iError )
777
865
{
778
 
        SKGTRACEIN(1, "SKGMainPanel::displayErrorMessage");
779
 
        QWidget* parent=(SKGMainPanel*) QApplication::activeWindow();
 
866
        SKGTRACEIN ( 1, "SKGMainPanel::displayErrorMessage" );
 
867
        QWidget* parent= ( SKGMainPanel* ) QApplication::activeWindow();
780
868
 
781
 
        if (iError.isFailed()) {
782
 
                QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
783
 
                int rc=KMessageBox::warningContinueCancel (parent, iError.getFullMessage(),
784
 
                                i18n("Warning"),
 
869
        if ( iError.isFailed() ) {
 
870
                QApplication::setOverrideCursor ( QCursor ( Qt::ArrowCursor ) );
 
871
                int rc=KMessageBox::warningContinueCancel ( parent, iError.getFullMessage(),
 
872
                                i18n ( "Warning" ),
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(),
790
 
                                                  i18n("History"));
 
876
                if ( rc==KMessageBox::Cancel ) {
 
877
                        KMessageBox::information ( parent, iError.getFullMessageWithHistorical(),
 
878
                                                   i18n ( "History" ) );
791
879
                }
792
880
        } else {
793
881
                //Status bar
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() );
796
884
        }
797
885
}
798
886
 
801
889
        SKGMainPanel::currentActionCanceled=true;
802
890
}
803
891
 
804
 
int SKGMainPanel::progressBarCallBack(int iPos, void* iProgressBar)
 
892
void SKGMainPanel::onQuitAction()
 
893
{
 
894
        //Bug 2777697: To be sure that all page modifications are closed
 
895
        closeAllTabs();
 
896
        //Bug 2777697:
 
897
 
 
898
        qApp->closeAllWindows();
 
899
}
 
900
 
 
901
void SKGMainPanel::onChangeStyleSheet ( const QString& iNewStryle )
 
902
{
 
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() );
 
907
 
 
908
                file.close();
 
909
 
 
910
                KSharedConfigPtr config=KSharedConfig::openConfig ( "skroogerc" );
 
911
                KConfigGroup pref=config->group ( "skrooge" );
 
912
                pref.writeEntry ( "last_theme", iNewStryle );
 
913
        } else {
 
914
                SKGTRACE << "WARNING: " << file.fileName() << " does not exits for language [" << KGlobal::locale()->language() << "]" << endl;
 
915
        }
 
916
}
 
917
 
 
918
int SKGMainPanel::progressBarCallBack ( int iPos, void* iProgressBar )
805
919
{
806
920
        QProgressBar* progressBar=NULL;
807
921
        QPushButton* button=NULL;
808
 
        doublePointer* pointers=(doublePointer*) iProgressBar;
809
 
        if (pointers) {
810
 
                progressBar=(QProgressBar*) pointers->p1;
811
 
                button=(QPushButton*) pointers->p2;
 
922
        doublePointer* pointers= ( doublePointer* ) iProgressBar;
 
923
        if ( pointers ) {
 
924
                progressBar= ( QProgressBar* ) pointers->p1;
 
925
                button= ( QPushButton* ) pointers->p2;
812
926
        }
813
927
 
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 );
816
930
 
817
931
        SKGMainPanel::currentActionCanceled=false;
818
932
        qApp->processEvents();
819
 
        return (SKGMainPanel::currentActionCanceled ? 1 : 0);
 
933
        return ( SKGMainPanel::currentActionCanceled ? 1 : 0 );
820
934
}
821
935
 
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 )
823
937
{
824
 
        QString fileName=KFileDialog::getSaveFileName(startDir, filter , parent, caption);
825
 
        if (fileName.isEmpty()) return "";
826
 
        QFile f( fileName );
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 "";
830
944
 
831
945
        return fileName;
832
946
}
833
947
 
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 )
840
954
{
841
 
        SKGTRACEIN(10, "SKGMainPanel::fillComboWithDistinctValue");
842
 
 
843
 
        //Get list
844
 
        QStringList list;
845
 
        SKGServices::getDistinctValues(iDoc, iTable, iAttribut, iWhereClause, list);
846
 
        if (list.count() && !list.at(0).isEmpty()) list.insert(0, "");
847
 
 
848
 
        //Fill combo
849
 
        iComboBox->clear();
850
 
        iComboBox->addItems(list);
851
 
 
852
 
        //Fill completion
853
 
        KCompletion *comp = iComboBox->completionObject();
854
 
        comp->clear ();
855
 
        comp->insertItems(list);
 
955
        SKGTRACEIN ( 10, "SKGMainPanel::fillComboWithDistinctValue" );
 
956
 
 
957
        if ( iComboBox ) {
 
958
                //Get list
 
959
                QStringList list;
 
960
                SKGServices::getDistinctValues ( iDoc, iTable, iAttribut, iWhereClause, list );
 
961
                if ( list.count() && !list.at ( 0 ).isEmpty() ) list.insert ( 0, "" );
 
962
 
 
963
                //Fill combo
 
964
                iComboBox->clear();
 
965
                iComboBox->addItems ( list );
 
966
 
 
967
                //Fill completion
 
968
                KCompletion *comp = iComboBox->completionObject();
 
969
                comp->clear ();
 
970
                comp->insertItems ( list );
 
971
        }
856
972
}
857
973
#include "skgmainpanel.moc"