From d748bf3f7af8e7dd70fa99bdf09e86fa9dd7c956 Mon Sep 17 00:00:00 2001 From: Oguzhan INAN Date: Sun, 25 Feb 2018 22:38:33 +0300 Subject: [PATCH] added start on boot option to settings page --- stacer/Pages/Settings/settings_page.cpp | 37 ++++ stacer/Pages/Settings/settings_page.h | 3 + stacer/Pages/Settings/settings_page.ui | 206 +++++++++++------- stacer/Pages/StartupApps/startup_app_edit.cpp | 15 +- stacer/Pages/StartupApps/startup_app_edit.ui | 5 +- stacer/Pages/Uninstaller/uninstaller_page.cpp | 4 +- stacer/main.cpp | 1 + stacer/static.qrc | 1 + stacer/static/loading.svg | 33 +++ 9 files changed, 220 insertions(+), 85 deletions(-) create mode 100644 stacer/static/loading.svg diff --git a/stacer/Pages/Settings/settings_page.cpp b/stacer/Pages/Settings/settings_page.cpp index 28e4c16d..5f9d6642 100644 --- a/stacer/Pages/Settings/settings_page.cpp +++ b/stacer/Pages/Settings/settings_page.cpp @@ -53,6 +53,19 @@ void SettingsPage::init() QString dk = apm->getDiskName(); ui->disksCmb->setCurrentText(dk); + // start on boot + startupAppPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); + startupAppPath.append("/autostart/stacer.desktop"); + + QFile startupAppFile(startupAppPath); + if (startupAppFile.exists()) { + QStringList appContent = FileUtil::readListFromFile(startupAppPath); + QString isHidden = Utilities::getDesktopValue(QRegExp("^Hidden=.*"), appContent).toLower(); + ui->checkAutostart->setChecked(isHidden == "false"); + } else { + ui->checkAutostart->setChecked(false); + } + // effects Utilities::addDropShadow(ui->languagesCmb, 40); Utilities::addDropShadow(ui->themesCmb, 40); @@ -84,3 +97,27 @@ void SettingsPage::diskCmbChanged(const int &index) apm->setDiskName(diskName); } + +void SettingsPage::on_checkAutostart_clicked(bool checked) +{ + if (checked) { + QString appTemplate = QString("[Desktop Entry]\n" + "Name=Stacer\n" + "Comment=Linux System Optimizer and Monitoring\n" + "Exec=/usr/share/stacer/stacer -m \n" + "Type=Application\n" + "Terminal=false\n" + "Hidden=false"); + + QFile autostartApp(startupAppPath); + + if (autostartApp.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + QTextStream stream(&autostartApp); + stream << appTemplate << endl; + + autostartApp.close(); + } + } else { + QFile::remove(startupAppPath); + } +} diff --git a/stacer/Pages/Settings/settings_page.h b/stacer/Pages/Settings/settings_page.h index 57cf3b3f..662e03d7 100644 --- a/stacer/Pages/Settings/settings_page.h +++ b/stacer/Pages/Settings/settings_page.h @@ -24,12 +24,15 @@ private slots: void themesCmbChanged(const int &index); void languagesCmbChanged(const int &index); void diskCmbChanged(const int &index); + void on_checkAutostart_clicked(bool checked); private: Ui::SettingsPage *ui; private: AppManager *apm; + + QString startupAppPath; }; #endif // SETTINGS_PAGE_H diff --git a/stacer/Pages/Settings/settings_page.ui b/stacer/Pages/Settings/settings_page.ui index 9d76b5ca..090687bb 100644 --- a/stacer/Pages/Settings/settings_page.ui +++ b/stacer/Pages/Settings/settings_page.ui @@ -38,83 +38,19 @@ 10 - - - - Theme - - - - - - - - 150 - 0 - - - - - 200 - 16777215 - - - - PointingHandCursor - - - Qt::NoFocus - - - QComboBox::AdjustToMinimumContentsLength - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + + + + 0 + 0 + + Disks - - - - - 150 - 0 - - - - - 200 - 16777215 - - - - PointingHandCursor - - - Qt::NoFocus - - - QComboBox::AdjustToMinimumContentsLength - - - @@ -142,12 +78,56 @@ + + + 0 + 0 + + Language - + + + + + 150 + 0 + + + + + 200 + 16777215 + + + + PointingHandCursor + + + Qt::NoFocus + + + QComboBox::AdjustToMinimumContentsLength + + + + + + + + 0 + 0 + + + + Theme + + + + Qt::Horizontal @@ -160,7 +140,7 @@ - + <html><head/><body><p>Created by <a href="https://github.com/oguzhaninan"><span style=" text-decoration: underline; color:#007af4;">Oğuzhan İNAN</span></a></p></body></html> @@ -176,6 +156,86 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + + + + + + 150 + 0 + + + + + 200 + 16777215 + + + + PointingHandCursor + + + Qt::NoFocus + + + QComboBox::AdjustToMinimumContentsLength + + + + + + + PointingHandCursor + + + Qt::NoFocus + + + + + + + + + + + 0 + 0 + + + + Start on boot + + + diff --git a/stacer/Pages/StartupApps/startup_app_edit.cpp b/stacer/Pages/StartupApps/startup_app_edit.cpp index 0fb9a1f5..df88b899 100644 --- a/stacer/Pages/StartupApps/startup_app_edit.cpp +++ b/stacer/Pages/StartupApps/startup_app_edit.cpp @@ -18,7 +18,7 @@ StartupAppEdit::StartupAppEdit(QWidget *parent) : "Exec=%3\n" "Type=Application\n" "Terminal=false\n" - "Hidden=true") + "Hidden=true\n") { ui->setupUi(this); @@ -78,20 +78,17 @@ void StartupAppEdit::changeDesktopValue(QStringList &lines, const QRegExp ®, void StartupAppEdit::on_saveBtn_clicked() { - if(isValid()) - { - if(! selectedFilePath.isEmpty()) - { + if(isValid()) { + if(! selectedFilePath.isEmpty()) { QStringList lines = FileUtil::readListFromFile(selectedFilePath); changeDesktopValue(lines, NAME_REG, QString("Name=%1").arg(ui->appNameTxt->text())); changeDesktopValue(lines, COMMENT_REG, QString("Comment=%1").arg(ui->appCommentTxt->text())); changeDesktopValue(lines, EXEC_REG, QString("Exec=%1").arg(ui->appCommandTxt->text())); - FileUtil::writeFile(selectedFilePath, QString(lines.join("\n")), QIODevice::ReadWrite | QIODevice::Truncate); + FileUtil::writeFile(selectedFilePath, lines.join("\n").append('\n'), QIODevice::ReadWrite | QIODevice::Truncate); } - else - { + else { // new file content QString appContent = newAppTemplate .arg(ui->appNameTxt->text()) @@ -109,7 +106,7 @@ void StartupAppEdit::on_saveBtn_clicked() } close(); - closeWindow(); // signal + emit closeWindow(); // signal } else { ui->errorMsg->show(); diff --git a/stacer/Pages/StartupApps/startup_app_edit.ui b/stacer/Pages/StartupApps/startup_app_edit.ui index 54499753..de6a75c2 100644 --- a/stacer/Pages/StartupApps/startup_app_edit.ui +++ b/stacer/Pages/StartupApps/startup_app_edit.ui @@ -82,11 +82,14 @@ - + Application + + Qt::AlignCenter + diff --git a/stacer/Pages/Uninstaller/uninstaller_page.cpp b/stacer/Pages/Uninstaller/uninstaller_page.cpp index 434ce68a..87c0a6d2 100644 --- a/stacer/Pages/Uninstaller/uninstaller_page.cpp +++ b/stacer/Pages/Uninstaller/uninstaller_page.cpp @@ -19,8 +19,8 @@ UninstallerPage::UninstallerPage(QWidget *parent) : void UninstallerPage::init() { - auto path = QString(":/static/themes/%1/img/loading.gif").arg(AppManager::ins()->getThemeName()); - auto loadingMovie = new QMovie(path, QByteArray(), this); + QString path = QString(":/static/themes/%1/img/loading.gif").arg(AppManager::ins()->getThemeName()); + QMovie *loadingMovie = new QMovie(path, QByteArray(), this); ui->loading->setMovie(loadingMovie); loadingMovie->start(); ui->loading->hide(); diff --git a/stacer/main.cpp b/stacer/main.cpp index 60543a4b..ef39f5ea 100644 --- a/stacer/main.cpp +++ b/stacer/main.cpp @@ -63,6 +63,7 @@ int main(int argc, char *argv[]) splashShadowEffect->setOffset(0); QSplashScreen splash(pixmap); + splash.setGraphicsEffect(splashShadowEffect); splash.show(); diff --git a/stacer/static.qrc b/stacer/static.qrc index 8fcbff3c..ecf84ef9 100755 --- a/stacer/static.qrc +++ b/stacer/static.qrc @@ -67,5 +67,6 @@ static/themes/default/img/sidebar-icons/ppa-manager.png static/themes/default/img/ppa-repository.png static/splashscreen.png + static/loading.svg diff --git a/stacer/static/loading.svg b/stacer/static/loading.svg new file mode 100644 index 00000000..6f7b43a1 --- /dev/null +++ b/stacer/static/loading.svg @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + +