~ubuntu-branches/ubuntu/utopic/clementine/utopic

« back to all changes in this revision

Viewing changes to src/covers/coversearchstatisticsdialog.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Clementine.
 
2
   Copyright 2010, David Sansome <me@davidsansome.com>
 
3
 
 
4
   Clementine is free software: you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation, either version 3 of the License, or
 
7
   (at your option) any later version.
 
8
 
 
9
   Clementine is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
#include "coversearchstatisticsdialog.h"
 
19
#include "ui_coversearchstatisticsdialog.h"
 
20
#include "core/utilities.h"
 
21
 
 
22
CoverSearchStatisticsDialog::CoverSearchStatisticsDialog(QWidget *parent)
 
23
  : QDialog(parent),
 
24
    ui_(new Ui_CoverSearchStatisticsDialog)
 
25
{
 
26
  ui_->setupUi(this);
 
27
  details_layout_ = new QVBoxLayout(ui_->details);
 
28
  details_layout_->setSpacing(0);
 
29
 
 
30
  setStyleSheet(
 
31
    "#details {"
 
32
    "  background-color: palette(base);"
 
33
    "}"
 
34
    "#details QLabel[type=\"label\"] {"
 
35
    "  border: 2px solid transparent;"
 
36
    "  border-right: 2px solid palette(midlight);"
 
37
    "  margin-right: 10px;"
 
38
    "}"
 
39
    "#details QLabel[type=\"value\"] {"
 
40
    "  font-weight: bold;"
 
41
    "  max-width: 100px;"
 
42
    "}"
 
43
  );
 
44
}
 
45
 
 
46
CoverSearchStatisticsDialog::~CoverSearchStatisticsDialog() {
 
47
  delete ui_;
 
48
}
 
49
 
 
50
void CoverSearchStatisticsDialog::Show(const CoverSearchStatistics& statistics) {
 
51
  QStringList providers(statistics.total_images_by_provider_.keys());
 
52
  qSort(providers);
 
53
 
 
54
  ui_->summary->setText(tr("Got %1 covers out of %2 (%3 failed)")
 
55
                        .arg(statistics.chosen_images_)
 
56
                        .arg(statistics.chosen_images_ + statistics.missing_images_)
 
57
                        .arg(statistics.missing_images_));
 
58
 
 
59
  foreach (const QString& provider, providers) {
 
60
    AddLine(tr("Covers from %1").arg(provider),
 
61
            QString::number(statistics.chosen_images_by_provider_[provider]));
 
62
  }
 
63
 
 
64
  if (!providers.isEmpty()) {
 
65
    AddSpacer();
 
66
  }
 
67
 
 
68
  AddLine(tr("Total network requests made"),
 
69
          QString::number(statistics.network_requests_made_));
 
70
  AddLine(tr("Average image size"), statistics.AverageDimensions());
 
71
  AddLine(tr("Total bytes transferred"),
 
72
          statistics.bytes_transferred_
 
73
            ? Utilities::PrettySize(statistics.bytes_transferred_)
 
74
            : "0 bytes");
 
75
 
 
76
  details_layout_->addStretch();
 
77
 
 
78
  show();
 
79
}
 
80
 
 
81
void CoverSearchStatisticsDialog::AddLine(const QString& label, const QString& value) {
 
82
  QLabel* label1 = new QLabel(label);
 
83
  QLabel* label2 = new QLabel(value);
 
84
 
 
85
  label1->setProperty("type", "label");
 
86
  label2->setProperty("type", "value");
 
87
 
 
88
  QHBoxLayout* layout = new QHBoxLayout;
 
89
  layout->addWidget(label1);
 
90
  layout->addWidget(label2);
 
91
  details_layout_->addLayout(layout);
 
92
}
 
93
 
 
94
void CoverSearchStatisticsDialog::AddSpacer() {
 
95
  details_layout_->addSpacing(20);
 
96
}