Пример #1
0
QVariant AnimeModel::data(const QModelIndex &index, int role) const {
  if (index.row() < 0 || index.row() >= m_list.count() ||
      role != Qt::DisplayRole) {
    return QVariant();
  }

  AnimePtr anime = m_list.at(index.row());

  if (index.column() == ListRoles::ID) return anime->id();
  if (index.column() == ListRoles::Title) return anime->title();
  if (index.column() == ListRoles::RomajiTitle) return anime->titleRomaji();
  if (index.column() == ListRoles::JapaneseTitle) return anime->titleJapanese();
  if (index.column() == ListRoles::EnglishTitle) return anime->titleEnglish();
  if (index.column() == ListRoles::Progress)
    return QString::number(anime->episodesWatched()) + " / " +
           QString::number(anime->totalEpisodes());
  if (index.column() == ListRoles::Score) return anime->score();
  if (index.column() == ListRoles::Status)
    return User::sharedUser()->trList(anime->listStatus());
  if (index.column() == ListRoles::AiringStatus)
    return User::sharedUser()->trStatus(anime->airingStatus());
  if (index.column() == ListRoles::Type)
    return User::sharedUser()->trType(anime->type());
  if (index.column() == ListRoles::Notes) return anime->notes();

  return QVariant();
}
Пример #2
0
void BrowseWidget::parseBrowserData(const QString &t_id,
                                    QNetworkReply *t_reply) {
  if (t_id != m_request_id) return;

  auto title_language = User::sharedUser()->titleLanguage();
  QByteArray data = t_reply->readAll();
  QJsonArray browse_results = QJsonDocument::fromJson(data).array();

  for (int i = 0; i <= browse_results.size(); i++) {
    QJsonObject anime = browse_results.at(i).toObject();
    auto title = anime.value(title_language).toString();

    if (title.isEmpty()) {
      qDebug() << "Unknown title for: " << QJsonDocument(anime).toJson();
      continue;
    }

    AnimePtr a = User::sharedUser()->getAnimeByTitle(title);

    if (a == AnimePtr(nullptr)) {
      a = Anime::makeAnime();
      a->setId(QString::number(anime.value("id").toInt()));
      a->setTitle(title);
      a->setImageUrl(anime.value("image_url_lge").toString());
      a->setTitleRomaji(anime.value("title_romaji").toString());
      a->setTitleJapanese(anime.value("title_japanese").toString());
      a->setTitleEnglish(anime.value("title_english").toString());
      a->setType(anime.value("type").toString());
      a->setAiringStatus(anime.value("airing_status").toString());
      a->setAverageScore(anime.value("average_score").toString().toDouble());
      a->setTotalEpisodes(anime.value("total_episodes").toInt());
      a->setAdult(anime.value("adult").toBool());

      if (a->id() == "0") {
        continue;
      }

      User::sharedUser()->addKnownAnime(a);
    }

    if (a->adult() && !User::sharedUser()->adultContent()) {
      continue;
    }

    BrowseAnime *s = new BrowseAnime(this, User::sharedUser()->scoreType());

    if (!a->hasLoaded()) {
      connect(a.get(), SIGNAL(imageLoaded()), s, SLOT(repaint()));
      emit loadAnime(a);
    }

    s->setAnime(a);

    m_browse_layout->addWidget(s);
    m_browse_layout->setGeometry(m_ui->result_area->geometry());

    int width = m_browse_layout->geometry().width();
    int cwidth = m_browse_layout->contentsWidth();

    if (m_browse_layout->heightForWidth(width) > this->geometry().height()) {
      width -= qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
    }

    m_browse_layout->setContentsMargins((width - cwidth) / 2, 0, 0, 0);
  }

  m_ui->browse_button->setEnabled(true);
}
Пример #3
0
void AnimeListWidget::customContextMenuRequested(const QPoint &t_pos) {
    auto model = m_ui->table->indexAt(t_pos);
    auto row = model.row();

    if (row < 0) return;

    QPoint position = t_pos;
    position.setY(t_pos.y() + 20);

    QAction *pAnimePanel = new QAction(tr("Open Anime Panel"), m_ui->table);
    QAction *pEpisodeIncrement =
        new QAction(tr("Increment Progress by 1"), m_ui->table);
    QMenu *pStatusUpdate = new QMenu(tr("Status"), m_ui->table);
    QAction *pDeleteEntry = new QAction(tr("Delete Entry"), m_ui->table);
    QMenu *pCustomLists = new QMenu(tr("Custom Lists"), m_ui->table);

    QAction *pWatching = new QAction(tr("Watching"), pStatusUpdate);
    QAction *pOnHold = new QAction(tr("On Hold"), pStatusUpdate);
    QAction *pPlanToWatch = new QAction(tr("Plan to Watch"), pStatusUpdate);
    QAction *pCompleted = new QAction(tr("Completed"), pStatusUpdate);
    QAction *pDropped = new QAction(tr("Dropped"), pStatusUpdate);

    QAction *pHideDefault = new QAction(tr("Hide Default"), pCustomLists);

    QAction *pRuleAction = new QAction(tr("Create rule"), m_ui->table);
    QAction *pSearch = new QAction(tr("Search For Torrents"), m_ui->table);

    auto index = m_proxy_model->index(model.row(), ListRoles::Title);
    auto title = m_proxy_model->data(index, Qt::DisplayRole).toString();
    AnimePtr anime = User::sharedUser()->getAnimeByTitle(title);

    for (int i = 0; i < User::sharedUser()->customListNames().count(); i++) {
        QString list = User::sharedUser()->customListNames().at(i);
        if (list.isEmpty()) continue;

        QAction *temp = new QAction(list, m_ui->table);
        temp->setCheckable(true);

        if (anime->customLists().at(i) == 1) {
            temp->setChecked(true);
        } else {
            temp->setChecked(false);
        }

        connect(temp, &QAction::toggled, [this, anime, i](bool selected) {
            QList<int> custom = anime->customLists();
            custom.replace(i, selected ? 1 : 0);
            anime->setCustomLists(custom);

            QMap<QString, QString> data;
            data.insert("id", anime->id());
            QString d;
            for (int i = 0; i < custom.length(); i++) {
                d += QString::number(custom.at(i)) +
                     ((i == custom.length() - 1) ? "" : ",");
            }

            data.insert("custom_lists", d);

            auto api = API::sharedAPI()->sharedAniListAPI();

            api->put(api->API_EDIT_LIST, data);

            emit refreshLists();
        });

        pCustomLists->addAction(temp);
    }

    pHideDefault->setCheckable(true);
    pHideDefault->setChecked(anime->hiddenDefault());

    pCustomLists->addAction(pHideDefault);

    connect(pHideDefault, &QAction::toggled, [this, anime](bool selected) {
        QMap<QString, QString> data;
        data.insert("id", anime->id());
        data.insert("hidden_default", selected ? "1" : "0");

        if (selected) {
            User::sharedUser()->removeFromList(anime->listStatus(), anime);
        }

        emit animePayloadChanged(anime, data);
    });

    pStatusUpdate->addAction(pWatching);
    pStatusUpdate->addAction(pOnHold);
    pStatusUpdate->addAction(pPlanToWatch);
    pStatusUpdate->addAction(pCompleted);
    pStatusUpdate->addAction(pDropped);

    connect(pAnimePanel, &QAction::triggered,
    [this, row, anime]() {
        emit animePanelRequested(anime);
    });

    connect(pEpisodeIncrement, &QAction::triggered, [&anime, this]() {
        if (anime->episodesWatched() >= anime->totalEpisodes() &&
                anime->totalEpisodes() != 0) {
            return;
        }
        anime->setEpisodesWatched(anime->episodesWatched() + 1);

        if (anime->episodesWatched() == anime->totalEpisodes() &&
                anime->totalEpisodes() != 0) {
            anime->setListStatus("completed");
        }

        m_proxy_model->invalidate();
        emit animeChanged(anime);
    });

    connect(pWatching, &QAction::triggered,
    [this, anime]() {
        updateStatus(anime, "watching");
    });

    connect(pPlanToWatch, &QAction::triggered,
    [this, anime]() {
        updateStatus(anime, "plan to watch");
    });

    connect(pOnHold, &QAction::triggered,
    [this, anime]() {
        updateStatus(anime, "on-hold");
    });

    connect(pDropped, &QAction::triggered,
    [this, anime]() {
        updateStatus(anime, "dropped");
    });

    connect(pCompleted, &QAction::triggered,
    [this, anime]() {
        updateStatus(anime, "completed");
    });

    connect(pDeleteEntry, &QAction::triggered, [this, anime]() {
        auto api = API::sharedAPI()->sharedAniListAPI();
        auto url = api->API_DELETE_ANIME(anime->id());

        api->deleteResource(url);

        User::sharedUser()->removeAll(anime);
        emit refreshLists();
    });

    connect(pRuleAction, &QAction::triggered,
    [this, anime]() {
        emit createAndShowRule(anime, "");
    });

    connect(pSearch, &QAction::triggered,
    [this, anime]() {
        emit searchTorrents(anime);
    });

    QMenu *pContextMenu = new QMenu(this);

    pContextMenu->addAction(pAnimePanel);
    pContextMenu->addAction(pEpisodeIncrement);
    pContextMenu->addMenu(pStatusUpdate);

    if (User::sharedUser()->customListNames().length() > 0) {
        pContextMenu->addMenu(pCustomLists);
    } else {
        delete pCustomLists;
    }

    pContextMenu->addAction(pDeleteEntry);
    pContextMenu->addAction(pRuleAction);
    pContextMenu->addAction(pSearch);

    pContextMenu->exec(mapToGlobal(position));

    delete pContextMenu;
    pContextMenu = nullptr;
}