Commit edbca605 authored by denis's avatar denis

Merge branches 'master' and 'master' of github.com:victor-yacovlev/kumir2

parents d0804c99 4cb45b2b
#include "errormessages.h"
#include <kumir2-libs/extensionsystem/pluginmanager.h>
#include <kumir2-libs/extensionsystem/kplugin.h>
#include <QtCore>
......@@ -44,10 +45,12 @@ QStringList ErrorMessages::readCSVRow(const QString &line)
return result;
}
bool ErrorMessages::loadMessages(const QString &plugin)
bool ErrorMessages::loadMessages(const QByteArray &pluginName)
{
const QString fileName = ExtensionSystem::PluginManager::instance()->sharePath() +
+ "/" + plugin.toLower() + "/messages.csv";
ExtensionSystem::KPlugin* kPlugin = ExtensionSystem::PluginManager::instance()->loadedPlugin(pluginName);
const QString fileName = kPlugin->myResourcesDir().absoluteFilePath("messages.csv");
// const QString fileName = ExtensionSystem::PluginManager::instance()->sharePath() +
// + "/" + pluginName.toLower() + "/messages.csv";
QFile f(fileName);
if (f.open(QIODevice::ReadOnly|QIODevice::Text)) {
......@@ -58,7 +61,7 @@ bool ErrorMessages::loadMessages(const QString &plugin)
QList<Context> contexts;
for (int i=0; i<languages.size(); i++) {
QLocale loc(languages[i]);
contexts << Context(plugin,loc.language());
contexts << Context(pluginName,loc.language());
}
if (contexts.isEmpty()) {
qWarning() << fileName+": file data is empty or not valid CSV-file";
......@@ -88,11 +91,11 @@ bool ErrorMessages::loadMessages(const QString &plugin)
return true;
}
QString ErrorMessages::message(const QString &plugin
QString ErrorMessages::message(const QByteArray &pluginName
, const QLocale::Language &language
, const QString &key)
{
Context context(plugin, language);
Context context(pluginName, language);
static QRegExp arg1("\\\\1=\\{(\\S*)\\}");
arg1.setMinimal(true);
static QRegExp arg2("\\\\2=\\{(\\S*)\\}");
......
......@@ -42,14 +42,14 @@ inline QString _(const char * x, const QString &a, const QString &b, const QStri
class EM_EXPORT ErrorMessages {
public:
static bool loadMessages(const QString &plugin);
static bool loadMessages(const QByteArray &pluginName);
static QString message(const QString &plugin
static QString message(const QByteArray &pluginName
, const QLocale::Language &language
, const QString &key);
private:
static QStringList readCSVRow(const QString &line);
typedef QPair<QString,QLocale::Language> Context;
typedef QPair<QByteArray,QLocale::Language> Context;
typedef QHash<QString,QString> Database;
static QMap<Context, Database> database;
};
......
......@@ -35,7 +35,7 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTextBrowser" name="licenseTextBrowser">
<widget class="Widgets::Utf8TextBrowser" name="licenseTextBrowser">
<property name="html">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
......
......@@ -2,6 +2,8 @@
#include "plugin.h"
#include "mainwindow.h"
#include "ui_defaultstartpage.h"
#include <kumir2-libs/extensionsystem/pluginmanager.h>
#include <kumir2/coursesinterface.h>
#include <QtCore>
#if QT_VERSION >= 0x050000
......@@ -20,6 +22,12 @@ CoreGUI::DefaultStartPage::DefaultStartPage(Plugin* plugin, MainWindow* mw, QWid
this->setObjectName("startPageRoot");
ui->setupUi(this);
CoursesInterface *cs =
ExtensionSystem::PluginManager::instance()->findPlugin<CoursesInterface>();
_coursesAvailable = 0 != cs;
ui->coursesBox->setVisible(_coursesAvailable);
relayoutBlocks(this->width());
ui->headerText->setText(_mainWindow->applicationTitle() + " " + _plugin->applicationVersionString());
......@@ -76,32 +84,45 @@ void CoreGUI::DefaultStartPage::relayoutBlocks(const int width)
static const int OneCol = 400;
static const int TwoCol = 780;
int columns = 3;
if (width < OneCol)
columns = 1;
else if (width < TwoCol)
columns = 2;
int columns;
int programsRow, programsColumn, coursesRow, coursesColumn, helpRow, helpColumn;
if (3 == columns) {
programsRow = coursesRow = helpRow = 0;
programsColumn = 0;
coursesColumn = 1;
helpColumn = 2;
}
else if (2 == columns) {
programsRow = coursesRow = 0;
helpRow = 1;
programsColumn = 0;
coursesColumn = 1;
helpColumn = 0;
if (_coursesAvailable) {
columns = 3;
if (width < OneCol) columns = 1;
else if (width < TwoCol) columns = 2;
if (3 == columns) {
programsRow = coursesRow = helpRow = 0;
programsColumn = 0;
coursesColumn = 1;
helpColumn = 2;
}
else if (2 == columns) {
programsRow = coursesRow = 0;
helpRow = 1;
programsColumn = 0;
coursesColumn = 1;
helpColumn = 0;
}
else if (1 == columns) {
programsColumn = coursesColumn = helpColumn = 0;
programsRow = 0;
coursesRow = 1;
helpRow = 2;
}
}
else if (1 == columns) {
programsColumn = coursesColumn = helpColumn = 0;
programsRow = 0;
coursesRow = 1;
helpRow = 2;
else {
columns = width < OneCol ? 1 : 2;
if (2 == columns) {
programsRow = helpRow = 0;
programsColumn = 0;
helpColumn = 1;
}
else {
programsRow = 0;
helpRow = 1;
programsColumn = helpColumn = 0;
}
}
ui->centralViewLayout->removeWidget(ui->programsBox);
......@@ -109,7 +130,9 @@ void CoreGUI::DefaultStartPage::relayoutBlocks(const int width)
ui->centralViewLayout->removeWidget(ui->headerBox);
ui->centralViewLayout->addWidget(ui->programsBox, programsRow, programsColumn, 1, 1);
ui->centralViewLayout->addWidget(ui->coursesBox, coursesRow, coursesColumn, 1, 1);
if (_coursesAvailable) {
ui->centralViewLayout->addWidget(ui->coursesBox, coursesRow, coursesColumn, 1, 1);
}
ui->centralViewLayout->addWidget(ui->helpBox, helpRow, helpColumn, 1, 1);
updateContents();
......@@ -117,8 +140,10 @@ void CoreGUI::DefaultStartPage::relayoutBlocks(const int width)
void CoreGUI::DefaultStartPage::updateContents()
{
updateRecentFiles();
updateRecentCourses();
updateRecentFiles();
if (_coursesAvailable) {
updateRecentCourses();
}
updateHelp();
}
......
......@@ -54,6 +54,7 @@ protected Q_SLOTS:
protected /*fields*/:
Plugin* _plugin;
MainWindow* _mainWindow;
bool _coursesAvailable;
Ui::DefaultStartPage * ui;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment