潘卫平(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
--
潘卫平(Peter Pan)
Red Flag Software Co., Ltd
Index: quicklaunchApplet.h
===================================================================
--- quicklaunchApplet.h (revision 1013166)
+++ quicklaunchApplet.h (working copy)
@@ -149,6 +149,12 @@
void addProgram(int index, const QString &desktopFile, bool isNewIcon = false);
/**
+ * Check duplicate KUrls
+ * @param urls The urls to be inserted into quicklaunch
+ */
+ void checkDuplicateUrls(const KUrl::List &urls);
+
+ /**
* Removes all items from a BoxLayout
* @param layout Layout to clear
*/
Index: quicklaunchApplet.cpp
===================================================================
--- quicklaunchApplet.cpp (revision 1013166)
+++ quicklaunchApplet.cpp (working copy)
@@ -610,29 +610,15 @@
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;
- }
+ return;
}
}
}
- if (!do_add_program) {
- return;
- }
-
if (appUrl.isLocalFile() && KDesktopFile::isDesktopFile(appUrl.toLocalFile())) {
KDesktopFile *f = new KDesktopFile(appUrl.toLocalFile());
@@ -694,17 +680,15 @@
if (urls.isEmpty()) {
return false;
}
-
- //if there are more than one the last is junk
- if (urls.count() > 1) {
- urls.removeLast();
- }
-
+
+ checkDuplicateUrls(urls);
+
foreach (const KUrl &url, urls) {
if (KDesktopFile::isDesktopFile(url.toLocalFile())) {
addProgram(pos, url.toLocalFile(), true);
}
}
+
return true;
}
@@ -728,11 +712,55 @@
void QuicklaunchApplet::addAccepted()
{
+ checkDuplicateUrls(KUrl::List(addUi.urlIcon->url().url()));
int insertplace = m_rightClickedIcon ? m_icons.indexOf(m_rightClickedIcon) : m_icons.size();
addProgram(insertplace, addUi.urlIcon->url().url(), true);
performUiRefactor();
}
+void QuicklaunchApplet::checkDuplicateUrls(const KUrl::List &urls)
+{
+ QStringList duplicateWarningMessage;
+ duplicateWarningMessage.clear();
+
+ foreach (const KUrl &url, urls) {
+ foreach (QuicklaunchIcon *icon, m_icons) {
+ if (icon->url().url() == url.url()) {
+ duplicateWarningMessage << url.pathOrUrl();
+ 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();
+ }
+}
+
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