コード例 #1
0
void PlaylistTabBar::InsertTab(int id, int index, const QString& text,
                               bool favorite) {
  suppress_current_changed_ = true;
  insertTab(index, text);
  setTabData(index, id);
  setTabToolTip(index, text);

  FavoriteWidget* widget = new FavoriteWidget(id, favorite);
  widget->setToolTip(
      tr("Click here to favorite this playlist so it will be saved and remain "
         "accessible "
         "through the \"Playlists\" panel on the left side bar"));
  connect(widget, SIGNAL(FavoriteStateChanged(int, bool)),
          SIGNAL(PlaylistFavorited(int, bool)));
  setTabButton(index, QTabBar::LeftSide, widget);
  suppress_current_changed_ = false;

  // If we are still starting up, we don't need to do this, as the
  // tab ordering after startup will be the same as was already in the db.
  if (initialized_) {
    if (currentIndex() == index) emit CurrentIdChanged(id);

    // Update playlist tab order/visibility
    TabMoved();
  }
}
コード例 #2
0
void PlaylistTabBar::Close() {
  if (menu_index_ == -1)
    return;

  // Just hide the tab from the UI - don't delete it completely (it can still
  // be resurrected from the Playlists tab).
  emit Close(tabData(menu_index_).toInt());

  // Select the nearest tab.
  if (menu_index_ > 1) {
    setCurrentIndex(menu_index_ - 1);
  }

  // Update playlist tab order/visibility
  TabMoved();
}
コード例 #3
0
void PlaylistTabBar::InsertTab(int id, int index, const QString& text, bool favorite) {
  suppress_current_changed_ = true;
  insertTab(index, text);
  setTabData(index, id);
  setTabToolTip(index, text);
  FavoriteWidget* widget = new FavoriteWidget(id, favorite);
  connect(widget, SIGNAL(FavoriteStateChanged(int, bool)),
                  SIGNAL(PlaylistFavorited(int, bool)));
  setTabButton(index, QTabBar::LeftSide, widget);
  suppress_current_changed_ = false;

  if (currentIndex() == index)
    emit CurrentIdChanged(id);

  // Update playlist tab order/visibility
  TabMoved();
}
コード例 #4
0
void PlaylistTabBar::Close() {
  if (menu_index_ == -1) return;

  const int playlist_id = tabData(menu_index_).toInt();

  const int active_id = manager_->active_id();

  qLog(Debug) << "Close : active_id = " << active_id << " and playlist_id = " << playlist_id;


  QSettings s;
  s.beginGroup(kSettingsGroup);

  const bool ask_for_delete = s.value("warn_close_playlist", true).toBool();

  bool check_delete = (ask_for_delete && !manager_->IsPlaylistFavorite(playlist_id) &&
        !manager_->playlist(playlist_id)->GetAllSongs().empty());

  bool check_active = (active_id == playlist_id && manager_->app()->player_locked_);

  qLog(Debug) << "Close : check_delete = " << check_delete << " and check_active = " << check_active;

  if (check_delete || check_active) {

    QMessageBox confirmation_box;
    confirmation_box.setWindowIcon(QIcon(":/icon.png"));
    confirmation_box.setWindowTitle(tr("Remove playlist"));
    confirmation_box.setIcon(QMessageBox::Question);
    confirmation_box.setText(
        tr("You are about to remove a playlist which is not part of your "
           "favorite playlists: "
           "the playlist will be deleted (this action cannot be undone). \n"
           "Are you sure you want to continue?"));
    confirmation_box.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);

    QCheckBox dont_prompt_again(tr("Warn me when closing a playlist tab"),
                                &confirmation_box);
    dont_prompt_again.setChecked(ask_for_delete);
    dont_prompt_again.blockSignals(true);
    dont_prompt_again.setToolTip(
        tr("This option can be changed in the \"Behavior\" preferences"));

    QGridLayout* grid = qobject_cast<QGridLayout*>(confirmation_box.layout());
    QDialogButtonBox* buttons = confirmation_box.findChild<QDialogButtonBox*>();
    if (grid && buttons) {
      const int index = grid->indexOf(buttons);
      int row, column, row_span, column_span = 0;
      grid->getItemPosition(index, &row, &column, &row_span, &column_span);
      QLayoutItem* buttonsItem = grid->takeAt(index);
      grid->addWidget(&dont_prompt_again, row, column, row_span, column_span,
                      Qt::AlignLeft | Qt::AlignTop);
      grid->addItem(buttonsItem, ++row, column, row_span, column_span);
    } else {
      confirmation_box.addButton(&dont_prompt_again, QMessageBox::ActionRole);
    }

    if (confirmation_box.exec() != QMessageBox::Yes) {
      return;
    }

    // If user changed the pref, save the new one
    if (dont_prompt_again.isChecked() != ask_for_delete) {
      s.setValue("warn_close_playlist", dont_prompt_again.isChecked());
    }
  }

  // Close the playlist. If the playlist is not a favorite playlist, it will be
  // deleted, as it will not be visible after being closed. Otherwise, the tab
  // is closed but the playlist still exists and can be resurrected from the
  // "Playlists" tab.
  emit Close(playlist_id);

  // Select the nearest tab.
  if (menu_index_ > 1) {
    setCurrentIndex(menu_index_ - 1);
  }

  // Update playlist tab order/visibility
  TabMoved();
}