Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Język pobranych napisów w oknie podsumowania #53

Merged
merged 5 commits into from
Feb 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions qnapi.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ CONFIG += warn_on \
thread \
qt \
resources \
release \
silent \
c++11

Expand Down Expand Up @@ -52,7 +51,8 @@ SOURCES += src/main.cpp \
src/subconvert/formats/mpl2.cpp \
src/subconvert/subtitleformat.cpp \
src/libmediainfomovieinfoparser.cpp \
src/qsubpostprocess.cpp
src/qsubpostprocess.cpp \
src/forms/subdatawidget.cpp


HEADERS += src/engines/qnapiabstractengine.h \
Expand Down Expand Up @@ -99,7 +99,8 @@ HEADERS += src/engines/qnapiabstractengine.h \
src/subconvert/formats/subrip.h \
src/subconvert/formats/mpl2.h \
src/libmediainfomovieinfoparser.h \
src/qsubpostprocess.h
src/qsubpostprocess.h \
src/forms/subdatawidget.h

FORMS += ui/frmprogress.ui \
ui/frmlistsubtitles.ui \
Expand All @@ -112,7 +113,8 @@ FORMS += ui/frmprogress.ui \
ui/napiprojekt/frmnapiprojektreport.ui \
ui/napiprojekt/frmnapiprojektupload.ui \
ui/opensubtitles/frmopensubtitlesconfig.ui \
ui/frmconvert.ui
ui/frmconvert.ui \
ui/subDataWidget.ui

RESOURCES += res/resources.qrc
UI_DIR = tmp
Expand Down
1 change: 1 addition & 0 deletions src/engines/qopensubtitlesengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ QList<QNapiSubtitleInfo> QOpenSubtitlesEngine::listSubtitles()
case SUBTITLE_GOOD: good << n; break;
case SUBTITLE_UNKNOWN: unknown << n; break;
case SUBTITLE_BAD: bad << n; break;
case SUBTITLE_NONE:break;
}
}

Expand Down
23 changes: 11 additions & 12 deletions src/forms/frmprogress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ void frmProgress::downloadFinished()
{
QMessageBox::critical(0, tr("Błąd krytyczny!"), getThread.criticalMessage);
}
else if(queue.size() > 0
&& !(getThread.gotList.isEmpty() && getThread.failedList.isEmpty()))
else if(queue.size() > 0 && !getThread.subStatusList.isEmpty())
{
summary.setSummaryList(getThread.gotList, getThread.failedList);
summary.setSummaryList(getThread.subStatusList);
summary.exec();
}
}
Expand Down Expand Up @@ -266,8 +265,7 @@ void GetThread::run()
if(queue.size() <= 0) return;

napiSuccess = napiFail = 0;
gotList.clear();
failedList.clear();
subStatusList.clear();

QNapi *napi = new QNapi();

Expand Down Expand Up @@ -343,8 +341,9 @@ void GetThread::run()
emit actionChange(tr("Szukanie napisów [%1] (%2)...").arg(language, e));
found = napi->lookForSubtitles(language, e) || found;

if(sp == SP_BREAK_IF_FOUND && found)
if(sp == SP_BREAK_IF_FOUND && found){
break;
}

ABORT_POINT
}
Expand All @@ -367,7 +366,7 @@ void GetThread::run()
if(!found)
{
++napiFail;
failedList << queue[i];
subStatusList << QNapiSubtitleInfo("","","",queue[i],"","",SUBTITLE_NONE);
continue;
}

Expand All @@ -391,7 +390,7 @@ void GetThread::run()
if(selIdx == -1)
{
++napiFail;
failedList << queue[i];
subStatusList << QNapiSubtitleInfo("","","",queue[i],"","",SUBTITLE_NONE);
continue;
}

Expand All @@ -403,7 +402,7 @@ void GetThread::run()
ABORT_POINT

++napiFail;
failedList << queue[i];
subStatusList << QNapiSubtitleInfo("","","",queue[i],"","",SUBTITLE_NONE);
continue;
}

Expand All @@ -415,7 +414,7 @@ void GetThread::run()
if(!napi->unpack(selIdx))
{
++napiFail;
failedList << queue[i];
subStatusList << QNapiSubtitleInfo("","","",queue[i],"","",SUBTITLE_NONE);
continue;
}

Expand All @@ -435,14 +434,14 @@ void GetThread::run()
ABORT_POINT

++napiFail;
failedList << queue[i];
subStatusList << QNapiSubtitleInfo("","","",queue[i],"","",SUBTITLE_NONE);

emit criticalError(tr("Nie udało się dopasować napisów!!"));
return;
}

++napiSuccess;
gotList << queue[i];
subStatusList << napi->listSubtitles().at(selIdx);

napi->cleanup();

Expand Down
3 changes: 2 additions & 1 deletion src/forms/frmprogress.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Q_OBJECT
}
void run();

QStringList queue, gotList, failedList, engines;
QStringList queue, engines;
QList<QNapiSubtitleInfo> subStatusList;
QString lang, langBackup;
bool langBackupPassed;
int napiSuccess, napiFail;
Expand Down
70 changes: 52 additions & 18 deletions src/forms/frmsummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*****************************************************************************/

#include "frmsummary.h"
#include "qnapi.h"

#include "subdatawidget.h"

frmSummary::frmSummary(QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f)
{
Expand All @@ -25,30 +28,61 @@ frmSummary::frmSummary(QWidget * parent, Qt::WindowFlags f) : QDialog(parent, f)
move(position.topLeft());
}

void frmSummary::setSummaryList(const QStringList & listSuccess, const QStringList & listFailures)
void frmSummary::setSummaryList(QList<QNapiSubtitleInfo> &list)
{
ui.lwSummary->clear();
std::sort(list.begin(), list.end());

ui.lbSuccess->setVisible(!listSuccess.isEmpty());
ui.lbFail->setVisible(!listFailures.isEmpty());
QNapi n;
n.addEngines(n.enumerateEngines());

QIcon succIcon(":/ui/accept.png"), failIcon(":/ui/exclamation.png");

foreach(QString successItem, listSuccess)
{
ui.lwSummary->addItem(new QListWidgetItem(succIcon, QFileInfo(successItem).fileName()));
}
ui.lwSummary->clear();
ui.lwSummary->setFocusPolicy(Qt::NoFocus);

int i = 0, good = 0, bad = 0;
foreach(QNapiSubtitleInfo s, list)
{
bool isGood = false;

if(s.resolution != SUBTITLE_NONE){
++good;
isGood = true;
}
else{
++bad;
}

QNapiAbstractEngine *e = n.engineByName(s.engine);
QListWidgetItem *listitem = new QListWidgetItem();


ui.lwSummary->addItem(listitem);

subDataWidget *subData = new subDataWidget();

if(isGood){
QString lang_path = QString(":/languages/") + s.lang + ".png";
subData->setSubData(succIcon, s.name,QIcon(lang_path),e->engineIcon());

}else{
subData->setSubData(failIcon, QFileInfo(s.name).fileName());

}
ui.lwSummary->setItemWidget(listitem, subData);
listitem->setSizeHint(subData->sizeHint());

++i;
}


ui.lwSummary->setMinimumWidth(ui.lwSummary->sizeHintForColumn(0) + 20);
this->adjustSize();

foreach(QString failureItem, listFailures)
{
ui.lwSummary->addItem(new QListWidgetItem(failIcon, QFileInfo(failureItem).fileName()));
}
ui.lbSuccess->setVisible(good != 0);
ui.lbFail->setVisible(bad != 0);

ui.lbSuccess->setText(tr("Pobrano napisy dla %1 %2")
.arg(listSuccess.size())
.arg(tr(listSuccess.size() > 1 ? "plików" : "pliku")));
ui.lbSuccess->setText(tr("Pobrano napisy dla %1 %2").arg(good).arg(tr(good > 1 ? "plików" : "pliku")));

ui.lbFail->setText(tr("Nie pobrano napisów dla %1 %2")
.arg(listFailures.size())
.arg(tr(listFailures.size() > 1 ? "plików" : "pliku")));
ui.lbFail->setText(tr("Nie pobrano napisów dla %1 %2").arg(bad).arg(tr(bad > 1 ? "plików" : "pliku")));
}
4 changes: 3 additions & 1 deletion src/forms/frmsummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
#include <QDesktopWidget>
#include <QListWidget>
#include <QFileInfo>
#include <QtCore>

#include "qnapiconfig.h"

#include "ui_frmsummary.h"
#include "qnapisubtitleinfo.h"

class frmSummary: public QDialog
{
Expand All @@ -30,7 +32,7 @@ Q_OBJECT
frmSummary(QWidget *parent = 0, Qt::WindowFlags f = 0);
~frmSummary() {};

void setSummaryList(const QStringList & listSuccess, const QStringList & listFailures);
void setSummaryList(QList<QNapiSubtitleInfo> &list);

private:
Ui::frmSummary ui;
Expand Down
40 changes: 40 additions & 0 deletions src/forms/subdatawidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "subdatawidget.h"

subDataWidget::subDataWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::subDataWidget)
{
ui->setupUi(this);
}

subDataWidget::~subDataWidget()
{
delete ui;
}

void subDataWidget::setSubData(const QIcon &stateIcon, QString name, const QIcon &langIcon, const QIcon &engineIcon){

ui->place1->clear();
ui->place2->clear();
ui->place3->clear();
ui->place4->clear();

ui->place1->setPixmap(stateIcon.pixmap(16));
ui->place2->setText(name);
ui->place3->setPixmap(langIcon.pixmap(16));
ui->place4->setPixmap(engineIcon.pixmap(16));
}

void subDataWidget::setSubData(const QIcon &stateIcon, QString name){

ui->place1->clear();
ui->place2->clear();
ui->place3->clear();
ui->place4->clear();

ui->place3->hide();
ui->place4->hide();

ui->place1->setPixmap(stateIcon.pixmap(16));
ui->place2->setText(name);
}
21 changes: 21 additions & 0 deletions src/forms/subdatawidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef SUBDATAWIDGET_H
#define SUBDATAWIDGET_H

#include <QWidget>
#include "ui_subDataWidget.h"

class subDataWidget : public QWidget
{
Q_OBJECT

public:
explicit subDataWidget(QWidget *parent = 0);
void setSubData(const QIcon &_stateIcon, QString _name, const QIcon &_langIcon, const QIcon &_engineIcon);
void setSubData(const QIcon &_stateIcon, QString _name);
~subDataWidget();

private:
Ui::subDataWidget *ui;
};

#endif // SUBDATAWIDGET_H
6 changes: 6 additions & 0 deletions src/qnapisubtitleinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
// Orientacyjne okreslenie czy napisy na pewno pasuja lub nie do naszego filmu
enum QNapiSubtitleResolution
{
// brak napisów
SUBTITLE_NONE,
// nie wiadomo (lub nie jestesmy pewni)
SUBTITLE_UNKNOWN,
// podejrzenie, ze napisy nie pasuja
Expand Down Expand Up @@ -56,6 +58,10 @@ struct QNapiSubtitleInfo
QString format;
QNapiSubtitleResolution resolution;
QUuid id;

bool operator<(const QNapiSubtitleInfo& other) const {
return resolution > other.resolution;
}
};

Q_DECLARE_METATYPE(QNapiSubtitleInfo);
Expand Down
25 changes: 22 additions & 3 deletions ui/frmsummary.ui
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>419</width>
<height>333</height>
<width>460</width>
<height>330</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>460</width>
<height>330</height>
</size>
</property>
<property name="windowTitle">
<string>QNapi - rezultat dopasowania napisów</string>
</property>
Expand Down Expand Up @@ -51,7 +63,14 @@
</widget>
</item>
<item>
<widget class="QListWidget" name="lwSummary"/>
<widget class="QListWidget" name="lwSummary">
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
Expand Down
Loading