2 * This file is a part of QComicBook.
4 * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
6 * QComicBook is free software; you can redestribute it and/or modify it
7 * under terms of GNU General Public License by Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY. See GPL for more details.
14 #include "bookmarks.h"
15 #include "comicmain.h"
20 #include "imgarchivesink.h"
21 #include "imgsinkfactory.h"
22 #include "aboutdialog.h"
23 #include "cbsettings.h"
25 #include "helpbrowser.h"
26 #include "cbconfigdialog.h"
27 #include "statusbar.h"
28 #include "thumbnailswin.h"
29 #include "thumbnailsview.h"
30 #include "thumbnailloader.h"
31 #include "bookmarkmanager.h"
33 #include "archiverdialog.h"
34 #include "suparchwin.h"
35 #include "imlibimage.h"
38 #include <qpopupmenu.h>
39 #include <qstringlist.h>
41 #include <qfiledialog.h>
42 #include <qfileinfo.h>
44 #include <qmessagebox.h>
47 #include <jumptopagewin.h>
49 #include <qdragobject.h>
52 using namespace QComicBook;
53 using namespace Utility;
55 ComicMainWindow::ComicMainWindow(QWidget *parent): QMainWindow(parent, NULL, WType_TopLevel|WDestructiveClose), sink(NULL), currpage(0), prevpage(-1), nextpage(-1), spreading(false), stripping(false), edit_menu(NULL)
58 setIcon(Icons::get(ICON_APPICON).pixmap(QIconSet::Small, true));
59 setMinimumSize(320, 200);
61 setAcceptDrops(true); //???
63 cfg = &ComicBookSettings::instance();
65 setGeometry(cfg->geometry());
70 setupComicImageView();
71 setupThumbnailsWindow();
74 if (cfg->editSupport())
77 setupNavigationMenu();
83 lastdir = cfg->lastDir();
84 recentfiles = new History(10);
85 *recentfiles = cfg->recentlyOpened();
86 setRecentFilesMenu(*recentfiles);
88 cfg->restoreDockLayout(this);
90 enableComicBookActions(false);
93 ComicMainWindow::~ComicMainWindow()
95 if (cfg->cacheThumbnails())
96 ImgDirSink::removeThumbnails(cfg->thumbnailsAge());
107 void ComicMainWindow::setupActions()
109 openArchiveAction = new QAction(Icons::get(ICON_OPENARCH), tr("Open archive"), CTRL+Key_O, this);
110 openDirAction = new QAction(Icons::get(ICON_OPENDIR), tr("Open directory"), CTRL+Key_D, this);
111 openNextAction = new QAction(tr("Open next"), CTRL+Key_N, this);
112 openPrevAction = new QAction(tr("Open previous"), CTRL+Key_P, this);
113 fullScreenAction = new QAction(tr("&Fullscreen"), Key_F11, this);
114 nextPageAction = new QAction(Icons::get(ICON_NEXTPAGE), tr("Next page"), Key_PageDown, this);
115 forwardPageAction = new QAction(Icons::get(ICON_FORWARD), tr("5 pages forward"), QKeySequence(), this);
116 backwardPageAction = new QAction(Icons::get (ICON_BACKWARD), tr("5 pages backward"), QKeySequence(), this);
117 jumpDownAction = new QAction(QString::null, Key_Space, this);
118 jumpUpAction = new QAction(QString::null, Key_Backspace, this);
119 prevPageAction = new QAction(Icons::get(ICON_PREVPAGE), tr("&Previous page"), Key_PageUp, this);
120 pageTopAction = new QAction(Icons::get(ICON_PAGETOP), tr("Page top"), Key_Home, this);
121 pageBottomAction = new QAction(Icons::get(ICON_PAGEBOTTOM), tr("Page bottom"), Key_End, this);
122 firstPageAction = new QAction(tr("First page"), CTRL+Key_Home, this);
123 lastPageAction = new QAction(tr("Last page"), CTRL+Key_End, this);
124 scrollRightAction = new QAction(tr("Scroll right"), Key_Right, this);
125 scrollLeftAction = new QAction(tr("Scroll left"), Key_Left, this);
126 scrollRightFastAction = new QAction(tr("Fast scroll right"), SHIFT+Key_Right, this);
127 scrollLeftFastAction = new QAction(tr("Fast scroll left"), SHIFT+Key_Left, this);
128 scrollUpAction = new QAction(tr("Scroll up"), Key_Up, this);
129 scrollDownAction = new QAction(tr("Scroll down"), Key_Down, this);
130 scrollUpFastAction = new QAction(tr("Fast scroll up"), SHIFT+Key_Up, this);
131 scrollDownFastAction = new QAction(tr("Fast scroll down"), SHIFT+Key_Down, this);
132 quitAction = new QAction(tr("Quit"), CTRL+Key_Q, this);
134 QActionGroup *scaleActions = new QActionGroup(this);
135 fitWidthAction = new QAction(Icons::get(ICON_FITWIDTH), tr("Fit width"), ALT+Key_W, scaleActions);
136 fitWidthAction->setToggleAction(true);
137 fitHeightAction = new QAction(Icons::get(ICON_FITHEIGHT), tr("Fit height"), ALT+Key_H, scaleActions);
138 fitHeightAction->setToggleAction(true);
139 wholePageAction = new QAction(Icons::get(ICON_WHOLEPAGE), tr("Whole page"), ALT+Key_A, scaleActions);
140 wholePageAction->setToggleAction(true);
141 originalSizeAction = new QAction(Icons::get(ICON_ORGSIZE), tr("Original size"), ALT+Key_O, scaleActions);
142 originalSizeAction->setToggleAction(true);
143 bestFitAction = new QAction(Icons::get(ICON_BESTFIT), tr("Best fit"), ALT+Key_B, scaleActions);
144 bestFitAction->setToggleAction(true);
145 mangaModeAction = new QAction(Icons::get(ICON_JAPANESE), tr("Japanese mode"), CTRL+Key_J, this);
146 mangaModeAction->setToggleAction(true);
147 twoPagesAction = new QAction(Icons::get(ICON_TWOPAGES), tr("Two pages"), CTRL+Key_T, this);
148 twoPagesAction->setToggleAction(true);
149 stripModeAction = new QAction(tr("Strip Mode"), QKeySequence(), this);
150 stripModeAction->setToggleAction(true);
151 rotateRightAction = new QAction(Icons::get(ICON_ROTRIGHT), tr("Rotate right"), QKeySequence(), this);
152 rotateLeftAction = new QAction(Icons::get(ICON_ROTLEFT), tr("Rotate left"), QKeySequence(), this);
153 rotateResetAction = new QAction(tr("No rotation"), QKeySequence(), this);
154 togglePreserveRotationAction = new QAction(tr("Preserve rotation"), QKeySequence(), this);
155 togglePreserveRotationAction->setToggleAction(true);
156 showInfoAction = new QAction(Icons::get(ICON_INFO), tr("Info"), ALT+Key_I, this);
157 exitFullScreenAction = new QAction(QString::null, Key_Escape, this);
158 toggleStatusbarAction = new QAction(tr("Statusbar"), QKeySequence(), this);
159 toggleStatusbarAction->setToggleAction(true);
160 toggleThumbnailsAction = new QAction(Icons::get(ICON_THUMBNAILS), tr("Thumbnails"), ALT+Key_T, this);
161 toggleThumbnailsAction->setToggleAction(true);
162 toggleToolbarAction = new QAction(tr("Toolbar"), QKeySequence(), this);
163 toggleToolbarAction->setToggleAction(true);
165 connect(openArchiveAction, SIGNAL(activated()), this, SLOT(browseArchive()));
166 connect(openDirAction, SIGNAL(activated()), this, SLOT(browseDirectory()));
167 connect(openNextAction, SIGNAL(activated()), this, SLOT(openNext()));
168 connect(openPrevAction, SIGNAL(activated()), this, SLOT(openPrevious()));
169 connect(showInfoAction, SIGNAL(activated()), this, SLOT(showInfo()));
170 connect(exitFullScreenAction, SIGNAL(activated()), this, SLOT(exitFullscreen()));
171 connect(nextPageAction, SIGNAL(activated()), this, SLOT(nextPage()));
172 connect(forwardPageAction, SIGNAL(activated()), this, SLOT(forwardPages()));
173 connect(firstPageAction, SIGNAL(activated()), this, SLOT(firstPage()));
174 connect(lastPageAction, SIGNAL(activated()), this, SLOT(lastPage()));
175 connect(backwardPageAction, SIGNAL(activated()), this, SLOT(backwardPages()));
176 connect(quitAction, SIGNAL(activated()), this, SLOT(close()));
179 void ComicMainWindow::setupComicImageView()
181 view = new ComicImageView(this, cfg->pageSize(), cfg->background());
182 setCentralWidget(view);
184 view->setSmallCursor(cfg->smallCursor());
185 connect(cfg, SIGNAL(backgroundChanged(const QColor&)), view, SLOT(setBackground(const QColor&)));
186 connect(cfg, SIGNAL(cursorChanged(bool)), view, SLOT(setSmallCursor(bool)));
187 connect(fullScreenAction, SIGNAL(activated()), this, SLOT(toggleFullScreen()));
188 connect(pageTopAction, SIGNAL(activated()), view, SLOT(scrollToTop()));
189 connect(pageBottomAction, SIGNAL(activated()), view, SLOT(scrollToBottom()));
190 connect(scrollRightAction, SIGNAL(activated()), view, SLOT(scrollRight()));
191 connect(scrollLeftAction, SIGNAL(activated()), view, SLOT(scrollLeft()));
192 connect(scrollRightFastAction, SIGNAL(activated()), view, SLOT(scrollRightFast()));
193 connect(scrollLeftFastAction, SIGNAL(activated()), view, SLOT(scrollLeftFast()));
194 connect(scrollUpAction, SIGNAL(activated()), view, SLOT(scrollUp()));
195 connect(scrollDownAction, SIGNAL(activated()), view, SLOT(scrollDown()));
196 connect(scrollUpFastAction, SIGNAL(activated()), view, SLOT(scrollUpFast()));
197 connect(scrollDownFastAction, SIGNAL(activated()), view, SLOT(scrollDownFast()));
198 connect(fitWidthAction, SIGNAL(activated()), view, SLOT(setSizeFitWidth()));
199 connect(fitHeightAction, SIGNAL(activated()), view, SLOT(setSizeFitHeight()));
200 connect(wholePageAction, SIGNAL(activated()), view, SLOT(setSizeWholePage()));
201 connect(originalSizeAction, SIGNAL(activated()), view, SLOT(setSizeOriginal()));
202 connect(bestFitAction, SIGNAL(activated()), view, SLOT(setSizeBestFit()));
203 connect(mangaModeAction, SIGNAL(toggled(bool)), this, SLOT(toggleJapaneseMode(bool)));
204 connect(twoPagesAction, SIGNAL(toggled(bool)), this, SLOT(toggleTwoPages(bool)));
205 connect(stripModeAction, SIGNAL(toggled(bool)), this, SLOT(toggleStripMode(bool)));
206 connect(prevPageAction, SIGNAL(activated()), this, SLOT(prevPage()));
207 connect(rotateRightAction, SIGNAL(activated()), view, SLOT(rotateRight()));
208 connect(rotateLeftAction, SIGNAL(activated()), view, SLOT(rotateLeft()));
209 connect(rotateResetAction, SIGNAL(activated()), view, SLOT(resetRotation()));
210 connect(jumpDownAction, SIGNAL(activated()), view, SLOT(jumpDown()));
211 connect(jumpUpAction, SIGNAL(activated()), view, SLOT(jumpUp()));
212 if (cfg->continuousScrolling())
214 connect(view, SIGNAL(bottomReached()), this, SLOT(nextPage()));
215 connect(view, SIGNAL(topReached()), this, SLOT(prevPageBottom()));
217 connect(view, SIGNAL(doubleClick()), this, SLOT(nextPage()));
218 view->enableScrollbars(cfg->scrollbarsVisible());
219 QAction *which = originalSizeAction;
220 switch (cfg->pageSize())
222 case FitWidth: which = fitWidthAction; break;
223 case FitHeight: which = fitHeightAction; break;
224 case BestFit: which = bestFitAction; break;
225 case WholePage: which = wholePageAction; break;
226 case Original: which = originalSizeAction; break;
231 void ComicMainWindow::setupThumbnailsWindow()
233 thumbswin = new ThumbnailsWindow(QDockWindow::InDock, this);
234 moveDockWindow(thumbswin, Qt::DockLeft); //initial position of thumbnails window
235 connect(thumbswin, SIGNAL(requestedPage(int, bool)), this, SLOT(jumpToPage(int, bool)));
236 connect(thumbswin, SIGNAL(visibilityChanged(bool)), this, SLOT(thumbnailsVisibilityChanged(bool)));
237 connect(thumbswin, SIGNAL(visibilityChanged(bool)), toggleThumbnailsAction, SLOT(setOn(bool)));
238 connect(toggleThumbnailsAction, SIGNAL(toggled(bool)), thumbswin, SLOT(setShown(bool)));
241 void ComicMainWindow::setupToolbar()
243 toolbar = new QToolBar(tr("Toolbar"), this);
244 openArchiveAction->addTo(toolbar);
245 openDirAction->addTo(toolbar);
246 toolbar->addSeparator();
247 showInfoAction->addTo(toolbar);
248 toggleThumbnailsAction->addTo(toolbar);
249 toolbar->addSeparator();
250 twoPagesAction->addTo(toolbar);
251 stripModeAction->addTo(toolbar);
252 mangaModeAction->addTo(toolbar);
253 toolbar->addSeparator();
254 prevPageAction->addTo(toolbar);
255 nextPageAction->addTo(toolbar);
256 backwardPageAction->addTo(toolbar);
257 forwardPageAction->addTo(toolbar);
258 pageTopAction->addTo(toolbar);
259 pageBottomAction->addTo(toolbar);
260 toolbar->addSeparator();
261 originalSizeAction->addTo(toolbar);
262 fitWidthAction->addTo(toolbar);
263 fitHeightAction->addTo(toolbar);
264 wholePageAction->addTo(toolbar);
265 bestFitAction->addTo(toolbar);
266 toolbar->addSeparator();
267 rotateRightAction->addTo(toolbar);
268 rotateLeftAction->addTo(toolbar);
269 connect(toggleToolbarAction, SIGNAL(toggled(bool)), toolbar, SLOT(setShown(bool)));
270 connect(toolbar, SIGNAL(visibilityChanged(bool)), this, SLOT(toolbarVisibilityChanged(bool)));
273 void ComicMainWindow::setupFileMenu()
275 file_menu = new QPopupMenu(this);
276 openArchiveAction->addTo(file_menu);
277 openDirAction->addTo(file_menu);
278 openNextAction->addTo(file_menu);
279 openPrevAction->addTo(file_menu);
280 recent_menu = new QPopupMenu(this);
281 file_menu->insertItem(tr("Recently opened"), recent_menu);
282 connect(recent_menu, SIGNAL(activated(int)), this, SLOT(recentSelected(int)));
283 file_menu->insertSeparator();
284 //create_id = file_menu->insertItem(tr("Create archive"), this, SLOT(createArchive()));
285 //file_menu->insertSeparator();
286 showInfoAction->addTo(file_menu);
287 file_menu->insertSeparator();
288 close_id = file_menu->insertItem(tr("Close"), this, SLOT(closeSink()));
289 file_menu->insertSeparator();
290 quitAction->addTo(file_menu);
291 menuBar()->insertItem(tr("&File"), file_menu);
294 void ComicMainWindow::setupEditMenu()
296 edit_menu = new QPopupMenu(this);
297 gimp_id = edit_menu->insertItem(tr("Open with Gimp"), this, SLOT(openWithGimp()));
298 //edit_menu->insertItem(tr("Open with Kolour Paint"), this, SLOT(openWithGimp()));
299 //edit_menu->insertItem(tr("Open with ImageMagick"), this, SLOT(openWithGimp()));
300 edit_menu->insertSeparator();
301 reload_id = edit_menu->insertItem(tr("Reload page"), this, SLOT(reloadPage()));
302 menuBar()->insertItem(tr("&Edit"), edit_menu);
305 void ComicMainWindow::setupViewMenu()
307 view_menu = new QPopupMenu(this);
308 view_menu->setCheckable(true);
309 originalSizeAction->addTo(view_menu);
310 fitWidthAction->addTo(view_menu);
311 fitHeightAction->addTo(view_menu);
312 wholePageAction->addTo(view_menu);
313 bestFitAction->addTo(view_menu);
314 view_menu->insertSeparator();
315 rotateRightAction->addTo(view_menu);
316 rotateLeftAction->addTo(view_menu);
317 rotateResetAction->addTo(view_menu);
318 togglePreserveRotationAction->addTo(view_menu);
319 view_menu->insertSeparator();
320 twoPagesAction->addTo(view_menu);
321 stripModeAction->addTo(view_menu);
322 mangaModeAction->addTo(view_menu);
323 toggleThumbnailsAction->addTo(view_menu);
324 menuBar()->insertItem(tr("&View"), view_menu);
327 void ComicMainWindow::setupNavigationMenu()
329 navi_menu = new QPopupMenu(this);
330 nextPageAction->addTo(navi_menu);
331 prevPageAction->addTo(navi_menu);
332 navi_menu->insertSeparator();
333 forwardPageAction->addTo(navi_menu);
334 backwardPageAction->addTo(navi_menu);
335 navi_menu->insertSeparator();
336 jumpto_id = navi_menu->insertItem(tr("Jump to page..."), this, SLOT(showJumpToPage()));
337 firstPageAction->addTo(navi_menu);
338 lastPageAction->addTo(navi_menu);
339 navi_menu->insertSeparator();
340 pageTopAction->addTo(navi_menu);
341 pageBottomAction->addTo(navi_menu);
342 navi_menu->insertSeparator();
343 contscr_id = navi_menu->insertItem(tr("Continuous scrolling"), this, SLOT(toggleContinousScroll()));
344 twoPagesAction->setOn(cfg->twoPagesMode());
345 stripModeAction->setOn(cfg->stripMode());
346 mangaModeAction->setOn(cfg->japaneseMode());
347 navi_menu->setItemChecked(contscr_id, cfg->continuousScrolling());
348 menuBar()->insertItem(tr("&Navigation"), navi_menu);
351 void ComicMainWindow::setupBookmarksMenu()
353 bookmarks_menu = new QPopupMenu(this);
354 bookmarks = new Bookmarks(bookmarks_menu);
355 menuBar()->insertItem(tr("&Bookmarks"), bookmarks_menu);
356 setbookmark_id = bookmarks_menu->insertItem(Icons::get(ICON_BOOKMARK), tr("Set bookmark for this comicbook"), this, SLOT(setBookmark()));
357 rmvbookmark_id = bookmarks_menu->insertItem(tr("Remove bookmark for this comicbook"), this, SLOT(removeBookmark()));
358 bookmarks_menu->insertItem(tr("Manage bookmarks"), this, SLOT(openBookmarksManager()));
359 bookmarks_menu->insertSeparator();
361 connect(bookmarks_menu, SIGNAL(activated(int)), this, SLOT(bookmarkSelected(int)));
364 void ComicMainWindow::setupSettingsMenu()
366 settings_menu = new QPopupMenu(this);
367 scrv_id = settings_menu->insertItem(tr("Scrollbars"), this, SLOT(toggleScrollbars()));
368 settings_menu->setItemChecked(scrv_id, cfg->scrollbarsVisible());
369 toggleToolbarAction->addTo(settings_menu);
370 toggleStatusbarAction->addTo(settings_menu);
371 settings_menu->insertSeparator();
372 fullScreenAction->addTo(settings_menu);
373 settings_menu->insertSeparator();
374 settings_menu->insertItem(Icons::get(ICON_SETTINGS), tr("Configure QComicBook"), this, SLOT(showConfigDialog()));
375 menuBar()->insertItem(tr("&Settings"), settings_menu);
378 void ComicMainWindow::setupHelpMenu()
380 QPopupMenu *help_menu = new QPopupMenu(this);
381 help_menu->insertItem(tr("System information"), this, SLOT(showSysInfo()));
382 help_menu->insertSeparator();
383 help_menu->insertItem(tr("Index"), this, SLOT(showHelp()));
384 help_menu->insertItem(tr("About"), this, SLOT(showAbout()));
385 menuBar()->insertItem(tr("&Help"), help_menu);
388 void ComicMainWindow::setupStatusbar()
390 statusbar = new StatusBar(this);
391 connect(toggleStatusbarAction, SIGNAL(toggled(bool)), statusbar, SLOT(setShown(bool)));
392 toggleStatusbarAction->setOn(cfg->showStatusbar());
393 statusbar->setShown(cfg->showStatusbar());
396 void ComicMainWindow::setupContextMenu()
398 QPopupMenu *cmenu = view->contextMenu();
399 pageinfo = new QLabel(cmenu);
400 pageinfo->setMargin(3);
401 pageinfo->setAlignment(Qt::AlignHCenter);
402 pageinfo->setFrameStyle(QFrame::Box | QFrame::Raised);
403 nextPageAction->addTo(cmenu);
404 prevPageAction->addTo(cmenu);
405 cmenu->insertSeparator();
406 fitWidthAction->addTo(cmenu);
407 fitHeightAction->addTo(cmenu);
408 wholePageAction->addTo(cmenu);
409 originalSizeAction->addTo(cmenu);
410 bestFitAction->addTo(cmenu);
411 cmenu->insertSeparator();
412 rotateRightAction->addTo(cmenu);
413 rotateLeftAction->addTo(cmenu);
414 rotateResetAction->addTo(cmenu);
415 cmenu->insertSeparator();
416 twoPagesAction->addTo(cmenu);
417 stripModeAction->addTo(cmenu);
418 mangaModeAction->addTo(cmenu);
419 cmenu->insertSeparator();
420 fullScreenAction->addTo(cmenu);
421 cmenu->insertSeparator();
422 cmenu->insertItem(pageinfo);
425 void ComicMainWindow::enableComicBookActions(bool f)
429 const bool x = f && sink && sink->supportsNext();
430 file_menu->setItemEnabled(close_id, f);
431 file_menu->setItemEnabled(create_id, f);
432 showInfoAction->setEnabled(f);
433 openNextAction->setEnabled(x);
434 openPrevAction->setEnabled(x);
440 edit_menu->setItemEnabled(gimp_id, f);
441 edit_menu->setItemEnabled(reload_id, f);
446 rotateRightAction->setEnabled(f);
447 rotateLeftAction->setEnabled(f);
448 rotateResetAction->setEnabled(f);
452 lastPageAction->setEnabled(f);
453 firstPageAction->setEnabled(f);
454 navi_menu->setItemEnabled(jumpto_id, f);
455 nextPageAction->setEnabled(f);
456 prevPageAction->setEnabled(f);
457 backwardPageAction->setEnabled(f);
458 forwardPageAction->setEnabled(f);
459 pageTopAction->setEnabled(f);
460 pageBottomAction->setEnabled(f);
464 bookmarks_menu->setItemEnabled(setbookmark_id, f);
465 bookmarks_menu->setItemEnabled(rmvbookmark_id, f);
468 void ComicMainWindow::dragEnterEvent(QDragEnterEvent *e)
470 e->accept(QUriDrag::canDecode(e));
473 void ComicMainWindow::dropEvent(QDropEvent *e)
476 if (QUriDrag::decodeLocalFiles(e, files))
480 void ComicMainWindow::keyPressEvent(QKeyEvent *e)
482 if ((e->key()>=Qt::Key_1) && (e->key()<=Qt::Key_9))
485 showJumpToPage(e->text());
488 QMainWindow::keyPressEvent(e);
491 void ComicMainWindow::closeEvent(QCloseEvent *e)
493 return (!cfg->confirmExit() || confirmExit()) ? e->accept() : e->ignore();
496 bool ComicMainWindow::confirmExit()
498 return QMessageBox::question(this, tr("Leave QComicBook?"), tr("Do you really want to quit QComicBook?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes;
501 void ComicMainWindow::thumbnailsVisibilityChanged(bool f)
505 int max = sink->numOfImages();
506 for (int i=0; i<max; i++)
507 if (!thumbswin->view()->isLoaded(i))
508 sink->requestThumbnail(i);
512 void ComicMainWindow::toolbarVisibilityChanged(bool f)
514 toggleToolbarAction->setOn(f);
517 void ComicMainWindow::toggleScrollbars()
519 bool f = settings_menu->isItemChecked(scrv_id);
520 settings_menu->setItemChecked(scrv_id, !f);
521 view->enableScrollbars(!f);
524 void ComicMainWindow::toggleContinousScroll()
526 bool f = navi_menu->isItemChecked(contscr_id);
527 navi_menu->setItemChecked(contscr_id, !f);
530 view->disconnect(SIGNAL(bottomReached()), this);
531 view->disconnect(SIGNAL(topReached()), this);
534 { connect(view, SIGNAL(bottomReached()), this, SLOT(nextPage()));
535 connect(view, SIGNAL(topReached()), this, SLOT(prevPageBottom()));
539 void ComicMainWindow::toggleTwoPages(bool f)
541 twoPagesAction->setOn(f);
542 jumpToPage(currpage, true);
545 void ComicMainWindow::toggleStripMode(bool f)
547 stripModeAction->setOn(f);
548 jumpToPage(currpage, true);
551 void ComicMainWindow::toggleJapaneseMode(bool f)
553 mangaModeAction->setOn(f);
554 if (twoPagesAction->isOn())
555 jumpToPage(currpage, true);
558 void ComicMainWindow::reloadPage()
561 jumpToPage(currpage, true);
564 void ComicMainWindow::updateCaption()
566 QString c = "QComicBook";
568 c += " - " + sink->getName();
572 void ComicMainWindow::setRecentFilesMenu(const History &hist)
574 QStringList list = hist.getAll();
575 recent_menu->clear();
576 for (QStringList::const_iterator it = list.begin(); it != list.end(); it++)
577 recent_menu->insertItem(*it);
580 void ComicMainWindow::recentSelected(int id)
582 const QString &fname = recent_menu->text(id);
583 if (fname != QString::null)
585 QFileInfo finfo(fname);
588 recentfiles->remove(fname);
589 recent_menu->removeItem(id);
595 void ComicMainWindow::sinkReady(const QString &path)
597 statusbar->setShown(toggleStatusbarAction->isOn() && !(isFullScreen() && cfg->fullScreenHideStatusbar())); //applies back user's statusbar&toolbar preferences
598 //toolbar->setShown(toggleToolbarAction->isOn() && !(isFullScreen() && cfg->fullScreenHideToolbar()));
600 recentfiles->append(path);
601 setRecentFilesMenu(*recentfiles);
603 enableComicBookActions(true);
605 statusbar->setName(sink->getFullName());
607 thumbswin->view()->setPages(sink->numOfImages());
610 // request thumbnails for all pages
611 if (thumbswin->isVisible())
612 sink->requestThumbnails(0, sink->numOfImages());
614 jumpToPage(currpage, true);
616 const bool hasdesc = (sink->getDescription().count() > 0);
617 showInfoAction->setDisabled(!hasdesc);
619 if (hasdesc && cfg->autoInfo())
623 void ComicMainWindow::sinkError(int code)
625 statusbar->setShown(toggleStatusbarAction->isOn() && !(isFullScreen() && cfg->fullScreenHideStatusbar())); //applies back user's statusbar&toolbar preferences
626 //toolbar->setShown(toggleToolbarAction->isOn() && !(isFullScreen() && cfg->fullScreenHideToolbar()));
631 case SINKERR_EMPTY: msg = tr("no images found"); break;
632 case SINKERR_UNKNOWNFILE: msg = tr("unknown archive"); break;
633 case SINKERR_ACCESS: msg = tr("can't access directory"); break;
634 case SINKERR_NOTFOUND: msg = tr("file/directory not found"); break;
635 case SINKERR_NOTSUPPORTED: msg = tr("archive not supported"); break;
636 case SINKERR_ARCHEXIT: msg = tr("archive extractor exited with error"); break;
639 QMessageBox::critical(this, "QComicBook error", "Error opening comicbook: " + msg,
640 QMessageBox::Ok, QMessageBox::NoButton);
644 void ComicMainWindow::browseDirectory()
646 const QString dir = QFileDialog::getExistingDirectory(lastdir, this,
647 NULL, tr("Choose a directory") );
652 void ComicMainWindow::browseArchive()
654 const QString file = QFileDialog::getOpenFileName(lastdir,
655 "Archives (" + ImgArchiveSink::supportedOpenExtensions() + ");;All files (*)",
656 this, NULL, tr("Choose a file") );
661 void ComicMainWindow::open(const QString &path, int page)
663 const QFileInfo f(path);
664 const QString fullname = f.absFilePath();
666 if (sink && sink->getFullName() == fullname) //trying to open same dir?
669 lastdir = f.dirPath(true);
674 ImlibImage::setCacheSize(cfg->cacheSize()*1024*1024);
676 sink = ImgSinkFactory::instance().createImgSink(path);
677 sink->thumbnailLoader().setReciever(thumbswin);
678 sink->thumbnailLoader().setUseCache(cfg->cacheThumbnails());
680 connect(sink, SIGNAL(sinkReady(const QString&)), this, SLOT(sinkReady(const QString&)));
681 connect(sink, SIGNAL(sinkError(int)), this, SLOT(sinkError(int)));
682 connect(sink, SIGNAL(progress(int, int)), statusbar, SLOT(setProgress(int, int)));
684 statusbar->setShown(true); //ensures status bar is visible when opening regardless of user settings
686 sink->open(fullname);
689 void ComicMainWindow::openNext()
691 if (sink && sink->supportsNext())
693 QString fname = sink->getNext();
694 if (!fname.isEmpty())
699 void ComicMainWindow::openPrevious()
701 if (sink && sink->supportsNext())
703 QString fname = sink->getPrevious();
704 if (!fname.isEmpty())
709 void ComicMainWindow::toggleFullScreen()
717 if (cfg->fullScreenHideMenu())
719 if (cfg->fullScreenHideStatusbar())
721 /*if (cfg->fullScreenHideToolbar())
727 void ComicMainWindow::exitFullscreen()
732 if (toggleStatusbarAction->isOn())
734 /*if (toggleToolbarAction->isOn())
740 void ComicMainWindow::nextPage()
744 int savedpage = currpage;
747 jumpToPage(nextpage);
751 if (!spreading && twoPagesAction->isOn() && cfg->twoPagesStep())
753 if (currpage < sink->numOfImages() - 2) //do not change pages if last two pages are visible
754 jumpToPage(currpage + 2);
758 jumpToPage(currpage + 1);
761 if (currpage != savedpage)
762 prevpage = savedpage;
766 void ComicMainWindow::prevPage()
769 jumpToPage(prevpage);
771 if (!spreading && twoPagesAction->isOn() && cfg->twoPagesStep())
772 jumpToPage(currpage - 2);
774 jumpToPage(currpage - 1);
777 void ComicMainWindow::prevPageBottom()
782 view->scrollToBottom();
786 void ComicMainWindow::firstPage()
791 void ComicMainWindow::lastPage()
794 jumpToPage(sink->numOfImages() - (twoPagesAction->isOn() && cfg->twoPagesStep() ? 2 : 1));
797 void ComicMainWindow::forwardPages()
799 jumpToPage(currpage + 5*(nextpage-currpage));
802 void ComicMainWindow::backwardPages()
804 jumpToPage(currpage - 5*(nextpage-currpage));
807 void ComicMainWindow::jumpToPage(int n, bool force)
811 if (n >= sink->numOfImages())
812 n = sink->numOfImages()-1;
815 if ((n != currpage) || force)
818 int result1, result2;
819 ImlibImage *img1, *img2;
820 ImlibImageList list[2];
822 const bool preserveangle = togglePreserveRotationAction->isOn();
824 img1 = sink->getImage(currpage = n, result1);
826 if (img1->getFormat() == STRIP_FORMAT && stripModeAction->isOn())
828 nextpage = buildStripList(n, img1, list, twoPagesAction->isOn());
829 jumpToStrip(n, list, twoPagesAction->isOn());
833 if (twoPagesAction->isOn())
835 img2 = sink->getImage(currpage + (++page_off), result2);
837 if (result2 == 0 && img2->getFormat() == STRIP_FORMAT && stripModeAction->isOn()) {
838 list[0].append(img1);
839 nextpage = buildStripList(currpage+page_off, img2, &(list[1]), false);
840 jumpToStrip(n, list, true);
844 if (img1->getFormat() == SPREAD_FORMAT)
854 // Ignore spreads as second pages
855 // Showing the next page or not showing any page
856 // should be an option because some sinks have the spread
857 // between the left and right page, while others have the
858 // spread but not the single pages, and there is no way simple way
861 // For the moment we just use the "stop at spread"
864 while (result2 == 0 && img2->getFormat() == SPREAD_FORMAT)
867 img2 = sink->getImage(currpage + (++page_off), result2);
872 if (result2 == 0 && img2->getFormat() == SPREAD_FORMAT)
881 if (mangaModeAction->isOn())
883 view->setImage(img2, img1, preserveangle);
884 statusbar->setImageInfo(img2, img1);
888 view->setImage(img1, img2, preserveangle);
889 statusbar->setImageInfo(img1, img2);
894 view->setImage(img1, preserveangle);
895 statusbar->setImageInfo(img1);
896 if (cfg->preloadPages())
897 sink->preload(currpage + 1);
902 view->setImage(img1, preserveangle);
903 statusbar->setImageInfo(img1);
905 if (mangaModeAction->isOn())
906 view->ensureVisible(view->imageWidth(), 0);
907 const QString page = tr("Page") + " " + QString::number(currpage + 1) + "/" + QString::number(sink->numOfImages());
908 pageinfo->setText(page);
909 statusbar->setPage(currpage + 1, sink->numOfImages());
910 thumbswin->view()->scrollToPage(currpage);
911 if (cfg->preloadPages())
913 if (!twoPagesAction->isOn())
915 sink->preload(currpage + 1);
919 sink->preload(currpage + 3);
920 sink->preload(currpage + 2);
923 nextpage = currpage + (++page_off);
927 int ComicMainWindow::buildStripList(int n, ImlibImage *img1, ImlibImageList *list, bool twoPages)
934 list[0].append(img1);
936 img2 = sink->getImage(n + (++page_off), result2) ;
937 while (result2 == 0 && img2->getFormat() == STRIP_FORMAT && list[0].count() < STRIP_MAX) {
938 list[0].append(img2) ;
939 img2 = sink->getImage(n + (++page_off), result2) ;
942 // If we are displaying two pages, start filling the second side
943 if (twoPages && result2 == 0)
945 list[1].append(img2) ;
946 // ... which is a strip collection if the first strip is a strip
947 if (img2->getFormat() == STRIP_FORMAT)
949 img2 = sink->getImage(n + (++page_off), result2) ;
950 while (result2 == 0 && img2->getFormat() == STRIP_FORMAT && list[1].count() < STRIP_MAX) {
951 list[1].append(img2) ;
952 img2 = sink->getImage(n + (++page_off), result2) ;
957 return (n + page_off);
960 void ComicMainWindow::jumpToStrip(int n, ImlibImageList *list, bool twoPages)
962 const bool preserveangle = togglePreserveRotationAction->isOn();
965 ImlibImage *img1, *img2;
967 img1 = list[0].at(0);
971 img2 = list[1].at(0);
972 if (mangaModeAction->isOn())
974 view->setImage(list[1], list[0], preserveangle);
975 statusbar->setImageInfo(img2, img1);
979 view->setImage(list[0], list[1], preserveangle);
980 statusbar->setImageInfo(img1, img2);
985 view->setImage(list[0], preserveangle);
986 statusbar->setImageInfo(img1);
988 if (mangaModeAction->isOn())
989 view->ensureVisible(view->imageWidth(), 0);
990 const QString page = tr("Page") + " " + QString::number(currpage + 1) + "/" + QString::number(sink->numOfImages());
991 pageinfo->setText(page);
992 statusbar->setPage(currpage + 1, sink->numOfImages());
993 thumbswin->view()->scrollToPage(currpage);
996 void ComicMainWindow::showInfo()
1000 ComicBookInfo *i = new ComicBookInfo(this, *sink, cfg->infoFont());
1005 void ComicMainWindow::showSysInfo()
1007 SupportedArchivesWindow *win = new SupportedArchivesWindow(this);
1011 void ComicMainWindow::createArchive()
1015 ArchiverDialog *win = new ArchiverDialog(this, sink);
1021 void ComicMainWindow::showAbout()
1023 AboutDialog *win = new AboutDialog(this, "About QComicBook",
1024 "QComicBook " VERSION " - comic book viewer for GNU/Linux\n"
1025 "(c)by Pawel Stolowski 2005-2006\n"
1026 "released under terms of GNU General Public License\n\n"
1027 "http://linux.bydg.org/~yogin\n"
1028 "pawel.stolowski@wp.pl", QPixmap(DATADIR "qcomicbook-splash.png"));
1032 void ComicMainWindow::showHelp()
1034 const QString helpdir = HelpBrowser::getLocaleHelpDir(DATADIR "/help");
1035 if (!cfg->useInternalBrowser() && cfg->externalBrowser() != QString::null)
1037 QProcess *proc = new QProcess(this);
1038 proc->addArgument(cfg->externalBrowser());
1039 proc->addArgument(helpdir + "/index.html");
1040 connect(proc, SIGNAL(processExited()), proc, SLOT(deleteLater()));
1043 proc->deleteLater();
1044 cfg->useInternalBrowser(true);
1047 if (cfg->useInternalBrowser())
1049 HelpBrowser *help = new HelpBrowser(tr("QComicBook Help"), helpdir);
1054 void ComicMainWindow::showConfigDialog()
1056 ComicBookCfgDialog *d = new ComicBookCfgDialog(this, cfg);
1060 void ComicMainWindow::showJumpToPage(const QString &number)
1064 JumpToPageWindow *win = new JumpToPageWindow(this, number.toInt(), sink->numOfImages());
1065 connect(win, SIGNAL(pageSelected(int)), this, SLOT(jumpToPage(int)));
1070 void ComicMainWindow::closeSink()
1072 enableComicBookActions(false);
1076 /*if (typeid(*sink) == typeid(ImgArchiveSink) && cfg->editSupport() && sink->hasModifiedFiles())
1078 if (QMessageBox::warning(this, tr("Create archive?"),
1079 tr("Warning! Some files were modified in this comic book\nDo you want to create new archive file?"),
1080 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
1082 ArchiverDialog *win = new ArchiverDialog(this, sink);
1088 sink->deleteLater();
1092 thumbswin->view()->clear();
1097 void ComicMainWindow::setBookmark()
1100 bookmarks->set(sink->getFullName(), currpage);
1103 void ComicMainWindow::removeBookmark()
1105 if (sink && bookmarks->exists(sink->getFullName()) && QMessageBox::question(this, tr("Removing bookmark"),
1106 tr("Do you really want to remove bookmark\nfor this comic book?"),
1107 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
1108 bookmarks->remove(sink->getFullName());
1111 void ComicMainWindow::openBookmarksManager()
1113 BookmarkManager *win = new BookmarkManager(this, bookmarks);
1117 void ComicMainWindow::openWithGimp()
1121 QProcess *proc = new QProcess(this);
1122 proc->addArgument("gimp-remote");
1123 proc->addArgument(sink->getFullFileName(currpage));
1124 connect(proc, SIGNAL(processExited()), proc, SLOT(deleteLater()));
1127 proc->deleteLater();
1131 void ComicMainWindow::bookmarkSelected(int id)
1134 if (bookmarks->get(id, b))
1136 if (b.getName() != QString::null)
1138 QString fname = b.getName();
1139 if (sink && fname == sink->getFullName()) //is this comicbook already opened?
1141 jumpToPage(b.getPage(), true); //if so, just jump to bookmarked page
1145 QFileInfo finfo(fname);
1146 if (!finfo.exists())
1148 if (QMessageBox::question(this, tr("Comic book not found"),
1149 tr("Selected bookmark points to\nnon-existing comic book\nDo you want to remove it?"),
1150 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
1151 bookmarks->remove(id);
1154 open(fname, b.getPage());
1159 void ComicMainWindow::saveSettings()
1161 cfg->geometry(frameGeometry());
1162 cfg->saveDockLayout(this);
1163 cfg->scrollbarsVisible(settings_menu->isItemChecked(scrv_id));
1164 cfg->twoPagesMode(twoPagesAction->isOn());
1165 cfg->stripMode(stripModeAction->isOn());
1166 cfg->japaneseMode(mangaModeAction->isOn());
1167 cfg->continuousScrolling(navi_menu->isItemChecked(contscr_id));
1168 cfg->lastDir(lastdir);
1169 cfg->recentlyOpened(*recentfiles);
1170 cfg->pageSize(view->getSize());
1171 cfg->showStatusbar(toggleStatusbarAction->isOn());