Lukas Appelhans 写道:
Am Mittwoch 19 August 2009 15:51:18 schrieb 潘卫平(Peter Pan):
Lukas Appelhans 写道:
Am Mittwoch 19 August 2009 14:25:09 schrieb 潘卫平(Peter Pan):
Lukas Appelhans 写道:
Am Mittwoch 19 August 2009 05:50:08 schrieb 潘卫平(Peter Pan):
潘卫平(Peter Pan) 写道:
Aaron J. Seigo 写道:
On Friday 14 August 2009, 潘卫平(Peter Pan) wrote:
svn r 1011382
there are a couple issues with this patch, unfortunately. first, it
introduces a modal dialog. that will block the rest of plasma. not
good.
:/
That's really not good.
second, the button names are just "Ok" and "Cancel", they should be
changed to having meaningful labels that say _what_ will happen if
"Ok" or "Cancel" is pressed. but that's a moot point, because we
really can't have a modal dialog here.
is there any use case where it makes sense to have more than one
icon for the _same_ application or file? i can't think of one. so
i'd suggest just silently dropping duplicates.
I prefer to show user a warning message rather than drop it silently.
--------------------------------------------------------------------
-- --
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel
Every time you want to add an application, call checkDuplicateUrls()
first.In this function, I give user a hint when we find duplicate
URLs, then ignore them.
And setModal(false) for KMessageBox.
Regards
Mmh, I don't like that we iterate through the list 2 times, we should
just remove the iteration for checkin duplicates in the addProgram()
method imo...
I prefer to make the applications in quicklaunch unique, not allow
duplicating. Because I don't like that quicklaunch is too wide.
Yeah, sure, but why do we iterate through the list 2 times? One time to
show the dialog and one time to remove duplicates? that doesn't make much
sense to me... :/
oh, because KDialog->show() will return immediately, so first time, I
prepare a message for KMessageBox.
If we checkin duplicates in addProgram()'s iteration, only the last
duplicate application will be shown.
And second time iteration, remove duplicates.
Well why not let checkDuplicates() return a cleared KUrl::List where all
duplicates are removed?
I got it.
Lukas
Also the KDialog way seems a bit too much to me, isn't there a way to
just get a KMessageBox like the command we got before?
KMessageBox needs a KDialog parameter.
I can't find another way if we use KMessageBox.
Okee then leave it that way :)
Lukas
Lukas
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel
Regards
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel
Regards
--
潘卫平(Peter Pan)
Red Flag Software Co., Ltd
Index: quicklaunchApplet.h
===================================================================
--- quicklaunchApplet.h ï¼çæ¬ 1013469ï¼
+++ quicklaunchApplet.h ï¼å·¥ä½å¯æ¬ï¼
@@ -149,6 +149,13 @@
void addProgram(int index, const QString &desktopFile, bool isNewIcon = false);
/**
+ * Remove duplicate KUrls
+ * @param urls The urls to be inserted into quicklaunch
+ * @return the KUrl::List which arleady removed duplications
+ */
+ KUrl::List removeDuplicateUrls(const KUrl::List &urls);
+
+ /**
* Removes all items from a BoxLayout
* @param layout Layout to clear
*/
Index: quicklaunchApplet.cpp
===================================================================
--- quicklaunchApplet.cpp ï¼çæ¬ 1013469ï¼
+++ quicklaunchApplet.cpp ï¼å·¥ä½å¯æ¬ï¼
@@ -610,29 +610,7 @@
KIcon icon;
QString text;
QString genericName;
- bool do_add_program = true;
- if (!m_isBusy) {
- foreach (QuicklaunchIcon *icon, m_icons) {
- if (icon->url().url() == appUrl.url()) {
- if (KMessageBox::warningContinueCancel(
- 0,
- i18n("\"%1\" is already in quicklaunch!", icon->url().pathOrUrl()),
- i18n("Warning")
- ) == KMessageBox::Cancel) {
- do_add_program = false;
- break;
- } else {
- break;
- }
- }
- }
- }
-
- if (!do_add_program) {
- return;
- }
-
if (appUrl.isLocalFile() && KDesktopFile::isDesktopFile(appUrl.toLocalFile())) {
KDesktopFile *f = new KDesktopFile(appUrl.toLocalFile());
@@ -694,18 +672,20 @@
if (urls.isEmpty()) {
return false;
}
-
- //if there are more than one the last is junk
- if (urls.count() > 1) {
- urls.removeLast();
+
+ KUrl::List uniqueUrls = removeDuplicateUrls(urls);
+
+ if (uniqueUrls.count()) {
+ foreach (const KUrl &url, uniqueUrls) {
+ if (KDesktopFile::isDesktopFile(url.toLocalFile())) {
+ addProgram(pos, url.toLocalFile(), true);
+ }
+ }
+
+ return true;
}
- foreach (const KUrl &url, urls) {
- if (KDesktopFile::isDesktopFile(url.toLocalFile())) {
- addProgram(pos, url.toLocalFile(), true);
- }
- }
- return true;
+ return false;
}
@@ -728,11 +708,61 @@
void QuicklaunchApplet::addAccepted()
{
- int insertplace = m_rightClickedIcon ? m_icons.indexOf(m_rightClickedIcon) : m_icons.size();
- addProgram(insertplace, addUi.urlIcon->url().url(), true);
- performUiRefactor();
+ KUrl::List uniqueUrls = removeDuplicateUrls(KUrl::List(addUi.urlIcon->url()));
+ if (uniqueUrls.count() == 1) {
+ int insertplace = m_rightClickedIcon ? m_icons.indexOf(m_rightClickedIcon) : m_icons.size();
+ addProgram(insertplace, uniqueUrls.first().toLocalFile(), true);
+ performUiRefactor();
+ }
}
+KUrl::List QuicklaunchApplet::removeDuplicateUrls(const KUrl::List &urls)
+{
+ QStringList duplicateWarningMessage;
+ duplicateWarningMessage.clear();
+
+ KUrl::List uniqueUrls = urls;
+ foreach (const KUrl &url, urls) {
+ foreach (QuicklaunchIcon *icon, m_icons) {
+ if (icon->url().url() == url.url()) {
+ duplicateWarningMessage << url.pathOrUrl();
+ uniqueUrls.removeOne(url);
+ break;
+ }
+ }
+ }
+
+ if (!duplicateWarningMessage.isEmpty()) {
+ KDialog *warningDialog = new KDialog;
+ warningDialog->setButtons(KDialog::Ok);
+ warningDialog->setModal(false);
+ warningDialog->setDefaultButton(KDialog::Ok);
+
+ QString warningMessage;
+ int count = duplicateWarningMessage.count();
+
+ foreach (QString str, duplicateWarningMessage) {
+ warningMessage += str + "\n";
+ }
+
+ KMessageBox::createKMessageBox(warningDialog,
+ QMessageBox::Warning,
+ i18np("%2is already in quicklaunch, ignore it!",
+ "%2are already in quicklaunch, ignore them!",
+ count,
+ warningMessage),
+ QStringList(),
+ QString(""),
+ NULL,
+ KMessageBox::NoExec);
+
+ warningDialog->resize(400, 300);
+ warningDialog->show();
+ }
+
+ return uniqueUrls;
+}
+
K_EXPORT_PLASMA_APPLET(quicklaunch, QuicklaunchApplet)
#include "quicklaunchApplet.moc"
_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel