コード例 #1
0
ファイル: rsswidget.cpp プロジェクト: glassez/qBittorrent
RSSWidget::RSSWidget(QWidget *parent)
    : QWidget {parent}
    , m_ui {new Ui::RSSWidget}
{
    m_ui->setupUi(this);

    // Icons
    m_ui->actionCopyFeedURL->setIcon(GuiIconProvider::instance()->getIcon("edit-copy"));
    m_ui->actionDelete->setIcon(GuiIconProvider::instance()->getIcon("edit-delete"));
    m_ui->actionDownloadTorrent->setIcon(GuiIconProvider::instance()->getIcon("download"));
    m_ui->actionMarkItemsRead->setIcon(GuiIconProvider::instance()->getIcon("mail-mark-read"));
    m_ui->actionNewFolder->setIcon(GuiIconProvider::instance()->getIcon("folder-new"));
    m_ui->actionNewSubscription->setIcon(GuiIconProvider::instance()->getIcon("list-add"));
    m_ui->actionOpenNewsURL->setIcon(GuiIconProvider::instance()->getIcon("application-x-mswinurl"));
    m_ui->actionRename->setIcon(GuiIconProvider::instance()->getIcon("edit-rename"));
    m_ui->actionUpdate->setIcon(GuiIconProvider::instance()->getIcon("view-refresh"));
    m_ui->actionUpdateAllFeeds->setIcon(GuiIconProvider::instance()->getIcon("view-refresh"));
#ifndef Q_OS_MAC
    m_ui->newFeedButton->setIcon(GuiIconProvider::instance()->getIcon("list-add"));
    m_ui->markReadButton->setIcon(GuiIconProvider::instance()->getIcon("mail-mark-read"));
    m_ui->updateAllButton->setIcon(GuiIconProvider::instance()->getIcon("view-refresh"));
    m_ui->rssDownloaderBtn->setIcon(GuiIconProvider::instance()->getIcon("download"));
#endif

    m_rssTreeView = new QTreeView {m_ui->splitterSide};
    m_ui->splitterSide->insertWidget(0, m_rssTreeView);
    auto *rssProxyModel = new RSSSortModel {m_rssTreeView};
    rssProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
    rssProxyModel->setSourceModel(new RSSModel {m_rssTreeView});
    m_rssTreeView->setModel(rssProxyModel);
    connect(m_rssTreeView, &QAbstractItemView::doubleClicked, this, &RSSWidget::renameSelectedRSSItem);
    connect(m_rssTreeView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &RSSWidget::handleCurrentItemChanged);
    connect(m_rssTreeView, &QWidget::customContextMenuRequested, this, &RSSWidget::displayRSSListMenu);
    m_rssTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
    m_rssTreeView->setDragEnabled(true);
    m_rssTreeView->setAcceptDrops(true);
    m_rssTreeView->setDragDropMode(QAbstractItemView::InternalMove);
    m_rssTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
    expandItems(Preferences::instance()->getRSSWidgetExpandedItems(), {});
    m_rssTreeView->setSortingEnabled(true);
    m_rssTreeView->sortByColumn(0, Qt::AscendingOrder);

    m_articleListView = new QListView {m_ui->splitterMain};
    m_ui->splitterMain->insertWidget(0, m_articleListView);
    m_rssFeedModel = new RSSFeedModel {nullptr, m_articleListView};
    auto *articleProxyModel = new RSSFeedSortModel {m_articleListView};
    articleProxyModel->setSourceModel(m_rssFeedModel);
    m_articleListView->setModel(articleProxyModel);
    connect(m_articleListView, &QListView::customContextMenuRequested, this, &RSSWidget::displayArticleListMenu);
    connect(m_articleListView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &RSSWidget::handleCurrentArticleChanged);
    connect(m_articleListView, &QListView::doubleClicked, this, &RSSWidget::downloadSelectedTorrents);
    m_articleListView->setContextMenuPolicy(Qt::CustomContextMenu);
    m_articleListView->setSelectionMode(QAbstractItemView::ExtendedSelection);

    m_rssTreeView->setCurrentIndex(m_rssTreeView->model()->index(0, 0));

    auto *editHotkey = new QShortcut {Qt::Key_F2, m_rssTreeView, nullptr, nullptr, Qt::WidgetShortcut};
    connect(editHotkey, &QShortcut::activated, this, &RSSWidget::renameSelectedRSSItem);
    auto *deleteHotkey = new QShortcut {QKeySequence::Delete, m_rssTreeView, nullptr, nullptr, Qt::WidgetShortcut};
    connect(deleteHotkey, &QShortcut::activated, this, &RSSWidget::deleteSelectedItems);

    // Feeds list actions
    connect(m_ui->actionDelete, &QAction::triggered, this, &RSSWidget::deleteSelectedItems);
    connect(m_ui->actionRename, &QAction::triggered, this, &RSSWidget::renameSelectedRSSItem);
    connect(m_ui->actionUpdate, &QAction::triggered, this, &RSSWidget::refreshSelectedItems);
    connect(m_ui->actionNewFolder, &QAction::triggered, this, &RSSWidget::askNewFolder);
    connect(m_ui->actionNewSubscription, &QAction::triggered, this, &RSSWidget::on_newFeedButton_clicked);
    connect(m_ui->actionUpdateAllFeeds, &QAction::triggered, this, &RSSWidget::refreshAllFeeds);
    connect(m_ui->updateAllButton, &QAbstractButton::clicked, this, &RSSWidget::refreshAllFeeds);
    connect(m_ui->actionCopyFeedURL, &QAction::triggered, this, &RSSWidget::copySelectedFeedsURL);
    connect(m_ui->actionMarkItemsRead, &QAction::triggered, this, &RSSWidget::on_markReadButton_clicked);

    // News list actions
    connect(m_ui->actionOpenNewsURL, &QAction::triggered, this, &RSSWidget::openSelectedArticlesUrls);
    connect(m_ui->actionDownloadTorrent, &QAction::triggered, this, &RSSWidget::downloadSelectedTorrents);

    // Restore sliders position
    restoreSlidersPosition();
    // Bind saveSliders slots
    connect(m_ui->splitterMain, &QSplitter::splitterMoved, this, &RSSWidget::saveSlidersPosition);
    connect(m_ui->splitterSide, &QSplitter::splitterMoved, this, &RSSWidget::saveSlidersPosition);

    if (RSS::Manager::instance()->isProcessingEnabled())
        m_ui->labelWarn->hide();
    connect(RSS::Manager::instance(), &RSS::Manager::processingStateChanged
            , this, &RSSWidget::handleSessionProcessingStateChanged);
    connect(RSS::Manager::instance()->rootFolder(), &RSS::Folder::unreadCountChanged
            , this, &RSSWidget::handleUnreadCountChanged);
}
コード例 #2
0
ファイル: rsswidget.cpp プロジェクト: ATGardner/qBittorrent
RSSWidget::RSSWidget(QWidget *parent)
    : QWidget(parent)
    , m_ui(new Ui::RSSWidget)
{
    m_ui->setupUi(this);

    // Icons
    m_ui->actionCopyFeedURL->setIcon(GuiIconProvider::instance()->getIcon("edit-copy"));
    m_ui->actionDelete->setIcon(GuiIconProvider::instance()->getIcon("edit-delete"));
    m_ui->actionDownloadTorrent->setIcon(GuiIconProvider::instance()->getIcon("download"));
    m_ui->actionMarkItemsRead->setIcon(GuiIconProvider::instance()->getIcon("mail-mark-read"));
    m_ui->actionNewFolder->setIcon(GuiIconProvider::instance()->getIcon("folder-new"));
    m_ui->actionNewSubscription->setIcon(GuiIconProvider::instance()->getIcon("list-add"));
    m_ui->actionOpenNewsURL->setIcon(GuiIconProvider::instance()->getIcon("application-x-mswinurl"));
    m_ui->actionRename->setIcon(GuiIconProvider::instance()->getIcon("edit-rename"));
    m_ui->actionUpdate->setIcon(GuiIconProvider::instance()->getIcon("view-refresh"));
    m_ui->actionUpdateAllFeeds->setIcon(GuiIconProvider::instance()->getIcon("view-refresh"));
    m_ui->newFeedButton->setIcon(GuiIconProvider::instance()->getIcon("list-add"));
    m_ui->markReadButton->setIcon(GuiIconProvider::instance()->getIcon("mail-mark-read"));
    m_ui->updateAllButton->setIcon(GuiIconProvider::instance()->getIcon("view-refresh"));
    m_ui->rssDownloaderBtn->setIcon(GuiIconProvider::instance()->getIcon("download"));

    m_articleListWidget = new ArticleListWidget(m_ui->splitterMain);
    m_ui->splitterMain->insertWidget(0, m_articleListWidget);
    connect(m_articleListWidget, &ArticleListWidget::customContextMenuRequested, this, &RSSWidget::displayItemsListMenu);
    connect(m_articleListWidget, &ArticleListWidget::currentItemChanged, this, &RSSWidget::handleCurrentArticleItemChanged);
    connect(m_articleListWidget, &ArticleListWidget::itemDoubleClicked, this, &RSSWidget::downloadSelectedTorrents);

    m_feedListWidget = new FeedListWidget(m_ui->splitterSide);
    m_ui->splitterSide->insertWidget(0, m_feedListWidget);
    connect(m_feedListWidget, &QAbstractItemView::doubleClicked, this, &RSSWidget::renameSelectedRSSItem);
    connect(m_feedListWidget, &QTreeWidget::currentItemChanged, this, &RSSWidget::handleCurrentFeedItemChanged);
    connect(m_feedListWidget, &QWidget::customContextMenuRequested, this, &RSSWidget::displayRSSListMenu);
    loadFoldersOpenState();
    m_feedListWidget->setCurrentItem(m_feedListWidget->stickyUnreadItem());

    m_editHotkey = new QShortcut(Qt::Key_F2, m_feedListWidget, 0, 0, Qt::WidgetShortcut);
    connect(m_editHotkey, &QShortcut::activated, this, &RSSWidget::renameSelectedRSSItem);
    m_deleteHotkey = new QShortcut(QKeySequence::Delete, m_feedListWidget, 0, 0, Qt::WidgetShortcut);
    connect(m_deleteHotkey, &QShortcut::activated, this, &RSSWidget::deleteSelectedItems);

    // Feeds list actions
    connect(m_ui->actionDelete, &QAction::triggered, this, &RSSWidget::deleteSelectedItems);
    connect(m_ui->actionRename, &QAction::triggered, this, &RSSWidget::renameSelectedRSSItem);
    connect(m_ui->actionUpdate, &QAction::triggered, this, &RSSWidget::refreshSelectedItems);
    connect(m_ui->actionNewFolder, &QAction::triggered, this, &RSSWidget::askNewFolder);
    connect(m_ui->actionNewSubscription, &QAction::triggered, this, &RSSWidget::on_newFeedButton_clicked);
    connect(m_ui->actionUpdateAllFeeds, &QAction::triggered, this, &RSSWidget::refreshAllFeeds);
    connect(m_ui->updateAllButton, &QAbstractButton::clicked, this, &RSSWidget::refreshAllFeeds);
    connect(m_ui->actionCopyFeedURL, &QAction::triggered, this, &RSSWidget::copySelectedFeedsURL);
    connect(m_ui->actionMarkItemsRead, &QAction::triggered, this, &RSSWidget::on_markReadButton_clicked);

    // News list actions
    connect(m_ui->actionOpenNewsURL, &QAction::triggered, this, &RSSWidget::openSelectedArticlesUrls);
    connect(m_ui->actionDownloadTorrent, &QAction::triggered, this, &RSSWidget::downloadSelectedTorrents);

    // Restore sliders position
    restoreSlidersPosition();
    // Bind saveSliders slots
    connect(m_ui->splitterMain, &QSplitter::splitterMoved, this, &RSSWidget::saveSlidersPosition);
    connect(m_ui->splitterSide, &QSplitter::splitterMoved, this, &RSSWidget::saveSlidersPosition);

    if (RSS::Session::instance()->isProcessingEnabled())
        m_ui->labelWarn->hide();
    connect(RSS::Session::instance(), &RSS::Session::processingStateChanged
            , this, &RSSWidget::handleSessionProcessingStateChanged);
    connect(RSS::Session::instance()->rootFolder(), &RSS::Folder::unreadCountChanged
            , this, &RSSWidget::handleUnreadCountChanged);
}