Code cleanup, slots&signals

This commit is contained in:
ArsenArsen 2017-04-25 21:27:29 +02:00
parent 90fbb80f50
commit 895960c1b0
4 changed files with 19 additions and 9 deletions

View File

@ -38,13 +38,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ui->uploaderList->setSelectionMode(QAbstractItemView::SingleSelection); ui->uploaderList->setSelectionMode(QAbstractItemView::SingleSelection);
// Add items to uploader selection // Add items to uploader selection
for (Uploader *u : UploaderSingleton::inst().uploaderList()) for (Uploader *u : UploaderSingleton::inst().uploaderList()) newUploader(u);
{ connect(&UploaderSingleton::inst(), &UploaderSingleton::newUploader, this, &MainWindow::newUploader);
QListWidgetItem *item = new QListWidgetItem(u->name());
item->setToolTip(u->description());
ui->uploaderList->addItem(item);
if (u->name() == UploaderSingleton::inst().selectedUploader()) item->setSelected(true);
}
// Set filename scheme // Set filename scheme
if ((settings::settings().contains("fileFormat"))) if ((settings::settings().contains("fileFormat")))
@ -85,6 +80,14 @@ void MainWindow::toggleVisible()
this->setVisible(!this->isVisible()); this->setVisible(!this->isVisible());
} }
void MainWindow::newUploader(Uploader *u)
{
QListWidgetItem *item = new QListWidgetItem(u->name());
item->setToolTip(u->description());
ui->uploaderList->addItem(item);
if (u->name() == UploaderSingleton::inst().selectedUploader()) item->setSelected(true);
}
void MainWindow::on_actionQuit_triggered() void MainWindow::on_actionQuit_triggered()
{ {
quit(); quit();

View File

@ -4,6 +4,8 @@
#include <QMainWindow> #include <QMainWindow>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <uploaders/uploader.hpp>
namespace Ui namespace Ui
{ {
class MainWindow; class MainWindow;
@ -15,6 +17,7 @@ class MainWindow : public QMainWindow
private slots: private slots:
void quit(); void quit();
void toggleVisible(); void toggleVisible();
void newUploader(Uploader *u);
void on_actionQuit_triggered(); void on_actionQuit_triggered();
void on_actionFullscreen_triggered(); void on_actionFullscreen_triggered();

View File

@ -8,7 +8,7 @@
#include <formatter.hpp> #include <formatter.hpp>
#include <settings.hpp> #include <settings.hpp>
UploaderSingleton::UploaderSingleton() UploaderSingleton::UploaderSingleton() : QObject()
{ {
QDir configDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)); QDir configDir(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation));
configDir.mkpath("KShare/uploaders"); configDir.mkpath("KShare/uploaders");
@ -46,6 +46,7 @@ UploaderSingleton::UploaderSingleton()
void UploaderSingleton::registerUploader(Uploader *uploader) void UploaderSingleton::registerUploader(Uploader *uploader)
{ {
uploaders.insert(uploader->name(), uploader); uploaders.insert(uploader->name(), uploader);
emit newUploader(uploader);
} }
void UploaderSingleton::upload(QPixmap *pixmap) void UploaderSingleton::upload(QPixmap *pixmap)

View File

@ -4,8 +4,9 @@
#include "uploader.hpp" #include "uploader.hpp"
#include <QMap> #include <QMap>
class UploaderSingleton class UploaderSingleton : public QObject
{ {
Q_OBJECT
public: public:
static UploaderSingleton &inst() static UploaderSingleton &inst()
{ {
@ -18,6 +19,8 @@ class UploaderSingleton
void set(QString uploader); void set(QString uploader);
QString selectedUploader(); QString selectedUploader();
QList<std::runtime_error> errors(); QList<std::runtime_error> errors();
signals:
void newUploader(Uploader *u);
private: private:
UploaderSingleton(); UploaderSingleton();