File: profilewidget.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 (152 lines) | stat: -rw-r--r-- 5,069 bytes parent folder | download | duplicates (2)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* 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 "profilewidget.h"

profileWidget::profileWidget(ProfileModel *profileModel, QWidget *parent) : profileWidgetUI(parent) {

  profile_model = profileModel;
  if (!profile_model) {
    kDebug() << "ProfileModel is NULL!";
    return;
  }

  listView->setModel(profile_model);
  listView->setModelColumn(1);
  listView->setIconSize(QSize(22, 22));
  connect(listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(_update()));
  connect(listView, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(mod_profile(const QModelIndex&)));
  connect(kpushbutton_add, SIGNAL(clicked()), this, SLOT(add_profile()));
  connect(kpushbutton_rem, SIGNAL(clicked()), this, SLOT(rem_profile()));
  connect(kpushbutton_mod, SIGNAL(clicked()), this, SLOT(mod_profile()));
  connect(kpushbutton_copy, SIGNAL(clicked()), this, SLOT(copy_profile()));
  connect(kpushbutton_load, SIGNAL(clicked()), this, SLOT(load_profiles()));
  connect(kpushbutton_save, SIGNAL(clicked()), this, SLOT(save_profiles()));
  connect(kpushbutton_init, SIGNAL(clicked()), this, SLOT(init_profiles()));

  kpushbutton_add->setIcon(KIcon("list-add"));
  kpushbutton_rem->setIcon(KIcon("list-remove"));

  kpushbutton_load->setIcon(KIcon("document-open"));
  kpushbutton_save->setIcon(KIcon("document-save"));

  kpushbutton_init->setIcon(KIcon("view-refresh"));

  _update();

}

profileWidget::~profileWidget() {

}

void profileWidget::_update() {
  kpushbutton_rem->setEnabled(listView->selectionModel()->selectedIndexes().count()>0);
  kpushbutton_mod->setEnabled(listView->selectionModel()->selectedIndexes().count()>0);
  kpushbutton_copy->setEnabled(listView->selectionModel()->selectedIndexes().count()>0);
  kpushbutton_save->setEnabled(profile_model->rowCount()>0);
}

void profileWidget::add_profile() {

  ProfileDataDialog *dialog = new ProfileDataDialog(profile_model, -1, this);

  if (dialog->exec() != QDialog::Accepted) { delete dialog; return; }
  delete dialog;

  profile_model->sortItems();

  _update();

}

void profileWidget::rem_profile() {

  if (KMessageBox::warningYesNo(this, i18n("Do you really want to delete profile \"%1\"?", profile_model->data(profile_model->index(listView->currentIndex().row(), PROFILE_MODEL_COLUMN_NAME_INDEX)).toString()),
				i18n("Delete profile"),
				KStandardGuiItem::yes(),
				KStandardGuiItem::no())== KMessageBox::No) return;

  QModelIndex ci = listView->currentIndex();
  profile_model->removeRows(ci.row(), 1);

  profile_model->commit();

  if (ci.isValid()) listView->setCurrentIndex(ci);

  _update();

}

void profileWidget::mod_profile(const QModelIndex& index) {

  ProfileDataDialog *dialog = new ProfileDataDialog(profile_model, index.row(), this);

  dialog->exec();

  delete dialog;

  _update();

}

void profileWidget::mod_profile() {

  mod_profile(listView->currentIndex());

}

void profileWidget::copy_profile() {
  profile_model->copy(listView->currentIndex().row());
  profile_model->commit();
  profile_model->sortItems();
  _update();
}

void profileWidget::save_profiles() {
  QString filename = KFileDialog::getSaveFileName(KUrl(QDir::homePath()), "*.apf", this, i18n("Save Cover"));
  if (!filename.isEmpty()) {
    profile_model->saveProfilesToFile(filename);
  }
}

void profileWidget::load_profiles() {
  QString filename = KFileDialog::getOpenFileName(KUrl(QDir::homePath()), "*.apf", this, i18n("Load Profiles"));
  if (!filename.isEmpty()) {
    profile_model->loadProfilesFromFile(filename);
  }
}

void profileWidget::init_profiles() {

  if (KMessageBox::Yes == KMessageBox::questionYesNo(this,
       i18n("<p>Do you wish to rescan your system for codecs (Lame, Ogg Vorbis, Flac, etc.)?</p>"
            "<p><font style=\"font-style:italic;\">This will attempt to create some sample profiles based upon any found codecs.</font></p>"),
       i18n("Codec Scan"))) {

    int sizeBefore = profile_model->rowCount();
    profile_model->autoCreate();
    int diff = profile_model->rowCount()-sizeBefore;
    KMessageBox::information(this, 0==diff
                                     ? i18n("No new codecs found")
                                     : i18np("1 new profile added", "%1 new profiles added", diff),
                                 i18n("Codec Scan"));

  }

}