Beispiel #1
0
void KMimeTypeTest::testAllMimeTypes()
{
    const KMimeType::List lst = KMimeType::allMimeTypes(); // does NOT include aliases
    QVERIFY(!lst.isEmpty());

    for (KMimeType::List::ConstIterator it = lst.begin();
            it != lst.end(); ++it) {
        const KMimeType::Ptr mime = (*it);
        const QString name = mime->name();
        //qDebug( "%s", qPrintable( name ) );
        QVERIFY(!name.isEmpty());
        QCOMPARE(name.count('/'), 1);

        const KMimeType::Ptr lookedupMime = KMimeType::mimeType(name);
        QVERIFY(lookedupMime);   // not null
        if (name != "application/vnd.ms-word" && name != "application/x-pkcs7-certificates"
                && name != "application/x-x509-ca-cert"
                && name != "application/x-vnd.kde.kexi" // due to /usr/share/mime/packages/kde.xml from KDE4
                && name != "application/x-kexiproject-sqlite" // due to /usr/share/mime/packages/kde.xml from KDE4
                && name != "application/vnd.sun.xml.base" // libreoffice.xml messing things up yet again
           ) {
            QCOMPARE(lookedupMime->name(), name);
            // if this fails, you have an alias defined as a real mimetype too!
            //
            // Note: this also happens with x-win-lnk when your kde.xml defines it as an alias, while
            // /usr/share/mime/packages/kde.xml defines it as a real mimetype. This is a false positive,
            // remove one of the kde.xml files.
            //
            // It also happens with application/x-pkcs7-certificates due to
            // /usr/share/mime/packages/gcr-crypto-types.xml. Remove that file and run
            // `update-mime-database /usr/share/mime`.
        }
    }
}
Beispiel #2
0
void KfindTabWidget::initMimeTypes()
{
    KMimeType::List sortedList;
    foreach ( const KMimeType::Ptr &type, KMimeType::allMimeTypes() )
    {
      if ( (!type->comment().isEmpty())
           && (!type->name().startsWith( QLatin1String("kdedevice/") ))
           && (!type->name().startsWith( QLatin1String("all/") )) )
        sortedList.append(type);
    }
    qSort( sortedList.begin(), sortedList.end(), LessMimeType_ByComment() );
    m_types += sortedList;
}
Beispiel #3
0
void KfindTabWidget::initSpecialMimeTypes()
{
    KMimeType::List tmp = KMimeType::allMimeTypes();

    for ( KMimeType::List::ConstIterator it = tmp.begin(); it != tmp.end(); ++it )
    {
      KMimeType * type = *it;

      if(!type->comment().isEmpty()) {
        if(type->name().startsWith("image/"))
           m_ImageTypes.append(type->name());
        else if(type->name().startsWith("video/"))
          m_VideoTypes.append(type->name());
        else if(type->name().startsWith("audio/"))
          m_AudioTypes.append(type->name());
      }
    }
}
Beispiel #4
0
void DesktopBehavior::fillMediaListView()
{
    mediaListView->clear();
    mediaListView->setRootIsDecorated(false);
    KMimeType::List mimetypes = KMimeType::allMimeTypes();
    QValueListIterator<KMimeType::Ptr> it2(mimetypes.begin());
    g_pConfig->setGroup( "Media" );
    enableMediaBox->setChecked(g_pConfig->readBoolEntry("enabled",false));
    QString excludedMedia=g_pConfig->readEntry("exclude","media/hdd_mounted,media/hdd_unmounted,media/floppy_unmounted,media/cdrom_unmounted,media/floppy5_unmounted");
    for (; it2 != mimetypes.end(); ++it2) {
       if ( ((*it2)->name().startsWith("media/")) )
	{
    	    bool ok=excludedMedia.contains((*it2)->name())==0;
		new DesktopBehaviorMediaItem (this, mediaListView, (*it2)->comment(), (*it2)->name(),ok);

        }
    }
}
void PreferencesDialog::setExcludedMediumTypes(QStringList excludedTypesList)
{
    mpMediumTypesListView->clear();
    mpMediumTypesListView->setRootIsDecorated(false);
    KMimeType::List mimetypes = KMimeType::allMimeTypes();

    QValueListIterator< KMimeType::Ptr > it(mimetypes.begin());

    for(; it != mimetypes.end(); ++it)
    {
        if((*it)->name().startsWith("media/"))
        {
            bool ok = excludedTypesList.contains((*it)->name()) == 0;
            MediumTypeItem *item = new MediumTypeItem(mpMediumTypesListView, (*it)->comment(), (*it)->name());
            item->setOn(ok);
        }
    }
}
Beispiel #6
0
void KfindTabWidget::initMimeTypes()
{
    KMimeType::List tmp = KMimeType::allMimeTypes();
    KSortedMimeTypeList sortedList;
    for ( KMimeType::List::ConstIterator it = tmp.begin();
          it != tmp.end(); ++it )
    {
      KMimeType * type = *it;
      if ((!type->comment().isEmpty())
         && (!type->name().startsWith("kdedevice/"))
         && (!type->name().startsWith("all/")))
        sortedList.append(type);
    }
    sortedList.sort();
    for ( KMimeType *type = sortedList.first(); type; type = sortedList.next())
    {
       m_types.append(type);
    }
}
Beispiel #7
0
void KMimeTypeTest::testAllMimeTypes()
{
    const KMimeType::List lst = KMimeType::allMimeTypes(); // does NOT include aliases
    QVERIFY( !lst.isEmpty() );

    for ( KMimeType::List::ConstIterator it = lst.begin();
          it != lst.end(); ++it ) {
        const KMimeType::Ptr mime = (*it);
        const QString name = mime->name();
        //qDebug( "%s", qPrintable( name ) );
        QVERIFY( !name.isEmpty() );
        QCOMPARE( name.count( '/' ), 1 );
        QVERIFY( mime->isType( KST_KMimeType ) );

        const KMimeType::Ptr lookedupMime = KMimeType::mimeType( name );
        QVERIFY( lookedupMime ); // not null
        QCOMPARE( lookedupMime->name(), name ); // if this fails, you have an alias defined as a real mimetype too!
    }
}
KURL::List ProjectNewLocal::projectFiles()
{
  KURL::List list;

  if (!QExtFileInfo::exists(baseURL, false, this) ||
      !baseURL.path().endsWith("/")  ||
      !checkInsert->isChecked() ) return list;

  QString fmask = "*";
  if ( checkInsertWeb->isChecked() )
  {
    KMimeType::List list = KMimeType::allMimeTypes();
    KMimeType::List::iterator it;
    QString name;
    fmask = "";
    for ( it = list.begin(); it != list.end(); ++it )
    {
      name = (*it)->name();
      if (qConfig.markupMimeTypes.contains(name) ||
          qConfig.scriptMimeTypes.contains(name) ||
          qConfig.imageMimeTypes.contains(name))
      {
        QStringList patterns = (*it)->patterns();
        for (uint i = 0 ; i < patterns.count(); i++)
        {
          fmask = fmask+patterns[i]+" ";
        }
      }
    }
  } else
  {
    fmask = mask->text();
  }

  list = QExtFileInfo::allFilesRelative(baseURL, fmask, this, false);

  return list;
}
Beispiel #9
0
/** Return true, if the url belong to the mimetype group. */
bool QuantaCommon::checkMimeGroup(const KUrl& url, const QString& group)
{
 bool status = false;
 KMimeType::Ptr mime = KMimeType::findByUrl(url);
 QString mimetype = mime->name();
 mimetype = mimetype.section('/',-1);
#if 0
 // This is really a slow way to lookup one mimetype - why do it this way? (DF)
 const KMimeType::List list = KMimeType::allMimeTypes(); // slow. We need a allMimeTypeNames for this.
 KMimeType::List::const_iterator it;
 for ( it = list.begin(); it != list.end(); ++it )
 {
    // ## why indexOf and not just == ?
    if ( ((*it)->name().startsWith(group)) && ((*it)->name().indexOf(mimetype) != -1)
)    {
      status = true;
      break;
    }
 }
#endif
 status = mime->name().startsWith(group);

 if (!status && group == "text")
 {
   if (url.isLocalFile())
   {
     status = !KMimeType::isBinaryData(url.path());
   } else
   {
     status = mime->is("text/plain");
   }
 }
 if (!status && group == "text" && mimetype == "x-zerosize")
     status = true;

 return status;
}
Beispiel #10
0
KXmlCommandDlg::KXmlCommandDlg(TQWidget *parent, const char *name)
: KDialogBase(parent, name, true, TQString::null, Ok|Cancel|Details, Ok, true)
{
	setButtonText(Details, i18n("&Mime Type Settings"));
	m_cmd = 0;

	TQWidget	*dummy = new TQWidget(this, "TopDetail");
	TQWidget	*topmain = new TQWidget(this, "TopMain");

	TQGroupBox	*m_gb1 = new TQGroupBox(0, Qt::Horizontal, i18n("Supported &Input Formats"), dummy);
	TQGroupBox	*m_gb2 = new TQGroupBox(0, Qt::Horizontal, i18n("Requirements"), topmain);

	m_description = new TQLineEdit(topmain);
	m_idname = new TQLabel(topmain);
	m_requirements = new TDEListView(m_gb2);
	m_requirements->addColumn("");
	m_requirements->header()->hide();
	m_addreq = new TQToolButton(m_gb2);
	m_addreq->setIconSet(SmallIconSet("filenew"));
	m_removereq = new TQToolButton(m_gb2);
	m_removereq->setIconSet(SmallIconSet("editdelete"));
	TQPushButton	*m_edit = new KPushButton(KGuiItem(i18n("&Edit Command..."), "edit"), topmain);
	m_mimetype = new TQComboBox(dummy);
	m_availablemime = new TDEListBox(m_gb1);
	m_selectedmime = new TDEListBox(m_gb1);
	m_addmime = new TQToolButton(m_gb1);
	m_addmime->setIconSet(TQApplication::reverseLayout()? SmallIconSet("forward") : SmallIconSet("back"));
	m_removemime = new TQToolButton(m_gb1);
	m_removemime->setIconSet(TQApplication::reverseLayout()? SmallIconSet("back" ) : SmallIconSet("forward"));
	m_gb2->setMinimumWidth(380);
	m_gb1->setMinimumHeight(180);
	m_requirements->setMaximumHeight(80);
	m_removereq->setEnabled(false);
	m_addmime->setEnabled(false);
	m_removemime->setEnabled(false);

	TQLabel	*m_desclab = new TQLabel(i18n("&Description:"), topmain);
	m_desclab->setBuddy(m_description);
	TQLabel	*m_mimetypelab = new TQLabel(i18n("Output &format:"), dummy);
	m_mimetypelab->setBuddy(m_mimetype);
	TQLabel	*m_idnamelab = new TQLabel(i18n("ID name:"), topmain);

	TQFont	f(m_idname->font());
	f.setBold(true);
	m_idname->setFont(f);

	KSeparator	*sep1 = new KSeparator(TQFrame::HLine, dummy);

	TQVBoxLayout	*l0 = new TQVBoxLayout(topmain, 0, 10);
	TQGridLayout	*l5 = new TQGridLayout(0, 2, 2, 0, 5);
	l0->addLayout(TQT_TQLAYOUT(l5));
	l5->addWidget(m_idnamelab, 0, 0);
	l5->addWidget(m_idname, 0, 1);
	l5->addWidget(m_desclab, 1, 0);
	l5->addWidget(m_description, 1, 1);
	l0->addWidget(m_gb2);
	TQHBoxLayout	*l3 = new TQHBoxLayout(0, 0, 0);
	l0->addLayout(l3);
	l3->addWidget(m_edit);
	l3->addStretch(1);

	TQVBoxLayout	*l7 = new TQVBoxLayout(dummy, 0, 10);
	TQHBoxLayout	*l6 = new TQHBoxLayout(0, 0, 5);
	l7->addWidget(sep1);
	l7->addLayout(l6);
	l6->addWidget(m_mimetypelab, 0);
	l6->addWidget(m_mimetype, 1);
	l7->addWidget(m_gb1);
	TQGridLayout	*l2 = new TQGridLayout(TQT_TQLAYOUT(m_gb1->layout()), 4, 3, 10);
	l2->addMultiCellWidget(m_availablemime, 0, 3, 2, 2);
	l2->addMultiCellWidget(m_selectedmime, 0, 3, 0, 0);
	l2->addWidget(m_addmime, 1, 1);
	l2->addWidget(m_removemime, 2, 1);
	l2->setRowStretch(0, 1);
	l2->setRowStretch(3, 1);
	TQHBoxLayout	*l4 = new TQHBoxLayout(TQT_TQLAYOUT(m_gb2->layout()), 10);
	l4->addWidget(m_requirements);
	TQVBoxLayout	*l8 = new TQVBoxLayout(0, 0, 0);
	l4->addLayout(l8);
	l8->addWidget(m_addreq);
	l8->addWidget(m_removereq);
	l8->addStretch(1);

	connect(m_addmime, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddMime()));
	connect(m_removemime, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveMime()));
	connect(m_edit, TQT_SIGNAL(clicked()), TQT_SLOT(slotEditCommand()));
	connect(m_requirements, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(slotReqSelected(TQListViewItem*)));
	connect(m_availablemime, TQT_SIGNAL(selectionChanged(TQListBoxItem*)), TQT_SLOT(slotAvailableSelected(TQListBoxItem*)));
	connect(m_selectedmime, TQT_SIGNAL(selectionChanged(TQListBoxItem*)), TQT_SLOT(slotSelectedSelected(TQListBoxItem*)));
	connect(m_addreq, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddReq()));
	connect(m_removereq, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveReq()));

	KMimeType::List	list = KMimeType::allMimeTypes();
	for (TQValueList<KMimeType::Ptr>::ConstIterator it=list.begin(); it!=list.end(); ++it)
	{
		TQString	mimetype = (*it)->name();
		m_mimelist << mimetype;
	}

	m_mimelist.sort();
	m_mimetype->insertStringList(m_mimelist);
	m_availablemime->insertStringList(m_mimelist);

	setMainWidget(topmain);
	setDetailsWidget(dummy);
}
Beispiel #11
0
KMSpecialPrinterDlg::KMSpecialPrinterDlg(QWidget *parent, const char *name)
: KDialogBase(parent, name, true, QString::null, Ok|Cancel, Ok)
{
	setCaption(i18n("Add Special Printer"));

	QWidget	*dummy = new QWidget(this);
	setMainWidget(dummy);

	// widget creation
	m_name = new QLineEdit(dummy);
	connect(m_name, SIGNAL(textChanged ( const QString & )),this,SLOT(slotTextChanged(const QString & )));
	m_description = new QLineEdit(dummy);
	m_location = new QLineEdit(dummy);
	QLabel	*m_namelabel = new QLabel(i18n("&Name:"), dummy);
	QLabel	*m_desclabel = new QLabel(i18n("&Description:"), dummy);
	QLabel	*m_loclabel = new QLabel(i18n("&Location:"), dummy);
	m_namelabel->setBuddy(m_name);
	m_desclabel->setBuddy(m_description);
	m_loclabel->setBuddy(m_location);

	KSeparator* sep = new KSeparator( KSeparator::HLine, dummy);

	sep->setFixedHeight(10);
	QGroupBox	*m_gb = new QGroupBox(1, Qt::Horizontal, i18n("Command &Settings"), dummy);
	m_command = new KXmlCommandSelector(true, m_gb, "CommandSelector", this);

	QGroupBox *m_outfile_gb = new QGroupBox( 0, Qt::Horizontal, i18n( "Outp&ut File" ), dummy );

	m_usefile = new QCheckBox( i18n("&Enable output file"), m_outfile_gb);

	m_mimetype = new QComboBox(m_outfile_gb);
	KMimeType::List	list = KMimeType::allMimeTypes();
	for (QValueList<KMimeType::Ptr>::ConstIterator it=list.begin(); it!=list.end(); ++it)
	{
		QString	mimetype = (*it)->name();
		m_mimelist << mimetype;
	}
	m_mimelist.sort();
	m_mimetype->insertStringList(m_mimelist);

	QLabel	*m_mimetypelabel = new QLabel(i18n("&Format:"), m_outfile_gb);
	m_mimetypelabel->setBuddy (m_mimetype);

	m_extension = new QLineEdit(m_outfile_gb);

	QLabel	*m_extensionlabel = new QLabel(i18n("Filename e&xtension:"), m_outfile_gb);
	m_extensionlabel->setBuddy(m_extension);

	m_icon = new KIconButton(dummy);
	m_icon->setIcon("fileprint");
	m_icon->setFixedSize(QSize(48,48));

	connect( m_usefile, SIGNAL( toggled( bool ) ), m_mimetype, SLOT( setEnabled( bool ) ) );
	connect( m_usefile, SIGNAL( toggled( bool ) ), m_extension, SLOT( setEnabled( bool ) ) );
	connect( m_usefile, SIGNAL( toggled( bool ) ), m_mimetypelabel, SLOT( setEnabled( bool ) ) );
	connect( m_usefile, SIGNAL( toggled( bool ) ), m_extensionlabel, SLOT( setEnabled( bool ) ) );
	m_mimetypelabel->setEnabled( false );
	m_mimetype->setEnabled( false );
	m_extensionlabel->setEnabled( false );
	m_extension->setEnabled( false );

	QWhatsThis::add(m_usefile,
		i18n("<p>The command will use an output file. If checked, make sure the "
		     "command contains an output tag.</p>"));
	QWhatsThis::add(m_command,
		i18n("<p>The command to execute when printing on this special printer. Either enter "
			 "the command to execute directly, or associate/create a command object with/for "
			 "this special printer. The command object is the preferred method as it provides "
			 "support for advanced settings like mime type checking, configurable options and "
			 "requirement list (the plain command is only provided for backward compatibility). "
			 "When using a plain command, the following tags are recognized:</p>"
			 "<ul><li><b>%in</b>: the input file (required).</li>"
			 "<li><b>%out</b>: the output file (required if using an output file).</li>"
			 "<li><b>%psl</b>: the paper size in lower case.</li>"
			 "<li><b>%psu</b>: the paper size with the first letter in upper case.</li></ul>"));
	QString mimetypeWhatsThis = i18n("<p>The default mimetype for the output file (e.g. application/postscript).</p>");
	QWhatsThis::add(m_mimetypelabel, mimetypeWhatsThis);
	QWhatsThis::add(m_mimetype, mimetypeWhatsThis);
	QString extensionWhatsThis = i18n("<p>The default extension for the output file (e.g. ps, pdf, ps.gz).</p>");
	QWhatsThis::add(m_extensionlabel, extensionWhatsThis);
	QWhatsThis::add(m_extension, extensionWhatsThis);

	// layout creation
	QVBoxLayout	*l0 = new QVBoxLayout(dummy, 0, 10);
	QGridLayout	*l1 = new QGridLayout(0, 3, 3, 0, 5);
	l0->addLayout(l1);
	l1->setColStretch(2,1);
	l1->addColSpacing(0,60);
	l1->addMultiCellWidget(m_icon, 0, 2, 0, 0, Qt::AlignCenter);
	l1->addWidget(m_namelabel, 0, 1);
	l1->addWidget(m_desclabel, 1, 1);
	l1->addWidget(m_loclabel, 2, 1);
	l1->addWidget(m_name, 0, 2);
	l1->addWidget(m_description, 1, 2);
	l1->addWidget(m_location, 2, 2);
	l0->addWidget(sep);
	l0->addWidget(m_gb);
	l0->addWidget(m_outfile_gb);
	QGridLayout	*l6 = new QGridLayout(m_outfile_gb->layout(), 3, 2, 10);
	l6->addMultiCellWidget( m_usefile, 0, 0, 0, 1 );
	l6->addWidget(m_mimetypelabel, 1, 0);
	l6->addWidget(m_mimetype, 1, 1);
	l6->addWidget(m_extensionlabel, 2, 0);
	l6->addWidget(m_extension, 2, 1);

	enableButton(Ok, !m_name->text().isEmpty());

	// resize dialog
	resize(400,100);
}