3131
3232#include < QDebug>
3333
34+ #include < QApplication>
35+ #include < QtGlobal>
36+ #include < QtDebug>
37+ #include < QTextStream>
38+ #include < QTextCodec>
39+ #include < QLocale>
40+ #include < QTime>
41+
3442
3543Controller::Controller (QObject *parent) : QObject(parent)
3644{
@@ -84,13 +92,17 @@ void Controller::readSettings()
8492
8593 settings->beginGroup (" LastSelection" );
8694 steamDir = settings->value (" SteamDir" , defaultSteamDir).toString ();
87- if ( QDir (steamDir).exists () )
95+ if (QDir (steamDir).exists ())
8896 emit sendLabelsText (QStringList () << " label_steamDirValue" , convertSlashes (steamDir));
8997 else
9098 emit sendLabelsText (QStringList () << " label_steamDirValue" , " Not found, please locate manually" );
9199 lastSelectedScreenshotDir = settings->value (" Screenshots" , QDir::currentPath ()).toString ();
92100 lastSelectedUserID = settings->value (" UserID" ).toString ();
93101 lastSelectedGameID = settings->value (" GameID" ).toString ();
102+ quint32 jpegQuality = settings->value (" JPEGQuality" ).toInt ();
103+ if (jpegQuality < 1 || jpegQuality > 100 )
104+ jpegQuality = defaultJpegQuality;
105+ emit sendJpegQualityValue (jpegQuality);
94106 settings->endGroup ();
95107
96108 settings->beginGroup (" Screenshots" );
@@ -103,7 +115,7 @@ void Controller::readSettings()
103115}
104116
105117
106- void Controller::writeSettings (QSize size, QPoint pos, QString userID, QString gameID)
118+ void Controller::writeSettings (QSize size, QPoint pos, QString userID, QString gameID, quint32 jpegQuality )
107119{
108120 settings->beginGroup (" WindowGeometry" );
109121 settings->setValue (" Size" , size);
@@ -117,6 +129,7 @@ void Controller::writeSettings(QSize size, QPoint pos, QString userID, QString g
117129 settings->setValue (" UserID" , userID);
118130 if ( !gameID.isEmpty () )
119131 settings->setValue (" GameID" , gameID);
132+ settings->setValue (" JPEGQuality" , jpegQuality);
120133 settings->endGroup ();
121134
122135 settings->beginGroup (" Screenshots" );
@@ -136,7 +149,7 @@ void Controller::checkForUpdates()
136149
137150void Controller::handleUpdate (QNetworkReply *reply)
138151{
139- if ( reply->error () == QNetworkReply::NoError ) {
152+ if (reply->error () == QNetworkReply::NoError) {
140153
141154 QByteArray raw = reply->readAll ();
142155 QJsonDocument doc (QJsonDocument::fromJson (raw));
@@ -167,6 +180,7 @@ void Controller::writeSettingNeverOfferUpdate()
167180void Controller::setUserDataPaths (QString dir) // function to validate and set data paths and IDs
168181{
169182 userDataDir = dir + " /userdata" ;
183+
170184 QStringList userIDsCombined;
171185
172186 vdfPaths.clear (); // there may be multiple Steam installations in the system and thus multiple VDFs
@@ -191,19 +205,24 @@ void Controller::setUserDataPaths(QString dir) // function to validate and set
191205
192206 emit sendWidgetsDisabled (widgetList << " groupBox_screenshotQueue" << " treeWidget_screenshotList" , false );
193207 emit sendLabelsText (QStringList () << " label_steamDirValue" , convertSlashes (dir));
194- emit sendLabelsVisible (QStringList () << " label_status" , false );
195208
196209 steamDir = dir;
197210
198211 QStringList userIDsCombinedWithNames;
199212 QListIterator<QString> i (vdfPaths);
200213 while ( i.hasNext () ) {
201214 QString current = i.next ();
215+
202216 QStringList splitted = current.split (' /' );
217+
203218 userID = splitted.takeAt (splitted.length () - 3 );
219+
204220 someID = splitted.takeAt (splitted.length () - 2 );
221+
205222 userIDsCombined << userID + " /" + someID;
223+
206224 QString personalName = getPersonalNameByUserID (userID);
225+
207226 userIDsCombinedWithNames << userID + " /" + someID + personalName;
208227 }
209228
@@ -220,6 +239,7 @@ void Controller::setUserDataPaths(QString dir) // function to validate and set
220239 items = userIDsCombinedWithNames.replaceInStrings (" /" , " \\ " );
221240 userID = userID.replace (" /" , " \\ " );
222241 }
242+
223243 selectedUserID = userID;
224244
225245 emit sendToComboBox (" comboBox_userID" , items);
@@ -228,18 +248,23 @@ void Controller::setUserDataPaths(QString dir) // function to validate and set
228248
229249 emit sendToComboBox (" comboBox_gameID" , QStringList () << " loading..." );
230250
251+ emit sendStatusLabelText (" ready" , " " );
252+ emit sendLabelsVisible (QStringList () << " label_status" , true );
253+
231254 QNetworkAccessManager *nam = new QNetworkAccessManager (this );
232255
233256 QObject::connect (nam, &QNetworkAccessManager::finished,
234257 this , &Controller::getGameNames);
235258
236259 nam->get (QNetworkRequest (QUrl (" http://api.steampowered.com/ISteamApps/GetAppList/v2" )));
237260
238- } else
261+ } else {
239262 emit sendLabelsOnMissingStuff (false , vdfFilename);
263+ }
240264
241- } else
265+ } else {
242266 emit sendLabelsOnMissingStuff (true , vdfFilename);
267+ }
243268}
244269
245270
@@ -250,6 +275,7 @@ QString Controller::getPersonalNameByUserID(QString userID)
250275 {
251276 QDirIterator i (userDataDir + " /" + userID, QStringList () << " config.cfg" , QDir::Files, QDirIterator::Subdirectories);
252277 while ( i.hasNext () ) {
278+
253279 configFiles << i.next ();
254280 }
255281 }
@@ -265,17 +291,21 @@ QString Controller::getPersonalNameByUserID(QString userID)
265291
266292 while ( !text.atEnd () ) {
267293 QString line = text.readLine ();
294+
268295 lines << line;
269296 }
270297
271298 vdf.close ();
272299
273300 QRegularExpression re (" ^name \" (?<name>.+)\" $" );
274301 int pos = lines.indexOf (re);
302+
275303 QRegularExpressionMatch matchNew;
276304
277- if ( (lines[pos].contains (re, &matchNew)) )
305+ if ( pos != -1 && (lines[pos].contains (re, &matchNew)) ) {
306+
278307 return " <" + matchNew.captured (" name" ) + " >" ;
308+ }
279309 }
280310
281311 return " " ;
@@ -451,12 +481,13 @@ void Controller::writeVDF() // write to VDF from list of strings. previo
451481}
452482
453483
454- void Controller::prepareScreenshots (QString userID, QString gameID, MainWindow *mainWindow) // this routine copies screenshots to the respective folders
484+ void Controller::prepareScreenshots (QString userID, QString gameID, quint32 jpegQuality, MainWindow *mainWindow) // this routine copies screenshots to the respective folders
455485{ // ...and manipulates a string list copy of the VDF (file is not written yet)
456486 someScreenshotsWereNotPrepared = false ;
457487 QRegularExpression desc (" <.+>$" );
458488 selectedUserID = userID.replace (" \\ " , " /" ).remove (desc);
459489 selectedGameID = gameID.remove (desc); // it's possible to enter game ID by hand or left what was auto-generated (with <...>)
490+ selectedJpegQuality = jpegQuality;
460491
461492 if ( lines.isEmpty () )
462493 lines = readVDF ();
@@ -630,7 +661,7 @@ void Controller::prepareScreenshots(QString userID, QString gameID, MainWindow *
630661 else {
631662 sendLabelsVisible (QStringList () << " label_progress" << " progressBar_status" , false );
632663 sendLabelsVisible (QStringList () << " label_status" , true );
633- emit sendStatusLabelText (" none of screenshots were copied" , " #ab4e52 " );
664+ emit sendStatusLabelText (" none of screenshots were copied" , warningColor );
634665 screenshotPathsPool.clear ();
635666 }
636667 }
@@ -734,7 +765,7 @@ void Controller::resizeAndSaveLargeScreenshot(Screenshot screenshot)
734765 saveThumbnail (filename, image, newWidth, newHeight);
735766
736767 resizedImage = image.scaled (QSize (newWidth, newHeight), Qt::KeepAspectRatio, Qt::SmoothTransformation);
737- resizedImage.save (copyDest + filename, " jpg" , 95 );
768+ resizedImage.save (copyDest + filename, " jpg" , selectedJpegQuality );
738769}
739770
740771
@@ -812,7 +843,7 @@ void Controller::pushScreenshots(QList<Screenshot> screenshotList)
812843 if ( ((extension == " jpg" ) || (extension == " jpeg" )) && (getEncodingProcessOfJpeg (&file) == " progressive" ) )
813844 file.copy (copyDest + filename); // copy untouched JPEG file if it is really JPEG, is not large (or if user decided to try it upload anyway)
814845 else // ...only progressive JPEGs are copied as is, baseline or some unidentified jpegs are
815- image.save (copyDest + filename, " jpg" , 95 ); // ...getting processed and saved by Qt to prevent Steam Cloud to reject them
846+ image.save (copyDest + filename, " jpg" , selectedJpegQuality); // ...getting processed and saved by Qt to prevent Steam Cloud to reject them
816847
817848 saveThumbnail (filename, image, width, height); // ...see issue https://github.com/Foyl/SteaScree/issues/9
818849
@@ -871,9 +902,9 @@ void Controller::pushScreenshots(QList<Screenshot> screenshotList)
871902 emit sendDirStatusLabelsVisible (true );
872903
873904 if (someScreenshotsWereNotPrepared)
874- emit sendStatusLabelText (" some screenshots were not copied" , " #ab4e52 " );
905+ emit sendStatusLabelText (" some screenshots were not copied" , warningColor );
875906 else
876- emit sendStatusLabelText (" screenshots are ready for preparation" , " grey " );
907+ emit sendStatusLabelText (" screenshots are ready for preparation" , " " );
877908
878909 emit sendWidgetsDisabled (QStringList () << " pushButton_prepare" , false );
879910 }
@@ -941,12 +972,6 @@ void Controller::returnLastSelectedScreenshotDir()
941972}
942973
943974
944- void Controller::returnScreenshotPathPoolLength ()
945- {
946- emit sendProgressBarLength (screenshotPathsPool.length ());
947- }
948-
949-
950975void Controller::returnSteamDir ()
951976{
952977 emit sendSteamDir (steamDir);
0 commit comments