Debian Codegraph @

gui/src/forms/frmsummary.cpp

raw symbols SCIP
1 /*****************************************************************************
2 ** QNapi
3 ** Copyright (C) 2008-2017 Piotr Krzemiński <[email protected]>
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 **
13 *****************************************************************************/
14
15 #include "frmsummary.h"
16 #include "libqnapi.h"
17
18 #include "subdatawidget.h"
19
20 #include <QDesktopWidget>
21 #include <QListWidget>
22
23 frmSummary::frmSummary(QWidget *parent, Qt::WindowFlags f)
24 : QDialog(parent, f) {
25 ui.setupUi(this);
26
27 setAttribute(Qt::WA_QuitOnClose, false);
28
29 QRect position = frameGeometry();
30 position.moveCenter(QDesktopWidget().availableGeometry().center());
31 move(position.topLeft());
32 }
33
34 void frmSummary::setSummaryList(QList<SubtitleInfo> list) {
35 std::sort(list.begin(), list.end());
36
37 QIcon succIcon(":/ui/accept.png"), failIcon(":/ui/exclamation.png");
38
39 ui.lwSummary->clear();
40 ui.lwSummary->setFocusPolicy(Qt::NoFocus);
41
42 int i = 0, goodCount = 0, badCount = 0;
43 foreach (SubtitleInfo s, list) {
44 bool isGood = s.resolution != SUBTITLE_NONE;
45
46 QListWidgetItem *listItem = new QListWidgetItem();
47
48 ui.lwSummary->addItem(listItem);
49
50 subDataWidget *subData = new subDataWidget();
51
52 if (isGood) {
53 ++goodCount;
54 QString lang_path = QString(":/languages/") + s.lang + ".png";
55 QIcon engineIcon =
56 QIcon(QPixmap(enginesRegistry->enginePixmapData(s.engine)));
57 subData->setSubData(succIcon, s.name, QIcon(lang_path), engineIcon);
58 } else {
59 ++badCount;
60 subData->setSubData(failIcon, s.name);
61 }
62
63 ui.lwSummary->setItemWidget(listItem, subData);
64 listItem->setSizeHint(subData->sizeHint());
65
66 ++i;
67 }
68
69 ui.lwSummary->setMinimumWidth(ui.lwSummary->sizeHintForColumn(0) + 20);
70 this->adjustSize();
71
72 ui.lbSuccess->setVisible(goodCount != 0);
73 ui.lbFail->setVisible(badCount != 0);
74
75 ui.lbSuccess->setText(tr("Subtitles downloaded for %1 %2")
76 .arg(goodCount)
77 .arg(goodCount > 1 ? tr("files") : tr("file")));
78 ui.lbFail->setText(tr("Could not download subtitles for %1 %2")
79 .arg(badCount)
80 .arg(badCount > 1 ? tr("files") : tr("file")));
81 }