From: "Rodolfo García Peñas (kix)" <k...@kix.es>

The new function check_image_filepath(), checks if the file argument
exists in the disk and if the icon doesn't exist, show a dialog to
the user. Else return the full path for the file.

This new function replaces the ugly/dup code at winspector.c and
dockedapp.c, doing the code more clean.

The code at winspector.c is easy to see the change, but in dockedapp.c
is more difficult. The idea in dockedapp.c is first check if the file
exists in the disk, then call wIconChangeImageFile(). Because we know
the file exists, wIconChangeImageFile() doesn't return error.

Before this patch the code at dockedapp.c was more difficult to see and
had a problem. Function calls wIconChangeImageFile() to change the icon,
and allow to the user "Ignore" the error and set an incorrect file path
for the icon.

This patch also removes some curly brackets not needed and "if 0"
deactivated code in winspector.c and removes the variable "done"
because is not used (is set to 1 and the value is always 1) and
some empty lines at dockedapp.c
---
 src/dialog.c     |   19 +++++++++++++++++++
 src/dialog.h     |    3 ++-
 src/dockedapp.c  |   42 +++++++++++++++---------------------------
 src/winspector.c |   20 ++------------------
 4 files changed, 38 insertions(+), 46 deletions(-)

diff --git a/src/dialog.c b/src/dialog.c
index 6964495..fdfa44e 100644
--- a/src/dialog.c
+++ b/src/dialog.c
@@ -1607,3 +1607,22 @@ int wShowCrashingDialogPanel(int whatSig)
 
        return action;
 }
+
+char *check_image_filepath(WScreen *scr, char *file)
+{
+       char *msg = NULL, *path = NULL;
+       int len = strlen(file) + 64;
+
+       if (!file)
+               return NULL;
+
+       path = FindImage(wPreferences.icon_path, file);
+       if (path)
+               return path;
+
+       msg = wmalloc(len);
+       snprintf(msg, len, _("Could not select specified icon file: %s"), file);
+       wMessageDialog(scr, _("Error"), msg, _("OK"), NULL, NULL);
+       wfree(msg);
+       return NULL;
+}
diff --git a/src/dialog.h b/src/dialog.h
index 530bd26..a48b34d 100644
--- a/src/dialog.h
+++ b/src/dialog.h
@@ -40,9 +40,10 @@ int wExitDialog(WScreen *scr, char *title, char *message, 
char *defBtn,
 
 Bool wIconChooserDialog(WScreen *scr, char **file, char *instance, char 
*class);
 
+char *check_image_filepath(WScreen *scr, char *file);
+
 void wShowInfoPanel(WScreen *scr);
 void wShowLegalPanel(WScreen *scr);
 int wShowCrashingDialogPanel(int whatSig);
 
-
 #endif
diff --git a/src/dockedapp.c b/src/dockedapp.c
index 6c6d1f0..bead77f 100644
--- a/src/dockedapp.c
+++ b/src/dockedapp.c
@@ -149,9 +149,9 @@ static void chooseIconCallback(WMWidget * self, void 
*clientData)
 static void panelBtnCallback(WMWidget * self, void *data)
 {
        WMButton *btn = self;
+       WAppIcon *aicon = NULL;
        AppSettingsPanel *panel = (AppSettingsPanel *) data;
-       char *text;
-       int done = 1;
+       char *text = NULL, *path = NULL;
 
        if (panel->okBtn == btn) {
                text = WMGetTextFieldText(panel->iconField);
@@ -160,30 +160,20 @@ static void panelBtnCallback(WMWidget * self, void *data)
                        text = NULL;
                }
 
-               if (!wIconChangeImageFile(panel->editedIcon->icon, text)) {
-                       char *buf;
-                       int len = strlen(text) + 64;
-
-                       buf = wmalloc(len);
-                       snprintf(buf, len, _("Could not open specified icon 
file: %s"), text);
-                       if (wMessageDialog(panel->wwin->screen_ptr, _("Error"), 
buf,
-                                          _("OK"), _("Ignore"), NULL) == 
WAPRDefault) {
-                               if (text)
-                                       wfree(text);
-                               wfree(buf);
-                               return;
-                       }
-                       wfree(buf);
-               } else {
-                       WAppIcon *aicon = panel->editedIcon;
+               path = check_image_filepath(panel->wwin->screen_ptr, text);
+               if (!path)
+                       return;
 
-                       if (aicon == aicon->icon->core->screen_ptr->clip_icon)
-                               wClipIconPaint(aicon);
-                       else
-                               wAppIconPaint(aicon);
+               wIconChangeImageFile(panel->editedIcon->icon, text);
+
+               aicon = panel->editedIcon;
+               if (aicon == aicon->icon->core->screen_ptr->clip_icon)
+                       wClipIconPaint(aicon);
+               else
+                       wAppIconPaint(aicon);
+
+               wDefaultChangeIcon(panel->wwin->screen_ptr, aicon->wm_instance, 
aicon->wm_class, text);
 
-                       wDefaultChangeIcon(panel->wwin->screen_ptr, 
aicon->wm_instance, aicon->wm_class, text);
-               }
                if (text)
                        wfree(text);
 
@@ -205,12 +195,10 @@ static void panelBtnCallback(WMWidget * self, void *data)
                updatePasteCommand(panel->editedIcon, text);
 
                panel->editedIcon->auto_launch = 
WMGetButtonSelected(panel->autoLaunchBtn);
-
                panel->editedIcon->lock = WMGetButtonSelected(panel->lockBtn);
        }
 
-       if (done)
-               DestroyDockAppSettingsPanel(panel);
+       DestroyDockAppSettingsPanel(panel);
 }
 
 #define PWIDTH 295
diff --git a/src/winspector.c b/src/winspector.c
index bbbefd1..99bcd3a 100644
--- a/src/winspector.c
+++ b/src/winspector.c
@@ -334,21 +334,12 @@ static int showIconFor(WMScreen *scrPtr, InspectorPanel 
*panel, char *wm_instanc
                flags |= UPDATE_TEXT_FIELD;
        }
 
-       if ((flags & UPDATE_TEXT_FIELD) != 0) {
+       if ((flags & UPDATE_TEXT_FIELD) != 0)
                WMSetTextFieldText(panel->fileText, file);
-       }
 
        if (file) {
-               path = FindImage(wPreferences.icon_path, file);
-
+               path = check_image_filepath(panel->frame->screen_ptr, file);
                if (!path) {
-                       char *buf;
-                       int len = strlen(file) + 80;
-
-                       buf = wmalloc(len);
-                       snprintf(buf, len, _("Could not find icon \"%s\" 
specified for this window"), file);
-                       wMessageDialog(panel->frame->screen_ptr, _("Error"), 
buf, _("OK"), NULL, NULL);
-                       wfree(buf);
                        wfree(file);
                        return -1;
                }
@@ -378,13 +369,6 @@ static int showIconFor(WMScreen *scrPtr, InspectorPanel 
*panel, char *wm_instanc
        return 0;
 }
 
-#if 0
-static void updateIcon(WMButton * button, InspectorPanel * panel)
-{
-       showIconFor(WMWidgetScreen(button), panel, NULL, NULL, USE_TEXT_FIELD);
-}
-#endif
-
 static int getBool(WMPropList *value)
 {
        char *val;
-- 
1.7.10.4


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to