Display scrollbar in helpwindow
[qcpufreq] / src / helpwindow.cpp
1 /*
2  * QCPUFreq - a simple cpufreq GUI
3  * Copyright (C) 2010 Daniel Klaffenbach <danielklaffenbach@gmail.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "helpwindow.h"
20 #include "ui_helpwindow.h"
21
22 #include <QFile>
23 #include <QLocale>
24 #include <QTextStream>
25 #include <QMessageBox>
26
27
28 HelpWindow::HelpWindow(QWidget *parent) :
29     QWidget(parent),
30     ui(new Ui::HelpWindow)
31 {
32     ui->setupUi(this);
33
34     setHelpText();
35 }
36
37
38 HelpWindow::~HelpWindow()
39 {
40     delete ui;
41 }
42
43
44 /**
45   * Assigns the help text to the QTextEdit
46   */
47 void HelpWindow::setHelpText()
48 {
49     //get the current locale name for lacalized help messages
50     QString locale = QLocale::system().name();
51     QStringList tmp = locale.split("_");
52     locale = tmp.first();
53
54     //open help text
55     QFile help( ":/txt/help_" + locale );
56
57     //open the file
58     if ( !help.exists() || !help.open( QIODevice::ReadOnly ) ) {
59         //try to open the file in english language instead
60         help.setFileName(":/txt/help_en");
61         if ( !help.exists() || !help.open( QIODevice::ReadOnly ) ) {
62             QMessageBox::critical(this, tr("QCPUFreq"), tr("Cannot open help file!"));
63             return;
64         }
65     }
66
67     //read the file
68     QTextStream in( &help );
69     QString txt;
70     do {
71         txt += in.readLine();
72         txt += "\n";
73     } while ( !in.atEnd() );
74
75     ui->textBrowser->setText( txt );
76 }