CategoryFilterModel::CategoryFilterModel(QObject *parent)
    : QAbstractItemModel(parent)
    , m_rootItem(new CategoryModelItem)
{
    auto session = BitTorrent::Session::instance();

    connect(session, SIGNAL(categoryAdded(QString)), SLOT(categoryAdded(QString)));
    connect(session, SIGNAL(categoryRemoved(QString)), SLOT(categoryRemoved(QString)));
    connect(session, SIGNAL(torrentCategoryChanged(BitTorrent::TorrentHandle *const, QString))
            , SLOT(torrentCategoryChanged(BitTorrent::TorrentHandle *const, QString)));
    connect(session, SIGNAL(subcategoriesSupportChanged()), SLOT(subcategoriesSupportChanged()));
    connect(session, SIGNAL(torrentAdded(BitTorrent::TorrentHandle *const))
            , SLOT(torrentAdded(BitTorrent::TorrentHandle *const)));
    connect(session, SIGNAL(torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const))
            , SLOT(torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const)));

    populate();
}
CategoryFiltersList::CategoryFiltersList(QWidget *parent, TransferListWidget *transferList)
    : FiltersBase(parent, transferList)
{
    connect(BitTorrent::Session::instance(), SIGNAL(torrentCategoryChanged(BitTorrent::TorrentHandle *const, QString)), SLOT(torrentCategoryChanged(BitTorrent::TorrentHandle *const, QString)));
    connect(BitTorrent::Session::instance(), SIGNAL(categoryAdded(QString)), SLOT(addItem(QString)));
    connect(BitTorrent::Session::instance(), SIGNAL(categoryRemoved(QString)), SLOT(categoryRemoved(QString)));
    connect(BitTorrent::Session::instance(), SIGNAL(subcategoriesSupportChanged()), SLOT(subcategoriesSupportChanged()));

    refresh();
    toggleFilter(Preferences::instance()->getCategoryFilterState());
}