reworked widget system a little. added more functions
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@743 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
@@ -369,7 +369,7 @@ return (GP_ERROR);
|
||||
|
||||
int camera_config_get (CameraWidget *window) {
|
||||
|
||||
CameraWidget *t, *page;
|
||||
CameraWidget *t, *section;
|
||||
int num;
|
||||
char buf[1024];
|
||||
|
||||
@@ -378,50 +378,32 @@ int camera_config_get (CameraWidget *window) {
|
||||
/* set the window label to something more specific */
|
||||
strcpy(window->label, "Fujitsu Camera Settings");
|
||||
|
||||
/* Create a new page for "Quality" */
|
||||
page = gp_widget_new(GP_WIDGET_PAGE, "Quality");
|
||||
gp_widget_append(window, page);
|
||||
/* Create a new section for "Quality" */
|
||||
section = gp_widget_new(GP_WIDGET_SECTION, "Quality");
|
||||
gp_widget_append(window, section);
|
||||
|
||||
/* Add the Resolution setting radio buttons */
|
||||
t = gp_widget_new(GP_WIDGET_RADIO, "Resolution");
|
||||
strcpy(t->choice, "Standard");
|
||||
gp_widget_append(page, t);
|
||||
gp_widget_choice_append(t, "Normal");
|
||||
gp_widget_choice_append(t, "High");
|
||||
gp_widget_choice_append(t, "Best");
|
||||
gp_widget_append(section, t);
|
||||
|
||||
t = gp_widget_new(GP_WIDGET_RADIO, "Resolution");
|
||||
strcpy(t->choice, "High");
|
||||
gp_widget_append(page, t);
|
||||
|
||||
t = gp_widget_new(GP_WIDGET_RADIO, "Resolution");
|
||||
strcpy(t->choice, "Best");
|
||||
gp_widget_append(page, t);
|
||||
|
||||
/* Create a new page for "Flash/Lens" and append to window */
|
||||
page = gp_widget_new(GP_WIDGET_PAGE, "Flash/Lens");
|
||||
gp_widget_append(window, page);
|
||||
/* Create a new section for "Flash/Lens" and append to window */
|
||||
section = gp_widget_new(GP_WIDGET_SECTION, "Flash/Lens");
|
||||
gp_widget_append(window, section);
|
||||
|
||||
t = gp_widget_new(GP_WIDGET_MENU, "Flash Setting");
|
||||
strcpy(t->choice, "Auto");
|
||||
gp_widget_append(page, t);
|
||||
|
||||
t = gp_widget_new(GP_WIDGET_MENU, "Flash Setting");
|
||||
strcpy(t->choice, "Red-eye");
|
||||
gp_widget_append(page, t);
|
||||
|
||||
t = gp_widget_new(GP_WIDGET_MENU, "Flash Setting");
|
||||
strcpy(t->choice, "Force");
|
||||
gp_widget_append(page, t);
|
||||
|
||||
t = gp_widget_new(GP_WIDGET_MENU, "Flash Setting");
|
||||
strcpy(t->choice, "None");
|
||||
gp_widget_append(page, t);
|
||||
gp_widget_choice_append(t, "Auto");
|
||||
gp_widget_choice_append(t, "Red-eye");
|
||||
gp_widget_choice_append(t, "Force");
|
||||
gp_widget_choice_append(t, "None");
|
||||
gp_widget_append(section, t);
|
||||
|
||||
t = gp_widget_new(GP_WIDGET_RADIO, "Lens Mode");
|
||||
strcpy(t->choice, "Normal");
|
||||
gp_widget_append(page, t);
|
||||
|
||||
t = gp_widget_new(GP_WIDGET_RADIO, "Lens Mode");
|
||||
strcpy(t->choice, "Macro");
|
||||
gp_widget_append(page, t);
|
||||
gp_widget_choice_append(t, "Normal");
|
||||
gp_widget_choice_append(t, "Macro");
|
||||
gp_widget_append(section, t);
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
@@ -960,43 +960,105 @@ void camera_delete_all() {
|
||||
camera_delete_common(1);
|
||||
}
|
||||
|
||||
void camera_configure_rec (CameraWidget *w, GtkWidget *page, GtkWidget *parent) {
|
||||
/*
|
||||
child_count = gp_widget_child_count(window);
|
||||
for (x=0; x<child_count; x++) {
|
||||
c = gp_widget_child(window, x);
|
||||
camera_configure_rec
|
||||
void camera_configure_rec (CameraWidget *w, GtkWidget *box, GtkWidget *window) {
|
||||
|
||||
GtkWidget *widget, *label, *hbox, *vbox, *notebook;
|
||||
GtkWidget *new_page=NULL;
|
||||
CameraWidget *c;
|
||||
GSList *group;
|
||||
int x, child_count;
|
||||
|
||||
switch(w->type) {
|
||||
case GP_WIDGET_WINDOW:
|
||||
/* do nothing. */
|
||||
break;
|
||||
case GP_WIDGET_SECTION:
|
||||
if ((notebook=gtk_object_get_data(GTK_OBJECT(window), "notebook"))==NULL) {
|
||||
notebook = gtk_notebook_new();
|
||||
gtk_widget_show(notebook);
|
||||
gtk_box_pack_start(GTK_BOX(box), notebook, FALSE, FALSE, 0);
|
||||
gtk_object_set_data(GTK_OBJECT(window), "notebook", notebook);
|
||||
}
|
||||
label = gtk_label_new(w->label);
|
||||
gtk_widget_show(label);
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
gtk_widget_show(vbox);
|
||||
box = vbox;
|
||||
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, label);
|
||||
break;
|
||||
case GP_WIDGET_TEXT:
|
||||
break;
|
||||
case GP_WIDGET_RANGE:
|
||||
break;
|
||||
case GP_WIDGET_TOGGLE:
|
||||
break;
|
||||
case GP_WIDGET_RADIO:
|
||||
break;
|
||||
case GP_WIDGET_MENU:
|
||||
break;
|
||||
case GP_WIDGET_BUTTON:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
child_count = gp_widget_child_count(w);
|
||||
printf("child_count=%i\n", child_count);
|
||||
for (x=0; x<child_count; x++) {
|
||||
c = gp_widget_child(w, x);
|
||||
camera_configure_rec(c, box, window);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void camera_configure() {
|
||||
|
||||
CameraWidget *w;
|
||||
GtkWidget *window;
|
||||
GSList *radio_list[256];
|
||||
int x, child_count;
|
||||
GtkWidget *window, *box, *ok, *cancel;
|
||||
|
||||
debug_print("camera configure");
|
||||
|
||||
if (!gp_gtk_camera_init)
|
||||
if (camera_set()==GP_ERROR) {return;}
|
||||
|
||||
/* Get the camera configuration widgets */
|
||||
w = gp_widget_new(GP_WIDGET_WINDOW, "Camera Configuration");
|
||||
|
||||
if (gp_config_get(w)==GP_ERROR) {
|
||||
gp_message("Could not retrieve camera configuration information");
|
||||
gp_widget_free(window);
|
||||
gp_widget_free(w);
|
||||
return;
|
||||
}
|
||||
|
||||
// if (gp_gtk_debug)
|
||||
gp_widget_dump(window);
|
||||
gp_widget_dump(w);
|
||||
|
||||
/* Create the GTK window */
|
||||
window = gtk_window_new(GTK_WINDOW_DIALOG);
|
||||
gtk_window_set_title(GTK_WINDOW(window), w->label);
|
||||
|
||||
camera_configure_rec(window, NULL, NULL);
|
||||
box = gtk_vbox_new(FALSE, 0);
|
||||
gtk_widget_show(box);
|
||||
gtk_container_add(GTK_CONTAINER(window), box);
|
||||
|
||||
gp_widget_free(window);
|
||||
ok = gtk_button_new_with_label("OK");
|
||||
gtk_widget_show(ok);
|
||||
|
||||
cancel = gtk_button_new_with_label("Cancel");
|
||||
gtk_widget_show(cancel);
|
||||
|
||||
/* Build the dialog */
|
||||
camera_configure_rec(w, box, window);
|
||||
|
||||
if (wait_for_hide(window, ok, NULL)==0) {
|
||||
gp_widget_free(w);
|
||||
return;
|
||||
}
|
||||
printf("gathering widget data\n");
|
||||
|
||||
/* Clean up and leave */
|
||||
gp_widget_free(w);
|
||||
gtk_widget_destroy(window);
|
||||
}
|
||||
|
||||
void camera_show_information() {
|
||||
|
||||
@@ -38,7 +38,7 @@ typedef enum {
|
||||
|
||||
typedef enum {
|
||||
GP_WIDGET_WINDOW,
|
||||
GP_WIDGET_PAGE,
|
||||
GP_WIDGET_SECTION,
|
||||
GP_WIDGET_TEXT,
|
||||
GP_WIDGET_RANGE,
|
||||
GP_WIDGET_TOGGLE,
|
||||
@@ -61,9 +61,9 @@ struct CameraWidget {
|
||||
char value_string[32];
|
||||
float value_number;
|
||||
|
||||
|
||||
/* For Radio and Menu */
|
||||
char choice[32];
|
||||
char choice[32][64];
|
||||
int choice_count;
|
||||
|
||||
/* For Range */
|
||||
float min;
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <gphoto2.h>
|
||||
|
||||
/* Create/free a widget */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
CameraWidget* gp_widget_new(CameraWidgetType type, char *label) {
|
||||
|
||||
CameraWidget *w;
|
||||
int x;
|
||||
|
||||
w = (CameraWidget*)malloc(sizeof(CameraWidget));
|
||||
memset(w, 0, sizeof(CameraWidget));
|
||||
@@ -16,9 +21,35 @@ CameraWidget* gp_widget_new(CameraWidgetType type, char *label) {
|
||||
memset(w->children, 0, sizeof(CameraWidget*)*64);
|
||||
w->children_count = 0;
|
||||
|
||||
for (x=0; x<32; x++)
|
||||
strcpy(w->choice[x], "");
|
||||
w->choice_count = 0;
|
||||
|
||||
return (w);
|
||||
}
|
||||
|
||||
int gp_widget_free(CameraWidget *widget) {
|
||||
/* Recursively delete the widget and all children */
|
||||
|
||||
int x;
|
||||
|
||||
if (widget->children_count == 0)
|
||||
return (GP_OK);
|
||||
|
||||
for (x=0; x<widget->children_count; x++) {
|
||||
gp_widget_free(widget->children[x]);
|
||||
free(widget->children[x]);
|
||||
}
|
||||
|
||||
free(widget);
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
|
||||
/* Attach widgets to a parent widget */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int gp_widget_append(CameraWidget *parent, CameraWidget *child) {
|
||||
|
||||
parent->children[parent->children_count] = child;
|
||||
@@ -52,28 +83,38 @@ CameraWidget* gp_widget_child(CameraWidget *parent, int child_number) {
|
||||
return (parent->children[child_number]);
|
||||
}
|
||||
|
||||
int gp_widget_free(CameraWidget *widget) {
|
||||
/* Recursively delete the widget and all children */
|
||||
/* Retrieve and set choices for menus/radio buttons */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int x;
|
||||
int gp_widget_choice_append(CameraWidget *widget, char *choice) {
|
||||
|
||||
if (widget->children_count == 0)
|
||||
return (GP_OK);
|
||||
|
||||
for (x=0; x<widget->children_count; x++) {
|
||||
gp_widget_free(widget->children[x]);
|
||||
free(widget->children[x]);
|
||||
}
|
||||
|
||||
free(widget);
|
||||
strncpy(widget->choice[widget->choice_count], choice, 64);
|
||||
widget->choice_count += 1;
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int gp_widget_choice_count(CameraWidget *widget) {
|
||||
|
||||
return (widget->choice_count);
|
||||
}
|
||||
|
||||
char *gp_widget_choice(CameraWidget *widget, int choice_number) {
|
||||
|
||||
if (choice_number > widget->choice_count)
|
||||
return NULL;
|
||||
|
||||
return (widget->choice[choice_number]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Debugging output */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void gp_widget_dump_rec (CameraWidget *widget, int depth) {
|
||||
|
||||
int x;
|
||||
char buf[1024];
|
||||
|
||||
printf("core: ");
|
||||
for (x=0; x<depth*2; x++)
|
||||
@@ -86,7 +127,7 @@ void gp_widget_dump_rec (CameraWidget *widget, int depth) {
|
||||
|
||||
int gp_widget_dump(CameraWidget *widget) {
|
||||
|
||||
printf("core: Dumping widget \"%s\" and children:", widget->label);
|
||||
printf("core: Dumping widget \"%s\" and children:\n", widget->label);
|
||||
gp_widget_dump_rec(widget, 0);
|
||||
|
||||
return (GP_OK);
|
||||
|
||||
Reference in New Issue
Block a user