~ubuntu-branches/ubuntu/lucid/ktorrent/lucid

« back to all changes in this revision

Viewing changes to plugins/mediaplayer/mediaview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-12-08 19:17:41 UTC
  • mfrom: (1.2.1 upstream) (0.7.12 sid)
  • Revision ID: james.westby@ubuntu.com-20091208191741-lqlq0xvnlv8ki19u
Tags: 3.3.1+dfsg.1-1ubuntu1
* Merge with Debian Testing remaining changes:
  - Build-depend directly on libboost-serialization1.40-dev since
    libboost-serialization-dev from boost-defaults is not in Main
  - Add in rules: include /usr/lib/kubuntu-desktop-i18n/debhelper/kubuntu.mk
  - Don't use dpkg-source 3.0 format
  - Add quilt to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 ***************************************************************************/
21
21
#include <QHeaderView>
22
22
#include <QVBoxLayout>
 
23
#include <QLabel>
23
24
#include <QSpacerItem>
24
 
#include <QFile>
25
25
#include <ktoolbar.h>
26
26
#include <klocale.h>
27
27
#include <util/log.h>
28
 
#include <taglib/tag.h>
29
 
#include <taglib/fileref.h>
30
28
#include "mediaview.h"
31
29
#include "mediamodel.h"
32
30
#include "mediaplayer.h"
33
31
#include "mediaplayerpluginsettings.h"
34
32
 
 
33
 
35
34
using namespace bt;
36
35
 
37
36
namespace kt
38
37
{
39
38
 
40
 
        MediaView::MediaView(MediaPlayer* player,MediaModel* model,QWidget* parent)
41
 
                        : QWidget(parent),player(player),model(model)
 
39
        MediaView::MediaView(MediaModel* model,QWidget* parent)
 
40
                        : QWidget(parent),model(model)
42
41
        {
43
42
                QVBoxLayout* layout = new QVBoxLayout(this);
44
43
                layout->setSpacing(0);
45
44
                layout->setMargin(0);
46
45
                
47
 
                tool_bar = new KToolBar(this);
48
 
                tool_bar->setToolButtonStyle(Qt::ToolButtonIconOnly);
49
 
                layout->addWidget(tool_bar);
50
 
                
51
 
                play_slider = new Phonon::SeekSlider(this);
52
 
                play_slider->setMediaObject(player->media0bject());
53
 
                layout->addWidget(play_slider);
54
 
                
55
 
                info_label = new QLabel(this);
56
 
                info_label->setMargin(5);
57
 
                info_label->setFrameShadow(QFrame::Sunken);
58
 
                info_label->setFrameShape(QFrame::StyledPanel);
59
 
                info_label->setBackgroundRole(QPalette::Base);
60
 
                info_label->setAutoFillBackground(true);
61
 
                info_label->setWordWrap(true);
62
 
                layout->addWidget(info_label);
63
 
                info_label->setText(i18n("Ready to play"));
64
 
                
 
46
                layout->addWidget(new QLabel(i18n("Collection:")));
65
47
                media_tree = new QTreeView(this);
66
48
                media_tree->setModel(model);
67
49
                media_tree->header()->hide();
 
50
                media_tree->setDragEnabled(true);
68
51
                layout->addWidget(media_tree);
69
52
                
70
 
                QHBoxLayout* hlayout = new QHBoxLayout(0);
71
 
                hlayout->addWidget(new QLabel(i18n("Mode:"),this));
72
 
                
73
 
                queue_mode = new QComboBox(this);
74
 
                queue_mode->addItem(i18n("Single File"));
75
 
                queue_mode->addItem(i18n("All Files"));
76
 
                queue_mode->addItem(i18n("Random Files"));
77
 
                queue_mode->setCurrentIndex(MediaPlayerPluginSettings::playMode());
78
 
                hlayout->addWidget(queue_mode);
79
 
                
80
 
                QSpacerItem* s = new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum);
81
 
                hlayout->addItem(s);
82
 
                
83
 
                layout->addLayout(hlayout);
84
 
                
85
 
                skip_incomplete = new QCheckBox(i18n("Skip incomplete files"),this);
86
 
                skip_incomplete->setChecked(MediaPlayerPluginSettings::skipIncomplete());
87
 
                layout->addWidget(skip_incomplete);
88
 
                
89
 
                volume = new Phonon::VolumeSlider(this);
90
 
                volume->setAudioOutput(player->output());
91
 
                layout->addWidget(volume);
92
 
                
93
 
                
94
 
                
95
 
                connect(media_tree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection & , const QItemSelection & )),
96
 
                                this,SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
97
53
                connect(media_tree,SIGNAL(doubleClicked(const QModelIndex &)),this,SIGNAL(doubleClicked(const QModelIndex&)));
98
 
                connect(player,SIGNAL(stopped()),this,SLOT(stopped()));
99
 
                connect(skip_incomplete,SIGNAL(toggled(bool)),this,SLOT(skipIncompleteChecked(bool)));
100
 
                connect(queue_mode,SIGNAL(activated(int)),this,SLOT(modeActivated(int)));
101
54
        }
102
55
 
103
56
 
105
58
        {
106
59
        }
107
60
        
108
 
        void MediaView::onSelectionChanged(const QItemSelection & s, const QItemSelection & d)
109
 
        {
110
 
                Q_UNUSED(d);
111
 
                QModelIndexList idx = s.indexes();
112
 
                if (idx.count() > 0)
113
 
                        selectionChanged(idx.front());
114
 
                else
115
 
                        selectionChanged(QModelIndex());
116
 
        }
117
 
        
118
61
        QModelIndex MediaView::selectedItem() const
119
62
        {
120
63
                QModelIndexList rows = media_tree->selectionModel()->selectedRows();
124
67
                        return QModelIndex();
125
68
        }
126
69
 
127
 
        void MediaView::playing(const QString & file)
128
 
        {
129
 
                if (file.isEmpty())
130
 
                {
131
 
                        stopped();
132
 
                }
133
 
                else
134
 
                {
135
 
                        current_file = file;
136
 
                        info_label->setText(i18n("Playing: <b>%1</b>",current_file));
137
 
                        metaDataChanged();
138
 
                }
139
 
        }
140
 
        
141
 
        void MediaView::stopped()
142
 
        {
143
 
                info_label->setText(i18n("Ready to play"));
144
 
                current_file = QString();
145
 
        }
146
 
        
147
 
        void MediaView::metaDataChanged()
148
 
        {
149
 
                QString extra_data;
150
 
                QByteArray encoded = QFile::encodeName(current_file);
151
 
                TagLib::FileRef ref(encoded.data(),true,TagLib::AudioProperties::Fast);
152
 
                if (ref.isNull())
153
 
                        return;
154
 
                
155
 
                TagLib::Tag* tag = ref.tag();
156
 
                if (!tag)
157
 
                        return;
158
 
                
159
 
                QString artist = tag->artist().toCString(true);
160
 
                QString title =  tag->title().toCString(true);
161
 
                QString album = tag->album().toCString(true);
162
 
                
163
 
                bool has_artist = !artist.isEmpty();
164
 
                bool has_title = !title.isEmpty();
165
 
                bool has_album = !album.isEmpty();
166
 
                
167
 
                if (has_artist && has_title && has_album)
168
 
                {
169
 
                        extra_data = i18n("Title: <b>%1</b><br/>Artist: <b>%2</b><br/>Album: <b>%3</b>",title,artist,album);
170
 
                        info_label->setText(i18n("Playing: <b>%1</b><br/>\n%2",current_file,extra_data));
171
 
                }
172
 
                else if (has_title && has_artist)
173
 
                {
174
 
                        extra_data = i18n("Title: <b>%1</b><br/>Artist: <b>%2</b>",title,artist);
175
 
                        info_label->setText(i18n("Playing: <b>%1</b><br/>\n%2",current_file,extra_data));
176
 
                }
177
 
                else if (has_title)
178
 
                {
179
 
                        extra_data = i18n("Title: <b>%1</b>",title);
180
 
                        info_label->setText(i18n("Playing: <b>%1</b><br/>\n%2",current_file,extra_data));
181
 
                }
182
 
                else
183
 
                {
184
 
                        info_label->setText(i18n("Playing: <b>%1</b>",current_file));
185
 
                }
186
 
        }
187
 
        
188
 
        void MediaView::skipIncompleteChecked(bool on)
189
 
        {
190
 
                MediaPlayerPluginSettings::setSkipIncomplete(on);
191
 
                MediaPlayerPluginSettings::self()->writeConfig();
192
 
        }
193
 
        
194
 
        void MediaView::modeActivated(int idx)
195
 
        {
196
 
                MediaPlayerPluginSettings::setPlayMode(idx);
197
 
                MediaPlayerPluginSettings::self()->writeConfig();
198
 
                if (idx == 2)
199
 
                        randomModeActivated();
200
 
        }
 
70
        
201
71
 
202
72
}