aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwi <william.os4y@gmail.com>2015-04-12 21:59:39 +0200
committerwi <william.os4y@gmail.com>2015-04-12 21:59:39 +0200
commit64f8f190c27f5880982353a7dac57b92793090b1 (patch)
tree4b201a9794f15ed6d7ed57868576aca4f1bcb573
parenthave a config directory to store templates (diff)
downloadlumina-64f8f190c27f5880982353a7dac57b92793090b1.tar.gz
lumina-64f8f190c27f5880982353a7dac57b92793090b1.tar.bz2
lumina-64f8f190c27f5880982353a7dac57b92793090b1.zip
refactring of lumina-fileinfo:
- detect if a field exist in different language and inform the user - add the inMemoryFile which contains the whole lines of the config. every modifications are stored in there and once the user click "apply" the whole content goes to disk - adapt the changes requested by the user in the inMemoryFile (no more when the user click on "Apply").
-rw-r--r--lumina-fileinfo/dialog.cpp159
-rw-r--r--lumina-fileinfo/dialog.h4
2 files changed, 96 insertions, 67 deletions
diff --git a/lumina-fileinfo/dialog.cpp b/lumina-fileinfo/dialog.cpp
index 30d80064..4b21e9cd 100644
--- a/lumina-fileinfo/dialog.cpp
+++ b/lumina-fileinfo/dialog.cpp
@@ -31,7 +31,6 @@ Dialog::Dialog(QWidget *parent) :
QFile::copy(":defaults/fileinfo-app.template", templateFile);
QFile(templateFile).setPermissions(QFileDevice::ReadUser|QFileDevice::WriteUser);
}
-
}
@@ -124,6 +123,14 @@ void Dialog::LoadDesktopFile(QString input)
QMessageBox::critical(this, tr("Error"), tr("Problem to read the desktop file called:") + desktopFileName );
exit(1);
}
+
+ //we load the file in memory and will adapt it before saving it to disk
+ QFile file(desktopFileName);
+ inMemoryFile="";
+ if (file.open(QFile::ReadWrite)) {
+ QTextStream fileData(&file);
+ inMemoryFile = fileData.readAll();
+ }
}
@@ -164,22 +171,9 @@ void Dialog::on_pbWorkingDir_clicked()
//we just change the required lines and we don't touch to the rest of the file and copy it back.
void Dialog::textReplace(QString &origin, QString from, QString to, QString topic)
{
- if (origin.contains(QRegExp("\n" + topic + "\\[\\S+\\]\\s*=",Qt::CaseInsensitive))) {
- QMessageBox msgBox;
- msgBox.setText(tr("By modifying this value, you will loose all translated versions"));
- msgBox.setInformativeText(tr("The field:") + topic + tr( "is translated in several other languages. If you want to continue, you will loose all translated versions"));
- msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
- int answer = msgBox.exec();
- if (answer==QMessageBox::Ok) {
- //remove all translated versions. The lang cannot be null, but the value can be.
- origin.replace(QRegExp("\n" + topic + "\\[\\S+\\]\\s*=[^\n]*",Qt::CaseInsensitive), "");
- }
- else return;
- }
- if (!from.isEmpty()) {
+ if (origin.contains(QRegExp("\n" + topic + "\\s*=\\s*" + from + "\n",Qt::CaseInsensitive))) {
origin.replace(QRegExp("\n" + topic + "\\s*=\\s*" + from + "\n",Qt::CaseInsensitive),"\n" + topic + "=" + to + "\n");
} else {
- //TODO: check if last char in \n. If not add it
origin.append(topic + "=" + to + "\n");
}
}
@@ -187,65 +181,62 @@ void Dialog::textReplace(QString &origin, QString from, QString to, QString topi
//we save the changes to the destination file
void Dialog::on_pbApply_clicked()
{
-
- QByteArray fileData;
- QFile file(desktopFileName);
- if (file.open(QFile::ReadWrite)) {
- QString from,to;
- fileData = file.readAll();
- QString text(fileData);
-
- QString desktopTypeVal="Application";
- if (DF.type == XDGDesktop::APP) { desktopTypeVal="Application"; }
- else if (DF.type == XDGDesktop::LINK) { desktopTypeVal="Link"; }
- else if (DF.type == XDGDesktop::DIR) { desktopTypeVal="Dir"; }
- textReplace(text, desktopTypeVal, desktopType, "Type");
+ QString from,to;
+ QString desktopTypeVal="Application";
+ if (DF.type == XDGDesktop::APP) { desktopTypeVal="Application"; }
+ else if (DF.type == XDGDesktop::LINK) { desktopTypeVal="Link"; }
+ else if (DF.type == XDGDesktop::DIR) { desktopTypeVal="Dir"; }
+ textReplace(inMemoryFile, desktopTypeVal, desktopType, "Type");
- if (ui->lName->isModified()) { textReplace(text, DF.name, ui->lName->text(), "Name");}
- if (ui->lComment->isModified()) { textReplace(text, DF.comment, ui->lComment->text(), "Comment");}
- if (ui->lCommand->isModified()) { textReplace(text, DF.exec, ui->lCommand->text(),"Exec");}
- if (desktopType=="link") {
- //incase of "link" layout WorkingDir is corresponding to the URL
- if (ui->lWorkingDir->isModified()) { textReplace(text, DF.url, ui->lWorkingDir->text(),"URL");}
- } else {
- if (ui->lWorkingDir->isModified()) { textReplace(text, DF.path, ui->lWorkingDir->text(),"Path");}
- }
- if (ui->cbStartupNotification->isChecked() != DF.startupNotify) {
- if (DF.startupNotify) {from="true"; to="false";} else {from="false"; to="true";}
- textReplace(text, from, to,"StartupNotify");
- }
- if (ui->cbRunInTerminal->isChecked() != DF.useTerminal) {
- if (DF.useTerminal) {from="true"; to="false";} else {from="false"; to="true";}
- textReplace(text, from, to,"Terminal");
- }
- if (!iconFileName.isEmpty()) {
- from=DF.icon;
- to=iconFileName;
- textReplace(text, from, to,"Icon");
- }
+ if (ui->lName->isModified()) { textReplace(inMemoryFile, DF.name, ui->lName->text(), "Name");}
+ if (ui->lComment->isModified()) { textReplace(inMemoryFile, DF.comment, ui->lComment->text(), "Comment");}
+ if (ui->lCommand->isModified()) { textReplace(inMemoryFile, DF.exec, ui->lCommand->text(),"Exec");}
+ if (desktopType=="link") {
+ //incase of "link" layout WorkingDir is corresponding to the URL
+ if (ui->lWorkingDir->isModified()) { textReplace(inMemoryFile, DF.url, ui->lWorkingDir->text(),"URL");}
+ } else {
+ if (ui->lWorkingDir->isModified()) { textReplace(inMemoryFile, DF.path, ui->lWorkingDir->text(),"Path");}
+ }
+ if (ui->cbStartupNotification->isChecked() != DF.startupNotify) {
+ if (DF.startupNotify) {from="true"; to="false";} else {from="false"; to="true";}
+ textReplace(inMemoryFile, from, to,"StartupNotify");
+ }
+ if (ui->cbRunInTerminal->isChecked() != DF.useTerminal) {
+ if (DF.useTerminal) {from="true"; to="false";} else {from="false"; to="true";}
+ textReplace(inMemoryFile, from, to,"Terminal");
+ }
+ if (!iconFileName.isEmpty()) {
+ from=DF.icon;
+ to=iconFileName;
+ textReplace(inMemoryFile, from, to,"Icon");
+ }
- file.seek(0);
- file.write(text.toUtf8());
+ QFile file(desktopFileName);
+ if (file.open(QFile::ReadWrite)) {
+ file.seek(0);
+ file.write(inMemoryFile.toUtf8());
- file.resize(file.pos());//remove possible trailing lines
+ file.resize(file.pos());//remove possible trailing lines
- file.close();
+ file.close();
+ } else {
+ //problem to write to the disk
+ }
- //hack required to update the icon on the desktop
- QTemporaryFile tempFile ;
- tempFile.setAutoRemove(false);
- tempFile.open();
- tempFile.close();
+ //hack required to update the icon on the desktop
+ QTemporaryFile tempFile ;
+ tempFile.setAutoRemove(false);
+ tempFile.open();
+ tempFile.close();
- //TODO: capture errors
- QString cmd = "mv";
- cmd = cmd + " " + desktopFileName + " " + tempFile.fileName();
- int ret = LUtils::runCmd(cmd);
+ //TODO: capture errors
+ QString cmd = "mv";
+ cmd = cmd + " " + desktopFileName + " " + tempFile.fileName();
+ int ret = LUtils::runCmd(cmd);
- cmd = "mv";
- cmd = cmd + " " + tempFile.fileName() + " " + desktopFileName;
- ret = LUtils::runCmd(cmd);
- }
+ cmd = "mv";
+ cmd = cmd + " " + tempFile.fileName() + " " + desktopFileName;
+ ret = LUtils::runCmd(cmd);
}
@@ -264,3 +255,37 @@ void Dialog::on_pbIcon_clicked()
iconFileName=fileName;
}
}
+
+void Dialog::on_lName_textChanged(QString text)
+{
+ if (text != DF.name && inMemoryFile.contains(QRegExp("\nName\\[\\S+\\]\\s*=",Qt::CaseInsensitive))) {
+ QMessageBox msgBox;
+ msgBox.setText(tr("By modifying this value, you will loose all translated versions"));
+ msgBox.setInformativeText(tr("The field: Name is translated in several other languages. If you want to continue, you will loose all translated versions"));
+ msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+ int answer = msgBox.exec();
+ if (answer==QMessageBox::Ok) {
+ //remove all translated versions. The lang cannot be null, but the value can be.
+ inMemoryFile.replace(QRegExp("\nName\\[\\S+\\]\\s*=[^\n]*",Qt::CaseInsensitive), "");
+ } else {
+ ui->lName->setText(DF.name);
+ }
+ }
+}
+
+void Dialog::on_lComment_textChanged(QString text)
+{
+ if (text != DF.name && inMemoryFile.contains(QRegExp("\nComment\\[\\S+\\]\\s*=",Qt::CaseInsensitive))) {
+ QMessageBox msgBox;
+ msgBox.setText(tr("By modifying this value, you will loose all translated versions"));
+ msgBox.setInformativeText(tr("The field: Comment is translated in several other languages. If you want to continue, you will loose all translated versions"));
+ msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+ int answer = msgBox.exec();
+ if (answer==QMessageBox::Ok) {
+ //remove all translated versions. The lang cannot be null, but the value can be.
+ inMemoryFile.replace(QRegExp("\nComment\\[\\S+\\]\\s*=[^\n]*",Qt::CaseInsensitive), "");
+ } else {
+ ui->lName->setText(DF.comment);
+ }
+ }
+}
diff --git a/lumina-fileinfo/dialog.h b/lumina-fileinfo/dialog.h
index e58f0938..1dfbd64c 100644
--- a/lumina-fileinfo/dialog.h
+++ b/lumina-fileinfo/dialog.h
@@ -16,6 +16,7 @@ public:
explicit Dialog(QWidget *parent = 0);
XDGDesktop DF ;
+ QString inMemoryFile;
QString desktopFileName ;
QString iconFileName;
@@ -38,6 +39,9 @@ private slots:
void on_pbIcon_clicked();
void textReplace(QString &origin, QString from, QString to, QString topic);
+
+ void on_lName_textChanged(QString text);
+ void on_lComment_textChanged(QString text);
private:
Ui::Dialog *ui;
bgstack15