~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/library/libraryview.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
*/
17
17
 
18
18
#include "librarydirectorymodel.h"
 
19
#include "libraryfilterwidget.h"
19
20
#include "librarymodel.h"
20
21
#include "libraryview.h"
21
22
#include "libraryitem.h"
26
27
#include "core/utilities.h"
27
28
#include "devices/devicemanager.h"
28
29
#include "devices/devicestatefiltermodel.h"
29
 
#include "scripting/scriptmanager.h"
30
 
#include "scripting/uiinterface.h"
31
30
#include "smartplaylists/wizard.h"
32
31
#include "ui/iconloader.h"
33
32
#include "ui/organisedialog.h"
131
130
 
132
131
LibraryView::LibraryView(QWidget* parent)
133
132
  : AutoExpandingTreeView(parent),
134
 
    scripts_(NULL),
 
133
    cover_providers_(NULL),
135
134
    library_(NULL),
 
135
    devices_(NULL),
 
136
    task_manager_(NULL),
 
137
    filter_(NULL),
136
138
    total_song_count_(-1),
137
139
    nomusic_(":nomusic.png"),
138
140
    context_menu_(NULL),
146
148
  setDragDropMode(QAbstractItemView::DragOnly);
147
149
  setSelectionMode(QAbstractItemView::ExtendedSelection);
148
150
 
149
 
  ReloadSettings();
150
151
  setStyleSheet("QTreeView::item{padding-top:1px;}");
151
152
}
152
153
 
164
165
  }
165
166
}
166
167
 
 
168
void LibraryView::SetCoverProviders(CoverProviders* cover_providers) {
 
169
  cover_providers_ = cover_providers;
 
170
}
 
171
 
167
172
void LibraryView::SetTaskManager(TaskManager *task_manager) {
168
173
  task_manager_ = task_manager;
169
174
}
177
182
  devices_ = device_manager;
178
183
}
179
184
 
180
 
void LibraryView::SetScriptManager(ScriptManager* scripts) {
181
 
  scripts_ = scripts;
 
185
void LibraryView::SetFilter(LibraryFilterWidget* filter) {
 
186
  filter_ = filter;
182
187
}
183
188
 
184
189
void LibraryView::TotalSongCountUpdated(int count) {
277
282
 
278
283
    context_menu_->addSeparator();
279
284
 
 
285
    context_menu_->addMenu(filter_->menu());
 
286
 
280
287
    copy_to_device_->setDisabled(devices_->connected_devices_model()->rowCount() == 0);
281
288
    connect(devices_->connected_devices_model(), SIGNAL(IsEmptyChanged(bool)),
282
289
            copy_to_device_, SLOT(setDisabled(bool)));
283
 
 
284
 
    if(scripts_) {
285
 
      scripts_->ui()->RegisterActionLocation("library_context_menu", context_menu_, NULL);
286
 
    }
287
290
  }
288
291
 
289
292
  context_menu_index_ = indexAt(e->pos());
377
380
  if (!context_menu_index_.isValid())
378
381
    return;
379
382
 
380
 
  // Build a list of the selected unique album/artist combos
381
 
  typedef QPair<QString, QString> AlbumArtist;
382
 
  QSet<AlbumArtist> selected;
 
383
  // Map is from album name -> all artists sharing that album name, built from each selected
 
384
  // song. We put through "Various Artists" changes one album at a time, to make sure the old album
 
385
  // node gets removed (due to all children removed), before the new one gets added
 
386
  QMultiMap<QString, QString> albums;
383
387
  foreach (const Song& song, GetSelectedSongs()) {
384
 
    selected << AlbumArtist(song.album(), song.artist());
 
388
    if (albums.find(song.album(), song.artist()) == albums.end())
 
389
      albums.insert( song.album(), song.artist() );
385
390
  }
386
391
 
387
 
  foreach (const AlbumArtist& albumartist, selected.values()) {
388
 
    library_->backend()->ForceCompilation(
389
 
          albumartist.second, albumartist.first, on);
 
392
  foreach (const QString& album, QSet<QString>::fromList(albums.keys())) {
 
393
    library_->backend()->ForceCompilation(album, albums.values(album), on);
390
394
  }
391
395
}
392
396
 
472
476
 
473
477
void LibraryView::EditTracks() {
474
478
  if(!edit_tag_dialog_) {
475
 
    edit_tag_dialog_.reset(new EditTagDialog(this));
 
479
    edit_tag_dialog_.reset(new EditTagDialog(cover_providers_, this));
476
480
  }
477
481
  edit_tag_dialog_->SetSongs(GetSelectedSongs());
478
482
  edit_tag_dialog_->SetTagCompleter(library_->backend());
547
551
  library_->UpdateGenerator(context_menu_index_, wizard->CreateGenerator());
548
552
}
549
553
 
550
 
QString LibraryView::GetNameForNewPlaylist(const SongList& songs) {
551
 
  if (songs.isEmpty()) {
552
 
    return tr("Playlist");
553
 
  }
554
 
 
555
 
  QSet<QString> artists;
556
 
  QSet<QString> albums;
557
 
 
558
 
  foreach(const Song& song, songs) {
559
 
    artists << (song.artist().isEmpty()
560
 
                    ? tr("Unknown")
561
 
                    : song.artist());
562
 
    albums << (song.album().isEmpty()
563
 
                    ? tr("Unknown")
564
 
                    : song.album());
565
 
 
566
 
    if(artists.size() > 1) {
567
 
      break;
568
 
    }
569
 
  }
570
 
 
571
 
  bool various_artists = artists.size() > 1;
572
 
 
573
 
  QString result;
574
 
  if(various_artists) {
575
 
    result = tr("Various artists");
576
 
  } else {
577
 
    result = artists.values().first();
578
 
  }
579
 
 
580
 
  if(!various_artists && albums.size() == 1) {
581
 
    result += " - " + albums.toList().first();
582
 
  }
583
 
 
584
 
  return result;
585
 
}
586
 
 
587
554
void LibraryView::ShowInBrowser() {
588
 
  QStringList filenames;
 
555
  QList<QUrl> urls;
589
556
  foreach (const Song& song, GetSelectedSongs()) {
590
 
    filenames << song.filename();
 
557
    urls << song.url();
591
558
  }
592
559
 
593
 
  Utilities::OpenInFileBrowser(filenames);
 
560
  Utilities::OpenInFileBrowser(urls);
594
561
}