File: coverbrowserdialog.cpp

package info (click to toggle)
audex 0.78-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,844 kB
  • ctags: 1,461
  • sloc: cpp: 10,604; makefile: 7; sh: 3
file content (122 lines) | stat: -rw-r--r-- 4,367 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* AUDEX CDDA EXTRACTOR
 * Copyright (C) 2007-2014 Marco Nelles (audex@maniatek.com)
 * <http://kde.maniatek.com/audex>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "coverbrowserdialog.h"
#include "utils/errordialog.h"

CoverBrowserDialog::CoverBrowserDialog(QWidget *parent) : KDialog(parent) {

  Q_UNUSED(parent);

  setup();
  showButtonSeparator(TRUE);

}

CoverBrowserDialog::~CoverBrowserDialog() {

}

void CoverBrowserDialog::fetchThumbnails(const QString& searchstring, const int fetchCount) {
  if (fetchCount == 0)
    cover_fetcher.startFetchThumbnails(searchstring, Preferences::fetchCount());
  else
    cover_fetcher.startFetchThumbnails(searchstring, fetchCount);
  ui.label->setText(i18n("Searching for covers..."));
}

void CoverBrowserDialog::startFetchCover(const int no) {
  cover_fetcher.startFetchCover(no);
}

void CoverBrowserDialog::slotButtonClicked(int button) {
  if (button == KDialog::Ok)
    select_this(ui.listWidget->selectedItems().at(0));
  else
    KDialog::slotButtonClicked(button);
}

void CoverBrowserDialog::select_this(QListWidgetItem* item) {
  cover_fetcher.stopFetchThumbnails();
  int match = item->data(Qt::UserRole).toInt();
  cover_fetcher.startFetchCover(match);
  accept();
}

void CoverBrowserDialog::enable_select_button() {
  enableButtonOk(ui.listWidget->selectedItems().count() > 0);
}

void CoverBrowserDialog::add_item(const QByteArray& cover, const QString& caption, int no) {
  QListWidgetItem *item = new QListWidgetItem;
  QPixmap pixmap;
  if (pixmap.loadFromData(cover)) {
    item->setText(caption);
    //item->setToolTip(i18n("%1\nCover Size: %2x%3", caption, pixmap.width(), pixmap.height()));
    item->setIcon(QIcon(pixmap.scaled(128, 128, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
    item->setData(Qt::UserRole, no-1);
    ui.listWidget->addItem(item);
  }
  ui.label->setText(i18n("Fetching Thumbnail %1 / %2...", no, cover_fetcher.count()));
}

void CoverBrowserDialog::all_fetched() {
  ui.label->setText(i18np("Found 1 Cover", "Found %1 Covers", cover_fetcher.count()));
  emit allCoverThumbnailsFetched();
}

void CoverBrowserDialog::nothing_fetched() {
  ui.label->setText(i18n("No Covers Found"));
  emit nothingFetched();
}

void CoverBrowserDialog::cover_fetched(const QByteArray& cover) {
  emit coverFetched(cover);
}

void CoverBrowserDialog::error(const QString& description, const QString& solution) {
  ErrorDialog::show(this, description, solution);
}

void CoverBrowserDialog::setup() {

  static const int constIconSize=128;

  QWidget *widget = new QWidget(this);
  ui.setupUi(widget);

  setMainWidget(widget);

  setCaption(i18n("Fetch Cover From Google"));
  setButtons(KDialog::Ok | KDialog::Cancel);

  connect(&cover_fetcher, SIGNAL(fetchedThumbnail(const QByteArray&, const QString&, int)), this, SLOT(add_item(const QByteArray&, const QString&, int)));
  connect(&cover_fetcher, SIGNAL(allCoverThumbnailsFetched()), this, SLOT(all_fetched()));
  connect(&cover_fetcher, SIGNAL(nothingFetched()), this, SLOT(nothing_fetched()));
  connect(&cover_fetcher, SIGNAL(fetchedCover(const QByteArray&)), this, SLOT(cover_fetched(const QByteArray&)));
  connect(&cover_fetcher, SIGNAL(error(const QString&, const QString&)), this, SLOT(error(const QString&, const QString&)));
  
  ui.listWidget->setIconSize(QSize(constIconSize, constIconSize));
  ui.listWidget->setWordWrap(TRUE);
  ui.listWidget->setViewMode(QListView::IconMode);
  connect(ui.listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(enable_select_button()));
  connect(ui.listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(select_this(QListWidgetItem*)));
  ui.listWidget->setMinimumSize((constIconSize+12)*4, (constIconSize+12)*2);
  enable_select_button();

}