Initial help window support, show sudo errors.
[qcpufreq] / src / helpwindow.cpp
1 #include "helpwindow.h"
2 #include "ui_helpwindow.h"
3
4 #include <QFile>
5 #include <QLocale>
6 #include <QTextStream>
7 #include <QMessageBox>
8
9 HelpWindow::HelpWindow(QWidget *parent) :
10     QWidget(parent),
11     ui(new Ui::HelpWindow)
12 {
13     //this is a stacked window on Maemo 5
14     #if defined(Q_WS_MAEMO_5)
15         //setAttribute(Qt::WA_Maemo5StackedWindow);
16     #endif
17     ui->setupUi(this);
18
19     setHelpText();
20
21 }
22
23 HelpWindow::~HelpWindow()
24 {
25     delete ui;
26 }
27
28
29 /**
30   * Assigns the help text to the QTextEdit
31   */
32 void HelpWindow::setHelpText()
33 {
34     //get the current locale name for lacalized help messages
35     QString locale = QLocale::system().name();
36
37     //open help text
38     QFile help( ":/txt/help_" + locale );
39
40     //open the file
41     if ( !help.exists() || !help.open( QIODevice::ReadOnly ) ) {
42         //try to open the file in english language instead
43         help.setFileName(":/txt/help_en");
44         if ( !help.exists() || !help.open( QIODevice::ReadOnly ) ) {
45             QMessageBox::critical(this, tr("QCPUFreq"), tr("Cannot open help file!"));
46             return;
47         }
48     }
49
50     //read the file
51     QTextStream in( &help );
52     QString txt;
53     do {
54         txt += in.readLine();
55         txt += "\n";
56     } while ( !in.atEnd() );
57
58     ui->textEdit->setText( txt );
59 }