Commit e41fc357 authored by Victor Yacovlev's avatar Victor Yacovlev

kumir2-open: implemented settings

parent a6901c3d
......@@ -423,7 +423,7 @@ Right click to navigate target</source>
<name>CoreGUI::MainWindow</name>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.ui" line="14"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="523"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="525"/>
<source>Kumir</source>
<translation>Кумир</translation>
</message>
......@@ -506,10 +506,10 @@ Right click to navigate target</source>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.ui" line="147"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="805"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1205"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1305"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1447"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="807"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1211"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1311"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1453"/>
<source>Save</source>
<translation>Сохранить программу</translation>
</message>
......@@ -618,14 +618,14 @@ Right click to navigate target</source>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.ui" line="227"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1144"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1150"/>
<source>Restore previous session</source>
<translation>Восстановить предыдущий сеанс</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="122"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="129"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="136"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="124"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="131"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="138"/>
<source>No actions for this tab</source>
<translation>Для этой вкладки нет действий</translation>
</message>
......@@ -658,81 +658,85 @@ Right click to navigate target</source>
<translation type="obsolete">Новый текст</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="721"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1334"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1340"/>
<source>%1 programs (*%2)</source>
<translation>Программы %1 (*%2)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="724"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1337"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="726"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1343"/>
<source>Text files (*.txt)</source>
<translation>Текстовые файлы (*.txt)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="726"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1339"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="723"/>
<source>%1 programs (*.%2)</source>
<translation>Программы %1 (*.%2)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="728"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1345"/>
<source>All files (*)</source>
<translation>Все файлы (*)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="727"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="729"/>
<source>Save file</source>
<translation>Сохранить файл</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="754"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="756"/>
<source>Can&apos;t save file</source>
<translation>Не могу сохранить файл</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="799"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="801"/>
<source>Close editor</source>
<translation>Закрытие текста</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="800"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1300"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1442"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="802"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1306"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1448"/>
<source>Save current text?</source>
<translation>Сохранить текущий текст?</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="807"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1207"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1307"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1449"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="809"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1213"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1313"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1455"/>
<source>Don&apos;t save</source>
<translation>Не сохранять</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="809"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1209"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="811"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1215"/>
<source>Cancel closing</source>
<translation>Отменить закрытие</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="852"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="854"/>
<source>Preferences</source>
<translation>Настройки</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1145"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1151"/>
<source>Are you sure to restore previous session? All unsaved changes will be lost.</source>
<translation>Вы уверены, что хотите восстановить предыдущий сеанс? Все открытые файлы будут закрыты без сохранения.</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1149"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1155"/>
<source>Yes</source>
<translation>Да</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1150"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1156"/>
<source>No</source>
<translation>Нет</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1196"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1202"/>
<source>The following files have changes:
%1
Save them?</source>
......@@ -741,29 +745,29 @@ Save them?</source>
Сохранить их?</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1199"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1205"/>
<source>Close Kumir</source>
<translation>Выход из Кумир</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1299"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1441"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1305"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1447"/>
<source>Open another file</source>
<translation>Открытие другого файла</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1309"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1451"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1315"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1457"/>
<source>Cancel opening another file</source>
<translation>Не открывать другой файл</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1336"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1342"/>
<source>Web pages (*.html *.htm)</source>
<translation>Web-страницы (*.html *.htm)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1510"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1516"/>
<source>Can&apos;t open file</source>
<translation>Не могу открыть файл</translation>
</message>
......@@ -802,7 +806,7 @@ Using Qt version %2</source>
Использует Qt версии %2</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1343"/>
<location filename="../../../src/plugins/coregui/mainwindow.cpp" line="1349"/>
<source>Load file...</source>
<translation>Загрузить файл...</translation>
</message>
......@@ -829,45 +833,55 @@ Using Qt version %2</source>
<translation type="obsolete">Область ввода/вывода</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="367"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="400"/>
<source>Variables</source>
<translation>Значения величин</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="302"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="313"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="335"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="346"/>
<source>Remote Control</source>
<translation>Пульт</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="98"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="63"/>
<source>PROGRAM.kum</source>
<translation>ПРОГРАММА.kum</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="64"/>
<source>Source file name</source>
<translation>Имя файла</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="131"/>
<source>Input/Output</source>
<translation>Ввод/вывод</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="123"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="156"/>
<source>Save console output</source>
<translation>Сохранить вывод</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="134"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="167"/>
<source>Copy to clipboard console output</source>
<translation>Скопировать вывод в буфер обмена</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="188"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="221"/>
<source>Help</source>
<translation>Справка</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="211"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="221"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="244"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="254"/>
<source>Courses</source>
<translation>Практикум</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="339"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="340"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="372"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="373"/>
<source>No actions for this tab</source>
<translation>Для этой вкладки нет действий</translation>
</message>
......@@ -888,7 +902,7 @@ Using Qt version %2</source>
<translation type="obsolete">Пауза</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="344"/>
<location filename="../../../src/plugins/coregui/plugin.cpp" line="377"/>
<source>Start</source>
<translation>Начало</translation>
</message>
......@@ -1082,6 +1096,24 @@ p, li { white-space: pre-wrap; }
<translation>Выбор рабочего каталога</translation>
</message>
</context>
<context>
<name>CoreGUI::SystemOpenFileSettings</name>
<message>
<location filename="../../../src/plugins/coregui/systemopenfilesettings.ui" line="14"/>
<source>File Open</source>
<translation>Открытие файлов</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/systemopenfilesettings.ui" line="20"/>
<source>Open .kum file by system in:</source>
<translation>Открывать файлы &quot;*.kum&quot; в:</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/systemopenfilesettings.cpp" line="26"/>
<source>Choose on run</source>
<translation>Спросить при запуске</translation>
</message>
</context>
<context>
<name>CoreGUI::TabBar</name>
<message>
......@@ -1101,17 +1133,17 @@ p, li { white-space: pre-wrap; }
<context>
<name>CoreGUI::TabWidgetElement</name>
<message>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="117"/>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="131"/>
<source>%1 (Course)</source>
<translation>%1 (Практикум)</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="122"/>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="136"/>
<source>New Program</source>
<translation>Новая программа</translation>
</message>
<message>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="125"/>
<location filename="../../../src/plugins/coregui/tabwidgetelement.cpp" line="139"/>
<source>New Text</source>
<translation>Новый текст</translation>
</message>
......
......@@ -19,6 +19,7 @@ set(SOURCES
debuggerview.cpp
row.cpp
switchworkspacedialog.cpp
systemopenfilesettings.cpp
)
set(EXTRA_LIBS
......@@ -47,12 +48,14 @@ set(MOC_HEADERS
debuggerview.h
row.h
switchworkspacedialog.h
systemopenfilesettings.h
)
set(FORMS
mainwindow.ui
aboutdialog.ui
switchworkspacedialog.ui
systemopenfilesettings.ui
)
set(RESOURCES
......
......@@ -8,6 +8,7 @@
#include "dataformats/kumfile.h"
#include "statusbar.h"
#include "tabwidget.h"
#include "systemopenfilesettings.h"
#include <algorithm>
#include <QSharedPointer>
......@@ -860,6 +861,10 @@ void MainWindow::createSettingsDialog()
settingsDialog_->addPage(page);
}
}
#ifndef Q_OS_MACX
SystemOpenFileSettings * openFileSettings = new SystemOpenFileSettings;
settingsDialog_->addPage(openFileSettings);
#endif
}
void MainWindow::showPreferences()
......
......@@ -441,12 +441,10 @@ void Plugin::handleExternalProcessCommand(const QString &command)
}
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACX)
void Plugin::handleSIGUSR1(int signal, siginfo_t * info, void * )
void Plugin::handleSIGUSR1(int , siginfo_t * info, void * )
{
sigval_t val = info->si_value;
qDebug() << "Received signal " << signal;
qDebug() << "Data available at port: " << val.sival_int;
::sleep(1);
::usleep(1000u);
int sock = socket(AF_INET, SOCK_STREAM, 0);
sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
......@@ -466,9 +464,7 @@ void Plugin::handleSIGUSR1(int signal, siginfo_t * info, void * )
data += block;
}
const QString message = QString::fromUtf8(data);
qDebug() << "Received message: " << message;
emit instance_->externalProcessCommandReceived(message);
}
#endif
......
#include "systemopenfilesettings.h"
#include "ui_systemopenfilesettings.h"
#include <QDir>
#include <QFileInfo>
#include <QTextStream>
#include <QRadioButton>
#include <QSpacerItem>
namespace CoreGUI {
SystemOpenFileSettings::SystemOpenFileSettings(QWidget *parent) :
QWidget(parent),
ui(new Ui::SystemOpenFileSettings)
{
ui->setupUi(this);
const QString appsDir =
QDir::cleanPath(QApplication::applicationDirPath() +
"/../share/applications");
const QString iconsDir =
QDir::cleanPath(QApplication::applicationDirPath() +
"/../share/icons/hicolor");
scanForApplications(appsDir, iconsDir);
chooseAtRunOption_ = new QRadioButton(tr("Choose on run"), this);
ui->groupBox->layout()->addWidget(chooseAtRunOption_);
ui->groupBox->layout()->addItem(new QSpacerItem(10, 10, QSizePolicy::Fixed, QSizePolicy::Fixed));
foreach (const Application & app, applications_) {
ui->groupBox->layout()->addWidget(app.button);
}
ui->groupBox->layout()->addItem(new QSpacerItem(10, 50, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding));
sett_ = new QSettings("kumir2", "kumir2-open");
sett_->setIniCodec("UTF-8");
}
void SystemOpenFileSettings::init()
{
const bool skipDialog = sett_->value("SkipOpenDialog", false).toBool();
const QString lastKey = sett_->value("LastSelected", "").toString();
QRadioButton * btn = chooseAtRunOption_;
if (skipDialog && lastKey.length() > 0) {
foreach (const Application & app, applications_) {
if (app.key == lastKey) {
btn = app.button;
break;
}
}
}
btn->setChecked(true);
}
void SystemOpenFileSettings::accept()
{
if (chooseAtRunOption_->isChecked()) {
sett_->setValue("SkipOpenDialog", false);
}
else {
sett_->setValue("SkipOpenDialog", true);
foreach (const Application & app, applications_) {
if (app.button->isChecked()) {
sett_->setValue("LastSelected", app.key);
break;
}
}
}
}
void SystemOpenFileSettings::scanForApplications(const QString &appsDirPath,
const QString &iconsDirPath)
{
QDir appsDir(appsDirPath);
QDir iconsDir(iconsDirPath);
QStringList files = appsDir.entryList(QStringList() << "kumir2-*.desktop");
foreach (const QString & fileName, files) {
QFile f(appsDir.absoluteFilePath(fileName));
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream ts(&f);
QStringList lines = ts.readAll().split("\n");
f.close();
Application app;
bool isApp = false;
foreach (const QString & line, lines) {
int eqPos = line.indexOf('=');
if (eqPos != -1) {
const QString key = line.left(eqPos).trimmed().toLower();
const QString value = line.mid(eqPos + 1).trimmed();
if (key == "type") {
isApp = value.toLower() == "application";
}
else if (key.startsWith("name")) {
if (app.name.isEmpty() || key=="name[ru]") {
app.name = value;
}
}
else if (key == "icon") {
const QString iconFileName =
iconsDir.absoluteFilePath(
QString("32x32/apps/%1.png").arg(value)
);
app.icon = QIcon(iconFileName);
}
else if (key == "exec") {
QString executableFileName;
QString cleanName = value;
int spacePos = cleanName.indexOf(' ');
if (spacePos != -1) {
cleanName = cleanName.left(spacePos);
}
executableFileName =
QDir::cleanPath(
QApplication::applicationDirPath() +
"/" + cleanName
);
#ifdef Q_OS_WIN32
executableFileName += ".exe";
#endif
app.key = QFileInfo(executableFileName).baseName();
}
}
}
if (isApp) {
applications_.push_back(app);
}
}
}
for (int i=0 ; i<applications_.size(); i++) {
Application & app = applications_[i];
app.button = new QRadioButton(app.name, this);
}
}
SystemOpenFileSettings::~SystemOpenFileSettings()
{
delete ui;
}
} // namespace CoreGUI
#ifndef COREGUI_SYSTEMOPENFILESETTINGS_H
#define COREGUI_SYSTEMOPENFILESETTINGS_H
#include <QWidget>
#include <QIcon>
#include <QRadioButton>
#include <QSettings>
namespace CoreGUI {
namespace Ui {
class SystemOpenFileSettings;
}
class SystemOpenFileSettings : public QWidget
{
Q_OBJECT
public:
explicit SystemOpenFileSettings(QWidget *parent = 0);
~SystemOpenFileSettings();
public slots:
void init();
void accept();
private:
struct Application {
QString key;
QString name;
QIcon icon;
QRadioButton * button;
};
void scanForApplications(const QString & appsDir, const QString & iconsDir);
QList<Application> applications_;
Ui::SystemOpenFileSettings *ui;
QRadioButton *chooseAtRunOption_;
QSettings * sett_;
};
} // namespace CoreGUI
#endif // COREGUI_SYSTEMOPENFILESETTINGS_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CoreGUI::SystemOpenFileSettings</class>