예제 #1
0
// at first, tries to find the iconname in the cache
// if not available, tries to find the pixmap for the mimetype of url
// if that fails, gets the icon for the protocol
// finally, inserts the url/icon pair into the cache
QString KonqPixmapProvider::iconNameFor( const KUrl& url )
{
    QMap<KUrl,QString>::iterator it = iconMap.find( url );
    QString icon;
    if ( it != iconMap.end() ) {
        icon = it.value();
        if ( !icon.isEmpty() )
            return icon;
    }

    if ( url.url().isEmpty() ) {
        // Use the folder icon for the empty URL
        const KMimeType::Ptr directoryType = KMimeType::mimeType( "inode/directory" );
        if( directoryType.isNull() ) // no mimetypes installed!
            return QString();
        icon = directoryType->iconName();
        Q_ASSERT( !icon.isEmpty() );
    }
    else
    {
        icon = KMimeType::iconNameForUrl( url );
        Q_ASSERT( !icon.isEmpty() );
    }

    // cache the icon found for url
    iconMap.insert( url, icon );

    return icon;
}
예제 #2
0
bool MimeTypeChecker::isWantedCollection( const Collection &collection, const QString &wantedMimeType )
{
  if ( wantedMimeType.isEmpty() || !collection.isValid() )
    return false;

  const QStringList contentMimeTypes = collection.contentMimeTypes();
  if ( contentMimeTypes.isEmpty() )
    return false;

  foreach ( const QString &mimeType, contentMimeTypes ) {
    if ( mimeType.isEmpty() )
      continue;

    if ( mimeType == wantedMimeType )
      return true;

    KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases );
    if ( mimeTypePtr.isNull() )
      continue;

   if ( mimeTypePtr->is( wantedMimeType ) )
     return true;
  }

  return false;
}
예제 #3
0
//===========================================================
//
void ImportWizard::setupIntro()
{
    m_introPage = new QWidget(this);
    Q3VBoxLayout *vbox = new Q3VBoxLayout(m_introPage, KDialog::marginHint());

    QLabel *lblIntro = new QLabel(m_introPage);
    lblIntro->setAlignment(Qt::AlignTop | Qt::AlignLeft);
    lblIntro->setWordWrap(true);
    QString msg;
    if (m_predefinedConnectionData) { //predefined import: server source
        msg = i18n("<qt>Database Importing wizard is about to import \"%1\" database "
                   "<nobr>(connection %2)</nobr> into a Kexi database.</qt>",
                   m_predefinedDatabaseName, m_predefinedConnectionData->serverInfoString());
    } else if (!m_predefinedDatabaseName.isEmpty()) { //predefined import: file source
//! @todo this message is currently ok for files only
        KMimeType::Ptr mimeTypePtr = KMimeType::mimeType(m_predefinedMimeType);
        if (mimeTypePtr.isNull())
            KexiDBWarn << QString("'%1' mimetype not installed!").arg(m_predefinedMimeType);
        msg = i18n(
                  "<qt>Database Importing wizard is about to import <nobr>\"%1\"</nobr> file "
                  "of type \"%2\" into a Kexi database.</qt>",
                  QDir::convertSeparators(m_predefinedDatabaseName), mimeTypePtr ? mimeTypePtr->comment() : "???");
    } else {
        msg = i18n("Database Importing wizard allows you to import an existing database "
                   "into a Kexi database.");
    }
    lblIntro->setText(msg + "\n\n"
                      + i18n("Click \"Next\" button to continue or \"Cancel\" button to exit this wizard."));
    vbox->addWidget(lblIntro);
    addPage(m_introPage, i18n("Welcome to the Database Importing Wizard"));
}
예제 #4
0
 KIcon iconForContent( KMime::Content *content )
 {
   if ( !content->contentType( false ) )
     return KIcon();
   KMimeType::Ptr mimeType = KMimeType::mimeType( QString::fromLatin1( content->contentType()->mimeType() ) );
   if ( mimeType.isNull() || mimeType->iconName().isEmpty() )
     return KIcon();
   return KIcon( mimeType->iconName() );
 }
예제 #5
0
 QString typeForContent( KMime::Content *content )
 {
   if ( !content->contentType( false ) )
     return QString();
   KMimeType::Ptr mimeType = KMimeType::mimeType( QString::fromLatin1( content->contentType()->mimeType() ) );
   if ( mimeType.isNull() )
     return QString::fromLatin1( content->contentType()->mimeType() );
   return mimeType->comment();
 }
예제 #6
0
bool MimeTypeChecker::isWantedItem( const Item &item, const QString &wantedMimeType )
{
  if ( wantedMimeType.isEmpty() || !item.isValid() )
    return false;

  const QString mimeType = item.mimeType();
  if ( mimeType.isEmpty() )
    return false;

  if ( mimeType == wantedMimeType )
    return true;

  KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases );
  if ( mimeTypePtr.isNull() )
    return false;

  return mimeTypePtr->is( wantedMimeType );
}
예제 #7
0
void KMMsgPartDialog::slotMimeTypeChanged( const QString & mimeType ) {
  // message subparts MUST have 7bit or 8bit encoding...
#if 0
  // ...but until KMail can recode 8bit messages on attach, so that
  // they can be signed, we can't enforce this :-(
  if ( mimeType.startsWith("message/") ) {
    setEncoding( SevenBit );
    mEncoding->setEnabled( false );
  } else {
    mEncoding->setEnabled( !mReadOnly );
  }
#endif
  // find a mimetype icon:
  KMimeType::Ptr mt = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases );
  if ( !mt.isNull() )
    mIcon->setPixmap( KIconLoader::global()->loadMimeTypeIcon( mt->iconName(),
                      KIconLoader::Desktop ) );
  else
    mIcon->setPixmap( DesktopIcon("unknown") );
}
예제 #8
0
PropertiesDialog::PropertiesDialog(QWidget *parent, Okular::Document *doc)
    : KPageDialog( parent ), m_document( doc ), m_fontPage( 0 ),
      m_fontModel( 0 ), m_fontInfo( 0 ), m_fontProgressBar( 0 ),
      m_fontScanStarted( false )
{
    setFaceType( Tabbed );
    setCaption( i18n( "Unknown File" ) );
    setButtons( Ok );

    // PROPERTIES
    QFrame *page = new QFrame();
    KPageWidgetItem *item = addPage( page, i18n( "&Properties" ) );
    item->setIcon( KIcon( "document-properties" ) );

    // get document info
    const Okular::DocumentInfo info = doc->documentInfo();
    QFormLayout *layout = new QFormLayout( page );

    // mime name based on mimetype id
    QString mimeName = info.get( Okular::DocumentInfo::MimeType ).section( '/', -1 ).toUpper();
    setCaption( i18n( "%1 Properties", mimeName ) );

    int valMaxWidth = 100;

    /* obtains the properties list, conveniently ordered */
    QStringList orderedProperties;
    orderedProperties << Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::FilePath )
                      << Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::PagesSize )
                      << Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::DocumentSize );
    for (Okular::DocumentInfo::Key ks = Okular::DocumentInfo::Title;
                                   ks <= Okular::DocumentInfo::Keywords;
                                   ks = Okular::DocumentInfo::Key( ks+1 ) )
    {
        orderedProperties << Okular::DocumentInfo::getKeyString( ks );
    }
    foreach( const QString &ks, info.keys()) {
        if ( !orderedProperties.contains( ks ) ) {
            orderedProperties << ks;
        }
    }

    for ( QStringList::Iterator it = orderedProperties.begin();
                                it != orderedProperties.end();
                                ++it )
    {
        const QString key = *it;
        const QString titleString = info.getKeyTitle( key );
        const QString valueString = info.get( key );
        if ( titleString.isNull() || valueString.isNull() )
            continue;

        // create labels and layout them
        QWidget *value = NULL;
        if ( key == Okular::DocumentInfo::getKeyString( Okular::DocumentInfo::MimeType ) ) {
            /// for mime type fields, show icon as well
            value = new QWidget( page );
            /// place icon left of mime type's name
            QHBoxLayout *hboxLayout = new QHBoxLayout( value );
            hboxLayout->setMargin( 0 );
            /// retrieve icon and place it in a QLabel
            KMimeType::Ptr mimeType = KMimeType::mimeType( valueString );
            KSqueezedTextLabel *squeezed;
            if (!mimeType.isNull()) {
                /// retrieve icon and place it in a QLabel
                QLabel *pixmapLabel = new QLabel( value );
                hboxLayout->addWidget( pixmapLabel, 0 );
                pixmapLabel->setPixmap( KIconLoader::global()->loadMimeTypeIcon( mimeType->iconName(), KIconLoader::Small ) );
                /// mime type's name and label
                squeezed = new KSqueezedTextLabel( i18nc( "mimetype information, example: \"PDF Document (application/pdf)\"", "%1 (%2)", mimeType->comment(), valueString ), value );
            } else {
                /// only mime type name
                squeezed = new KSqueezedTextLabel( valueString, value );
            }
            squeezed->setTextInteractionFlags( Qt::TextSelectableByMouse );
            hboxLayout->addWidget( squeezed, 1 );
        } else {
            /// default for any other document information
            KSqueezedTextLabel *label = new KSqueezedTextLabel( valueString, page );
            label->setTextInteractionFlags( Qt::TextSelectableByMouse );
            value = label;
        }
        layout->addRow( new QLabel( i18n( "%1:", titleString ) ), value);

        // refine maximum width of 'value' labels
        valMaxWidth = qMax( valMaxWidth, fontMetrics().width( valueString ) );
    }

    // FONTS
    QVBoxLayout *page2Layout = 0;
    if ( doc->canProvideFontInformation() ) {
        // create fonts tab and layout it
        QFrame *page2 = new QFrame();
        m_fontPage = addPage(page2, i18n("&Fonts"));
        m_fontPage->setIcon( KIcon( "preferences-desktop-font" ) );
        page2Layout = new QVBoxLayout(page2);
        page2Layout->setMargin(marginHint());
        page2Layout->setSpacing(spacingHint());
        // add a tree view
        QTreeView *view = new QTreeView(page2);
        view->setContextMenuPolicy(Qt::CustomContextMenu);
        connect(view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showFontsMenu(QPoint)));
        page2Layout->addWidget(view);
        view->setRootIsDecorated(false);
        view->setAlternatingRowColors(true);
        view->setSortingEnabled( true );
        // creating a proxy model so we can sort the data
        QSortFilterProxyModel *proxymodel = new QSortFilterProxyModel(view);
        proxymodel->setDynamicSortFilter( true );
        proxymodel->setSortCaseSensitivity( Qt::CaseInsensitive );
        m_fontModel = new FontsListModel(view);
        proxymodel->setSourceModel(m_fontModel);
        view->setModel(proxymodel);
        view->sortByColumn( 0, Qt::AscendingOrder );
        m_fontInfo = new QLabel( this );
        page2Layout->addWidget( m_fontInfo );
        m_fontInfo->setText( i18n( "Reading font information..." ) );
        m_fontInfo->hide();
        m_fontProgressBar = new QProgressBar( this );
        page2Layout->addWidget( m_fontProgressBar );
        m_fontProgressBar->setRange( 0, 100 );
        m_fontProgressBar->setValue( 0 );
        m_fontProgressBar->hide();
    }

    // current width: left columnt + right column + dialog borders
    int width = layout->minimumSize().width() + valMaxWidth + 2 * marginHint() + spacingHint() + 30;
    if ( page2Layout )
        width = qMax( width, page2Layout->sizeHint().width() + marginHint() + spacingHint() + 31 );
    // stay inside the 2/3 of the screen width
    QRect screenContainer = KGlobalSettings::desktopGeometry( this );
    width = qMin( width, 2*screenContainer.width()/3 );
    resize(width, 1);

    connect( pageWidget(), SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)),
             this, SLOT(pageChanged(KPageWidgetItem*,KPageWidgetItem*)) );
}