diff --git a/entryprovider.cpp b/entryprovider.cpp index c5408b4..54f9ce8 100644 --- a/entryprovider.cpp +++ b/entryprovider.cpp @@ -295,6 +295,16 @@ void EntryProvider::saveUserEntry(const EntryConfig &config) } } +bool EntryProvider::deleteUserEntry(const EntryConfig &config) +{ + if(!config.userEntry || config.entryPath.isEmpty()) + { + throw std::runtime_error("Only user entries can be saved"); + } + QFile file { config.entryPath }; + return file.remove(); +} + template void assignIfDestDefault(T &dest, const T &source) { if(dest == T()) diff --git a/entryprovider.h b/entryprovider.h index 9f4ac1e..c2e6535 100644 --- a/entryprovider.h +++ b/entryprovider.h @@ -50,6 +50,7 @@ class EntryProvider QVector getUserEntries(); QVector getSystemEntries(); void saveUserEntry(const EntryConfig &config); + bool deleteUserEntry(const EntryConfig &config); }; #endif // ENTRYPROVIDER_H diff --git a/entrypushbutton.h b/entrypushbutton.h index f7e4626..f88cc6d 100644 --- a/entrypushbutton.h +++ b/entrypushbutton.h @@ -39,7 +39,7 @@ class EntryPushButton : public QPushButton signals: void clicked(const EntryConfig &config); - void deleteRequested(const EntryConfig &config); + void deleteRequested(EntryConfig &config); void addToFavourites(const EntryConfig &config); protected: diff --git a/window.cpp b/window.cpp index 809a2af..5c00ddb 100644 --- a/window.cpp +++ b/window.cpp @@ -147,6 +147,12 @@ void Window::addToFavourites(const EntryPushButton &button) userEntryButtons.append(createEntryButton(userConfig)); } +void Window::deleteEntry(EntryConfig &config) +{ + this->entryProvider->deleteUserEntry(config); + initFromConfig(); +} + void Window::closeWindow() { if(settingsProvider->singleInstanceMode()) @@ -422,6 +428,7 @@ EntryPushButton *Window::createEntryButton(const EntryConfig &entry) EntryPushButton *button = new EntryPushButton(entry); connect(button, &EntryPushButton::clicked, this, &Window::buttonClick); connect(button, &EntryPushButton::addToFavourites, this, &Window::addToFavourites); + connect(button, &EntryPushButton::deleteRequested, this, &Window::deleteEntry); return button; } diff --git a/window.h b/window.h index ac955c5..c0735e5 100644 --- a/window.h +++ b/window.h @@ -65,6 +65,7 @@ class Window : public QWidget void keyPressEvent(QKeyEvent *event); void buttonClick(const EntryPushButton &button); void addToFavourites(const EntryPushButton &button); + void deleteEntry(EntryConfig &config); QLineEdit *lineEdit; QGridLayout *grid; EntryPushButton *createEntryButton(const EntryConfig &config);