changeset 13267:f3ae450fb947

[gaim-migrate @ 15633] Part of SF Patch #1175520 from dennisne This adds a request API function to select a folder. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Mon, 13 Feb 2006 03:40:00 +0000
parents d1088b7771d4
children 16f6d6f8afc7
files plugins/ChangeLog.API src/gtkrequest.c src/request.c src/request.h
diffstat 4 files changed, 114 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Mon Feb 13 03:07:13 2006 +0000
+++ b/plugins/ChangeLog.API	Mon Feb 13 03:40:00 2006 +0000
@@ -272,6 +272,9 @@
 	* gaim_date_format_full()
 	* gaim_time_format()
 	* gaim_plugin_action_free()
+	* GaimRequestType: Added GAIM_REQUEST_FOLDER
+	* GaimRequestUiOps: Added request_folder
+	* gaim_request_folder()
 
 	Signals - Changed:  (See the Doxygen docs for details on all signals.)
 	* Signal propagation now stops after a handler returns a non-NULL value.
--- a/src/gtkrequest.c	Mon Feb 13 03:07:13 2006 +0000
+++ b/src/gtkrequest.c	Mon Feb 13 03:40:00 2006 +0000
@@ -1951,6 +1951,44 @@
 	return (void *)data;
 }
 
+static void *
+gaim_gtk_request_folder(const char *title, const char *dirname,
+					  GCallback ok_cb, GCallback cancel_cb,
+					  void *user_data)
+{
+	GaimGtkRequestData *data;
+	GtkWidget *dirsel;
+	
+	data = g_new0(GaimGtkRequestData, 1);
+	data->type = GAIM_REQUEST_FOLDER;
+	data->user_data = user_data;
+	data->cb_count = 2;
+	data->cbs = g_new0(GCallback, 2);
+	data->cbs[0] = cancel_cb;
+	data->cbs[1] = ok_cb;
+	data->u.file.savedialog = FALSE;
+	
+	dirsel = gtk_file_chooser_dialog_new(
+						title ? title : _("Select Folder..."),
+						NULL,
+						GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+						GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+						GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+						NULL);
+	gtk_dialog_set_default_response(GTK_DIALOG(dirsel), GTK_RESPONSE_ACCEPT);
+
+	if ((dirname != NULL) && (*dirname != '\0'))
+		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dirsel), dirname);
+
+	g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(dirsel)), "response",
+						G_CALLBACK(file_ok_check_if_exists_cb), data);
+
+	data->dialog = dirsel;
+	gtk_widget_show(dirsel);
+
+	return (void *)data;
+}
+
 static void
 gaim_gtk_close_request(GaimRequestType type, void *ui_handle)
 {
@@ -1976,7 +2014,8 @@
 	gaim_gtk_request_action,
 	gaim_gtk_request_fields,
 	gaim_gtk_request_file,
-	gaim_gtk_close_request
+	gaim_gtk_close_request,
+	gaim_gtk_request_folder
 };
 
 GaimRequestUiOps *
--- a/src/request.c	Mon Feb 13 03:07:13 2006 +0000
+++ b/src/request.c	Mon Feb 13 03:40:00 2006 +0000
@@ -1363,6 +1363,29 @@
 	return NULL;
 }
 
+void *
+gaim_request_folder(void *handle, const char *title, const char *dirname,
+				  GCallback ok_cb, GCallback cancel_cb, void *user_data)
+{
+	GaimRequestUiOps *ops;
+
+	ops = gaim_request_get_ui_ops();
+
+	if (ops != NULL && ops->request_file != NULL) {
+		GaimRequestInfo *info;
+
+		info            = g_new0(GaimRequestInfo, 1);
+		info->type      = GAIM_REQUEST_FOLDER;
+		info->handle    = handle;
+		info->ui_handle = ops->request_folder(title, dirname,
+											ok_cb, cancel_cb, user_data);
+		handles = g_list_append(handles, info);
+		return info->ui_handle;
+	}
+
+	return NULL;
+}
+
 static void
 gaim_request_close_info(GaimRequestInfo *info)
 {
--- a/src/request.h	Mon Feb 13 03:07:13 2006 +0000
+++ b/src/request.h	Mon Feb 13 03:40:00 2006 +0000
@@ -42,7 +42,8 @@
 	GAIM_REQUEST_CHOICE,     /**< Multiple-choice request.   */
 	GAIM_REQUEST_ACTION,     /**< Action request.            */
 	GAIM_REQUEST_FIELDS,     /**< Multiple fields request.   */
-	GAIM_REQUEST_FILE        /**< File open or save request. */
+	GAIM_REQUEST_FILE,       /**< File open or save request. */
+	GAIM_REQUEST_FOLDER      /**< Folder selection request.  */
 
 } GaimRequestType;
 
@@ -205,6 +206,9 @@
 						  gboolean savedialog, GCallback ok_cb,
 						  GCallback cancel_cb, void *user_data);
 	void (*close_request)(GaimRequestType type, void *ui_handle);
+	void *(*request_folder)(const char *title, const char *dirname,
+							GCallback ok_cb, GCallback cancel_cb,
+							void *user_data);
 } GaimRequestUiOps;
 
 typedef void (*GaimRequestInputCb)(void *, const char *);
@@ -1164,10 +1168,10 @@
  * @param hint          Optionally suggest how the input box should appear.
  *                      Use "html," for example, to allow the user to enter
  *                      HTML.
- * @param ok_text       The text for the OK button.
- * @param ok_cb         The callback for the OK button.
- * @param cancel_text   The text for the cancel button.
- * @param cancel_cb     The callback for the cancel button.
+ * @param ok_text       The text for the @c OK button.
+ * @param ok_cb         The callback for the @c OK button.
+ * @param cancel_text   The text for the @c Cancel button.
+ * @param cancel_cb     The callback for the @c Cancel button.
  * @param user_data     The data to pass to the callback.
  *
  * @return A UI-specific handle.
@@ -1190,10 +1194,10 @@
  * @param primary       The main point of the message.
  * @param secondary     The secondary information.
  * @param default_value The default value.
- * @param ok_text       The text for the OK button.
- * @param ok_cb         The callback for the OK button.
- * @param cancel_text   The text for the cancel button.
- * @param cancel_cb     The callback for the cancel button.
+ * @param ok_text       The text for the @c OK button.
+ * @param ok_cb         The callback for the @c OK button.
+ * @param cancel_text   The text for the @c Cancel button.
+ * @param cancel_cb     The callback for the @c Cancel button.
  * @param user_data     The data to pass to the callback.
  * @param ...           The choices.  This argument list should be
  *                      terminated with a NULL parameter.
@@ -1217,13 +1221,13 @@
  * @param primary       The main point of the message.
  * @param secondary     The secondary information.
  * @param default_value The default value.
- * @param ok_text       The text for the OK button.
- * @param ok_cb         The callback for the OK button.
- * @param cancel_text   The text for the cancel button.
- * @param cancel_cb     The callback for the cancel button.
+ * @param ok_text       The text for the @c OK button.
+ * @param ok_cb         The callback for the @c OK button.
+ * @param cancel_text   The text for the @c Cancel button.
+ * @param cancel_cb     The callback for the @c Cancel button.
  * @param user_data     The data to pass to the callback.
  * @param choices       The choices.  This argument list should be
- *                      terminated with a NULL parameter.
+ *                      terminated with a @c NULL parameter.
  *
  * @return A UI-specific handle.
  */
@@ -1291,10 +1295,10 @@
  * @param primary     The main point of the message.
  * @param secondary   The secondary information.
  * @param fields      The list of fields.
- * @param ok_text     The text for the OK button.
- * @param ok_cb       The callback for the OK button.
- * @param cancel_text The text for the cancel button.
- * @param cancel_cb   The callback for the cancel button.
+ * @param ok_text     The text for the @c OK button.
+ * @param ok_cb       The callback for the @c OK button.
+ * @param cancel_text The text for the @c Cancel button.
+ * @param cancel_cb   The callback for the @c Cancel button.
  * @param user_data   The data to pass to the callback.
  *
  * @return A UI-specific handle.
@@ -1322,7 +1326,7 @@
 void gaim_request_close_with_handle(void *handle);
 
 /**
- * A wrapper for gaim_request_action() that uses Yes and No buttons.
+ * A wrapper for gaim_request_action() that uses @c Yes and @c No buttons.
  */
 #define gaim_request_yes_no(handle, title, primary, secondary, \
 							default_action, user_data, yes_cb, no_cb) \
@@ -1331,7 +1335,7 @@
 						_("Yes"), (yes_cb), _("No"), (no_cb))
 
 /**
- * A wrapper for gaim_request_action() that uses OK and Cancel buttons.
+ * A wrapper for gaim_request_action() that uses @c OK and @c Cancel buttons.
  */
 #define gaim_request_ok_cancel(handle, title, primary, secondary, \
 							default_action, user_data, ok_cb, cancel_cb) \
@@ -1350,18 +1354,18 @@
 						_("_Accept"), (accept_cb), _("Cancel"), (cancel_cb))
 
 /**
- * Displays a file selector request dialog.  Returns the selected filename into
+ * Displays a file selector request dialog.  Returns the selected filename to
  * the callback.  Can be used for either opening a file or saving a file.
  *
  * @param handle      The plugin or connection handle.  For some
  *                    things this is EXTREMELY important.  See
  *                    the comments on gaim_request_input.
- * @param title       The title for the dialog (may be NULL)
- * @param filename    The default filename (may be NULL)
+ * @param title       The title for the dialog (may be @c NULL)
+ * @param filename    The default filename (may be @c NULL)
  * @param savedialog  True if this dialog is being used to save a file.
  *                    False if it is being used to open a file.
- * @param ok_cb       The callback for the OK button.
- * @param cancel_cb   The callback for the cancel button.
+ * @param ok_cb       The callback for the @c OK button.
+ * @param cancel_cb   The callback for the @c Cancel button.
  * @param user_data   The data to pass to the callback.
  *
  * @return A UI-specific handle.
@@ -1371,6 +1375,25 @@
 						GCallback ok_cb, GCallback cancel_cb,
 						void *user_data);
 
+/**
+ * Displays a folder select dialog. Returns the selected filename to
+ * the callback.
+ *
+ * @param handle      The plugin or connection handle.  For some
+ *                    things this is EXTREMELY important.  See
+ *                    the comments on gaim_request_input.
+ * @param title       The title for the dialog (may be @c NULL)
+ * @param dirname     The default directory name (may be @c NULL)
+ * @param ok_cb       The callback for the @c OK button.
+ * @param cancel_cb   The callback for the @c Cancel button.
+ * @param user_data   The data to pass to the callback.
+ *
+ * @return A UI-specific handle.
+ */
+void *gaim_request_folder(void *handle, const char *title, const char *dirname,
+						  GCallback ok_cb, GCallback cancel_cb,
+						  void *user_data);
+
 /*@}*/
 
 /**************************************************************************/