2
Gwenview - A simple image viewer for KDE
3
Copyright (C) 2000-2002 Aur�lien G�teau
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
#include <kcmdlineargs.h>
28
#include <kfiledialog.h>
30
#include <khelpmenu.h>
31
#include <kkeydialog.h>
34
#include <kmessagebox.h>
35
#include <kprogress.h>
36
#include <kstatusbar.h>
37
#include <kstdaccel.h>
38
#include <kstdaction.h>
41
#include "configdialog.h"
44
#include "fileoperation.h"
46
#include "pixmapview.h"
47
#include "scrollpixmapview.h"
48
#include "statusbarprogress.h"
50
#include "mainwindow.moc"
53
enum { SB_FOLDER, SB_FILE};
55
const char* CONFIG_DOCK_GROUP="dock";
56
const char* CONFIG_MAINWINDOW_GROUP="main window";
57
const char* CONFIG_FILEWIDGET_GROUP="file widget";
58
const char* CONFIG_PIXMAPWIDGET_GROUP="pixmap widget";
59
const char* CONFIG_FILEOPERATION_GROUP="file operations";
62
MainWindow::MainWindow()
63
: KDockMainWindow(), mProgress(0L), mFullScreen(false)
65
FileOperation::readConfig(KGlobal::config(),CONFIG_FILEOPERATION_GROUP);
68
mGVPixmap=new GVPixmap(this);
75
createFileViewPopupMenu();
76
createScrollPixmapViewPopupMenu();
80
connect(mDirView,SIGNAL(folderChanged(QString)),
81
this,SLOT(setPath(QString)) );
84
connect(mPixmapView,SIGNAL(selectPrevious()),
85
mFileView,SLOT(slotSelectPrevious()) );
86
connect(mPixmapView,SIGNAL(selectNext()),
87
mFileView,SLOT(slotSelectNext()) );
88
connect(mPixmapView,SIGNAL(escapePressed()),
89
this,SLOT(escapePressed()) );
91
// Scroll pixmap connections
92
connect(mPixmapView->scrollPixmapView(),SIGNAL(zoomChanged(double)),
93
this,SLOT(updateFileStatusBar()) );
96
// Thumbnail view connections
97
connect(mFileView,SIGNAL(updateStarted(int)),
98
this,SLOT(thumbnailUpdateStarted(int)) );
99
connect(mFileView,SIGNAL(updateEnded()),
100
this,SLOT(thumbnailUpdateEnded()) );
101
connect(mFileView,SIGNAL(updatedOneThumbnail()),
102
this,SLOT(thumbnailUpdateProcessedOne()) );
104
// File view connections
105
connect(mFileView,SIGNAL(filenameChanged(QString)),
106
this,SLOT(setFilename(QString)) );
107
connect(mFileView,SIGNAL(completed()),
108
this,SLOT(updateStatusBar()) );
109
connect(mFileView,SIGNAL(canceled()),
110
this,SLOT(updateStatusBar()) );
112
// GVPixmap connections
113
connect(mGVPixmap,SIGNAL(loading()),
114
this,SLOT(pixmapLoading()) );
115
connect(mGVPixmap,SIGNAL(loaded()),
116
this,SLOT(pixmapLoaded()) );
120
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
123
if (args->count()==0) {
124
fullPath=QDir::currentDirPath();
126
fullPath=QFile::decodeName(args->arg(0));
129
// Go to requested file
134
MainWindow::~MainWindow() {
135
KConfig* config=KGlobal::config();
136
FileOperation::writeConfig(config,CONFIG_FILEOPERATION_GROUP);
137
mPixmapView->writeConfig(config,CONFIG_PIXMAPWIDGET_GROUP);
138
mFileView->writeConfig(config,CONFIG_FILEWIDGET_GROUP);
139
writeDockConfig(config,CONFIG_DOCK_GROUP);
140
mAccel->writeSettings();
144
//-Public slots----------------------------------------------------------
145
void MainWindow::setPath(QString fullPath) {
146
QFileInfo fileInfo(fullPath);
147
bool filenameIsValid;
149
// Init mFolder and mFilename
150
if (fileInfo.isFile()) {
151
mFolder=fileInfo.dirPath(true);
152
mFilename=fileInfo.fileName();
153
filenameIsValid=true;
154
mGVPixmap->load(fullPath);
156
filenameIsValid=false;
157
mFolder=fileInfo.absFilePath();
162
mToggleFullScreen->setEnabled(filenameIsValid);
163
mRenameFile->setEnabled(filenameIsValid);
164
mCopyFile->setEnabled(filenameIsValid);
165
mMoveFile->setEnabled(filenameIsValid);
166
mDeleteFile->setEnabled(filenameIsValid);
169
mFileView->setFolderAndFile(mFolder,mFilename);
170
mDirView->setFolder(mFolder);
172
if (filenameIsValid) {
173
mGVPixmap->load(fullPath);
180
void MainWindow::setFilename(QString filename) {
181
if (mFilename==filename) return;
185
bool filenameIsValid= mFilename!="";
187
mToggleFullScreen->setEnabled(filenameIsValid);
188
mRenameFile->setEnabled(filenameIsValid);
189
mCopyFile->setEnabled(filenameIsValid);
190
mMoveFile->setEnabled(filenameIsValid);
191
mDeleteFile->setEnabled(filenameIsValid);
193
if (filenameIsValid) {
194
mFileView->selectFilename(mFilename);
195
mGVPixmap->load(mFolder + '/' + mFilename);
199
updateFileStatusBar();
203
//-Private slots---------------------------------------------------------
204
void MainWindow::pixmapLoading() {
205
kapp->setOverrideCursor(QCursor(WaitCursor));
209
void MainWindow::pixmapLoaded() {
210
kapp->restoreOverrideCursor();
211
if ( (!mFilename.isEmpty()) && mGVPixmap->isNull()) {
212
KMessageBox::sorry(this,i18n("Could not load <b>%1</b>").arg(mFilename));
217
void MainWindow::toggleFullScreen() {
218
KConfig* config=KGlobal::config();
225
writeDockConfig(config,CONFIG_DOCK_GROUP);
226
makeDockInvisible(mFileDock);
227
makeDockInvisible(mFolderDock);
230
mPixmapView->setFullScreen(true);
233
readDockConfig(config,CONFIG_DOCK_GROUP);
239
mPixmapView->setFullScreen(false);
244
void MainWindow::showConfigDialog() {
245
ConfigDialog dialog(this,this);
250
void MainWindow::showKeyDialog() {
251
KKeyDialog::configureKeys(mAccel);
255
void MainWindow::escapePressed() {
257
mToggleFullScreen->activate();
262
void MainWindow::openFile() {
263
QString path=KFileDialog::getOpenFileName();
264
if (path.isNull()) return;
268
void MainWindow::openWithEditor() {
269
if (mFilename.isEmpty()) return;
271
FileOperation::openWithEditor(mFolder + '/' + mFilename);
275
void MainWindow::thumbnailUpdateStarted(int count) {
276
mProgress=new StatusBarProgress(statusBar(),i18n("Generating thumbnails..."),count);
277
mProgress->progress()->setFormat("%v/%m");
279
mStop->setEnabled(true);
283
void MainWindow::thumbnailUpdateEnded() {
284
mStop->setEnabled(false);
293
void MainWindow::thumbnailUpdateProcessedOne() {
294
mProgress->progress()->advance(1);
299
//-GUI-------------------------------------------------------------------
300
void MainWindow::updateStatusBar() {
302
uint count=mFileView->fileCount();
304
txt=i18n("%1 - %2 images");
306
txt=i18n("%1 - %2 image");
308
txt=txt.arg(mFolder).arg(count);
310
statusBar()->changeItem( txt, SB_FOLDER );
311
updateFileStatusBar();
315
void MainWindow::updateFileStatusBar() {
317
if (!mFilename.isEmpty()) {
318
txt=QString("%1 %2x%3 @ %4%")
319
.arg(mFilename).arg(mGVPixmap->width()).arg(mGVPixmap->height())
320
.arg(int(mPixmapView->scrollPixmapView()->zoom()*100) );
324
statusBar()->changeItem( txt, SB_FILE );
328
void MainWindow::createWidgets() {
329
KConfig* config=KGlobal::config();
332
statusBar()->insertItem("",SB_FOLDER);
333
statusBar()->setItemAlignment(SB_FOLDER, AlignLeft|AlignVCenter);
334
statusBar()->insertItem("",SB_FILE,1);
335
statusBar()->setItemAlignment(SB_FILE, AlignLeft|AlignVCenter);
338
mPixmapDock = createDockWidget("Image",SmallIcon("gwenview"),NULL,i18n("Image"));
340
mPixmapView=new PixmapView(mPixmapDock,mGVPixmap);
341
mPixmapDock->setWidget(mPixmapView);
342
setView(mPixmapDock);
343
setMainDockWidget(mPixmapDock);
346
mFolderDock = createDockWidget("Folders",SmallIcon("folder_open"),NULL,i18n("Folders"));
347
mDirView=new DirView(mFolderDock);
348
mFolderDock->setWidget(mDirView);
351
mFileDock = createDockWidget("Files",SmallIcon("image"),NULL,i18n("Files"));
352
mFileView=new FileView(this);
353
mFileDock->setWidget(mFileView);
355
// Default dock config
356
setGeometry(20,20,600,400);
357
mFolderDock->manualDock( mPixmapDock,KDockWidget::DockLeft,30);
358
mFileDock->manualDock( mPixmapDock,KDockWidget::DockTop,30);
361
readDockConfig(config,CONFIG_DOCK_GROUP);
362
mFileView->readConfig(config,CONFIG_FILEWIDGET_GROUP);
363
mPixmapView->readConfig(config,CONFIG_PIXMAPWIDGET_GROUP);
367
void MainWindow::createActions() {
368
mOpenFile=KStdAction::open(this, SLOT(openFile()),actionCollection() );
370
mRenameFile=new KAction(i18n("&Rename..."),Key_F2,mFileView,SLOT(renameFile()),actionCollection(),"file_new");
372
mCopyFile=new KAction(i18n("&Copy to..."),Key_F5,mFileView,SLOT(copyFile()),actionCollection(),"file_copy");
374
mMoveFile=new KAction(i18n("&Move to..."),Key_F6,mFileView,SLOT(moveFile()),actionCollection(),"file_move");
376
mDeleteFile=new KAction(i18n("&Delete"),"editdelete",Key_Delete,mFileView,SLOT(deleteFile()),actionCollection(),"file_delete");
378
mOpenWithEditor=new KAction(i18n("&Open with editor"),"paintbrush",0,this,SLOT(openWithEditor()),actionCollection(),"file_edit");
380
mToggleFullScreen=new KAction(i18n("Full screen"),"window_fullscreen",CTRL + Key_F,this,SLOT(toggleFullScreen()),actionCollection(),"view_fullscreen");
382
mShowConfigDialog=new KAction(i18n("Configure Gwenview"),"configure",0,this,SLOT(showConfigDialog()),actionCollection());
384
mShowKeyDialog=KStdAction::keyBindings(this,SLOT(showKeyDialog()),actionCollection());
386
mStop=new KAction(i18n("Stop"),"stop",Key_Escape,mFileView,SLOT(cancel()),actionCollection());
387
mStop->setEnabled(false);
391
void MainWindow::createAccels() {
392
// Associate actions with accelerator
393
mAccel=new KAccel(this);
394
int count=actionCollection()->count();
396
for (int pos=0;pos<count;++pos) {
397
KAction *action = actionCollection()->action(pos);
398
if ( action->accel() ) {
399
action->plugAccel(mAccel);
402
mFileView->plugActionsToAccel(mAccel);
403
mPixmapView->scrollPixmapView()->plugActionsToAccel(mAccel);
405
// Read user accelerator
406
mAccel->readSettings();
410
void MainWindow::createMenu() {
411
QPopupMenu* fileMenu = new QPopupMenu;
413
mOpenFile->plug(fileMenu);
414
fileMenu->insertSeparator();
415
mOpenWithEditor->plug(fileMenu);
416
mRenameFile->plug(fileMenu);
417
mCopyFile->plug(fileMenu);
418
mMoveFile->plug(fileMenu);
419
mDeleteFile->plug(fileMenu);
420
fileMenu->insertSeparator();
421
KStdAction::quit( kapp, SLOT (closeAllWindows()) )->plug(fileMenu);
422
menuBar()->insertItem(i18n("&File"), fileMenu);
424
QPopupMenu* viewMenu = new QPopupMenu;
425
mStop->plug(viewMenu);
427
viewMenu->insertSeparator();
428
mFileView->noThumbnails()->plug(viewMenu);
429
mFileView->smallThumbnails()->plug(viewMenu);
430
mFileView->medThumbnails()->plug(viewMenu);
431
mFileView->largeThumbnails()->plug(viewMenu);
433
viewMenu->insertSeparator();
434
mToggleFullScreen->plug(viewMenu);
435
mPixmapView->scrollPixmapView()->zoomIn()->plug(viewMenu);
436
mPixmapView->scrollPixmapView()->zoomOut()->plug(viewMenu);
437
mPixmapView->scrollPixmapView()->resetZoom()->plug(viewMenu);
438
mPixmapView->scrollPixmapView()->autoZoom()->plug(viewMenu);
439
menuBar()->insertItem(i18n("&View"), viewMenu);
441
QPopupMenu* goMenu = new QPopupMenu;
442
mFileView->selectFirst()->plug(goMenu);
443
mFileView->selectPrevious()->plug(goMenu);
444
mFileView->selectNext()->plug(goMenu);
445
mFileView->selectLast()->plug(goMenu);
446
menuBar()->insertItem(i18n("&Go"), goMenu);
448
QPopupMenu* settingsMenu = new QPopupMenu;
449
mShowConfigDialog->plug(settingsMenu);
450
mShowKeyDialog->plug(settingsMenu);
451
menuBar()->insertItem(i18n("&Settings"),settingsMenu);
453
menuBar()->insertItem(i18n("&Windows"), dockHideShowMenu());
455
menuBar()->insertItem(i18n("&Help"), helpMenu());
461
void MainWindow::createFileViewPopupMenu() {
462
QPopupMenu* menu=new QPopupMenu(this);
464
mOpenWithEditor->plug(menu);
465
mRenameFile->plug(menu);
466
mCopyFile->plug(menu);
467
mMoveFile->plug(menu);
468
mDeleteFile->plug(menu);
470
mFileView->installRBPopup(menu);
474
void MainWindow::createScrollPixmapViewPopupMenu() {
475
QPopupMenu* menu=new QPopupMenu(this);
477
mPixmapView->scrollPixmapView()->zoomIn()->plug(menu);
478
mPixmapView->scrollPixmapView()->zoomOut()->plug(menu);
479
mPixmapView->scrollPixmapView()->resetZoom()->plug(menu);
480
mPixmapView->scrollPixmapView()->autoZoom()->plug(menu);
482
menu->insertSeparator();
483
mToggleFullScreen->plug(menu);
485
menu->insertSeparator();
486
mFileView->selectFirst()->plug(menu);
487
mFileView->selectPrevious()->plug(menu);
488
mFileView->selectNext()->plug(menu);
489
mFileView->selectLast()->plug(menu);
491
menu->insertSeparator();
492
mOpenWithEditor->plug(menu);
493
mRenameFile->plug(menu);
494
mCopyFile->plug(menu);
495
mMoveFile->plug(menu);
496
mDeleteFile->plug(menu);
498
mPixmapView->scrollPixmapView()->installRBPopup(menu);
503
void MainWindow::createToolBar() {
504
mFileView->selectFirst()->plug(toolBar());
505
mFileView->selectPrevious()->plug(toolBar());
506
mFileView->selectNext()->plug(toolBar());
507
mFileView->selectLast()->plug(toolBar());
508
toolBar()->insertLineSeparator();
510
mStop->plug(toolBar());
511
toolBar()->insertLineSeparator();
512
mFileView->noThumbnails()->plug(toolBar());
513
mFileView->smallThumbnails()->plug(toolBar());
514
mFileView->medThumbnails()->plug(toolBar());
515
mFileView->largeThumbnails()->plug(toolBar());
517
toolBar()->insertLineSeparator();
518
mToggleFullScreen->plug(toolBar());
519
mPixmapView->scrollPixmapView()->zoomIn()->plug(toolBar());
520
mPixmapView->scrollPixmapView()->zoomOut()->plug(toolBar());
521
mPixmapView->scrollPixmapView()->resetZoom()->plug(toolBar());
522
mPixmapView->scrollPixmapView()->autoZoom()->plug(toolBar());