From 6ade341229a0ce755b3e606d974b37c7d1609c8a Mon Sep 17 00:00:00 2001 From: tpearson Date: Fri, 24 Sep 2010 01:59:23 +0000 Subject: * Allow XDG launcher to directly rewrite the XDG configuration file instead of going through a third party application * Fix desktop icon builtin detection * Desktop icon removal is now more intuitive git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1178835 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kdesktop/init/My_Computer | 3 +- kdesktop/init/My_Documents | 1 + kdesktop/init/My_Network_Places | 1 + kdesktop/init/Printers | 1 + kdesktop/init/Trash | 1 + kdesktop/init/Web_Browser | 1 + kdesktop/kdiconview.cc | 103 ++++++++++++++++++++++++++++++++-------- kdesktop/kdiconview.h | 7 +++ kdesktop/kxdglauncher.cpp | 12 +++-- 9 files changed, 107 insertions(+), 23 deletions(-) diff --git a/kdesktop/init/My_Computer b/kdesktop/init/My_Computer index bed37415a..45117cfdc 100644 --- a/kdesktop/init/My_Computer +++ b/kdesktop/init/My_Computer @@ -5,4 +5,5 @@ Name=My Computer Name[en_US]=My Computer OnlyShowIn=KDE; Type=Link -URL=media:/ \ No newline at end of file +URL=media:/ +X-Trinity-BuiltIn=true \ No newline at end of file diff --git a/kdesktop/init/My_Documents b/kdesktop/init/My_Documents index ca461a586..3ced85d07 100644 --- a/kdesktop/init/My_Documents +++ b/kdesktop/init/My_Documents @@ -14,3 +14,4 @@ Type=Application X-DCOP-ServiceType= X-KDE-SubstituteUID=false X-KDE-Username= +X-Trinity-BuiltIn=true \ No newline at end of file diff --git a/kdesktop/init/My_Network_Places b/kdesktop/init/My_Network_Places index 58664524e..a02d422f0 100644 --- a/kdesktop/init/My_Network_Places +++ b/kdesktop/init/My_Network_Places @@ -6,3 +6,4 @@ Name[en_US]=My Network Places OnlyShowIn=KDE; Type=Link URL=remote:/ +X-Trinity-BuiltIn=true \ No newline at end of file diff --git a/kdesktop/init/Printers b/kdesktop/init/Printers index e2711cbf5..e7287a4e0 100644 --- a/kdesktop/init/Printers +++ b/kdesktop/init/Printers @@ -8,3 +8,4 @@ Exec=kjobviewer --all --show %i %m OnlyShowIn=KDE; X-DCOP-ServiceType=Unique X-KDE-StartupNotify=true +X-Trinity-BuiltIn=true \ No newline at end of file diff --git a/kdesktop/init/Trash b/kdesktop/init/Trash index 2dcee0299..1d2f0f52d 100644 --- a/kdesktop/init/Trash +++ b/kdesktop/init/Trash @@ -6,3 +6,4 @@ Icon=trashcan_full EmptyIcon=trashcan_empty Name=Trash Comment=Contains removed files +X-Trinity-BuiltIn=true \ No newline at end of file diff --git a/kdesktop/init/Web_Browser b/kdesktop/init/Web_Browser index e11733188..0dd86b96c 100644 --- a/kdesktop/init/Web_Browser +++ b/kdesktop/init/Web_Browser @@ -16,3 +16,4 @@ Type=Application X-DCOP-ServiceType= X-KDE-SubstituteUID=false X-KDE-Username= +X-Trinity-BuiltIn=true \ No newline at end of file diff --git a/kdesktop/kdiconview.cc b/kdesktop/kdiconview.cc index fa7a9d7d0..ed0500e1c 100644 --- a/kdesktop/kdiconview.cc +++ b/kdesktop/kdiconview.cc @@ -190,6 +190,8 @@ KDIconView::KDIconView( TQWidget *parent, const char* name ) setAcceptDrops(false); viewport()->setAcceptDrops(false); } + + g_pConfig = new KConfig("kdesktoprc"); } KDIconView::~KDIconView() @@ -719,6 +721,74 @@ void KDIconView::slotPopupPasteTo() paste( m_popupURL ); } +// These two functions and the following class are all lifted from desktopbehavior_impl.cpp to handle the media icons +class DesktopBehaviorMediaItem : public QCheckListItem +{ +public: + DesktopBehaviorMediaItem(TQListView *parent, const TQString name, const TQString mimetype, bool on) + : TQCheckListItem(parent, name, CheckBox), + m_mimeType(mimetype){setOn(on);} + + const TQString &mimeType() const { return m_mimeType; } + +private: + TQString m_mimeType; +}; + +void KDIconView::fillMediaListView() +{ + if (!mMediaListView) + mMediaListView = new TQListView(); + mMediaListView->hide(); + mMediaListView->clear(); + KMimeType::List mimetypes = KMimeType::allMimeTypes(); + TQValueListIterator it2(mimetypes.begin()); + g_pConfig->setGroup( "Media" ); + TQString 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 (mMediaListView, (*it2)->comment(), (*it2)->name(),ok); + } + } +} + +void KDIconView::saveMediaListView() +{ + g_pConfig->setGroup( "Media" ); + TQStringList exclude; + for (DesktopBehaviorMediaItem *it=static_cast(mMediaListView->firstChild()); + it; it=static_cast(it->nextSibling())) + { + if (!it->isOn()) exclude << it->mimeType(); + } + g_pConfig->writeEntry("exclude",exclude); + g_pConfig->sync(); + + // Reload kdesktop configuration to apply changes + TQByteArray data; + int konq_screen_number = KApplication::desktop()->primaryScreen(); + TQCString appname; + if (konq_screen_number == 0) + appname = "kdesktop"; + else + appname.sprintf("kdesktop-screen-%d", konq_screen_number); + kapp->dcopClient()->send( appname, "KDesktopIface", "configure()", data ); +} + +void KDIconView::removeBuiltinIcon(TQString iconName) +{ + DesktopBehaviorMediaItem *changeItem; + fillMediaListView(); + changeItem = static_cast(mMediaListView->findItem(iconName, 0)); + if (changeItem != 0) { + changeItem->setOn(false); + } + saveMediaListView(); + KMessageBox::information(0, i18n("You have chosen to remove a system icon") + TQString(".\n") + i18n("You can restore this icon in the future through the") + TQString(" \"") + ("Device Icons") + TQString("\" ") + i18n("tab in the") + TQString(" \"") + i18n("Behavior") + TQString("\" ") + i18n("pane of the Desktop Settings control module."), "System Icon Removed", "sysiconremovedwarning"); +} + /** * The files on the desktop come from a variety of sources. * If an attempt is made to delete a .desktop file that does @@ -762,49 +832,44 @@ bool KDIconView::deleteGlobalDesktopFiles() // Ignore these special files // Name URL Type OnlyShowIn - // My Documents $HOME/Documents Link KDE; + // My Documents kxdglauncher --xdgname DOCUMENTS Application KDE; // My Computer media:/ Link KDE; // My Network Places remote:/ Link KDE; // Printers [exec] kjobviewer --all --show %i %m Application KDE; // Trash trash:/ Link KDE; - // Web Browser Application KDE; + // Web Browser kfmclient openBrowser %u Application KDE; if ( isDesktopFile(fItem) ) { KSimpleConfig cfg( fItem->url().path(), true ); cfg.setDesktopGroup(); - if ( cfg.readEntry( "Type" ) == "Link" && - cfg.readEntry( "URL" ) == "$HOME/Documents" && - cfg.readEntry( "OnlyShowIn" ) == "KDE;" && + if ( cfg.readEntry( "X-Trinity-BuiltIn" ) == "true" && cfg.readEntry( "Name" ) == "My Documents" ) { + removeBuiltinIcon("My Documents"); continue; } - if ( cfg.readEntry( "Type" ) == "Link" && - cfg.readEntry( "URL" ) == "media:/" && - cfg.readEntry( "OnlyShowIn" ) == "KDE;" && + if ( cfg.readEntry( "X-Trinity-BuiltIn" ) == "true" && cfg.readEntry( "Name" ) == "My Computer" ) { + removeBuiltinIcon("My Computer"); continue; } - if ( cfg.readEntry( "Type" ) == "Link" && - cfg.readEntry( "URL" ) == "remote:/" && - cfg.readEntry( "OnlyShowIn" ) == "KDE;" && + if ( cfg.readEntry( "X-Trinity-BuiltIn" ) == "true" && cfg.readEntry( "Name" ) == "My Network Places" ) { + removeBuiltinIcon("My Network Places"); continue; } - if ( cfg.readEntry( "Type" ) == "Application" && - cfg.readEntry( "Exec" ) == "kjobviewer --all --show %i %m" && - cfg.readEntry( "OnlyShowIn" ) == "KDE;" && + if ( cfg.readEntry( "X-Trinity-BuiltIn" ) == "true" && cfg.readEntry( "Name" ) == "Printers" ) { + removeBuiltinIcon("Printers"); continue; } - if ( cfg.readEntry( "Type" ) == "Link" && - cfg.readEntry( "URL" ) == "trash:/" && - cfg.readEntry( "OnlyShowIn" ) == "KDE;" && + if ( cfg.readEntry( "X-Trinity-BuiltIn" ) == "true" && cfg.readEntry( "Name" ) == "Trash" ) { + removeBuiltinIcon("Trash"); continue; } - if ( cfg.readEntry( "Type" ) == "Application" && - cfg.readEntry( "OnlyShowIn" ) == "KDE;" && + if ( cfg.readEntry( "X-Trinity-BuiltIn" ) == "true" && cfg.readEntry( "Name" ) == "Web Browser" ) { + removeBuiltinIcon("Web Browser"); continue; } } diff --git a/kdesktop/kdiconview.h b/kdesktop/kdiconview.h index 73b493120..4e2841588 100644 --- a/kdesktop/kdiconview.h +++ b/kdesktop/kdiconview.h @@ -24,6 +24,7 @@ #include #include #include +#include class KDirLister; class KonqSettings; @@ -173,6 +174,9 @@ protected: void moveToFreePosition(TQIconViewItem *item ); bool deleteGlobalDesktopFiles(); + void removeBuiltinIcon(TQString iconName); + void fillMediaListView(); + void saveMediaListView(); static void renameDesktopFile(const TQString &path, const TQString &name); @@ -260,6 +264,9 @@ private: bool m_gotIconsArea; bool m_needDesktopAlign; + + TQListView *mMediaListView; + KConfig *g_pConfig; }; #endif diff --git a/kdesktop/kxdglauncher.cpp b/kdesktop/kxdglauncher.cpp index fba2c3fbf..ff173c842 100644 --- a/kdesktop/kxdglauncher.cpp +++ b/kdesktop/kxdglauncher.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -130,9 +131,14 @@ int main( int argc, char **argv) directoryOk = TRUE; } if (directoryOk == true) { - char systemcommand[8192]; - sprintf(systemcommand, "xdg-user-dirs-update --set DOCUMENTS \"%s\"", newDirectory.ascii()); - system(systemcommand); + TQString xdgModifiedDirectory = newDirectory; + xdgModifiedDirectory = xdgModifiedDirectory.replace(TQDir::homeDirPath(), "$HOME"); + while (xdgModifiedDirectory.endsWith("/")) { + xdgModifiedDirectory.truncate(xdgModifiedDirectory.length()-1); + } + KConfig config(TQDir::homeDirPath() + "/.config/user-dirs.dirs", false, false); + config.writeEntry("XDG_DOCUMENTS_DIR", TQString("\"") + xdgModifiedDirectory + TQString("\""), true); + config.sync(); if (args->isSet( "getpath" ) == true) { printf("%s\n\r", getDocumentPath().ascii()); return 0; -- cgit v1.2.3