Example #1
0
void UserLoader::downloadCover(const AnimePtr &t_anime) {
  ImageDownloader *downloader = new ImageDownloader(t_anime->imageUrl());

  connect(downloader, &ImageDownloader::downloaded, [t_anime, downloader]() {
#ifndef DISABLE_PIXMAP
    t_anime->setCoverImage(downloader->downloadedData());
#endif
    downloader->deleteLater();
  });
}
Example #2
0
void AnimeListWidget::updateStatus(AnimePtr t_anime, const QString &t_status) {
    if (t_status == t_anime->listStatus()) return;

    t_anime->setListStatus(t_status);
    emit animeChanged(t_anime);

    User::sharedUser()->removeFromList(m_list, t_anime);
    User::sharedUser()->addToList(t_status, t_anime);

    m_proxy_model->invalidate();
}
Example #3
0
void ProgressDelegate::setEditorData(QWidget *editor,
                                     const QModelIndex &index) const {
  auto model = index.model();
  auto id =
      model->data(model->index(index.row(), ListRoles::ID), Qt::DisplayRole);

  AnimePtr anime = User::sharedUser()->getAnimeByID(id.toString());

  auto episodes_watched = anime->episodesWatched();
  auto total_episodes = anime->totalEpisodes();

  if (total_episodes == 0) {
    total_episodes = std::numeric_limits<int>::max();
  }

  QSpinBox *spinBox = static_cast<QSpinBox *>(editor);
  spinBox->setMaximum(total_episodes);
  spinBox->setValue(episodes_watched);
  spinBox->setSuffix(" / " + QString::number(anime->totalEpisodes()));
}
Example #4
0
bool AnimeModel::setData(const QModelIndex &index, const QVariant &value,
                         int role) {
  if (index.row() < 0 || index.row() >= m_list.count() ||
      role != Qt::EditRole) {
    return false;
  }

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

  if (index.column() == ListRoles::Progress) {
    anime->setEpisodesWatched(value.toInt());
    emit animeChanged(anime);
    return true;
  } else if (index.column() == ListRoles::Status) {
    anime->setListStatus(value.toString());
    emit animeChanged(anime);
    return true;
  } else if (index.column() == ListRoles::Score) {
    auto score_type = User::sharedUser()->scoreType();

    if ((score_type == ScoreType::TenPoint) ||
        (score_type == ScoreType::HundredPoint)) {
      anime->setScore(QString::number(value.toInt()));
    } else if (score_type == ScoreType::FiveStar) {
      anime->setScore(value.toString());
    } else if (score_type == ScoreType::Smiles) {
      anime->setScore(value.toString());
    } else {
      anime->setScore(QString::number(value.toDouble()));
    }

    emit animeChanged(anime);
    return true;
  }

  return false;
}
Example #5
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);
}
Example #6
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;
}
Example #7
0
void UserLoader::parseAnime(const QJsonObject &t_reply) {
  QJsonObject result = t_reply;
  auto id = QString::number(result.value("id").toInt());
  auto title_language = User::sharedUser()->titleLanguage();

  AnimePtr anime = User::sharedUser()->getAnimeByID(id);

  if (anime == AnimePtr(nullptr)) {
    anime = Anime::makeAnime();

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

  auto description = result.value("description").toString();
  auto airing = result.value("airing").toObject();

  anime->setDuration(result.value("duration").toInt());
  anime->setDescription(description);
  anime->setTitleRomaji(result.value("title_romaji").toString());
  anime->setTitleJapanese(result.value("title_japanese").toString());
  anime->setTitleEnglish(result.value("title_english").toString());
  anime->setType(result.value("type").toString());
  anime->setAiringStatus(result.value("airing_status").toString());
  anime->setAverageScore(result.value("average_score").toString().toDouble());
  anime->setTotalEpisodes(result.value("total_episodes").toInt());
  anime->setAdult(result.value("adult").toBool());
  anime->setTitle(result.value(title_language).toString());
  anime->setNextEpisode(airing.value("next_episode").toInt());
  anime->setCountdown(airing.value("countdown").toInt());

  anime->finishLoad();

  qDebug() << "Loaded extra data for anime" << anime->title();
}
Example #8
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();
}