~ubuntu-branches/ubuntu/intrepid/gwenview/intrepid

« back to all changes in this revision

Viewing changes to src/gvmainwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christopher Martin
  • Date: 2005-04-06 11:33:06 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050406113306-7zovl7z0io5bacpd
Tags: 1.2.0-1
* New upstream release.
  + Fixes crashes when using "Back" to navigate. (Closes: #301811)
* Enable KIPI support.
* Add a doc-base file for the handbook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
 
2
/*
 
3
Gwenview - A simple image viewer for KDE
 
4
Copyright 2000-2004 Aur�ien G�eau
 
5
 
 
6
This program is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU General Public License
 
8
as published by the Free Software Foundation; either version 2
 
9
of the License, or (at your option) any later version.
 
10
 
 
11
This program is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with this program; if not, write to the Free Software
 
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 
 
20
*/
 
21
// Qt
 
22
#include <qcursor.h>
 
23
#include <qdir.h>
 
24
#include <qdockarea.h>
 
25
#include <qhbox.h>
 
26
#include <qtooltip.h>
 
27
 
 
28
// KDE
 
29
#include <kaboutdata.h>
 
30
#include <kaccel.h>
 
31
#include <kaction.h>
 
32
#include <kapplication.h>
 
33
#include <kbookmarkmanager.h>
 
34
#include <kbookmarkmenu.h>
 
35
#include <kcmdlineargs.h>
 
36
#include <kcombobox.h>
 
37
#include <kconfig.h>
 
38
#include <kdebug.h>
 
39
#include <kdeversion.h>
 
40
#include <kdockwidget.h>
 
41
#include <kedittoolbar.h>
 
42
#include <kfiledialog.h>
 
43
#include <kglobal.h>
 
44
#include <khelpmenu.h>
 
45
#include <kiconloader.h>
 
46
#include <kimageio.h>
 
47
#include <kio/netaccess.h>
 
48
#include <kkeydialog.h>
 
49
#include <klargefile.h>
 
50
#include <klocale.h>
 
51
#include <kmenubar.h>
 
52
#include <kmessagebox.h>
 
53
#include <kpopupmenu.h>
 
54
#include <ksqueezedtextlabel.h>
 
55
#include <kstandarddirs.h>
 
56
#include <kstatusbar.h>
 
57
#include <kstdaccel.h>
 
58
#include <kstdaction.h>
 
59
#include <ktoolbarbutton.h>
 
60
#include <kurlcompletion.h>
 
61
#include <kurlpixmapprovider.h>
 
62
#include <kurlrequesterdlg.h>
 
63
#include <kprinter.h>
 
64
 
 
65
#include <config.h>
 
66
// KIPI
 
67
#ifdef HAVE_KIPI
 
68
#include <libkipi/plugin.h>
 
69
#include <libkipi/pluginloader.h>
 
70
#endif
 
71
 
 
72
// Local
 
73
#include "fileoperation.h"
 
74
#include "gvarchive.h"
 
75
#include "gvbatchmanipulator.h"
 
76
#include "gvbookmarkowner.h"
 
77
#include "gvconfigdialog.h"
 
78
#include "gvdirview.h"
 
79
#include "gvdocument.h"
 
80
#include "gvexternaltooldialog.h"
 
81
#include "gvfileviewbase.h"
 
82
#include "gvfileviewstack.h"
 
83
#include "gvhistory.h"
 
84
#include "gvscrollpixmapview.h"
 
85
#include "gvslideshow.h"
 
86
#include "gvslideshowdialog.h"
 
87
#include "gvmetaedit.h"
 
88
#include "gvprintdialog.h"
 
89
#include "gvcache.h"
 
90
#include "thumbnailloadjob.h"
 
91
 
 
92
#include "config.h"
 
93
 
 
94
#ifdef HAVE_KIPI
 
95
#include "gvkipiinterface.h"
 
96
#endif
 
97
 
 
98
#include <kcursor.h>
 
99
 
 
100
#include "gvmainwindow.moc"
 
101
 
 
102
const char CONFIG_DOCK_GROUP[]="dock";
 
103
const char CONFIG_MAINWINDOW_GROUP[]="main window";
 
104
const char CONFIG_FILEWIDGET_GROUP[]="file widget";
 
105
const char CONFIG_DIRWIDGET_GROUP[]="dir widget";
 
106
const char CONFIG_PIXMAPWIDGET_GROUP[]="pixmap widget";
 
107
const char CONFIG_FILEOPERATION_GROUP[]="file operations";
 
108
const char CONFIG_SLIDESHOW_GROUP[]="slide show";
 
109
const char CONFIG_CACHE_GROUP[]="cache";
 
110
const char CONFIG_THUMBNAILLOADJOB_GROUP[]="thumbnail loading";
 
111
 
 
112
const char CONFIG_BUSYPTR_IN_FS[]="busy ptr in full screen";
 
113
const char CONFIG_SHOW_LOCATION_TOOLBAR[]="show address bar";
 
114
const char CONFIG_AUTO_DELETE_THUMBNAIL_CACHE[]="Delete Thumbnail Cache whe exit";
 
115
const char CONFIG_GWENVIEW_DOCK_VERSION[]="Gwenview version";
 
116
 
 
117
const char CONFIG_SESSION_URL[] = "url";
 
118
 
 
119
// This version is here to avoid configuration migration troubles when changes
 
120
// are made to the dock behavior
 
121
const int GWENVIEW_DOCK_VERSION=2;
 
122
 
 
123
//#define ENABLE_LOG
 
124
#ifdef ENABLE_LOG
 
125
#define LOG(x) kdDebug() << k_funcinfo << x << endl
 
126
#else
 
127
#define LOG(x) ;
 
128
#endif
 
129
 
 
130
enum { StackIDBrowse, StackIDView };
 
131
 
 
132
 
 
133
// This function is used in the ctor to find out whether to start in viewing
 
134
// or browsing mode if URL is passed on the command line.
 
135
static bool urlIsDirectory(QWidget* parent, const KURL& url) {
 
136
        if( url.filename( false ).isEmpty()) return true; // file:/somewhere/<nothing here>
 
137
        // Do direct stat instead of using KIO if the file is local (faster)
 
138
        if( url.isLocalFile()
 
139
                && !KIO::probably_slow_mounted( url.path())) {
 
140
                KDE_struct_stat buff;
 
141
                if ( KDE_stat( QFile::encodeName(url.path()), &buff ) == 0 )  {
 
142
                        return S_ISDIR( buff.st_mode );
 
143
                }
 
144
        }
 
145
        KIO::UDSEntry entry;
 
146
#if KDE_IS_VERSION(3, 2, 0)
 
147
        if( KIO::NetAccess::stat( url, entry, parent)) {
 
148
#else
 
149
        if( KIO::NetAccess::stat( url, entry)) {
 
150
#endif
 
151
                KIO::UDSEntry::ConstIterator it;
 
152
                for(it=entry.begin();it!=entry.end();++it) {
 
153
                        if ((*it).m_uds==KIO::UDS_FILE_TYPE) {
 
154
                                return S_ISDIR( (*it).m_long );
 
155
                        }
 
156
                }
 
157
        }
 
158
        return false;
 
159
}
 
160
 
 
161
 
 
162
GVMainWindow::GVMainWindow()
 
163
: KMainWindow(), mLoadingCursor(false)
 
164
{
 
165
        FileOperation::readConfig(KGlobal::config(),CONFIG_FILEOPERATION_GROUP);
 
166
        readConfig(KGlobal::config(),CONFIG_MAINWINDOW_GROUP);
 
167
 
 
168
        // Backend
 
169
        mDocument=new GVDocument(this);
 
170
        mGVHistory=new GVHistory(actionCollection());
 
171
        // GUI
 
172
        createWidgets();
 
173
        createActions();
 
174
        createLocationToolBar();
 
175
 
 
176
        setStandardToolBarMenuEnabled(true);
 
177
        createGUI("gwenviewui.rc", false);
 
178
 
 
179
        createConnections();
 
180
        mWindowListActions.setAutoDelete(true);
 
181
        updateWindowActions();
 
182
        loadPlugins();
 
183
        applyMainWindowSettings();
 
184
 
 
185
        mFileViewStack->setFocus();
 
186
 
 
187
        if( !kapp->isSessionRestored()) {
 
188
                // Command line
 
189
                KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
190
 
 
191
                if (args->count()==0) {
 
192
                        KURL url;
 
193
                        url.setPath( QDir::currentDirPath() );
 
194
                        mFileViewStack->setDirURL(url);
 
195
                } else {
 
196
                        bool fullscreen=args->isSet("f");
 
197
                        if (fullscreen) mToggleFullScreen->activate();
 
198
                        KURL url=args->url(0);
 
199
 
 
200
                        if( urlIsDirectory(this, url)) {
 
201
                                mFileViewStack->setDirURL(url);
 
202
                        } else {
 
203
                                if (!fullscreen) mToggleBrowse->activate();
 
204
                                openURL(url);
 
205
                        }
 
206
                        updateLocationURL();
 
207
                }
 
208
        }
 
209
}
 
210
 
 
211
 
 
212
bool GVMainWindow::queryClose() {
 
213
        if (!mDocument->saveBeforeClosing()) return false;
 
214
 
 
215
        KConfig* config=KGlobal::config();
 
216
        FileOperation::writeConfig(config, CONFIG_FILEOPERATION_GROUP);
 
217
        mPixmapView->writeConfig(config, CONFIG_PIXMAPWIDGET_GROUP);
 
218
        mFileViewStack->writeConfig(config, CONFIG_FILEWIDGET_GROUP);
 
219
        mDirView->writeConfig(config, CONFIG_DIRWIDGET_GROUP);
 
220
        mSlideShow->writeConfig(config, CONFIG_SLIDESHOW_GROUP);
 
221
        ThumbnailLoadJob::writeConfig(config, CONFIG_THUMBNAILLOADJOB_GROUP);
 
222
 
 
223
        // Don't store dock layout if only the image dock is visible. This avoid
 
224
        // saving layout when in "fullscreen" or "image only" mode.
 
225
        if (mFileViewStack->isVisible() || mDirView->isVisible()) {
 
226
                mDockArea->writeDockConfig(config,CONFIG_DOCK_GROUP);
 
227
        }
 
228
        writeConfig(config,CONFIG_MAINWINDOW_GROUP);
 
229
 
 
230
        // If we are in fullscreen mode, we need to make the needed GUI elements
 
231
        // visible before saving the window settings.
 
232
        if (mToggleFullScreen->isChecked()) {
 
233
                statusBar()->show();
 
234
 
 
235
                if (toolBar()->area()) {
 
236
                        toolBar()->area()->show();
 
237
                } else {
 
238
                        toolBar()->show();
 
239
                }
 
240
                leftDock()->show();
 
241
                rightDock()->show();
 
242
                topDock()->show();
 
243
                bottomDock()->show();
 
244
 
 
245
                menuBar()->show();
 
246
        }
 
247
 
 
248
        if (mAutoDeleteThumbnailCache) {
 
249
                QString dir=ThumbnailLoadJob::thumbnailBaseDir();
 
250
 
 
251
                if (QFile::exists(dir)) {
 
252
                        KURL url;
 
253
                        url.setPath(dir);
 
254
#if KDE_IS_VERSION(3, 2, 0)
 
255
                        KIO::NetAccess::del(url, 0);
 
256
#else
 
257
                        KIO::NetAccess::del(url);
 
258
#endif
 
259
                }
 
260
        }
 
261
        
 
262
        saveMainWindowSettings(KGlobal::config(), "MainWindow");
 
263
 
 
264
        return true;
 
265
}
 
266
 
 
267
void GVMainWindow::saveProperties( KConfig* cfg ) {
 
268
        cfg->writeEntry( CONFIG_SESSION_URL, mFileViewStack->url().url());
 
269
}
 
270
 
 
271
void GVMainWindow::readProperties( KConfig* cfg ) {
 
272
        KURL url(cfg->readEntry(CONFIG_SESSION_URL));
 
273
        if( urlIsDirectory(this, url)) {
 
274
                mFileViewStack->setDirURL(url);
 
275
        } else {
 
276
                openURL(url);
 
277
        }
 
278
}
 
279
 
 
280
//-----------------------------------------------------------------------
 
281
//
 
282
// Public slots
 
283
//
 
284
//-----------------------------------------------------------------------
 
285
void GVMainWindow::openURL(const KURL& url) {
 
286
        mDocument->setURL(url);
 
287
        mFileViewStack->setDirURL(url.upURL());
 
288
        mFileViewStack->setFileNameToSelect(url.filename());
 
289
}
 
290
 
 
291
 
 
292
void GVMainWindow::slotDirURLChanged(const KURL& dirURL) {
 
293
        LOG(dirURL.prettyURL(0,KURL::StripFileProtocol));
 
294
        
 
295
        if (dirURL.path()!="/") {
 
296
                mGoUp->setEnabled(true);
 
297
                QPopupMenu *upPopup = mGoUp->popupMenu();
 
298
                upPopup->clear();
 
299
                int pos = 0;
 
300
                KURL url = dirURL.upURL();
 
301
                for (; url.hasPath() && pos<10; url=url.upURL(), ++pos) {
 
302
                        upPopup->insertItem(url.url());
 
303
                        if (url.path()=="/") break;
 
304
                }
 
305
        } else {
 
306
                mGoUp->setEnabled(false);
 
307
        }
 
308
 
 
309
        updateStatusInfo();
 
310
        updateImageActions();
 
311
        updateLocationURL();
 
312
}
 
313
 
 
314
void GVMainWindow::updateLocationURL() {
 
315
        LOG("");
 
316
        KURL url;
 
317
        if (mToggleBrowse->isChecked()) {
 
318
                url=mFileViewStack->dirURL();
 
319
                if (!url.isValid()) {
 
320
                        url=mDocument->url();
 
321
                }
 
322
        } else {
 
323
                url=mDocument->url();
 
324
        }
 
325
        LOG(url.prettyURL());
 
326
        mURLEdit->setEditText(url.prettyURL(0,KURL::StripFileProtocol));
 
327
        mURLEdit->addToHistory(url.prettyURL(0,KURL::StripFileProtocol));
 
328
}
 
329
 
 
330
void GVMainWindow::goUp() {
 
331
        goUpTo(mGoUp->popupMenu()->idAt(0));
 
332
}
 
333
 
 
334
void GVMainWindow::goUpTo(int id) {
 
335
        KPopupMenu* menu=mGoUp->popupMenu();
 
336
        KURL url(menu->text(id));
 
337
        KURL childURL;
 
338
        int index=menu->indexOf(id);
 
339
        if (index>0) {
 
340
                childURL=KURL(menu->text(menu->idAt(index-1)));
 
341
        } else {
 
342
                childURL=mDocument->dirURL();
 
343
        }
 
344
        mFileViewStack->setDirURL(url);
 
345
        mFileViewStack->setFileNameToSelect(childURL.fileName());
 
346
}
 
347
 
 
348
 
 
349
//-----------------------------------------------------------------------
 
350
//
 
351
// File operations
 
352
//
 
353
//-----------------------------------------------------------------------
 
354
void GVMainWindow::openHomeDir() {
 
355
        KURL url;
 
356
        url.setPath( QDir::homeDirPath() );
 
357
        mFileViewStack->setDirURL(url);
 
358
}
 
359
 
 
360
 
 
361
void GVMainWindow::renameFile() {
 
362
        if (mFileViewStack->isVisible()) {
 
363
                mFileViewStack->renameFile();
 
364
        } else {
 
365
                mPixmapView->renameFile();
 
366
        }
 
367
}
 
368
 
 
369
 
 
370
void GVMainWindow::copyFiles() {
 
371
        if (mFileViewStack->isVisible()) {
 
372
                mFileViewStack->copyFiles();
 
373
        } else {
 
374
                mPixmapView->copyFile();
 
375
        }
 
376
}
 
377
 
 
378
 
 
379
void GVMainWindow::moveFiles() {
 
380
        if (mFileViewStack->isVisible()) {
 
381
                mFileViewStack->moveFiles();
 
382
        } else {
 
383
                mPixmapView->moveFile();
 
384
        }
 
385
}
 
386
 
 
387
 
 
388
void GVMainWindow::deleteFiles() {
 
389
        if (mFileViewStack->isVisible()) {
 
390
                mFileViewStack->deleteFiles();
 
391
        } else {
 
392
                mPixmapView->deleteFile();
 
393
        }
 
394
}
 
395
 
 
396
 
 
397
void GVMainWindow::showFileProperties() {
 
398
        if (mFileViewStack->isVisible()) {
 
399
                mFileViewStack->showFileProperties();
 
400
        } else {
 
401
                mPixmapView->showFileProperties();
 
402
        }
 
403
}
 
404
 
 
405
 
 
406
void GVMainWindow::rotateLeft() {
 
407
        modifyImage(GVImageUtils::ROT_270);
 
408
}
 
409
 
 
410
void GVMainWindow::rotateRight() {
 
411
        modifyImage(GVImageUtils::ROT_90);
 
412
}
 
413
 
 
414
void GVMainWindow::mirror() {
 
415
        modifyImage(GVImageUtils::HFLIP);
 
416
}
 
417
 
 
418
void GVMainWindow::flip() {
 
419
        modifyImage(GVImageUtils::VFLIP);
 
420
}
 
421
 
 
422
void GVMainWindow::modifyImage(GVImageUtils::Orientation orientation) {
 
423
        const KURL::List& urls=mFileViewStack->selectedURLs();
 
424
        if (mFileViewStack->isVisible() && urls.size()>1) {
 
425
                GVBatchManipulator manipulator(this, urls, orientation);
 
426
                connect(&manipulator, SIGNAL(imageModified(const KURL&)),
 
427
                        mFileViewStack, SLOT(updateThumbnail(const KURL&)) );
 
428
                manipulator.apply();
 
429
                if (urls.find(mDocument->url())!=urls.end()) {
 
430
                        mDocument->reload();
 
431
                }
 
432
        } else {
 
433
                mDocument->transform(orientation);
 
434
        }
 
435
}
 
436
 
 
437
void GVMainWindow::showFileDialog() {
 
438
        KURL url=KFileDialog::getOpenURL();
 
439
        if (!url.isValid()) return;
 
440
 
 
441
        openURL(url);
 
442
}
 
443
 
 
444
 
 
445
void GVMainWindow::printFile() {
 
446
        KPrinter printer;
 
447
 
 
448
        printer.setDocName(mDocument->filename());
 
449
        const KAboutData* pAbout = KApplication::kApplication()->aboutData();
 
450
        QString nm = pAbout->appName();
 
451
        nm += "-";
 
452
        nm += pAbout->version();
 
453
        printer.setCreator( nm );
 
454
 
 
455
        KPrinter::addDialogPage( new GVPrintDialogPage( mDocument, this, "GV page"));
 
456
 
 
457
        if (printer.setup(this, QString::null, true)) {
 
458
                mDocument->print(&printer);
 
459
        }
 
460
}
 
461
 
 
462
 
 
463
//-----------------------------------------------------------------------
 
464
//
 
465
// Private slots
 
466
//
 
467
//-----------------------------------------------------------------------
 
468
void GVMainWindow::slotImageLoading() {
 
469
        if (mShowBusyPtrInFullScreen || !mToggleFullScreen->isChecked()) {
 
470
                if( !mLoadingCursor ) {
 
471
                        kapp->setOverrideCursor(KCursor::workingCursor());
 
472
                }
 
473
                mLoadingCursor = true;
 
474
        }
 
475
}
 
476
 
 
477
 
 
478
void GVMainWindow::slotImageLoaded() {
 
479
        if( mLoadingCursor )
 
480
                kapp->restoreOverrideCursor();
 
481
        mLoadingCursor = false;
 
482
        updateStatusInfo();
 
483
        updateImageActions();
 
484
        updateLocationURL();
 
485
}
 
486
 
 
487
 
 
488
void GVMainWindow::hideToolBars() {
 
489
        QPtrListIterator<KToolBar> it=toolBarIterator();
 
490
        KToolBar* bar;
 
491
 
 
492
        for(;it.current()!=0L; ++it) {
 
493
                bar=it.current();
 
494
                if (bar->area()) {
 
495
                        bar->area()->hide();
 
496
                } else {
 
497
                        bar->hide();
 
498
                }
 
499
        }
 
500
}
 
501
 
 
502
 
 
503
void GVMainWindow::showToolBars() {
 
504
        QPtrListIterator<KToolBar> it=toolBarIterator();
 
505
 
 
506
        KToolBar* bar;
 
507
 
 
508
        for(;it.current()!=0L; ++it) {
 
509
                bar=it.current();
 
510
                if (bar->area()) {
 
511
                        bar->area()->show();
 
512
                } else {
 
513
                        bar->show();
 
514
                }
 
515
        }
 
516
}
 
517
 
 
518
 
 
519
void GVMainWindow::toggleFullScreen() {
 
520
        if (mToggleFullScreen->isChecked()) {
 
521
                showFullScreen();
 
522
                menuBar()->hide();
 
523
                statusBar()->hide();
 
524
                
 
525
                /* Hide toolbar
 
526
                 * If the toolbar is docked we hide the DockArea to avoid
 
527
                 * having a one pixel band remaining
 
528
                 * For the same reason, we hide all the empty DockAreas
 
529
                 *
 
530
                 * NOTE: This does not work really well if the toolbar is in
 
531
                 * the left or right dock area.
 
532
                 */
 
533
                hideToolBars();
 
534
                if (leftDock()->isEmpty())       leftDock()->hide();
 
535
                if (rightDock()->isEmpty())  rightDock()->hide();
 
536
                if (topDock()->isEmpty())        topDock()->hide();
 
537
                if (bottomDock()->isEmpty()) bottomDock()->hide();
 
538
                
 
539
                if (mToggleBrowse->isChecked()) {
 
540
                        mPixmapView->reparent(mViewModeWidget, QPoint(0,0));
 
541
                        mCentralStack->raiseWidget(StackIDView);
 
542
                }
 
543
                KActionPtrList actions;
 
544
                actions.append(mFileViewStack->selectPrevious());
 
545
                actions.append(mFileViewStack->selectNext());
 
546
                actions.append(mToggleFullScreen);
 
547
                mPixmapView->setFullScreenActions(actions);
 
548
                mPixmapView->setFullScreen(true);
 
549
                mPixmapView->setFocus();
 
550
        } else {
 
551
                // Stop the slideshow if it's running, harmless if it does not
 
552
                mSlideShow->stop();
 
553
 
 
554
                // Make sure the file view points to the right URL, it might not be the
 
555
                // case if we are getting out of a slideshow
 
556
                mFileViewStack->setDirURL(mDocument->url().upURL());
 
557
                mFileViewStack->setFileNameToSelect(mDocument->url().fileName());
 
558
 
 
559
                showNormal();
 
560
                menuBar()->show();
 
561
                
 
562
                showToolBars();
 
563
                leftDock()->show();
 
564
                rightDock()->show();
 
565
                topDock()->show();
 
566
                bottomDock()->show();
 
567
                
 
568
                statusBar()->show();
 
569
                mPixmapView->setFullScreen(false);
 
570
                
 
571
                if (mToggleBrowse->isChecked()) {
 
572
                        mPixmapDock->setWidget(mPixmapView);
 
573
                        mCentralStack->raiseWidget(StackIDBrowse);
 
574
                }
 
575
                mFileViewStack->setFocus();
 
576
        }
 
577
}
 
578
 
 
579
 
 
580
void GVMainWindow::startSlideShow() {
 
581
        KURL::List list;
 
582
        KFileItemListIterator it( *mFileViewStack->currentFileView()->items() );
 
583
        for ( ; it.current(); ++it ) {
 
584
                KFileItem* item=it.current();
 
585
                if (!item->isDir() && !GVArchive::fileItemIsArchive(item)) {
 
586
                        list.append(item->url());
 
587
                }
 
588
        }
 
589
        if (list.count()==0) {
 
590
                return;
 
591
        }
 
592
 
 
593
        GVSlideShowDialog dialog(this,mSlideShow);
 
594
        if (!dialog.exec()) return;
 
595
        
 
596
        if (!mToggleFullScreen->isChecked()) {
 
597
                mToggleFullScreen->activate();
 
598
        }
 
599
        mSlideShow->start(list);
 
600
}
 
601
 
 
602
 
 
603
void GVMainWindow::showConfigDialog() {
 
604
        GVConfigDialog dialog(this);
 
605
        dialog.exec();
 
606
}
 
607
 
 
608
 
 
609
void GVMainWindow::showExternalToolDialog() {
 
610
        GVExternalToolDialog* dialog=new GVExternalToolDialog(this);
 
611
        dialog->show();
 
612
}
 
613
 
 
614
 
 
615
void GVMainWindow::showKeyDialog() {
 
616
        KKeyDialog dialog(true, this);
 
617
        dialog.insert(actionCollection());
 
618
#ifdef HAVE_KIPI
 
619
        KIPI::PluginLoader::PluginList pluginList=mPluginLoader->pluginList();
 
620
        KIPI::PluginLoader::PluginList::ConstIterator it(pluginList.begin());
 
621
        KIPI::PluginLoader::PluginList::ConstIterator itEnd(pluginList.end());
 
622
        for( ; it!=itEnd; ++it ) {
 
623
                KIPI::Plugin* plugin=(*it)->plugin();
 
624
                if (plugin) {
 
625
                        dialog.insert(plugin->actionCollection(), (*it)->name());
 
626
                }
 
627
        }
 
628
#endif
 
629
        dialog.configure(true);
 
630
}
 
631
 
 
632
 
 
633
void GVMainWindow::showToolBarDialog() {
 
634
        saveMainWindowSettings(KGlobal::config(), "MainWindow");
 
635
        KEditToolbar dlg(actionCollection());
 
636
        connect(&dlg,SIGNAL(newToolbarConfig()),this,SLOT(applyMainWindowSettings()));
 
637
        if (dlg.exec()) {
 
638
                createGUI();
 
639
        }
 
640
}
 
641
 
 
642
void GVMainWindow::applyMainWindowSettings() {
 
643
        KMainWindow::applyMainWindowSettings(KGlobal::config(), "MainWindow");
 
644
}
 
645
 
 
646
 
 
647
 
 
648
void GVMainWindow::escapePressed() {
 
649
        if (mToggleFullScreen->isChecked()) {
 
650
                mToggleFullScreen->activate();
 
651
        }
 
652
}
 
653
 
 
654
 
 
655
void GVMainWindow::slotDirRenamed(const KURL& oldURL, const KURL& newURL) {
 
656
        LOG(oldURL.prettyURL(0,KURL::StripFileProtocol) << " to " << newURL.prettyURL(0,KURL::StripFileProtocol));
 
657
 
 
658
        KURL url(mFileViewStack->dirURL());
 
659
        if (!oldURL.isParentOf(url) ) {
 
660
                LOG(oldURL.prettyURL() << " is not a parent of " << url.prettyURL());
 
661
                return;
 
662
        }
 
663
 
 
664
        QString oldPath=oldURL.path();
 
665
        LOG("current path: " << url.path() );
 
666
        QString path=newURL.path() + url.path().mid(oldPath.length());
 
667
        LOG("new path: " << path);
 
668
        url.setPath(path);
 
669
        mFileViewStack->setDirURL(url);
 
670
}
 
671
 
 
672
 
 
673
void GVMainWindow::slotGo() {
 
674
        KURL url(mURLEditCompletion->replacedPath(mURLEdit->currentText()));
 
675
        LOG(url.prettyURL());
 
676
        if( urlIsDirectory(this, url)) {
 
677
                LOG(" '-> is a directory");
 
678
                mFileViewStack->setDirURL(url);
 
679
        } else {
 
680
                LOG(" '-> is not a directory");
 
681
                openURL(url);
 
682
        }
 
683
        mFileViewStack->setFocus();
 
684
}
 
685
 
 
686
void GVMainWindow::slotShownFileItemRefreshed(const KFileItem* item) {
 
687
        LOG("");
 
688
        if (int(item->size())!=mDocument->fileSize()) {
 
689
                LOG("need reload " << int(item->size()) << "!=" << mDocument->fileSize());
 
690
                mDocument->reload();
 
691
        }
 
692
}
 
693
        
 
694
 
 
695
void GVMainWindow::slotToggleCentralStack() {
 
696
        LOG("");
 
697
        if (mToggleBrowse->isChecked()) {
 
698
                mPixmapDock->setWidget(mPixmapView);
 
699
                mCentralStack->raiseWidget(StackIDBrowse);
 
700
                mFileViewStack->setSilentMode( false );
 
701
                // force re-reading the directory to show the error
 
702
                if( mFileViewStack->lastURLError()) mFileViewStack->retryURL();
 
703
        } else {
 
704
                mPixmapView->reparent(mViewModeWidget, QPoint(0,0));
 
705
                mCentralStack->raiseWidget(StackIDView);
 
706
                mFileViewStack->setSilentMode( true );
 
707
        }
 
708
 
 
709
        // Make sure the window list actions are disabled if we are in view mode,
 
710
        // otherwise weird things happens when we go back to browse mode
 
711
        QPtrListIterator<KAction> it(mWindowListActions);
 
712
        for (;it.current(); ++it) {
 
713
                it.current()->setEnabled(mToggleBrowse->isChecked());
 
714
        }
 
715
        updateLocationURL();
 
716
}
 
717
 
 
718
 
 
719
void GVMainWindow::resetDockWidgets() {
 
720
        mFolderDock->undock();
 
721
        mPixmapDock->undock();
 
722
        mMetaDock->undock();
 
723
 
 
724
        mFolderDock->manualDock(mFileDock, KDockWidget::DockLeft, 4000);
 
725
        mPixmapDock->manualDock(mFolderDock, KDockWidget::DockBottom, 3734);
 
726
        mMetaDock->manualDock(mPixmapDock, KDockWidget::DockBottom, 8560);
 
727
}
 
728
 
 
729
 
 
730
//-----------------------------------------------------------------------
 
731
//
 
732
// GUI
 
733
//
 
734
//-----------------------------------------------------------------------
 
735
void GVMainWindow::updateStatusInfo() {
 
736
        QString txt;
 
737
        uint count=mFileViewStack->fileCount();
 
738
        QString url=mDocument->dirURL().prettyURL(0,KURL::StripFileProtocol);
 
739
        if (count==0) {
 
740
                txt=i18n("%1 - No Images").arg(url);
 
741
        } else {
 
742
                txt=i18n("%1 - One Image","%1 - %n images",count).arg(url);
 
743
        }
 
744
        mSBDirLabel->setText(txt);
 
745
 
 
746
        updateFileInfo();
 
747
}
 
748
 
 
749
 
 
750
void GVMainWindow::updateFileInfo() {
 
751
        QString filename=mDocument->filename();
 
752
        if (!filename.isEmpty()) {
 
753
                QString info=QString("%1 %2x%3 @ %4%")
 
754
                        .arg(filename).arg(mDocument->width()).arg(mDocument->height())
 
755
                        .arg(int(mPixmapView->zoom()*100) );
 
756
                mSBDetailLabel->show();
 
757
                mSBDetailLabel->setText(info);
 
758
        } else {
 
759
                mSBDetailLabel->hide();
 
760
        }
 
761
        setCaption(filename);
 
762
}
 
763
 
 
764
 
 
765
void GVMainWindow::updateImageActions() {
 
766
        bool filenameIsValid=!mDocument->isNull();
 
767
 
 
768
        mStartSlideShow->setEnabled(filenameIsValid);
 
769
        mRenameFile->setEnabled(filenameIsValid);
 
770
        mCopyFiles->setEnabled(filenameIsValid);
 
771
        mMoveFiles->setEnabled(filenameIsValid);
 
772
        mDeleteFiles->setEnabled(filenameIsValid);
 
773
        mShowFileProperties->setEnabled(filenameIsValid);
 
774
        mRotateLeft->setEnabled(filenameIsValid);
 
775
        mRotateRight->setEnabled(filenameIsValid);
 
776
        mMirror->setEnabled(filenameIsValid);
 
777
        mFlip->setEnabled(filenameIsValid);
 
778
        mSaveFile->setEnabled(filenameIsValid);
 
779
        mSaveFileAs->setEnabled(filenameIsValid);
 
780
        mFilePrint->setEnabled(filenameIsValid);
 
781
        mReload->setEnabled(filenameIsValid);
 
782
 
 
783
}
 
784
 
 
785
 
 
786
void GVMainWindow::createWidgets() {
 
787
        KConfig* config=KGlobal::config();
 
788
 
 
789
        mCentralStack=new QWidgetStack(this);
 
790
        setCentralWidget(mCentralStack);
 
791
 
 
792
        mDockArea=new KDockArea(mCentralStack);
 
793
        mCentralStack->addWidget(mDockArea, StackIDBrowse);
 
794
        mDockArea->manager()->setSplitterHighResolution(true);
 
795
        mDockArea->manager()->setSplitterOpaqueResize(true);
 
796
        
 
797
        mViewModeWidget=new QWidget(mCentralStack);
 
798
        QVBoxLayout* layout=new QVBoxLayout(mViewModeWidget);
 
799
        layout->setAutoAdd(true);
 
800
        mCentralStack->addWidget(mViewModeWidget);
 
801
 
 
802
        // Status bar
 
803
        mSBDirLabel=new KSqueezedTextLabel("", statusBar());
 
804
        statusBar()->addWidget(mSBDirLabel,1);
 
805
        mSBDetailLabel=new QLabel("", statusBar());
 
806
        statusBar()->addWidget(mSBDetailLabel);
 
807
 
 
808
        // Pixmap widget
 
809
        mPixmapDock = mDockArea->createDockWidget("Image",SmallIcon("gwenview"),NULL,i18n("Image"));
 
810
        mPixmapView=new GVScrollPixmapView(mPixmapDock,mDocument,actionCollection());
 
811
        mPixmapDock->setWidget(mPixmapView);
 
812
 
 
813
        // Folder widget
 
814
        mFolderDock = mDockArea->createDockWidget("Folders",SmallIcon("folder_open"),NULL,i18n("Folders"));
 
815
        mDirView=new GVDirView(mFolderDock);
 
816
        mFolderDock->setWidget(mDirView);
 
817
 
 
818
        // File widget
 
819
        mFileDock = mDockArea->createDockWidget("Files",SmallIcon("image"),NULL,i18n("Files"));
 
820
        QVBox* vbox=new QVBox(this);
 
821
        (void)new KToolBar(vbox, "fileViewToolBar", true);
 
822
        mFileViewStack=new GVFileViewStack(vbox, actionCollection());
 
823
        mFileDock->setWidget(vbox);
 
824
        mFileDock->setEnableDocking(KDockWidget::DockNone);
 
825
        mDockArea->setMainDockWidget(mFileDock);
 
826
 
 
827
        // Meta info edit widget
 
828
        mMetaDock = mDockArea->createDockWidget("File Attributes", SmallIcon("doc"),NULL,
 
829
                i18n("File Info"));
 
830
        mMetaEdit = new GVMetaEdit(mMetaDock, mDocument);
 
831
        mMetaDock->setWidget(mMetaEdit);
 
832
 
 
833
        // Slide show controller (not really a widget)
 
834
        mSlideShow=new GVSlideShow(mDocument);
 
835
 
 
836
        // Default position on desktop
 
837
        setGeometry(20,20,720,520);
 
838
 
 
839
        // Default dock config
 
840
        // (The "magic numbers" were found by adjusting the layout from within the
 
841
        // app and looking at the result in the configuration file)
 
842
        mFolderDock->manualDock(mFileDock, KDockWidget::DockLeft, 4000);
 
843
        mPixmapDock->manualDock(mFolderDock, KDockWidget::DockBottom, 3734);
 
844
        mMetaDock->manualDock(mPixmapDock, KDockWidget::DockBottom, 8560);
 
845
 
 
846
        // Load dock config if up to date
 
847
        if (config->hasGroup(CONFIG_DOCK_GROUP)) {
 
848
                config->setGroup(CONFIG_DOCK_GROUP);
 
849
                if (config->readNumEntry(CONFIG_GWENVIEW_DOCK_VERSION, 1)==GWENVIEW_DOCK_VERSION) {
 
850
                        mDockArea->readDockConfig(config,CONFIG_DOCK_GROUP);
 
851
                } else {
 
852
                        KMessageBox::sorry(this, i18n(
 
853
                                "<qt><b>Configuration update</b><br>"
 
854
                                "Due to some changes in the dock behavior, your old dock configuration has been discarded. "
 
855
                                "Please adjust your docks again.</qt>")
 
856
                                );
 
857
                        // Store the default dock config and create the
 
858
                        // GWENVIEW_DOCK_VERSION entry
 
859
                        mDockArea->writeDockConfig(config,CONFIG_DOCK_GROUP);
 
860
                        config->writeEntry(CONFIG_GWENVIEW_DOCK_VERSION, GWENVIEW_DOCK_VERSION);
 
861
                        config->sync();
 
862
                }
 
863
        } else {
 
864
                // There was no dock config, lets create the GWENVIEW_DOCK_VERSION entry
 
865
                config->setGroup(CONFIG_DOCK_GROUP);
 
866
                config->writeEntry(CONFIG_GWENVIEW_DOCK_VERSION, GWENVIEW_DOCK_VERSION);
 
867
                config->sync();
 
868
        }
 
869
        
 
870
        // Load config
 
871
        mFileViewStack->readConfig(config,CONFIG_FILEWIDGET_GROUP);
 
872
        mDirView->readConfig(config,CONFIG_DIRWIDGET_GROUP);
 
873
        mPixmapView->readConfig(config,CONFIG_PIXMAPWIDGET_GROUP);
 
874
        mSlideShow->readConfig(config,CONFIG_SLIDESHOW_GROUP);
 
875
        ThumbnailLoadJob::readConfig(config,CONFIG_THUMBNAILLOADJOB_GROUP);
 
876
        GVCache::instance()->readConfig(config,CONFIG_CACHE_GROUP);
 
877
}
 
878
 
 
879
 
 
880
void GVMainWindow::createActions() {
 
881
        // Stack
 
882
        mToggleBrowse=new KToggleAction(i18n("Browse"), "folder", CTRL + Key_Return, this, SLOT(slotToggleCentralStack()), actionCollection(), "toggle_browse");
 
883
        mToggleBrowse->setChecked(true);
 
884
        mToggleBrowse->setShortcut(CTRL + Key_Return);
 
885
        
 
886
        // File
 
887
        KStdAction::open(this,SLOT(showFileDialog()),actionCollection() );
 
888
        mSaveFile=KStdAction::save(mDocument,SLOT(save()),actionCollection() );
 
889
        mSaveFileAs=KStdAction::saveAs(mDocument,SLOT(saveAs()),actionCollection() );
 
890
        mFilePrint = KStdAction::print(this, SLOT(printFile()), actionCollection());
 
891
        mRenameFile=new KAction(i18n("&Rename..."),Key_F2,this,SLOT(renameFile()),actionCollection(),"file_rename");
 
892
        mCopyFiles=new KAction(i18n("&Copy To..."),Key_F7,this,SLOT(copyFiles()),actionCollection(),"file_copy");
 
893
        mMoveFiles=new KAction(i18n("&Move To..."),Key_F8,this,SLOT(moveFiles()),actionCollection(),"file_move");
 
894
        mDeleteFiles=new KAction(i18n("&Delete"),"editdelete",Key_Delete,this,SLOT(deleteFiles()),actionCollection(),"file_delete");
 
895
        mShowFileProperties=new KAction(i18n("Properties"),0,this,SLOT(showFileProperties()),actionCollection(),"file_properties");
 
896
        KStdAction::quit( kapp, SLOT (closeAllWindows()), actionCollection() );
 
897
 
 
898
        // Edit
 
899
        mRotateLeft=new KAction(i18n("Rotate &Left"),"rotate_left",CTRL + Key_L, this, SLOT(rotateLeft()),actionCollection(),"rotate_left");
 
900
        mRotateRight=new KAction(i18n("Rotate &Right"),"rotate_right",CTRL + Key_R, this, SLOT(rotateRight()),actionCollection(),"rotate_right");
 
901
        mMirror=new KAction(i18n("&Mirror"),"mirror",0, this, SLOT(mirror()),actionCollection(),"mirror");
 
902
        mFlip=new KAction(i18n("&Flip"),"flip",0, this, SLOT(flip()),actionCollection(),"flip");
 
903
 
 
904
        // View
 
905
        mReload=new KAction(i18n("Reload"), "reload", Key_F5, mDocument, SLOT(reload()), actionCollection(), "reload");
 
906
        mReload->setEnabled(false);
 
907
 
 
908
#if KDE_IS_VERSION(3, 1, 90)
 
909
        mToggleFullScreen= KStdAction::fullScreen(this,SLOT(toggleFullScreen()),actionCollection(),0);
 
910
#else
 
911
        mToggleFullScreen=new KToggleAction(i18n("Full Screen"),"window_fullscreen",CTRL + Key_F,this,SLOT(toggleFullScreen()),actionCollection(),"fullscreen");
 
912
#endif
 
913
        mStartSlideShow=new KAction(i18n("Slide Show..."),"slideshow",0,this,SLOT(startSlideShow()),actionCollection(),"slideshow");
 
914
 
 
915
        // Go
 
916
        mGoUp=new KToolBarPopupAction(i18n("Up"), "up", ALT + Key_Up, this, SLOT(goUp()), actionCollection(), "go_up");
 
917
        mOpenHomeDir=KStdAction::home(this, SLOT(openHomeDir()), actionCollection() );
 
918
 
 
919
        // Bookmarks
 
920
        QString file = locate( "data", "kfile/bookmarks.xml" );
 
921
        if (file.isEmpty()) {
 
922
                file = locateLocal( "data", "kfile/bookmarks.xml" );
 
923
        }
 
924
 
 
925
        KBookmarkManager* manager=KBookmarkManager::managerForFile(file,false);
 
926
        manager->setUpdate(true);
 
927
        manager->setShowNSBookmarks(false);
 
928
 
 
929
        GVBookmarkOwner* bookmarkOwner=new GVBookmarkOwner(this);
 
930
 
 
931
        KActionMenu* bookmark=new KActionMenu(i18n( "&Bookmarks" ), "bookmark", actionCollection(), "bookmarks" );
 
932
        new KBookmarkMenu(manager, bookmarkOwner, bookmark->popupMenu(), 0, true);
 
933
 
 
934
        connect(bookmarkOwner,SIGNAL(openURL(const KURL&)),
 
935
                mFileViewStack,SLOT(setDirURL(const KURL&)) );
 
936
 
 
937
        connect(mFileViewStack,SIGNAL(directoryChanged(const KURL&)),
 
938
                bookmarkOwner,SLOT(setURL(const KURL&)) );
 
939
 
 
940
        // Window
 
941
        mResetDockWidgets = new KAction(i18n("Reset"), 0, this, SLOT(resetDockWidgets()), actionCollection(), "reset_dock_widgets");
 
942
 
 
943
        // Settings
 
944
        mShowConfigDialog=
 
945
                KStdAction::preferences(this, SLOT(showConfigDialog()), actionCollection() );
 
946
        mShowKeyDialog=
 
947
                KStdAction::keyBindings(this, SLOT(showKeyDialog()), actionCollection() );
 
948
        (void)new KAction(i18n("Configure External Tools..."), "configure", 0,
 
949
                this, SLOT(showExternalToolDialog()), actionCollection(), "configure_tools");
 
950
        (void)KStdAction::configureToolbars(
 
951
                this, SLOT(showToolBarDialog()), actionCollection() );
 
952
 
 
953
        actionCollection()->readShortcutSettings();
 
954
}
 
955
 
 
956
 
 
957
void GVMainWindow::createHideShowAction(KDockWidget* dock) {
 
958
        QString caption;
 
959
        if (dock->mayBeHide()) {
 
960
                caption=i18n("Hide %1").arg(dock->caption());
 
961
        } else {
 
962
                caption=i18n("Show %1").arg(dock->caption());
 
963
        }
 
964
 
 
965
        KAction* action=new KAction(caption, 0, dock, SLOT(changeHideShowState()), (QObject*)0 );
 
966
        if (dock->icon()) {
 
967
                action->setIconSet( QIconSet(*dock->icon()) );
 
968
        }
 
969
        mWindowListActions.append(action);
 
970
}
 
971
 
 
972
 
 
973
void GVMainWindow::updateWindowActions() {
 
974
        unplugActionList("winlist");
 
975
        mWindowListActions.clear();
 
976
        createHideShowAction(mFolderDock);
 
977
        createHideShowAction(mPixmapDock);
 
978
        createHideShowAction(mMetaDock);
 
979
        plugActionList("winlist", mWindowListActions);
 
980
}
 
981
 
 
982
 
 
983
void GVMainWindow::createConnections() {
 
984
        connect(mGoUp->popupMenu(), SIGNAL(activated(int)),
 
985
                this,SLOT(goUpTo(int)));
 
986
 
 
987
        // Dir view connections
 
988
        connect(mDirView,SIGNAL(dirURLChanged(const KURL&)),
 
989
                mFileViewStack,SLOT(setDirURL(const KURL&)) );
 
990
 
 
991
        connect(mDirView, SIGNAL(dirRenamed(const KURL&, const KURL&)),
 
992
                this, SLOT(slotDirRenamed(const KURL&, const KURL&)) );
 
993
 
 
994
        // Pixmap view connections
 
995
        connect(mPixmapView,SIGNAL(selectPrevious()),
 
996
                mFileViewStack,SLOT(slotSelectPrevious()) );
 
997
        connect(mPixmapView,SIGNAL(selectNext()),
 
998
                mFileViewStack,SLOT(slotSelectNext()) );
 
999
        connect(mPixmapView,SIGNAL(zoomChanged(double)),
 
1000
                this,SLOT(updateFileInfo()) );
 
1001
 
 
1002
        // File view connections
 
1003
        connect(mFileViewStack,SIGNAL(urlChanged(const KURL&)),
 
1004
                mDocument,SLOT(setURL(const KURL&)) );
 
1005
        connect(mFileViewStack,SIGNAL(directoryChanged(const KURL&)),
 
1006
                this,SLOT(slotDirURLChanged(const KURL&)) );
 
1007
        connect(mFileViewStack,SIGNAL(directoryChanged(const KURL&)),
 
1008
                mDirView,SLOT(setURL(const KURL&)) );
 
1009
        connect(mFileViewStack,SIGNAL(directoryChanged(const KURL&)),
 
1010
                mGVHistory,SLOT(addURLToHistory(const KURL&)) );
 
1011
 
 
1012
        connect(mFileViewStack,SIGNAL(completed()),
 
1013
                this,SLOT(updateStatusInfo()) );
 
1014
        connect(mFileViewStack,SIGNAL(canceled()),
 
1015
                this,SLOT(updateStatusInfo()) );
 
1016
        connect(mFileViewStack,SIGNAL(imageDoubleClicked()),
 
1017
                mToggleBrowse,SLOT(activate()) );
 
1018
        connect(mFileViewStack,SIGNAL(shownFileItemRefreshed(const KFileItem*)),
 
1019
                this,SLOT(slotShownFileItemRefreshed(const KFileItem*)) );
 
1020
 
 
1021
        // GVHistory connections
 
1022
        connect(mGVHistory, SIGNAL(urlChanged(const KURL&)),
 
1023
                mFileViewStack, SLOT(setDirURL(const KURL&)) );
 
1024
        
 
1025
        // GVDocument connections
 
1026
        connect(mDocument,SIGNAL(loading()),
 
1027
                this,SLOT(slotImageLoading()) );
 
1028
        connect(mDocument,SIGNAL(loaded(const KURL&)),
 
1029
                this,SLOT(slotImageLoaded()) );
 
1030
        connect(mDocument,SIGNAL(saved(const KURL&)),
 
1031
                mFileViewStack,SLOT(updateThumbnail(const KURL&)) );
 
1032
        connect(mDocument,SIGNAL(reloaded(const KURL&)),
 
1033
                mFileViewStack,SLOT(updateThumbnail(const KURL&)) );
 
1034
 
 
1035
        // Slide show
 
1036
        connect(mSlideShow,SIGNAL(finished()),
 
1037
                mToggleFullScreen,SLOT(activate()) );
 
1038
 
 
1039
        // Location bar
 
1040
        connect(mURLEdit, SIGNAL(activated(const QString &)),
 
1041
                this,SLOT(slotGo()) );
 
1042
        connect(mURLEdit, SIGNAL(returnPressed()),
 
1043
                this,SLOT(slotGo()) );
 
1044
 
 
1045
        // Non configurable stop-fullscreen accel
 
1046
        QAccel* accel=new QAccel(this);
 
1047
        accel->connectItem(accel->insertItem(Key_Escape),this,SLOT(escapePressed()));
 
1048
 
 
1049
        // Dock related
 
1050
        connect(mDockArea->manager(), SIGNAL(change()),
 
1051
                this, SLOT(updateWindowActions()) );
 
1052
}
 
1053
 
 
1054
 
 
1055
void GVMainWindow::createLocationToolBar() {
 
1056
        // URL Combo
 
1057
        mURLEdit=new KHistoryCombo(this);
 
1058
        mURLEdit->setDuplicatesEnabled(false);
 
1059
        mURLEdit->setPixmapProvider(new KURLPixmapProvider);
 
1060
 
 
1061
        mURLEditCompletion=new KURLCompletion();
 
1062
        //mURLEditCompletion->setDir("/");
 
1063
 
 
1064
        mURLEdit->setCompletionObject(mURLEditCompletion);
 
1065
        mURLEdit->setAutoDeleteCompletionObject(true);
 
1066
 
 
1067
        KWidgetAction* comboAction=new KWidgetAction( mURLEdit, i18n("Location Bar"), 0,
 
1068
                0, 0, actionCollection(), "location_url");
 
1069
        comboAction->setShortcutConfigurable(false);
 
1070
        comboAction->setAutoSized(true);
 
1071
 
 
1072
        // Clear button
 
1073
        (void)new KAction( i18n("Clear Location Bar"),
 
1074
                QApplication::reverseLayout()?"clear_left" : "locationbar_erase",
 
1075
                0, this, SLOT(clearLocationLabel()), actionCollection(), "clear_location");
 
1076
 
 
1077
        // URL Label
 
1078
        /* we use "kde toolbar widget" to avoid the flat background (looks bad with
 
1079
         * styles like Keramik). See konq_misc.cc.
 
1080
         */
 
1081
        QLabel* urlLabel=new QLabel(i18n("L&ocation:"), this, "kde toolbar widget");
 
1082
        (void)new KWidgetAction( urlLabel, i18n("L&ocation: "), Key_F6, this, SLOT( activateLocationLabel()),
 
1083
                actionCollection(), "location_label");
 
1084
        urlLabel->setBuddy(mURLEdit);
 
1085
 
 
1086
        // Go button
 
1087
        (void)new KAction(i18n("Go"), "key_enter", 0, this, SLOT(slotGo()), actionCollection(), "location_go");
 
1088
 
 
1089
}
 
1090
 
 
1091
 
 
1092
void GVMainWindow::clearLocationLabel() {
 
1093
        mURLEdit->clearEdit();
 
1094
        mURLEdit->setFocus();
 
1095
}
 
1096
 
 
1097
 
 
1098
void GVMainWindow::activateLocationLabel() {
 
1099
        mURLEdit->setFocus();
 
1100
        mURLEdit->lineEdit()->selectAll();
 
1101
}
 
1102
 
 
1103
 
 
1104
#ifdef HAVE_KIPI
 
1105
void GVMainWindow::loadPlugins() {
 
1106
        // Sets up the plugin interface, and load the plugins
 
1107
        GVKIPIInterface* interface = new GVKIPIInterface(this, mFileViewStack);
 
1108
        mPluginLoader = new KIPI::PluginLoader(QStringList(), interface );
 
1109
        connect( mPluginLoader, SIGNAL( replug() ), this, SLOT( slotReplug() ) );
 
1110
        mPluginLoader->loadPlugins();
 
1111
}
 
1112
 
 
1113
 
 
1114
// Helper class for slotReplug(), gcc does not want to instantiate templates
 
1115
// with local classes, so this is declared outside of slotReplug()
 
1116
struct MenuInfo {
 
1117
        QString mName;
 
1118
        QPtrList<KAction> mActions;
 
1119
        MenuInfo() {}
 
1120
        MenuInfo(const QString& name) : mName(name) {}
 
1121
};
 
1122
 
 
1123
void GVMainWindow::slotReplug() {
 
1124
        typedef QMap<KIPI::Category, MenuInfo> CategoryMap;
 
1125
        CategoryMap categoryMap;
 
1126
        categoryMap[KIPI::IMAGESPLUGIN]=MenuInfo("image_actions");
 
1127
        categoryMap[KIPI::EFFECTSPLUGIN]=MenuInfo("effect_actions");
 
1128
        categoryMap[KIPI::TOOLSPLUGIN]=MenuInfo("tool_actions");
 
1129
        categoryMap[KIPI::IMPORTPLUGIN]=MenuInfo("import_actions");
 
1130
        categoryMap[KIPI::EXPORTPLUGIN]=MenuInfo("export_actions");
 
1131
        categoryMap[KIPI::BATCHPLUGIN]=MenuInfo("batch_actions");
 
1132
        categoryMap[KIPI::COLLECTIONSPLUGIN]=MenuInfo("collection_actions");
 
1133
        
 
1134
        // Fill the mActions
 
1135
        KIPI::PluginLoader::PluginList pluginList=mPluginLoader->pluginList();
 
1136
        KIPI::PluginLoader::PluginList::ConstIterator it(pluginList.begin());
 
1137
        KIPI::PluginLoader::PluginList::ConstIterator itEnd(pluginList.end());
 
1138
        for( ; it!=itEnd; ++it ) {
 
1139
                if (!(*it)->shouldLoad()) continue;
 
1140
                KIPI::Plugin* plugin = (*it)->plugin();
 
1141
                Q_ASSERT(plugin);
 
1142
                if (!plugin) continue;
 
1143
 
 
1144
                plugin->setup(this);
 
1145
                KActionPtrList actions = plugin->actions();
 
1146
                KActionPtrList::ConstIterator actionIt=actions.begin(), end=actions.end();
 
1147
                for (; actionIt!=end; ++actionIt) {
 
1148
                        KIPI::Category category = plugin->category(*actionIt);
 
1149
 
 
1150
                        if (!categoryMap.contains(category)) {
 
1151
                                kdWarning() << "Unknown category '" << category << "'\n";
 
1152
                                continue;
 
1153
                        }
 
1154
 
 
1155
                        categoryMap[category].mActions.append(*actionIt);
 
1156
                }
 
1157
                plugin->actionCollection()->readShortcutSettings();
 
1158
        }
 
1159
 
 
1160
        // Create a dummy "no plugin" action list
 
1161
        KAction* noPlugin=new KAction(i18n("No Plugin"), 0, 0, 0, actionCollection(), "no_plugin");
 
1162
        noPlugin->setShortcutConfigurable(false);
 
1163
        noPlugin->setEnabled(false);
 
1164
        QPtrList<KAction> noPluginList;
 
1165
        noPluginList.append(noPlugin);
 
1166
        
 
1167
        // Fill the menu
 
1168
        CategoryMap::ConstIterator catIt=categoryMap.begin(), catItEnd=categoryMap.end();
 
1169
        for (; catIt!=catItEnd; ++catIt) {
 
1170
                const MenuInfo& info=catIt.data();
 
1171
                unplugActionList(info.mName);
 
1172
                if (info.mActions.count()>0) {
 
1173
                        plugActionList(info.mName, info.mActions);
 
1174
                } else {
 
1175
                        plugActionList(info.mName, noPluginList);
 
1176
                }
 
1177
        }
 
1178
}
 
1179
#else
 
1180
void GVMainWindow::loadPlugins() {
 
1181
        QPopupMenu *popup = static_cast<QPopupMenu*>(
 
1182
                factory()->container( "plugins", this));
 
1183
        delete popup;
 
1184
}
 
1185
 
 
1186
 
 
1187
void GVMainWindow::slotReplug() {
 
1188
}
 
1189
#endif
 
1190
 
 
1191
 
 
1192
//-----------------------------------------------------------------------
 
1193
//
 
1194
// Properties
 
1195
//
 
1196
//-----------------------------------------------------------------------
 
1197
void GVMainWindow::setShowBusyPtrInFullScreen(bool value) {
 
1198
        mShowBusyPtrInFullScreen=value;
 
1199
}
 
1200
 
 
1201
void GVMainWindow::setAutoDeleteThumbnailCache(bool value){
 
1202
        mAutoDeleteThumbnailCache=value;
 
1203
}
 
1204
 
 
1205
 
 
1206
//-----------------------------------------------------------------------
 
1207
//
 
1208
// Configuration
 
1209
//
 
1210
//-----------------------------------------------------------------------
 
1211
void GVMainWindow::readConfig(KConfig* config,const QString& group) {
 
1212
        config->setGroup(group);
 
1213
        mShowBusyPtrInFullScreen=config->readBoolEntry(CONFIG_BUSYPTR_IN_FS, true);
 
1214
        mAutoDeleteThumbnailCache=config->readBoolEntry(CONFIG_AUTO_DELETE_THUMBNAIL_CACHE, false);     
 
1215
}
 
1216
 
 
1217
 
 
1218
void GVMainWindow::writeConfig(KConfig* config,const QString& group) const {
 
1219
        config->setGroup(group);
 
1220
        config->writeEntry(CONFIG_BUSYPTR_IN_FS, mShowBusyPtrInFullScreen);
 
1221
        config->writeEntry(CONFIG_AUTO_DELETE_THUMBNAIL_CACHE, mAutoDeleteThumbnailCache);
 
1222
}