~adiroiban/ubuntu/karmic/kover/i18n-support

« back to all changes in this revision

Viewing changes to src/sd.cpp

  • Committer: Adi Roiban
  • Date: 2009-11-08 21:05:34 UTC
  • Revision ID: adi@roiban.ro-20091108210534-v1zh1zmfs9u72a0a
fix LP: #478507

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * kover - Kover is an easy to use WYSIWYG CD cover printer with CDDB support.
 
3
 * Copyright (C) 2001, 2008 by Adrian Reber
 
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 program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 */
 
19
 
 
20
/* This is the dialog for freedb server selection */
 
21
 
 
22
#include "sd.moc"
 
23
#include "sd.h"
 
24
#include <cddb_fill.h>
 
25
#include <kover.h>
 
26
 
 
27
#include <QVBoxLayout>
 
28
#include <QLabel>
 
29
#include <QPushButton>
 
30
 
 
31
sd::sd():QDialog()
 
32
{
 
33
        cddb_fill *bla = new cddb_fill();
 
34
        bla->sites(server_list);
 
35
        delete(bla);
 
36
        QVBoxLayout *top_layout = new QVBoxLayout(this);
 
37
 
 
38
        top_layout->setMargin(7);
 
39
        top_layout->addSpacing(10);
 
40
        QLabel *label = new QLabel (tr("Choose wisely!"), this);
 
41
 
 
42
        top_layout->addWidget(label);
 
43
        top_layout->addSpacing(10);
 
44
        box = new QListWidget(this);
 
45
        list < server * >::iterator item;
 
46
 
 
47
        QString string;
 
48
 
 
49
        for (item = server_list.begin(); item != server_list.end(); item++) {
 
50
                if (verbose)
 
51
                        (*item)->dump();
 
52
                if (((*item)->get_proto()).compare("http")) {
 
53
                        string = ((*item)->get_site()).c_str();
 
54
                        string += " (";
 
55
                        string += ((*item)->get_description()).c_str();
 
56
                        string += ")";
 
57
                        QListWidgetItem *newItem = new QListWidgetItem;
 
58
                        newItem->setText(string);
 
59
                        box->addItem(newItem);
 
60
                }
 
61
 
 
62
        }
 
63
        connect(box, SIGNAL(itemDoubleClicked(QListWidgetItem *)), SLOT(double_clicked(QListWidgetItem *)));
 
64
 
 
65
        top_layout->addWidget(box);
 
66
        top_layout->addSpacing(20);
 
67
 
 
68
        QBoxLayout *button_layout = new QBoxLayout(QBoxLayout::RightToLeft);
 
69
 
 
70
        top_layout->addLayout(button_layout);
 
71
        QPushButton *ok = new QPushButton(tr("Ok"), this);
 
72
 
 
73
        ok->setDefault(TRUE);
 
74
 
 
75
        ok->setMaximumWidth(70);
 
76
 
 
77
        connect(ok, SIGNAL(clicked()), SLOT(accept()));
 
78
        button_layout->addWidget(ok, 0, Qt::AlignRight);
 
79
        button_layout->addSpacing(5);
 
80
 
 
81
        QPushButton *quit = new QPushButton(tr("Quit"), this);
 
82
 
 
83
        connect(quit, SIGNAL(clicked()), SLOT(quit()));
 
84
        quit->setMaximumWidth(70);
 
85
        button_layout->addWidget(quit, 0, Qt::AlignRight);
 
86
        button_layout->addStretch(20);
 
87
        adjustSize();
 
88
}
 
89
 
 
90
sd::~sd()
 
91
{
 
92
        fprintf(stderr, "%s:sd::~sd()\n", PACKAGE);
 
93
 
 
94
        while (server_list.size()) {
 
95
                delete((server_list.back()));
 
96
                server_list.pop_back();
 
97
        }
 
98
}
 
99
 
 
100
/**
 
101
 * The accept() slot. Setting the return value.
 
102
 * reimplemented from QDialog
 
103
 */
 
104
void
 
105
sd::accept()
 
106
{
 
107
        QDialog::done(box->currentRow());
 
108
}
 
109
 
 
110
/**
 
111
 * The done() slot. Setting the return value.
 
112
 */
 
113
void
 
114
sd::quit()
 
115
{
 
116
        QDialog::done(-1);
 
117
}
 
118
 
 
119
/**
 
120
 * The double_clicked() slot. Setting the return value.
 
121
 * reimplemented from QDialog
 
122
 */
 
123
void
 
124
sd::double_clicked(QListWidgetItem *item)
 
125
{
 
126
        QDialog::done(item->listWidget()->currentRow());
 
127
}
 
128
 
 
129
/**
 
130
 * The exec() method. Executing the dialog.
 
131
 * reimplemented from QDialog
 
132
 * @see double_clicked(QListBoxItem *item)
 
133
 * @see accept()
 
134
 * @return an int representation of the selected item
 
135
 */
 
136
int
 
137
sd::exec()
 
138
{
 
139
        if (server_list.size() == 1) {
 
140
                return 0;
 
141
        } else {
 
142
                return QDialog::exec();
 
143
        }
 
144
}
 
145
 
 
146
/**
 
147
 * The get() method.
 
148
 * @param index the int value returned by exec()
 
149
 * @see exec()
 
150
 * @return the string containing the cddb id and category. Can be freed with free(3).
 
151
 */
 
152
string sd::get(int index)
 
153
{
 
154
        int
 
155
                i = 0;
 
156
 
 
157
        list < server * >::iterator item;
 
158
 
 
159
        for (item = server_list.begin(); item != server_list.end(); item++) {
 
160
                if (i++ == index * 2)
 
161
                        return (*item)->get_site();
 
162
        }
 
163
        return string();
 
164
}