diff --git a/keditfiletype/CMakeLists.txt b/keditfiletype/CMakeLists.txt index 162c3b7..cd6559e 100644 --- a/keditfiletype/CMakeLists.txt +++ b/keditfiletype/CMakeLists.txt @@ -1,74 +1,74 @@ ########### next target ############### set(libfiletypes_SRCS filetypesview.cpp filetypedetails.cpp filegroupdetails.cpp kservicelistwidget.cpp typeslistitem.cpp newtypedlg.cpp kserviceselectdlg.cpp ) set(kcm_filetypes_PART_SRCS control.cpp ${libfiletypes_SRCS}) kde4_automoc(${kcm_filetypes_PART_SRCS}) kde4_add_plugin(kcm_filetypes ${kcm_filetypes_PART_SRCS}) kde4_install_libtool_file( ${PLUGIN_INSTALL_DIR} kcm_filetypes ) target_link_libraries(kcm_filetypes ${KDE4_KDE3SUPPORT_LIBS} ) -install_targets(${PLUGIN_INSTALL_DIR} kcm_filetypes ) +install(TARGETS kcm_filetypes DESTINATION ${PLUGIN_INSTALL_DIR} ) ########### next target ############### set(keditfiletype_SRCS keditfiletype.cpp ${libfiletypes_SRCS}) kde4_automoc(${keditfiletype_SRCS}) kde4_add_executable(keditfiletype ${keditfiletype_SRCS}) target_link_libraries(keditfiletype ${KDE4_KIO_LIBS} ) install(TARGETS keditfiletype DESTINATION bin) ########### next target ############### ########### install files ############### -install_files( ${XDG_APPS_DIR} FILES filetypes.desktop ) +install( FILES filetypes.desktop DESTINATION ${XDG_APPS_DIR} ) #original Makefile.am contents follow: #AM_CPPFLAGS = $(all_includes) # #kcm_filetypes_la_LIBADD = libfiletypes.la $(LIB_KIO) #kcm_filetypes_la_LDFLAGS = -module -avoid-version -no-undefined $(all_libraries) #METASOURCES = AUTO # #kde_module_LTLIBRARIES = kcm_filetypes.la # #kcm_filetypes_la_SOURCES = control.cpp # #noinst_HEADERS = filetypesview.h filetypedetails.h filegroupdetails.h \ # kservicelistwidget.h typeslistitem.h newtypedlg.h \ # kserviceselectdlg.h # #bin_PROGRAMS = keditfiletype # #noinst_LTLIBRARIES = libfiletypes.la #libfiletypes_la_SOURCES = filetypesview.cpp filetypedetails.cpp filegroupdetails.cpp \ # kservicelistwidget.cpp typeslistitem.cpp newtypedlg.cpp \ # kserviceselectdlg.cpp # #keditfiletype_SOURCES = keditfiletype.cpp #keditfiletype_LDADD = libfiletypes.la $(LIB_KIO) #keditfiletype_LDFLAGS = $(KDE_RPATH) $(all_libraries) # #messages: # $(XGETTEXT) *.cpp -o $(podir)/filetypes.pot # #xdg_apps_DATA = filetypes.desktop diff --git a/keditfiletype/filetypesview.cpp b/keditfiletype/filetypesview.cpp index 7efad4c..c0521c7 100644 --- a/keditfiletype/filetypesview.cpp +++ b/keditfiletype/filetypesview.cpp @@ -1,445 +1,445 @@ /* Missing license header */ #include #include #include #include //Added by qt3to4: #include #include #include #include #include #include #include #include #include #include #include #include #include #include "newtypedlg.h" #include "filetypedetails.h" #include "filegroupdetails.h" #include "filetypesview.h" #include FileTypesView::FileTypesView(KInstance *inst, QWidget *parent) : KCModule(inst, parent) { m_konqConfig = KSharedConfig::openConfig("konquerorrc", false, false); setQuickHelp( i18n("

File Associations

" " This module allows you to choose which applications are associated" " with a given type of file. File types are also referred to MIME types" " (MIME is an acronym which stands for \"Multipurpose Internet Mail" " Extensions\".)

A file association consists of the following:" "

  • Rules for determining the MIME-type of a file, for example" " the filename pattern *.kwd, which means 'all files with names that end" " in .kwd', is associated with the MIME type \"x-kword\";
  • " "
  • A short description of the MIME-type, for example the description" " of the MIME type \"x-kword\" is simply 'KWord document';
  • " "
  • An icon to be used for displaying files of the given MIME-type," " so that you can easily identify the type of file in, say, a Konqueror" " view (at least for the types you use often);
  • " "
  • A list of the applications which can be used to open files of the" " given MIME-type -- if more than one application can be used then the" " list is ordered by priority.
" " You may be surprised to find that some MIME types have no associated" " filename patterns; in these cases, Konqueror is able to determine the" " MIME-type by directly examining the contents of the file.")); KServiceTypeProfile::setConfigurationMode(); setButtons(Help | Apply | Cancel | Ok); QString wtstr; QHBoxLayout *l = new QHBoxLayout(this); l->setMargin(KDialog::marginHint()); QGridLayout *leftLayout = new QGridLayout((QWidget*)0L); leftLayout->setSpacing(KDialog::spacingHint()); leftLayout->setColumnStretch(1, 1); l->addLayout( leftLayout ); QLabel *patternFilterLBL = new QLabel(i18n("F&ind filename pattern:"), this); leftLayout->addWidget(patternFilterLBL, 0, 0, 1, 3); patternFilterLE = new KLineEdit(this); patternFilterLBL->setBuddy( patternFilterLE ); leftLayout->addWidget(patternFilterLE, 1, 0, 1, 3); connect(patternFilterLE, SIGNAL(textChanged(const QString &)), this, SLOT(slotFilter(const QString &))); wtstr = i18n("Enter a part of a filename pattern. Only file types with a " "matching file pattern will appear in the list."); patternFilterLE->setWhatsThis( wtstr ); patternFilterLBL->setWhatsThis( wtstr ); typesLV = new K3ListView(this); typesLV->setRootIsDecorated(true); typesLV->setFullWidth(true); typesLV->addColumn(i18n("Known Types")); leftLayout->addWidget(typesLV, 2, 0, 1, 3); connect(typesLV, SIGNAL(selectionChanged(Q3ListViewItem *)), this, SLOT(updateDisplay(Q3ListViewItem *))); connect(typesLV, SIGNAL(doubleClicked(Q3ListViewItem *)), this, SLOT(slotDoubleClicked(Q3ListViewItem *))); typesLV->setWhatsThis( i18n("Here you can see a hierarchical list of" " the file types which are known on your system. Click on the '+' sign" " to expand a category, or the '-' sign to collapse it. Select a file type" " (e.g. text/html for HTML files) to view/edit the information for that" " file type using the controls on the right.") ); QPushButton *addTypeB = new QPushButton(i18n("Add..."), this); connect(addTypeB, SIGNAL(clicked()), SLOT(addType())); leftLayout->addWidget(addTypeB, 3, 0); addTypeB->setWhatsThis( i18n("Click here to add a new file type.") ); m_removeTypeB = new QPushButton(i18n("&Remove"), this); connect(m_removeTypeB, SIGNAL(clicked()), SLOT(removeType())); leftLayout->addWidget(m_removeTypeB, 3, 2); m_removeTypeB->setEnabled(false); m_removeTypeB->setWhatsThis( i18n("Click here to remove the selected file type.") ); // For the right panel, prepare a widget stack m_widgetStack = new QStackedWidget(this); l->addWidget( m_widgetStack ); // File Type Details m_details = new FileTypeDetails( m_widgetStack ); connect( m_details, SIGNAL( changed(bool) ), this, SLOT( setDirty(bool) ) ); connect( m_details, SIGNAL( embedMajor(const QString &, bool &) ), this, SLOT( slotEmbedMajor(const QString &, bool &))); m_widgetStack->insertWidget( 1, m_details /*id*/ ); // File Group Details m_groupDetails = new FileGroupDetails( m_widgetStack ); connect( m_groupDetails, SIGNAL( changed(bool) ), this, SLOT( setDirty(bool) ) ); m_widgetStack->insertWidget( 2,m_groupDetails /*id*/ ); // Widget shown on startup m_emptyWidget = new QLabel( i18n("Select a file type by name or by extension"), m_widgetStack); m_emptyWidget->setAlignment( Qt::AlignCenter ); m_widgetStack->insertWidget( 3,m_emptyWidget ); m_widgetStack->setCurrentWidget( m_emptyWidget ); QTimer::singleShot( 0, this, SLOT( init() ) ); // this takes some time connect( KSycoca::self(), SIGNAL( databaseChanged() ), SLOT( slotDatabaseChanged() ) ); } FileTypesView::~FileTypesView() { } void FileTypesView::setDirty(bool state) { emit changed(state); m_dirty = state; } void FileTypesView::init() { show(); setEnabled( false ); setCursor( KCursor::waitCursor() ); readFileTypes(); unsetCursor(); setDirty(false); setEnabled( true ); } // only call this method once on startup, then never again! Otherwise, newly // added Filetypes will be lost. void FileTypesView::readFileTypes() { typesLV->clear(); m_majorMap.clear(); m_itemList.clear(); TypesListItem::reset(); TypesListItem *groupItem; KMimeType::List mimetypes = KMimeType::allMimeTypes(); KMimeType::List::const_iterator it2(mimetypes.begin()); for (; it2 != mimetypes.end(); ++it2) { QString mimetype = (*it2)->name(); int index = mimetype.indexOf("/"); QString maj = mimetype.left(index); QString min = mimetype.right(mimetype.length() - index+1); QMap::const_iterator mit = m_majorMap.find( maj ); if ( mit == m_majorMap.end() ) { groupItem = new TypesListItem( typesLV, maj ); m_majorMap.insert( maj, groupItem ); } else groupItem = mit.value(); TypesListItem *item = new TypesListItem(groupItem, (*it2)); m_itemList.append( item ); } updateDisplay(0L); } void FileTypesView::slotEmbedMajor(const QString &major, bool &embed) { TypesListItem *groupItem; QMap::const_iterator mit = m_majorMap.find( major ); if ( mit == m_majorMap.end() ) return; groupItem = mit.value(); embed = (groupItem->autoEmbed() == 0); } void FileTypesView::slotFilter(const QString & patternFilter) { // one of the few ways to clear a listview without destroying the // listviewitems and without making QListView crash. Q3ListViewItem *item; while ( (item = typesLV->firstChild()) ) { while ( item->firstChild() ) item->takeItem( item->firstChild() ); typesLV->takeItem( item ); } // insert all items and their group that match the filter Q3PtrListIterator it( m_itemList ); while ( it.current() ) { if ( patternFilter.isEmpty() || !((*it)->patterns().filter( patternFilter, Qt::CaseInsensitive )).isEmpty() ) { TypesListItem *group = m_majorMap[ (*it)->majorType() ]; // QListView makes sure we don't insert a group-item more than once typesLV->insertItem( group ); group->insertItem( *it ); } ++it; } } void FileTypesView::addType() { QStringList allGroups; QMap::iterator it = m_majorMap.begin(); while ( it != m_majorMap.end() ) { allGroups.append( it.key() ); ++it; } NewTypeDialog m(allGroups, this); if (m.exec()) { Q3ListViewItemIterator it(typesLV); QString loc = m.group() + "/" + m.text() + ".desktop"; - loc = locateLocal("mime", loc); + loc = KStandardDirs::locate("mime", loc); KMimeType::Ptr mimetype(new KMimeType(loc, m.group() + "/" + m.text(), QString(), QString(), QStringList())); TypesListItem *group = m_majorMap[ m.group() ]; if ( !group ) { //group = new TypesListItem( //TODO ! (The combo in NewTypeDialog must be made editable again when that happens) Q_ASSERT(group); } // find out if our group has been filtered out -> insert if necessary Q3ListViewItem *item = typesLV->firstChild(); bool insert = true; while ( item ) { if ( item == group ) { insert = false; break; } item = item->nextSibling(); } if ( insert ) typesLV->insertItem( group ); TypesListItem *tli = new TypesListItem(group, mimetype, true); m_itemList.append( tli ); group->setOpen(true); typesLV->setSelected(tli, true); setDirty(true); } } void FileTypesView::removeType() { TypesListItem *current = (TypesListItem *) typesLV->currentItem(); if ( !current ) return; // Can't delete groups if ( current->isMeta() ) return; // nor essential mimetypes if ( current->isEssential() ) return; Q3ListViewItem *li = current->itemAbove(); if (!li) li = current->itemBelow(); if (!li) li = current->parent(); removedList.append(current->name()); current->parent()->takeItem(current); m_itemList.removeRef( current ); setDirty(true); if ( li ) typesLV->setSelected(li, true); } void FileTypesView::slotDoubleClicked(Q3ListViewItem *item) { if ( !item ) return; item->setOpen( !item->isOpen() ); } void FileTypesView::updateDisplay(Q3ListViewItem *item) { if (!item) { m_widgetStack->setCurrentWidget( m_emptyWidget ); m_removeTypeB->setEnabled(false); return; } bool wasDirty = m_dirty; TypesListItem *tlitem = (TypesListItem *) item; if (tlitem->isMeta()) // is a group { m_widgetStack->setCurrentWidget( m_groupDetails ); m_groupDetails->setTypeItem( tlitem ); m_removeTypeB->setEnabled(false); } else { m_widgetStack->setCurrentWidget( m_details ); m_details->setTypeItem( tlitem ); m_removeTypeB->setEnabled( !tlitem->isEssential() ); } // Updating the display indirectly called change(true) if ( !wasDirty ) setDirty(false); } bool FileTypesView::sync( QList& itemsModified ) { bool didIt = false; // first, remove those items which we are asked to remove. QStringList::Iterator it(removedList.begin()); QString loc; for (; it != removedList.end(); ++it) { didIt = true; KMimeType::Ptr m_ptr = KMimeType::mimeType(*it); loc = m_ptr->desktopEntryPath(); - loc = locateLocal("mime", loc); + loc = KStandardDirs::locate("mime", loc); KDesktopFile config(loc, false, "mime"); config.writeEntry("Type", "MimeType"); config.writeEntry("MimeType", m_ptr->name()); config.writeEntry("Hidden", true); } // now go through all entries and sync those which are dirty. // don't use typesLV, it may be filtered QMap::iterator it1 = m_majorMap.begin(); while ( it1 != m_majorMap.end() ) { TypesListItem *tli = *it1; if (tli->isDirty()) { kDebug() << "Entry " << tli->name() << " is dirty. Saving." << endl; tli->sync(); itemsModified.append( tli ); didIt = true; } ++it1; } Q3PtrListIterator it2( m_itemList ); while ( it2.current() ) { TypesListItem *tli = *it2; if (tli->isDirty()) { kDebug() << "Entry " << tli->name() << " is dirty. Saving." << endl; tli->sync(); itemsModified.append( tli ); didIt = true; } ++it2; } m_konqConfig->sync(); setDirty(false); return didIt; } void FileTypesView::load() { readFileTypes(); } void FileTypesView::save() { m_itemsModified.clear(); if (sync(m_itemsModified)) { // only rebuild if sync() was necessary KBuildSycocaProgressDialog::rebuildKSycoca(this); KIPC::sendMessageAll(KIPC::SettingsChanged); } } void FileTypesView::slotDatabaseChanged() { if ( KSycoca::self()->isChanged( "mime" ) ) { // ksycoca has new KMimeTypes objects for us, make sure to update // our 'copies' to be in sync with it. Not important for OK, but // important for Apply (how to differentiate those 2?). // See BR 35071. QList::Iterator it = m_itemsModified.begin(); for( ; it != m_itemsModified.end(); ++it ) { QString name = (*it)->name(); if ( removedList.indexOf( name ) == -1 ) // if not deleted meanwhile (*it)->refresh(); } m_itemsModified.clear(); } } void FileTypesView::defaults() { } #include "filetypesview.moc" diff --git a/keditfiletype/keditfiletype.cpp b/keditfiletype/keditfiletype.cpp index 92298fa..fede4f4 100644 --- a/keditfiletype/keditfiletype.cpp +++ b/keditfiletype/keditfiletype.cpp @@ -1,192 +1,192 @@ /* This file is part of the KDE project Copyright (C) 2000 David Faure This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "filetypedetails.h" #include "typeslistitem.h" #include "keditfiletype.h" #include #include #include #include #include #include #include #include #include #include #ifdef Q_WS_X11 #include #include #include #endif FileTypeDialog::FileTypeDialog( KMimeType::Ptr mime ) : KDialog( 0 ) { setButtons( Cancel | Apply | Ok ); showButtonSeparator( false ); init( mime, false ); } FileTypeDialog::FileTypeDialog( KMimeType::Ptr mime, bool newItem ) : KDialog( 0 ) { setButtons( Cancel | Apply | Ok ); showButtonSeparator( false ); init( mime, newItem ); } void FileTypeDialog::init( KMimeType::Ptr mime, bool newItem ) { m_details = new FileTypeDetails( this ); Q3ListView * dummyListView = new Q3ListView( m_details ); dummyListView->hide(); m_item = new TypesListItem( dummyListView, mime, newItem ); m_details->setTypeItem( m_item ); // This code is very similar to kcdialog.cpp setMainWidget( m_details ); connect(m_details, SIGNAL(changed(bool)), this, SLOT(clientChanged(bool))); // TODO setHelp() enableButton(Apply, false); connect( KSycoca::self(), SIGNAL( databaseChanged() ), SLOT( slotDatabaseChanged() ) ); connect( this, SIGNAL( okClicked() ), SLOT( slotOk() ) ); connect( this, SIGNAL( applyClicked() ), SLOT( slotApply() ) ); } void FileTypeDialog::save() { if (m_item->isDirty()) { m_item->sync(); KBuildSycocaProgressDialog::rebuildKSycoca(this); } } void FileTypeDialog::slotOk() { save(); accept(); } void FileTypeDialog::slotApply() { save(); } void FileTypeDialog::clientChanged(bool state) { // enable/disable buttons enableButton(User1, state); enableButton(Apply, state); } void FileTypeDialog::slotDatabaseChanged() { if ( KSycoca::self()->isChanged( "mime" ) ) { m_item->refresh(); } } #include "keditfiletype.moc" static KCmdLineOptions options[] = { { "parent ", I18N_NOOP("Makes the dialog transient for the window specified by winid"), 0 }, { "+mimetype", I18N_NOOP("File type to edit (e.g. text/html)"), 0 }, KCmdLineLastOption }; int main(int argc, char ** argv) { KServiceTypeProfile::setConfigurationMode(); KLocale::setMainCatalog("filetypes"); KAboutData aboutData( "keditfiletype", I18N_NOOP("KEditFileType"), "1.0", I18N_NOOP("KDE file type editor - simplified version for editing a single file type"), KAboutData::License_GPL, I18N_NOOP("(c) 2000, KDE developers") ); aboutData.addAuthor("Preston Brown",0, "pbrown@kde.org"); aboutData.addAuthor("David Faure",0, "faure@kde.org"); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->count() == 0) KCmdLineArgs::usage(); QString arg = args->arg(0); bool createType = arg.startsWith( "*" ); KMimeType::Ptr mime; if ( createType ) { QString mimeString = "application/x-kdeuser%1"; QString loc; int inc = 0; do { ++inc; - loc = locateLocal( "mime", mimeString.arg( inc ) + ".desktop" ); + loc = KStandardDirs::locate( "mime", mimeString.arg( inc ) + ".desktop" ); } while ( QFile::exists( loc ) ); QStringList patterns; if ( arg.length() > 2 ) patterns << arg.toLower() << arg.toUpper(); QString comment; if ( arg.startsWith( "*." ) && arg.length() >= 3 ) { QString type = arg.mid( 3 ).prepend( arg[2].toUpper() ); comment = i18n( "%1 File", type ); } mime = new KMimeType( loc, mimeString.arg( inc ), QString(), comment, patterns ); } else { mime = KMimeType::mimeType( arg ); if (!mime) kFatal() << "Mimetype " << arg << " not found" << endl; } FileTypeDialog dlg( mime, createType ); #if defined Q_WS_X11 if( args->isSet( "parent" )) { bool ok; long id = QString(args->getOption("parent")).toLong(&ok); if (ok) XSetTransientForHint( QX11Info::display(), dlg.winId(), id ); } #endif args->clear(); if ( !createType ) dlg.setCaption( i18n("Edit File Type %1", mime->name()) ); else { dlg.setCaption( i18n("Create New File Type %1", mime->name()) ); dlg.enableButton( KDialog::Apply, true ); } dlg.show(); // non-modal return app.exec(); } diff --git a/keditfiletype/kservicelistwidget.cpp b/keditfiletype/kservicelistwidget.cpp index 856a052..0e6c95e 100644 --- a/keditfiletype/kservicelistwidget.cpp +++ b/keditfiletype/kservicelistwidget.cpp @@ -1,445 +1,445 @@ /* This file is part of the KDE project Copyright (C) 2003 Waldo Bastian Copyright (C) 2003 David Faure Copyright (C) 2002 Daniel Molkentin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include //Added by qt3to4: #include #include #include #include #include #include #include #include "kservicelistwidget.h" #include "kserviceselectdlg.h" #include "typeslistitem.h" #include #include KServiceListItem::KServiceListItem( KService::Ptr pService, int kind ) : Q3ListBoxText(), desktopPath(pService->desktopEntryPath()) { if ( kind == KServiceListWidget::SERVICELIST_APPLICATIONS ) setText( pService->name() ); else setText( i18n( "%1 (%2)", pService->name(), pService->desktopEntryName() ) ); bool isApplication = pService->type() == "Application"; if (!isApplication) - localPath = locateLocal("services", desktopPath); + localPath = KStandardDirs::locateLocal("services", desktopPath); else localPath = pService->locateLocal(); } bool KServiceListItem::isImmutable() { - return !checkAccess(localPath, W_OK); + return !KStandardDirs::checkAccess(localPath, W_OK); } KServiceListWidget::KServiceListWidget(int kind, QWidget *parent, const char *name) : Q3GroupBox( kind == SERVICELIST_APPLICATIONS ? i18n("Application Preference Order") : i18n("Services Preference Order"), parent, name ), m_kind( kind ), m_item( 0L ) { QWidget * gb = this; QGridLayout * grid = new QGridLayout(gb); grid->setMargin(KDialog::marginHint()); grid->setSpacing(KDialog::spacingHint()); grid->addItem(new QSpacerItem(0,fontMetrics().lineSpacing()), 0, 0); grid->setRowStretch(1, 1); grid->setRowStretch(2, 1); grid->setRowStretch(3, 1); grid->setRowStretch(4, 1); grid->setRowStretch(5, 1); grid->setRowStretch(6, 1); servicesLB = new Q3ListBox(gb); connect(servicesLB, SIGNAL(highlighted(int)), SLOT(enableMoveButtons(int))); grid->addWidget(servicesLB, 1, 0, 6, 1); connect( servicesLB, SIGNAL( doubleClicked ( Q3ListBoxItem * )), this, SLOT( editService())); QString wtstr = (kind == SERVICELIST_APPLICATIONS ? i18n("This is a list of applications associated with files of the selected" " file type. This list is shown in Konqueror's context menus when you select" " \"Open With...\". If more than one application is associated with this file type," " then the list is ordered by priority with the uppermost item taking precedence" " over the others.") : i18n("This is a list of services associated with files of the selected" " file type. This list is shown in Konqueror's context menus when you select" " a \"Preview with...\" option. If more than one application is associated with this file type," " then the list is ordered by priority with the uppermost item taking precedence" " over the others.")); gb->setWhatsThis( wtstr ); servicesLB->setWhatsThis( wtstr ); servUpButton = new QPushButton(i18n("Move &Up"), gb); servUpButton->setEnabled(false); connect(servUpButton, SIGNAL(clicked()), SLOT(promoteService())); grid->addWidget(servUpButton, 2, 1); servUpButton->setWhatsThis( kind == SERVICELIST_APPLICATIONS ? i18n("Assigns a higher priority to the selected\n" "application, moving it up in the list. Note: This\n" "only affects the selected application if the file type is\n" "associated with more than one application.") : i18n("Assigns a higher priority to the selected\n" "service, moving it up in the list.")); servDownButton = new QPushButton(i18n("Move &Down"), gb); servDownButton->setEnabled(false); connect(servDownButton, SIGNAL(clicked()), SLOT(demoteService())); grid->addWidget(servDownButton, 3, 1); servDownButton->setWhatsThis( kind == SERVICELIST_APPLICATIONS ? i18n("Assigns a lower priority to the selected\n" "application, moving it down in the list. Note: This \n" "only affects the selected application if the file type is\n" "associated with more than one application."): i18n("Assigns a lower priority to the selected\n" "service, moving it down in the list.")); servNewButton = new QPushButton(i18n("Add..."), gb); servNewButton->setEnabled(false); connect(servNewButton, SIGNAL(clicked()), SLOT(addService())); grid->addWidget(servNewButton, 1, 1); servNewButton->setWhatsThis( i18n( "Add a new application for this file type." ) ); servEditButton = new QPushButton(i18n("Edit..."), gb); servEditButton->setEnabled(false); connect(servEditButton, SIGNAL(clicked()), SLOT(editService())); grid->addWidget(servEditButton, 4, 1); servEditButton->setWhatsThis( i18n( "Edit command line of the selected application." ) ); servRemoveButton = new QPushButton(i18n("Remove"), gb); servRemoveButton->setEnabled(false); connect(servRemoveButton, SIGNAL(clicked()), SLOT(removeService())); grid->addWidget(servRemoveButton, 5, 1); servRemoveButton->setWhatsThis( i18n( "Remove the selected application from the list." ) ); } void KServiceListWidget::setTypeItem( TypesListItem * item ) { m_item = item; if ( servNewButton ) servNewButton->setEnabled(true); // will need a selection servUpButton->setEnabled(false); servDownButton->setEnabled(false); if ( servRemoveButton ) servRemoveButton->setEnabled(false); if ( servEditButton ) servEditButton->setEnabled(false); servicesLB->clear(); servicesLB->setEnabled(false); if ( item ) { QStringList services = ( m_kind == SERVICELIST_APPLICATIONS ) ? item->appServices() : item->embedServices(); if (services.count() == 0) { servicesLB->insertItem(i18n("None")); } else { for ( QStringList::Iterator it = services.begin(); it != services.end(); it++ ) { KService::Ptr pService = KService::serviceByDesktopPath( *it ); if (pService) servicesLB->insertItem( new KServiceListItem(pService, m_kind) ); } servicesLB->setEnabled(true); } } } void KServiceListWidget::promoteService() { if (!servicesLB->isEnabled()) { KNotification::beep(); return; } unsigned int selIndex = servicesLB->currentItem(); if (selIndex == 0) { KNotification::beep(); return; } Q3ListBoxItem *selItem = servicesLB->item(selIndex); servicesLB->takeItem(selItem); servicesLB->insertItem(selItem, selIndex-1); servicesLB->setCurrentItem(selIndex - 1); updatePreferredServices(); emit changed(true); } void KServiceListWidget::demoteService() { if (!servicesLB->isEnabled()) { KNotification::beep(); return; } unsigned int selIndex = servicesLB->currentItem(); if (selIndex == servicesLB->count() - 1) { KNotification::beep(); return; } Q3ListBoxItem *selItem = servicesLB->item(selIndex); servicesLB->takeItem(selItem); servicesLB->insertItem(selItem, selIndex+1); servicesLB->setCurrentItem(selIndex + 1); updatePreferredServices(); emit changed(true); } void KServiceListWidget::addService() { if (!m_item) return; KService::Ptr service; if ( m_kind == SERVICELIST_APPLICATIONS ) { KOpenWithDlg dlg(m_item->name(), QString(), 0L); dlg.setSaveNewApplications(true); if (dlg.exec() != QDialog::Accepted) return; service = dlg.service(); Q_ASSERT(service); if (!service) return; // Don't crash if KOpenWith wasn't able to create service. } else { KServiceSelectDlg dlg(m_item->name(), QString(), 0L); if (dlg.exec() != QDialog::Accepted) return; service = dlg.service(); Q_ASSERT(service); if (!service) return; } // if None is the only item, then there currently is no default if (servicesLB->text(0) == i18n("None")) { servicesLB->removeItem(0); servicesLB->setEnabled(true); } else { // check if it is a duplicate entry for (unsigned int index = 0; index < servicesLB->count(); index++) if (static_cast( servicesLB->item(index) )->desktopPath == service->desktopEntryPath()) return; } servicesLB->insertItem( new KServiceListItem(service, m_kind), 0 ); servicesLB->setCurrentItem(0); updatePreferredServices(); emit changed(true); } void KServiceListWidget::editService() { if (!m_item) return; int selected = servicesLB->currentItem(); if ( selected >= 0 ) { // Only edit applications, not services as // they don't have any parameters if ( m_kind == SERVICELIST_APPLICATIONS ) { // Just like popping up an add dialog except that we // pass the current command line as a default Q3ListBoxItem *selItem = servicesLB->item(selected); KService::Ptr service = KService::serviceByDesktopPath( ((KServiceListItem*)selItem)->desktopPath ); if (!service) return; QString path = service->desktopEntryPath(); // If the path to the desktop file is relative, try to get the full // path from KStdDirs. - path = locate("apps", path); + path = KStandardDirs::locate("apps", path); KUrl serviceURL; serviceURL.setPath( path ); KFileItem item( serviceURL, "application/x-desktop", KFileItem::Unknown ); KPropertiesDialog dlg( &item, this, 0, true /*modal*/, false /*no auto-show*/ ); if ( dlg.exec() != QDialog::Accepted ) return; // Reload service service = KService::serviceByDesktopPath( ((KServiceListItem*)selItem)->desktopPath ); if (!service) return; // Remove the old one... servicesLB->removeItem( selected ); // ...check that it's not a duplicate entry... bool addIt = true; for (unsigned int index = 0; index < servicesLB->count(); index++) if (static_cast( servicesLB->item(index) )->desktopPath == service->desktopEntryPath()) { addIt = false; break; } // ...and add it in the same place as the old one: if ( addIt ) { servicesLB->insertItem( new KServiceListItem(service, m_kind), selected ); servicesLB->setCurrentItem(selected); } updatePreferredServices(); emit changed(true); } } } void KServiceListWidget::removeService() { if (!m_item) return; int selected = servicesLB->currentItem(); if ( selected >= 0 ) { // Check if service is associated with this mimetype or with one of its parents KServiceListItem *serviceItem = static_cast(servicesLB->item(selected)); KMimeType::Ptr mimetype = m_item->findImplicitAssociation(serviceItem->desktopPath); if (serviceItem->isImmutable()) { KMessageBox::sorry(this, i18n("You are not authorized to remove this service.")); } else if (mimetype) { KMessageBox::sorry(this, ""+ i18n("The service %1 can not be removed.", serviceItem->text())+ "

"+ i18n("The service is listed here because it has been associated " "with the %1 (%2) file type and files of type " "%3 (%4) are per definition also of type " "%5.", mimetype->name(), mimetype->comment(), m_item->name(), m_item->comment(), mimetype->name())+ "

"+ i18n("Either select the %1 file type to remove the " "service from there or move the service down " "to deprecate it.", mimetype->name())); // i18n("Do you want to remove the service from the %1 " // "file type or from the %2 file type?", ???, ???); } else { servicesLB->removeItem( selected ); updatePreferredServices(); emit changed(true); } } if ( servRemoveButton && servicesLB->currentItem() == -1 ) servRemoveButton->setEnabled(false); if ( servEditButton && servicesLB->currentItem() == -1 ) servEditButton->setEnabled(false); } void KServiceListWidget::updatePreferredServices() { if (!m_item) return; QStringList sl; unsigned int count = servicesLB->count(); for (unsigned int i = 0; i < count; i++) { KServiceListItem *sli = (KServiceListItem *) servicesLB->item(i); sl.append( sli->desktopPath ); } if ( m_kind == SERVICELIST_APPLICATIONS ) m_item->setAppServices(sl); else m_item->setEmbedServices(sl); } void KServiceListWidget::enableMoveButtons(int index) { if (servicesLB->count() <= 1) { servUpButton->setEnabled(false); servDownButton->setEnabled(false); } else if ((uint) index == (servicesLB->count() - 1)) { servUpButton->setEnabled(true); servDownButton->setEnabled(false); } else if (index == 0) { servUpButton->setEnabled(false); servDownButton->setEnabled(true); } else { servUpButton->setEnabled(true); servDownButton->setEnabled(true); } if ( servRemoveButton ) servRemoveButton->setEnabled(true); if ( servEditButton ) servEditButton->setEnabled(true && ( m_kind == SERVICELIST_APPLICATIONS ) ); } #include "kservicelistwidget.moc"