Skip to content

Commit

Permalink
remove useless delete (handled by Qt), clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Mar 1, 2013
1 parent 387440a commit 14ebe0d
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 98 deletions.
16 changes: 2 additions & 14 deletions controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,11 @@ Controller::Controller(Settings* _data) : QObject(0)
srand(time(NULL));

m_poSettings = _data;
m_poMainTimer = new QTimer();
m_poMainWidget = NULL;
m_poMainTimer = new QTimer(this);

connect(m_poMainTimer, SIGNAL(timeout()), this, SLOT(vSlotUpdate()));
}

/*
* destructor
*/
Controller::~Controller()
{
delete m_poMainTimer;
}

/*
* update the wallpaper and start the timer
*/
Expand Down Expand Up @@ -68,10 +59,7 @@ void Controller::vSlotUpdate(bool _forcecheck)
{
m_poSettings->vUpdateSets();
m_poSettings->vReadNbWalls();
if (m_poMainWidget != NULL)
{
m_poMainWidget->vUpdateList();
}
emit listChanged();
}

int iTotalFiles = m_poSettings->iNbFiles();
Expand Down
6 changes: 2 additions & 4 deletions controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ class Controller : public QObject

private:
Settings* m_poSettings;
MainWidget* m_poMainWidget;
QTimer* m_poMainTimer;

public:
Controller(Settings* _data);
~Controller();

Settings* const &settings() { return m_poSettings; }

void vSetWidget(MainWidget* _w) { m_poMainWidget=_w; }

bool const bIsRunning() { return m_poMainTimer->isActive(); }
void vStartTimer(bool _forcecheck=false);
void vStartPause();
Expand All @@ -38,6 +34,8 @@ class Controller : public QObject
public slots:
void vSlotUpdate(bool _forcecheck=false);

signals:
void listChanged();
};

#endif // CONTROLLER_H
11 changes: 0 additions & 11 deletions errorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ ErrorWidget::ErrorWidget(QWidget* _parent, Controller* _poCtrl) : QWidget(_paren
setLayout(poMainLayout);
}

/*
* destructor
*/
ErrorWidget::~ErrorWidget()
{
if (m_poEditPath!=NULL)
{
delete m_poEditPath;
}
}

/*
* open file dialog
*/
Expand Down
1 change: 0 additions & 1 deletion errorwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ErrorWidget : public QWidget

public:
ErrorWidget(QWidget* _parent=0, Controller* _poCtrl=0);
~ErrorWidget();

public slots:
void vSlotBrowse();
Expand Down
37 changes: 15 additions & 22 deletions mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
MainWidget::MainWidget(QWidget* _parent, Controller* _poCtrl) : QWidget(_parent)
{
m_poCtrl = _poCtrl;
m_poCtrl->vSetWidget(this);

// main list
m_poList = new QListWidget();
Expand Down Expand Up @@ -58,36 +57,29 @@ MainWidget::MainWidget(QWidget* _parent, Controller* _poCtrl) : QWidget(_parent)
poMainLayout->addLayout(poRightCollumn, 1, 1);


// events
connect(poAddButton, SIGNAL(clicked()), this, SLOT(vSlotAddSet()));
connect(m_poActivateButton, SIGNAL(clicked()), this, SLOT(vSlotActivateSets()));
connect(m_poUnactivateButton, SIGNAL(clicked()), this, SLOT(vSlotUnactivateSets()));
connect(m_poDeleteButton, SIGNAL(clicked()), this, SLOT(vSlotDeleteSets()));
connect(poApplyButton, SIGNAL(clicked()), _parent, SLOT(vSlotApply()));
// buttons events
connect(poAddButton, SIGNAL(clicked()), this, SLOT(vSlotAddSet()));
connect(m_poActivateButton, SIGNAL(clicked()), this, SLOT(vSlotActivateSets()));
connect(m_poUnactivateButton, SIGNAL(clicked()), this, SLOT(vSlotUnactivateSets()));
connect(m_poDeleteButton, SIGNAL(clicked()), this, SLOT(vSlotDeleteSets()));
connect(poApplyButton, SIGNAL(clicked()), _parent, SLOT(vSlotApply()));

// list events
connect(m_poList, SIGNAL(itemSelectionChanged()), this, SLOT(vSlotSelectionChanged()));
connect(m_poList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(vSlotItemDoubleClicked()));

// spin box changed
connect(m_poDelayInput, SIGNAL(valueChanged(int)), this, SLOT(vSlotDelayChanged(int)));

// list updated by the controller
connect(m_poCtrl, SIGNAL(listChanged()), this, SLOT(vUpdateList()));


setLayout(poMainLayout);

vUpdateList();
}

/*
* destructor
*/
MainWidget::~MainWidget()
{
delete m_poDeleteButton;
delete m_poActivateButton;
delete m_poUnactivateButton;
delete m_poDelayInput;
delete m_poList;
}

/*
* update list widget contents
*/
Expand Down Expand Up @@ -150,7 +142,8 @@ void MainWidget::vSlotAddSet()
*/
void MainWidget::vSlotDeleteSets()
{
int ret = QMessageBox::warning(this, tr("Delete"), tr("Are you sure?"), QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Cancel);
int ret = QMessageBox::warning(this, tr("Delete"), tr("Are you sure?"),
QMessageBox::Cancel | QMessageBox::Ok, QMessageBox::Cancel);

if (ret == QMessageBox::Ok)
{
Expand All @@ -168,7 +161,7 @@ void MainWidget::vSlotActivateSets()

for (QList<int>::iterator i=list.begin(); i!=list.end(); i++)
{
m_poCtrl->settings()->poGetSet(*i)->vSetActive(true);
m_poCtrl->settings()->vSetState(*i, true);
QListWidgetItem* poItem = m_poList->item(*i);
poItem->setData(Qt::UserRole+2, true);
vSetListItemIcon(poItem, true);
Expand All @@ -187,7 +180,7 @@ void MainWidget::vSlotUnactivateSets()

for (QList<int>::iterator i=list.begin(); i!=list.end(); i++)
{
m_poCtrl->settings()->poGetSet(*i)->vSetActive(false);
m_poCtrl->settings()->vSetState(*i, false);
QListWidgetItem* poItem = m_poList->item(*i);
poItem->setData(Qt::UserRole+2, false);
vSetListItemIcon(poItem, false);
Expand Down
3 changes: 1 addition & 2 deletions mainwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ class MainWidget : public QWidget

public:
MainWidget(QWidget* _parent=0, Controller* _poCtrl=0);
~MainWidget();

void vUpdateList();
void vSetListItemIcon(QListWidgetItem* _poItem, bool _active);
QList<int> oGetSelectedIndexes();

public slots:
void vUpdateList();
void vSlotAddSet();
void vSlotDeleteSets();
void vSlotActivateSets();
Expand Down
58 changes: 24 additions & 34 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ MainWindow::MainWindow(Controller* _oCtrl) : QMainWindow(0)
}
}

/*
* destructor
*/
MainWindow::~MainWindow()
{
if (m_poCentralWidget != NULL) delete m_poCentralWidget;
if (m_poStatusBar != NULL) delete m_poStatusBar;
if (m_poMenuBar != NULL) delete m_poMenuBar;
if (m_poTrayIcon != NULL) delete m_poTrayIcon;
}

/*
* init window, called in the constructor and by ErrorWidget
*/
Expand Down Expand Up @@ -117,25 +106,26 @@ void MainWindow::vInit()

QAction* poOptionMinimize = m_poOptionsMenu->addAction(tr("Minimize on startup"));
QAction* poOptionCheck = m_poOptionsMenu->addAction(tr("Check files periodically"));
QAction* poOptionAutostart = m_poOptionsMenu->addAction(tr("Start with Windows"));

poOptionMinimize->setCheckable(true);
poOptionMinimize->setChecked(m_poCtrl->settings()->bMinimize());
poOptionCheck->setCheckable(true);
poOptionCheck->setChecked(m_poCtrl->settings()->bCheckFiles());

connect(poActionQuit1, SIGNAL(triggered()), this, SLOT(vSlotQuit()));
connect(m_poActionHide1, SIGNAL(triggered()), this, SLOT(vSlotToggleWindow()));
connect(m_poActionPause1, SIGNAL(triggered()), this, SLOT(vSlotStartPause()));
connect(poActionHelp, SIGNAL(triggered()), this, SLOT(vSlotShowHelp()));
connect(poOptionMinimize, SIGNAL(toggled(bool)), this, SLOT(vSlotOptionMinimizeChanged(bool)));
connect(poOptionCheck, SIGNAL(toggled(bool)), this, SLOT(vSlotOptionCheckChanged(bool)));

if (m_poCtrl->settings()->bCanAddShortcut())
poOptionAutostart->setCheckable(true);
poOptionAutostart->setChecked(m_poCtrl->settings()->bIsAutostart());

connect(poActionQuit1, SIGNAL(triggered()), this, SLOT(vSlotQuit()));
connect(m_poActionHide1, SIGNAL(triggered()), this, SLOT(vSlotToggleWindow()));
connect(m_poActionPause1, SIGNAL(triggered()), this, SLOT(vSlotStartPause()));
connect(poActionHelp, SIGNAL(triggered()), this, SLOT(vSlotShowHelp()));
connect(poOptionMinimize, SIGNAL(toggled(bool)), this, SLOT(vSlotOptionMinimizeChanged(bool)));
connect(poOptionCheck, SIGNAL(toggled(bool)), this, SLOT(vSlotOptionCheckChanged(bool)));
connect(poOptionAutostart, SIGNAL(toggled(bool)), this, SLOT(vSlotOptionAutostartChanged(bool)));

if (!(m_poCtrl->settings()->bCanAddShortcut()))
{
QAction* poOptionAutostart = m_poOptionsMenu->addAction(tr("Start with Windows"));
poOptionAutostart->setCheckable(true);
poOptionAutostart->setChecked(m_poCtrl->settings()->bIsAutostart());
connect(poOptionAutostart, SIGNAL(toggled(bool)), this, SLOT(vSlotOptionAutostartChanged(bool)));
poOptionAutostart->setVisible(false);
}

setMenuBar(m_poMenuBar);
Expand All @@ -158,7 +148,6 @@ void MainWindow::vInit()
if (m_poTrayIcon == NULL && iState == UM_OK)
{
m_poTrayIcon = new QSystemTrayIcon(QIcon(":/img/icon"), this);
m_poTrayIcon->setToolTip(APP_NAME);

connect(m_poTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(vSlotTrayAction(QSystemTrayIcon::ActivationReason)));

Expand All @@ -173,11 +162,12 @@ void MainWindow::vInit()
poActionRefresh->setIcon(QPixmap(":/img/refresh"));
m_poActionHide2->setIcon(QPixmap(":/img/hide"));

connect(poActionQuit2, SIGNAL(triggered()), this, SLOT(vSlotQuit()));
connect(m_poActionHide2, SIGNAL(triggered()), this, SLOT(vSlotToggleWindow()));
connect(m_poActionPause2, SIGNAL(triggered()), this, SLOT(vSlotStartPause()));
connect(poActionRefresh, SIGNAL(triggered()), this, SLOT(vSlotApply()));
connect(poActionQuit2, SIGNAL(triggered()), this, SLOT(vSlotQuit()));
connect(m_poActionHide2, SIGNAL(triggered()), this, SLOT(vSlotToggleWindow()));
connect(m_poActionPause2, SIGNAL(triggered()), this, SLOT(vSlotStartPause()));
connect(poActionRefresh, SIGNAL(triggered()), this, SLOT(vSlotApply()));

m_poTrayIcon->setToolTip(APP_NAME);
m_poTrayIcon->setContextMenu(poTrayMenu);
m_poTrayIcon->show();
}
Expand All @@ -203,16 +193,16 @@ void MainWindow::vSlotToggleWindow(bool _forcehide)
{
hide();

m_poCtrl->settings()->vSetWindowSize(size());
m_poCtrl->settings()->vWriteXML();

m_poActionHide2->setText(tr("Show"));

if (m_poCtrl->settings()->iMsgCount() < 3)
{
m_poTrayIcon->showMessage(APP_NAME, tr("%1 is still running").arg(APP_NAME));
m_poCtrl->settings()->vAddMsgCount();
}

m_poCtrl->settings()->vSetWindowSize(size());
m_poCtrl->settings()->vWriteXML();

m_poActionHide2->setText(tr("Show"));
}
else
{
Expand Down
1 change: 0 additions & 1 deletion mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class MainWindow : public QMainWindow

public:
MainWindow(Controller* _oCtrl);
~MainWindow();

void vInit();

Expand Down
26 changes: 17 additions & 9 deletions settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,22 +486,31 @@ QString Settings::sRenameSet(short int _i, const QString &_name, bool _returnFul
return "";
}

/*
* set the state of a set
*/
void Settings::vSetState(short int _i, bool _a)
{
m_bUnsaved = true;
m_oSets.at(_i)->vSetActive(_a);
}

/*
* remove unexisting sets and update file lists
*/
void Settings::vUpdateSets()
{
for (int i=0; i<iNbSets(); i++)
for (QVector<Set*>::iterator it=m_oSets.begin(); it!=m_oSets.end(); )
{
Set* poSet = m_oSets.at(i);
if (!bDirectoryExists(poSet->path().toStdString()))
if (!bDirectoryExists((*it)->path().toStdString()))
{
vDeleteSet(i);
i--;
m_bUnsaved = true;
m_oSets.erase(it);
}
else
{
poSet->vPopulateFiles();
(*it)->vPopulateFiles();
it++;
}
}
}
Expand All @@ -514,10 +523,9 @@ int const Settings::iNbFiles()
int iTotalFiles = 0;
for (QVector<Set*>::iterator it=m_oSets.begin(); it!=m_oSets.end(); ++it)
{
Set* poSet = *it;
if (poSet->isActive())
if ((*it)->isActive())
{
iTotalFiles+= poSet->count();
iTotalFiles+= (*it)->count();
}
}
return iTotalFiles;
Expand Down
1 change: 1 addition & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Settings
void vDeleteSets(const QList<int> &_list);
void vDeleteAll();
QString sRenameSet(short int _i, const QString &_name, bool _returnFull);
void vSetState(short int _i, bool _a);
void vUpdateSets();

void vCreateShortcut();
Expand Down

0 comments on commit 14ebe0d

Please sign in to comment.