KoDocumentInfoDlg::KoDocumentInfoDlg(QWidget* parent, KoDocumentInfo* docInfo, KoDocumentRdf* docRdf)
        : KPageDialog(parent)
        , d(new KoDocumentInfoDlgPrivate)
{
    d->m_info = docInfo;
    d->m_rdf = docRdf;

    setCaption(i18n("Document Information"));
    setInitialSize(QSize(500, 500));
    setFaceType(KPageDialog::List);
    setButtons(KDialog::Ok | KDialog::Cancel);
    setDefaultButton(KDialog::Ok);

    d->m_aboutUi = new Ui::KoDocumentInfoAboutWidget();
    QWidget *infodlg = new QWidget();
    d->m_aboutUi->setupUi(infodlg);
    if (!KoEncryptionChecker::isEncryptionSupported()) {
        d->m_aboutUi->lblEncryptedDesc->setVisible(false);
        d->m_aboutUi->lblEncrypted->setVisible(false);
        d->m_aboutUi->pbEncrypt->setVisible(false);
        d->m_aboutUi->lblEncryptedPic->setVisible(false);
    }
    KPageWidgetItem *page = new KPageWidgetItem(infodlg, i18n("General"));
    page->setHeader(i18n("General"));

    // Ugly hack, the mimetype should be a parameter, instead
    KoDocument* doc = dynamic_cast< KoDocument* >(d->m_info->parent());
    if (doc) {
        KMimeType::Ptr mime = KMimeType::mimeType(doc->mimeType());
        if (! mime)
            mime = KMimeType::defaultMimeTypePtr();
        page->setIcon(KIcon(KIconLoader::global()->loadMimeTypeIcon(mime->iconName(), KIconLoader::Desktop, 48)));
    }
    addPage(page);
    d->m_pages.append(page);

    initAboutTab();

    d->m_authorUi = new Ui::KoDocumentInfoAuthorWidget();
    QWidget *authordlg = new QWidget();
    d->m_authorUi->setupUi(authordlg);
    page = new KPageWidgetItem(authordlg, i18n("Author"));
    page->setHeader(i18n("Author"));
    page->setIcon(KIcon("user-identity"));
    addPage(page);
    d->m_pages.append(page);

    initAuthorTab();

    // Saving encryption implies saving the document, this is done after closing the dialog
    connect(this, SIGNAL(hidden()), this, SLOT(slotSaveEncryption()));

    if (d->m_rdf) {
        d->m_rdfEditWidget = 0;

#ifdef SHOULD_BUILD_RDF
        d->m_rdfEditWidget = new KoDocumentRdfEditWidget(this, d->m_rdf);
        page = new KPageWidgetItem(d->m_rdfEditWidget->widget(), i18n("Rdf"));
        page->setHeader(i18n("Rdf"));
        page->setIcon(KIcon("text-rdf"));
        addPage(page);
        d->m_pages.append(page);
#endif
    }
}
void KoDocumentInfoDlg::initAboutTab()
{
    KoDocument* doc = dynamic_cast< KoDocument* >(d->m_info->parent());
    if (!doc)
        return;

    d->m_aboutUi->filePathLabel->setText(doc->localFilePath());

    d->m_aboutUi->leTitle->setText(d->m_info->aboutInfo("title"));
    d->m_aboutUi->leSubject->setText(d->m_info->aboutInfo("subject"));

    d->m_aboutUi->leKeywords->setToolTip(i18n("Use ';' (Example: Office;KDE;KOffice)"));
    if (!d->m_info->aboutInfo("keyword").isEmpty())
        d->m_aboutUi->leKeywords->setText(d->m_info->aboutInfo("keyword"));

    d->m_aboutUi->meComments->setPlainText(d->m_info->aboutInfo("comments"));
    if (!doc->mimeType().isEmpty()) {
        KMimeType::Ptr docmime = KMimeType::mimeType(doc->mimeType());
        if (docmime)
            d->m_aboutUi->lblType->setText(docmime->comment());
    }
    if (!d->m_info->aboutInfo("creation-date").isEmpty()) {
        QDateTime t = QDateTime::fromString(d->m_info->aboutInfo("creation-date"),
                                            Qt::ISODate);
        QString s = KGlobal::locale()->formatDateTime(t);
        d->m_aboutUi->lblCreated->setText(s + ", " +
                                          d->m_info->aboutInfo("initial-creator"));
    }

    if (!d->m_info->aboutInfo("date").isEmpty()) {
        QDateTime t = QDateTime::fromString(d->m_info->aboutInfo("date"), Qt::ISODate);
        QString s = KGlobal::locale()->formatDateTime(t);
        d->m_aboutUi->lblModified->setText(s + ", " + d->m_info->authorInfo("creator"));
    }

    d->m_aboutUi->lblRevision->setText(d->m_info->aboutInfo("editing-cycles"));

    if ( doc->supportedSpecialFormats() & KoDocument::SaveEncrypted ) {
        if (doc->specialOutputFlag() == KoDocument::SaveEncrypted) {
            if (d->m_toggleEncryption) {
                QPixmap p = KIconLoader::global()->loadIcon("object-unlocked", KIconLoader::Small);
                d->m_aboutUi->lblEncrypted->setText(i18n("This document will be decrypted"));
                d->m_aboutUi->lblEncryptedPic->setPixmap(p);
                d->m_aboutUi->pbEncrypt->setText(i18n("Do not decrypt"));
            } else {
                QPixmap p = KIconLoader::global()->loadIcon("object-locked", KIconLoader::Small);
                d->m_aboutUi->lblEncrypted->setText(i18n("This document is encrypted"));
                d->m_aboutUi->lblEncryptedPic->setPixmap(p);
                d->m_aboutUi->pbEncrypt->setText(i18n("D&ecrypt"));
            }
        } else {
            if (d->m_toggleEncryption) {
                QPixmap p = KIconLoader::global()->loadIcon("object-locked", KIconLoader::Small);
                d->m_aboutUi->lblEncrypted->setText(i18n("This document will be encrypted."));
                d->m_aboutUi->lblEncryptedPic->setPixmap(p);
                d->m_aboutUi->pbEncrypt->setText(i18n("Do not encrypt"));
            } else {
                QPixmap p = KIconLoader::global()->loadIcon("object-unlocked", KIconLoader::Small);
                d->m_aboutUi->lblEncrypted->setText(i18n("This document is not encrypted"));
                d->m_aboutUi->lblEncryptedPic->setPixmap(p);
                d->m_aboutUi->pbEncrypt->setText(i18n("&Encrypt"));
            }
        }
    } else {
        d->m_aboutUi->lblEncrypted->setText(i18n("This document does not support encryption"));
        d->m_aboutUi->pbEncrypt->setEnabled( false );
    }
    connect(d->m_aboutUi->pbReset, SIGNAL(clicked()),
            this, SLOT(slotResetMetaData()));
    connect(d->m_aboutUi->pbEncrypt, SIGNAL(clicked()),
            this, SLOT(slotToggleEncryption()));
}