diff --git a/src/config/buttonlistview.cpp b/src/config/buttonlistview.cpp index e6cda487..d69055aa 100644 --- a/src/config/buttonlistview.cpp +++ b/src/config/buttonlistview.cpp @@ -27,8 +27,6 @@ ButtonListView::ButtonListView(QWidget *parent) : QListWidget(parent) { setFlow(QListWidget::TopToBottom); initButtonList(); updateComponents(); - connect(this, &QListWidget::itemChanged, this, - &ButtonListView::updateActiveButtons); connect(this, &QListWidget::itemClicked, this, &ButtonListView::reverseItemCheck); } @@ -44,7 +42,6 @@ void ButtonListView::initButtonList() { m_buttonTypeByName.insert(tool->getName(), t); // init the menu option - QListWidgetItem *m_buttonItem = new QListWidgetItem(this); // when the background is lighter than gray, it uses the white icons @@ -78,6 +75,7 @@ void ButtonListView::updateActiveButtons(QListWidgetItem *item) { } else { m_listButtons.removeOne(buttonIndex); } + qDebug("updateActiveButtons"); QSettings().setValue("buttons", QVariant::fromValue(m_listButtons)); } @@ -87,6 +85,7 @@ void ButtonListView::reverseItemCheck(QListWidgetItem *item){ } else { item->setCheckState(Qt::Checked); } + updateActiveButtons(item); } void ButtonListView::selectAll() { diff --git a/src/config/buttonlistview.h b/src/config/buttonlistview.h index 84455eb1..bb6915cb 100644 --- a/src/config/buttonlistview.h +++ b/src/config/buttonlistview.h @@ -30,7 +30,6 @@ public slots: void updateComponents(); private slots: - void updateActiveButtons(QListWidgetItem *); void reverseItemCheck(QListWidgetItem *); protected: @@ -40,6 +39,7 @@ private: QList m_listButtons; QMap m_buttonTypeByName; + void updateActiveButtons(QListWidgetItem *); }; #endif // BUTTONLISTVIEW_H diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp index e8b5ee5b..f5b3642e 100644 --- a/src/config/configwindow.cpp +++ b/src/config/configwindow.cpp @@ -22,10 +22,13 @@ #include "src/config/geneneralconf.h" #include "src/config/filenameeditor.h" #include "src/config/strftimechooserwidget.h" +#include "src/utils/confighandler.h" #include #include #include #include +#include +#include // ConfigWindow contains the menus where you can configure the application @@ -35,6 +38,19 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) { setWindowIcon(QIcon(":img/flameshot.png")); setWindowTitle(tr("Configuration")); + auto changedSlot = [this](QString s){ + Q_UNUSED(s); + this->m_configWatcher->removePath(s); + this->m_configWatcher->addPath(s); + if(!this->hasFocus()) { + Q_EMIT updateComponents(); + } + }; + m_configWatcher = new QFileSystemWatcher(this); + m_configWatcher->addPath(ConfigHandler().getConfigFilePath()); + connect(m_configWatcher, &QFileSystemWatcher::fileChanged, + this, changedSlot); + QColor background = this->palette().background().color(); bool isWhite = CaptureButton::iconIsWhiteByColor(background); QString modifier = isWhite ? ":img/configWhite/" : ":img/configBlack/"; diff --git a/src/config/configwindow.h b/src/config/configwindow.h index 1417f830..660e600a 100644 --- a/src/config/configwindow.h +++ b/src/config/configwindow.h @@ -24,6 +24,7 @@ class ButtonListView; class UIcolorEditor; class FileNameEditor; class GeneneralConf; +class QFileSystemWatcher; class ConfigWindow : public QTabWidget { Q_OBJECT @@ -45,6 +46,8 @@ private: FileNameEditor *m_filenameEditor; GeneneralConf *m_generalConfig; + QFileSystemWatcher *m_configWatcher; + }; #endif // CONFIGURATION_H diff --git a/src/core/controller.cpp b/src/core/controller.cpp index ca189fc7..e2c4dc1e 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -32,8 +32,6 @@ Controller::Controller() : m_captureWindow(nullptr) { - // required for the button serialization - qRegisterMetaTypeStreamOperators >("QList"); qApp->setQuitOnLastWindowClosed(false); // init tray icon @@ -133,7 +131,9 @@ void Controller::enableTrayIcon() { } void Controller::disableTrayIcon() { - m_trayIcon->deleteLater(); + if (m_trayIcon) { + m_trayIcon->deleteLater(); + } ConfigHandler().setDisabledTrayIcon(true); } diff --git a/src/core/flameshotdbusadapter.cpp b/src/core/flameshotdbusadapter.cpp index 3768003e..3ebaafce 100644 --- a/src/core/flameshotdbusadapter.cpp +++ b/src/core/flameshotdbusadapter.cpp @@ -58,5 +58,4 @@ void FlameshotDBusAdapter::trayIconEnabled(bool enabled) { } else { controller->disableTrayIcon(); } - controller->updateConfigComponents(); } diff --git a/src/main.cpp b/src/main.cpp index aa08c013..605e3721 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,8 @@ #include int main(int argc, char *argv[]) { + // required for the button serialization + qRegisterMetaTypeStreamOperators >("QList"); qApp->setApplicationVersion(static_cast(APP_VERSION)); QTranslator translator; diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index a2501e81..2b541725 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -34,6 +34,7 @@ QList ConfigHandler::getButtons() { void ConfigHandler::setButtons(const QList &buttons) { QList l = fromButtonToInt(buttons); normalizeButtons(l); + qDebug("setButtons"); m_settings->setValue("buttons", QVariant::fromValue(l)); } @@ -131,6 +132,10 @@ void ConfigHandler::setAllTheButtons() { m_settings->setValue("buttons", QVariant::fromValue(buttons)); } +QString ConfigHandler::getConfigFilePath() const { + return m_settings->fileName(); +} + bool ConfigHandler::normalizeButtons(QList &buttons) { auto listTypes = CaptureButton::getIterableButtonTypes(); QList listTypesInt; diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index e5125bdf..f977fe2f 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -64,6 +64,8 @@ public: void setAllTheButtons(); + QString getConfigFilePath() const; + private: QSettings *m_settings;