Skip to content

Commit 95e593a

Browse files
committed
Various fixes for #20
1 parent 3aadc1f commit 95e593a

File tree

9 files changed

+79
-86
lines changed

9 files changed

+79
-86
lines changed

installer/package.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"C:\Program Files\7-Zip\7z.exe" a UMWP_Autochanger_2.1.zip ./data/* -x!*.ico
1+
"C:\Program Files\7-Zip\7z.exe" a UMWP_Autochanger_2.2.zip ./data/* -x!*.ico

installer/setup.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define AppId "{401CCECB-FFCC-4AF3-846D-A535F59D0834}"
22
#define AppName "UMWP Autochanger"
3-
#define AppVersion "2.1"
3+
#define AppVersion "2.2"
44
#define AppPublisher "StrangePlanet"
55
#define PublisherURL "http://www.strangeplanet.fr"
66
#define ProjectURL "http://www.strangeplanet.fr/work/umwp-autochanger"

src/customlayoutgenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ QList<QRect> CustomLayoutGenerator::generate(const CustomLayout &_conf)
8585

8686
// compute the surface occupied by all pool items
8787
int poolSurface = 0;
88-
foreach (const QRect block, pool)
88+
foreach (const QRect &block, pool)
8989
poolSurface+= block.width() * block.height();
9090

9191
// compute how many times each item must be duplicated in the pool
9292
// in order to fill the whole surface
9393
int nbPool = poolSurface==0 ? 0 : qCeil(totalSurface / poolSurface);
9494

9595
// actually duplicate the items
96-
foreach (const QRect block, pool)
96+
foreach (const QRect &block, pool)
9797
for (int k=0; k<nbPool; k++)
9898
pool.append(block);
9999

src/gui/previewdialog.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,25 @@ void PreviewDialog::draw()
5454

5555
WallpaperGenerator::Result current = m_ctrl->current();
5656

57-
int width = 100;
58-
if (current.type == UM::W_DESKTOP)
57+
int width;
58+
if (current.type == UM::W_DESKTOP && current.sets.at(0)->style() != UM::IM_CUSTOM)
5959
{
60-
width*= m_ctrl->settings()->nbEnabledMonitors();
60+
width = 200 * m_ctrl->settings()->nbEnabledMonitors();
61+
}
62+
else if (current.files.size() <= 4)
63+
{
64+
width = 150;
65+
}
66+
else
67+
{
68+
width = 100;
6169
}
6270

6371
int col = 0; int row = 0;
6472

6573
bool showEdit = !m_settings->param(UM::CONF::open_program).toString().isEmpty();
6674

67-
foreach (QString file, current.files)
75+
foreach (const QString &file, current.files)
6876
{
6977
if (file.isEmpty())
7078
{

src/set.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ Set::Set(const QDomElement* _dom)
5050
m_mode = static_cast<UM::MODE>(_dom->attribute("mode").toInt());
5151
}
5252

53-
// added in 2.1.1
53+
// added in 2.2
5454
if (_dom->hasAttribute("frequency"))
5555
{
5656
m_frequency = _dom->attribute("frequency").toDouble();
5757
}
5858

59-
// added in 2.1.1
60-
if (_dom->hasAttribute("monitors"))
59+
// added in 2.2
60+
if (_dom->hasAttribute("monitors") && !_dom->attribute("monitors").isEmpty())
6161
{
6262
QStringList monitors = _dom->attribute("monitors").split(",");
6363
foreach (QString monitor, monitors)

src/settings.cpp

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const int Settings::nbEnabledMonitors() const
9090
{
9191
int n = 0;
9292

93-
foreach (const UM::Monitor mon, m_monitors)
93+
foreach (const UM::Monitor &mon, m_monitors)
9494
{
9595
if (mon.enabled) n++;
9696
}
@@ -115,15 +115,14 @@ void Settings::log()
115115
hotkeys.append(it.key() +": "+ QString::number(it.value()));
116116
}
117117

118-
QList<QString> sets;
119-
for (QVector<Set*>::const_iterator it = m_sets.constBegin(); it != m_sets.constEnd(); ++it)
120-
{
121-
sets.append((*it)->name()+": "+((*it)->isActive()?"active":"inactive"));
122-
}
123-
124118
QLOG_DEBUG() << "== OPTIONS" << options;
125119
QLOG_DEBUG() << "== HOTKEYS" << hotkeys;
126-
QLOG_DEBUG() << "== SETS" << sets;
120+
QLOG_DEBUG() << "== SETS";
121+
122+
foreach (Set* set, m_sets)
123+
{
124+
QLOG_DEBUG()<<" "<<set->name()<<(set->isActive()?"active":"inactive")<<","<<set->nbFiles()<<"files,"<<set->nbFolders()<<"folders";
125+
}
127126
}
128127

129128
/**
@@ -287,14 +286,14 @@ bool Settings::load(QString _filename)
287286
save();
288287
}
289288

290-
if (QsLogging::Logger::instance().loggingLevel() != QsLogging::OffLevel)
289+
foreach (Set* set, m_sets)
291290
{
292-
log();
291+
set->init();
293292
}
294293

295-
foreach (Set* set, m_sets)
294+
if (QsLogging::Logger::instance().loggingLevel() != QsLogging::OffLevel)
296295
{
297-
set->init();
296+
log();
298297
}
299298

300299
return true;
@@ -363,7 +362,7 @@ bool Settings::save(QString _filename)
363362
// monitors node
364363
writer.writeStartElement("monitors");
365364

366-
foreach (const UM::Monitor mon, m_monitors)
365+
foreach (const UM::Monitor &mon, m_monitors)
367366
{
368367
writer.writeStartElement("monitor");
369368
writer.writeAttribute("enabled", QString::number(mon.enabled));
@@ -597,45 +596,6 @@ int const Settings::nbActiveSets() const
597596
return totalSets;
598597
}
599598

600-
/**
601-
* @brief Get one of the active sets on a monitor
602-
* @param int _i - position in the sub-vector of active sets
603-
* @return Set*
604-
*/
605-
Set* Settings::activeSetOnMonitor(int _i, int _monitor) const
606-
{
607-
QVector<Set*> activeSets;
608-
609-
foreach (Set* set, m_sets)
610-
{
611-
if (set->isValid() && set->isActive() && set->isActiveOnMonitor(_monitor) && set->nbFiles() > 0)
612-
{
613-
activeSets.append(set);
614-
}
615-
}
616-
617-
return activeSets.at(_i);
618-
}
619-
620-
/**
621-
* @brief Get the number of active sets on a monitor
622-
* @return int
623-
*/
624-
int const Settings::nbActiveSetsOnMonitor(int _monitor) const
625-
{
626-
int totalSets = 0;
627-
628-
foreach (const Set* set, m_sets)
629-
{
630-
if (set->isValid() && set->isActive() && set->isActiveOnMonitor(_monitor) && set->nbFiles() > 0)
631-
{
632-
totalSets++;
633-
}
634-
}
635-
636-
return totalSets;
637-
}
638-
639599
/**
640600
* @brief Build sets hotkeys when migrating from version 1.3
641601
* @param int WinMod

src/settings.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class Settings
4141
const int nbSets() const { return m_sets.size(); }
4242
Set* activeSet(int _i) const;
4343
const int nbActiveSets() const;
44-
Set* activeSetOnMonitor(int _i, int _monitor) const;
45-
const int nbActiveSetsOnMonitor(int _monitor) const;
4644

4745
// setters
4846
void setParam(const QString &_key, const QVariant &_val) { m_options[_key] = _val; }

src/wallpapergenerator.cpp

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ WallpaperGenerator::Result WallpaperGenerator::generate()
4242

4343
WallpaperGenerator::Result result;
4444

45-
Set* tempSet = getRandomSet(-1, QVector<Set*>());
45+
Set* tempSet = getRandomSet();
4646

4747
if (tempSet == NULL)
4848
{
@@ -88,14 +88,11 @@ WallpaperGenerator::Result WallpaperGenerator::generate()
8888
tempFiles.append(getFile(0, &result));
8989
}
9090

91+
m_enviro->setWallpaper(generateFile(tempFiles, &result));
92+
9193
QLOG_DEBUG() << "Current type:" << result.type;
9294
QLOG_DEBUG() << "Current sets:" << result.sets;
9395
QLOG_DEBUG() << "Current files:" << result.files;
94-
95-
QString filepath = generateFile(tempFiles, &result);
96-
97-
m_enviro->setWallpaper(filepath);
98-
9996
QLOG_INFO() << "Wallpaper generated in" << timer.elapsed() << "milliseconds";
10097

10198
return result;
@@ -143,7 +140,13 @@ Set* WallpaperGenerator::getRandomSet(const int _monitor, const QVector<Set*> &_
143140
for (int i=0; i<nbSets; i++)
144141
{
145142
Set* set = sets.at(i);
143+
146144
int setWeight = qRound(set->nbFiles() * set->frequency());
145+
if (set->type() == UM::W_DESKTOP && set->style() != UM::IM_CUSTOM)
146+
{
147+
setWeight*= m_settings->nbEnabledMonitors();
148+
}
149+
147150
nbWalls.append(nbWalls.last() + setWeight);
148151
}
149152

@@ -217,13 +220,13 @@ QString WallpaperGenerator::getFile(int _idx, Result* _context)
217220
* @param Set* _set
218221
* @return string
219222
*/
220-
QString WallpaperGenerator::getRandomFolder(Set *_set)
223+
QString WallpaperGenerator::getRandomFolder(Set* _set)
221224
{
222225
int nbFolders = _set->nbFolders();
223226

224227
if (nbFolders == 0)
225228
{
226-
return _set->path();
229+
return "";
227230
}
228231

229232
if (nbFolders == 1)
@@ -241,7 +244,7 @@ QString WallpaperGenerator::getRandomFolder(Set *_set)
241244
* @brief Get a file in set a position _idx and adapt it for the monitor
242245
* @param int _idx
243246
* @param Result* _context
244-
* @return
247+
* @return string
245248
*/
246249
QString WallpaperGenerator::getAndAdaptFile(int _idx, Result* _context)
247250
{
@@ -275,7 +278,7 @@ QString WallpaperGenerator::getAndAdaptFile(int _idx, Result* _context)
275278
* @param Set* _set
276279
* @param int _nb
277280
* @param Result* _context
278-
* @return
281+
* @return string[]
279282
*/
280283
QVector<QString> WallpaperGenerator::getFilesForCustom(Set* _set, int _nb, Result* _context)
281284
{
@@ -293,7 +296,7 @@ QVector<QString> WallpaperGenerator::getFilesForCustom(Set* _set, int _nb, Resul
293296

294297
for (int i=0; i<_nb; i++)
295298
{
296-
files.append(getRandomFile(_set, folder));
299+
files.append(getRandomFile(_set, folder, files));
297300
}
298301

299302
if (layout.perFolder)
@@ -363,7 +366,7 @@ QString WallpaperGenerator::getNextFile(Set* _set)
363366
* @param string _folder optional
364367
* @return string
365368
*/
366-
QString WallpaperGenerator::getRandomFile(Set *_set, const QString &_folder)
369+
QString WallpaperGenerator::getRandomFile(Set* _set, const QString &_folder, const QVector<QString> &_files)
367370
{
368371
int totalFiles = _set->nbFilesInFolder(_folder);
369372

@@ -379,13 +382,35 @@ QString WallpaperGenerator::getRandomFile(Set *_set, const QString &_folder)
379382
}
380383

381384
std::uniform_int<int> unif(0, totalFiles-1);
382-
int counter = unif(m_randomEngine);
383385

384-
return _set->fileInFolder(_folder, counter);
386+
// search a random unused file
387+
short loop = 10; // the collisions detection will only try 10 times
388+
QString file;
389+
390+
// if all files are already used, disable collisions detection
391+
if (totalFiles <= _files.size())
392+
{
393+
loop = 1;
394+
}
395+
396+
while (loop > 0)
397+
{
398+
loop--;
399+
400+
int counter = unif(m_randomEngine);
401+
file = _set->fileInFolder(_folder, counter);
402+
403+
if (!_files.contains(file))
404+
{
405+
loop = 0;
406+
}
407+
}
408+
409+
return file;
385410
}
386411

387412
/**
388-
* @brief Generate one custom layout file for set at position _idx
413+
* @brief Generate one custom layout file for the set at position _idx
389414
* @param int _idx
390415
* @param Result* _context
391416
* @return string
@@ -412,7 +437,7 @@ QString WallpaperGenerator::generateCustomFile(int _idx, WallpaperGenerator::Res
412437
double wRatio = scrRect.width() / (double) layout.cols;
413438
double hRatio = scrRect.height() / (double) layout.rows;
414439

415-
foreach (const QRect block, rawBlocks)
440+
foreach (const QRect &block, rawBlocks)
416441
{
417442
QRect newBlock = UM::scaledRect(block, wRatio, hRatio);
418443

@@ -432,6 +457,8 @@ QString WallpaperGenerator::generateCustomFile(int _idx, WallpaperGenerator::Res
432457
// get necessary files from set
433458
QVector<QString> files = getFilesForCustom(set, blocks.size(), _context);
434459

460+
QLOG_DEBUG()<<"Custom sources:"<<files;
461+
435462
QImage image(scrRect.size(), QImage::Format_RGB32);
436463
QPainter painter(&image);
437464

@@ -463,9 +490,9 @@ QString WallpaperGenerator::generateCustomFile(int _idx, WallpaperGenerator::Res
463490
pen.setWidth(layout.borderWidth);
464491
painter.setPen(pen);
465492

466-
foreach (const QRect block, blocks)
493+
foreach (const QRect &block, blocks)
467494
{
468-
foreach (const QLine line, UM::rectBorders(block))
495+
foreach (const QLine &line, UM::rectBorders(block))
469496
{
470497
if (
471498
(line.x1()==0 && line.x2()==0) ||
@@ -773,7 +800,7 @@ QString WallpaperGenerator::generateFile(const QVector<QString> &_files, Result*
773800

774801
/**
775802
* @brief Compute the total size of enabled monitors
776-
* @return QRect
803+
* @return QRect
777804
*/
778805
QRect WallpaperGenerator::getDesktopEnabledRect()
779806
{

src/wallpapergenerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class WallpaperGenerator : public QObject
4646

4747
// random access
4848
QString getFile(int _idx, Result* _context);
49-
Set* getRandomSet(const int _monitor, const QVector<Set*> &_existingSets);
49+
Set* getRandomSet(const int _monitor=-1, const QVector<Set*> &_existingSets=QVector<Set*>());
5050
QString getRandomFolder(Set* _set);
51-
QString getRandomFile(Set* _set, const QString &_folder="");
51+
QString getRandomFile(Set* _set, const QString &_folder="", const QVector<QString> &_files=QVector<QString>());
5252
QString getNextFile(Set* _set);
5353

5454
// custom generation

0 commit comments

Comments
 (0)