Example #1
0
PlacesItemModel::PlacesItemModel(QObject* parent) :
    KStandardItemModel(parent),
    m_fileIndexingEnabled(false),
    m_hiddenItemsShown(false),
    m_availableDevices(),
    m_predicate(),
    m_bookmarkManager(0),
    m_systemBookmarks(),
    m_systemBookmarksIndexes(),
    m_bookmarkedItems(),
    m_hiddenItemToRemove(-1),
    m_updateBookmarksTimer(0),
    m_storageSetupInProgress()
{
#ifdef HAVE_BALOO
    Baloo::IndexerConfig config;
    m_fileIndexingEnabled = config.fileIndexingEnabled();
#endif
    const QString file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/user-places.xbel";
    m_bookmarkManager = KBookmarkManager::managerForExternalFile(file);

    createSystemBookmarks();
    initializeAvailableDevices();
    loadBookmarks();

    const int syncBookmarksTimeout = 100;

    m_updateBookmarksTimer = new QTimer(this);
    m_updateBookmarksTimer->setInterval(syncBookmarksTimeout);
    m_updateBookmarksTimer->setSingleShot(true);
    connect(m_updateBookmarksTimer, &QTimer::timeout, this, &PlacesItemModel::updateBookmarks);

    connect(m_bookmarkManager, &KBookmarkManager::changed,
            m_updateBookmarksTimer, static_cast<void(QTimer::*)()>(&QTimer::start));
}
AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent,
                                           const QList<QByteArray>& visibleRoles) :
    QDialog(parent),
    m_visibleRoles(visibleRoles),
    m_listWidget(0)
{
    setWindowTitle(i18nc("@title:window", "Additional Information"));
    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);

    auto layout = new QVBoxLayout(this);
    setLayout(layout);

    // Add header
    auto header = new QLabel(this);
    header->setText(i18nc("@label", "Select which additional information should be shown:"));
    header->setWordWrap(true);
    layout->addWidget(header);

    // Add checkboxes
    bool indexingEnabled = false;
#ifdef HAVE_BALOO
    Baloo::IndexerConfig config;
    indexingEnabled = config.fileIndexingEnabled();
#endif

    m_listWidget = new QListWidget(this);
    m_listWidget->setSelectionMode(QAbstractItemView::NoSelection);
    const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
    foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
        QListWidgetItem* item = new QListWidgetItem(info.translation, m_listWidget);
        item->setCheckState(visibleRoles.contains(info.role) ? Qt::Checked : Qt::Unchecked);

        const bool enable = (!info.requiresBaloo && !info.requiresIndexer) ||
                            (info.requiresBaloo) ||
                            (info.requiresIndexer && indexingEnabled);

        if (!enable) {
            item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
        }
    }