diff options
Diffstat (limited to 'lumina-fileinfo')
-rw-r--r-- | lumina-fileinfo/dialog.cpp | 587 | ||||
-rw-r--r-- | lumina-fileinfo/dialog.h | 44 | ||||
-rw-r--r-- | lumina-fileinfo/dialog.ui | 495 | ||||
-rw-r--r-- | lumina-fileinfo/lumina-fileinfo.pro | 2 | ||||
-rw-r--r-- | lumina-fileinfo/main.cpp | 32 |
5 files changed, 694 insertions, 466 deletions
diff --git a/lumina-fileinfo/dialog.cpp b/lumina-fileinfo/dialog.cpp index 0444a390..f44ace8f 100644 --- a/lumina-fileinfo/dialog.cpp +++ b/lumina-fileinfo/dialog.cpp @@ -4,363 +4,400 @@ #include <QRegExp> #include <QTemporaryFile> #include <QMessageBox> +#include <QImageReader> #include "LuminaUtils.h" #include <LuminaOS.h> - //this function is just like a regexp. //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*" + from + "\n",Qt::CaseInsensitive))) { - origin.replace(QRegExp("\n" + topic + "\\s*=\\s*" + from + "\n",Qt::CaseInsensitive),"\n" + topic + "=" + to + "\n"); - } else { - origin.append(topic + "=" + to + "\n"); - } + 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 { + origin.append(topic + "=" + to + "\n"); + } } //get the template from the user home directory or from the qrc files void Dialog::copyTemplate(QString templateType) { - if ((templateType == "-link") or (templateType == "-app")) { - if (QFile::exists(QDir::homePath() + "/.lumina/LuminaDE/fileinfo" + templateType + ".template")) { - //We take the template from homedir - QFile::copy(QDir::homePath() + "/.lumina/LuminaDE/fileinfo" + templateType + ".template", desktopFileName); - } else { - //last possibility is to use the qrc template. - //But based on the initialisation, this should never occurs - QFile::copy(":defaults/fileinfo" + templateType + ".template", desktopFileName); - } - } else { - //error message for developpers - qDebug() << "copyTemplate only accept '-link' or '-app' as parameter"; - } + if ((templateType == "-link") or (templateType == "-app")) { + if (QFile::exists(QDir::homePath() + "/.lumina/LuminaDE/fileinfo" + templateType + ".template")) { + //We take the template from homedir + QFile::copy(QDir::homePath() + "/.lumina/LuminaDE/fileinfo" + templateType + ".template", desktopFileName); + } else { + //last possibility is to use the qrc template. + //But based on the initialisation, this should never occurs + QFile::copy(":defaults/fileinfo" + templateType + ".template", desktopFileName); + } + } else { + //error message for developpers + qDebug() << "copyTemplate only accept '-link' or '-app' as parameter"; + } } Dialog::Dialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::Dialog) + QDialog(parent), + ui(new Ui::Dialog) { - ui->setupUi(this); - desktopType="Application"; //default value - - //Setup all the icons using libLumina - setupIcons(); - - //we copy qrc templates in the home dir of the user. - //this allow the user to adapt those template to is own whishes - QString templateFile = QDir::homePath() + "/.lumina/LuminaDE/fileinfo-link.template"; - if (!QFile::exists(templateFile)) { - QFile::copy(":defaults/fileinfo-link.template", templateFile); - QFile(templateFile).setPermissions(QFileDevice::ReadUser|QFileDevice::WriteUser); - } - templateFile = QDir::homePath() + "/.lumina/LuminaDE/fileinfo-app.template"; - if (!QFile::exists(templateFile)) { - QFile::copy(":defaults/fileinfo-app.template", templateFile); - QFile(templateFile).setPermissions(QFileDevice::ReadUser|QFileDevice::WriteUser); - } + ui->setupUi(this); + desktopType="Application"; //default value + + //Setup all the icons using libLumina + setupIcons(); + + //we copy qrc templates in the home dir of the user. + //this allow the user to adapt those template to is own whishes + QString templateFile = QDir::homePath() + "/.lumina/LuminaDE/fileinfo-link.template"; + if (!QFile::exists(templateFile)) { + QFile::copy(":defaults/fileinfo-link.template", templateFile); + QFile(templateFile).setPermissions(QFileDevice::ReadUser|QFileDevice::WriteUser); + } + templateFile = QDir::homePath() + "/.lumina/LuminaDE/fileinfo-app.template"; + if (!QFile::exists(templateFile)) { + QFile::copy(":defaults/fileinfo-app.template", templateFile); + QFile(templateFile).setPermissions(QFileDevice::ReadUser|QFileDevice::WriteUser); + } } Dialog::~Dialog() { - delete ui; + delete ui; } void Dialog::setupIcons(){ - this->setWindowIcon( LXDG::findIcon("unknown","") ); - ui->pbWorkingDir->setIcon( LXDG::findIcon("folder","") ); - ui->pbCommand->setIcon( LXDG::findIcon("system-search","") ); + this->setWindowIcon( LXDG::findIcon("unknown","") ); + ui->pbWorkingDir->setIcon( LXDG::findIcon("folder","") ); + ui->pbCommand->setIcon( LXDG::findIcon("system-search","") ); } //Inform the user that required input parameters are missing void Dialog::MissingInputs() { - qDebug() << "We cannot continue without a desktop file !!!"; - QMessageBox::critical(this, tr("Error"), tr("Lumina-fileinfo requires inputs:")+"\n"+QString(tr("Example: \"%1\"")).arg("lumina-fileinfo <-application>|<-link> desktopfile") ); - exit(1); + qDebug() << "We cannot continue without a desktop file !!!"; + QMessageBox::critical(this, tr("Error"), tr("Lumina-fileinfo requires inputs:")+"\n"+QString(tr("Example: \"%1\"")).arg("lumina-fileinfo <-application>|<-link> desktopfile") ); + exit(1); } //Initialise the layout of the screen. void Dialog::Initialise(QString param) { - - //in case of "link", several objects are no required - if (param.startsWith("-link")) { - ui->cbRunInTerminal->setVisible(false); - ui->cbStartupNotification->setVisible(false); - ui->lCommand->setVisible(false); - ui->pbCommand->setVisible(false); - ui->lblCommand->setVisible(false); - ui->lblOptions->setVisible(false); - ui->lblWorkingDir->setText(tr("URL")); //we use the WorkingDir boxes for URL - desktopType="link"; - } - if (param.startsWith("-app")) { - ui->cbRunInTerminal->setVisible(true); - ui->cbStartupNotification->setVisible(true); - ui->lCommand->setVisible(true); - ui->pbCommand->setVisible(true); - ui->lblCommand->setVisible(true); - ui->lblOptions->setVisible(true); - ui->lblWorkingDir->setText(tr("Working dir")); - desktopType="app"; - } + //in case of "link", several objects are no required + if (param.startsWith("-link")) { + ui->cbRunInTerminal->setVisible(false); + ui->cbStartupNotification->setVisible(false); + ui->lCommand->setVisible(false); + ui->pbCommand->setVisible(false); + ui->lblCommand->setVisible(false); + ui->lblOptions->setVisible(false); + ui->lblWorkingDir->setText(tr("URL")); //we use the WorkingDir boxes for URL + desktopType="link"; + } + if (param.startsWith("-app")) { + ui->cbRunInTerminal->setVisible(true); + ui->cbStartupNotification->setVisible(true); + ui->lCommand->setVisible(true); + ui->pbCommand->setVisible(true); + ui->lblCommand->setVisible(true); + ui->lblOptions->setVisible(true); + ui->lblWorkingDir->setText(tr("Working dir")); + desktopType="app"; + } } - - - //load the desktop file or the required template void Dialog::LoadDesktopFile(QString input) { - //if we have "-" as 1st char, it means that this is not a desktop file, but a parameter - desktopFileName = input; - if (input.startsWith("-")) { - QMessageBox::critical(this,tr("Error"),tr("The filename cannot start with a \"-\".")); - exit(1); + //if we have "-" as 1st char, it means that this is not a desktop file, but a parameter + desktopFileName = input; + if (input.startsWith("-")) { + QMessageBox::critical(this,tr("Error"),tr("The filename cannot start with a \"-\".")); + exit(1); + } + //if proposed file does not exist, than we will create one based on the templates + if (!QFile::exists(input)) { + if (desktopType=="link") { + copyTemplate("-link"); + } else { + copyTemplate("-app"); } - - //if proposed file does not exist, than we will create one based on the templates - if (!QFile::exists(input)) { - if (desktopType=="link") { - copyTemplate("-link"); - } else { - copyTemplate("-app"); - } + } + this->setWindowTitle(desktopFileName.section("/",-1)); + ui->tabWidget->setCurrentIndex(0); //always start on the file info tab + //Now load the file info and put it into the UI + QFileInfo info(desktopFileName); + QString mime = LXDG::findAppMimeForFile(desktopFileName); + + QList<QByteArray> fmt = QImageReader::supportedImageFormats(); + bool foundimage=false; + for(int i=0; i<fmt.length(); i++){ + if(info.suffix().toLower() == QString(fmt[i]).toLower()){foundimage=true; break; } } - - //use the standard LXDG object and load the desktop file - bool ok = false; - if(desktopFileName.endsWith(".desktop")){ - DF = LXDG::loadDesktopFile(desktopFileName, ok); + if(foundimage){ + ui->label_file_icon->setPixmap( QPixmap(desktopFileName).scaledToHeight(64) ); + }else{ + ui->label_file_icon->setPixmap( LXDG::findMimeIcon(mime).pixmap(QSize(64,64)) ); + } + ui->label_file_mimetype->setText(mime); + QString type; + if(desktopFileName.endsWith(".desktop")){ type = tr("XDG Shortcut"); } + else if(info.isDir()){ type = tr("Directory"); ui->label_file_icon->setPixmap( LXDG::findIcon("folder","").pixmap(QSize(64,64)) ); } + else if(info.isExecutable()){ type = tr("Binary"); } + else{ type = info.suffix().toUpper(); } + if(info.isHidden()){ type = QString(tr("Hidden %1")).arg(type); } + ui->label_file_type->setText(type); + double bytes = info.size(); + QStringList lab; lab << "B" << "KB" << "MB" << "GB" << "TB" << "PB"; + int i=0; + while(i<lab.length() && bytes>1024){ + bytes = bytes/1024; + i++; //next label + } + //convert the size to two decimel places and add the label + QString sz = QString::number( qRound(bytes*100)/100.0 )+lab[i]; + ui->label_file_size->setText( sz ); + ui->label_file_owner->setText(info.owner()); + ui->label_file_group->setText(info.group()); + QString perms; + if(info.isReadable() && info.isWritable()){ perms = tr("Read/Write"); } + else if(info.isReadable()){ perms = tr("Read Only"); } + else if(info.isWritable()){ perms = tr("Write Only"); } + else{ perms = tr("No Access"); } + ui->label_file_perms->setText(perms); + ui->label_file_created->setText( info.created().toString(Qt::SystemLocaleLongDate) ); + ui->label_file_modified->setText( info.lastModified().toString(Qt::SystemLocaleLongDate) ); + + //use the standard LXDG object and load the desktop file + bool ok = false; + if(desktopFileName.endsWith(".desktop")){ + DF = LXDG::loadDesktopFile(desktopFileName, ok); + } + if( ok ) { + if ((DF.type == XDGDesktop::LINK) && (desktopType!="link" )) { + //we open a desktop type "link" but it was not mentionned by parameters + Dialog::Initialise("-link"); } - if( ok ) { - if ((DF.type == XDGDesktop::LINK) && (desktopType!="link" )) { - //we open a desktop type "link" but it was not mentionned by parameters - Dialog::Initialise("-link"); - } - ui->lName->setText(DF.name); - ui->lComment->setText(DF.comment); - ui->lCommand->setText(DF.exec); - //in case of "link" desktop, we populate the correct content in lWorkingDir - if (desktopType=="link") { - ui->lWorkingDir->setText(DF.url); - } else { - ui->lWorkingDir->setText(DF.path); - } - if (DF.startupNotify) ui->cbStartupNotification->setChecked(true); else ui->cbStartupNotification->setChecked(false); - if (DF.useTerminal) ui->cbRunInTerminal->setChecked(true); else ui->cbRunInTerminal->setChecked(false); - iconFileName=""; - ui->pbIcon->setIcon(LXDG::findIcon(DF.icon,"")); - this->setWindowTitle(DF.filePath.section("/",-1)); + ui->lName->setText(DF.name); + ui->lComment->setText(DF.comment); + ui->lCommand->setText(DF.exec); + //in case of "link" desktop, we populate the correct content in lWorkingDir + if (desktopType=="link") { + ui->lWorkingDir->setText(DF.url); } else { - QMessageBox::critical(this, tr("Error"), tr("Invalid File Supplied:") +"\n"+desktopFileName ); - exit(1); + ui->lWorkingDir->setText(DF.path); } - - //we load the file in memory and will adapt it before saving it to disk - QFile file(desktopFileName); - inMemoryFile=""; - if (file.open(QFile::ReadOnly)) { - QTextStream fileData(&file); - inMemoryFile = fileData.readAll(); - file.close(); - //perform some validation checks - //TODO: put those Regex in a config file. - //this will allow checks improvements without compilation of the file - if ((inMemoryFile.contains(QRegExp(".*\\[Desktop Entry\\].*\n"))) && - (inMemoryFile.contains(QRegExp("\n\\s*Type\\s*=.*\n"))) && - (inMemoryFile.contains(QRegExp("\n\\s*Name\\s*=.*\n")))) { - //qDebug() << "sounds a good file"; - } else { - //qDebug() << "wrong file!!!!"; - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Question); - msgBox.setText(tr("There are some issues with this file !!!!")); - msgBox.setInformativeText(tr("Either you correct this file your self with an editor, or you start from scratch using the link or app template.\nPlease note that this process will update the file called:") + desktopFileName); - QPushButton *linkButton = msgBox.addButton("Link",QMessageBox::AcceptRole); - QPushButton *appButton = msgBox.addButton("App",QMessageBox::ResetRole); - QPushButton *cancelButton = msgBox.addButton("Cancel",QMessageBox::NoRole); - msgBox.exec(); - if (msgBox.clickedButton() == linkButton) { - QFile::remove(desktopFileName); - copyTemplate("-link"); - Initialise("-link"); - LoadDesktopFile(desktopFileName); - } - if (msgBox.clickedButton() == appButton) { - QFile::remove(desktopFileName); - copyTemplate("-app"); - Initialise("-app"); - LoadDesktopFile(desktopFileName); - } - if (msgBox.clickedButton() == cancelButton) { - //we stop here - exit(0); - } - } + if (DF.startupNotify) ui->cbStartupNotification->setChecked(true); else ui->cbStartupNotification->setChecked(false); + if (DF.useTerminal) ui->cbRunInTerminal->setChecked(true); else ui->cbRunInTerminal->setChecked(false); + iconFileName=""; + ui->pbIcon->setIcon(LXDG::findIcon(DF.icon,"")); + if(!info.isWritable()){ ui->tab_deskedit->setEnabled(false); } + } else { + ui->tabWidget->removeTab(1); + return; + } + + //we load the file in memory and will adapt it before saving it to disk + QFile file(desktopFileName); + inMemoryFile=""; + if (file.open(QFile::ReadOnly)) { + QTextStream fileData(&file); + inMemoryFile = fileData.readAll(); + file.close(); + //perform some validation checks + //this will allow checks improvements without compilation of the file + if ((inMemoryFile.contains(QRegExp(".*\\[Desktop Entry\\].*\n"))) && + (inMemoryFile.contains(QRegExp("\n\\s*Type\\s*=.*\n"))) && + (inMemoryFile.contains(QRegExp("\n\\s*Name\\s*=.*\n")))) { + //qDebug() << "sounds a good file"; + } else { + //qDebug() << "wrong file!!!!"; + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Question); + msgBox.setText(tr("There are some issues with this file !!!!")); + msgBox.setInformativeText(tr("Either you correct this file your self with an editor, or you start from scratch using the link or app template.\nPlease note that this process will update the file called:") + desktopFileName); + QPushButton *linkButton = msgBox.addButton("Link",QMessageBox::AcceptRole); + QPushButton *appButton = msgBox.addButton("App",QMessageBox::ResetRole); + QPushButton *cancelButton = msgBox.addButton("Cancel",QMessageBox::NoRole); + msgBox.exec(); + if (msgBox.clickedButton() == linkButton) { + QFile::remove(desktopFileName); + copyTemplate("-link"); + Initialise("-link"); + LoadDesktopFile(desktopFileName); + } + if (msgBox.clickedButton() == appButton) { + QFile::remove(desktopFileName); + copyTemplate("-app"); + Initialise("-app"); + LoadDesktopFile(desktopFileName); + } + if (msgBox.clickedButton() == cancelButton) { + //we stop here + exit(0); + } } + } } void Dialog::on_pbCommand_clicked() { - //the default directory is the user's home directory - QString commandFolder = QDir::homePath(); - if (!ui->lCommand->text().isEmpty()) commandFolder = ui->lCommand->text().section('/', 0, -2); - if (commandFolder.isEmpty()) commandFolder = QDir::homePath(); - - QString fileName = QFileDialog::getOpenFileName(this, + //the default directory is the user's home directory + QString commandFolder = QDir::homePath(); + if (!ui->lCommand->text().isEmpty()) commandFolder = ui->lCommand->text().section('/', 0, -2); + if (commandFolder.isEmpty()) commandFolder = QDir::homePath(); + + QString fileName = QFileDialog::getOpenFileName(this, tr("Open command"), commandFolder, tr("All Files (*)")); - if (!fileName.isEmpty()) { - ui->lCommand->setText(fileName); - ui->lCommand->setModified(true); - } + if (!fileName.isEmpty()) { + ui->lCommand->setText(fileName); + ui->lCommand->setModified(true); + } } void Dialog::on_pbWorkingDir_clicked() { - //the default directory is / - QString workingDir = "/"; - if (ui->lWorkingDir->text().isEmpty()) workingDir = "/"; - else workingDir = ui->lWorkingDir->text(); - QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly; - QString directory = QFileDialog::getExistingDirectory(this, + //the default directory is / + QString workingDir = "/"; + if (ui->lWorkingDir->text().isEmpty()) workingDir = "/"; + else workingDir = ui->lWorkingDir->text(); + QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly; + QString directory = QFileDialog::getExistingDirectory(this, tr("Working Directory"), workingDir, options); - if (!directory.isEmpty()) { - ui->lWorkingDir->setText(directory); - ui->lWorkingDir->setModified(true); - } + if (!directory.isEmpty()) { + ui->lWorkingDir->setText(directory); + ui->lWorkingDir->setModified(true); + } } //we save the changes to the destination file void Dialog::on_pbApply_clicked() { - 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(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"); - } - - QFile file(desktopFileName); - if (file.open(QFile::ReadWrite)) { - file.seek(0); - file.write(inMemoryFile.toUtf8()); - - file.resize(file.pos());//remove possible trailing lines - - file.close(); - } else { - //problem to write to the disk - QMessageBox::critical(this, tr("Problem to write to disk"), tr("We have a problem to write the adapted desktop file to the disk. Can you re-try the modification after solving the issue with the disk ?")); - } - - //hack required to update the icon on the desktop - QTemporaryFile tempFile ; - tempFile.setAutoRemove(false); - tempFile.setFileTemplate("/tmp/lumina-XXXXXX"); - tempFile.open(); - tempFile.close(); - - QString cmd = "mv"; - cmd = cmd + " " + desktopFileName + " " + tempFile.fileName(); - int ret = LUtils::runCmd(cmd); - if (ret !=0 ) { - qDebug() << "Problem to execute:" << cmd; - QMessageBox::critical(this, tr("Problem to write to disk"), tr("We have a problem to execute the following command:") + cmd); - - } - - cmd = "mv"; - cmd = cmd + " " + tempFile.fileName() + " " + desktopFileName; - ret = LUtils::runCmd(cmd); - if (ret !=0 ) { - qDebug() << "Problem to execute:" << cmd; - QMessageBox::critical(this, tr("Problem to write to disk"), tr("We have a problem to execute the following command:") + cmd); - } + 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(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"); + } + + QFile file(desktopFileName); + if (file.open(QFile::ReadWrite)) { + file.seek(0); + file.write(inMemoryFile.toUtf8()); + + file.resize(file.pos());//remove possible trailing lines + + file.close(); + } else { + //problem to write to the disk + QMessageBox::critical(this, tr("Problem to write to disk"), tr("We have a problem to write the adapted desktop file to the disk. Can you re-try the modification after solving the issue with the disk ?")); + } + + //hack required to update the icon on the desktop + QTemporaryFile tempFile ; + tempFile.setAutoRemove(false); + tempFile.setFileTemplate("/tmp/lumina-XXXXXX"); + tempFile.open(); + tempFile.close(); + + QString cmd = "mv"; + cmd = cmd + " " + desktopFileName + " " + tempFile.fileName(); + int ret = LUtils::runCmd(cmd); + if (ret !=0 ) { + qDebug() << "Problem to execute:" << cmd; + QMessageBox::critical(this, tr("Problem to write to disk"), tr("We have a problem to execute the following command:") + cmd); + } + + cmd = "mv"; + cmd = cmd + " " + tempFile.fileName() + " " + desktopFileName; + ret = LUtils::runCmd(cmd); + if (ret !=0 ) { + qDebug() << "Problem to execute:" << cmd; + QMessageBox::critical(this, tr("Problem to write to disk"), tr("We have a problem to execute the following command:") + cmd); + } } void Dialog::on_pbIcon_clicked() { - //the default directory is local/share/icons - QString iconFolder = LOS::AppPrefix()+"/share/icons"; - if (!iconFileName.isEmpty()) iconFolder = iconFileName.section('/', 0, -2); - else if (!DF.icon.isEmpty()) iconFolder = DF.icon.section('/', 0, -2); - if (iconFolder.isEmpty()) iconFolder = LOS::AppPrefix()+"/share/icons"; - - QString fileName = QFileDialog::getOpenFileName(this, + //the default directory is local/share/icons + QString iconFolder = LOS::AppPrefix()+"/share/icons"; + if (!iconFileName.isEmpty()) iconFolder = iconFileName.section('/', 0, -2); + else if (!DF.icon.isEmpty()) iconFolder = DF.icon.section('/', 0, -2); + if (iconFolder.isEmpty()) iconFolder = LOS::AppPrefix()+"/share/icons"; + + QString fileName = QFileDialog::getOpenFileName(this, tr("Open command"), iconFolder, tr("Image Files (*.png *.jpg *.bmp)")); - if (!fileName.isEmpty()) { - ui->pbIcon->setIcon(QPixmap(fileName)); - iconFileName=fileName; - } + if (!fileName.isEmpty()) { + ui->pbIcon->setIcon(QPixmap(fileName)); + 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); - } - } + 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); - } - } + 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 6f0a4dbf..785cb52e 100644 --- a/lumina-fileinfo/dialog.h +++ b/lumina-fileinfo/dialog.h @@ -10,42 +10,42 @@ class Dialog; class Dialog : public QDialog { - Q_OBJECT - + Q_OBJECT + public: - explicit Dialog(QWidget *parent = 0); + explicit Dialog(QWidget *parent = 0); - XDGDesktop DF ; - QString inMemoryFile; + XDGDesktop DF ; + QString inMemoryFile; - QString desktopFileName ; - QString iconFileName; - QString desktopType; + QString desktopFileName ; + QString iconFileName; + QString desktopType; - void Initialise(QString); - void MissingInputs(); - void LoadDesktopFile(QString); + void Initialise(QString); + void MissingInputs(); + void LoadDesktopFile(QString); - ~Dialog(); + ~Dialog(); public slots: - void setupIcons(); + void setupIcons(); private slots: - void on_pbCommand_clicked(); - void on_pbWorkingDir_clicked(); - void on_pbApply_clicked(); - void on_pbIcon_clicked(); + void on_pbCommand_clicked(); + void on_pbWorkingDir_clicked(); + void on_pbApply_clicked(); + void on_pbIcon_clicked(); - void textReplace(QString &origin, QString from, QString to, QString topic); - void copyTemplate(QString templateType); + void textReplace(QString &origin, QString from, QString to, QString topic); + void copyTemplate(QString templateType); - void on_lName_textChanged(QString text); - void on_lComment_textChanged(QString text); + void on_lName_textChanged(QString text); + void on_lComment_textChanged(QString text); private: - Ui::Dialog *ui; + Ui::Dialog *ui; }; #endif // DIALOG_H diff --git a/lumina-fileinfo/dialog.ui b/lumina-fileinfo/dialog.ui index 311c2ff0..2827127c 100644 --- a/lumina-fileinfo/dialog.ui +++ b/lumina-fileinfo/dialog.ui @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>383</width> - <height>288</height> + <width>349</width> + <height>327</height> </rect> </property> <property name="windowTitle"> @@ -15,162 +15,353 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <layout class="QGridLayout" name="gridLayout"> - <item row="3" column="0" alignment="Qt::AlignRight"> - <widget class="QLabel" name="lblWorkingDir"> - <property name="text"> - <string>Working dir:</string> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="tab_file"> + <attribute name="title"> + <string>File Properties</string> + </attribute> + <layout class="QFormLayout" name="formLayout"> + <property name="labelAlignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> </property> - </widget> - </item> - <item row="3" column="2"> - <widget class="QPushButton" name="pbWorkingDir"> - <property name="enabled"> - <bool>true</bool> + <item row="0" column="0"> + <widget class="QLabel" name="label_file_icon"> + <property name="text"> + <string notr="true">icon</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="4" column="0" colspan="2"> + <widget class="Line" name="line_2"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="5" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Owner:</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QLabel" name="label_file_owner"> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + <item row="6" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Group:</string> + </property> + </widget> + </item> + <item row="6" column="1"> + <widget class="QLabel" name="label_file_group"> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + <item row="7" column="0"> + <widget class="QLabel" name="label_11"> + <property name="text"> + <string>Permissions:</string> + </property> + </widget> + </item> + <item row="10" column="0" colspan="2"> + <widget class="Line" name="line_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item row="11" column="0"> + <widget class="QLabel" name="label_7"> + <property name="text"> + <string>Created:</string> + </property> + </widget> + </item> + <item row="11" column="1"> + <widget class="QLabel" name="label_file_created"> + <property name="toolTip"> + <string>Note: The time a file was created might be more recent than the time modified if the file permissions were changed recently.</string> + </property> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + <item row="12" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Last Modified:</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Type:</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>MimeType:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLabel" name="label_file_mimetype"> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLabel" name="label_file_type"> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + <item row="7" column="1"> + <widget class="QLabel" name="label_file_perms"> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + <item row="12" column="1"> + <widget class="QLabel" name="label_file_modified"> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>File Size:</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLabel" name="label_file_size"> + <property name="text"> + <string notr="true"/> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab_deskedit"> + <attribute name="title"> + <string>Edit Shortcut</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <property name="spacing"> + <number>2</number> </property> - <property name="text"> - <string/> + <property name="leftMargin"> + <number>4</number> </property> - <property name="icon"> - <iconset> - <normalon>../../../../usr/local/share/icons/gnome/32x32/places/folder.png</normalon> - </iconset> + <property name="topMargin"> + <number>4</number> </property> - </widget> - </item> - <item row="2" column="2"> - <widget class="QPushButton" name="pbCommand"> - <property name="text"> - <string/> + <property name="rightMargin"> + <number>4</number> </property> - <property name="icon"> - <iconset> - <normalon>../../../../usr/local/share/icons/gnome/32x32/actions/gnome-run.png</normalon> - </iconset> + <property name="bottomMargin"> + <number>4</number> </property> - </widget> - </item> - <item row="5" column="1"> - <widget class="QCheckBox" name="cbStartupNotification"> - <property name="text"> - <string>Use startup notification</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QLineEdit" name="lWorkingDir"> - <property name="enabled"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="4" column="0" alignment="Qt::AlignRight"> - <widget class="QLabel" name="lblIcon"> - <property name="text"> - <string>Icon:</string> - </property> - </widget> - </item> - <item row="2" column="0" alignment="Qt::AlignRight"> - <widget class="QLabel" name="lblCommand"> - <property name="text"> - <string>Command:</string> - </property> - </widget> - </item> - <item row="1" column="0" alignment="Qt::AlignRight"> - <widget class="QLabel" name="lblComment"> - <property name="text"> - <string>Comment:</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="lCommand"/> - </item> - <item row="4" column="1" alignment="Qt::AlignLeft"> - <widget class="QPushButton" name="pbIcon"> - <property name="maximumSize"> - <size> - <width>275</width> - <height>16777215</height> - </size> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset> - <normalon>../../../../usr/local/share/icons/gnome/32x32/categories/xfce-graphics.png</normalon> - </iconset> - </property> - <property name="iconSize"> - <size> - <width>64</width> - <height>64</height> - </size> - </property> - </widget> - </item> - <item row="6" column="1"> - <widget class="QCheckBox" name="cbRunInTerminal"> - <property name="text"> - <string>Run in terminal</string> - </property> - </widget> - </item> - <item row="0" column="0" alignment="Qt::AlignRight"> - <widget class="QLabel" name="lblName"> - <property name="text"> - <string>Name:</string> - </property> - </widget> - </item> - <item row="5" column="0" alignment="Qt::AlignRight"> - <widget class="QLabel" name="lblOptions"> - <property name="text"> - <string>Options</string> - </property> - </widget> - </item> - <item row="0" column="1" colspan="2"> - <widget class="QLineEdit" name="lName"/> - </item> - <item row="1" column="1" colspan="2"> - <widget class="QLineEdit" name="lComment"/> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="pbCancel"> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pbApply"> - <property name="text"> - <string>Apply</string> - </property> - </widget> - </item> - </layout> + <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="3" column="0" alignment="Qt::AlignRight"> + <widget class="QLabel" name="lblWorkingDir"> + <property name="text"> + <string>Working dir:</string> + </property> + </widget> + </item> + <item row="3" column="2"> + <widget class="QPushButton" name="pbWorkingDir"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset> + <normalon>../../../../usr/local/share/icons/gnome/32x32/places/folder.png</normalon> + </iconset> + </property> + </widget> + </item> + <item row="2" column="2"> + <widget class="QPushButton" name="pbCommand"> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset> + <normalon>../../../../usr/local/share/icons/gnome/32x32/actions/gnome-run.png</normalon> + </iconset> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QCheckBox" name="cbStartupNotification"> + <property name="text"> + <string>Use startup notification</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLineEdit" name="lWorkingDir"> + <property name="enabled"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="4" column="0" alignment="Qt::AlignRight"> + <widget class="QLabel" name="lblIcon"> + <property name="text"> + <string>Icon:</string> + </property> + </widget> + </item> + <item row="2" column="0" alignment="Qt::AlignRight"> + <widget class="QLabel" name="lblCommand"> + <property name="text"> + <string>Command:</string> + </property> + </widget> + </item> + <item row="1" column="0" alignment="Qt::AlignRight"> + <widget class="QLabel" name="lblComment"> + <property name="text"> + <string>Comment:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="lCommand"/> + </item> + <item row="4" column="1" alignment="Qt::AlignLeft"> + <widget class="QPushButton" name="pbIcon"> + <property name="maximumSize"> + <size> + <width>275</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string/> + </property> + <property name="icon"> + <iconset> + <normalon>../../../../usr/local/share/icons/gnome/32x32/categories/xfce-graphics.png</normalon> + </iconset> + </property> + <property name="iconSize"> + <size> + <width>64</width> + <height>64</height> + </size> + </property> + </widget> + </item> + <item row="6" column="1"> + <widget class="QCheckBox" name="cbRunInTerminal"> + <property name="text"> + <string>Run in terminal</string> + </property> + </widget> + </item> + <item row="0" column="0" alignment="Qt::AlignRight"> + <widget class="QLabel" name="lblName"> + <property name="text"> + <string>Name:</string> + </property> + </widget> + </item> + <item row="5" column="0" alignment="Qt::AlignRight"> + <widget class="QLabel" name="lblOptions"> + <property name="text"> + <string>Options</string> + </property> + </widget> + </item> + <item row="0" column="1" colspan="2"> + <widget class="QLineEdit" name="lName"/> + </item> + <item row="1" column="1" colspan="2"> + <widget class="QLineEdit" name="lComment"/> + </item> + </layout> + </item> + <item> + <widget class="Line" name="line"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="pbCancel"> + <property name="text"> + <string>Cancel</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pbApply"> + <property name="text"> + <string>Apply</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </widget> </item> </layout> </widget> diff --git a/lumina-fileinfo/lumina-fileinfo.pro b/lumina-fileinfo/lumina-fileinfo.pro index b565818d..c90dd5a4 100644 --- a/lumina-fileinfo/lumina-fileinfo.pro +++ b/lumina-fileinfo/lumina-fileinfo.pro @@ -100,7 +100,7 @@ TRANSLATIONS = i18n/lumina-fileinfo_af.ts \ i18n/lumina-fileinfo_zh_CN.ts \ i18n/lumina-fileinfo_zh_HK.ts \ i18n/lumina-fileinfo_zh_TW.ts \ - i18n/lumina-fileinfo_zu.ts + i18n/lumina-fileinfo_zu.ts dotrans.path=$$PREFIX/share/Lumina-DE/i18n/ dotrans.extra=cd i18n && $${LRELEASE} -nounfinished *.ts && cp *.qm $(INSTALL_ROOT)$$PREFIX/share/Lumina-DE/i18n/ diff --git a/lumina-fileinfo/main.cpp b/lumina-fileinfo/main.cpp index 59e86623..5f6a0d57 100644 --- a/lumina-fileinfo/main.cpp +++ b/lumina-fileinfo/main.cpp @@ -9,22 +9,22 @@ int main(int argc, char ** argv) { - QApplication a(argc, argv); - LUtils::LoadTranslation(&a, "lumina-fileinfo"); - LuminaThemeEngine theme(&a); + QApplication a(argc, argv); + LUtils::LoadTranslation(&a, "lumina-fileinfo"); + LuminaThemeEngine theme(&a); - Dialog w; - QObject::connect(&theme, SIGNAL(updateIcons()), &w, SLOT(setupIcons()) ); - if (argc==2) { - w.LoadDesktopFile(QString(argv[1]).simplified()); - } else if (argc==3) { - w.Initialise(QString(argv[1]).simplified()); - w.LoadDesktopFile(QString(argv[2]).simplified()); - } else { - w.MissingInputs(); - } - w.show(); + Dialog w; + QObject::connect(&theme, SIGNAL(updateIcons()), &w, SLOT(setupIcons()) ); + if (argc==2) { + w.LoadDesktopFile(QString(argv[1]).simplified()); + } else if (argc==3) { + w.Initialise(QString(argv[1]).simplified()); + w.LoadDesktopFile(QString(argv[2]).simplified()); + } else { + w.MissingInputs(); + } + w.show(); - int retCode = a.exec(); - return retCode; + int retCode = a.exec(); + return retCode; }
\ No newline at end of file |