updateImageSize() now takes the whole ImlibImageList into consideration
[qcomicbook-oblomov] / src / helpbrowser.cpp
1 /*
2  * This file is a part of QComicBook.
3  *
4  * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
5  *
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.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY. See GPL for more details.
11  */
12
13 #include "helpbrowser.h"
14 #include <qtextbrowser.h>
15 #include <qtextcodec.h>
16 #include <qfileinfo.h>
17 #include <qpopupmenu.h>
18 #include <qmenubar.h>
19
20 using namespace QComicBook;
21
22 HelpBrowser::HelpBrowser(const QString &caption, const QString &path, const QString &file, const QString &imgpath, QWidget *parent): QMainWindow(parent)
23 {
24         setCaption(caption);
25         txtb = new QTextBrowser(this);
26         setCentralWidget(txtb);
27
28         QStringList fpaths;
29         fpaths.append(path);
30         //if (!imgpath.isEmpty())
31         //      fpaths.append(path + "/" + imgpath); //append common images subdirectory
32         txtb->mimeSourceFactory()->setFilePath(fpaths);
33         txtb->setSource(file);
34
35         //
36         // menu
37         QPopupMenu *file_menu = new QPopupMenu(this);
38         file_menu->insertItem(tr("Quit"), this, SLOT(close()));
39         menuBar()->insertItem(tr("File"), file_menu);
40         go_menu = new QPopupMenu(this);
41         go_menu->insertItem(tr("Table of contents"), txtb, SLOT(home()));
42         go_menu->insertSeparator();
43         id_back = go_menu->insertItem(tr("Back"), txtb, SLOT(backward()));
44         id_forward = go_menu->insertItem(tr("Forward"), txtb, SLOT(forward()));
45         menuBar()->insertItem(tr("Go"), go_menu);
46
47         enableBackward(false);
48         enableForward(false);
49         
50         connect(txtb, SIGNAL(backwardAvailable(bool)), this, SLOT(enableBackward(bool)));
51         connect(txtb, SIGNAL(forwardAvailable(bool)), this, SLOT(enableForward(bool)));
52
53         resize(640, 480);
54 }
55
56 HelpBrowser::~HelpBrowser()
57 {
58 }
59
60 void HelpBrowser::enableBackward(bool f)
61 {
62         go_menu->setItemEnabled(id_back, f);
63 }
64
65 void HelpBrowser::enableForward(bool f)
66 {
67         go_menu->setItemEnabled(id_forward, f);
68 }
69
70 QString HelpBrowser::getLocaleHelpDir(const QString &maindir, const QString &file)
71 {
72         const QString locale = QTextCodec::locale();
73         const QString paths[] = { maindir + "/" + locale,
74                                   maindir + "/" + locale.left(4),
75                                   maindir + "/" + locale.left(2),
76                                   maindir + "/en" };
77         //
78         // try to find translated help first according to locale setting; fallback to en
79         for (int i=0; i<4; i++)
80         {
81                 QFileInfo f(paths[i] + "/" + file);
82                 if (f.exists())
83                         return f.absFilePath();
84         }
85         return QString::null;
86 }
87