コード例 #1
0
ファイル: prefs.c プロジェクト: BartMassey/gnome-inform7
void
on_style_remove_clicked(GtkButton *button, I7App *app)
{
	GtkTreeSelection *selection = gtk_tree_view_get_selection(app->prefs->schemes_view);
	GtkTreeModel *model;
	GtkTreeIter iter;
	if(gtk_tree_selection_get_selected(selection, &model, &iter)) {
		gchar *id;
		gchar *name;
		gtk_tree_model_get(model, &iter,
			ID_COLUMN, &id,
			NAME_COLUMN, &name,
			-1);

		if(!i7_app_uninstall_color_scheme(app, id))
			error_dialog(GTK_WINDOW(app->prefs->window), NULL, _("Could not remove color scheme \"%s\"."), name);
		else {
			gchar *new_id = NULL;
			GtkTreeIter new_iter;
			gboolean new_iter_set = FALSE;

			/* If the removed style scheme is the last of the list, set as new
			 default style scheme the previous one, otherwise set the next one.
			 To make this possible, we need to get the id of the new default
			 style scheme before re-populating the list. */
			GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
			/* Try to move to the next path */
			gtk_tree_path_next(path);
			if(!gtk_tree_model_get_iter(model, &new_iter, path)) {
				/* It seems the removed style scheme was the last of the list.
				 Try to move to the previous one */
				gtk_tree_path_free(path);
				path = gtk_tree_model_get_path(model, &iter);
				gtk_tree_path_prev(path);
				if(gtk_tree_model_get_iter(model, &new_iter, path))
					new_iter_set = TRUE;
			}
			else
				new_iter_set = TRUE;
			gtk_tree_path_free(path);

			if(new_iter_set)
				gtk_tree_model_get(model, &new_iter,
					ID_COLUMN, &new_id,
					-1);

			if(!new_id)
				new_id = g_strdup("inform");

			populate_schemes_list(app->prefs->schemes_list);

			I7App *theapp = i7_app_get();
			GSettings *prefs = i7_app_get_prefs(theapp);
			g_settings_set(prefs, PREFS_STYLE_SCHEME, new_id);

			g_free(new_id);
		}
		g_free(id);
		g_free(name);
	}
}
コード例 #2
0
/*
   ** fill out the rest of the image structure, given "number" already
 */
static struct Image *
SDSC_ReadImage (int picnum, int thumbnail)
{
  unsigned char buffer[2048];
  char str[1024];
  int len;
  int i;
  int blocks;

  struct Image *image = (struct Image *) malloc (sizeof (struct Image));
  byte *ptr;
  int left, size;

#ifdef DEBUG
  fprintf(stderr,"ReadImage \n");
#endif
  if (thumbnail)
    {
      free (image);
      return 0;
    }

  SDSC_disconnect (fd);         /*Rewind */

  i = picnum;
#ifdef DEBUG
  fprintf(stderr,"Fetching %d (%d,%d)\n",picnum,thumbnail);
#endif

  while (--i) 			/*Seek*/
    {
      sendcommand (SDSC_START);    
      len = receive (buffer, sizeof (buffer), SDSC_INFOSIZE);
      sendcommand (SDSC_NEXT);
    }

  sendcommand (SDSC_START);     /*Read out a header */
  len = receive (buffer, sizeof (buffer), SDSC_INFOSIZE);

  if (len != SDSC_INFOSIZE)
    {
      free (image);
      return 0;
    }

  buffer[SDSC_INFOSIZE] = 0;

  image->image_size = atoi (&buffer[15]);


  sprintf (str, "Length of image %d is %d bytes\n",
           picnum,
           image->image_size);
  update_status (str);

  blocks = (image->image_size + 0x3ff) / 0x400;
  blocks += 2;

  left = size = 0x400 * blocks;
  i = 0;

  ptr = image->image = (unsigned char *) malloc (size);

  if (!image->image)
    {
      error_dialog ("Failed to malloc image data.");
      free (image);
      return 0;
    }

  update_progress (0);

  sendcommand (SDSC_BINARY);    /*Put into image mode */
  sendcommand (SDSC_START);     /*Start reading */

  while (left > 0x400)
    {
      len = receive (buffer, sizeof (buffer), SDSC_BLOCKSIZE);

      if (!len)
        {
          free (image->image);
          free (image);
#ifdef DEBUG
  fprintf(stderr,"ReadImage failed \n");
#endif
          return 0;
        }

      if ((len == 1) && (buffer[1] == 0x4))
        break;

      bcopy (buffer + 3, ptr, 0x400);

      ptr += 0x400;
      left -= 0x400;
      i += 0x400;

      if (size)
	      update_progress (100 * i / size);

      sendcommand (SDSC_BINARY);  /*Next block */
    }


  SDSC_disconnect (fd);         /*Rewind */

  strcpy (image->image_type, "jpg");
  image->image_info_size = 0;
#ifdef DEBUG
  fprintf(stderr,"Done ReadImage \n");
#endif

  return image;
}
コード例 #3
0
ファイル: read_param.c プロジェクト: dschwen/MCERD
/* Read all parameters from the files */
void read_param(char *file_name)
{
   FILE *fp;
   char buf[MAXLEN],*c,*word;
   TextLine *line;
   double number;
   int i,n,rinput[NINPUT];
   
   for(i=0;i<NINPUT;i++)
      rinput[i] = FALSE; 
   
   error = 0;

   line = NULL;

   fp = fopen(file_name,"r");
      if(fp == NULL){
         error_dialog_open(file_name);
         return;
      }

   while(fgets(buf,MAXLEN,fp)!=NULL){
      i = 0;
      while(i<NINPUT && (c=strstr(buf,inlines[i]))==NULL)
         i++;
      
      if(i<NINPUT){
         c += strlen(inlines[i]);
         c = trim_space(c);
      }

      switch(i){
         case I_TYPE:
            if(c != NULL && strcmp(c, "")){
               word = get_word(c,&n);  /* we should free word-memory also! */
               if(strcmp(word,"ERD") == 0)
                  sim_type = SIM_ERD;
               else if(strcmp(word,"RBS") == 0)
                  sim_type = SIM_RBS;
 	           else{
 	              sim_type = SIM_ERD;
                  error = 1;
               }
               free(word);
            }
            else{
               sim_type = SIM_ERD;
               error = 1;
            }
            break;
         case  I_ION:
            if(c != NULL){
	      if(strcmp(c, "")){
                 c = get_string(c);
                 beam_ion = c;
	      }
	      else
	         beam_ion = "";
            }
            else{
               beam_ion = "";
               error = 1;
            }
            break;
         case  I_ENERGY:
            if(c != NULL && strcmp(c, "")){
               c = get_number(c,&number);
               beam_energy = number;
            }
            else{
               beam_energy = 0;
               error = 1;
            }
            break;
         case  I_RECOIL:
            if(c != NULL){
               if(strcmp(c, "")){
                  c = get_string(c);
                  recoil_atom = c;
	       }
	       else
	          recoil_atom = "";
            }
            else{
               recoil_atom = "";
               error = 1;
            }
            break;
         case I_TANGLE:
            if(c != NULL && strcmp(c, "")){
               c = get_number(c,&number);
               target_angle = number;
            }
            else{
               target_angle = 0;
               error = 1;
            }
            break;
         case I_SPOTSIZE:
            if(c != NULL && strcmp(c, "")){
               c = get_number(c,&number);
               beam_size_x = number;
            }
            else{
               beam_size_x = 0;
               error = 1;
            }
            if(c != NULL && strcmp(c, "")){
               c = get_number(c,&number);
               beam_size_y = number;
            }
            else{
               beam_size_y = 0;
               error = 1;
            }
            break;
         case I_MINANGLE:
            if(c != NULL && strcmp(c, "")){
               c = get_number(c,&number);
               min_angle = number;
            }
            else{
               min_angle = 0;
               error = 1;
            }
            break;
         case I_MINENERGY:
            if(c != NULL && strcmp(c, "")){
               c = get_number(c,&number);
               min_energy = number;
            }
            else{
               min_energy = 0;
               error = 1;
            }
            break;
         case I_NIONS:
            if(c != NULL && strcmp(c, "")){
               c = get_number(c,&number);
               nions = number;
            }
            else{
               nions = 0;
               error = 1;
            }
            break;
         case I_NPREIONS:
            if(c != NULL && strcmp(c, "")){
               c = get_number(c,&number);
               nions_presim = number;
            }
            else{
               nions_presim = 0;
               error = 1;
            }
            break;
         case I_RECAVE:
            if(c != NULL && strcmp(c, "")){
               c = get_number(c,&number);
               aver_nions = number;
            }
            else{
               aver_nions = 0;
               error = 1;
            }
            break;
         case I_SEED:
            if(c != NULL && strcmp(c, "")){
               c = get_number(c,&number);
               nseed = number;
            }
            else{
               nseed = 0;
               error = 1;
            }
            break;
         case I_RECWIDTH:
            if(c != NULL && strcmp(c, "")){
               word = get_word(c,&n);
               if(strcmp(word,"wide") == 0 || strcmp(word,"WIDE") == 0)
                  angle_width = REC_WIDE;
               else if(strcmp(word,"narrow") == 0 || strcmp(word,"NARROW") == 0)
                  angle_width = REC_NARROW;
               else{
                  angle_width = REC_NARROW;
                  error = 1;
               }
               free(word);
            }
            else{
               angle_width = REC_NARROW;
               error = 1;
            }
            break;
         default:
            break;
      }
   }
   
   read_target_file(file_name, TYPE_TARGET);
   read_target_file(file_name, TYPE_FOIL);
   read_detector_file(file_name);
   read_rdist_file(file_name);
   read_presimu_file(file_name);
   read_espe_params_file(file_name);

  /* If error occurs somewhere */
  if(error)
    error_dialog("Problems with reading the data");
    
  fclose(fp);
  
  /* Clean "memory" */
  format_layers(nlayers);
  format_foils(nfoils);
    
  saved = 1;
}
コード例 #4
0
ファイル: main.c プロジェクト: Tetralet/LilyTerm
// it will return TRUE if succeed
gboolean convert_string_to_socket_data(gchar *socket_str)
{
#ifdef DETAIL
	g_debug("! Launch convert_string_to_socket_data() with socket_str = %s", socket_str);
#endif
	//	     0			 1     2	   3	    4		5   6	 7		   8		9	      10      11
	// get data: SOCKET_DATA_VERSION SHELL LOCALE_LIST ENCODING LC_MESSAGES PWD HOME VTE_CJK_WIDTH_STR wmclass_name wmclass_class ENVIRON ARGV

	gchar **datas = split_string(socket_str, SEPARATE_STR, 12);
	// g_debug("The SOCKET_DATA_VERSION = %s ,and the data sent via socket is %s",
	//	   SOCKET_DATA_VERSION, datas[0]);

	if (datas==NULL)
	{
		// A dirty hack for sometimes the received socket datas is empty.
		g_warning("Got a NULL string from the socket!");
		new_window(0,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   FALSE,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   FALSE,
			   NULL,
			   NULL,
			   NULL);
	}
	else if (compare_strings(SOCKET_DATA_VERSION, datas[0], TRUE))
	{
		// The SOCKET_DATA_VERSION != the data sent via socket
		gchar *received_socket_version = NULL;
		if (datas) received_socket_version = datas[0];

		gchar *message = g_strdup_printf(_("The data got from socket seems incorrect.\n\n"
						   "\tReceived socket version: %s\n"
						   "\tExpected socket version: %s\n\n"
						   "If you just updated %s recently,\n"
						   "Please close all the windows of %s and try again."),
						   received_socket_version, SOCKET_DATA_VERSION,
						   PACKAGE, PACKAGE);
		error_dialog(NULL,
			     _("The format of socket data is out of date"),
			     "The format of socket data is out of date",
			     GTK_FAKE_STOCK_DIALOG_ERROR,
			     message,
			     NULL);
		g_free(message);
	}
	else
	{
		// g_debug("datas[11] = %s", datas[11]);
		gchar **argv = split_string(datas[11], SEPARATE_STR, -1);
		gint argc = 0;
		if (argv)
			while (argv[argc])
				argc ++;

		// g_debug("Final:");
		// g_debug("\targc =%d", argc);
		// print_array("\targv", argv);
		// g_debug("\tSHELL = %s", datas[1]);
		// g_debug("\tenvironments = %s", datas[10]);
		// g_debug("\tlocale_list = %s", datas[2]);
		// g_debug("\tPWD = %s", datas[5]);
		// g_debug("\tHOME = %s", datas[6]);
		// g_debug("\tVTE_CJK_WIDTH_STR = %s", datas[7]);
		// g_debug("\twmclass_name = %s", datas[8]);
		// g_debug("\twmclass_class= %s", datas[9]);
		// g_debug("\tencoding = %s", datas[3]);
		// g_debug("\tlc_messages = %s", datas[4]);

		//GtkNotebook *new_window(int argc,
		//			char *argv[],
		//			gchar *shell,					// 1
		//			gchar *environment,				// 10
		//			gchar *locale_list,				// 2
		//			gchar *PWD,					// 5
		//			gchar *HOME,					// 6
		//			gchar *VTE_CJK_WIDTH_STR,			// 7
		//			gboolean VTE_CJK_WIDTH_STR_overwrite_profile,
		//			gchar *wmclass_name,				// 8
		//			gchar *wmclass_class,				// 9
		//			gchar *user_environ,
		//			gchar *encoding,				// 3
		//			gboolean encoding_overwrite_profile,
		//			gchar *lc_messages,				// 4
		//			struct Window *win_data_orig,
		//			struct Page *page_data_orig)

		if ((new_window(argc,
				argv,
				datas[1],
				datas[10],
				datas[2],
				datas[5],
				datas[6],
				datas[7],
				FALSE,
				datas[8],
				datas[9],
				NULL,
				datas[3],
				FALSE,
				datas[4],
				NULL,
				NULL) == NULL && (g_list_length(window_list) == 0)))
			// Sometimes, new_window() will return NULL. Therefore LilyTerm may should quit.
			quit_gtk();
		// g_debug("main(3): gtk_main_level = %d, g_list_length(window_list) = %d", gtk_main_level(), g_list_length(window_list));
		g_strfreev(argv);
	}
	g_strfreev(datas);

	// return FALSE means this connection is finish.
	return FALSE;
}
コード例 #5
0
ファイル: main.c プロジェクト: ajbogh/Camorite
int
main(int argc, char *argv[]) {
    cam cam_object, *cam;
    Display *display;
    Screen *screen_num;
    gchar *poopoo = NULL;
    gchar *pixfilename = "camorama/camorama.png";
    gchar *filename;            //= "/usr/opt/garnome/share/camorama/camorama.glade";
    int x = -1, y = -1;
    gboolean buggery = FALSE;
    GtkWidget *button;
    GConfClient *gc;

    const struct poptOption popt_options[] = {
        {"version", 'V', POPT_ARG_NONE, &ver, 0,
         N_("show version and exit"), NULL},
        {"device", 'd', POPT_ARG_STRING, &poopoo, 0,
         N_("v4l device to use"), NULL},
        {"debug", 'D', POPT_ARG_NONE, &buggery, 0,
         N_("enable debugging code"), NULL},
        {"width", 'x', POPT_ARG_INT, &x, 0, N_("capture width"),
         NULL},
        {"height", 'y', POPT_ARG_INT, &y, 0, N_("capture height"),
         NULL},
        {"max", 'M', POPT_ARG_NONE, &max, 0,
         N_("maximum capture size"), NULL},
        {"min", 'm', POPT_ARG_NONE, &min, 0,
         N_("minimum capture size"), NULL},
        {"half", 'H', POPT_ARG_NONE, &half, 0,
         N_("middle capture size"), NULL},
        {"read", 'R', POPT_ARG_NONE, &use_read, 0,
         N_("use read() rather than mmap()"), NULL},
        POPT_TABLEEND
    };

    cam = &cam_object;
    /* set some default values */
    cam->frame_number = 0;
    cam->pic = NULL;
    cam->pixmap = NULL;
    cam->size = PICHALF;
    cam->video_dev = NULL;
    cam->read = FALSE;

    bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);
    setlocale (LC_ALL, "");

    /* gnome_program_init  - initialize everything (gconf, threads, etc) */
    gnome_program_init (PACKAGE_NAME, PACKAGE_VERSION, LIBGNOMEUI_MODULE, argc, argv,
                        GNOME_PARAM_APP_DATADIR, PACKAGE_DATA_DIR,
                        GNOME_PARAM_POPT_TABLE, popt_options,
                        GNOME_PARAM_HUMAN_READABLE_NAME, _("camorama"), NULL);

    /* gtk is initialized now */
    camorama_stock_init();
    camorama_filters_init();

    cam->debug = buggery;

	cam->x = x;
	cam->y = y;
	glade_gnome_init ();
	glade_set_custom_handler (camorama_glade_handler,
				  cam);


    if (ver) {
        fprintf (stderr, _("\n\nCamorama version %s\n\n"), VERSION);
        exit (0);
    }
    if (max) {
        cam->size = PICMAX;
    }
    if (min) {
        cam->size = PICMIN;
    }
    if (half) {
        cam->size = PICHALF;
    }
    if (use_read) {
        printf ("gah!\n");
        cam->read = TRUE;
    }
    gc = gconf_client_get_default ();
    cam->gc = gc;

    gconf_client_add_dir (cam->gc, PATH, GCONF_CLIENT_PRELOAD_NONE, NULL);
    gconf_client_notify_add (cam->gc, KEY1, (void *) gconf_notify_func,
                             cam->pixdir, NULL, NULL);
    gconf_client_notify_add (cam->gc, KEY5, (void *) gconf_notify_func,
                             cam->rhost, NULL, NULL);
    gconf_client_notify_add (cam->gc, KEY2, (void *) gconf_notify_func,
                             cam->capturefile, NULL, NULL);
    gconf_client_notify_add (cam->gc, KEY3,
                             (void *) gconf_notify_func_int,
                             GINT_TO_POINTER (cam->savetype), NULL, NULL);
    gconf_client_notify_add (cam->gc, KEY4,
                             (void *) gconf_notify_func_bool,
                             &cam->timestamp, NULL, NULL);

    if (!poopoo) {
	gchar const* gconf_device = gconf_client_get_string(cam->gc, KEY_DEVICE, NULL);
	if(gconf_device) {
		cam->video_dev = g_strdup(gconf_device);
	} else {
		cam->video_dev = g_strdup ("/dev/video0");
	}
    } else {
        cam->video_dev = g_strdup (poopoo);
    }

    cam->pixdir = g_strdup (gconf_client_get_string (cam->gc, KEY1, NULL));
    cam->capturefile =
        g_strdup (gconf_client_get_string (cam->gc, KEY2, NULL));
    cam->rhost = g_strdup (gconf_client_get_string (cam->gc, KEY5, NULL));
    cam->rlogin = g_strdup (gconf_client_get_string (cam->gc, KEY6, NULL));
    cam->rpw = g_strdup (gconf_client_get_string (cam->gc, KEY7, NULL));
    cam->rpixdir = g_strdup (gconf_client_get_string (cam->gc, KEY8, NULL));
    cam->rcapturefile =
        g_strdup (gconf_client_get_string (cam->gc, KEY9, NULL));
    cam->savetype = gconf_client_get_int (cam->gc, KEY3, NULL);
    cam->rsavetype = gconf_client_get_int (cam->gc, KEY10, NULL);
    cam->ts_string =
        g_strdup (gconf_client_get_string (cam->gc, KEY16, NULL));
    cam->date_format = "%Y-%m-%d %H:%M:%S";
    cam->timestamp = gconf_client_get_bool (cam->gc, KEY4, NULL);
    cam->rtimestamp = gconf_client_get_bool (cam->gc, KEY11, NULL);

    cam->cap = gconf_client_get_bool (cam->gc, KEY12, NULL);
    cam->rcap = gconf_client_get_bool (cam->gc, KEY13, NULL);
    cam->timefn = gconf_client_get_bool (cam->gc, KEY14, NULL);
    cam->rtimefn = gconf_client_get_bool (cam->gc, KEY15, NULL);
    cam->usestring = gconf_client_get_bool (cam->gc, KEY18, NULL);
    cam->usedate = gconf_client_get_bool (cam->gc, KEY19, NULL);
    cam->acap = gconf_client_get_bool (cam->gc, KEY20, NULL);
    cam->timeout_interval = gconf_client_get_int (cam->gc, KEY21, NULL);
    cam->show_adjustments = gconf_client_get_bool (cam->gc, KEY22, NULL);
	 cam->show_effects = gconf_client_get_bool (cam->gc, KEY23, NULL);


    /* get desktop depth */
    display = (Display *) gdk_x11_get_default_xdisplay ();
    screen_num = xlib_rgb_get_screen ();
    gdk_pixbuf_xlib_init (display, 0);
    cam->desk_depth = xlib_rgb_get_depth ();

    cam->dev = open (cam->video_dev, O_RDWR);

    camera_cap (cam);
    get_win_info (cam);

    /* query/set window attributes */
    cam->vid_win.x = 0;
    cam->vid_win.y = 0;
    cam->vid_win.width = cam->x;
    cam->vid_win.height = cam->y;
    cam->vid_win.chromakey = 0;
    cam->vid_win.flags = 0;

    set_win_info (cam);
    get_win_info (cam);

    /* get picture attributes */
    get_pic_info (cam);
//	set_pic_info(cam);
    /* set_pic_info(cam); */
    cam->contrast = cam->vid_pic.contrast;
    cam->brightness = cam->vid_pic.brightness;
    cam->colour = cam->vid_pic.colour;
    cam->hue = cam->vid_pic.hue;
    cam->wb = cam->vid_pic.whiteness;
    cam->depth = cam->vid_pic.depth / 8;
    cam->pic_buf = malloc (cam->x * cam->y * cam->depth);
    cam->tmp =
        malloc (cam->vid_cap.maxwidth * cam->vid_cap.maxheight * cam->depth);
    //cam->tmp = NULL;
    /* set the buffer size */
    if (cam->read == FALSE) {
        set_buffer (cam);
    }
    //cam->read = FALSE;
    /* initialize cam and create the window */

    if (cam->read == FALSE) {
        pt2Function = timeout_func;
        init_cam (NULL, cam);
    } else {
        printf ("using read()\n");
        cam->pic =
            realloc (cam->pic,
                     (cam->vid_cap.maxwidth * cam->vid_cap.maxheight * 3));
        pt2Function = read_timeout_func;
    }
    cam->pixmap = gdk_pixmap_new (NULL, cam->x, cam->y, cam->desk_depth);

    filename =
        gnome_program_locate_file (NULL,
                                   GNOME_FILE_DOMAIN_APP_DATADIR,
                                   "camorama/camorama.glade", TRUE, NULL);
    if (filename == NULL) {
        error_dialog (_
                      ("Couldn't find the main interface file (camorama.glade)."));
        exit (1);
    }

    //pixfilename = gnome_program_locate_file(NULL, GNOME_FILE_DOMAIN_APP_DATADIR, "pixmaps/camorama.png", TRUE, NULL);
    //printf("pixfile = %s\n",pixfilename);
    //pixfilename);
    //printf("pixfile = %s\n",pixfilename);
    cam->xml = glade_xml_new (filename, NULL, NULL);
    /*eggtray */

    /*tray_icon = egg_tray_icon_new ("Our other cool tray icon");
     * button = gtk_button_new_with_label ("This is a another\ncool tray icon");
     * g_signal_connect (button, "clicked",
     * G_CALLBACK (second_button_pressed), tray_icon);
     * 
     * gtk_container_add (GTK_CONTAINER (tray_icon), button);
     * gtk_widget_show_all (GTK_WIDGET (tray_icon)); */
    load_interface (cam);

    cam->idle_id = gtk_idle_add ((GSourceFunc) pt2Function, (gpointer) cam);

    gtk_timeout_add (2000, (GSourceFunc) fps, cam->status);
    gtk_main ();
    return 0;
}
コード例 #6
0
static void
view_edit (WDiff *view, int ord)
{
    /* XXX */
    error_dialog(_("Edit"), _(" Edit not yet implemented "));
}
コード例 #7
0
/* Finish up the user's Export iFiction Record command. This is a callback and
 the GDK lock is held when entering this function. */
void
i7_story_save_ifiction(I7Story *story)
{
    /* Work out where the file should be */
    GFile *project_file = i7_document_get_file(I7_DOCUMENT(story));
    if(project_file == NULL) {
        g_warning("Tried to save iFiction record of story without associated file");
        return; /* This shouldn't happen because the file is saved before compilation */
    }
    GFile *ifiction_file = g_file_get_child(project_file, "Metadata.iFiction");

    /* Prompt user to save iFiction file if it exists */
    if(g_file_query_exists(ifiction_file, NULL))
    {
        /* Make a file filter */
        GtkFileFilter *filter = gtk_file_filter_new();
        gtk_file_filter_set_name(filter, _("iFiction records (.iFiction)"));
        gtk_file_filter_add_pattern(filter, "*.iFiction");

        /* Make up a default file name */
        gchar *name = i7_document_get_display_name(I7_DOCUMENT(story));
        /* project_file is not NULL so neither is name */
        *(strrchr(name, '.')) = '\0';
        gchar *filename = g_strconcat(name, ".iFiction", NULL);
        g_free(name);

        /* Create a file chooser */
        GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Save iFiction record"),
                            GTK_WINDOW(story), GTK_FILE_CHOOSER_ACTION_SAVE,
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
                            NULL);
        gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
        gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
        g_free(filename);

        GFile *parent_file = g_file_get_parent(project_file);
        /* Ignore error */
        gtk_file_chooser_set_current_folder_file(GTK_FILE_CHOOSER(dialog), parent_file, NULL);
        g_object_unref(parent_file);

        gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);

        /* Copy the finished file to the chosen location */
        if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
            GFile *dest_file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(dialog));
            GError *error = NULL;

            if(!g_file_copy(ifiction_file, dest_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) {
                IO_ERROR_DIALOG(GTK_WINDOW(story), dest_file, error, _("copying iFiction record"));
            }

            g_object_unref(dest_file);
        }
        gtk_widget_destroy(dialog);
    }
    else
        error_dialog(GTK_WINDOW(story), NULL,
                     _("The compiler failed to create an iFiction record; check the "
                       "results page to see why."));

    g_object_unref(ifiction_file);
    g_object_unref(project_file);
}
コード例 #8
0
int philips_configure () {


    struct	P_CONFIG_CONTROLS	controls;
    PhilipsCfgInfo	*pcfginfo;
    int			error;
    GtkWidget	*dialog;
    GtkWidget	*notebook;
    GtkWidget	*button;

    char		*info, title[128];

    /* initialize camera and grab configuration information */

    if (philips_open_camera() == 0) {
        error_dialog ( "Could not open camera." );
        return 0;
    }

    if ( (pcfginfo = philips_getcfginfo ( &error )) == NULL ) {
        error_dialog ( "Can't get camera configuration." );
        philips_close_camera();
        return ( 0 );
    }
    philips_close_camera();

    update_progress(12);

    sprintf ( title, "Configure Camera %s", philips_model(cameraid) );
    info = (char *)malloc(2048);

    /* create a new dialog box */
    dialog = gtk_dialog_new();
    gtk_window_set_title (GTK_WINDOW(dialog), title);
    gtk_container_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 10);

    /* create a new notebook, place the position of the tabs */
    notebook = gtk_notebook_new ();
    gtk_notebook_set_tab_pos ( GTK_NOTEBOOK(notebook), GTK_POS_TOP );
    gtk_widget_show ( notebook );
    gtk_container_add ( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), notebook );

    /* add a page to the notebook */
    philips_cfg_page1 ( notebook, &controls, pcfginfo );
    update_progress(25);
    philips_cfg_page2 ( notebook, &controls, pcfginfo );
    update_progress(50);
    philips_cfg_page3 ( notebook, &controls, pcfginfo );
    update_progress(75);
    philips_cfg_page4 ( notebook, &controls, pcfginfo );


    /* create an OK button */
    button = gtk_button_new_with_label ( " OK " );
    gtk_signal_connect_object ( GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(dialog) );

    gtk_box_pack_end ( GTK_BOX(GTK_DIALOG(dialog)->action_area), button, TRUE, FALSE, 0 );
    gtk_widget_show ( button );

    /* create a Cancel button */
    button = gtk_button_new_with_label ( " Cancel " );
    gtk_signal_connect_object ( GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(dialog) );
    gtk_box_pack_end ( GTK_BOX(GTK_DIALOG(dialog)->action_area), button, TRUE, FALSE, 0 );
    gtk_widget_show ( button );

    update_progress(100);

    gtk_widget_show ( dialog );
    update_status ( "Done." );
    update_progress ( 0 );

    while (GTK_WIDGET_VISIBLE(dialog))
        gtk_main_iteration();

    /*
    	if (strcmp("Cancel", (char*)gtk_object_get_data(GTK_OBJECT(dialog), "button"))==0) {
    		printf ( "Cancel button pressed, return 1\n" );
            return 1;
    		}
    */

    printf ( "Done with config, return 1\n" );
    return 1;
}
コード例 #9
0
ファイル: gui.c プロジェクト: MufriA/stoken
static int do_password_dialog(struct securid_token *t)
{
	GtkWidget *dialog;
	GtkWidget *pass_entry = NULL, *pin_entry = NULL;
	gint resp;
	int rc, pass_required = 0, pin_required = 0;

	if (securid_pass_required(t)) {
		pass_required = 1;
		if (opt_password) {
			rc = securid_decrypt_seed(t, opt_password, NULL);
			if (rc == ERR_DECRYPT_FAILED)
				warn("warning: --password parameter is incorrect\n");
			else if (rc != ERR_NONE)
				error_dialog("Token decrypt error",
					stoken_errstr[rc]);
			else
				pass_required = 0;
		}
	} else {
		rc = securid_decrypt_seed(t, opt_password, NULL);
		if (rc != ERR_NONE)
			error_dialog("Token decrypt error", stoken_errstr[rc]);
	}

	if (securid_pin_required(t)) {
		pin_required = 1;
		if (opt_pin) {
			if (securid_pin_format_ok(opt_pin) == ERR_NONE) {
				xstrncpy(t->pin, opt_pin, MAX_PIN + 1);
				pin_required = 0;
			} else
				warn("warning: --pin argument is invalid\n");
		} else if (strlen(t->pin) || t->enc_pin_str)
			pin_required = 0;
	}

	if (!pin_required && !pass_required)
		return ERR_NONE;

	if (pass_required)
		pass_entry = gtk_entry_new();
	if (pin_required)
		pin_entry = gtk_entry_new();

	create_password_dialog(&dialog, pass_entry, pin_entry);

	while (1) {
		const char *pass = NULL, *pin = NULL;

		resp = gtk_dialog_run(GTK_DIALOG(dialog));
		if (resp != GTK_RESPONSE_ACCEPT) {
			gtk_widget_destroy(dialog);
			return 1;
		}

		if (pass_required) {
			pass = gtk_entry_get_text(GTK_ENTRY(pass_entry));
			rc = securid_decrypt_seed(current_token, pass, NULL);
			if (rc == ERR_DECRYPT_FAILED) {
				warning_dialog(dialog, "Bad password",
					"Please enter the correct password for this seed.");
				continue;
			} else if (rc != ERR_NONE)
				error_dialog("Token decrypt error",
					stoken_errstr[rc]);
		}

		if (t->enc_pin_str) {
			rc = securid_decrypt_pin(t->enc_pin_str, pass, t->pin);
			if (rc != ERR_NONE)
				error_dialog("PIN decrypt error",
					stoken_errstr[rc]);
		}

		if (pin_required) {
			pin = gtk_entry_get_text(GTK_ENTRY(pin_entry));
			if (securid_pin_format_ok(pin) != ERR_NONE) {
				warning_dialog(dialog, "Bad PIN",
					"Please enter 4-8 digits, or '0000' to skip.");
				continue;
			}
			xstrncpy(t->pin, pin, MAX_PIN + 1);
		}
		break;
	}
	gtk_widget_destroy(dialog);

	return ERR_NONE;
}
コード例 #10
0
ファイル: main.c プロジェクト: ChunHungLiu/LilyTerm
// it will return TRUE if succeed
gboolean read_socket(GIOChannel *channel, GIOCondition condition, gpointer user_data)
{
#ifdef DETAIL
	g_debug("! Launch read_socket() to read data !");
#endif
#ifdef SAFEMODE
	if (channel==NULL) return FALSE;
#endif

	GError *error = NULL;
	gchar *data = NULL, **datas;
	gsize len = 0;
	gsize term;

	if (g_io_channel_read_line (channel, &data, &len, &term, &error) == G_IO_STATUS_ERROR)
		return socket_fault(7, error, channel, TRUE);
	// g_debug("Read %ld bytes from Lilyterm socket: '%s'", len, data);
	if (len > 0)
	{
		//	     0			 1     2	   3	    4		5   6	 7		   8		9	      10      11
		// get data: SOCKET_DATA_VERSION SHELL LOCALE_LIST ENCODING LC_MESSAGES PWD HOME VTE_CJK_WIDTH_STR wmclass_name wmclass_class ENVIRON ARGV
		// clear '\n' at the end of data[]
		data[len-1] = 0;

		datas = split_string(data, "\x10", 12);
		// g_debug("The SOCKET_DATA_VERSION = %s ,and the data sent via socket is %s",
		//	   SOCKET_DATA_VERSION, datas[0]);

		if (datas==NULL)
		{
			// A dirty hack for sometimes the received socket datas is empty.
			socket_fault(14, NULL, NULL, FALSE);
			new_window(0,
				   NULL,
				   NULL,
				   NULL,
				   NULL,
				   NULL,
				   NULL,
				   NULL,
				   FALSE,
				   NULL,
				   NULL,
				   NULL,
				   NULL,
				   FALSE,
				   NULL,
				   NULL,
				   NULL);
		}
		else if (compare_strings(SOCKET_DATA_VERSION, datas[0], TRUE))
		{
			// The SOCKET_DATA_VERSION != the data sent via socket
			gchar *received_socket_version = NULL;
			if (datas) received_socket_version = datas[0];

			gchar *message = g_strdup_printf(_("The data got from socket seems incorrect.\n\n"
							   "\tReceived socket version: %s\n"
							   "\tExpected socket version: %s\n\n"
							   "If you just updated %s recently,\n"
							   "Please close all the windows of %s and try again."),
							   received_socket_version, SOCKET_DATA_VERSION,
							   PACKAGE, PACKAGE);
			error_dialog(NULL,
				     _("The format of socket data is out of date"),
				     "The format of socket data is out of date",
				     GTK_FAKE_STOCK_DIALOG_ERROR,
				     message,
				     NULL);
			g_free(message);
		}
		else
		{
			gchar **argv = split_string(datas[11], "\x10", -1);
			gint argc = 0;
			if (argv)
				while (argv[argc])
					argc ++;

			// g_debug("Final:");
			// g_debug("\targc =%d", argc);
			// print_array("\targv", argv);
			// g_debug("\tSHELL = %s", datas[1]);
			// g_debug("\tenvironments = %s", datas[10]);
			// g_debug("\tlocale_list = %s", datas[2]);
			// g_debug("\tPWD = %s", datas[5]);
			// g_debug("\tHOME = %s", datas[6]);
			// g_debug("\tVTE_CJK_WIDTH_STR = %s", datas[7]);
			// g_debug("\twmclass_name = %s", datas[8]);
			// g_debug("\twmclass_class= %s", datas[9]);
			// g_debug("\tencoding = %s", datas[3]);
			// g_debug("\tlc_messages = %s", datas[4]);

			//GtkNotebook *new_window(int argc,
			//			char *argv[],
			//			gchar *shell,					// 1
			//			gchar *environment,				// 10
			//			gchar *locale_list,				// 2
			//			gchar *PWD,					// 5
			//			gchar *HOME,					// 6
			//			gchar *VTE_CJK_WIDTH_STR,			// 7
			//			gboolean VTE_CJK_WIDTH_STR_overwrite_profile,
			//			gchar *wmclass_name,				// 8
			//			gchar *wmclass_class,				// 9
			//			gchar *user_environ,
			//			gchar *encoding,				// 3
			//			gboolean encoding_overwrite_profile,
			//			gchar *lc_messages,				// 4
			//			struct Window *win_data_orig,
			//			struct Page *page_data_orig)

			new_window(argc,
				   argv,
				   datas[1],
				   datas[10],
				   datas[2],
				   datas[5],
				   datas[6],
				   datas[7],
				   FALSE,
				   datas[8],
				   datas[9],
				   NULL,
				   datas[3],
				   FALSE,
				   datas[4],
				   NULL,
				   NULL);
			g_strfreev(argv);
		}
		g_strfreev(datas);
		data[len-1] = '\n';
		g_free(data);
	}
	clear_channel(channel, TRUE);
	// return FALSE means this connection is finish.
	return FALSE;
}
コード例 #11
0
ファイル: network.c プロジェクト: ElFeesho/OldCProjects
gboolean network_receive(GIOChannel *source, GIOCondition condition, gpointer data)
{
	/* Primarily, we'll only be reading in a small amount of info */
	if(log_level == 0)
	{
		if((condition&G_IO_HUP)==G_IO_HUP)
		{
			return FALSE;
		}
		if((condition&G_IO_IN) == G_IO_IN)
		{
			GIOError error = G_IO_ERROR_NONE;
			char data = 0;
			unsigned int offset = 0;
			char message[1024] = { '\0' };
			gsize n = 1;
			while(data!='\n')
			{
				error = gnet_io_channel_readn(msn_channel, &data, n, &n); 
				if(n == 0)
				{
					return FALSE;
				}
				if (error != G_IO_ERROR_NONE) 
				{
					error_dialog("Error receiving network data!");
					return FALSE;
				}
				message[offset++] = data;
			}
			printf("Received: %s\n",message);
			/*
				TODO: action to take
			*/
			if(strncmp(message, "VER",3)==0)
			{
				/* Got a response from VER, time to send CVR */
				char *tmp_message = g_strdup_printf("CVR 2 0x0c0a winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs %s\r\n",uemail);
				net_send(tmp_message);
				g_free(tmp_message);
			}
			else if(strncmp(message, "CVR", 3) == 0)
			{
				/* Got a response from CVR, time to send USR */
				char *tmp_message = g_strdup_printf("USR 3 TWN I %s\r\n",uemail);
				net_send(tmp_message);
				g_free(tmp_message);
			}
			else if(strncmp(message, "XFR", 3) == 0)
			{
				/* The tricky part... */
				log_level = 1;

				/*
					Now we close our socket, and point it at the ip given to us in the XFR message

					Sample specimen

					XFR 3 NS 207.46.108.91:1863 0 65.54.239.210:1863

				*/

				char *ip_start = strstr(message, "NS ");
				/* Skip past the "NS " */
				ip_start+=3;

				/* Find the splitter, " 0 " */
				char *ip_end = strstr(ip_start, " 0 ");
				ip_end[0] = '\0';

				char *ip_port_split = strstr(ip_start, ":");
				ip_port_split[0] = '\0';

				/* Voila */
				printf("IP: %s\n",ip_start);
				gnet_tcp_socket_delete(msn_socket);
				
				GInetAddr* addr;
				addr = gnet_inetaddr_new(ip_start, 1863);
				if(addr)
				{
					msn_socket = gnet_tcp_socket_new(addr);
					gnet_inetaddr_delete(addr);
				}
				else
				{
					error_dialog("Failed to resolve messenger.msn.com");
					return;
				}
	
				msn_channel = gnet_tcp_socket_get_io_channel(msn_socket);
				g_io_channel_set_buffer_size(msn_channel,128);
				g_io_channel_set_buffered(msn_channel,1);
				g_io_channel_set_encoding(msn_channel, NULL, NULL);
				g_io_add_watch(msn_channel,G_IO_IN|G_IO_HUP|G_IO_ERR,(GIOFunc)network_receive,NULL);
				printf("Transfered\n");
				net_send("VER 0 MSNP8 MYPROTOCOL CVR0 \r\n");
				return FALSE;
			}
		}
	}
	/* When the primary login stage (jumping connection) is done log_level = 1 */
	else if(log_level == 1)
	{
		if((condition&G_IO_HUP)==G_IO_HUP)
		{
			return FALSE;
		}
		if((condition&G_IO_IN) == G_IO_IN)
		{
			GIOError error = G_IO_ERROR_NONE;
			char data = 0;
			unsigned int offset = 0;
			char message[1024] = { '\0' };
			gsize n = 1;
			while(data!='\n')
			{
				error = gnet_io_channel_readn(msn_channel, &data, n, &n); 
				if(n == 0)
				{
					return FALSE;
				}
				if (error != G_IO_ERROR_NONE) 
				{
					error_dialog("Error receiving network data!");
					return FALSE;
				}
				message[offset++] = data;
			}
			printf("Received: %s\n",message);
			/*
				TODO: action to take
			*/
			if(strncmp(message, "VER",3)==0)
			{
				/* Got a response from VER, time to send CVR */
				char *tmp_message = g_strdup_printf("CVR 2 0x0c0a winnt 5.1 i386 MSNMSGR 8.0.0792 msmsgs %s\r\n",uemail);
				net_send(tmp_message);
				g_free(tmp_message);
			}
			else if(strncmp(message, "CVR", 3) == 0)
			{
				/* Got a response from CVR, time to send USR */
				char *tmp_message = g_strdup_printf("USR 3 TWN I %s\r\n",uemail);
				net_send(tmp_message);
				g_free(tmp_message);
			}
			else if(strncmp(message, "USR 3", 5) == 0)
			{
				/* 
					REALLY Tricky part now. OpenSSL - woohoo :( 

					Basically, the MSN protocol uses SSL to autheticate clients; so what happens now is, the MSN server sends us a 'challenge'
					for the SSL login page that we must send to it. So we need to extract that data, and send it to MSN to grab our golden 'ticket'
					which is used in the final login period.
				*/
				
				/* Example: USR 3 TWN S ct=1202475836,rver=5.0.3270.0,wp=FS_40SEC_0_COMPACT,lc=1033,id=507,ru=http:%2F%2Fmessenger.msn.com,tw=0,kpp=1,kv=4,ver=2.1.6000.1,rn=1lgjBfIL,tpf=b0735e3a873dfb5e75054465196398e0 */
				char *ticket = strstr(message, " ct=")+1;
				printf("Ticket: %s\n",ticket);
				
				char *return_ticket = net_ssl_auth(ticket);
				printf("Got ticket: %s\n",return_ticket);
				char *tmp_message = g_strdup_printf("USR 4 TWN S %s\r\n", return_ticket);
				net_send(tmp_message);
				g_free(tmp_message);
			}
			else if(strncmp(message, "USR 4", 5) == 0)
			{
				/* Woot I'm in! - We just got our email (useless) AND OUR NICKNAME! DAMN RIGHT BITCHES! */

				char *nick = split(message, ' ', 4);
				char *email = split(message, ' ', 3);
				globals_email = email;
				mwin_change_nick(nick);

				g_free(nick);
				char *tmp_message = g_strdup_printf("SYN 5 0\r\n");
				net_send(tmp_message);
				g_free(tmp_message);
				tmp_message = g_strdup_printf("CHG %d NLN 0\r\n",msg_num++);
				net_send(tmp_message);
				g_free(tmp_message);
				
			}
			else if(strncmp(message, "CHL", 3) == 0)
			{
				/* Got a challenge from MSN, and who am I to refuse? */
				char *challenge = message + 6;
				char *end = strstr(message, "\r\n");
				end[0] = '\0';
				char *chal_string = g_strdup_printf("%s%s",challenge,"Q1P7W2E4J9R8U3S5");
				GMD5* chal_md5 = gnet_md5_new(chal_string,strlen(chal_string));
				g_free(chal_string);
				
				gchar *hash = gnet_md5_get_string(chal_md5);
				gnet_md5_delete(chal_md5);
				
				printf("Challenge reply: %s\n",hash);
				
				char *tmp_message = g_strdup_printf("QRY %d [email protected] 32\r\n%s",msg_num++, hash);
				net_send(tmp_message);
				g_free(tmp_message);	
			}
			else if(strncmp(message,"RNG",3) == 0)
			{
				/* Got an incoming message! */
				printf("Got an incoming message, someone hast double clicked upon us!\n");
				printf("MESSAGE: %s\n",message);
				char *phost = split(message,' ', 2);
				char *host = split(phost,':',0);
				free(phost);
				printf("Host: %s\n",host);
				
				char *session = split(message,' ', 1);
				printf("Session: %s\n",session);
				
				char *auth_str = split(message,' ',4);
				char *email = split(message, ' ', 5);
				char *nick = split(message, ' ', 6);
				nick[strlen(nick)-2]='\0';
			
				printf("Auth: %s\n",auth_str);
				printf("Email: %s\n",email);
				printf("Nick: %s\n", nick);

				conversation_new(host, session, auth_str, email, nick, uemail);
			}
			else if(strncmp(message,"MSG",3) == 0)
			{
				// Got a message, most likely it's gonna be from Hotmail
				// Important thing is, MSG's have a payload size!
				char *nick = split(message,' ',2);
				char *len = split(message,' ',3);
				len[strlen(len)-2] = '\0';
				int length = atoi(len);
				printf("Inbound message length: %d\n",length);

				error = G_IO_ERROR_NONE;
				char incoming_msg[length+1];
				memset(incoming_msg, '\0',length+1);
				gsize n = length;
				error = gnet_io_channel_readn(msn_channel, incoming_msg, n, &n);
				if(error != G_IO_ERROR_NONE)
				{
				   fprintf(stderr, "Error occurred reading message\n");
				   return FALSE;
				}
				printf("Message: %s\n",incoming_msg);
			}
		}
	}
	return TRUE;
}
コード例 #12
0
ファイル: connectdb.c プロジェクト: christianglodt/gchartman
void on_connectdbok_clicked(GtkWidget *widget, gpointer user_data) {
	gchar	*host;
	gchar	*user;
	gchar	*password;
	gchar	*dbname;
	gchar	dbquery[200];
	gchar	dbstatus[1000];
	int	broken,found;
	xmlNodePtr node;

	host=gtk_entry_get_text((GtkEntry *)gnome_entry_gtk_entry(connectdb_host));
	user=gtk_entry_get_text((GtkEntry *)gnome_entry_gtk_entry(connectdb_user));
	password=gtk_entry_get_text(connectdb_password);
	dbname=gtk_entry_get_text((GtkEntry *)gnome_entry_gtk_entry(connectdb_database));

	broken=FALSE;

	mysql=mysql_init(NULL);
	if (!mysql_real_connect(mysql,host,user,password,NULL,0,NULL,0)) {
		error_dialog("Could not connect to Database");
		fprintf(stderr, "Failed to connect to database: Error: %s\n", mysql_error(mysql));
		mysql_close(mysql);
		mysql=NULL;
	} else {
		sprintf(dbquery,"use %s",dbname);
		mysql_query(mysql,dbquery);
	
		if (mysql_errno(mysql)!=0) {
			switch (ok_cancel_dialog("The database does not exist.\nCreate a new one?")) {
				case 0:
					g_message("Creating new Database %s.\n",dbname);
					sprintf(dbquery,"create database %s",dbname);
					if (mysql_query(mysql,dbquery)!=0) {
						fprintf(stderr, "Failed to create database: Error: %s\n", mysql_error(mysql));
					}
					sprintf(dbquery,"use %s",dbname);
					if (mysql_query(mysql,dbquery)!=0) {
						fprintf(stderr, "Failed to use database: Error: %s\n", mysql_error(mysql));
					}
					break;
				case 1:
					broken=TRUE;
					break;
				default:
					broken=TRUE;
					break;
			}
		}
		
		if (broken==FALSE) {		
			sprintf(dbquery,"create table _TableNames (Name Text,TName Text,Comment Text)");
			mysql_query(mysql,dbquery);
			name_cache=g_hash_table_new(g_str_hash,g_str_equal);
			tname_cache=g_hash_table_new(g_str_hash,g_str_equal);
		
			sprintf(dbstatus,"Database: %s\nuser:     %s\nhost:     %s",dbname,user,host);
			gtk_label_set_text(database_status_label,dbstatus);
		// -------------------------------
			found=FALSE;
			node=global_configs_doc->children;
			while (node) {
				if (strcmp(node->name,"configurations")==0) {
					node=node->children;
					break;
				}
				node=node->next;
			}

			if (node) {
				while (node) {
					if (strcmp(node->name,"dbconfig")==0) {
						if (strcmp(xmlGetProp(node,"dbname"),dbname)==0) {
							found=TRUE;
							db_global_configs_node=node;
							break;
						}
					}
					node=node->next;
				}
			}
			if (!found) {
				db_global_configs_node=xmlNewNode(NULL,"dbconfig");
				xmlSetProp(db_global_configs_node,"dbname",dbname);
				xmlAddChild(global_configs_doc->children,db_global_configs_node);
			}
		// ---------------------------------
			found=FALSE;
			node=local_configs_doc->children;
			while (node) {
				if (strcmp(node->name,"configurations")==0) {
					node=node->children;
					break;
				}
				node=node->next;
			}

			if (node) {
				while (node) {
					if (strcmp(node->name,"dbconfig")==0) {
						if (strcmp(xmlGetProp(node,"dbname"),dbname)==0) {
							found=TRUE;
							db_local_configs_node=node;
							break;
						}
					}
					node=node->next;
				}
			}
			if (!found) {
				db_local_configs_node=xmlNewNode(NULL,"dbconfig");
				xmlSetProp(db_local_configs_node,"dbname",xmlEncodeEntitiesReentrant(local_configs_doc,dbname));
				xmlAddChild(local_configs_doc->children,db_local_configs_node);
			} else {
				gtk_widget_set_sensitive(GTK_WIDGET(connect_button),FALSE);
				gtk_widget_set_sensitive(GTK_WIDGET(disconnect_button),TRUE);
				gtk_widget_set_sensitive(GTK_WIDGET(add_category_button),TRUE);
			}
		// ---------------------------------
			gnome_dialog_close(connectdb_dialog);
			update_tablelist(mysql);

		}
	}
}
コード例 #13
0
ファイル: kodak_dc2x.c プロジェクト: pinkavaj/gphoto2
int kodak_dc2x_configure () {

    error_dialog("The DC25 has switches on the case for configuration. Use those for now! -Del");
    return(0);

}
コード例 #14
0
ファイル: kodak_dc2x.c プロジェクト: pinkavaj/gphoto2
struct Image *kodak_dc2x_get_picture (int picNum, int thumbnail) {

    int tfd, image_size, image_width, net_width, camera_header, components;
    Dc20Info *my_info;
    unsigned char color_thumb[14400];
    unsigned char pic[MAX_IMAGE_SIZE];
    struct pixmap	*pp;

    GdkImlibImage *this_image, *scaled_image;
    GdkImlibColorModifier mod;

    FILE *jpgfile;
    int jpgfile_size;
    char filename[1024];
    struct Image *im;

    if ((tfd = kodak_dc2x_open_camera()) == 0) {
        error_dialog("Could not open camera.");
        return (0);
    }

    my_info = get_info(tfd);

    fprintf(stderr, "downloading from a DC%x\n", my_info->model);

    if (my_info->model == 0x25) {
        fprintf(stderr, "Match with 25!\n");
        if (thumbnail) {
            fprintf(stderr, "Getting thumbnail #%d from a DC25!\n", picNum);
            if (get_thumb(tfd, picNum, color_thumb) == -1) {
                fprintf(stderr,"get_thumb failed!\n");
                return(0);
            } else {
                fprintf(stderr,"get_thumb returned ok! Creating ImLib image!\n");
                this_image = gdk_imlib_create_image_from_data(color_thumb, NULL, 80, 60);
                fprintf(stderr, "Made it back from imlib_create!\n");
                sprintf(filename, "%s/gphoto-kodak-%i.jpg", gphotoDir, picNum);
                gdk_imlib_save_image (this_image, filename, NULL);
                gdk_imlib_kill_image (this_image);
                jpgfile = fopen(filename, "r");
                fseek(jpgfile, 0, SEEK_END);
                jpgfile_size = ftell(jpgfile);
                rewind(jpgfile);
                im = (struct Image*)malloc(sizeof(struct Image));
                im->image = (char *)malloc(sizeof(char)*jpgfile_size);
                fread(im->image, (size_t)sizeof(char), (size_t)jpgfile_size, jpgfile);
                fclose(jpgfile);
                strcpy(im->image_type, "jpg");
                im->image_size = (int)jpgfile_size;
                im->image_info_size = 0;
                remove(filename);
                return (im);
            }
        } else {
            fprintf(stderr, "Getting picture #%d from a DC25!\n", picNum );
            if (get_pic(tfd, picNum, pic, 0) == -1) {
                fprintf(stderr, "get_pic puked!\n");
                return(0);
            } else {
                fprintf(stderr, "returned from get_pic ok!\n");

                /*
                 *	Setup image size with resolution
                 */

                image_size = IMAGE_SIZE(pic[4]);
                image_width = WIDTH(pic[4]);
                net_width = image_width - LEFT_MARGIN - RIGHT_MARGIN(pic[4]);
                camera_header = CAMERA_HEADER(pic[4]);
                components = 3;

                /*
                 *	Convert the image to 24 bits
                 */

                if ((pp = alloc_pixmap(net_width - 1, HEIGHT - BOTTOM_MARGIN - 1, components)) == NULL) {
                    if (!quiet) fprintf(stderr, "%s: convert_pic: error: alloc_pixmap\n", __progname);
                    return 0;
                }

                if (comet_to_pixmap(pic, pp) == -1) {
                    fprintf(stderr, "comet_to_pixmap puked!\n");
                    return (0);
                } else {

                    fprintf(stderr, "attempting to imlib_create the image!\n");
                    this_image = gdk_imlib_create_image_from_data(pp->planes, NULL, pp->width, pp->height);
                    fprintf(stderr, "Made it back from imlib_create!\n");

                    /* now we just need to resize it! */
                    if (!pic[4]) {
                        /* high res 493x373 */
                        fprintf(stderr, "High Res!\n");
                        scaled_image = gdk_imlib_clone_scaled_image(this_image, 493, 373);

                    } else {
                        /* low res 320x240 */
                        fprintf(stderr, "Low Res!\n");
                        scaled_image = gdk_imlib_clone_scaled_image(this_image, 320, 240);

                        /* How? */
                    }

                    gdk_imlib_kill_image(this_image);

                    /* correct the contrast a bit before handing it back.. */
                    gdk_imlib_get_image_modifier(scaled_image,&mod);
                    mod.contrast = 256 * 1.3;
                    gdk_imlib_set_image_modifier(scaled_image,&mod);
                    gdk_imlib_apply_modifiers_to_rgb(scaled_image);

                    kodak_dc2x_close_camera(tfd);

                    sprintf(filename, "%s/gphoto-kodak-%i.jpg", gphotoDir, picNum);
                    gdk_imlib_save_image (scaled_image, filename, NULL);
                    gdk_imlib_kill_image (scaled_image);
                    jpgfile = fopen(filename, "r");
                    fseek(jpgfile, 0, SEEK_END);
                    jpgfile_size = ftell(jpgfile);
                    rewind(jpgfile);
                    im = (struct Image*)malloc(sizeof(struct Image));
                    im->image = (char *)malloc(sizeof(char)*jpgfile_size);
                    fread(im->image,(size_t)sizeof(char),(size_t)jpgfile_size,jpgfile);
                    fclose(jpgfile);
                    strcpy(im->image_type, "jpg");
                    im->image_size = jpgfile_size;
                    im->image_info_size = 0;
                    remove(filename);

                    return (im);
                }

            }
        }
    } else {
        fprintf(stderr, "No match with 25!");
        return(0);
    }
    return(0);
}