Changeset View
Changeset View
Standalone View
Standalone View
kcms/desktoppaths/globalpaths.cpp
Show All 31 Lines | |||||
32 | // Port to KControl, split from Misc Tab, Port to KControl2 | 32 | // Port to KControl, split from Misc Tab, Port to KControl2 | ||
33 | // (c) David Faure 1998 | 33 | // (c) David Faure 1998 | ||
34 | // Desktop menus, paths | 34 | // Desktop menus, paths | ||
35 | // (c) David Faure 2000 | 35 | // (c) David Faure 2000 | ||
36 | 36 | | |||
37 | 37 | | |||
38 | // Own | 38 | // Own | ||
39 | #include "globalpaths.h" | 39 | #include "globalpaths.h" | ||
40 | #include "ui_globalpaths.h" | ||||
40 | #include "desktoppathssettings.h" | 41 | #include "desktoppathssettings.h" | ||
41 | 42 | | |||
42 | // Qt | 43 | // Qt | ||
43 | #include <QCheckBox> | 44 | #include <QCheckBox> | ||
44 | #include <QComboBox> | 45 | #include <QComboBox> | ||
45 | #include <QLabel> | 46 | #include <QLabel> | ||
46 | #include <QLayout> | 47 | #include <QLayout> | ||
47 | #include <QFormLayout> | 48 | #include <QFormLayout> | ||
Show All 19 Lines | |||||
67 | Q_LOGGING_CATEGORY(KCM_DESKTOPPATH, "kcm_desktoppath") | 68 | Q_LOGGING_CATEGORY(KCM_DESKTOPPATH, "kcm_desktoppath") | ||
68 | 69 | | |||
69 | K_PLUGIN_FACTORY(KcmDesktopPathsFactory, registerPlugin<DesktopPathConfig>();) | 70 | K_PLUGIN_FACTORY(KcmDesktopPathsFactory, registerPlugin<DesktopPathConfig>();) | ||
70 | 71 | | |||
71 | //----------------------------------------------------------------------------- | 72 | //----------------------------------------------------------------------------- | ||
72 | 73 | | |||
73 | DesktopPathConfig::DesktopPathConfig(QWidget *parent, const QVariantList &) | 74 | DesktopPathConfig::DesktopPathConfig(QWidget *parent, const QVariantList &) | ||
74 | : KCModule( parent ) | 75 | : KCModule( parent ) | ||
76 | , m_ui(new Ui::DesktopPathsView) | ||||
75 | , m_pathsSettings(new DesktopPathsSettings(this)) | 77 | , m_pathsSettings(new DesktopPathsSettings(this)) | ||
76 | { | 78 | { | ||
77 | QFormLayout *lay = new QFormLayout(this); | 79 | m_ui->setupUi(this); | ||
78 | lay->setVerticalSpacing(0); | | |||
79 | lay->setContentsMargins(0, 0, 0, 0); | | |||
80 | | ||||
81 | setQuickHelp( i18n("<h1>Paths</h1>\n" | 80 | setQuickHelp(i18n("<h1>Paths</h1>\n" | ||
82 | "This module allows you to choose where in the filesystem the " | 81 | "This module allows you to choose where in the filesystem the " | ||
83 | "files on your desktop should be stored.\n" | 82 | "files on your desktop should be stored.\n" | ||
84 | "Use the \"Whats This?\" (Shift+F1) to get help on specific options.")); | 83 | "Use the \"Whats This?\" (Shift+F1) to get help on specific options.")); | ||
85 | 84 | addConfig(m_pathsSettings, this); | |||
86 | urDesktop = addRow(lay, i18n("Desktop path:"), | | |||
87 | i18n("This folder contains all the files" | | |||
88 | " which you see on your desktop. You can change the location of this" | | |||
89 | " folder if you want to, and the contents will move automatically" | | |||
90 | " to the new location as well.")); | | |||
91 | | ||||
92 | urAutostart = addRow(lay, i18n("Autostart path:"), | | |||
93 | i18n("This folder contains applications or" | | |||
94 | " links to applications (shortcuts) that you want to have started" | | |||
95 | " automatically whenever the session starts. You can change the location of this" | | |||
96 | " folder if you want to, and the contents will move automatically" | | |||
97 | " to the new location as well.")); | | |||
98 | | ||||
99 | urDocument = addRow(lay, i18n("Documents path:"), | | |||
100 | i18n("This folder will be used by default to " | | |||
101 | "load or save documents from or to.")); | | |||
102 | | ||||
103 | urDownload = addRow(lay, i18n("Downloads path:"), | | |||
104 | i18n("This folder will be used by default to " | | |||
105 | "save your downloaded items.")); | | |||
106 | | ||||
107 | urMovie = addRow(lay, i18n("Movies path:"), | | |||
108 | i18n("This folder will be used by default to " | | |||
109 | "load or save movies from or to.")); | | |||
110 | | ||||
111 | urPicture = addRow(lay, i18n("Pictures path:"), | | |||
112 | i18n("This folder will be used by default to " | | |||
113 | "load or save pictures from or to.")); | | |||
114 | | ||||
115 | urMusic = addRow(lay, i18n("Music path:"), | | |||
116 | i18n("This folder will be used by default to " | | |||
117 | "load or save music from or to.")); | | |||
118 | } | 85 | } | ||
119 | 86 | | |||
120 | KUrlRequester* DesktopPathConfig::addRow(QFormLayout *lay, const QString& label, const QString& whatsThis) | 87 | DesktopPathConfig::~DesktopPathConfig() | ||
121 | { | 88 | { | ||
122 | KUrlRequester* ur = new KUrlRequester(this); | | |||
123 | ur->setMode(KFile::Directory | KFile::LocalOnly); | | |||
124 | lay->addRow(label, ur); | | |||
125 | connect(ur, SIGNAL(textChanged(QString)), this, SLOT(changed())); | | |||
126 | lay->labelForField(ur)->setWhatsThis(whatsThis); | | |||
127 | ur->setWhatsThis(whatsThis); | | |||
128 | return ur; | | |||
129 | } | | |||
130 | | ||||
131 | void DesktopPathConfig::load() | | |||
132 | { | | |||
133 | m_pathsSettings->load(); | | |||
134 | | ||||
135 | // Desktop Paths | | |||
136 | urAutostart->setUrl(m_pathsSettings->autostartLocation()); | | |||
137 | | ||||
138 | urDesktop->setUrl(m_pathsSettings->desktopLocation()); | | |||
139 | urDocument->setUrl(m_pathsSettings->documentsLocation()); | | |||
140 | urDownload->setUrl(m_pathsSettings->downloadsLocation()); | | |||
141 | urMovie->setUrl(m_pathsSettings->videosLocation()); | | |||
142 | urPicture->setUrl(m_pathsSettings->picturesLocation()); | | |||
143 | urMusic->setUrl(m_pathsSettings->musicLocation()); | | |||
144 | | ||||
145 | emit changed(false); | | |||
146 | } | | |||
147 | | ||||
148 | void DesktopPathConfig::defaults() | | |||
149 | { | | |||
150 | // Desktop Paths - keep defaults in sync with kglobalsettings.cpp | | |||
151 | m_pathsSettings->setDefaults(); | | |||
152 | m_pathsSettings->setDefaults(); | | |||
153 | | ||||
154 | urAutostart->setUrl(m_pathsSettings->autostartLocation()); | | |||
155 | | ||||
156 | urDesktop->setUrl(m_pathsSettings->desktopLocation()); | | |||
157 | urDocument->setUrl(m_pathsSettings->documentsLocation()); | | |||
158 | urDownload->setUrl(m_pathsSettings->downloadsLocation()); | | |||
159 | urMovie->setUrl(m_pathsSettings->videosLocation()); | | |||
160 | urPicture->setUrl(m_pathsSettings->picturesLocation()); | | |||
161 | urMusic->setUrl(m_pathsSettings->musicLocation()); | | |||
162 | } | 89 | } | ||
163 | 90 | | |||
164 | void DesktopPathConfig::save() | 91 | void DesktopPathConfig::save() | ||
165 | { | 92 | { | ||
166 | bool autostartMoved = false; | 93 | bool autostartMoved = false; | ||
167 | 94 | | |||
168 | QUrl desktopURL = m_pathsSettings->desktopLocation(); | 95 | QUrl desktopURL = m_pathsSettings->desktopLocation(); | ||
169 | 96 | | |||
170 | QUrl autostartURL = m_pathsSettings->autostartLocation(); | 97 | QUrl autostartURL = m_pathsSettings->autostartLocation(); | ||
171 | QUrl newAutostartURL = urAutostart->url(); | 98 | QUrl newAutostartURL = m_ui->kcfg_autostartLocation->url(); | ||
172 | 99 | | |||
173 | if ( !urDesktop->url().matches( desktopURL, QUrl::StripTrailingSlash ) ) | 100 | if ( !m_ui->kcfg_desktopLocation->url().matches( desktopURL, QUrl::StripTrailingSlash ) ) | ||
174 | { | 101 | { | ||
175 | // Test which other paths were inside this one (as it is by default) | 102 | // Test which other paths were inside this one (as it is by default) | ||
176 | // and for each, test where it should go. | 103 | // and for each, test where it should go. | ||
177 | // * Inside destination -> let them be moved with the desktop (but adjust name if necessary) | 104 | // * Inside destination -> let them be moved with the desktop (but adjust name if necessary) | ||
178 | // * Not inside destination -> move first | 105 | // * Not inside destination -> move first | ||
179 | // !!! | 106 | // !!! | ||
180 | qCDebug(KCM_DESKTOPPATH) << "desktopURL=" << desktopURL; | 107 | qCDebug(KCM_DESKTOPPATH) << "desktopURL=" << desktopURL; | ||
181 | QString urlDesktop = urDesktop->url().toLocalFile(); | 108 | QString urlDesktop = m_ui->kcfg_desktopLocation->url().toLocalFile(); | ||
182 | if ( !urlDesktop.endsWith(QLatin1Char('/'))) | 109 | if ( !urlDesktop.endsWith(QLatin1Char('/'))) | ||
183 | urlDesktop+=QLatin1Char('/'); | 110 | urlDesktop+=QLatin1Char('/'); | ||
184 | 111 | | |||
185 | if ( desktopURL.isParentOf( autostartURL ) ) | 112 | if ( desktopURL.isParentOf( autostartURL ) ) | ||
186 | { | 113 | { | ||
187 | qCDebug(KCM_DESKTOPPATH) << "Autostart is on the desktop"; | 114 | qCDebug(KCM_DESKTOPPATH) << "Autostart is on the desktop"; | ||
188 | 115 | | |||
189 | // Either the Autostart field wasn't changed (-> need to update it) | 116 | // Either the Autostart field wasn't changed (-> need to update it) | ||
190 | if ( newAutostartURL.matches(autostartURL, QUrl::StripTrailingSlash) ) | 117 | if ( newAutostartURL.matches(autostartURL, QUrl::StripTrailingSlash) ) | ||
191 | { | 118 | { | ||
192 | // Hack. It could be in a subdir inside desktop. Hmmm... Argl. | 119 | // Hack. It could be in a subdir inside desktop. Hmmm... Argl. | ||
193 | urAutostart->setUrl(QUrl::fromLocalFile(urlDesktop + QStringLiteral("Autostart/"))); | 120 | m_ui->kcfg_autostartLocation->setUrl(QUrl::fromLocalFile(urlDesktop + QStringLiteral("Autostart/"))); | ||
194 | qCDebug(KCM_DESKTOPPATH) << "Autostart is moved with the desktop"; | 121 | qCDebug(KCM_DESKTOPPATH) << "Autostart is moved with the desktop"; | ||
195 | autostartMoved = true; | 122 | autostartMoved = true; | ||
196 | } | 123 | } | ||
197 | // or it has been changed (->need to move it from here) | 124 | // or it has been changed (->need to move it from here) | ||
198 | else | 125 | else | ||
199 | { | 126 | { | ||
200 | QUrl futureAutostartURL = QUrl::fromLocalFile(urlDesktop + QStringLiteral("Autostart/")); | 127 | QUrl futureAutostartURL = QUrl::fromLocalFile(urlDesktop + QStringLiteral("Autostart/")); | ||
201 | if ( newAutostartURL.matches( futureAutostartURL, QUrl::StripTrailingSlash ) ) | 128 | if ( newAutostartURL.matches( futureAutostartURL, QUrl::StripTrailingSlash ) ) | ||
202 | autostartMoved = true; | 129 | autostartMoved = true; | ||
203 | else | 130 | else | ||
204 | autostartMoved = moveDir( m_pathsSettings->autostartLocation(), urAutostart->url(), i18n("Autostart") ); | 131 | autostartMoved = moveDir( m_pathsSettings->autostartLocation(), m_ui->kcfg_autostartLocation->url(), i18n("Autostart") ); | ||
205 | } | 132 | } | ||
206 | } | 133 | } | ||
207 | 134 | | |||
208 | if ( moveDir( m_pathsSettings->desktopLocation(), QUrl::fromLocalFile( urlDesktop ), i18n("Desktop") ) ) | 135 | if ( moveDir( m_pathsSettings->desktopLocation(), QUrl::fromLocalFile( urlDesktop ), i18n("Desktop") ) ) | ||
209 | { | 136 | { | ||
210 | //save in XDG path | 137 | //save in XDG path | ||
211 | m_pathsSettings->setDesktopLocation(QUrl::fromLocalFile(urlDesktop)); | 138 | m_pathsSettings->setDesktopLocation(QUrl::fromLocalFile(urlDesktop)); | ||
212 | } | 139 | } | ||
213 | } | 140 | } | ||
214 | 141 | | |||
215 | if ( !newAutostartURL.matches( autostartURL, QUrl::StripTrailingSlash ) ) | 142 | if ( !newAutostartURL.matches( autostartURL, QUrl::StripTrailingSlash ) ) | ||
216 | { | 143 | { | ||
217 | if (!autostartMoved) | 144 | if (!autostartMoved) | ||
218 | autostartMoved = moveDir( m_pathsSettings->autostartLocation(), urAutostart->url(), i18n("Autostart") ); | 145 | autostartMoved = moveDir( m_pathsSettings->autostartLocation(), m_ui->kcfg_autostartLocation->url(), i18n("Autostart") ); | ||
219 | if (autostartMoved) | 146 | if (autostartMoved) | ||
220 | { | 147 | { | ||
221 | m_pathsSettings->setAutostartLocation(urAutostart->url()); | 148 | m_pathsSettings->setAutostartLocation(m_ui->kcfg_autostartLocation->url()); | ||
222 | } | 149 | } | ||
223 | } | 150 | } | ||
224 | 151 | | |||
225 | xdgSavePath(urDocument, m_pathsSettings->documentsLocation(), "documentsLocation", i18n("Documents")); | 152 | xdgSavePath(m_ui->kcfg_documentsLocation, m_pathsSettings->documentsLocation(), "documentsLocation", i18n("Documents")); | ||
226 | xdgSavePath(urDownload, m_pathsSettings->downloadsLocation(), "downloadsLocation", i18n("Downloads")); | 153 | xdgSavePath(m_ui->kcfg_downloadsLocation, m_pathsSettings->downloadsLocation(), "downloadsLocation", i18n("Downloads")); | ||
227 | xdgSavePath(urMovie, m_pathsSettings->videosLocation(), "videosLocation", i18n("Movies")); | 154 | xdgSavePath(m_ui->kcfg_videosLocation, m_pathsSettings->videosLocation(), "videosLocation", i18n("Movies")); | ||
228 | xdgSavePath(urPicture, m_pathsSettings->picturesLocation(), "picturesLocation", i18n("Pictures")); | 155 | xdgSavePath(m_ui->kcfg_picturesLocation, m_pathsSettings->picturesLocation(), "picturesLocation", i18n("Pictures")); | ||
229 | xdgSavePath(urMusic, m_pathsSettings->musicLocation(), "musicLocation", i18n("Music")); | 156 | xdgSavePath(m_ui->kcfg_musicLocation, m_pathsSettings->musicLocation(), "musicLocation", i18n("Music")); | ||
230 | 157 | | |||
231 | m_pathsSettings->save(); | 158 | m_pathsSettings->save(); | ||
232 | } | 159 | } | ||
233 | 160 | | |||
234 | bool DesktopPathConfig::xdgSavePath(KUrlRequester* ur, const QUrl& currentUrl, const char* xdgKey, const QString& type) | 161 | bool DesktopPathConfig::xdgSavePath(KUrlRequester* ur, const QUrl& currentUrl, const char* xdgKey, const QString& type) | ||
235 | { | 162 | { | ||
236 | QUrl newUrl = ur->url(); | 163 | QUrl newUrl = ur->url(); | ||
237 | //url might be empty, use QDir::homePath (the default for xdg) then | 164 | //url might be empty, use QDir::homePath (the default for xdg) then | ||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |