~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to noatun/noatun/library/cmodule.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cmodule.h>
 
2
#include <pluginloader.h>
 
3
#include <common.h>
 
4
#include <noatunapp.h>
 
5
 
 
6
#include <qpushbutton.h>
 
7
#include <qcheckbox.h>
 
8
#include <qpushbutton.h>
 
9
#include <qlayout.h>
 
10
#include <klocale.h>
 
11
#include <kdebug.h>
 
12
#include <klistview.h>
 
13
#include <qsplitter.h>
 
14
#include <qlabel.h>
 
15
#include <qdragobject.h>
 
16
#include <kurlrequester.h>
 
17
#include <kfiledialog.h>
 
18
#include <kdialog.h>
 
19
 
 
20
#include <qtextview.h>
 
21
#include <qwhatsthis.h>
 
22
 
 
23
#include "mimetypetree.h"
 
24
 
 
25
template<class T1, class T2> struct Dual
 
26
{
 
27
        Dual(const T1 &l, const T2 &r) : left(l), right(r) {}
 
28
        Dual() {}
 
29
        Dual(const Dual<T1, T2> &d) : left(d.left), right(d.right) {}
 
30
        T1 left;
 
31
        T2 right;
 
32
};
 
33
typedef Dual<QString, QString> StringDual;
 
34
 
 
35
static QString infoPane(const QString &title, const QValueList<StringDual> &prop)
 
36
{
 
37
        static const int cols=1;
 
38
        QString str;
 
39
 
 
40
        // get the title
 
41
        str+="<font size=\"+2\"><b>";
 
42
        str+=title;
 
43
        str+="</b></font>\n\n<table cols=";
 
44
        str+=QString::number(2);
 
45
        str+=" width=\"100%\"><tr>";
 
46
 
 
47
        // set up the properties table
 
48
 
 
49
        QValueList<StringDual>::ConstIterator i;
 
50
        i=prop.begin();
 
51
        
 
52
        while (i!=prop.end())
 
53
        {
 
54
                str+="<td>";
 
55
                bool first=true;
 
56
                for (int perRow=prop.count()/cols; i!=prop.end() && perRow!=0; perRow--)
 
57
                {
 
58
                        if (!first)
 
59
                                str+="<br>\n";
 
60
                        first=false;
 
61
 
 
62
                        str+="<b>";
 
63
                        str+=(*i).left;
 
64
                        str+=":</b> ";
 
65
                        str+=(*i).right;
 
66
                        ++i;
 
67
                }
 
68
                str+="</td>";
 
69
        }
 
70
        str+="</tr></table>";
 
71
        return str;
 
72
}
 
73
 
 
74
class MimeListItem : public QCheckListItem
 
75
{
 
76
public:
 
77
        MimeListItem(KListView *list, const QString &mime, const QString &extension,
 
78
                     const QString &author, const QString &url, const QString &name);
 
79
 
 
80
public:
 
81
        QString mime() const { return mMime; }
 
82
        QString extension() const { return mExtension; }
 
83
        QString author() const { return mAuthor; }
 
84
        QString url() const { return mUrl; }
 
85
        QString name() const { return mName; }
 
86
        
 
87
private:
 
88
        QString mMime, mExtension, mAuthor, mUrl, mName;
 
89
};
 
90
 
 
91
 
 
92
MimeListItem::MimeListItem(KListView *list, const QString &mime, const QString &extension,
 
93
                           const QString &author, const QString &url, 
 
94
                           const QString &name)
 
95
        : QCheckListItem(list, name, QCheckListItem::CheckBox)
 
96
{
 
97
        setText(1, extension);
 
98
        mName=name;
 
99
        mMime=mime;
 
100
        mExtension=extension;
 
101
        mAuthor=author;
 
102
        mUrl=url;
 
103
}
 
104
 
 
105
Types::Types(QObject *parent) : CModule(i18n("File Types"), i18n("Configure Mime Types"), parent), first(true)
 
106
{
 
107
}
 
108
 
 
109
void Types::reopen()
 
110
{
 
111
        if (first)
 
112
        {
 
113
                QGridLayout *layout=new QGridLayout(this);
 
114
                
 
115
                mimes=new MimeTypeTree(this);
 
116
                mimes->setFixedWidth(120);
 
117
                layout->addMultiCellWidget(mimes, 0, 1, 0, 0);
 
118
                
 
119
                list=new KListView(this);
 
120
                layout->addWidget(list, 0, 1);
 
121
 
 
122
                connect(list, SIGNAL(currentChanged(QListViewItem*)), SLOT(selectionChanged(QListViewItem*)));
 
123
                
 
124
                list->show();
 
125
                list->addColumn(i18n("Name"));
 
126
                list->addColumn(i18n("Extension"));
 
127
                list->setSorting(-1);
 
128
                i18n("URL");
 
129
                i18n("Author");
 
130
                i18n("&Enable");
 
131
 
 
132
                list->setItemsMovable(true);
 
133
                list->setDragEnabled(true);
 
134
                list->setAcceptDrops(true);
 
135
                //      if (!q.supports("Interface","Arts::PlayObject"))
 
136
                //              return;
 
137
 
 
138
                text=new QTextView(this);
 
139
                layout->addWidget(text, 1, 1);
 
140
                text->show();
 
141
                text->setFixedHeight(150);
 
142
                first=false;
 
143
        }
 
144
 
 
145
        list->clear();
 
146
        Arts::TraderQuery q;
 
147
 
 
148
        std::vector<Arts::TraderOffer> *results = q.query();
 
149
        for (std::vector<Arts::TraderOffer>::iterator i=results->begin(); i != results->end(); i++)
 
150
        {
 
151
                QString name=commaVector(&*i, "Interface", true);
 
152
                QString author=commaVector(&*i, "Author");
 
153
                QString url=commaVector(&*i, "URL");
 
154
                QString extension=commaVector(&*i, "Extension");
 
155
                QString mime=commaVector(&*i, "MimeType");
 
156
                if (author.isNull() || url.isNull() || extension.isNull() || mime.isNull())
 
157
                        continue;
 
158
 
 
159
                new MimeListItem(list, mime, extension, author, url, name);
 
160
        }
 
161
        delete results;
 
162
 
 
163
        selectionChanged(list->firstChild());
 
164
}
 
165
 
 
166
void Types::selectionChanged(QListViewItem *item)
 
167
{
 
168
        MimeListItem *type=static_cast<MimeListItem*>(item);
 
169
        QValueList<StringDual> bleh;
 
170
        
 
171
        bleh.append(StringDual(i18n("Author"), type->author()));
 
172
        bleh.append(StringDual(i18n("Web Site"), type->url()));
 
173
        bleh.append(StringDual(i18n("Extension"), type->extension()));
 
174
        bleh.append(StringDual(i18n("Mimetype"), type->mime()));
 
175
        
 
176
        text->setText(infoPane(type->name(),bleh));
 
177
}
 
178
 
 
179
QString Types::commaVector(Arts::TraderOffer *t, const char *field, bool limit)
 
180
{
 
181
        std::vector<std::string> *prop=t->getProperty(field);
 
182
        QString str;
 
183
        bool comma=false;
 
184
 
 
185
        for (std::vector<std::string>::iterator i=prop->begin(); i != prop->end(); i++)
 
186
        {
 
187
                if (!(*i).length()) continue;
 
188
                if (comma)
 
189
                        str+=", ";
 
190
                comma=true;
 
191
                str+=(*i).c_str();
 
192
                if (limit) break;
 
193
        }
 
194
        delete prop;
 
195
        return str;
 
196
}
 
197
 
 
198
Types::~Types()
 
199
{
 
200
 
 
201
}
 
202
 
 
203
void Types::save()
 
204
{
 
205
 
 
206
}
 
207
 
 
208
 
 
209
/*****************************************************************
 
210
 * General options
 
211
 *****************************************************************/
 
212
 
 
213
General::General(QObject *parent) : CModule(i18n("Options"), i18n("General Options"), parent)
 
214
{
 
215
        mLoopList=new QCheckBox(i18n("&Return to Start of Playlist on Finish"), this);
 
216
        mLoopList->setChecked(napp->loopList());
 
217
        QWhatsThis::add(mLoopList, i18n("When the playlist is done playing, return to the start, but don't start playing."));
 
218
 
 
219
        mAutoPlay=new QCheckBox(i18n("&Automatically Play First File"), this);
 
220
        mAutoPlay->setChecked(napp->autoPlay());
 
221
        QWhatsThis::add(mAutoPlay, i18n("Start playing the playlist as soon as Noatun is started."));
 
222
 
 
223
        mOneInstance=new QCheckBox(i18n("&Allow Only One Instance of Noatun"), this);
 
224
        mOneInstance->setChecked(napp->oneInstance());
 
225
        QWhatsThis::add(mOneInstance, i18n("Starting noatun a second time will cause it to just append items from the start to the current instance."));
 
226
 
 
227
        mClearOnOpen = new QCheckBox(i18n("Clear playlist when opening a file"), this);
 
228
        mClearOnOpen->setChecked(napp->clearOnOpen());
 
229
        QWhatsThis::add(mClearOnOpen, i18n("Opening a file with the global Open menu item will clear the playlist first."));
 
230
 
 
231
        mHackUpPlaylist = new QCheckBox(i18n("Process Playlist Items for Display"), this);
 
232
        mHackUpPlaylist->setChecked(napp->hackUpPlaylist());
 
233
 
 
234
        QWhatsThis::add(mHackUpPlaylist, i18n("Process filenames (e.g. removing spaces and the filename extension) and set them as the playlist item titles."));
 
235
 
 
236
        mFastVolume=new QCheckBox(i18n("Use Fast Hardware Volume Control"), this);
 
237
        mFastVolume->setChecked(napp->fastMixer());
 
238
        QWhatsThis::add(mFastVolume, i18n("Use the hardware mixer instead of aRts's.  It affects all streams, not just Noatun's, but is a little faster."));
 
239
                
 
240
        QFrame *dlSaverFrame = new QFrame(this);
 
241
        QLabel *dlsaver=new QLabel(i18n("&Download Directory"), dlSaverFrame);
 
242
        mDlSaver=new KURLRequester(napp->saveDirectory(), dlSaverFrame);
 
243
        dlsaver->setBuddy(mDlSaver);
 
244
        connect( mDlSaver, SIGNAL( openFileDialog( KURLRequester * )),
 
245
                 this, SLOT( slotRequesterClicked( KURLRequester * )));
 
246
        QWhatsThis::add(mDlSaver, i18n("When opening a non-local file, download it to the selected directory."));
 
247
 
 
248
        QVBoxLayout *layout = new QVBoxLayout(this, KDialog::marginHint(), KDialog::spacingHint());
 
249
        layout->addWidget(mLoopList);
 
250
        layout->addWidget(mAutoPlay);
 
251
        layout->addWidget(mOneInstance);
 
252
        layout->addWidget(mClearOnOpen);
 
253
        layout->addWidget(mHackUpPlaylist);
 
254
        layout->addWidget(mFastVolume);
 
255
        layout->addWidget(dlSaverFrame);
 
256
        layout->addStretch();
 
257
 
 
258
        QHBoxLayout *layoutSaver = new QHBoxLayout(dlSaverFrame, KDialog::marginHint(), KDialog::spacingHint());
 
259
        layoutSaver->addWidget(dlsaver);
 
260
        layoutSaver->addWidget(mDlSaver);
 
261
}
 
262
 
 
263
void General::save()
 
264
{
 
265
        napp->setLoopList(mLoopList->isChecked());
 
266
        napp->setAutoPlay(mAutoPlay->isChecked());
 
267
        napp->setOneInstance(mOneInstance->isChecked());
 
268
        napp->setClearOnOpen(mClearOnOpen->isChecked());
 
269
        napp->setSaveDirectory(mDlSaver->url());
 
270
        napp->setHackUpPlaylist(mHackUpPlaylist->isChecked());
 
271
        napp->setFastMixer(mFastVolume->isChecked());
 
272
}
 
273
 
 
274
void General::slotRequesterClicked( KURLRequester * )
 
275
{
 
276
        mDlSaver->fileDialog()->setMode(
 
277
                (KFile::Mode)(KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly));
 
278
}
 
279
 
 
280
#include "cmodule.moc"