Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Added Drag&Drop capability.
Browse files Browse the repository at this point in the history
Fixed a bug when the app crashed if QImage object was not created if the
image file is corrupted or have a wrong extension. Added a new status
message if there were such files in the queue and some such files were
not copied.
Fixed misleading status message when userdata directory was not found.
Some additional minor fixes.
  • Loading branch information
awthwathje committed Apr 16, 2017
1 parent 6d39cff commit 9e70722
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 54 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# SteaScree Changelog

## 1.4.0
* Added Drag&Drop capability.
* Fixed a bug when the app crashed if QImage object was not created if the image file is corrupted or have a wrong extension. Added a new status message if there were such files in the queue and some such files were not copied.
* Fixed misleading status message when userdata directory was not found.
* Some additional minor fixes.

## 1.3.3
* Fixed a bug when personal names were not populated to the respective combobox, if there are multiple config.cfg files were found for a single user. This is completely normal, and now personal name ges extracted from the first found config. Typically, even if there are multiple configs, personal names in them are exactly the same.
* Removed some unused methods.
Expand Down
8 changes: 5 additions & 3 deletions SteaScree.pro
Expand Up @@ -8,21 +8,23 @@ SOURCES += main.cpp\
mainwindow.cpp \
controller.cpp \
largefiledialog.cpp \
interfaceadjuster.cpp
interfaceadjuster.cpp \
qtreewidgetdraganddrop.cpp

HEADERS += mainwindow.h \
controller.h \
largefiledialog.h \
interfaceadjuster.h \
screenshot.h
screenshot.h \
qtreewidgetdraganddrop.h

FORMS += mainwindow.ui \
largefiledialog.ui

RESOURCES += \
images.qrc

VERSION = 1.3.3
VERSION = 1.4.0

DEFINES += APP_VERSION=\\\"$$VERSION\\\"

Expand Down
73 changes: 53 additions & 20 deletions controller.cpp
Expand Up @@ -390,10 +390,11 @@ void Controller::addScreenshotsToPool(QStringList screenshotsSelected)
while ( i.hasNext() ) {

QString current = i.next();
QString extension = current.section('.', -1).toLower();

if ( screenshotPathsPool.contains(current) )
if ( screenshotPathsPool.contains(current) || !imageFormatsSupported.contains(extension) )
screenshotsSelected.removeOne(current); // copies are removed from the list of selected screenshots about to add
}
} // ...non-supported files are also removed

if ( !screenshotsSelected.isEmpty() ) {

Expand All @@ -405,6 +406,15 @@ void Controller::addScreenshotsToPool(QStringList screenshotsSelected)
}


void Controller::receiveTreeWidgetPointer(QTreeWidgetDragAndDrop *receivedWidget)
{
treeWidget = receivedWidget;

QObject::connect(treeWidget, &QTreeWidgetDragAndDrop::sendDroppedScreenshots,
this, &Controller::addScreenshotsToPool);
}


QStringList Controller::readVDF() // read text from the VDF and return it in the form of list of strings for easy manipulating
{
QFile vdf(userDataDir + "/" + selectedUserID + "/" + vdfFilename);
Expand Down Expand Up @@ -443,6 +453,7 @@ void Controller::writeVDF() // write to VDF from list of strings. previo

void Controller::prepareScreenshots(QString userID, QString gameID, MainWindow *mainWindow) // this routine copies screenshots to the respective folders
{ // ...and manipulates a string list copy of the VDF (file is not written yet)
someScreenshotsWereNotPrepared = false;
QRegularExpression desc(" <.+>$");
selectedUserID = userID.replace("\\", "/").remove(desc);
selectedGameID = gameID.remove(desc); // it's possible to enter game ID by hand or left what was auto-generated (with <...>)
Expand Down Expand Up @@ -577,34 +588,51 @@ void Controller::prepareScreenshots(QString userID, QString gameID, MainWindow *

QStringList current = i.next();
QImage image(current[0]);
quint32 width = QImage(image).size().width();
quint32 height = QImage(image).size().height();

QList<quint32> geometry = QList<quint32>() << width << height;
if (!image.isNull()) { // sometimes image files are messed up, e.g. JPG files saved with the PNG extension

quint32 width = image.size().width(); // ...still they can be opened by some image viewers, but Qt doesn't tolerate such files and crahes the program
quint32 height = image.size().height(); // ...hence such files should be discarded from the queue

if ( (width > steamMaxSideSize) || (height > steamMaxSideSize) || ((width * height) > steamMaxResolution) ) {
QPixmap thumbnail = QPixmap::fromImage(image).scaled(320, 180, Qt::KeepAspectRatio);
preparedScreenshotList << Screenshot({id, current, thumbnail, geometry, true, 0});
thereAreLargeScreenshots = true;
QList<quint32> geometry = QList<quint32>() << width << height;

if ( (width > steamMaxSideSize) || (height > steamMaxSideSize) || ((width * height) > steamMaxResolution) ) {
QPixmap thumbnail = QPixmap::fromImage(image).scaled(320, 180, Qt::KeepAspectRatio);
preparedScreenshotList << Screenshot({id, current, thumbnail, geometry, true, 0});
thereAreLargeScreenshots = true;
}
else {
preparedScreenshotList << Screenshot({id, current, QPixmap(), geometry, false, 0});
}
}
else {
preparedScreenshotList << Screenshot({id, current, QPixmap(), geometry, false, 0});
someScreenshotsWereNotPrepared = true;
emit deleteCopiedWidgetItem(current[0]);
}

emit sendProgressBarValue(id + 1);
id++;
QCoreApplication::processEvents();
}

emit sendLabelsVisible(QStringList() << "label_progress" << "label_status" << "progressBar_status", false);
if (!preparedScreenshotList.isEmpty()) {

emit sendLabelsVisible(QStringList() << "label_progress" << "label_status" << "progressBar_status", false);

if (thereAreLargeScreenshots) {
emit sendLabelsVisible(QStringList() << "label_progress" << "label_status", true);
emit sendStatusLabelText("waiting for user decision", "");
getUserDecisionAboutLargeScreenshots(preparedScreenshotList, mainWindow);
if (thereAreLargeScreenshots) {
emit sendLabelsVisible(QStringList() << "label_progress" << "label_status", true);
emit sendStatusLabelText("waiting for user decision", "");
getUserDecisionAboutLargeScreenshots(preparedScreenshotList, mainWindow);
}
else
pushScreenshots(preparedScreenshotList);
}
else {
sendLabelsVisible(QStringList() << "label_progress" << "progressBar_status", false);
sendLabelsVisible(QStringList() << "label_status", true);
emit sendStatusLabelText("none of screenshots were copied", "#ab4e52");
screenshotPathsPool.clear();
}
else
pushScreenshots(preparedScreenshotList);
}
}
}
Expand Down Expand Up @@ -785,8 +813,8 @@ void Controller::pushScreenshots(QList<Screenshot> screenshotList)
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)
else // ...only progressive JPEGs are copied as is, baseline or some unidentified jpegs are
image.save(copyDest + filename, "jpg", 95); // ...getting processed and saved by Qt to prevent Steam Cloud to reject them
// ...see issue https://github.com/Foyl/SteaScree/issues/9
saveThumbnail(filename, image, width, height);

saveThumbnail(filename, image, width, height); // ...see issue https://github.com/Foyl/SteaScree/issues/9

} else // it is large and the user decision is "resize"
resizeAndSaveLargeScreenshot(current);
Expand Down Expand Up @@ -841,7 +869,12 @@ void Controller::pushScreenshots(QList<Screenshot> screenshotList)
if (addedLines > 0) {
emit sendLabelsText(QStringList() << "label_infoDirectories", QString::number(copiedDirsToNum));
emit sendDirStatusLabelsVisible(true);
emit sendStatusLabelText("screenshots are ready for preparation", "grey");

if (someScreenshotsWereNotPrepared)
emit sendStatusLabelText("some screenshots were not copied", "#ab4e52");
else
emit sendStatusLabelText("screenshots are ready for preparation", "grey");

emit sendWidgetsDisabled(QStringList() << "pushButton_prepare", false);
}

Expand Down
20 changes: 12 additions & 8 deletions controller.h
Expand Up @@ -3,7 +3,6 @@

#include "largefiledialog.h"
#include "mainwindow.h"
#include "screenshot.h"

#include <QObject>
#include <QSettings>
Expand Down Expand Up @@ -58,14 +57,18 @@ class Controller : public QObject
const quint32 steamMaxSideSize = 16000;
const quint32 steamMaxResolution = 26210175;
QString offerUpdateSetting;
QTreeWidgetDragAndDrop *treeWidget;
const QStringList imageFormatsSupported = QStringList() << "jpg" << "jpeg" << "png" << "bmp" << "tif" << "tiff";
bool someScreenshotsWereNotPrepared;

#if defined(Q_OS_WIN32)
const QString os = "Windows";
#elif defined(Q_OS_LINUX)
const QString os = "Linux";
#elif defined(Q_OS_OSX)
const QString os = "macOS";
#endif

#if defined(Q_OS_WIN32)
const QString os = "Windows";
#elif defined(Q_OS_LINUX)
const QString os = "Linux";
#elif defined(Q_OS_OSX)
const QString os = "macOS";
#endif

void pushScreenshots(QList<Screenshot> screenshotList);
void resizeAndSaveLargeScreenshot(Screenshot screenshot);
Expand Down Expand Up @@ -122,6 +125,7 @@ public slots:
void prepareScreenshotListWithDecisions(QList<Screenshot> screenshotList);
void writeSettingNeverOfferUpdate();
void fillGameIDs(QString userIDCombined);
void receiveTreeWidgetPointer(QTreeWidgetDragAndDrop *receivedWidget);


private slots:
Expand Down
2 changes: 1 addition & 1 deletion interfaceadjuster.cpp
@@ -1,7 +1,7 @@
#include "interfaceadjuster.h"


InterfaceAdjuster::InterfaceAdjuster(QObject *parent) : QObject(parent) // cross-platform window optimizations
InterfaceAdjuster::InterfaceAdjuster(QObject *parent) : QObject(parent) // window optimizations for different platforms
{
}

Expand Down
10 changes: 4 additions & 6 deletions main.cpp
@@ -1,17 +1,12 @@
#include "mainwindow.h"
#include "controller.h"
#include "interfaceadjuster.h"
#include "screenshot.h"

#include <QApplication>

Q_DECLARE_METATYPE(Screenshot)


// TODO: notify user when screenshot.vdf will not be modified for some reasons
// TODO: fix the visible resize of the main window on app's start
// TODO: design inconsitencies across platforms
// TODO: drag'n'drop screenshots
// TODO: UI in separate thread
// TODO: multi-threading

Expand Down Expand Up @@ -137,9 +132,12 @@ int main(int argc, char *argv[])
QObject::connect(&w, &MainWindow::sendNewlySelectedUserID,
&c, &Controller::fillGameIDs);

w.show();
QObject::connect(&w, &MainWindow::sendTreeWidgetPointer,
&c, &Controller::receiveTreeWidgetPointer);

w.bootStrap();
c.bootStrap();
w.show();

return a.exec();
}
29 changes: 17 additions & 12 deletions mainwindow.cpp
Expand Up @@ -18,6 +18,8 @@
#include <QMovie>
#include <QDesktopServices>

#include <QDebug>


MainWindow::MainWindow(QWidget *parent) :

Expand Down Expand Up @@ -50,11 +52,14 @@ void MainWindow::bootStrap()
ui->progressBar_status->setSizePolicy(spRetain);

emit sendButtonList(QList<QPushButton*>() << ui->pushButton_clearQueue << ui->pushButton_copyScreenshots // buttons should have specific padding
<< ui->pushButton_addScreenshots << ui->pushButton_prepare); // ...in each supported OS
<< ui->pushButton_addScreenshots << ui->pushButton_prepare); // ...in each supported OS

userIDComboBox = ui->comboBox_userID;
QObject::connect(userIDComboBox, static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::activated),
this, &MainWindow::reactToComboBoxActivation);

QTreeWidgetDragAndDrop *treeWidget = ui->treeWidget_screenshotList;
emit sendTreeWidgetPointer(treeWidget);
}


Expand Down Expand Up @@ -87,9 +92,9 @@ void MainWindow::makeWideMessageBox(QMessageBox *msgBox, quint32 width) // hack
void MainWindow::locateSteamDir(QString steamDir)
{
QString steamDirLocated = QFileDialog::getExistingDirectory(this,
"Locate Steam directory",
steamDir,
QFileDialog::ShowDirsOnly | QFileDialog::ReadOnly);
"Locate Steam directory",
steamDir,
QFileDialog::ShowDirsOnly | QFileDialog::ReadOnly);
if ( !steamDirLocated.isEmpty() ) {

steamDirLocated.remove(QRegularExpression("/userdata$"));
Expand Down Expand Up @@ -214,7 +219,7 @@ void MainWindow::setLabelsOnMissingStuff(bool userDataMissing, QString vdfFilena
{
ui->label_status->setVisible(true);
if ( userDataMissing )
setStatusLabelText("Steam executable is found, but there is no userdata directory", "#ab4e52");
setStatusLabelText("Steam userdata directory is not found", "#ab4e52");
else
setStatusLabelText("Steam userdata directory is found, but " + vdfFilename + " is missing", "#ab4e52");

Expand All @@ -226,32 +231,32 @@ void MainWindow::setLabelsOnMissingStuff(bool userDataMissing, QString vdfFilena
void MainWindow::returnScreenshotsSelected(QString lastSelectedScreenshotDir)
{
QStringList screenshotsSelected = QFileDialog::getOpenFileNames(this,
"Select one or more screenshots",
lastSelectedScreenshotDir,
"Images (*.jpg *.jpeg *.png *.bmp *.tif *.tiff)");
"Select one or several screenshots",
lastSelectedScreenshotDir,
"Images (*.jpg *.jpeg *.png *.bmp *.tif *.tiff)");
emit sendScreenshotsSelected(screenshotsSelected);
}


void MainWindow::setProgressBarValue(quint32 value)
{
ui->progressBar_status->setValue(value);
ui->progressBar_status->setValue(value);
}


void MainWindow::deleteCopiedWidgetItem(QString path)
{
QFile file(path);
QTreeWidgetItem *item = ui->treeWidget_screenshotList->findItems(QFileInfo(file).lastModified()
.toString("yyyy/MM/dd hh:mm:ss"), Qt::MatchExactly, 1)[0];
.toString("yyyy/MM/dd hh:mm:ss"), Qt::MatchExactly, 1)[0];
delete item;
}


void MainWindow::disableAllControls()
{
setWidgetsDisabled(QStringList() << "pushButton_clearQueue" << "pushButton_addScreenshots" << "pushButton_copyScreenshots"
<< "pushButton_locateSteamDir" << "comboBox_userID" << "comboBox_gameID" << "pushButton_prepare", true);
<< "pushButton_locateSteamDir" << "comboBox_userID" << "comboBox_gameID" << "pushButton_prepare", true);
}


Expand Down Expand Up @@ -330,7 +335,7 @@ void MainWindow::on_pushButton_addScreenshots_clicked()


void MainWindow::on_pushButton_clearQueue_clicked()
{
{
ui->treeWidget_screenshotList->clear();

setWidgetsDisabled(QStringList() << "pushButton_clearQueue" << "pushButton_copyScreenshots", true);
Expand Down
4 changes: 4 additions & 0 deletions mainwindow.h
@@ -1,6 +1,8 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "qtreewidgetdraganddrop.h"

#include <QMainWindow>
#include <QTreeWidgetItem>
#include <QMessageBox>
Expand Down Expand Up @@ -38,6 +40,7 @@ class MainWindow : public QMainWindow
void disableAllControls();



signals:
void sendButtonList(QList<QPushButton*> buttonList);
void pushButton_addScreenshots_clicked();
Expand All @@ -55,6 +58,7 @@ class MainWindow : public QMainWindow
void sendScreenshotsSelected(QStringList screenshotsSelected);
void sendNeverOfferUpdate();
void sendNewlySelectedUserID(QString userID);
void sendTreeWidgetPointer(QTreeWidgetDragAndDrop *treeWidget);


public slots:
Expand Down

0 comments on commit 9e70722

Please sign in to comment.