Skip to content

Commit bd9378d

Browse files
committed
add option to disable wallpaper support on certain monitor
+ buttons to delete files from preview dialog
1 parent 3c1d730 commit bd9378d

31 files changed

+2122
-487
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ You will need Qt 4.8.4 and libqxt 0.6.2
6060

6161

6262
## Changelog
63+
* 1.8
64+
* new: disable wallpaper support on specific monitors
65+
* new: choose background of each monitor
66+
* new: "Delete" button on "Active files" dialog
67+
* new: auto-update process
68+
* fixed: crash after changing delay
69+
6370
* [1.7 (01/08/2014)](http://www.strangeplanet.fr/work/umwp-autochanger/download.php?ver=1.7)
6471
* new: add "Fill" mode
6572
* new: create default.wallpaper file if not present

installer/setup.iss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Name: "{userstartup}\{#AppName}"; Filename: "{app}\{#AppExeName}"; Tasks: autost
6262
[Run]
6363
Filename: "{app}\{#AppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(AppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
6464

65+
[InstallDelete]
66+
Type: filesandordirs; Name: "{app}\cache";
67+
Type: files; Name: "{app}\debug.log";
68+
6569
[UninstallDelete]
6670
Type: filesandordirs; Name: "{app}\cache";
6771
Type: files; Name: "{app}\debug.log";

src/UMWP_Autochanger.pro

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ SOURCES += \
2424
gui/previewdialog.cpp \
2525
gui/newversiondialog.cpp \
2626
gui/menubar.cpp \
27-
gui/trayicon.cpp
27+
gui/trayicon.cpp \
28+
gui/screensdialog.cpp \
29+
wallpapergenerator.cpp
2830

2931
HEADERS += \
3032
ext/qlineedithotkey.h \
@@ -51,14 +53,17 @@ HEADERS += \
5153
gui/previewdialog.h \
5254
gui/newversiondialog.h \
5355
gui/menubar.h \
54-
gui/trayicon.h
56+
gui/trayicon.h \
57+
gui/screensdialog.h \
58+
wallpapergenerator.h
5559

5660
FORMS += \
5761
ext/qhotkeywidget.ui \
5862
gui/mainwidget.ui \
5963
gui/seteditdialog.ui \
6064
gui/configdialog.ui \
61-
gui/newversiondialog.ui
65+
gui/newversiondialog.ui \
66+
gui/screensdialog.ui
6267

6368
RESOURCES += \
6469
UMWP_Autochanger.qrc

src/UMWP_Autochanger.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<file alias="images">images/icons/images.png</file>
2828
<file alias="help-color">images/icons/help_color.png</file>
2929
<file alias="bullet_cross">images/icons/bullet_cross.png</file>
30+
<file alias="color">images/icons/color.png</file>
3031
</qresource>
3132
<qresource prefix="/button">
3233
<file alias="activate">images/buttons/button_activate.png</file>

src/controller.cpp

Lines changed: 33 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <ctime>
21
#include <iostream>
32
#include <fstream>
43

@@ -18,7 +17,7 @@ Controller::Controller(Settings* _settings, Environment* _enviro) :
1817
m_enviro(_enviro),
1918
m_set(NULL)
2019
{
21-
m_randomEngine.seed((unsigned int)time(NULL));
20+
m_generator = new WallpaperGenerator(this);
2221

2322
m_mainTimer = new QTimer(this);
2423
connect(m_mainTimer, SIGNAL(timeout()), this, SLOT(onUpdate()));
@@ -107,58 +106,53 @@ bool Controller::startPause()
107106
/**
108107
* @brief Update the wallpaper
109108
*/
110-
void Controller::onUpdate()
109+
void Controller::onUpdate(bool _forceRefresh)
111110
{
112111
qxtLog->info("Update !");
113112

114113
// update delay if needed
115114
int delay = m_settings->get("delay").toInt()*1000;
116115
if (delay != m_mainTimer->interval())
117116
{
118-
qxtLog->debug("Timer delay changed to: "+delay);
117+
qxtLog->debug("Timer delay changed to: "+QString::number(delay));
119118
m_mainTimer->setInterval(delay);
120119
}
121120

122121
// update config
123-
if (m_settings->get("check").toBool())
122+
if (_forceRefresh || m_settings->get("check").toBool())
124123
{
125124
m_settings->updateSets();
126125
m_enviro->refreshMonitors();
127126
emit listChanged(false);
128127
}
129128

130-
int totalSets = m_settings->nbActiveSets(true);
129+
// get random files
130+
m_set = m_generator->getRandomSet();
131131

132-
if (totalSets == 0)
132+
if (m_set == NULL)
133133
{
134134
qxtLog->warning("No active set");
135135
return;
136136
}
137137

138-
// get random files
139-
m_set = getRandomSet(totalSets);
140138
qxtLog->debug("Current set: "+m_set->name());
141139

142-
m_files.clear();
140+
m_files = m_generator->getFiles(m_set);
143141

144-
if (m_set->type() == UM::W_MONITOR)
142+
if (qxtLog->isLogLevelEnabled("debug", QxtLogger::DebugLevel))
145143
{
146-
for (int i=0, l=m_enviro->get("nb_monitors").toInt(); i<l; i++)
144+
foreach (QString file, m_files)
147145
{
148-
m_files.append(getRandomFile(m_set));
146+
qxtLog->debug("Current file: "+file);
149147
}
150148
}
151-
else
152-
{
153-
m_files.append(getRandomFile(m_set));
154-
}
155149

156-
QVector<QString> files = adaptFilesToFillMode(m_files, m_set);
150+
QVector<QString> tempFiles = m_generator->adaptFiles(m_set, m_files);
157151

158152
QString filename = m_enviro->get("wallpath").toString() + QString::fromAscii(APP_WALLPAPER_FILE);
159153

160154
// generate .wallpaper file
161-
generateFile(filename, files, m_set);
155+
generateFile(filename, tempFiles, m_set);
162156

163157
// remove old BMP file
164158
QFile::remove(m_enviro->get("bmppath").toString());
@@ -172,70 +166,6 @@ void Controller::onUpdate()
172166
emit wallpaperChanged();
173167
}
174168

175-
/**
176-
* @brief Get a random Set among all active sets
177-
* @param int _total - total number of Sets
178-
* @return Set*
179-
*/
180-
Set* Controller::getRandomSet(int _total)
181-
{
182-
if (_total == 1)
183-
{
184-
return m_settings->activeSet(0);
185-
}
186-
187-
uniform_int<int> unif(0, _total-1);
188-
int counter = unif(m_randomEngine);
189-
190-
return m_settings->activeSet(counter);
191-
}
192-
193-
/**
194-
* @brief Get a random file within a Set
195-
* @param Set* _set
196-
* @return string
197-
*/
198-
QString Controller::getRandomFile(Set* _set)
199-
{
200-
int total = _set->count();
201-
202-
// only one file in the set ?!
203-
if (total == 1)
204-
{
205-
return _set->file(0);
206-
}
207-
208-
// rare case for very small sets
209-
if (total <= m_files.size())
210-
{
211-
uniform_int<int> unif(0, m_files.size()-1);
212-
int counter = unif(m_randomEngine);
213-
return m_files.at(counter);
214-
}
215-
216-
// search a random unused file
217-
short loop = 10;
218-
QString file;
219-
uniform_int<int> unif(0, total-1);
220-
221-
while (loop > 0)
222-
{
223-
int counter = unif(m_randomEngine);
224-
file = _set->file(counter);
225-
226-
if (!m_files.contains(file))
227-
{
228-
loop = 0;
229-
}
230-
231-
loop--;
232-
}
233-
234-
qxtLog->debug("Current file: "+file);
235-
236-
return file;
237-
}
238-
239169
/**
240170
* @brief Generate AutoChanger.wallpaper file
241171
* @param string _filename
@@ -266,12 +196,16 @@ void Controller::generateFile(const QString &_filename, const QVector<QString> &
266196
{
267197
UM::WP_MONITOR_FILE wall;
268198
wall.bgType = UM::BG_SOLID;
269-
wall.color1 = 0x00000000;
199+
wall.color1 = m_settings->monitor(i).color;
270200
wall.color2 = 0x00000000;
271201
wall.imgStyle = wp_style;
272202

273203
memset(wall.imgFile, 0, 260*sizeof(wchar_t));
274-
_files.at(i).toWCharArray((wchar_t*)wall.imgFile);
204+
205+
if (!_files.at(i).isEmpty())
206+
{
207+
_files.at(i).toWCharArray((wchar_t*)wall.imgFile);
208+
}
275209

276210
buffer.append((char*)&wall, sizeof(UM::WP_MONITOR_FILE));
277211
}
@@ -284,73 +218,23 @@ void Controller::generateFile(const QString &_filename, const QVector<QString> &
284218
}
285219

286220
/**
287-
* @brief Resize image files and return an array of new paths in cache folder
288-
* @param string[] _files
289-
* @param Set* _set
290-
* @return string[] _files
221+
* @brief Move a file to trash bin
222+
* @param string _filename
223+
* @return bool
291224
*/
292-
QVector<QString> Controller::adaptFilesToFillMode(const QVector<QString> &_files, const Set* _set)
225+
bool Controller::moveFileToTrash(const QString &_filename)
293226
{
294-
if (_set->style() != UM::IM_FILL)
295-
{
296-
return _files;
297-
}
227+
wchar_t path[MAX_PATH];
228+
memset(path, 0, sizeof(path));
229+
int l = _filename.toWCharArray(path);
230+
path[l] = '\0';
298231

299-
QVector<QString> newFiles;
300-
int nb_walls = _files.size();
232+
SHFILEOPSTRUCT shfos = {0};
233+
shfos.wFunc = FO_DELETE;
234+
shfos.pFrom = path;
235+
shfos.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
301236

302-
QString tmpRoot = QDir::toNativeSeparators(QFileInfo(QString::fromAscii(APP_CACHE_DIR)).absoluteFilePath()+"/");
303-
304-
for (int i=0; i<nb_walls; i++)
305-
{
306-
// target size
307-
QSize size;
308-
if (_set->type() == UM::W_DESKTOP)
309-
{
310-
size = m_enviro->wpSize(-1);
311-
}
312-
else
313-
{
314-
size = m_enviro->wpSize(i);
315-
}
316-
317-
if (!size.isEmpty())
318-
{
319-
QFileInfo file(_files.at(i));
320-
QString tmpPath = tmpRoot+file.completeBaseName()+"-"+QString::number(size.width())+"x"+QString::number(size.height())+"."+file.suffix();
321-
322-
if (!QFile::exists(tmpPath))
323-
{
324-
QImage image(file.absoluteFilePath());
325-
326-
// if image ratio is almost the same, do not waste time in image croppping
327-
double curRatio = (double)image.size().width()/image.size().height();
328-
double targetRatio = (double)size.width()/size.height();
329-
330-
if (qAbs(curRatio - targetRatio) < 0.02)
331-
{
332-
newFiles.append(_files.at(i));
333-
continue;
334-
}
335-
336-
// scale
337-
image = image.scaled(size, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
338-
339-
// crop
340-
int diffW = image.width()-size.width();
341-
int diffH = image.height()-size.height();
342-
image = image.copy(diffW/2, diffH/2, size.width(), size.height());
343-
344-
image.save(tmpPath);
345-
}
346-
347-
newFiles.append(tmpPath);
348-
}
349-
else
350-
{
351-
newFiles.append(_files.at(i));
352-
}
353-
}
237+
int ret = SHFileOperation(&shfos);
354238

355-
return newFiles;
239+
return ret == 0;
356240
}

src/controller.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#ifndef CONTROLLER_H
22
#define CONTROLLER_H
33

4-
#include <random>
54
#include <QTimer>
65

7-
using namespace std::tr1;
8-
96
#include "main.h"
107
#include "set.h"
118
#include "settings.h"
129
#include "environment.h"
1310
#include "versionchecker.h"
11+
#include "wallpapergenerator.h"
1412

1513

1614
/**
@@ -23,9 +21,9 @@ class Controller : public QObject
2321
private:
2422
Settings* m_settings;
2523
Environment* m_enviro;
24+
WallpaperGenerator* m_generator;
2625

2726
QTimer* m_mainTimer;
28-
mt19937 m_randomEngine; // mersenne_twister
2927

3028
QVector<QString> m_files;
3129
Set* m_set;
@@ -49,14 +47,13 @@ class Controller : public QObject
4947

5048
void emitListChanged(bool _resetSel=false) { emit listChanged(_resetSel); }
5149

50+
bool moveFileToTrash(const QString &_filename);
51+
5252
private:
53-
Set* getRandomSet(int _total);
54-
QString getRandomFile(Set* _set);
55-
void generateFile(const QString &_filename, const QVector<QString> &_files, const Set* _set);
56-
QVector<QString> adaptFilesToFillMode(const QVector<QString> &_files, const Set* _set);
53+
void generateFile(const QString &_filename, const QVector<QString> &_files, const Set* _set);
5754

5855
public slots:
59-
void onUpdate();
56+
void onUpdate(bool _forceRefresh=false);
6057

6158
private slots:
6259
void onNewVersion(const QString &_ver, const QString &_link);

0 commit comments

Comments
 (0)