Exemple #1
0
void process()
{
  clear_results_message();

  child_params_t *cp = MALLOC(sizeof(child_params_t));
  strcpy(cp->in_file, get_string_from_entry("input_file_entry"));

  char *odir = get_string_from_entry("output_directory_entry");
  char *ofile = get_string_from_entry("output_file_entry");

  if (strlen(odir) > 0) {
#ifdef win32
    if (odir[strlen(odir)-1]=='/' || odir[strlen(odir)-1]=='\\')
#else
    if (odir[strlen(odir)-1]=='/')
#endif
      sprintf(cp->out_file, "%s%s", odir, ofile);
    else
      sprintf(cp->out_file, "%s/%s", odir, ofile);
  }
  else {
    strcpy(cp->out_file, ofile);
  }

  if (strlen(cp->in_file)==0) {
    message_box("No input file specified!");
    free(cp);
    return;
  }
  else if (strlen(cp->out_file)==0) {
    message_box("No output file selected!");
    free(cp);
    return;
  }
  else if (!fileExists(cp->in_file)) {
    message_box("Input file \"%s\" not found!", cp->in_file);
    free(cp);
    return;
  }

  int input_format = get_combo_box_item("input_format_combobox");
  int output_format = get_combo_box_item("output_format_combobox");

  if (input_format==INPUT_AUTO) {
    select_defaults_by_file_type(cp->in_file, FALSE);
    input_format = get_combo_box_item("input_format_combobox");
    if (input_format==INPUT_AUTO) {
      message_box("Can't figure out which type of data this is.\n"
                  "Please select the input format manually.");
      free(cp);
      return;
    }
  }

  strcpy(cp->in_format, input_format_to_str(input_format));
  strcpy(cp->out_format, output_format_to_str(output_format));
  char *logFile = appendExt(cp->out_file, ".log");

#ifdef win32
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    memset(&si, 0, sizeof(si));
    memset(&pi, 0, sizeof(pi));
    si.cb = sizeof(si);
    
    char *cmd = MALLOC(sizeof(char)*
        (strlen(cp->in_file) + strlen(cp->out_file) + strlen(get_asf_bin_dir_win()) + 512));
    sprintf(cmd,
        "\"%s/convert2vector.exe\" "
        "-log \"%s\" "
        "-input-format %s -output-format %s \"%s\" \"%s\"",
        get_asf_bin_dir_win(),
        logFile,
        cp->in_format, cp->out_format, cp->in_file, cp->out_file);

    // clear out any previously existing log file
    fLog = fopen(logFile, "a");
    FCLOSE(fLog);

    if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
    {
        DWORD dw = GetLastError();
        //printf( "CreateProcess failed (%ld)\n", dw );

        LPVOID lpMsgBuf;
        FormatMessage(
          FORMAT_MESSAGE_ALLOCATE_BUFFER |
          FORMAT_MESSAGE_FROM_SYSTEM |
          FORMAT_MESSAGE_IGNORE_INSERTS,
          NULL,
          dw,
          MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
          (LPTSTR)&lpMsgBuf,
          0,
          NULL);

        printf("CreateProcess() failed with error %ld: %s\n",
            dw, (char*)lpMsgBuf);
        printf("Failed command: %s\n", cmd);
    }

    DWORD dwWaitResult;

    // now wait for process to finish
    do {
        while (gtk_events_pending())
            gtk_main_iteration();
        dwWaitResult = WaitForSingleObject(pi.hProcess, 50);
    }
    while (dwWaitResult == WAIT_TIMEOUT);
#else
  asfFork(child_func, (void*)cp, parent_func, NULL);
#endif

  char message[1024];
  strcpy(message, "-");

  int success=FALSE;
  FILE *lfp = fopen(logFile, "r");
  if (!lfp) {
    sprintf(message, "Error Opening Log File '%s': %s\n",
            logFile, strerror(errno));
  }
  else {
    char *output = NULL;
    char line[1024];
    while (fgets(line, 1024, lfp)) {
      if (output) {
        output = realloc(output, sizeof(char)*(strlen(output)+strlen(line)+1));
        strcat(output, line);
      }
      else {
        output = malloc(sizeof(char)*(strlen(line)+1));
        strcpy(output, line);
      }
    }
    fclose(lfp);
    //unlink(logFile);

    char *p = output, *q;
    while (p) {
      q = strchr(p+1, '\n');
      if (q) {
        *q = '\0';
        if (strstr(p, "Error")!=NULL || strstr(p, "ERROR")!=NULL) {
          *q = '\n';
          int i,n = 0;
          do {
            p = q + 1;
            q = strchr(p, '\n') - 1;
            while (isspace(*q)) --q;
            if (q - p > 2) {
              // First 220 characters of the error string, unless line ends
              // first.  Don't cut off in the middle of a word, though
              strcpy(message, "Error: ");
              strncat(message, p, 220);
              while (isalnum(message[strlen(message)-1]))
                message[strlen(message)-1] = '\0';
              for (n=0; n<strlen(message); ++n)
                if (message[n] == '\n' || message[n] == '*') message[n] = ' ';
              int eating=FALSE;
              for (n=0,i=0; n<strlen(message); ++n) {
                if (isspace(message[n])) {
                  if (!eating) {
                    eating=TRUE;
                    message[i++] = message[n];
                  }
                } else {
                  eating=FALSE;
                  message[i++] = message[n];
                }
              }
              message[i]='\0';
              char *eoe = strstr(message, "End of error");
              if (eoe)
                *eoe = '\0';
              else if (strlen(message)>200)
                strcat(message, " ...");
              break;
            }
          }
          while (*p != '*' && ++n<5); // * flags the end of the error message
        }

        if (strstr(p,"Successful completion!") != NULL) {
          strcpy(message, "Processed successfully!");
          success=TRUE;
          break;
        }

        *q = '\n';
      }
      p=q;
    }

    if (strlen(message)==0) {
      // Did not find an error message, or the success message!
      // So, assume there was an error, but we don't know why
      strcpy(message, "Processing failed!");
    }

    FREE(output);
  }

  int open_output = get_checked("open_output_checkbutton");
  if (!success) open_output = FALSE;

  put_string_to_label("result_label", message);
  asfPrintStatus(message);
  asfPrintStatus("\n\nDone.\n\n");

  if (open_output) {
    switch (output_format) {
      case OUTPUT_KML:
        open_in_google_earth(cp->out_file);
        break;
      case OUTPUT_ALOS_CSV:
        open_in_excel(cp->out_file);
      default:
        // do nothing, output type has no natural associated app
        break;
    }
  }

  free(cp);
}
Exemple #2
0
/* Run a GUI to select and uninstall products */
int uninstall_ui(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *widget;
    GtkWidget *frame;
    GtkWidget *vbox;
    GtkWidget *button;
    GtkWidget *label;
    const char *product_name;
    product_t *product;
    product_info_t *product_info;
    product_component_t *component;
    component_list *component_list, *addon_list;
    char text[1024];

#ifdef ENABLE_GTK2
    // Turn off any themes
    setenv("GTK2_RC_FILES", "", 1);
    setenv("GTK_DATA_PREFIX", "", 1);
#endif

    gtk_init(&argc,&argv);

    /* Disable GLib warnings that may be triggered by libglade */
    g_log_set_handler ("libglade", G_LOG_LEVEL_WARNING | G_LOG_FLAG_RECURSION, log_handler, NULL);

    /* Initialize Glade */
    glade_init();
    uninstall_glade = GLADE_XML_NEW(DATADIR "/" UNINSTALL_GLADE, "loki_uninstall"); 

    /* Add all signal handlers defined in glade file */
    glade_xml_signal_autoconnect(uninstall_glade);

    /* Make sure the window is visible */
    widget = glade_xml_get_widget(uninstall_glade, "uninstall_button");
    if ( widget ) {
        gtk_button_set_sensitive(widget, FALSE);
    }
    window = glade_xml_get_widget(uninstall_glade, "loki_uninstall");
    gtk_widget_realize(window);
    while( gtk_events_pending() ) {
        gtk_main_iteration();
    }

    /* Add emergency signal handlers */
    signal(SIGHUP, main_signal_abort);
    signal(SIGINT, main_signal_abort);
    signal(SIGQUIT, main_signal_abort);
    signal(SIGTERM, main_signal_abort);

    /* Fill in the list of products and components */
    widget = glade_xml_get_widget(uninstall_glade, "uninstall_vbox");
    if ( ! widget ) {
        fprintf(stderr, _("No uninstall_vbox in glade file!\n"));
        return(-1);
    }
    gtk_container_foreach(GTK_CONTAINER(widget), empty_container, widget);
    for ( product_name=loki_getfirstproduct();
          product_name;
          product_name=loki_getnextproduct() ) {
        /* See if we can open the product */
        product = loki_openproduct(product_name);
        if ( ! product ) {
            continue;
        }
        /* See if we have permissions to remove the product */
        product_info = loki_getinfo_product(product);
        if ( ! check_permissions(product_info, 0) ) {
            loki_closeproduct(product);
            continue;
        }
        /* Add the product and components to our list */
        strncpy(text, product_info->description, sizeof(text));
        frame = gtk_frame_new(text);
        gtk_container_set_border_width(GTK_CONTAINER(frame), 4);
        gtk_box_pack_start(GTK_BOX(widget), frame, FALSE, TRUE, 0);
        gtk_widget_show(frame);
        vbox = gtk_vbox_new(FALSE, 0);
        gtk_container_add (GTK_CONTAINER (frame), vbox);
        gtk_widget_show(vbox);
        component = loki_getdefault_component(product);
        component_list = NULL;
        if ( component ) {
            component_list = create_component_list(product, product_info,
                                                   component);
            strncpy(text, _("Complete uninstall"), sizeof(text));
            button = gtk_check_button_new_with_label(text);
            gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
            gtk_signal_connect(GTK_OBJECT(button), "toggled",
                               GTK_SIGNAL_FUNC(component_toggled_slot),
                               (gpointer)component_list);
            gtk_object_set_data(GTK_OBJECT(button), "data",
                                (gpointer)component_list);
            gtk_widget_show(button);
        }
        for ( component = loki_getfirst_component(product);
              component;
              component = loki_getnext_component(component) ) {
            if ( loki_isdefault_component(component) ) {
                continue;
            }
            addon_list = create_component_list(product, product_info,
                                               component);
            strncpy(text, loki_getname_component(component), sizeof(text));
            button = gtk_check_button_new_with_label(text);
            gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
            gtk_signal_connect(GTK_OBJECT(button), "toggled",
                               GTK_SIGNAL_FUNC(component_toggled_slot),
                               (gpointer)addon_list);
            gtk_object_set_data(GTK_OBJECT(button), "data",
                                (gpointer)addon_list);
            gtk_widget_show(button);
            add_component_list(component_list, button);
        }

        /* Add this product to our list of open products */
        add_product(product);
    }

    /* Check to make sure there's something to uninstall */
    if ( ! product_list ) {
        label = gtk_label_new(
							  _("No products were installed by this user.\n"
								"You may need to run this tool as an administrator."));
        gtk_box_pack_start(GTK_BOX(widget), label, FALSE, TRUE, 0);
        gtk_widget_show(label);
    }

    /* Run the UI.. */
    gtk_main();

    /* Close all the products and return */
    close_products(0);
    return 0;
}
Exemple #3
0
wxDragResult wxDropSource::DoDragDrop(int flags)
{
    wxCHECK_MSG( m_data && m_data->GetFormatCount(), wxDragNone,
                 wxT("Drop source: no data") );

    // still in drag
    if (g_blockEventsOnDrag)
        return wxDragNone;

    // don't start dragging if no button is down
    if (g_lastButtonNumber == 0)
        return wxDragNone;

    // we can only start a drag after a mouse event
    if (g_lastMouseEvent == NULL)
        return wxDragNone;

    GTKConnectDragSignals();
    wxON_BLOCK_EXIT_OBJ0(*this, wxDropSource::GTKDisconnectDragSignals);

    m_waiting = true;

    GtkTargetList *target_list = gtk_target_list_new( NULL, 0 );

    wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
    m_data->GetAllFormats( array );
    size_t count = m_data->GetFormatCount();
    for (size_t i = 0; i < count; i++)
    {
        GdkAtom atom = array[i];
        wxLogTrace(TRACE_DND, wxT("Drop source: Supported atom %s"),
                   gdk_atom_name( atom ));
        gtk_target_list_add( target_list, atom, 0, 0 );
    }
    delete[] array;

    int allowed_actions = GDK_ACTION_COPY;
    if ( flags & wxDrag_AllowMove )
        allowed_actions |= GDK_ACTION_MOVE;

    // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad
    //     to use a global to pass the flags to the drop target but I'd
    //     surely prefer a better way to do it
    gs_flagsForDrag = flags;

    m_retValue = wxDragCancel;

    GdkDragContext *context = gtk_drag_begin( m_widget,
                target_list,
                (GdkDragAction)allowed_actions,
                g_lastButtonNumber,  // number of mouse button which started drag
                (GdkEvent*) g_lastMouseEvent );

    if ( !context )
    {
        // this can happen e.g. if gdk_pointer_grab() failed
        return wxDragError;
    }

    m_dragContext = context;

    PrepareIcon( allowed_actions, context );

    while (m_waiting)
        gtk_main_iteration();

    g_signal_handlers_disconnect_by_func (m_iconWindow,
                                          (gpointer) gtk_dnd_window_configure_callback, this);

    return m_retValue;
}
Exemple #4
0
static VALUE
rg_m_main_iteration(G_GNUC_UNUSED VALUE self)
{
    return CBOOL2RVAL(gtk_main_iteration());
}
Exemple #5
0
static void WaitForCleanup(void)
{
    while (gtk_events_pending())
        gtk_main_iteration();
}
Exemple #6
0
// Function adapted from Gens/GS (source/gens/ui/gtk/gens/gens_window_callbacks.c)
void on_sdlsocket_drag_data_received(GtkWidget *widget, GdkDragContext *context, gint x, gint y,
				    GtkSelectionData *selection_data, guint target_type, guint time,
				    gpointer data)
{
	if (selection_data == NULL || gtk_selection_data_get_length(selection_data) == 0)
	{
		// No selection data.
		gtk_drag_finish(context, FALSE, FALSE, time);
		return;
	}
	
	gboolean dnd_success = FALSE;
	
	gchar *filename = (gchar*)gtk_selection_data_get_data(selection_data);
	if (!filename)
	{
		// Selection data was not text.
		gtk_drag_finish(context, FALSE, FALSE, time);
		return;
	}
	
	if (strncmp(filename, "file:///", 8) == 0)
	{
		// "file:///" prefix. Remove the prefix.
		filename += 7;
	}
	else if (strncmp(filename, "file://", 7) == 0)
	{
		// "file://" prefix. Remove the prefix.
		filename += 6;
	}
	else if (strncmp(filename, "file:/", 6) == 0)
	{
		// "file:/" prefix. Remove the prefix.
		filename += 5;
	}
	else if (strncmp(filename, "desktop:/", 9) == 0)
	{
		// "desktop:/" prefix. Remove the prefix and prepend the user's desktop directory.
		char tmpname[1024] = {""};
		sprintf(tmpname, "%s/Desktop/%s", getenv("HOME"), filename + 9);
		filename = tmpname;
	}
	
	// Unescape the URI.
	char realname[1024];
	int i, j;
	for (i=0, j=0; i<strlen(filename); j++)
	{
		if (filename[i] == '%')
		{
			char tmp[3];
			strncpy(tmp, &filename[i+1], 2);
			realname[j] = (char)strtol(tmp, NULL, 16);
			i += 3;
		} else realname[j] = filename[i++];
		if(realname[j] == '\r' || realname[j] == '\n') realname[j] = 0;
	}
	realname[j] = 0;
	
	// Check that the file actually exists. (TODO)
	gboolean exists = TRUE;
	if (!exists) dnd_success = FALSE;
	
	if (exists)
	{
		CD_emulation = 0;
		strcpy(cart_name, realname);
		/* We need to flush any GTK events waiting to happen to avoid a deadlock
		 * when starting a game fullscreen (at least in Linux). */
		while (gtk_events_pending())
			gtk_main_iteration();
		play_game();
	}
	
	gtk_drag_finish(context, dnd_success, FALSE, time);
}
Exemple #7
0
void gui_update()
{
  gui_expand_view();
  while (gtk_events_pending ())
    gtk_main_iteration ();
}
Exemple #8
0
static gchar *input_dialog_open(const gchar *title, const gchar *message,
				const gchar *checkbtn_label,
				const gchar *default_string,
				gboolean default_checkbtn_state,
				gboolean *remember)
{
	gchar *str;

	if (dialog && gtk_widget_get_visible(dialog)) return NULL;

	if (!dialog)
		input_dialog_create(FALSE);

	if (checkbtn_label)
		gtk_button_set_label(GTK_BUTTON(remember_checkbtn), checkbtn_label);
	else
		gtk_button_set_label(GTK_BUTTON(remember_checkbtn), _("Remember this"));

	input_dialog_set(title, message, default_string);
	gtk_window_present(GTK_WINDOW(dialog));

	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(remember_checkbtn),
				     default_checkbtn_state);
	if (remember)
		gtk_widget_show(remember_checkbtn);
	else
		gtk_widget_hide(remember_checkbtn);

	gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
	manage_window_set_transient(GTK_WINDOW(dialog));

	ack = fin = FALSE;

	while (fin == FALSE)
		gtk_main_iteration();

	manage_window_focus_out(dialog, NULL, NULL);

	if (ack) {
		GtkEditable *editable;

		if (type == INPUT_DIALOG_COMBO)
			editable = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN((combo))));
		else
			editable = GTK_EDITABLE(entry);

		str = gtk_editable_get_chars(editable, 0, -1);
		if (str && *str == '\0' && !is_pass) {
			g_free(str);
			str = NULL;
		}
	} else
		str = NULL;

	GTK_EVENTS_FLUSH();

	if (remember) {
		*remember = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(remember_checkbtn));
	}

	gtk_widget_destroy(dialog);
	dialog = NULL;

	if (is_pass)
		debug_print("return string = %s\n", str ? "********": ("none"));
	else
		debug_print("return string = %s\n", str ? str : "(none)");
	return str;
}
int DoLoadPortalFileDialog ()
{
  GtkWidget *dlg, *vbox, *hbox, *button, *entry, *check2d, *check3d;
  int loop = 1, ret = IDCANCEL;

  dlg = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (dlg), "Load .prt");
  gtk_signal_connect (GTK_OBJECT (dlg), "delete_event",
                      GTK_SIGNAL_FUNC (dialog_delete_callback), NULL);
  gtk_signal_connect (GTK_OBJECT (dlg), "destroy",
                      GTK_SIGNAL_FUNC (gtk_widget_destroy), NULL);
  g_object_set_data (G_OBJECT (dlg), "loop", &loop);
  g_object_set_data (G_OBJECT (dlg), "ret", &ret);

  vbox = gtk_vbox_new (FALSE, 5);
  gtk_widget_show (vbox);
  gtk_container_add (GTK_CONTAINER (dlg), vbox);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);

  entry = gtk_entry_new ();
  gtk_widget_show (entry);
  gtk_entry_set_editable (GTK_ENTRY (entry), FALSE);
  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);

  hbox = gtk_hbox_new (FALSE, 5);
  gtk_widget_show (hbox);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

  check3d = gtk_check_button_new_with_label ("Show 3D");
  gtk_widget_show (check3d);
  gtk_box_pack_start (GTK_BOX (hbox), check3d, FALSE, FALSE, 0);

  check2d = gtk_check_button_new_with_label ("Show 2D");
  gtk_widget_show (check2d);
  gtk_box_pack_start (GTK_BOX (hbox), check2d, FALSE, FALSE, 0);

  button = gtk_button_new_with_label ("Change");
  gtk_widget_show (button);
  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (change_clicked), entry);
  gtk_widget_set_usize (button, 60, -2);

  hbox = gtk_hbox_new (FALSE, 5);
  gtk_widget_show (hbox);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

  button = gtk_button_new_with_label ("Cancel");
  gtk_widget_show (button);
  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDCANCEL));
  gtk_widget_set_usize (button, 60, -2);

  button = gtk_button_new_with_label ("OK");
  gtk_widget_show (button);
  gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  gtk_signal_connect (GTK_OBJECT (button), "clicked",
		      GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDOK));
  gtk_widget_set_usize (button, 60, -2);

  strcpy (portals.fn, g_FuncTable.m_pfnGetMapName());
  char* fn = strrchr (portals.fn, '.');
  if (fn != NULL)
  {
    strcpy(fn, ".prt");
  }

  gtk_entry_set_text (GTK_ENTRY (entry), portals.fn);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check2d), portals.show_2d);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check3d), portals.show_3d);

  gtk_grab_add (dlg);
  gtk_widget_show (dlg);

  while (loop)
    gtk_main_iteration ();

  if (ret == IDOK)
  {
    portals.Purge();

    portals.show_3d = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check3d)) ? qtrue : qfalse;
    portals.show_2d = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check2d)) ? qtrue : qfalse;
  }

  gtk_grab_remove (dlg);
  gtk_widget_destroy (dlg);

  return ret;
}
Exemple #10
0
static void gtk_savethread(void *args){
    MSG_FILE *file = args;
    uint16_t fid = file->progress;
    file->progress = 0;

    while(1){ //TODO, save current dir, and filename and preload them to gtk dialog if save fails.
        /* Create a GTK save window */
        void *dialog = gtk_file_chooser_dialog_new("Save File", NULL, 1, "gtk-cancel", -6, "gtk-save", -3, NULL);
        /* Get incoming file name*/
        char buf[sizeof(file->name) + 1];
        memcpy(buf, file->name, file->name_length);
        buf[file->name_length] = 0;
        /* give gtk the file name our friend is sending. */
        gtk_file_chooser_set_current_name(dialog, buf);
        /* Prompt to overwrite */
        gtk_file_chooser_set_do_overwrite_confirmation(dialog, (void*)1);
        /* Users can create folders when saving. */ //TODO ENABLE BELOW!
        //gtk_file_chooser_set_create_folders(dialog, TRUE);
        int result = gtk_dialog_run(dialog);
        /* If user is ready to save check then pass to utox. */
        if(result == -3) {
            char *name = gtk_file_chooser_get_filename(dialog);
            char *path = strdup(name);
            //g_free(name)

            debug("name: %s\npath: %s\n", name, path);

            /* can we really write this file? */
            FILE *fp = fopen(path, "w");
            if(fp == NULL){
                /* No, we can't display error, jump to top. */
                if(errno == EACCES){
                    debug("File write permission denied.\n");
                    void *errordialog = gtk_message_dialog_new(dialog, 1, 3, 2,
                            //parent, destroy_with_parent, gtk_error_message, gtk_buttons_close
                                            "Error writing to file '%s'", name);
                    gtk_dialog_run(errordialog);
                    gtk_widget_destroy(errordialog);
                    gtk_widget_destroy(dialog);
                    continue;
                } else {
                    debug("Unknown file write error...\n");
                }
            } else {
                /* write test passed, we're done! */
                gtk_widget_destroy(dialog);
                postmessage(SAVE_FILE, fid, file->filenumber, path);
                break;
            }
        }
        /* catch all */
        gtk_widget_destroy(dialog);
        break;
    }

    while(gtk_events_pending()) {
        gtk_main_iteration();
    }

    gtk_open = 0;
}
/* Test for GNOME bugzilla bug 359231 */
static void
test_bug359231 (void)
{
	int i;
	int height1, height2;
	GtkTreePath *path;
	GtkTreeIter iter, child;
	GtkTreeStore *store;
	GdkRectangle rect;
	ScrollFixture *fixture;

	/* See #359231. */
	g_test_bug ("359231");

	/* Create model (GtkTreeStore in this case) */
	store = gtk_tree_store_new (1, G_TYPE_STRING);

	gtk_tree_store_append (store, &iter, NULL);
	gtk_tree_store_set (store, &iter, 0, "Foo", -1);

	for (i = 0; i < 4; i++) {
		gtk_tree_store_append (store, &child, &iter);
		gtk_tree_store_set (store, &child, 0, "Two\nLines", -1);
	}
	
	fixture = g_new0 (ScrollFixture, 1);
	scroll_fixture_setup (fixture, GTK_TREE_MODEL (store), NULL);
	gtk_widget_show_all (fixture->window);

	while (gtk_events_pending ())
		gtk_main_iteration ();

	/* Prepend some rows at the top, expand */
	gtk_tree_store_prepend (store, &iter, NULL);
	gtk_tree_store_set (store, &iter, 0, "Foo", -1);

	gtk_tree_store_prepend (store, &child, &iter);
	gtk_tree_store_set (store, &child, 0, "Two\nLines", -1);

	gtk_tree_view_expand_all (GTK_TREE_VIEW (fixture->tree_view));

	while (gtk_events_pending ())
		gtk_main_iteration ();

	/* Test if height of row 0:0 is correct */
	path = gtk_tree_path_new_from_indices (0, -1);
	gtk_tree_view_get_background_area (GTK_TREE_VIEW (fixture->tree_view),
					   path, NULL, &rect);
	height1 = rect.height;

	gtk_tree_path_down (path);
	gtk_tree_view_get_background_area (GTK_TREE_VIEW (fixture->tree_view),
					   path, NULL, &rect);
	height2 = rect.height;
	gtk_tree_path_free (path);

	g_assert (height2 > height1);

	/* Clean up; the tear down also cleans up the model */
	scroll_fixture_teardown (fixture, NULL);
}
Exemple #12
0
void
open_grf_file (const char *fname)
{
	char *title, *tmp;
	GrfError err;
	Grf *newgrf;
	GList *list, *cols;

	if (!g_file_test (fname, G_FILE_TEST_EXISTS)) {
		show_error (_("File %s does not exist."), fname);
		return;
	}

	mainWin.busy (true);
	mainWin.status (_("Loading..."));
	while (gtk_events_pending ()) gtk_main_iteration ();
	newgrf = grf_open (fname, "r", &err);
	if (!newgrf) {
		char *base;

		base = g_path_get_basename (fname);
		mainWin.status ("");
		gdk_window_set_cursor (W(main)->window, NULL);
		show_error (_("Error while opening %s:\n%s"),
			base, grf_strerror (err));
		g_free (base);
		return;
	}
	if (document.grf)
		grf_free (document.grf);
	document.grf = newgrf;

	document.filename = fname;

	title = g_strdup_printf (_("%s - GRF Tool"), fname);
	gtk_window_set_title (GTK_WINDOW (W(main)), title);
	g_free (title);

	gtk_list_store_clear (GTK_LIST_STORE (filelist));

	cols = gtk_tree_view_get_columns (GTK_TREE_VIEW (W(filelist)));
	for (list = cols; list; list = list->next) {
		GtkTreeViewColumn *col = (GtkTreeViewColumn *) list->data;
		gtk_tree_view_column_set_sort_indicator (col, FALSE);
	}
	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (filelist),
		GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
	g_list_free (cols);


	fill_filelist ();


	tmp = g_path_get_basename (fname);
	title = g_strdup_printf (_("%s: %ld files"), tmp, document.grf->nfiles);
	mainWin.status (title);
	g_free (tmp);
	g_free (title);
	gtk_widget_set_sensitive (W(extract), TRUE);
	mainWin.busy (false);
}
Exemple #13
0
static int MicrocodeDialog()
{
    GtkWidget *infoLabel;
    GtkWidget *infoFrame, *infoTable;
    GtkWidget *crcInfoLabel, *crcDataInfoLabel, *textInfoLabel;
    GtkWidget *crcLabel = NULL, *crcDataLabel = NULL, *textLabel = NULL;
    GtkWidget *selectUcodeLabel;
    //GtkWidget *microcodeLabel;
    GtkWidget *okButton, *stopButton;
    GList *ucodeList = 0;
    char buf[1024];

    if (!g_thread_supported())
        g_thread_init( NULL );
    gdk_threads_enter();

    // create dialog
    if (microcodeWindow == 0)
    {
        microcodeWindow = gtk_dialog_new();
        gtk_signal_connect( GTK_OBJECT(microcodeWindow), "delete_event",
                            GTK_SIGNAL_FUNC(delete_question_event), (gpointer)NULL );
        sprintf( buf, "%s - unknown microcode", pluginName );
        gtk_window_set_title( GTK_WINDOW(microcodeWindow), buf );
        gtk_container_set_border_width( GTK_CONTAINER(GTK_DIALOG(microcodeWindow)->vbox), 11 );

        // ok button
        okButton = gtk_button_new_with_label( "Ok" );
        gtk_signal_connect_object( GTK_OBJECT(okButton), "clicked",
                               GTK_SIGNAL_FUNC(okButton_clicked), NULL );
        gtk_container_add( GTK_CONTAINER(GTK_DIALOG(microcodeWindow)->action_area), okButton );

        // stop button
        stopButton = gtk_button_new_with_label( "Stop" );
        gtk_signal_connect_object( GTK_OBJECT(stopButton), "clicked",
                               GTK_SIGNAL_FUNC(stopButton_clicked), NULL );
        gtk_container_add( GTK_CONTAINER(GTK_DIALOG(microcodeWindow)->action_area), stopButton );

        // info label
        infoLabel = gtk_label_new( "Unknown microcode. Please notify Orkin, including the following information:" );
        gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(microcodeWindow)->vbox), infoLabel );

        // info frame
        infoFrame = gtk_frame_new( "Microcode info" );
        gtk_container_set_border_width( GTK_CONTAINER(infoFrame), 7 );
        gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(microcodeWindow)->vbox), infoFrame );

        infoTable = gtk_table_new( 3, 2, FALSE );
        gtk_container_set_border_width( GTK_CONTAINER(infoTable), 7 );
        gtk_table_set_col_spacings( GTK_TABLE(infoTable), 3 );
        gtk_table_set_row_spacings( GTK_TABLE(infoTable), 3 );
        gtk_container_add( GTK_CONTAINER(infoFrame), infoTable );

        crcInfoLabel = gtk_label_new( "Microcode CRC:" );
        crcDataInfoLabel = gtk_label_new( "Microcode Data CRC:" );
        textInfoLabel = gtk_label_new( "Microcode Text:" );

        crcLabel = gtk_label_new( "" );
        crcDataLabel = gtk_label_new( "" );
        textLabel = gtk_label_new( "" );

        gtk_table_attach_defaults( GTK_TABLE(infoTable), crcInfoLabel, 0, 1, 0, 1 );
        gtk_table_attach_defaults( GTK_TABLE(infoTable), crcLabel, 1, 2, 0, 1 );
        gtk_table_attach_defaults( GTK_TABLE(infoTable), crcDataInfoLabel, 0, 1, 1, 2 );
        gtk_table_attach_defaults( GTK_TABLE(infoTable), crcDataLabel, 1, 2, 1, 2 );
        gtk_table_attach_defaults( GTK_TABLE(infoTable), textInfoLabel, 0, 1, 2, 3 );
        gtk_table_attach_defaults( GTK_TABLE(infoTable), textLabel, 1, 2, 2, 3 );

        selectUcodeLabel = gtk_label_new( "You can manually select the closest matching microcode." );
        for (int i = 0; i < numMicrocodeTypes; i++)
            ucodeList = g_list_append( ucodeList, gtk_list_item_new_with_label( MicrocodeTypes[i] ) );
        microcodeList = gtk_list_new();
        gtk_list_set_selection_mode( GTK_LIST(microcodeList), GTK_SELECTION_SINGLE );
        gtk_list_append_items( GTK_LIST(microcodeList), ucodeList );

        gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(microcodeWindow)->vbox), selectUcodeLabel );
        gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(microcodeWindow)->vbox), microcodeList );
    }

    snprintf( buf, 1024, "0x%8.8X", (unsigned int)uc_crc );
        if(crcLabel) gtk_label_set_text( GTK_LABEL(crcLabel), buf );
    snprintf( buf, 1024, "0x%8.8X", (unsigned int)uc_dcrc );
    if(crcDataLabel) gtk_label_set_text( GTK_LABEL(crcDataLabel), buf );
    if(textLabel) gtk_label_set_text( GTK_LABEL(textLabel), uc_str );

    selectedMicrocode = -1;
    gtk_widget_show_all( microcodeWindow );

    while (selectedMicrocode == -1)
    {
        if( gtk_main_iteration() )
            break;
        usleep( 10000 );
    }
    gdk_threads_leave();

    return selectedMicrocode;
}
Exemple #14
0
wxDragResult wxDropSource::DoDragDrop(int flags)
{
    wxCHECK_MSG( m_data && m_data->GetFormatCount(), wxDragNone,
                 wxT("Drop source: no data") );

    // still in drag
    if (g_blockEventsOnDrag)
        return wxDragNone;

    // don't start dragging if no button is down
    if (g_lastButtonNumber == 0)
        return wxDragNone;
        
    // we can only start a drag after a mouse event
    if (g_lastMouseEvent == NULL)
        return wxDragNone;

    // disabled for now
    g_blockEventsOnDrag = true;

    RegisterWindow();

    m_waiting = true;

    GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );

    wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
    m_data->GetAllFormats( array );
    size_t count = m_data->GetFormatCount();
    for (size_t i = 0; i < count; i++)
    {
        GdkAtom atom = array[i];
#ifdef __WXDEBUG__
        wxLogTrace(TRACE_DND, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom ));
#endif
       gtk_target_list_add( target_list, atom, 0, 0 );
    }
    delete[] array;

    int action = GDK_ACTION_COPY;
    if ( flags & wxDrag_AllowMove )
        action |= GDK_ACTION_MOVE;

    // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad
    //     to use a global to pass the flags to the drop target but I'd
    //     surely prefer a better way to do it
    gs_flagsForDrag = flags;

    GdkDragContext *context = gtk_drag_begin( m_widget,
                target_list,
                (GdkDragAction)action,
                g_lastButtonNumber,  // number of mouse button which started drag
                (GdkEvent*) g_lastMouseEvent );

    if ( !context )
    {
        // this can happen e.g. if gdk_pointer_grab() failed
        g_blockEventsOnDrag = false;

        UnregisterWindow();

        return wxDragError;
    }

    m_dragContext = context;

    PrepareIcon( action, context );

    while (m_waiting)
        gtk_main_iteration();

    m_retValue = ConvertFromGTK(context->action);
    if ( m_retValue == wxDragNone )
         m_retValue = wxDragCancel;

    g_blockEventsOnDrag = false;

    UnregisterWindow();

    return m_retValue;
}
Exemple #15
0
bool wxClipboard::GetData( wxDataObject& data )
{
    wxCHECK_MSG( m_open, false, wxT("clipboard not open") );

    /* get formats from wxDataObjects */
    wxDataFormat *array = new wxDataFormat[ data.GetFormatCount() ];
    data.GetAllFormats( array );

    for (size_t i = 0; i < data.GetFormatCount(); i++)
    {
        wxDataFormat format( array[i] );

        wxLogTrace( TRACE_CLIPBOARD,
                    wxT("wxClipboard::GetData: requested format: %s"),
                    format.GetId().c_str() );

        /* is data supported by clipboard ? */

        /* store requested format to be asked for by callbacks */
        m_targetRequested = format;

        wxCHECK_MSG( m_targetRequested, false, wxT("invalid clipboard format") );

        m_formatSupported = false;

        /* perform query. this will set m_formatSupported to
           true if m_targetRequested is supported.
           also, we have to wait for the "answer" from the
           clipboard owner which is an asynchronous process.
           therefore we set m_waiting = true here and wait
           until the callback "targets_selection_received"
           sets it to false */

        m_waiting = true;

#if 0
        gtk_selection_convert( m_targetsWidget,
                               m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
                               : g_clipboardAtom,
                               g_targetsAtom,
                               (guint32) GDK_CURRENT_TIME );

        while (m_waiting) gtk_main_iteration();
#endif

        if (!m_formatSupported) continue;

        /* store pointer to data object to be filled up by callbacks */
        m_receivedData = &data;

        /* store requested format to be asked for by callbacks */
        m_targetRequested = format;

        wxCHECK_MSG( m_targetRequested, false, wxT("invalid clipboard format") );

        /* start query */
        m_formatSupported = false;

        /* ask for clipboard contents.  this will set
           m_formatSupported to true if m_targetRequested
           is supported.
           also, we have to wait for the "answer" from the
           clipboard owner which is an asynchronous process.
           therefore we set m_waiting = true here and wait
           until the callback "targets_selection_received"
           sets it to false */

        m_waiting = true;

        wxLogTrace( TRACE_CLIPBOARD,
                    wxT("wxClipboard::GetData: format found, start convert") );

#if 0
        gtk_selection_convert( m_clipboardWidget,
                               m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
                               : g_clipboardAtom,
                               m_targetRequested,
                               (guint32) GDK_CURRENT_TIME );

        while (m_waiting) gtk_main_iteration();
#endif

        /* this is a true error as we checked for the presence of such data before */
        wxCHECK_MSG( m_formatSupported, false, wxT("error retrieving data from clipboard") );

        /* return success */
        delete[] array;
        return true;
    }

    wxLogTrace( TRACE_CLIPBOARD,
                wxT("wxClipboard::GetData: format not found") );

    /* return failure */
    delete[] array;
    return false;
}
Exemple #16
0
/* tu wchodzimy do programu, czytamy krainy i wyswietlamy liste krain.
   gdy uzytkownik wybierze kraine, wywolujemy kolejne funkcje (nizej w pliku) */
int main( int argc, char **argv )
{
    struct timeval now_time;
    AREA_DATA *a;
    GtkTreeIter iter;
    struct stat fst;
    char katalog[ MIL ], sciezka[ MIL ], *p;
    GtkWidget *powitalne;
    GtkCellRendererText *renderer;

    gtk_set_locale( );
    gtk_init( &argc, &argv );

    glacaxml = gtk_builder_new( );
    if ( !stat( "glaca.glade", &fst ) )
	gtk_builder_add_from_file( glacaxml, "glaca.glade", NULL /* &error */ );
    else
    {
	/* dirname( ) z glibc niszczy argumenty, wiec nie podam mu argv[ 0 ] */
	strcpy( katalog, argv[ 0 ] );
	strcpy( katalog, dirname( katalog ) );
	sprintf( sciezka, "%s/glaca.glade", katalog );
	if ( !stat( sciezka, &fst ) )
	    gtk_builder_add_from_file( glacaxml, sciezka, NULL /* &error */ );
	else
	{
	    sprintf( sciezka, "%s/gla/glaca.glade", katalog );
	    if ( !stat( sciezka, &fst ) )
		gtk_builder_add_from_file( glacaxml, sciezka, NULL /* &error */ );
	    else
	    {
		sprintf( sciezka, "%s/../glaca/glaca.glade", katalog );
		if ( !stat( sciezka, &fst ) )
		    gtk_builder_add_from_file( glacaxml, sciezka, NULL /* &error */ );
		else
		{
		    cbug( "Nie znalazlem pliku glaca.glade. Sprawdz swoja instalacje.", 0 );
		    return 1;
		}
	    }
	}
    }

    /* okienko powitalne */
    ZNAJDZ_KONTROLKE( powitalne, "oknopowitalne" );
    gtk_widget_show( powitalne );

    /* Doprowadzmy do natychmiastowego wyswietlenia tego okienka. Nie bedzie
       aktualizowane az zniknie, ale to juz minimalny problem, bo jednak
       wczytanie krain nie jest az tak dlugie :) */
    while ( gtk_events_pending( ) )
	gtk_main_iteration( );

    /* Wczytanie krain */
    TylkoKonwersja = TRUE;
    comm_main( TRUE, argc, argv );

    if ( ( iso_uni = iconv_open( "UTF-8", "ISO_8859-2" ) ) == (iconv_t) -1 )
	lac_perror( "iso_uni" );
    if ( ( uni_iso = iconv_open( "ISO_8859-2", "UTF-8" ) ) == (iconv_t) -1 )
	lac_perror( "uni_iso" );

    /* Wielkim problemem gtk_builder_connect_signals jest brak mozliwosci
       sprawdzenia, czy wszystko sie udalo (poza przeczytaniem stderr, gdzie
       to wyrzuca bledy, co za glupota).
       
       Moznaby przekierowac stderr do pliku, nastepnie go odczytac i wyswietlic
       w okienku GTK+, zeby pod Windows uzytkownik mial co skopiowac, zeby potem
       wkleic opiekunowi programu. */
    gtk_builder_connect_signals( glacaxml, NULL );

    ZNAJDZ_KONTROLKE( dlis.lista_krain, "treeviewlistakrain" );
    ZNAJDZ_KONTROLKE( dlis.okno_lista_krain, "oknolistakrain" );
    ZNAJDZ_KONTROLKE2( dlis.store_krain, "lis_store", GTK_LIST_STORE );
    ZNAJDZ_KONTROLKE2( renderer, "lis_renderer_nazwa", GTK_CELL_RENDERER_TEXT );
    g_object_set( renderer, "font", "Monospace", NULL );
    ZNAJDZ_KONTROLKE2( renderer, "lis_renderer_zakres", GTK_CELL_RENDERER_TEXT );
    g_object_set( renderer, "font", "Monospace", NULL );
    dlis.selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( dlis.lista_krain ) );
    gtk_tree_selection_set_mode( dlis.selection, GTK_SELECTION_MULTIPLE );

    ZNAJDZ_KONTROLKE( dlis.button_mob, "lis_button_mob" );
    ZNAJDZ_KONTROLKE( dlis.button_pom, "lis_button_pom" );
    ZNAJDZ_KONTROLKE( dlis.button_prz, "lis_button_prz" );
    ZNAJDZ_KONTROLKE2( dlis.entry_vnum, "lis_entry_vnum", GTK_ENTRY );

    for ( a = area_first; a; a = a->next )
    {
	p = wiersz( a, sciezka );
	gtk_list_store_append( dlis.store_krain, &iter );
	gtk_list_store_set( dlis.store_krain, &iter,
		KOL_WSKAZNIK, a,
		KOL_NAZWA, a->file_name,
		KOL_OPIS, sciezka,
		KOL_OPIS2, p, -1 );
    }

    font_desc = pango_font_description_from_string( "Monospace" );
    pango_font_description_set_absolute_size( font_desc, 12 * PANGO_SCALE );

    /* dialogi */
    zrob_Listy( );
    zrob_dialog_Combo( );
    zrob_okno_Krainy( );
    zrob_okno_Pomieszczenia( );
    zrob_okno_Moba( );
    zrob_okno_Vnuma( );
    zrob_okno_Mapy( );
    zrob_okno_Wyjscia( );
    zrob_okno_Progow( );
    zrob_okno_Przedmiotu( );
    zrob_okno_Resetu( );

    pango_font_description_free( font_desc );

    gtk_widget_show( dlis.okno_lista_krain );
    gtk_widget_hide( powitalne );

    /* zadne ZNAJDZ_KONTROLKE nie moze byc potem wywolywane - wszystko musi
       byc wczesniej znalezione w funkcjach zrob_okno_blabla */
    g_object_unref( G_OBJECT( glacaxml ) );
    gtk_main( );

    gettimeofday( &now_time, NULL );
    current_time = (time_t) now_time.tv_sec;
    log_string( "Edytor krain zakonczyl dzialanie." );

    return 0;
}
Exemple #17
0
static gboolean
handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
{
  static guint pulsate_timeout = 0;
  float percentage = 0.0;

  if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP))
    {
      GString *string;
      GError *err = NULL;

      string = g_string_new (NULL);

      if (options.progress_data.pulsate)
        {
          if (pulsate_timeout == 0)
            pulsate_timeout = g_timeout_add (100, pulsate_progress_bar, NULL);
        }

      while (channel->is_readable != TRUE);

      do
        {
          gint status;

          do
            {
              status = g_io_channel_read_line_string (channel, string, NULL, &err);
              while (gtk_events_pending ())
                gtk_main_iteration ();
            }
          while (status == G_IO_STATUS_AGAIN);

          if (status != G_IO_STATUS_NORMAL)
            {
              if (err)
                {
                  g_printerr ("yad_progress_handle_stdin(): %s\n", err->message);
                  g_error_free (err);
                  err = NULL;
                }
              /* stop handling */
              g_io_channel_shutdown (channel, TRUE, NULL);
              return FALSE;
            }

          if (string->str[0] == '#')
            {
              gchar *match;

              /* We have a comment, so let's try to change the label or write it to the log */
              match = g_strcompress (g_strstrip (string->str + 1));
              if (options.progress_data.log)
                {
                  gchar *logline;
                  GtkTextIter end;

                  logline = g_strdup_printf ("%s\n", match);    /* add new line */
                  gtk_text_buffer_get_end_iter (log_buffer, &end);
                  gtk_text_buffer_insert (log_buffer, &end, logline, -1);
                  g_free (logline);

                  /* scroll to end */
                  while (gtk_events_pending ())
                    gtk_main_iteration ();
                  gtk_text_buffer_get_end_iter (log_buffer, &end);
                  gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (progress_log), &end, 0, FALSE, 0, 0);
                }
              else
                gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress_bar), match);
              g_free (match);
            }
          else
            {
              if (g_ascii_isdigit (*(string->str)))
                {
                  /* Now try to convert the thing to a number */
                  percentage = atoi (string->str);
                  if (percentage >= 100)
                    {
                      gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0);
                      if (options.progress_data.autoclose && options.plug == -1)
                        yad_exit (options.data.def_resp);
                    }
                  else
                    gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), percentage / 100.0);
                }
            }

        }
      while (g_io_channel_get_buffer_condition (channel) == G_IO_IN);
      g_string_free (string, TRUE);
    }

  if ((condition != G_IO_IN) && (condition != G_IO_IN + G_IO_HUP))
    {
      gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), 1.0);

      if (options.progress_data.pulsate)
        {
          g_source_remove (pulsate_timeout);
          pulsate_timeout = 0;
        }

      if (options.progress_data.autoclose && options.plug == -1)
        yad_exit (options.data.def_resp);

      g_io_channel_shutdown (channel, TRUE, NULL);
      return FALSE;
    }
  return TRUE;
}
Exemple #18
0
gint
hex_document_export_html(HexDocument *doc, gchar *html_path, gchar *base_name,
                         guint start, guint end, guint cpl, guint lpp,
                         guint cpw)
{
    GtkWidget *progress_dialog, *progress_bar;
    FILE *file;
    int page, line, pos, lines, pages, c;
    gchar *page_name, b;
    gint update_pages;
    gchar *progress_str;

    lines = (end - start)/cpl;
    if((end - start)%cpl != 0)
        lines++;
    pages = lines/lpp;
    if(lines%lpp != 0)
        pages++;
    update_pages = pages/1000 + 1;

    /* top page */
    page_name = g_strdup_printf("%s/%s.html", html_path, base_name);
    file = fopen(page_name, "w");
    g_free(page_name);
    if(!file)
        return FALSE;
    fprintf(file, "<HTML>\n<HEAD>\n");
    fprintf(file, "<META HTTP-EQUIV=\"Content-Type\" "
            "CONTENT=\"text/html; charset=UTF-8\">\n");
    fprintf(file, "<META NAME=\"hexdata\" CONTENT=\"GHex export to HTML\">\n");
    fprintf(file, "</HEAD>\n<BODY>\n");

    fprintf(file, "<CENTER>");
    fprintf(file, "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">\n");
    fprintf(file, "<TR>\n<TD COLSPAN=\"3\"><B>%s</B></TD>\n</TR>\n",
            doc->file_name?doc->file_name:doc->path_end);
    fprintf(file, "<TR>\n<TD COLSPAN=\"3\">&nbsp;</TD>\n</TR>\n");
    for(page = 0; page < pages; page++) {
        fprintf(file, "<TR>\n<TD>\n<A HREF=\"%s%08d.html\"><PRE>", base_name, page);
        fprintf(file, _("Page"));
        fprintf(file, " %d</PRE></A>\n</TD>\n<TD>&nbsp;</TD>\n<TD VALIGN=\"CENTER\"><PRE>%08x -", page+1, page*cpl*lpp);
        fprintf(file, " %08x</PRE></TD>\n</TR>\n", MIN((page+1)*cpl*lpp-1, doc->file_size-1));
    }
    fprintf(file, "</TABLE>\n</CENTER>\n");
    fprintf(file, "<HR WIDTH=\"100%%\">");
    fprintf(file, _("Hex dump generated by"));
    fprintf(file, " <B>"LIBGTKHEX_RELEASE_STRING"</B>\n");
    fprintf(file, "</BODY>\n</HTML>\n");
    fclose(file);

    progress_dialog = gtk_dialog_new();
    gtk_window_set_resizable(GTK_WINDOW(progress_dialog), FALSE);
    gtk_window_set_modal(GTK_WINDOW(progress_dialog), TRUE);
    g_signal_connect(G_OBJECT(progress_dialog), "delete-event",
                     G_CALLBACK(ignore_cb), NULL);
    gtk_window_set_title(GTK_WINDOW(progress_dialog),
                         _("Saving to HTML..."));
    progress_bar = gtk_progress_bar_new();
    gtk_widget_show(progress_bar);
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(progress_dialog)->vbox),
                      progress_bar);
    gtk_widget_show(progress_dialog);

    pos = start;
    g_object_ref(G_OBJECT(doc));
    for(page = 0; page < pages; page++) {
        if((page%update_pages) == 0) {
            gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),
                                          (gdouble)page/(gdouble)pages);
            progress_str = g_strdup_printf("%d/%d", page, pages);
            gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar),
                                      progress_str);
            g_free(progress_str);
            while(gtk_events_pending())
                gtk_main_iteration();
        }
        /* write page header */
        page_name = g_strdup_printf("%s/%s%08d.html",
                                    html_path, base_name, page);
        file = fopen(page_name, "w");
        g_free(page_name);
        if(!file)
            break;
        /* write header */
        fprintf(file, "<HTML>\n<HEAD>\n");
        fprintf(file, "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">\n");
        fprintf(file, "<META NAME=\"hexdata\" CONTENT=\"GHex export to HTML\">\n");
        fprintf(file, "</HEAD>\n<BODY>\n");
        /* write top table |previous|filename: page/pages|next| */
        fprintf(file, "<TABLE BORDER=\"0\" CELLSPACING=\"0\" WIDTH=\"100%%\">\n");
        fprintf(file, "<TR>\n<TD WIDTH=\"33%%\">\n");
        if(page > 0) {
            fprintf(file, "<A HREF=\"%s%08d.html\">", base_name, page-1);
            fprintf(file, _("Previous page"));
            fprintf(file, "</A>");
        }
        else
            fprintf(file, "&nbsp;");
        fprintf(file, "\n</TD>\n");
        fprintf(file, "<TD WIDTH=\"33%%\" ALIGN=\"CENTER\">\n");
        fprintf(file, "<A HREF=\"%s.html\">", base_name);
        fprintf(file, "%s:", doc->path_end);
        fprintf(file, "</A>");
        fprintf(file, " %d/%d", page+1, pages);
        fprintf(file, "\n</TD>\n");
        fprintf(file, "<TD WIDTH=\"33%%\" ALIGN=\"RIGHT\">\n");
        if(page < pages - 1) {
            fprintf(file, "<A HREF=\"%s%08d.html\">", base_name, page+1);
            fprintf(file, _("Next page"));
            fprintf(file, "</A>");
        }
        else
            fprintf(file, "&nbsp;");
        fprintf(file, "\n</TD>\n");
        fprintf(file, "</TR>\n</TABLE>\n");

        /* now the actual data */
        fprintf(file, "<CENTER>\n");
        fprintf(file, "<TABLE BORDER=\"1\" CELLSPACING=\"2\" CELLPADDING=\"2\">\n");
        fprintf(file, "<TR>\n<TD>\n");
        fprintf(file, "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">\n");
        for(line = 0; line < lpp && pos + line*cpl < doc->file_size; line++) {
            /* offset of line*/
            fprintf(file, "<TR>\n<TD>\n");
            fprintf(file, "<PRE>%08x</PRE>\n", pos + line*cpl);
            fprintf(file, "</TD>\n</TR>\n");
        }
        fprintf(file, "</TABLE>\n");
        fprintf(file, "</TD>\n<TD>\n");
        fprintf(file, "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">\n");
        c = 0;
        for(line = 0; line < lpp; line++) {
            /* hex data */
            fprintf(file, "<TR>\n<TD>\n<PRE>");
            while(pos + c < end) {
                fprintf(file, "%02x", hex_document_get_byte(doc, pos + c));
                c++;
                if(c%cpl == 0)
                    break;
                if(c%cpw == 0)
                    fprintf(file, " ");
            }
            fprintf(file, "</PRE>\n</TD>\n</TR>\n");
        }
        fprintf(file, "</TABLE>\n");
        fprintf(file, "</TD>\n<TD>\n");
        fprintf(file, "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">\n");
        c = 0;
        for(line = 0; line < lpp; line++) {
            /* ascii data */
            fprintf(file, "<TR>\n<TD>\n<PRE>");
            while(pos + c < end) {
                b = hex_document_get_byte(doc, pos + c);
                if(b >= 0x20)
                    fprintf(file, "%c", b);
                else
                    fprintf(file, ".");
                c++;
                if(c%cpl == 0)
                    break;
            }
            fprintf(file, "</PRE></TD>\n</TR>\n");
            if(pos >= end)
                line = lpp;
        }
        pos += c;
        fprintf(file, "</TD>\n</TR>\n");
        fprintf(file, "</TABLE>\n");
        fprintf(file, "</TABLE>\n</CENTER>\n");
        fprintf(file, "<HR WIDTH=\"100%%\">");
        fprintf(file, _("Hex dump generated by"));
        fprintf(file, " <B>" LIBGTKHEX_RELEASE_STRING "</B>\n");
        fprintf(file, "</BODY>\n</HTML>\n");
        fclose(file);
    }
    g_object_unref(G_OBJECT(doc));
    gtk_widget_destroy(progress_dialog);

    return TRUE;
}
Exemple #19
0
void notification_popup_msg(MsgInfo *msginfo)
{
  FolderType ftype;
#if HAVE_LIBNOTIFY
  gchar *uistr;
#else
  NotificationPopup *ppopup;
  gboolean retval;
#endif
  NotificationFolderType nftype;

  nftype = F_TYPE_MAIL;

  if(!msginfo || !notify_config.popup_show)
    return;

  if(notify_config.popup_folder_specific) {
    guint id;
    GSList *list;
    gchar *identifier;
    gboolean found = FALSE;

    if(!(msginfo->folder))
      return;

    identifier = folder_item_get_identifier(msginfo->folder);

    id =
      notification_register_folder_specific_list(POPUP_SPECIFIC_FOLDER_ID_STR);
    list = notification_foldercheck_get_list(id);
    for(; (list != NULL) && !found; list = g_slist_next(list)) {
      gchar *list_identifier;
      FolderItem *list_item = (FolderItem*) list->data;

      list_identifier = folder_item_get_identifier(list_item);
      if(!strcmp2(list_identifier, identifier))
	found = TRUE;

      g_free(list_identifier);
    }
    g_free(identifier);

    if(!found)
      return;
  }

  ftype = msginfo->folder->folder->klass->type;

  G_LOCK(popup);
#ifdef HAVE_LIBNOTIFY
  /* Check out which type to notify about */
  switch(ftype) {
  case F_MH:
  case F_MBOX:
  case F_MAILDIR:
  case F_IMAP:
    nftype = F_TYPE_MAIL;
    break;
  case F_NEWS:
    nftype = F_TYPE_NEWS;
    break;
  case F_UNKNOWN:
    if((uistr = msginfo->folder->folder->klass->uistr) == NULL) {
      G_UNLOCK(popup);
      return;
    }
    else if(!strcmp(uistr, "vCalendar"))
      nftype = F_TYPE_CALENDAR;
    else if(!strcmp(uistr, "RSSyl"))
      nftype = F_TYPE_RSS;
    else {
      debug_print("Notification Plugin: Unknown folder type %d\n",ftype);
      G_UNLOCK(popup);
      return;
    }
    break;
  default:
    debug_print("Notification Plugin: Unknown folder type %d\n",ftype);
    G_UNLOCK(popup);
    return;
  }

  notification_libnotify_add_msg(msginfo, nftype);
#else /* !HAVE_LIBNOTIFY */
  ppopup = &popup;
  retval = notification_popup_add_msg(msginfo);

  /* Renew timeout only when the above call was successful */
  if(retval) {
    if(ppopup->timeout_id)
      g_source_remove(ppopup->timeout_id);
    ppopup->timeout_id = g_timeout_add(notify_config.popup_timeout,
                       popup_timeout_fun,
                       GINT_TO_POINTER(nftype));
  }

  #endif /* !HAVE_LIBNOTIFY */

  G_UNLOCK(popup);

#ifndef HAVE_LIBNOTIFY
  /* GUI update */
  while(gtk_events_pending())
    gtk_main_iteration();
#endif /* !HAVE_LIBNOTIFY */

}
Exemple #20
0
void OptionsX (void)
{
  if (ixdone == 1)
  {
    ixdone = 0;
    if (ioptionsx == 0)
    {
      ioptionsx = 1;
    }
    else
    {
      ioptionsx = 0;
    }

    gtk_container_remove (GTK_CONTAINER (changebutton), cbpixmapwid);
    if (ioptionsx == 1)
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/1x.png");
    }
    else
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/1.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap = gdk_imlib_move_image (im3);
    cbpixmapwid = gtk_pixmap_new (cbpixmap, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton), cbpixmapwid);
    gtk_widget_show (cbpixmapwid);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton2), cbpixmapwid2);
    if (ioptionsx == 1)
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/2x.png");
    }
    else
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/2.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap2 = gdk_imlib_move_image (im3);
    cbpixmapwid2 = gtk_pixmap_new (cbpixmap2, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton2), cbpixmapwid2);
    gtk_widget_show (cbpixmapwid2);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton3), cbpixmapwid3);
    if (ioptionsx == 1)
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/3x.png");
    }
    else
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/3.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap3 = gdk_imlib_move_image (im3);
    cbpixmapwid3 = gtk_pixmap_new (cbpixmap3, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton3), cbpixmapwid3);
    gtk_widget_show (cbpixmapwid3);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton4), cbpixmapwid4);
    if (ioptionsx == 1)
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/4x.png");
    }
    else
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/4.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap4 = gdk_imlib_move_image (im3);
    cbpixmapwid4 = gtk_pixmap_new (cbpixmap4, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton4), cbpixmapwid4);
    gtk_widget_show (cbpixmapwid4);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton5), cbpixmapwid5);
    if (ioptionsx == 1)
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/5x.png");
    }
    else
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/5.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap5 = gdk_imlib_move_image (im3);
    cbpixmapwid5 = gtk_pixmap_new (cbpixmap5, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton5), cbpixmapwid5);
    gtk_widget_show (cbpixmapwid5);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebuttonx), cbpixmapwidx);
    if (ioptionsx == 1)
    {
    im3 = gdk_imlib_load_image (PKGDATADIR"pix/5bx.png");
    }
    else
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/5b.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmapx = gdk_imlib_move_image (im3);
    cbpixmapwidx = gtk_pixmap_new (cbpixmapx, NULL);
    gtk_container_add (GTK_CONTAINER (changebuttonx), cbpixmapwidx);
    gtk_widget_show (cbpixmapwidx);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton6), cbpixmapwid6);
    if (ioptionsx == 1)
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/6x.png");
    }
    else
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/6.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap6 = gdk_imlib_move_image (im3);
    cbpixmapwid6 = gtk_pixmap_new (cbpixmap6, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton6), cbpixmapwid6);
    gtk_widget_show (cbpixmapwid6);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton7), cbpixmapwid7);
    if ((ioptionsx == 1) && (itooltips == 1))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/6onx.png");
    }
    if ((ioptionsx == 1) && (itooltips == 0))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/6offx.png");
    }
    if ((ioptionsx == 0) && (itooltips == 1))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/6on.png");
    }
    if ((ioptionsx == 0) && (itooltips == 0))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/6off.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap7 = gdk_imlib_move_image (im3);
    cbpixmapwid7 = gtk_pixmap_new (cbpixmap7, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton7), cbpixmapwid7);
    gtk_widget_show (cbpixmapwid7);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton8), cbpixmapwid8);
    if (ioptionsx == 1)
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/7x.png");
    }
    else
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/7.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap8 = gdk_imlib_move_image (im3);
    cbpixmapwid8 = gtk_pixmap_new (cbpixmap8, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton8), cbpixmapwid8);
    gtk_widget_show (cbpixmapwid8);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton9), cbpixmapwid9);
    if ((ioptionsx == 1) && (ishowlast == 1))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/7onx.png");
    }
    if ((ioptionsx == 1) && (ishowlast == 0))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/7offx.png");
    }
    if ((ioptionsx == 0) && (ishowlast == 1))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/7on.png");
    }
    if ((ioptionsx == 0) && (ishowlast == 0))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/7off.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap9 = gdk_imlib_move_image (im3);
    cbpixmapwid9 = gtk_pixmap_new (cbpixmap9, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton9), cbpixmapwid9);
    gtk_widget_show (cbpixmapwid9);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton10), cbpixmapwid10);
    if (ioptionsx == 1)
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/8x.png");
    }
    else
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/8.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap10 = gdk_imlib_move_image (im3);
    cbpixmapwid10 = gtk_pixmap_new (cbpixmap10, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton10), cbpixmapwid10);
    gtk_widget_show (cbpixmapwid10);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton11), cbpixmapwid11);
    if ((ioptionsx == 1) && (isound == 1))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/8onx.png");
    }
    if ((ioptionsx == 1) && (isound == 0))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/8offx.png");
    }
    if ((ioptionsx == 0) && (isound == 1))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/8on.png");
    }
    if ((ioptionsx == 0) && (isound == 0))
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/8off.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap11 = gdk_imlib_move_image (im3);
    cbpixmapwid11 = gtk_pixmap_new (cbpixmap11, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton11), cbpixmapwid11);
    gtk_widget_show (cbpixmapwid11);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton12), cbpixmapwid12);
    if (ioptionsx == 1)
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/9x.png");
    }
    else
    {
      im3 = gdk_imlib_load_image (PKGDATADIR"pix/9.png");
    }
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap12 = gdk_imlib_move_image (im3);
    cbpixmapwid12 = gtk_pixmap_new (cbpixmap12, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton12), cbpixmapwid12);
    gtk_widget_show (cbpixmapwid12);
    gdk_flush ();

    gtk_container_remove (GTK_CONTAINER (changebutton13), cbpixmapwid13);
    if (ioptionsx == 1)
    {
      sprintf (cThePng3, PKGDATADIR"pix/9%ix.png", ihandicap);
    }
    else
    {
      sprintf (cThePng3, PKGDATADIR"pix/9%i.png", ihandicap);
    }
    im3 = gdk_imlib_load_image (cThePng3);
    w3 = im3->rgb_width;
    h3 = im3->rgb_height;
    gdk_imlib_render (im3, w3, h3);
    cbpixmap13 = gdk_imlib_move_image (im3);
    cbpixmapwid13 = gtk_pixmap_new (cbpixmap13, NULL);
    gtk_container_add (GTK_CONTAINER (changebutton13), cbpixmapwid13);
    gtk_widget_show (cbpixmapwid13);
    gdk_flush ();
    while (gtk_events_pending ())
    {
      gtk_main_iteration ();
    }
    ixdone = 1;
  }
}
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;
}
Exemple #22
0
/* ----------------------------------------------------------------------------*/
int main(int argc,char* argv[]) {
    gboolean retry;
    GtkWidget* dialog;
    gint result;
    int i;

    gtk_init(&argc,&argv);

    fprintf(stderr,"gHermes Version %s\n",VERSION);

    strcpy(propertyPath,"gHermes.properties");
    // strcpy(soundCardName,"HPSDR");
    ozy_set_interface("eth0");
    processCommands(argc,argv);
    loadProperties(propertyPath);

#ifdef ALEX_TEST
    alex_rx_test_load("alex_rx_test.csv");
    alex_tx_test_load("alex_tx_test.csv");
#endif

    //init_cw();

    // initialize DttSP
    Setup_SDR();
    Release_Update();
    SetTRX(0,FALSE); // thread 0 is for receive
    SetTRX(1,TRUE);  // thread 1 is for transmit
    SetThreadProcessingMode(0,2); // set thread 0 to RUN
    SetThreadProcessingMode(1,2); // set thread 1 to RUN
    SetSubRXSt(0,0,TRUE);

    reset_for_buflen(0,buffer_size);
    reset_for_buflen(1,buffer_size);


    // initialize ozy (default 48K)
    //ozyRestoreState();
    do {
        switch(ozy_init()) {
            case -1: // cannot find ozy
                dialog = gtk_message_dialog_new (NULL,
                                                 GTK_DIALOG_DESTROY_WITH_PARENT,
                                                 GTK_MESSAGE_ERROR,
                                                 GTK_BUTTONS_YES_NO,
                                                 "Cannot locate Ozy!\n\nIs it powered on and plugged in?");
                gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"Retry?");
                gtk_window_set_title(GTK_WINDOW(dialog),"GHPSDR");
                result = gtk_dialog_run (GTK_DIALOG (dialog));
                switch (result) {
                    case GTK_RESPONSE_YES:
                        retry=TRUE;
                        break;
                    default:
                        exit(1);
                        break;
                }
                gtk_widget_destroy (dialog);
                break;
            case -2: // found but needs initializing
                result=fork();
                if(result==0) {
                    // child process - exec initozy
                    fprintf(stderr,"exec initozy\n");
                    result=execl("initozy",NULL,NULL);
                    fprintf(stderr,"exec returned %d\n",result);
                    exit(result);
                } else if(result>0) {
                    // wait for the forked process to terminate
                    dialog = gtk_message_dialog_new (NULL,
                                                 GTK_DIALOG_DESTROY_WITH_PARENT,
                                                 GTK_MESSAGE_INFO,
                                                 GTK_BUTTONS_NONE,
                                                 "Initializing Ozy");
                    gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"Please Wait ...");
                    gtk_window_set_title(GTK_WINDOW(dialog),"GHPSDR");
                    gtk_widget_show_all (dialog);
                    while (gtk_events_pending ())
                        gtk_main_iteration ();

                    wait(&result);
                    fprintf(stderr,"wait status=%d\n",result);
                    retry=TRUE;
                }
                gtk_widget_destroy (dialog);
                break;

            case -3: // did not find metis
                dialog = gtk_message_dialog_new (NULL,
                                                 GTK_DIALOG_DESTROY_WITH_PARENT,
                                                 GTK_MESSAGE_ERROR,
                                                 GTK_BUTTONS_YES_NO,
                                                 "Cannot locate Metis on interface %s!",
                                                 ozy_get_interface());
                gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"Retry?");
                gtk_window_set_title(GTK_WINDOW(dialog),"GHPSDR");
                result = gtk_dialog_run (GTK_DIALOG (dialog));
                switch (result) {
                    case GTK_RESPONSE_YES:
                        retry=TRUE;
                        break;
                    default:
                        exit(1);
                        break;
                }
                gtk_widget_destroy (dialog);
                break;
            default:
                retry=FALSE;
                break;
        }
    } while(retry);

    mainRootX=0;
    mainRootY=0;

    cwPitch =600;

    restoreInitialState();

    //SetKeyerResetSize(4096);
    //NewKeyer(600.0f,TRUE,0.0f,3.0f,25.0f,48000.0f);
    //SetKeyerPerf(FALSE);
    //StartKeyer();

    initColors();
    //gtk_key_snooper_install((GtkKeySnoopFunc)keyboardSnooper,NULL);

    //bandscopeRestoreState();
    //bandscopeWindow=buildBandscopeUI();
   
    //bandscope_controlRestoreState();
    //bandscope_controlWindow=buildBandscope_controlUI();
   
    meterRestoreState();
    meterWindow=buildMeterUI();

    vfoRestoreState();
    vfoWindow=buildVfoUI();

    bandRestoreState();
    bandWindow=buildBandUI();

    modeRestoreState();
    modeWindow=buildModeUI();

    filterRestoreState();
    filterWindow=buildFilterUI();

    displayRestoreState();
    displayWindow=buildDisplayUI();

    audioRestoreState();
    audioWindow=buildAudioUI();


    agcRestoreState();
    agcWindow=buildAgcUI();

    preampWindow=buildPreampUI();
    zoomWindow=buildZoomUI();

    receiverRestoreState();
    receiverWindow=buildReceiverUI();

    volumeRestoreState();
    volumeWindow=buildVolumeUI();

    keyerRestoreState();
    keyerWindow=buildKeyerUI();
    cwPitch =(int)cw_sidetone_frequency;

    transmitRestoreState();
    transmitWindow=buildTransmitUI();
    mic_meterWindow=buildMic_MeterUI();

    subrxRestoreState();
    subrxWindow=buildSubRxUI();

    restoreState();


    // build the Main UI
    buildMainUI();

    //setSoundcard(getSoundcardId(soundCardName));

    audio_stream_init();
    
    hamlibserv_init();

    gtk_main();

    return 0;
}
static visualizer_t * visualizer_create()
  {
  const bg_plugin_info_t * info;
  char * tmp_path;
  int row, col;
  
  GtkWidget * main_table;
  GtkWidget * table;
  GtkWidget * box;
  
  visualizer_t * ret;
  bg_cfg_section_t * cfg_section;
  
  ret = calloc(1, sizeof(*ret));
  
  ret->cb.motion_callback = motion_callback;
  ret->cb.data = ret;
  
  window_init(ret, &ret->normal_window, 0);
  window_init(ret, &ret->fullscreen_window, 1);
  ret->current_window = &ret->normal_window;

  ret->log_window = bg_gtk_log_window_create(log_close_callback, ret,
                                             TR("Gmerlin visualizer"));
  
  ret->config_button =
    create_pixmap_button(ret, "config_16.png", TRS("Configure"));
  ret->plugin_button =
    create_pixmap_button(ret, "plugin_16.png", TRS("Recording and display plugins"));
  ret->restart_button =
    create_pixmap_button(ret, "refresh_16.png", TRS("Restart visualization"));
  ret->quit_button =
    create_pixmap_button(ret, "quit_16.png", TRS("Quit"));
  ret->fullscreen_button =
    create_pixmap_button(ret, "fullscreen_16.png", TRS("Fullscreen mode"));
  ret->nofullscreen_button =
    create_pixmap_button(ret, "windowed_16.png", TRS("Leave fullscreen mode"));

  ret->log_button = create_pixmap_button(ret,
                                         "log_16.png",
                                         TRS("Show log window"));
  ret->about_button = create_pixmap_button(ret,
                                           "about_16.png",
                                           TRS("About Gmerlin visualizer"));
  ret->help_button = create_pixmap_button(ret,
                                          "help_16.png",
                                          TRS("Launch help in a webwroswer"));
  
  ret->fps = gtk_label_new("Fps: --:--");
  gtk_misc_set_alignment(GTK_MISC(ret->fps), 0.0, 0.5);
  gtk_widget_show(ret->fps);
  
  gtk_widget_hide(ret->nofullscreen_button);
  
  //  bg_gtk_box_pack_start_defaults(GTK_BOX(mainbox),
  //                              bg_gtk_vumeter_get_widget(ret->vumeter));
  
  ret->toolbar = gtk_event_box_new();

  gtk_widget_set_events(ret->toolbar,
                        GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
  
  g_signal_connect(G_OBJECT(ret->toolbar), "enter-notify-event",
                   G_CALLBACK(crossing_callback), (gpointer*)ret);
  
  g_signal_connect(G_OBJECT(ret->toolbar), "leave-notify-event",
                   G_CALLBACK(crossing_callback), (gpointer*)ret);

  
  g_object_ref(ret->toolbar); /* Must be done for widgets, which get
                                 reparented after */
  
  ret->vumeter = bg_gtk_vumeter_create(2, 0);
  
  /* Create actual objects */

  /* Create plugin regsitry */
  ret->cfg_reg = bg_cfg_registry_create();
  tmp_path =  bg_search_file_read("visualizer", "config.xml");
  bg_cfg_registry_load(ret->cfg_reg, tmp_path);
  if(tmp_path)
    free(tmp_path);
  
  cfg_section = bg_cfg_registry_find_section(ret->cfg_reg, "plugins");
  ret->plugin_reg = bg_plugin_registry_create(cfg_section);
  ret->visualizer = bg_visualizer_create(ret->plugin_reg);

  bg_visualizer_set_callbacks(ret->visualizer, &ret->cb);
  
  /* Create vis plugin widget */

  ret->vis_plugins =
    bg_gtk_plugin_widget_single_create(TR("Visualization"),
                                       ret->plugin_reg,
                                       BG_PLUGIN_VISUALIZATION,
                                       BG_PLUGIN_VISUALIZE_FRAME |
                                       BG_PLUGIN_VISUALIZE_GL);

  bg_gtk_plugin_widget_single_set_change_callback(ret->vis_plugins,
                                                  set_vis_plugin,
                                                  ret);

  bg_gtk_plugin_widget_single_set_parameter_callback(ret->vis_plugins,
                                                     set_vis_parameter,
                                                     ret);
  
  /* Create audio and video plugin widgets */
  
  plugin_window_init(&ret->plugin_window, ret);

  /* Get ov info */
  
  ret->ov_info =
    bg_gtk_plugin_widget_single_get_plugin(ret->plugin_window.ov_plugins);
  
  /* Load recording plugin */
  ret->ra_info =
    bg_gtk_plugin_widget_single_get_plugin(ret->plugin_window.ra_plugins);
  
  /* Create config stuff */
  
  ret->visualizer_section =
    bg_cfg_registry_find_section(ret->cfg_reg, "visualizer");
  ret->general_section =
    bg_cfg_registry_find_section(ret->cfg_reg, "general");
  ret->log_section =
    bg_cfg_registry_find_section(ret->cfg_reg, "log");
  
  ret->cfg_dialog = create_cfg_dialog(ret);


  
  /* Pack everything */

  main_table = gtk_table_new(2, 2, 0);

  gtk_table_set_row_spacings(GTK_TABLE(main_table), 5);
  gtk_table_set_col_spacings(GTK_TABLE(main_table), 5);
  gtk_container_set_border_width(GTK_CONTAINER(main_table), 5);
  
  table = gtk_table_new(1, 4, 0);

  gtk_table_set_row_spacings(GTK_TABLE(table), 5);
  gtk_table_set_col_spacings(GTK_TABLE(table), 5);
  gtk_container_set_border_width(GTK_CONTAINER(table), 5);
  
  
  row = 0;
  col = 0;
  bg_gtk_plugin_widget_single_attach(ret->vis_plugins,
                                     table,
                                     &row, &col);
  gtk_widget_show(table);
  
  gtk_table_attach(GTK_TABLE(main_table), table, 0, 1, 0, 1,
                   GTK_FILL, GTK_SHRINK, 0, 0);
  
  box = gtk_hbox_new(0, 0);
  gtk_box_pack_start(GTK_BOX(box), ret->plugin_button,
                     FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box), ret->config_button,
                     FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box), ret->restart_button,
                     FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box), ret->fullscreen_button,
                     FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box), ret->nofullscreen_button,
                     FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box), ret->log_button,
                     FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box), ret->about_button,
                     FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box), ret->help_button,
                     FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box), ret->quit_button,
                     FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(box), ret->fps, TRUE, TRUE, 5);
  gtk_widget_show(box);
  
  gtk_table_attach(GTK_TABLE(main_table), box, 0, 1, 1, 2,
                   GTK_FILL, GTK_SHRINK, 0, 0);

  gtk_table_attach(GTK_TABLE(main_table),
                   bg_gtk_vumeter_get_widget(ret->vumeter),
                   1, 2, 0, 2,
                   GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);

  
  gtk_widget_show(main_table);
  
  gtk_container_add(GTK_CONTAINER(ret->toolbar), main_table);
  
  //  gtk_widget_show(ret->toolbar);
  
  /* Start with non-fullscreen mode */
  attach_toolbar(ret, &ret->normal_window);
  
  apply_config(ret);
  
  /* Get visualization plugin */
  info = bg_gtk_plugin_widget_single_get_plugin(ret->vis_plugins);
  bg_visualizer_set_vis_plugin(ret->visualizer, info);
  
  /* Initialize stuff */
  open_audio(ret);
  open_vis(ret);

  
  gtk_widget_show(ret->current_window->window);

  if(ret->width && ret->height)
    gtk_decorated_window_move_resize_window(GTK_WINDOW(ret->current_window->window),
                                            ret->x, ret->y,
                                            ret->width, ret->height);
  else
    gtk_decorated_window_move_resize_window(GTK_WINDOW(ret->current_window->window),
                                            100, 100,
                                            640, 480);
  
  while(gdk_events_pending() || gtk_events_pending())
    gtk_main_iteration();
  
  
  g_idle_add(idle_func, ret);
  
  g_timeout_add(3000, toolbar_timeout, ret);
  g_timeout_add(1000, fps_timeout, ret);
  
  return ret;
  }
Exemple #24
0
char *inputback(struct filetransfer *ft, enum ftinput type, const char *prompt, char *def)
{
	/* if renaming and auto rename checked... */
	if(type == FT_RENAME &&
#ifdef CFG_USE_RADIO
		gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(opt_AutoRename))
#else
		gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(opt_AutoRename))
#endif
			)
		return def;

	GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	GtkWidget *ent = gtk_entry_new();
	GtkWidget *lbl = gtk_label_new(prompt);
	GtkWidget *hbx = gtk_hbox_new(FALSE, 0);
	GtkWidget *vbx = gtk_vbox_new(FALSE, 0);
	GtkWidget *btn = gtk_button_new();
	int clicked = 0, winclosed = 0;

	(void)ft;

	gtk_entry_set_text(GTK_ENTRY(ent), def);
	gtk_button_set_label(GTK_BUTTON(btn), prompt);

	g_signal_connect(G_OBJECT(btn), "clicked",  G_CALLBACK(widget_generic_callback), &clicked);
	g_signal_connect(G_OBJECT(win), "destroy",  G_CALLBACK(widget_generic_callback), &winclosed);

	gtk_container_add(GTK_CONTAINER(hbx), ent);
	gtk_container_add(GTK_CONTAINER(hbx), btn);
	gtk_container_add(GTK_CONTAINER(vbx), lbl);
	gtk_container_add(GTK_CONTAINER(vbx), hbx);

	gtk_container_add(GTK_CONTAINER(win), vbx);

	gtk_window_set_transient_for(GTK_WINDOW(win), GTK_WINDOW(winMain));
	gtk_window_set_modal(GTK_WINDOW(win), TRUE);
	gtk_window_set_destroy_with_parent(GTK_WINDOW(win), TRUE);

	gtk_widget_show_all(win);

	/* don't test the widget - could be closed */
	while(!winclosed && !clicked){
		while(gtk_events_pending())
			gtk_main_iteration();
		sleep_ms(25);
	}

	if(clicked){
		/* safe to access ent here - widget hasn't been destroyed */
		const char *txt = gtk_entry_get_text(GTK_ENTRY(ent));
		char *ret = malloc(strlen(txt) + 1);
		if(!ret)
			g_error("couldn't allocate %ld bytes", (long)(strlen(txt) + 1));
		strcpy(ret, txt);

		gtk_widget_destroy(win);

		return ret;
	}else{
		return NULL;
	}
}
Exemple #25
0
void perform_uninstall_slot(GtkWidget* w, gpointer data)
{
    GtkWidget *notebook;
    GtkWidget *progress;
    GtkWidget *widget;
    GList *list, *poopy, *clist;
    GtkWidget *button;
    component_list *component;
    size_t size, total;
    char text[1024];
	const char *message;

	/* Set through environment to hide questions, and assume Yes */
	int show_messages;
	const char *env;

	show_messages = 1;

	env = getenv("SETUP_NO_PROMPT");
	if ( env && atoi(env) )
		show_messages = 0;


    /* First switch to the next notebook page */
    notebook = glade_xml_get_widget(uninstall_glade, "uninstall_notebook");
    gtk_notebook_set_page(GTK_NOTEBOOK(notebook), 1);
    widget = glade_xml_get_widget(uninstall_glade, "finished_button");
    if ( widget ) {
        gtk_button_set_sensitive(widget, FALSE);
    }

    /* Now uninstall all the selected components */
    progress = glade_xml_get_widget(uninstall_glade, "uninstall_progress");
    size = 0;
    total = calculate_recovered_space();
    widget = glade_xml_get_widget(uninstall_glade, "uninstall_vbox");
    list = gtk_container_children(GTK_CONTAINER(widget));
    while ( list && ! uninstall_cancelled ) {
        widget = GTK_WIDGET(list->data);
        poopy = gtk_container_children(GTK_CONTAINER(widget));
        widget = GTK_WIDGET(poopy->data);
        /* First do the addon components */
        clist = gtk_container_children(GTK_CONTAINER(widget));
        while ( clist && ! uninstall_cancelled ) {
            button = GTK_WIDGET(clist->data);
            if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ) {
                component = gtk_object_get_data(GTK_OBJECT(button), "data");
                if ( loki_isdefault_component(component->component) ) {
                    clist = clist->next;
                    continue;
                }
                /* Put up the status */
                snprintf(text, sizeof(text), "%s: %s",
                        component->info->description,
                        loki_getname_component(component->component));
                set_status_text(text);

                /* See if the user wants to cancel the uninstall */
                while( gtk_events_pending() ) {
                    gtk_main_iteration();
                }
				
				/* Display an optional message to the user */
				message = loki_getmessage_component(component->component);
				if (show_messages && message && !display_message(message, BUTTON_OK|BUTTON_ABORT) ) {
                    clist = clist->next;
					uninstall_cancelled = 1;
					break;
				}

                /* Remove the component */
                if ( ! uninstall_component(component->component, component->info) ) {
					uninstall_cancelled = 2;
					snprintf(text, sizeof(text), _("Uninstallation of component %s has failed!\n"
												   "The whole uninstallation may be incomplete.\n"),
							 loki_getname_component(component->component));
					display_message(text, BUTTON_ABORT);
					break;
				}

                /* Update the progress bar */
                if ( total && progress ) {
                    size += component->size/1024;
                    gtk_progress_set_percentage(GTK_PROGRESS(progress),
                                                (float)size/total);
                }
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);

                /* See if the user wants to cancel the uninstall */
                while( gtk_events_pending() ) {
                    gtk_main_iteration();
                }
            }
            clist = clist->next;
        }
        /* Now do the primary components */
        clist = gtk_container_children(GTK_CONTAINER(widget));
        while ( clist && ! uninstall_cancelled ) {
            button = GTK_WIDGET(clist->data);
            if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ) {
                component = gtk_object_get_data(GTK_OBJECT(button), "data");
                if ( ! loki_isdefault_component(component->component) ) {
                    clist = clist->next;
                    continue;
                }
                /* Put up the status */
                strncpy(text, component->info->description, sizeof(text));
                set_status_text(text);

                /* See if the user wants to cancel the uninstall */
                while( gtk_events_pending() ) {
                    gtk_main_iteration();
                }

				/* Display an optional message to the user */
				message = loki_getmessage_component(component->component);
				if ( message && !display_message(message, BUTTON_OK|BUTTON_ABORT) ) {
                    clist = clist->next;
					uninstall_cancelled = 1;
					break;
				}

                /* Remove the component */
                if ( ! perform_uninstall(component->product, component->info, 0) ) {
					uninstall_cancelled = 2;
					snprintf(text, sizeof(text), _("Uninstallation of product %s has failed!\n"
												   "Aborting the rest of the uninstallation.\n"),
							 component->info->description);
					display_message(text, BUTTON_ABORT);
					break;
				}
                remove_product(component->product);

                /* Update the progress bar */
                if ( total && progress ) {
                    size += component->size/1024;
                    gtk_progress_set_percentage(GTK_PROGRESS(progress),
                                                (float)size/total);
                }

                /* See if the user wants to cancel the uninstall */
                while( gtk_events_pending() ) {
                    gtk_main_iteration();
                }
                break;
            }
            clist = clist->next;
        }
        list = list->next;
    }
    switch ( uninstall_cancelled ) {
	case 1:
        set_status_text(_("Uninstall cancelled"));
		break;
	case 2:
        set_status_text(_("Uninstall aborted"));
		break;
	default:
        set_status_text(_("Uninstall complete"));
		gtk_progress_set_percentage(GTK_PROGRESS(progress), 1.0f);
		break;
    }
    widget = glade_xml_get_widget(uninstall_glade, "cancel_button");
    if ( widget ) {
        gtk_button_set_sensitive(widget, FALSE);
    }
    widget = glade_xml_get_widget(uninstall_glade, "finished_button");
    if ( widget ) {
        gtk_button_set_sensitive(widget, TRUE);
    }
}
Exemple #26
0
bool wxClipboard::GetData( wxDataObject& data )
{
    wxCHECK_MSG( m_open, false, wxT("clipboard not open") );

    /* get formats from wxDataObjects */
    wxDataFormat *array = new wxDataFormat[ data.GetFormatCount() ];
    data.GetAllFormats( array );

    for (size_t i = 0; i < data.GetFormatCount(); i++)
    {
        wxDataFormat format( array[i] );

        wxLogTrace( TRACE_CLIPBOARD,
                    wxT("wxClipboard::GetData: requested format: %s"),
                    format.GetId().c_str() );

        /* is data supported by clipboard ? */

        /* store requested format to be asked for by callbacks */
        m_targetRequested = format;

        wxCHECK_MSG( m_targetRequested, false, wxT("invalid clipboard format") );

        m_formatSupported = false;

       /* perform query. this will set m_formatSupported to
          true if m_targetRequested is supported.
          also, we have to wait for the "answer" from the
          clipboard owner which is an asynchronous process.
          therefore we set m_waiting = true here and wait
          until the callback "targets_selection_received"
          sets it to false */

        m_waiting = true;

        gtk_selection_convert( m_targetsWidget,
                           m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
                                        : g_clipboardAtom,
                           g_targetsAtom,
                           (guint32) GDK_CURRENT_TIME );

        while (m_waiting) gtk_main_iteration();

        if (!m_formatSupported) continue;

        /* store pointer to data object to be filled up by callbacks */
        m_receivedData = &data;

        /* store requested format to be asked for by callbacks */
        m_targetRequested = format;

        wxCHECK_MSG( m_targetRequested, false, wxT("invalid clipboard format") );

        /* start query */
        m_formatSupported = false;

        /* ask for clipboard contents.  this will set
           m_formatSupported to true if m_targetRequested
           is supported.
           also, we have to wait for the "answer" from the
           clipboard owner which is an asynchronous process.
           therefore we set m_waiting = true here and wait
           until the callback "targets_selection_received"
           sets it to false */

        m_waiting = true;

        wxLogTrace( TRACE_CLIPBOARD,
                    wxT("wxClipboard::GetData: format found, start convert") );

        gtk_selection_convert( m_clipboardWidget,
                               m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
                                            : g_clipboardAtom,
                               m_targetRequested,
                               (guint32) GDK_CURRENT_TIME );

        while (m_waiting) gtk_main_iteration();

        /*
           Normally this is a true error as we checked for the presence of such
           data before, but there are applications that may return an empty
           string (e.g. Gnumeric-1.6.1 on Linux if an empty cell is copied)
           which would produce a false error message here, so we check for the
           size of the string first. In ansi, GetDataSize returns an extra
           value (for the closing null?), with unicode, the exact number of
           tokens is given (that is more than 1 for special characters)
           (tested with Gnumeric-1.6.1 and OpenOffice.org-2.0.2)
         */
#if wxUSE_UNICODE
        if ( format != wxDF_UNICODETEXT || data.GetDataSize(format) > 0 )
#else // !UNICODE
        if ( format != wxDF_TEXT || data.GetDataSize(format) > 1 )
#endif // UNICODE / !UNICODE
        {
            wxCHECK_MSG( m_formatSupported, false,
                         wxT("error retrieving data from clipboard") );
        }

        /* return success */
        delete[] array;
        return true;
    }

    wxLogTrace( TRACE_CLIPBOARD,
                wxT("wxClipboard::GetData: format not found") );

    /* return failure */
    delete[] array;
    return false;
}
Exemple #27
0
int show_progress (gint64 res, gint64 expected, int flag)
{
    static ProgressData *pdata;
    static gint64 offs;
    static int cancel;

    if (expected == 0) {
	return SP_RETURN_DONE;
    }

    if (res < 0 || flag == SP_FINISH) {
	/* clean up and get out */
	if (pdata != NULL && pdata->window != NULL) {
	    gtk_widget_destroy(GTK_WIDGET(pdata->window)); 
	    while (gtk_events_pending()) {
		gtk_main_iteration();
	    }	    
	}
	return SP_RETURN_DONE;
    }

    if (flag == SP_LOAD_INIT || flag == SP_SAVE_INIT || flag == SP_FONT_INIT) {
	/* initialize the progress bar */
	gchar *bytestr = NULL;

	offs = 0;
	cancel = 0;

	pdata = build_progress_window(flag, &cancel);
	if (pdata == NULL) {
	    return 0; 
	}

	g_signal_connect(G_OBJECT(pdata->window), "destroy",
			 G_CALLBACK(destroy_progress),
			 &pdata);

	gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pdata->pbar), 0.0);

	if (flag == SP_LOAD_INIT) {
#ifdef G_OS_WIN32
	    bytestr = g_strdup_printf("%s %I64d Kbytes", _("Retrieving"),
				      expected / 1024);
#else
	    bytestr = g_strdup_printf("%s %lld Kbytes", _("Retrieving"),
				      (long long) expected / 1024);
#endif
	} else if (flag == SP_SAVE_INIT) {
#ifdef G_OS_WIN32
	    bytestr = g_strdup_printf("%s %I64d Kbytes", _("Storing"),
				      expected / 1024);
#else
	    bytestr = g_strdup_printf("%s %lld Kbytes", _("Storing"),
				      (long long) expected / 1024);
#endif
	} else if (flag == SP_FONT_INIT) {
	    bytestr = g_strdup_printf(_("Scanning %d fonts"), (int) expected);
	}

	gtk_label_set_text(GTK_LABEL(pdata->label), bytestr);
	g_free(bytestr);

	while (gtk_events_pending()) {
	    gtk_main_iteration();
	}
    }

    if ((flag == SP_NONE || flag == SP_TOTAL) && cancel) {
	/* the user canceled */
	cancel = 0;
	return SP_RETURN_CANCELED;
    }    

    if ((flag == SP_NONE || flag == SP_TOTAL) &&
	(pdata == NULL || pdata->window == NULL)) {
	/* something has gone wrong */
	return 0;
    }

    if (flag == SP_TOTAL) {
	offs = res;
    } else {
	offs += res;
    }

    if (offs > expected && pdata != NULL) {
	gtk_widget_destroy(GTK_WIDGET(pdata->window)); 
	return SP_RETURN_DONE;
    }

    if (offs <= expected && pdata != NULL) {
	/* display the completed fraction */
	gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pdata->pbar), 
				      (gdouble) ((double) offs / expected));
	while (gtk_events_pending()) {
	    gtk_main_iteration();
	}
    } else {
	if (pdata != NULL && pdata->window != NULL) {
	    gtk_widget_destroy(GTK_WIDGET(pdata->window)); 
	}
	return SP_RETURN_DONE;
    }
	
    return SP_RETURN_OK;
}
Exemple #28
0
void
nautilus_self_check_directory (void)
{
	NautilusDirectory *directory;
	NautilusFile *file;

	directory = nautilus_directory_get_by_uri ("file:///etc");
	file = nautilus_file_get_by_uri ("file:///etc/passwd");

	EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1);

	nautilus_directory_file_monitor_add
		(directory, &data_dummy,
		 TRUE, 0, NULL, NULL);

	/* FIXME: these need to be updated to the new metadata infrastructure
	 *  as make check doesn't pass.
	nautilus_file_set_metadata (file, "test", "default", "value");
	EEL_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "test", "default"), "value");

	nautilus_file_set_boolean_metadata (file, "test_boolean", TRUE, TRUE);
	EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "test_boolean", TRUE), TRUE);
	nautilus_file_set_boolean_metadata (file, "test_boolean", TRUE, FALSE);
	EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "test_boolean", TRUE), FALSE);
	EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (NULL, "test_boolean", TRUE), TRUE);

	nautilus_file_set_integer_metadata (file, "test_integer", 0, 17);
	EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 0), 17);
	nautilus_file_set_integer_metadata (file, "test_integer", 0, -1);
	EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 0), -1);
	nautilus_file_set_integer_metadata (file, "test_integer", 42, 42);
	EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 42), 42);
	EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (NULL, "test_integer", 42), 42);
	EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "nonexistent_key", 42), 42);
	*/

	EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc") == directory, TRUE);
	nautilus_directory_unref (directory);

	EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc/") == directory, TRUE);
	nautilus_directory_unref (directory);

	EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc////") == directory, TRUE);
	nautilus_directory_unref (directory);

	nautilus_file_unref (file);

	nautilus_directory_file_monitor_remove (directory, &data_dummy);

	nautilus_directory_unref (directory);

	while (g_hash_table_size (directories) != 0) {
		gtk_main_iteration ();
	}

	EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 0);

	directory = nautilus_directory_get_by_uri ("file:///etc");

	got_files_flag = FALSE;

	nautilus_directory_call_when_ready (directory,
					    NAUTILUS_FILE_ATTRIBUTE_INFO |
					    NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS,
					    TRUE,
					    got_files_callback, &data_dummy);

	while (!got_files_flag) {
		gtk_main_iteration ();
	}

	EEL_CHECK_BOOLEAN_RESULT (directory->details->file_list == NULL, TRUE);

	EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1);

	file = nautilus_file_get_by_uri ("file:///etc/passwd");

	/* EEL_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "test", "default"), "value"); */
	
	nautilus_file_unref (file);

	nautilus_directory_unref (directory);

	EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 0);
}
Exemple #29
0
gint display_romversion_dbox(gboolean file_only)
{
    GladeXML *xml;
	GtkWidget *dbox;
	GtkWidget *data;
    gint result;
    GtkListStore *store;
	
	xml = glade_xml_new
		(tilp_paths_build_glade("romversion-2.glade"), "romversion_dbox",
		 PACKAGE);
	if (!xml)
		g_error(_("%s: GUI loading failed !\n"), __FILE__);
	glade_xml_signal_autoconnect(xml);

    // display list box
	dbox = glade_xml_get_widget(xml, "romversion_dbox");
    
    data = glade_xml_get_widget(xml, "clist1");
    store = clist_create(data);
	clist_populate(store);
    
	// run main box
	result = gtk_dialog_run(GTK_DIALOG(dbox));
	gtk_widget_destroy(dbox);

	switch (result) 
	{
		case GTK_RESPONSE_OK:
            if(chosen_file == NULL)
                break;

			if(!ti68k_is_a_img_file(chosen_file))
				break;

            // Remove previous tib file
            g_free(params.tib_file);
			params.tib_file = g_strconcat("", NULL);

            // Set new image
			g_free(params.rom_file);
			params.rom_file = g_strconcat(inst_paths.img_dir, chosen_file, NULL);
			g_free(chosen_file);
            chosen_file = NULL;

            if(file_only) return 0;

            // Restart engine by exiting the GTK loop
			g_free(params.sav_file);
			params.sav_file = g_strdup("");

			while(gtk_events_pending()) gtk_main_iteration();
			gtk_main_quit();	
		break;
		
		default:
            if(file_only) return -1;
		break;
	}

	return 0;
}
Exemple #30
0
static void
fill_buffer_from_file ()
{
  GtkTextIter iter, end;
  FILE *f;
  gchar buf[2048];
  gint remaining = 0;

  if (options.common_data.uri == NULL)
    return;

  f = fopen (options.common_data.uri, "r");

  if (f == NULL)
    {
      g_printerr (_("Cannot open file '%s': %s\n"),
		  options.common_data.uri, g_strerror (errno));
      return;
    }

  gtk_text_buffer_get_iter_at_offset (text_buffer, &iter, 0);

  while (!feof (f))
    {
      gint count;
      const char *leftover;
      int to_read = 2047 - remaining;

      count = fread (buf + remaining, 1, to_read, f);
      buf[count + remaining] = '\0';

      g_utf8_validate (buf, count + remaining, &leftover);

      g_assert (g_utf8_validate (buf, leftover - buf, NULL));
      gtk_text_buffer_insert (text_buffer, &iter, buf, leftover - buf);

      remaining = (buf + remaining + count) - leftover;
      g_memmove (buf, leftover, remaining);

      if (remaining > 6 || count < to_read)
        break;
    }

  if (remaining)
    {
      g_printerr (_("Invalid UTF-8 data encountered reading file %s\n"),
		  options.common_data.uri);
      return;
    }

  /* We had a newline in the buffer to begin with. (The buffer always contains
   * a newline, so we delete to the end of the buffer to clean up.
   */

  gtk_text_buffer_get_end_iter (text_buffer, &end);
  gtk_text_buffer_delete (text_buffer, &iter, &end);
  gtk_text_buffer_set_modified (text_buffer, FALSE);

  if (options.text_data.tail)
    {
      while (gtk_events_pending ())
	gtk_main_iteration ();
      gtk_text_buffer_get_end_iter (text_buffer, &end);
      gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (text_view), &end, 0, FALSE, 0, 0);
    }
}