示例#1
0
KoRecentDocumentsPane::KoRecentDocumentsPane(QWidget* parent, const KComponentData &_componentData,
        const QString& header)
        : KoDetailsPane(parent, _componentData, header)
        , d(new KoRecentDocumentsPanePrivate)
{
    setFocusProxy(m_documentList);
    KGuiItem openGItem(i18n("Open This Document"), "document-open");
    m_openButton->setGuiItem(openGItem);
    m_alwaysUseCheckBox->hide();

    model()->setSortRole(0); // Disable sorting

    KConfigGroup config(componentData().config(), "RecentFiles");

    int i = 1;
    QString path;
    KFileItemList fileList;
    QStandardItem* rootItem = model()->invisibleRootItem();

    do {
        path = config.readPathEntry(QString("File%1").arg(i), QString());

        if (!path.isEmpty()) {
            QString name = config.readPathEntry(QString("Name%1").arg(i), QString());

            KUrl url(path);

            if (name.isEmpty())
                name = url.fileName();

            if (!url.isLocalFile() || QFile::exists(url.toLocalFile())) {
                KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, url);
                fileList.prepend(fileItem);
                //center all icons in 64x64 area
                QImage icon = fileItem.pixmap(64).toImage();
                icon = icon.convertToFormat(QImage::Format_ARGB32);
                icon = icon.copy((icon.width() - 64) / 2, (icon.height() - 64) / 2, 64, 64);
                KoFileListItem* item = new KoFileListItem(QPixmap::fromImage(icon), name);
                item->setEditable(false);
                item->setData(fileItem.pixmap(128), Qt::UserRole);
                item->setFileItem(fileItem);
                rootItem->insertRow(0, item);
            }
        }

        i++;
    } while (!path.isEmpty() || i <= 10);


    //Select the first file
    QModelIndex firstIndex = model()->indexFromItem(model()->item(0));
    m_documentList->selectionModel()->select(firstIndex, QItemSelectionModel::Select);
    m_documentList->selectionModel()->setCurrentIndex(firstIndex, QItemSelectionModel::Select);

    d->m_previewJob = KIO::filePreview(fileList, QSize(200, 200), 0);

    connect(d->m_previewJob, SIGNAL(result(KJob*)), this, SLOT(previewResult(KJob*)));
    connect(d->m_previewJob, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
            this, SLOT(updatePreview(const KFileItem&, const QPixmap&)));
}
KoRecentDocumentsPane::KoRecentDocumentsPane(QWidget* parent, const KComponentData &_componentData,
        const QString& header)
        : KoDetailsPane(parent, _componentData, header)
        , d(new KoRecentDocumentsPanePrivate)
{
    setFocusProxy(m_documentList);
    KGuiItem openGItem(i18n("Open This Document"), koIconName("document-open"));
    m_openButton->setGuiItem(openGItem);
    m_alwaysUseCheckBox->hide();

    model()->setSortRole(0); // Disable sorting

    KConfigGroup config(componentData().config(), "RecentFiles");

    int i = 1;
    QString path;
    KFileItemList fileList;
    QStandardItem* rootItem = model()->invisibleRootItem();

    do {
        path = config.readPathEntry(QString("File%1").arg(i), QString());

        if (!path.isEmpty()) {
            QString name = config.readPathEntry(QString("Name%1").arg(i), QString());

            QUrl url(path);

            if (name.isEmpty())
                name = url.fileName();

            if (!url.isLocalFile() || QFile::exists(url.toLocalFile())) {
                KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, url);
                fileList.prepend(fileItem);
                const QIcon icon = QIcon::fromTheme(fileItem.iconName());
                KoFileListItem* item = new KoFileListItem(icon, name, fileItem);
                item->setEditable(false);
                rootItem->insertRow(0, item);
            }
        }

        i++;
    } while (!path.isEmpty() || i <= 10);


    //Select the first file
    QModelIndex firstIndex = model()->indexFromItem(model()->item(0));
    m_documentList->selectionModel()->select(firstIndex, QItemSelectionModel::Select);
    m_documentList->selectionModel()->setCurrentIndex(firstIndex, QItemSelectionModel::Select);

    QStringList availablePlugins = KIO::PreviewJob::availablePlugins();
    KIO::PreviewJob *previewJob = KIO::filePreview(fileList, QSize(IconExtent, IconExtent), &availablePlugins);

    d->m_previewJobs.append(previewJob);
    connect(previewJob, SIGNAL(result(KJob*)), SLOT(previewResult(KJob*)));
    connect(previewJob, SIGNAL(gotPreview(KFileItem,QPixmap)),
            SLOT(updateIcon(KFileItem,QPixmap)));
}
示例#3
0
KoRecentDocumentsPane::KoRecentDocumentsPane(QWidget* parent, const QString& header)
        : KoDetailsPane(parent, header)
        , d(new KoRecentDocumentsPanePrivate)
{
    setFocusProxy(m_documentList);
    m_openButton->setText(i18n("Open This Document"));
    m_openButton->setIcon(koIcon("document-open"));

    m_alwaysUseCheckBox->hide();

    model()->setSortRole(0); // Disable sorting

    // load list of recent files from config
    KConfigGroup config(KSharedConfig::openConfig(), "RecentFiles");

    QString fileKey;
    QString fileValue;
    QUrl url;
    QString nameValue;
    KFileItemList fileList;
    QStandardItem* rootItem = model()->invisibleRootItem();

    for (int i = 1; i <= MAX_RECENTFILES_ENTRIES; ++i) {
        fileValue = config.readPathEntry(QString("File%1").arg(i), QString());

        // ignore empty entries
        if (fileValue.isEmpty()) {
            continue;
        }

        url = QUrl::fromUserInput(fileValue);

        // ignore entries for files known to no longer exist
        if (url.isLocalFile() && !QFile::exists(url.toLocalFile())) {
            continue;
        }
        // ignore duplicated entries
        if (!fileList.findByUrl(url).isNull()) {
            continue;
        }

        nameValue = config.readPathEntry(QString("Name%1").arg(i), QString());
        // handle name entries with empty strings
        if (nameValue.isEmpty()) {
            nameValue = url.fileName();
        }

        KFileItem fileItem(url);
        fileList.prepend(fileItem);
        const QIcon icon = QIcon::fromTheme(fileItem.iconName());
        KoFileListItem* item = new KoFileListItem(icon, nameValue, fileItem);
        item->setEditable(false);
        rootItem->insertRow(0, item);
    }


    //Select the first file
    QModelIndex firstIndex = model()->indexFromItem(model()->item(0));
    m_documentList->selectionModel()->select(firstIndex, QItemSelectionModel::Select);
    m_documentList->selectionModel()->setCurrentIndex(firstIndex, QItemSelectionModel::Select);

    QStringList availablePlugins = KIO::PreviewJob::availablePlugins();
    KIO::PreviewJob *previewJob = KIO::filePreview(fileList, QSize(IconExtent, IconExtent), &availablePlugins);

    d->m_previewJobs.append(previewJob);
    connect(previewJob, SIGNAL(result(KJob*)), SLOT(previewResult(KJob*)));
    connect(previewJob, SIGNAL(gotPreview(KFileItem,QPixmap)),
            SLOT(updateIcon(KFileItem,QPixmap)));
}