static void
save_source (GdictSourceDialog *dialog)
{
  GdictSource *source;
  GdictDatabaseChooser *db_chooser;
  GdictStrategyChooser *strat_chooser;
  gchar *name, *text;
  GdictSourceTransport transport;
  gchar *host, *port;
  gchar *data;
  gsize length;
  GError *error;
  gchar *filename;
  
  source = gdict_source_loader_get_source (dialog->loader,
		  			   dialog->source_name);
  if (!source)
    {
      g_warning ("Attempting to save source `%s', but no "
		 "source for that name was found.",
		 dialog->source_name);

      return;
    }
      
  text = get_text_from_entry (dialog, "description_entry");
  gdict_source_set_description (source, text);
  g_free (text);

  db_chooser = GDICT_DATABASE_CHOOSER (dialog->db_chooser);
  text = gdict_database_chooser_get_current_database (db_chooser);
  gdict_source_set_database (source, text);
  g_free (text);

  strat_chooser = GDICT_STRATEGY_CHOOSER (dialog->strat_chooser);
  text = gdict_strategy_chooser_get_current_strategy (strat_chooser);
  gdict_source_set_strategy (source, text);
  g_free (text);


  /* get the selected transport id */
  transport = dialog->transport;
  switch (transport)
    {
    case GDICT_SOURCE_TRANSPORT_DICTD:
      host = get_text_from_entry (dialog, "hostname_entry");
      port = get_text_from_entry (dialog, "port_entry");
       
      gdict_source_set_transport (source, GDICT_SOURCE_TRANSPORT_DICTD,
          			  "hostname", host,
          			  "port", atoi (port),
          			  NULL);
          
      g_free (host);
      g_free (port);
      break;
    case GDICT_SOURCE_TRANSPORT_INVALID:
    default:
      g_warning ("Invalid transport");
      return;
    }
      
  error = NULL;
  data = gdict_source_to_data (source, &length, &error);
  if (error)
    {
      gdict_show_gerror_dialog (GTK_WINDOW (dialog),
			 	_("Unable to create a source file"),
			 	error);
      
      g_object_unref (source);
      return;
    }
      
  name = g_strdup_printf ("%s.desktop", gdict_source_get_name (source));
  filename = g_build_filename (g_get_home_dir (),
      			       ".gnome2",
			       "gnome-dictionary",
			       name,
			       NULL);
  g_free (name);
      
  g_file_set_contents (filename, data, length, &error);
  if (error)
    gdict_show_gerror_dialog (GTK_WINDOW (dialog),
       			      _("Unable to save source file"),
       			      error);

  g_free (filename);
  g_free (data);
  g_object_unref (source);
}
Example #2
0
/*! Migrate the toolbar settings from Galeon 1.3.11 to 1.3.12
 */
static void
migrate_toolbar (void)
{
	gchar *tb_file = g_build_filename (g_get_home_dir (), 
					   GALEON_DIR, "toolbars.xml", NULL);

	gchar *toolbar;
	gchar **items, **item;
	GString *xml;
	FILE *file;

	if (g_file_test (tb_file, G_FILE_TEST_EXISTS))
	{
		g_free (tb_file);
		return;
	}

	toolbar = eel_gconf_get_string (CONF_TOOLBAR_SETUP);
	if (!toolbar)
	{
		g_free (tb_file);
		return;
	}

	xml = g_string_new (NULL);
	g_string_append (xml, "<?xml version=\"1.0\"?>\n"
			 "<toolbars version=\"0\">\n"
			 "  <toolbar name=\"MigratedToolbar\">\n");

	items = g_strsplit (toolbar, ";", 0);
	for (item = items; *item; item++)
	{
		gchar *str = *item;
		const gchar *new_type = NULL;
		guint i;

		for (i = 0 ; i < G_N_ELEMENTS (toolbar_map); i++)
		{
			if (g_str_has_prefix (str, toolbar_map[i].old_type))
			{
				new_type = toolbar_map[i].new_type;
				break;
			}
		}

		if (new_type)
		{
			g_string_append_printf (xml, 
				       "    <toolitem type=\"application/x-toolbar-item\""
               			       " name=\"%s\"/>\n", toolbar_map[i].new_type);

		}
		else if (strcmp (str, "=separator") == 0)
		{
			g_string_append (xml, "    <separator/>\n");
		}
		else
		{
			g_warning ("Unknown toolbar type: %s", str);
		}
	}

	g_free (toolbar);
	g_strfreev (items);
	
	g_string_append (xml, "  </toolbar>\n</toolbars>\n");

	if (!(file = fopen (tb_file, "w"))) 
	{
		g_warning ("Could not open file '%s': %s", 
			   tb_file, g_strerror (errno));
		g_string_free (xml, TRUE);
		g_free (tb_file);
		return;
	}

	if (fputs (xml->str, file) == -1)
	{
		g_warning ("Could not save to file '%s': %s",
			   tb_file, g_strerror (errno));
		g_string_free (xml, TRUE);
		g_free (tb_file);
		return;
	}
	g_string_free (xml, TRUE);

	if (fclose (file) == -1)
	{
		g_warning ("Could not close file '%s': %s",
			   tb_file, g_strerror (errno));
	}
	g_free (tb_file);
}
Example #3
0
/**
 * gimp_path_parse:
 * @path:         A list of directories separated by #G_SEARCHPATH_SEPARATOR.
 * @max_paths:    The maximum number of directories to return.
 * @check:        %TRUE if you want the directories to be checked.
 * @check_failed: Returns a #GList of path elements for which the
 *                check failed.
 *
 * Returns: A #GList of all directories in @path.
 **/
GList *
gimp_path_parse (const gchar  *path,
                 gint          max_paths,
                 gboolean      check,
                 GList       **check_failed)
{
  const gchar  *home;
  gchar       **patharray;
  GList        *list      = NULL;
  GList        *fail_list = NULL;
  gint          i;
  gboolean      exists    = TRUE;

  if (!path || !*path || max_paths < 1 || max_paths > 256)
    return NULL;

  home = g_get_home_dir ();

  patharray = g_strsplit (path, G_SEARCHPATH_SEPARATOR_S, max_paths);

  for (i = 0; i < max_paths; i++)
    {
      GString *dir;

      if (! patharray[i])
        break;

#ifndef G_OS_WIN32
      if (*patharray[i] == '~')
        {
          dir = g_string_new (home);
          g_string_append (dir, patharray[i] + 1);
        }
      else
#endif
        {
          gimp_path_runtime_fix (&patharray[i]);
          dir = g_string_new (patharray[i]);
        }

      if (check)
        exists = g_file_test (dir->str, G_FILE_TEST_IS_DIR);

      if (exists)
        list = g_list_prepend (list, g_strdup (dir->str));
      else if (check_failed)
        fail_list = g_list_prepend (fail_list, g_strdup (dir->str));

      g_string_free (dir, TRUE);
    }

  g_strfreev (patharray);

  list = g_list_reverse (list);

  if (check && check_failed)
    {
      fail_list = g_list_reverse (fail_list);
      *check_failed = fail_list;
    }

  return list;
}
Example #4
0
int main (int argc, char *argv[])
{
	int i;
	
	const char *commandLine_File = NULL;
	GtkWidget *pVBox;
	GtkWidget *pMenuBar;
	GtkWidget *pMenu, *pSubMenu;
	GtkWidget *pMenuItem, *pSubMenuItem;
	GtkAccelGroup * accel_group;
       
	if(argc == 2) commandLine_File = argv[1];
	
#ifdef DEBUG
        LogStart();
#endif
	
	gtk_init(&argc, &argv);
	SDL_Init(SDL_INIT_VIDEO);
	desmume_init();
	
 	dTools_running = (BOOL*)malloc(sizeof(BOOL) * dTools_list_size);
	for(i=0; i<dTools_list_size; i++) dTools_running[i]=FALSE;
	
	CONFIG_FILE = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL);
	Read_ConfigFile();
	
	/* Creation de la fenetre */
	pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(pWindow), "Desmume");
	gtk_window_set_policy (GTK_WINDOW (pWindow), FALSE, FALSE, FALSE);
	gtk_window_set_icon(GTK_WINDOW (pWindow), gdk_pixbuf_new_from_xpm_data(DeSmuME_xpm));
	
	g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);
	g_signal_connect(G_OBJECT(pWindow), "key_press_event", G_CALLBACK(Key_Press), NULL);
	g_signal_connect(G_OBJECT(pWindow), "key_release_event", G_CALLBACK(Key_Release), NULL);

	/* Creation de la GtkVBox */
	pVBox = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(pWindow), pVBox);

	accel_group = gtk_accel_group_new();
	action_group = gtk_action_group_new("dui");
	gtk_action_group_add_actions(action_group, action_entries, sizeof(action_entries) / sizeof(GtkActionEntry), pWindow);
        {
                GList * list = gtk_action_group_list_actions(action_group);
                g_list_foreach(list, dui_set_accel_group, accel_group);
        }
	gtk_window_add_accel_group(GTK_WINDOW(pWindow), accel_group);
	gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "pause"), FALSE);
	gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), FALSE);
	gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "reset"), FALSE);
	gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "printscreen"), FALSE);

	/**** Creation du menu ****/

	pMenuBar = gtk_menu_bar_new();
	
	/** Menu "Fichier" **/

	pMenu = gtk_menu_new();

	gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "open")));
	gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "printscreen")));
	gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "quit")));
	
	pMenuItem = gtk_menu_item_new_with_label("File");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu);
	gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);

	/** Menu "Emulation" **/
	GtkWidget *mEmulation;
		GtkWidget *mFrameskip;
			GtkWidget *mFrameskip_Radio[MAX_FRAMESKIP];
		GtkWidget *mGraphics;
			GtkWidget *mSize;
				GtkWidget *mSize_Radio[MAX_SCREENCOEFF];
			GtkWidget *mLayers;
				GtkWidget *mLayers_Radio[10];
	
	
	mEmulation = gtk_menu_new();
	pMenuItem = gtk_menu_item_new_with_label("Emulation");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mEmulation);
	gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);
	
	gtk_container_add(GTK_CONTAINER(mEmulation), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "run")));
	
	gtk_container_add(GTK_CONTAINER(mEmulation), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "pause")));

	gtk_container_add(GTK_CONTAINER(mEmulation), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "reset")));
	
		mFrameskip = gtk_menu_new();
		pMenuItem = gtk_menu_item_new_with_label("Frameskip");
		gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mFrameskip);
		gtk_menu_shell_append(GTK_MENU_SHELL(mEmulation), pMenuItem);
		
		for(i = 0; i < MAX_FRAMESKIP; i++) {
			char frameskipRadio_buf[16];
			sprintf(frameskipRadio_buf, "%d", i);
			if(i>0) mFrameskip_Radio[i] = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(mFrameskip_Radio[i-1]), frameskipRadio_buf);
			else mFrameskip_Radio[i] = gtk_radio_menu_item_new_with_label(NULL, frameskipRadio_buf);
			g_signal_connect(G_OBJECT(mFrameskip_Radio[i]), "activate", G_CALLBACK(Modify_Frameskip), GINT_TO_POINTER(i));
			gtk_menu_shell_append(GTK_MENU_SHELL(mFrameskip), mFrameskip_Radio[i]);
		}
		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mFrameskip_Radio[0]), TRUE);
		
		mGraphics = gtk_menu_new();
		pMenuItem = gtk_menu_item_new_with_label("Graphics");
		gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mGraphics);
		gtk_menu_shell_append(GTK_MENU_SHELL(mEmulation), pMenuItem);
			
// TODO: Un jour, peut être... ><
			mSize = gtk_menu_new();
			pMenuItem = gtk_menu_item_new_with_label("Size");
			gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mSize);
			gtk_menu_shell_append(GTK_MENU_SHELL(mGraphics), pMenuItem);
			
			for(i = 1; i < MAX_SCREENCOEFF; i++) {
				char sizeRadio_buf[16];
				sprintf(sizeRadio_buf, "x%d", i);
				if(i>1) mSize_Radio[i] = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(mSize_Radio[i-1]), sizeRadio_buf);
				else mSize_Radio[i] = gtk_radio_menu_item_new_with_label(NULL, sizeRadio_buf);
				g_signal_connect(G_OBJECT(mSize_Radio[i]), "activate", G_CALLBACK(Modify_ScreenCoeff), GINT_TO_POINTER(i));
				gtk_menu_shell_append(GTK_MENU_SHELL(mSize), mSize_Radio[i]);
			}
			gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mFrameskip_Radio[0]), TRUE);
		
			mLayers = gtk_menu_new();
			pMenuItem = gtk_menu_item_new_with_label("Layers");
			gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mLayers);
			gtk_menu_shell_append(GTK_MENU_SHELL(mGraphics), pMenuItem);
		
			for(i = 0; i < 10; i++) {
				mLayers_Radio[i] = gtk_check_menu_item_new_with_label(Layers_Menu[i]);
				g_signal_connect(G_OBJECT(mLayers_Radio[i]), "activate", G_CALLBACK(Modify_Layer), (void*)Layers_Menu[i]);
				gtk_menu_shell_append(GTK_MENU_SHELL(mLayers), mLayers_Radio[i]);
				gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mLayers_Radio[i]), TRUE);
			}
			
	
	/** Menu "Options" **/
	GtkWidget *mConfig = gtk_menu_new();
	pMenuItem = gtk_menu_item_new_with_label("Config");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mConfig);
	gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);
	
	pMenuItem = gtk_menu_item_new_with_label("Edit controls");
	g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(Edit_Controls), (GtkWidget*) pWindow);
	gtk_menu_shell_append(GTK_MENU_SHELL(mConfig), pMenuItem);
	
#if 0
	
	GtkWidget *mFirmware;
	
	mFirmware = gtk_menu_new();
	pMenuItem = gtk_menu_item_new_with_label("Firmware");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mFirmware);
	gtk_menu_shell_append(GTK_MENU_SHELL(mConfig), pMenuItem);
	
	pMenuItem = gtk_menu_item_new_with_label("Select...");
	g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(SelectFirmwareFile), (gpointer)0);
	gtk_menu_shell_append(GTK_MENU_SHELL(mFirmware), pMenuItem);
		
	pMenuItem = gtk_menu_item_new_with_label("Config");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), mConfig);
	gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);
	
#endif
	
	/** Menu "Outils" **/
	
	pMenu = gtk_menu_new();
	
	for(i = 0; i < dTools_list_size; i++)
	{
		pMenuItem = gtk_menu_item_new_with_label(dTools_list[i]->name);
		g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(Start_dTool), GINT_TO_POINTER(i));
		gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);
	}
		
	pMenuItem = gtk_menu_item_new_with_label("Tools");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu);
	gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);
	
	/** Menu "?" **/

	pMenu = gtk_menu_new();

#if ((GTK_MAJOR_VERSION >= 2) && (GTK_MINOR_VERSION >= 6))
	pMenuItem = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT,NULL);
#else
	pMenuItem = gtk_menu_item_new_with_label("About");
#endif
	g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(About), (GtkWidget*) pWindow);
	gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);

	pMenuItem = gtk_menu_item_new_with_label("?");
	gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu);
	gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);

	/* Ajout du menu a la fenetre */
	gtk_box_pack_start(GTK_BOX(pVBox), pMenuBar, FALSE, FALSE, 0);

	/* Création de la Toolbar */
	
	pToolbar = gtk_toolbar_new();
	gtk_box_pack_start(GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0);

	gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "open"))), -1);
	gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "run"))), -1);
	gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "pause"))), -1);
	gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "quit"))), -1);

	/* Création de l'endroit pour l'affichage des écrans */
	
	pDrawingArea= gtk_drawing_area_new();
	
	gtk_drawing_area_size(GTK_DRAWING_AREA(pDrawingArea), 256, 384);
	gtk_widget_set_usize (pDrawingArea, 256, 384);
			
	gtk_widget_set_events(pDrawingArea, GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK );
	
	g_signal_connect(G_OBJECT(pDrawingArea), "button_press_event", G_CALLBACK(Stylus_Press), NULL);
	g_signal_connect(G_OBJECT(pDrawingArea), "button_release_event", G_CALLBACK(Stylus_Release), NULL);
	g_signal_connect(G_OBJECT(pDrawingArea), "motion_notify_event", G_CALLBACK(Stylus_Move), NULL);
	
	
	g_signal_connect( G_OBJECT(pDrawingArea), "realize", G_CALLBACK(Draw), NULL ) ;
	g_signal_connect( G_OBJECT(pDrawingArea), "expose_event", G_CALLBACK(gtkFloatExposeEvent), NULL ) ;
	
	gtk_box_pack_start(GTK_BOX(pVBox), pDrawingArea, FALSE, FALSE, 0);
	
	/* Création de la barre d'état */
	
	pStatusBar = gtk_statusbar_new();
	
	pStatusBar_Ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(pStatusBar), "Global");
	
	pStatusBar_Change("Desmume");

	gtk_box_pack_end(GTK_BOX(pVBox), pStatusBar, FALSE, FALSE, 0);
	
	gtk_widget_show_all(pWindow);
	
	//LoadFirmware("fw.bin");
	
	/* Vérifie la ligne de commandes */
	if(commandLine_File)
	{
		if(Open(commandLine_File) >= 0)
		{
			Launch();
		}
		else
		{
			GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow),
					GTK_DIALOG_MODAL,
					GTK_MESSAGE_INFO,
					GTK_BUTTONS_OK,
					"Unable to load :\n%s", commandLine_File);
			gtk_dialog_run(GTK_DIALOG(pDialog));
			gtk_widget_destroy(pDialog);
		}
	}
	
	/* Boucle principale */
	
//	gtk_idle_add(&EmuLoop, pWindow);
//	g_idle_add(&EmuLoop, pWindow);
	
	gtk_main();
	
	desmume_free();

#ifdef DEBUG
        LogStop();
#endif

	SDL_Quit();
	
	Write_ConfigFile();
	
	return EXIT_SUCCESS;
}
int main(int argc, char *argv[]) {

  uid_t uid=getuid(), euid=geteuid();
    if (uid==0) {



  GtkWidget *button1;
  GtkWidget *button2;
 
  GtkWidget *v_a_button;
  GtkWidget *v_f_button;

  GtkWidget *s_g_button;

  GtkWidget *view_log_button;
  GtkWidget *clear_log_button;

  GtkWidget *label_combo;
  GtkWidget *label_app;
  GtkWidget *label_data;
  GtkWidget *label_console;

  GtkWidget *menubar;
  GtkWidget *fileMenu;
  GtkWidget *fileMi;
  GtkWidget *helpMi;

  GtkWidget *vbox;

 



  /*Window Initilization*/
  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "User Utility");
  gtk_window_set_default_size(GTK_WINDOW(window), 400, 600);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_widget_show(window);

  /* Layout set to fixed*/
  fixed = gtk_fixed_new();
  gtk_container_add(GTK_CONTAINER(window), fixed);


  /*  Buttons Initilization*/
  button1 = gtk_button_new_with_label("Add");
  gtk_fixed_put(GTK_FIXED(fixed), button1, 350, 40);
  gtk_widget_set_size_request(button1, 80, 30);
  g_signal_connect(G_OBJECT(button1), "clicked",G_CALLBACK(add1_clicked), NULL);


  button2 = gtk_button_new_with_label("Add");
  gtk_fixed_put(GTK_FIXED(fixed), button2, 350, 110);
  gtk_widget_set_size_request(button2, 80, 30);
  g_signal_connect(G_OBJECT(button2), "clicked",G_CALLBACK(add2_clicked), NULL);


  /*Entry boxs initilization*/
  entry1 = gtk_entry_new();
  gtk_fixed_put(GTK_FIXED(fixed), entry1, 10, 40);
  gtk_widget_set_size_request(entry1, 260, 30);

 
  entry2 = gtk_entry_new();
  gtk_fixed_put(GTK_FIXED(fixed), entry2, 10,110);
  gtk_widget_set_size_request(entry2, 260, 30);


  /*  File choosers Initilization */
  c_button1 = gtk_file_chooser_button_new ("Choose fast",GTK_FILE_CHOOSER_ACTION_OPEN);
  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (c_button1),g_get_home_dir());
  gtk_fixed_put(GTK_FIXED(fixed), c_button1, 280, 40);
  gtk_widget_set_size_request(c_button1, 50, 30);
  g_signal_connect(G_OBJECT(c_button1), "file-set",G_CALLBACK(choose1_clicked), NULL);


  c_button2 = gtk_file_chooser_button_new ("Choose fast",GTK_FILE_CHOOSER_ACTION_OPEN);
  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (c_button2),g_get_home_dir());
  gtk_fixed_put(GTK_FIXED(fixed), c_button2, 280, 110);
  gtk_widget_set_size_request(c_button2, 50, 30);
  g_signal_connect(G_OBJECT(c_button2), "file-set",G_CALLBACK(choose2_clicked), NULL);


  /* Label Initilization */
  label_app = gtk_label_new("Choose an application to add to the whitelist:");
  gtk_fixed_put(GTK_FIXED(fixed), label_app, 10, 25);

  label_data = gtk_label_new("Choose a file to protect:  ");
  gtk_fixed_put(GTK_FIXED(fixed), label_data, 10, 95);

  label_combo = gtk_label_new("Choose a hashing algo :");
  gtk_fixed_put(GTK_FIXED(fixed), label_combo, 10, 167);

  label_console = gtk_label_new("Console Window :  ");
  gtk_fixed_put(GTK_FIXED(fixed), label_console, 10, 245);


  /* Combobox Initilization */
  combo = gtk_combo_box_text_new();
  gtk_combo_box_text_append_text(GTK_COMBO_BOX(combo), "SHA1\0\0");
  gtk_combo_box_text_append_text(GTK_COMBO_BOX(combo), "SHA2\0\0");
  gtk_combo_box_text_append_text(GTK_COMBO_BOX(combo), "SHA256\0");
  gtk_combo_box_text_append_text(GTK_COMBO_BOX(combo), "SHA512\0");
  gtk_combo_box_text_append_text(GTK_COMBO_BOX(combo), "MD5\0\0");

  gtk_fixed_put(GTK_FIXED(fixed), combo, 160, 160);
  gtk_widget_set_size_request(combo, 260, 30);

  g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(combo_selected), NULL);

  /* View Buttons */ 
  v_f_button = gtk_button_new_with_label("View Files");
  gtk_fixed_put(GTK_FIXED(fixed), v_f_button, 250, 200);
  gtk_widget_set_size_request(v_f_button, 150, 30);
  g_signal_connect(G_OBJECT(v_f_button), "clicked",G_CALLBACK(v_a_clicked), NULL);


  v_a_button = gtk_button_new_with_label("View Apps");
  gtk_fixed_put(GTK_FIXED(fixed), v_a_button, 10, 200);
  gtk_widget_set_size_request(v_a_button, 150, 30);
  g_signal_connect(G_OBJECT(v_a_button), "clicked",G_CALLBACK(v_a_clicked), NULL);



  /* Text view*/
  textview = gtk_text_view_new();
  gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), FALSE);
  gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview),FALSE);
  gtk_fixed_put(GTK_FIXED(fixed), textview, 10, 265);
  gtk_widget_set_size_request(textview, 330, 250);




 /*Log Buttons */
  view_log_button = gtk_button_new_with_label("View Log");
  gtk_fixed_put(GTK_FIXED(fixed), view_log_button, 350, 270);
  gtk_widget_set_size_request(view_log_button, 60, 30);
  g_signal_connect(G_OBJECT(view_log_button), "clicked",G_CALLBACK(view_log_clicked), NULL);


  clear_log_button = gtk_button_new_with_label("Clear Log");
  gtk_fixed_put(GTK_FIXED(fixed), clear_log_button, 350, 320);
  gtk_widget_set_size_request(clear_log_button, 60, 30);
  g_signal_connect(G_OBJECT(clear_log_button), "clicked",G_CALLBACK(clear_log_clicked), NULL);


  /*Generate Button */
  s_g_button = gtk_button_new_with_label("Generate CFG");
  gtk_fixed_put(GTK_FIXED(fixed), s_g_button, 150, 530);
  gtk_widget_set_size_request(s_g_button, 150, 30);
  g_signal_connect(G_OBJECT(s_g_button), "clicked",G_CALLBACK(g_clicked), NULL);


  /*  Menu bar */
  menubar = gtk_menu_bar_new();
  fileMenu = gtk_menu_new();

  fileMi = gtk_menu_item_new_with_label("File");
  helpMi = gtk_menu_item_new_with_label("Help");

  gtk_menu_item_set_submenu(GTK_MENU_ITEM(fileMi), fileMenu);
  gtk_menu_shell_append(GTK_MENU_SHELL(menubar), fileMi);
  gtk_menu_shell_append(GTK_MENU_SHELL(menubar), helpMi);

  gtk_fixed_put(GTK_FIXED(fixed), menubar, 0, 0);

  g_signal_connect(G_OBJECT(helpMi), "activate",G_CALLBACK(g_menu_help), NULL);


  gtk_widget_show_all(window);

  /* Close button signal */
  g_signal_connect(G_OBJECT(window), "destroy",G_CALLBACK(gtk_main_quit), NULL);

  gtk_main();
}
else{
	printf("You are not a sudo user\nRun this application using sudo \n");
}

  return 0;
}
Example #6
0
File: init.c Project: UIKit0/eXtace
void read_config(void)
{
	ConfigFile *cfgfile;
	gchar *filename;
	int fd;
	gchar *temp_cmap = NULL;
	Color_map.filename = NULL;
	filename = g_strconcat(g_get_home_dir(), "/.eXtace/config", NULL);
	cfgfile = cfg_open_file(filename);
	if (cfgfile)
	{
		cfg_read_int(cfgfile, "Global", "major_ver", &major_ver);
		cfg_read_int(cfgfile, "Global", "minor_ver", &minor_ver);
		cfg_read_int(cfgfile, "Global", "micro_ver", &micro_ver);
		if ((major_ver == 1) && (minor_ver == 8))
		{
			printf("Config file structure changed. using defaults. \nClosing eXtace will save your NEW settings.\n");
			cfg_free(cfgfile);
			unlink(filename);
			g_free(filename);
			return;

		}
		cfg_read_string(cfgfile, "Global", "last_colormap", &temp_cmap);
		if (temp_cmap != NULL)
		{
			fd = open(temp_cmap, O_RDONLY);
			if (fd > 0)
			{
				Color_map.filename = g_strdup(temp_cmap);
				close(fd);
			}
			else
				Color_map.filename = NULL;

			g_free(temp_cmap);
		}
		cfg_read_boolean(cfgfile, "Global", "landtilt", &landtilt);
		cfg_read_boolean(cfgfile, "Global", "spiketilt", &spiketilt);
		cfg_read_float(cfgfile, "Global", "low_freq", &low_freq);
		cfg_read_float(cfgfile, "Global", "high_freq", &high_freq);
		cfg_read_int(cfgfile, "Window", "width", &width);
		cfg_read_int(cfgfile, "Window", "height", &height);
		cfg_read_int(cfgfile, "Window", "main_x_origin", &main_x_origin);
		cfg_read_int(cfgfile, "Window", "main_y_origin", &main_y_origin);
		cfg_read_int(cfgfile, "Window", "grad_x_origin", &grad_x_origin);
		cfg_read_int(cfgfile, "Window", "grad_y_origin", &grad_y_origin);
		cfg_read_int(cfgfile, "Window", "dir_x_origin", &dir_x_origin);
		cfg_read_int(cfgfile, "Window", "dir_y_origin", &dir_y_origin);

		cfg_read_int(cfgfile, "Global", "mode", &mode);
		{
		  int i;
		  if(cfg_read_int(cfgfile, "Global", "data_source", &i))
		  data_source=i;
		}
		cfg_read_int(cfgfile, "Global", "decimation_factor", &decimation_factor);
		cfg_read_int(cfgfile, "Global", "fft_signal_source", &fft_signal_source);
		cfg_read_float(cfgfile, "Global", "scope_zoom", &scope_zoom);
		cfg_read_int(cfgfile, "Global", "refresh_rate", &refresh_rate);
		cfg_read_int(cfgfile, "Global", "landflip", &landflip);
		cfg_read_int(cfgfile, "Global", "spikeflip", &spikeflip);
		cfg_read_boolean(cfgfile, "Global", "outlined", &outlined);
		cfg_read_int(cfgfile, "Global", "sub_mode_3D", &sub_mode_3D);
		cfg_read_int(cfgfile, "Global", "scope_sub_mode", &scope_sub_mode);
		cfg_read_boolean(cfgfile, "Global", "dir_win_present", &dir_win_present);
		cfg_read_int(cfgfile, "Global", "nsamp", &nsamp);

		cfg_read_int(cfgfile, "Global", "window_func", &window_func);
		cfg_read_int(cfgfile, "Global", "win_width", &win_width);
		cfg_read_int(cfgfile, "Global", "axis_type", &axis_type);
		cfg_read_int(cfgfile, "Global", "bands", &bands);
		cfg_read_int(cfgfile, "Global", "lag", &lag);
		cfg_read_float(cfgfile, "Global", "noise_floor", &noise_floor);
		cfg_read_int(cfgfile, "Global", "seg_height", &seg_height);
		cfg_read_int(cfgfile, "Global", "seg_space", &seg_space);
		cfg_read_boolean(cfgfile, "Global", "bar_decay", &bar_decay);
		cfg_read_boolean(cfgfile, "Global", "peak_decay", &peak_decay);
		cfg_read_int(cfgfile, "Global", "decay_speed", &bar_decay_speed);
		cfg_read_boolean(cfgfile, "Global", "stabilized", &stabilized);
		cfg_read_boolean(cfgfile, "Global", "show_graticule", &show_graticule);
		cfg_read_int(cfgfile, "Global", "peak_decay_speed", &peak_decay_speed);
		cfg_read_int(cfgfile, "Global", "peak_hold_time", &peak_hold_time);
		cfg_read_int(cfgfile, "Global", "tape_scroll", &tape_scroll);
		cfg_read_int(cfgfile, "Global", "xdet_scroll", &xdet_scroll);
		cfg_read_int(cfgfile, "Global", "zdet_scroll", &zdet_scroll);
		cfg_read_float(cfgfile, "Global", "xdet_start", &xdet_start);
		cfg_read_float(cfgfile, "Global", "xdet_end", &xdet_end);
		cfg_read_float(cfgfile, "Global", "ydet_start", &ydet_start);
		cfg_read_float(cfgfile, "Global", "ydet_end", &ydet_end);
		cfg_read_float(cfgfile, "Global", "x3d_start", &x3d_start);
		cfg_read_float(cfgfile, "Global", "x3d_end", &x3d_end);
		cfg_read_float(cfgfile, "Global", "y3d_start", &y3d_start);
		cfg_read_float(cfgfile, "Global", "y3d_end", &y3d_end);
		cfg_read_float(cfgfile, "Global", "multiplier", &multiplier);
		cfg_read_int(cfgfile, "Global", "x3d_scroll", &x3d_scroll);
		cfg_read_int(cfgfile, "Global", "z3d_scroll", &z3d_scroll);
		cfg_read_boolean(cfgfile, "Global", "show_leader", &show_leader);
		cfg_read_int(cfgfile, "Global", "scope_sync_source", &scope_sync_source);
		cfg_read_int(cfgfile, "Global", "horiz_spec_start", &horiz_spec_start);
		cfg_read_int(cfgfile, "Global", "vert_spec_start", &vert_spec_start);
		if (horiz_spec_start > width)
			horiz_spec_start = width-10; 
		if (vert_spec_start > height)
			vert_spec_start = height-10;
		if (horiz_spec_start < 60)
			horiz_spec_start = 60; 
		if (vert_spec_start < 120)
			vert_spec_start = 120;


		cfg_free(cfgfile);

	}
	else
		printf("Config file not found, using defaults\n");
	g_free(filename);

}
Example #7
0
int main(int argc, char *argv[])
{
	gboolean root_override=FALSE, open_in_new_window = FALSE;
	GList *filenames = NULL, *projectfiles=NULL;
	gint linenumber = -1;

	Tbfwin *firstbfwin;
#ifndef NOSPLASH
	GtkWidget *splash_window;
#endif /* #ifndef NOSPLASH */

#ifdef ENABLE_NLS
	setlocale(LC_ALL,"");
	bindtextdomain(PACKAGE,LOCALEDIR);
	DEBUG_MSG("set bindtextdomain for %s to %s\n",PACKAGE,LOCALEDIR);
	bind_textdomain_codeset(PACKAGE, "UTF-8");
	textdomain(PACKAGE);
#endif
#ifdef HAVE_ATLEAST_GNOMEUI_2_6
	gnome_init(PACKAGE, VERSION, argc, argv);
#else
	gtk_init(&argc, &argv);
#endif /* HAVE_ATLEAST_GNOMEUI_2_6
 */
	main_v = g_new0(Tmain, 1);
	main_v->session = g_new0(Tsessionvars,1);
	DEBUG_MSG("main, main_v is at %p\n", main_v);

	rcfile_check_directory();
	rcfile_parse_main();

	parse_commandline(argc, argv, &root_override, &filenames, &projectfiles, &open_in_new_window, &linenumber);
#ifdef WITH_MSG_QUEUE
	if (((filenames || projectfiles) && (main_v->props.view_bars & MODE_REUSE_WINDOW)) || open_in_new_window) {
		msg_queue_start(filenames, projectfiles, linenumber, open_in_new_window);
	}
#endif /* WITH_MSG_QUEUE */
#ifndef NOSPLASH
	/* start splash screen somewhere here */
	splash_window = start_splash_screen();
	splash_screen_set_label(_("parsing highlighting file..."));
#endif /* #ifndef NOSPLASH */

	{
		gchar *filename = g_strconcat(g_get_home_dir(), "/.winefish/dir_history", NULL);
		main_v->recent_directories = get_stringlist(filename, NULL);
		g_free(filename);
	}
	rcfile_parse_global_session();
	rcfile_parse_highlighting();
#ifndef NOSPLASH
	splash_screen_set_label(_("compiling highlighting patterns..."));
#endif /* #ifndef NOSPLASH */
	hl_init();
#ifndef NOSPLASH
	splash_screen_set_label(_("initialize some other things..."));
#endif /* #ifndef NOSPLASH */
	filebrowserconfig_init();
	filebrowser_filters_rebuild();
	autoclosing_init();
#ifndef NOSPLASH
	splash_screen_set_label(_("parsing autotext and words file..."));
#endif /* #ifndef NOSPLASH */
	autotext_init();
	completion_init();
#ifndef NOSPLASH
	splash_screen_set_label(_("parsing custom menu file..."));
#endif /* #ifndef NOSPLASH */
	rcfile_parse_custom_menu(FALSE,FALSE);

#ifdef SNOOPER2
#ifndef NOSPLASH
	splash_screen_set_label(_("parsing keymap and initializing function list..."));
#endif /* #ifndef NOSPLASH */
	funclist_init();
	keymap_init();
#endif /* SNOOPER2 */
	
	main_v->tooltips = gtk_tooltips_new();
	/* initialize the completion window */
	/* main_v->completion.window = NULL; */
	fref_init();
	bmark_init();
#ifdef WITH_MSG_QUEUE
	if (!filenames && !projectfiles && (main_v->props.view_bars & MODE_REUSE_WINDOW)) {
		msg_queue_start(NULL, NULL, -1, open_in_new_window);
	}
#endif /* WITH_MSG_QUEUE */
#ifndef NOSPLASH
	splash_screen_set_label(_("creating main gui..."));
#endif /* #ifndef NOSPLASH */

	/* create the first window */
	firstbfwin = g_new0(Tbfwin,1);
	firstbfwin->session = main_v->session;
	firstbfwin->bookmarkstore = main_v->bookmarkstore;
	main_v->bfwinlist = g_list_append(NULL, firstbfwin);
	gui_create_main(firstbfwin, filenames, linenumber);
	bmark_reload(firstbfwin);
#ifndef NOSPLASH
	splash_screen_set_label(_("showing main gui..."));
#endif /* #ifndef NOSPLASH */

	/* set GTK settings, must be AFTER the menu is created */
	{
		gchar *shortcutfilename;
		GtkSettings* gtksettings = gtk_settings_get_default();
		g_object_set(G_OBJECT(gtksettings), "gtk-can-change-accels", TRUE, NULL); 
		shortcutfilename = g_strconcat(g_get_home_dir(), "/.winefish/menudump_2", NULL);
		gtk_accel_map_load(shortcutfilename);
		g_free(shortcutfilename);
	}

	gui_show_main(firstbfwin);
	/*
	if (main_v->props.view_html_toolbar && main_v->globses.quickbar_items == NULL) {
		info_dialog(firstbfwin->main_window, _("Winefish tip:"), _("This message is shown since you DONOT have any items in the QuickBar.\n\nIf you right-click a button in the Standard toolbars you can add buttons to the Quickbar."));
	}
	*/
	if (projectfiles) {
		GList *tmplist = g_list_first(projectfiles);
		while (tmplist) {
			project_open_from_file(firstbfwin, tmplist->data, linenumber);
			tmplist = g_list_next(tmplist);
		}
	}

#ifndef NOSPLASH
	DEBUG_MSG("destroy splash\n");
	flush_queue();
	{
		static struct timespec const req = { 0, 10000000};
		nanosleep(&req, NULL);
	}
	gtk_widget_destroy(splash_window);
#endif /* #ifndef NOSPLASH */

	/* snooper must be installed after the main gui has shown;
	otherwise the program may be aborted */
#ifndef SNOOPER2
	snooper_install();
#endif /* SNOOPER2 */

	DEBUG_MSG("main, before gtk_main()\n");
	gtk_main();
	DEBUG_MSG("main, after gtk_main()\n");
#ifdef WITH_MSG_QUEUE	
	/* do the cleanup */
	msg_queue_cleanup();
#endif /* WITH_MSG_QUEUE */
	DEBUG_MSG("Winefish: exiting cleanly\n");
	return 0;
}
Example #8
0
static void init_win32_paths(void)
{
	char *home_dir = NULL;
	HMODULE hModule;
	DWORD dWord;
	char *dirname;
	char *sBuffer;

	// Init the path for the Windows version by getting the 
	// executable location.
	hModule = GetModuleHandle("tilp.exe");
	sBuffer = (char *) malloc(4096 * sizeof(char));
	dWord = GetModuleFileName(hModule, sBuffer, 4096);
    dirname = g_dirname(sBuffer);
	
    // MinGW Option, allows Windows Users to run on a Linux File Hierarhcy
	#ifdef __MINGW32__
	  #define MINGW_REL "share\\tilp2"
	  
	  char *basename;
	  basename = g_path_get_basename(dirname);
	  
      // Will replace /target/bin with /target/share/tilp2 in MinGW/MSYS
      if ((strlen(basename) == 3) && !g_strcasecmp(basename, "bin"))
      {
          gchar *token;
          dirname = g_realloc(dirname, strlen(dirname) + strlen(MINGW_REL) + 1);
          token = dirname + strlen(dirname) - 3;
          strcpy(token, MINGW_REL);
      }
    #endif
    
    inst_paths.base_dir = g_strconcat(dirname, "\\", NULL);
	g_free(dirname);
	free(sBuffer);

	inst_paths.pixmap_dir =
	    g_strconcat(inst_paths.base_dir, "pixmaps\\", NULL);
	inst_paths.icon_dir =
	    g_strconcat(inst_paths.base_dir, "icons\\", NULL);
	inst_paths.help_dir =
	    g_strconcat(inst_paths.base_dir, "help\\", NULL);
	inst_paths.manpage_dir =
	    g_strconcat(inst_paths.base_dir, "", NULL);
	inst_paths.glade_dir =
	    g_strconcat(inst_paths.base_dir, "glade\\", NULL);
	#ifdef __MINGW32__
	inst_paths.home_dir = g_get_current_dir();
	#else
	if((g_win32_get_windows_version() & 255) > 5)
	{
		// Windows Vista
		inst_paths.home_dir = 
			g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, "Documents", G_DIR_SEPARATOR_S, _("My TI Files"), NULL);
		g_mkdir(inst_paths.home_dir, 0);
	}
	else
	{
		// Windows XP
		inst_paths.home_dir = g_strconcat(inst_paths.base_dir, "My TI files\\", NULL);
		g_mkdir(inst_paths.home_dir, 0);
	}
	#endif

#ifdef ENABLE_NLS
	inst_paths.locale_dir =
	    g_strconcat(inst_paths.base_dir, "locale\\", NULL);
#endif				/*  */
}
Example #9
0
static GtkWidget *
panel_place_menu_item_create_menu (PanelPlaceMenuItem *place_item)
{
	GtkWidget *places_menu;
	GtkWidget *item;
	char      *gsettings_name;
	char      *name;
	char      *uri;
	GFile     *file;

	places_menu = panel_create_menu ();

	file = g_file_new_for_path (g_get_home_dir ());
	uri = g_file_get_uri (file);
	name = panel_util_get_label_for_uri (uri);
	g_object_unref (file);

	panel_menu_items_append_place_item (PANEL_ICON_HOME, NULL,
					    name,
					    _("Open your personal folder"),
					    places_menu,
					    G_CALLBACK (activate_home_uri),
					    uri);
	g_free (name);
	g_free (uri);

	if (!g_settings_get_boolean (place_item->priv->caja_prefs_settings,
				     CAJA_PREFS_DESKTOP_IS_HOME_DIR_KEY)) {
		file = g_file_new_for_path (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP));
		uri = g_file_get_uri (file);
		g_object_unref (file);

		panel_menu_items_append_place_item (
				PANEL_ICON_DESKTOP, NULL,
				/* Translators: Desktop is used here as in
				 * "Desktop Folder" (this is not the Desktop
				 * environment). */
				C_("Desktop Folder", "Desktop"),
				_("Open the contents of your desktop in a folder"),
				places_menu,
				G_CALLBACK (activate_desktop_uri),
				/* FIXME: if the dir changes, we'd need to update the drag data since the uri is not the same */
				uri);
		g_free (uri);
	}

	panel_place_menu_item_append_gtk_bookmarks (places_menu);
	add_menu_separator (places_menu);

	gsettings_name = g_settings_get_string (place_item->priv->caja_desktop_settings,
					        CAJA_DESKTOP_COMPUTER_ICON_NAME_KEY);
	panel_menu_items_append_from_desktop (places_menu,
					      "caja-computer.desktop",
					      gsettings_name,
                                              TRUE);
	if (gsettings_name)
		g_free (gsettings_name);

	panel_place_menu_item_append_local_gio (place_item, places_menu);
	add_menu_separator (places_menu);

	panel_menu_items_append_from_desktop (places_menu,
					      "mate-network-scheme.desktop",
					      NULL,
                                              TRUE);
	panel_place_menu_item_append_remote_gio (place_item, places_menu);

	if (panel_is_program_in_path ("caja-connect-server")) {
		item = panel_menu_items_create_action_item (PANEL_ACTION_CONNECT_SERVER);
		if (item != NULL)
			gtk_menu_shell_append (GTK_MENU_SHELL (places_menu),
					       item);
	}

	add_menu_separator (places_menu);

	panel_menu_items_append_from_desktop (places_menu,
					      "mate-search-tool.desktop",
					      NULL,
                                              FALSE);

	panel_recent_append_documents_menu (places_menu,
					    place_item->priv->recent_manager);

	return places_menu;
}
static void indicator_rest_coupon_cb(GtkWidget *widget, gpointer data)
{
  IIJmioIndicatorOption *option = data;
  const gchar *access_token;
  gboolean enable_debug;
  CURL *curl;
  CURLcode res;
  struct curl_slist *chunk = NULL;
  FILE *json_file;
  gchar *json_path;
  gchar *json_dir;
  gchar *token_header;
  const gchar *home_dir;
  gchar *basename;
  GDateTime *datetime;

  access_token = gtk_entry_get_text(GTK_ENTRY(option->widgets.access_token));

  curl_global_init(CURL_GLOBAL_DEFAULT);
  curl = curl_easy_init();
  if (curl) {
    curl_easy_setopt(curl,
                     CURLOPT_URL,
                     "https://api.iijmio.jp/mobile/d/v1/coupon/");
    chunk = curl_slist_append(chunk,
                              "X-IIJmio-Developer: XpVuCioCmLzAeewwiDs");
    token_header = g_strdup_printf("%s: %s",
                                   "X-IIJmio-Authorization", access_token);
    chunk = curl_slist_append(chunk, token_header);
    res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);

    home_dir = g_get_home_dir();
    json_dir = g_build_path(G_DIR_SEPARATOR_S,
                            home_dir,
                            ".iijmio-appindicator",
                            "json",
                            NULL);
    g_mkdir_with_parents(json_dir, 0700);

    datetime = g_date_time_new_now_local();
    basename = g_date_time_format(datetime, "%Y%m%d-%H%M%S");
    json_path = g_strdup_printf("%s%s%s.json",
                                json_dir,
                                G_DIR_SEPARATOR_S,
                                basename);

    json_file = fopen(json_path, "w+");
    if (json_file) {

      curl_easy_setopt(curl, CURLOPT_FILE, json_file);

      res = curl_easy_perform(curl);
      if (res != CURLE_OK) {
        fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));
      }
      fclose(json_file);
    }
    g_free(token_header);
    curl_easy_cleanup(curl);
  }
  curl_global_cleanup();
}
static void
terminal_nautilus_menu_item_activate (NautilusMenuItem *item)
{
  TerminalNautilusMenuItem *menu_item = TERMINAL_NAUTILUS_MENU_ITEM (item);
  TerminalNautilus *nautilus = menu_item->nautilus;
  char *uri, *path;
  TerminalFileInfo info;
  ExecData *data;

  uri = nautilus_file_info_get_activation_uri (menu_item->file_info);
  if (uri == NULL)
    return;

  path = NULL;
  info = get_terminal_file_info_from_uri (uri);

  switch (info) {
    case FILE_INFO_LOCAL:
      path = g_filename_from_uri (uri, NULL, NULL);
      break;

    case FILE_INFO_DESKTOP:
      if (desktop_is_home_dir (nautilus) || desktop_opens_home_dir (nautilus)) {
        path = g_strdup (g_get_home_dir ());
      } else {
        path = g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP));
      }
      break;

    case FILE_INFO_SFTP:
      if (menu_item->remote_terminal)
        break;

      /* fall through */

    case FILE_INFO_OTHER: {
      GFile *file;

      /* map back remote URI to local path */
      file = g_file_new_for_uri (uri);
      path = g_file_get_path (file);
      g_object_unref (file);
      break;
    }

    default:
      g_assert_not_reached ();
  }

  if (path == NULL && (info != FILE_INFO_SFTP || !menu_item->remote_terminal)) {
    g_free (uri);
    return;
  }

  data = g_new (ExecData, 1);
  data->nautilus = g_object_ref (nautilus);
  data->timestamp = gtk_get_current_event_time ();
  data->path = path;
  data->uri = uri;
  data->display = gdk_screen_make_display_name (menu_item->screen);
  data->info = info;
  data->remote = menu_item->remote_terminal;
  data->run_in_mc = menu_item->run_in_mc;

  create_terminal (data);
}
Example #12
0
int
main (int argc, char **argv)
{
  GApplication *app;
  int exit_code = EXIT_FAILURE;
  const char *home_dir, *charset;
  GError *error = NULL;

  if (G_UNLIKELY ((getuid () != geteuid () ||
                  getgid () != getegid ()) &&
                  geteuid () == 0 &&
                  getegid () == 0)) {
    g_printerr ("Wrong euid/egid, exiting.\n");
    return _EXIT_FAILURE_WRONG_ID;
  }

  setlocale (LC_ALL, "");

  terminal_i18n_init (TRUE);

  if (!g_get_charset (&charset)) {
    g_printerr ("Non UTF-8 locale (%s) is not supported!\n", charset);
    return _EXIT_FAILURE_NO_UTF8;
  }

#ifndef ENABLE_DISTRO_PACKAGING
#ifdef HAVE_UBUNTU
  /* Set some env vars to disable the ubuntu modules. Their package will be 
   * built using --enable-distro-packaging, but anyone running from git will
   * get the right behaviour.
   */
  g_setenv ("LIBOVERLAY_SCROLLBAR", "0", TRUE);
  g_setenv ("UBUNTU_MENUPROXY", "0", TRUE);
  g_setenv ("NO_UNITY_GTK_MODULE", "1", TRUE);
#endif
#endif

  _terminal_debug_init ();

  // FIXMEchpe: just use / here but make sure #565328 doesn't regress
  /* Change directory to $HOME so we don't prevent unmounting, e.g. if the
   * factory is started by nautilus-open-terminal. See bug #565328.
   * On failure back to /.
   */
  home_dir = g_get_home_dir ();
  if (home_dir == NULL || chdir (home_dir) < 0)
    (void) chdir ("/");

  g_set_prgname ("gnome-terminal-server");
  g_set_application_name (_("Terminal"));

  if (!gtk_init_with_args (&argc, &argv, NULL, options, NULL, &error)) {
    g_printerr ("Failed to parse arguments: %s\n", error->message);
    g_error_free (error);
    exit (EXIT_FAILURE);
  }

  app = terminal_app_new (app_id);
  g_free (app_id);

  if (!g_application_register (app, NULL, &error)) {
    g_printerr ("Failed to register application: %s\n", error->message);
    g_error_free (error);
    goto out;
  }

  if (g_application_get_is_remote (app)) {
    /* How the f**k did this happen? */
    g_printerr ("Cannot be remote instance!\n");
    goto out;
  }

  exit_code = g_application_run (app, 0, NULL);

out:
  g_object_unref (app);

  return exit_code;
}
Example #13
0
/**
 * Set all the config variables to their default values.
 * called before loading the config
 * or for a new opening
 */
static void gsb_file_config_clean_config ( void )
{
    devel_debug (NULL);

    conf.main_width = 0;
    conf.main_height = 0;
    conf.prefs_width = 600;

    conf.force_enregistrement = 1;

    conf.r_modifiable = 0;       /* we can not change the reconciled transaction */
    conf.dernier_fichier_auto = 1;   /*  on n'ouvre pas directement le dernier fichier */
    conf.sauvegarde_auto = 0;    /* on NE sauvegarde PAS * automatiquement par défaut */
    conf.entree = 1;    /* la touche entree provoque l'enregistrement de l'opération */
    nb_days_before_scheduled = 0;     /* nb de jours avant l'échéance pour prévenir */
    conf.execute_scheduled_of_month = FALSE;
    conf.balances_with_scheduled = TRUE;
    conf.formulaire_toujours_affiche = 0;           /* le formulaire ne s'affiche que lors de l'edition d'1 opé */
    conf.affichage_exercice_automatique = 0;        /* l'exercice est choisi en fonction de la date */
    conf.automatic_completion_payee = 1;            /* by default automatic completion */
    conf.limit_completion_to_current_account = 0;   /* By default, do full search */
    conf.automatic_recover_splits = 1;
    conf.automatic_erase_credit_debit = 0;

    conf.display_grisbi_title = GSB_ACCOUNTS_TITLE; /* show Accounts file title par défaut */
    conf.display_toolbar = GSB_BUTTON_BOTH;         /* How to display toolbar icons. */
    conf.active_scrolling_left_pane = FALSE;        /* Active_scrolling_left_pane or not. */
    conf.show_headings_bar = TRUE;                  /* Show toolbar or not. */
    conf.show_transaction_selected_in_form = 1;     /* show selected transaction in form */
    conf.show_transaction_gives_balance = 1;        /* show transaction that gives the balance of the day */
    conf.transactions_list_primary_sorting = 1;     /* Primary sorting option for the transactions */
    conf.transactions_list_secondary_sorting = 0;   /* Secondary sorting option for the transactions */
    conf.show_closed_accounts = FALSE;

    if ( conf.font_string )
    {
    g_free ( conf.font_string );
    conf.font_string = NULL;
    }

    conf.force_enregistrement = 1;     /* par défaut, on force l'enregistrement */
    gsb_file_update_last_path (g_get_home_dir ());
    gsb_file_set_backup_path ( gsb_dirs_get_user_data_dir () );
    conf.make_backup = 1;
    conf.make_backup_every_minutes = FALSE;
    conf.make_backup_nb_minutes = 0;

#if IS_DEVELOPMENT_VERSION == 1
    conf.stable_config_file_model = 0;
#endif

    conf.nb_derniers_fichiers_ouverts = 0;
    conf.nb_max_derniers_fichiers_ouverts = 3;
    tab_noms_derniers_fichiers_ouverts = NULL;

    /* no compress by default */
    conf.compress_file = 0;
    conf.compress_backup = 0;

    /* archive data */
    conf.check_for_archival = TRUE;
    conf.max_non_archived_transactions_for_check = 3000;

    conf.last_tip = -1;
    conf.show_tip = FALSE;

    /* mise en conformité avec les recommandations FreeDesktop. */
    if ( conf.browser_command )
        g_free ( conf.browser_command );
    conf.browser_command = g_strdup ( ETAT_WWW_BROWSER );

    conf.metatree_action_2button_press = 0;     /* action par défaut pour le double clic sur division */

    memset ( etat.csv_skipped_lines, '\0', sizeof(gboolean) * CSV_MAX_TOP_LINES );
}
Example #14
0
/**
 * called for each new element in the last xml config file
 * see the g_lib doc for the description of param
 *
 * \param context
 * \param text
 * \param text_len
 * \param user_data
 * \param error
 *
 * \return
 * */
static void gsb_file_config_get_xml_text_element ( GMarkupParseContext *context,
                        const gchar *text,
                        gsize text_len,
                        gpointer user_data,
                        GError **error)
{
    const gchar *element_name;
    gint i;

    element_name = g_markup_parse_context_get_element ( context );

    if ( !strcmp ( element_name,
		   "Width" ))
    {
	conf.main_width = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Height" ))
    {
	conf.main_height = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Modification_operations_rapprochees" ))
    {
	conf.r_modifiable = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Dernier_chemin_de_travail" ))
    {
	gsb_file_update_last_path (text);

	if ( !gsb_file_get_last_path ()
	     ||
	     !strlen (gsb_file_get_last_path ()))
	    gsb_file_update_last_path (g_get_home_dir ());
	return;
    }

    if ( !strcmp ( element_name,
		   "Affichage_alerte_permission" ))
    {
	 conf.alerte_permission = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Force_enregistrement" ))
    {
	conf.force_enregistrement = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Fonction_touche_entree" ))
    {
	conf.entree = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Affichage_messages_alertes" ))
    {
	conf.alerte_mini = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Utilise_fonte_des_listes" ))
    {
	conf.utilise_fonte_listes = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Fonte_des_listes" ))
    {
	conf.font_string = my_strdup (text);
	return;
    }
     if ( !strcmp ( element_name,
		   "Navigateur_web" ))
    {
        if ( conf.browser_command )
            g_free ( conf.browser_command );
	conf.browser_command = my_strdelimit (text,
					      "\\e",
					      "&" );
	return;
    }

    if ( !strcmp ( element_name,
		   "Largeur_colonne_echeancier" ))
    {
	etat.largeur_colonne_echeancier = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Largeur_colonne_comptes_comptes" ))
    {
	etat.largeur_colonne_comptes_comptes = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Largeur_colonne_etats" ))
    {
	etat.largeur_colonne_etat = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Chargement_auto_dernier_fichier" ))
    {
	conf.dernier_fichier_auto = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Nom_dernier_fichier" ))
    {
	nom_fichier_comptes = my_strdup (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Enregistrement_automatique" ))
    {
	conf.sauvegarde_auto = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Enregistrement_au_demarrage" ))
    {
	conf.sauvegarde_demarrage = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Nb_max_derniers_fichiers_ouverts" ))
    {
	conf.nb_max_derniers_fichiers_ouverts = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Compression_fichier" ))
    {
	conf.compress_file = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Compression_backup" ))
    {
	conf.compress_backup = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "fichier" ))
    {
	if (!tab_noms_derniers_fichiers_ouverts)
	    tab_noms_derniers_fichiers_ouverts = g_malloc0 ( conf.nb_max_derniers_fichiers_ouverts * sizeof(gchar *) );

	tab_noms_derniers_fichiers_ouverts[conf.nb_derniers_fichiers_ouverts] = my_strdup (text);
	conf.nb_derniers_fichiers_ouverts++;
	return;
    }

    if ( !strcmp ( element_name,
		   "Delai_rappel_echeances" ))
    {
	nb_days_before_scheduled = utils_str_atoi (text);
	conf.execute_scheduled_of_month = FALSE;
	return;
    }

    if ( !strcmp ( element_name,
		   "Affichage_formulaire" ))
    {
	conf.formulaire_toujours_affiche = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "Affichage_exercice_automatique" ))
    {
	conf.affichage_exercice_automatique = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "display_toolbar" ))
    {
	conf.display_toolbar = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "show_closed_accounts" ))
    {
	conf.show_closed_accounts = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "show_tip" ))
    {
	conf.show_tip = utils_str_atoi (text);
	return;
    }

    if ( !strcmp ( element_name,
		   "last_tip" ))
    {
	conf.last_tip = utils_str_atoi (text);
	return;
    }

    for ( i = 0; messages[i].name; i++ )
    {
	if ( !strcmp ( element_name, messages[i].name ) )
	{
	    messages[i].hidden = utils_str_atoi (text);
	}
    }
}
Example #15
0
int
main (int argc, char **argv)
{
	DBusGConnection *session_bus;
	GError *error = NULL;
	RBShell *rb_shell;
	gboolean activated;
	gboolean autostarted;
	char *accel_map_file = NULL;
	char *desktop_file_path;

	GOptionContext *context;
	static const GOptionEntry options []  = {
		{ "debug",           'd', 0, G_OPTION_ARG_NONE,         &debug,           N_("Enable debug output"), NULL },
		{ "debug-match",     'D', 0, G_OPTION_ARG_STRING,       &debug_match,     N_("Enable debug output matching a specified string"), NULL },
		{ "no-update",	       0, 0, G_OPTION_ARG_NONE,         &no_update,       N_("Do not update the library with file changes"), NULL },
		{ "no-registration", 'n', 0, G_OPTION_ARG_NONE,         &no_registration, N_("Do not register the shell"), NULL },
		{ "dry-run",	       0, 0, G_OPTION_ARG_NONE,         &dry_run,         N_("Don't save any data permanently (implies --no-registration)"), NULL },
		{ "disable-plugins",   0, 0, G_OPTION_ARG_NONE,         &disable_plugins, N_("Disable loading of plugins"), NULL },
		{ "rhythmdb-file",     0, 0, G_OPTION_ARG_STRING,       &rhythmdb_file,   N_("Path for database file to use"), NULL },
		{ "playlists-file",    0, 0, G_OPTION_ARG_STRING,       &playlists_file,   N_("Path for playlists file to use"), NULL },
		{ "quit",	     'q', 0, G_OPTION_ARG_NONE,         &quit,            N_("Quit Rhythmbox"), NULL },
		{ G_OPTION_REMAINING,  0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining_args,  NULL, N_("[URI...]") },
		{ NULL }
	};

	g_thread_init (NULL);

	rb_profile_start ("starting rhythmbox");

	autostarted = (g_getenv ("DESKTOP_AUTOSTART_ID") != NULL);

#ifdef USE_UNINSTALLED_DIRS
	desktop_file_path = g_build_filename (SHARE_UNINSTALLED_BUILDDIR, "rhythmbox.desktop", NULL);

	g_setenv ("GSETTINGS_SCHEMA_DIR", SHARE_UNINSTALLED_BUILDDIR, TRUE);
#else
	desktop_file_path = g_build_filename (DATADIR, "applications", "rhythmbox.desktop", NULL);
#endif
	egg_set_desktop_file (desktop_file_path);
	g_free (desktop_file_path);

	context = g_option_context_new (NULL);
	g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);

	rb_profile_start ("initializing gstreamer");
	g_option_context_add_group (context, gst_init_get_option_group ());
	rb_profile_end ("initializing gstreamer");

	g_option_context_add_group (context, egg_sm_client_get_option_group ());
	g_option_context_add_group (context, gtk_get_option_group (TRUE));

	setlocale (LC_ALL, NULL);

	rb_profile_start ("parsing command line options");
	if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
		g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
			 error->message, argv[0]);
		g_error_free (error);
		g_option_context_free (context);
		exit (1);
	}
	g_option_context_free (context);
	rb_profile_end ("parsing command line options");

	g_random_set_seed (time (0));

#ifdef ENABLE_NLS
	/* initialize i18n */
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

	/* ask for utf-8 message text from GStreamer too,
	 * since it doesn't do that itself.
	 */
	bind_textdomain_codeset ("gstreamer-0.10", "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif

	if (!debug && debug_match)
		rb_debug_init_match (debug_match);
	else
		rb_debug_init (debug);
	rb_debug ("initializing Rhythmbox %s", VERSION);

#if defined(USE_UNINSTALLED_DIRS)
	g_irepository_prepend_search_path (SHARE_UNINSTALLED_BUILDDIR "/../bindings/gi");
#endif

	/* TODO: kill this function */
	rb_threads_init ();
	gdk_threads_enter ();

	activated = FALSE;

	rb_debug ("going to create DBus object");

	dbus_g_thread_init ();

	session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
	if (session_bus == NULL) {
		g_warning ("couldn't connect to session bus: %s", (error) ? error->message : "(null)");
		g_clear_error (&error);
	} else if (!no_registration) {
		guint request_name_reply;
		int flags;
#ifndef DBUS_NAME_FLAG_DO_NOT_QUEUE
		flags = DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT;
#else
		flags = DBUS_NAME_FLAG_DO_NOT_QUEUE;
#endif

		DBusGProxy *bus_proxy;

		bus_proxy = dbus_g_proxy_new_for_name (session_bus,
						       "org.freedesktop.DBus",
						       "/org/freedesktop/DBus",
						       "org.freedesktop.DBus");

		if (!dbus_g_proxy_call (bus_proxy,
					"RequestName",
					&error,
					G_TYPE_STRING,
					"org.gnome.Rhythmbox",
					G_TYPE_UINT,
					flags,
					G_TYPE_INVALID,
					G_TYPE_UINT,
					&request_name_reply,
					G_TYPE_INVALID)) {
			g_warning ("Failed to invoke RequestName: %s",
				   error->message);
		}
		g_object_unref (bus_proxy);

		if (request_name_reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER
		    || request_name_reply == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER)
			activated = FALSE;
		else if (request_name_reply == DBUS_REQUEST_NAME_REPLY_EXISTS
			 || request_name_reply == DBUS_REQUEST_NAME_REPLY_IN_QUEUE)
			activated = TRUE;
		else {
			g_warning ("Got unhandled reply %u from RequestName",
				   request_name_reply);
			activated = FALSE;
		}
	}

	if (!activated) {
		if (quit) {
			rb_debug ("was asked to quit, but no instance was running");
			gdk_notify_startup_complete ();
			exit (0);
		}
#ifdef WITH_RHYTHMDB_GDA
		gda_init (PACKAGE, VERSION, argc, argv);
#endif

		rb_refstring_system_init ();

#ifdef USE_UNINSTALLED_DIRS
		rb_file_helpers_init (TRUE);
#else
		rb_file_helpers_init (FALSE);
#endif

		/* XXX not sure what to do with this.  should we move it to
		 * the config dir, or leave it where it is?
		 */
		accel_map_file = g_build_filename (g_get_home_dir (),
						   ".gnome2",
						   "accels",
						   "rhythmbox",
						   NULL);
		gtk_accel_map_load (accel_map_file);


		rb_debug ("Going to create a new shell");

		rb_stock_icons_init ();

		g_setenv ("PULSE_PROP_media.role", "music", TRUE);

		rb_shell = rb_shell_new (no_registration, no_update, dry_run, autostarted, disable_plugins, rhythmdb_file, playlists_file);
		g_object_weak_ref (G_OBJECT (rb_shell), main_shell_weak_ref_cb, NULL);
		if (!no_registration && session_bus != NULL) {
			dbus_g_object_type_install_info (RB_TYPE_SHELL, &dbus_glib_rb_shell_object_info);
			dbus_g_connection_register_g_object (session_bus, "/org/gnome/Rhythmbox/Shell", G_OBJECT (rb_shell));

			g_signal_connect (G_OBJECT (rb_shell),
					  "database-load-complete",
					  G_CALLBACK (database_load_complete),
					  NULL);
		}
	} else if (!no_registration && session_bus != NULL) {
		DBusGProxy *shell_proxy;
		guint32 current_time;
		current_time = gdk_x11_display_get_user_time (gdk_display_get_default ());
		shell_proxy = dbus_g_proxy_new_for_name_owner (session_bus,
							       "org.gnome.Rhythmbox",
							       "/org/gnome/Rhythmbox/Shell",
							       "org.gnome.Rhythmbox.Shell",
							       &error);
		if (!shell_proxy) {
			g_warning ("Couldn't create proxy for Rhythmbox shell: %s",
				   error->message);
		} else {
			if (quit) {
				dbus_g_proxy_call_no_reply (shell_proxy, "quit",
							    G_TYPE_INVALID);
			} else {
				load_uri_args ((const char **) remaining_args, (GFunc) dbus_load_uri, shell_proxy);
				dbus_g_proxy_call_no_reply (shell_proxy, "present",
							    G_TYPE_UINT, current_time,
							    G_TYPE_INVALID);
			}
			g_object_unref (G_OBJECT (shell_proxy));
		}
	}

	if (activated) {
		gdk_notify_startup_complete ();
	} else {

		rb_profile_start ("mainloop");
#ifdef ENABLE_PYTHON
		if (rb_python_init_successful ()) {
			pyg_begin_allow_threads;
			gtk_main ();
			pyg_end_allow_threads;
		} else {
			gtk_main ();
		}
#else
		gtk_main ();
#endif
		rb_profile_end ("mainloop");

		rb_debug ("out of toplevel loop");

		rb_file_helpers_shutdown ();
		rb_stock_icons_shutdown ();
		rb_refstring_system_shutdown ();
	}

	gst_deinit ();

	rb_debug ("THE END");
	rb_profile_end ("starting rhythmbox");

	if (accel_map_file != NULL) {
		gtk_accel_map_save (accel_map_file);
	}

	gdk_threads_leave ();

	exit (0);
}
Example #16
0
static void
activate_home_uri (GtkWidget *menuitem,
		   gpointer   data)
{
	activate_path (menuitem, g_get_home_dir ());
}
static gpointer
dropbox_command_client_thread(DropboxCommandClient *dcc) {
  struct sockaddr_un addr;
  socklen_t addr_len;
  int connection_attempts = 1;

  /* intialize address structure */
  addr.sun_family = AF_UNIX;
  g_snprintf(addr.sun_path,
	     sizeof(addr.sun_path),
	     "%s/.dropbox/command_socket",
	     g_get_home_dir());
  addr_len = sizeof(addr) - sizeof(addr.sun_path) + strlen(addr.sun_path);

  while (1) {
    GIOChannel *chan = NULL;
    GError *gerr = NULL;
    int sock;
    gboolean failflag = TRUE;

    do {
      int flags;

      if (0 > (sock = socket(PF_UNIX, SOCK_STREAM, 0))) {
	/* WTF */
	break;
      }

      /* set timeout on socket, to protect against
	 bad servers */
      {
	struct timeval tv = {3, 0};
	if (0 > setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
			   &tv, sizeof(struct timeval)) ||
	    0 > setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
			   &tv, sizeof(struct timeval))) {
	  /* debug("setsockopt failed"); */
	  break;
	}
      }

      /* set native non-blocking, for connect timeout */
      {
	if ((flags = fcntl(sock, F_GETFL, 0)) < 0 ||
	    fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) {
	  /* debug("fcntl failed"); */
	  break;
	}
      }

      /* if there was an error we have to try again later */
      if (connect(sock, (struct sockaddr *) &addr, addr_len) < 0) {
	if (errno == EINPROGRESS) {
	  fd_set writers;
	  struct timeval tv = {1, 0};

	  FD_ZERO(&writers);
	  FD_SET(sock, &writers);

	  /* if nothing was ready after 3 seconds, fail out homie */
	  if (select(sock+1, NULL, &writers, NULL, &tv) == 0) {
	    /* debug("connection timeout"); */
	    break;
	  }

	  if (connect(sock, (struct sockaddr *) &addr, addr_len) < 0) {
	    /*	    debug("couldn't connect to command server after 1 second"); */
	    break;
	  }
	}
	/* errno != EINPROGRESS */
	else {
	  /*	  debug("bad connection"); */
	  break;
	}
      }

      /* set back to blocking */
      if (fcntl(sock, F_SETFL, flags) < 0) {
	/* debug("fcntl2 failed"); */
	break;
      }

      failflag = FALSE;
    } while (0);

    if (failflag) {
      ConnectionAttempt *ca = g_new(ConnectionAttempt, 1);
      ca->dcc = dcc;
      ca->connect_attempt = connection_attempts;
      g_idle_add((GSourceFunc) on_connection_attempt, ca);
      if (sock >= 0) {
	close(sock);
      }
      g_usleep(G_USEC_PER_SEC);
      connection_attempts++;
      continue;
    }
    else {
      connection_attempts = 0;
    }

    /* connected */
    debug("command client connected");

    chan = g_io_channel_unix_new(sock);
    g_io_channel_set_close_on_unref(chan, TRUE);
    g_io_channel_set_line_term(chan, "\n", -1);

#define SET_CONNECTED_STATE(s)     {			\
      g_mutex_lock(dcc->command_connected_mutex);	\
      dcc->command_connected = s;			\
      g_mutex_unlock(dcc->command_connected_mutex);	\
    }

    SET_CONNECTED_STATE(TRUE);

    g_idle_add((GSourceFunc) on_connect, dcc);

    while (1) {
      DropboxCommand *dc;

      while (1) {
	GTimeVal gtv;

	g_get_current_time(&gtv);
	g_time_val_add(&gtv, G_USEC_PER_SEC / 10);
	/* get a request from caja */
	dc = g_async_queue_timed_pop(dcc->command_queue, &gtv);
	if (dc != NULL) {
	  break;
	}
	else {
	  if (check_connection(chan) == FALSE) {
	    goto BADCONNECTION;
	  }
	}
      }

      /* this pointer should be unique */
      if ((gpointer (*)(DropboxCommandClient *data)) dc == &dropbox_command_client_thread) {
	debug("got a reset request");
	goto BADCONNECTION;
      }

      switch (dc->request_type) {
      case GET_FILE_INFO: {
	debug("doing file info command");
	do_file_info_command(chan, (DropboxFileInfoCommand *) dc, &gerr);
      }
	break;
      case GENERAL_COMMAND: {
	debug("doing general command");
	do_general_command(chan, (DropboxGeneralCommand *) dc, &gerr);
      }
	break;
      default: 
	g_assert_not_reached();
	break;
      }
      
      debug("done.");

      if (gerr != NULL) {
	//	debug("COMMAND ERROR*****************************");
	/* mark this request as never to be completed */
	end_request(dc);

	debug("command error: %s", gerr->message);
	
	g_error_free(gerr);
      BADCONNECTION:
	/* grab all the rest of the data off the async queue and mark it
	   never to be completed, who knows how long we'll be disconnected */
	while ((dc = g_async_queue_try_pop(dcc->command_queue)) != NULL) {
	  end_request(dc);
	}

	g_io_channel_unref(chan);

	SET_CONNECTED_STATE(FALSE);

	/* call the disconnect handler */
	g_idle_add((GSourceFunc) on_disconnect, dcc);

	break;
      }
    }
    
#undef SET_CONNECTED_STATE
  }
  
  return NULL;
}
Example #18
0
static void
panel_place_menu_item_init (PanelPlaceMenuItem *menuitem)
{
	GFile *bookmark;
	char  *bookmarks_filename;
	GError *error;

	menuitem->priv = PANEL_PLACE_MENU_ITEM_GET_PRIVATE (menuitem);

	menuitem->priv->caja_desktop_settings = g_settings_new (CAJA_DESKTOP_SCHEMA);
	menuitem->priv->caja_prefs_settings = g_settings_new (CAJA_PREFS_SCHEMA);

	g_signal_connect (menuitem->priv->caja_desktop_settings,
			  "changed::" CAJA_DESKTOP_HOME_ICON_NAME_KEY,
			  G_CALLBACK (panel_place_menu_item_key_changed),
			  G_OBJECT (menuitem));
	g_signal_connect (menuitem->priv->caja_desktop_settings,
			  "changed::" CAJA_DESKTOP_COMPUTER_ICON_NAME_KEY,
			  G_CALLBACK (panel_place_menu_item_key_changed),
			  G_OBJECT (menuitem));
	g_signal_connect (menuitem->priv->caja_prefs_settings,
			  "changed::" CAJA_PREFS_DESKTOP_IS_HOME_DIR_KEY,
			  G_CALLBACK (panel_place_menu_item_key_changed),
			  G_OBJECT (menuitem));

	menuitem->priv->recent_manager = gtk_recent_manager_get_default ();

	bookmarks_filename = g_build_filename (g_get_home_dir (),
					       BOOKMARKS_FILENAME, NULL);
	bookmark = g_file_new_for_path (bookmarks_filename);

	error = NULL;
	menuitem->priv->bookmarks_monitor = g_file_monitor_file
        						(bookmark,
        						G_FILE_MONITOR_NONE,
        						NULL,
        						&error);
	if (error) {
		g_warning ("Failed to add file monitor for %s: %s\n",
			   bookmarks_filename, error->message);
		g_error_free (error);
	} else {
		g_signal_connect (G_OBJECT (menuitem->priv->bookmarks_monitor),
				  "changed",
				  (GCallback) panel_place_menu_item_gtk_bookmarks_changed,
				  menuitem);
	}

	g_object_unref (bookmark);
	g_free (bookmarks_filename);

	menuitem->priv->volume_monitor = g_volume_monitor_get ();

	menuitem->priv->drive_changed_id = g_signal_connect (menuitem->priv->volume_monitor,
							   "drive-changed",
							   G_CALLBACK (panel_place_menu_item_drives_changed),
							   menuitem);
	menuitem->priv->drive_connected_id = g_signal_connect (menuitem->priv->volume_monitor,
							     "drive-connected",
							     G_CALLBACK (panel_place_menu_item_drives_changed),
							     menuitem);
	menuitem->priv->drive_disconnected_id = g_signal_connect (menuitem->priv->volume_monitor,
							     "drive-disconnected",
							     G_CALLBACK (panel_place_menu_item_drives_changed),
							     menuitem);
	menuitem->priv->volume_added_id = g_signal_connect (menuitem->priv->volume_monitor,
							   "volume-added",
							   G_CALLBACK (panel_place_menu_item_volumes_changed),
							   menuitem);
	menuitem->priv->volume_changed_id = g_signal_connect (menuitem->priv->volume_monitor,
							     "volume-changed",
							     G_CALLBACK (panel_place_menu_item_volumes_changed),
							     menuitem);
	menuitem->priv->volume_removed_id = g_signal_connect (menuitem->priv->volume_monitor,
							     "volume-removed",
							     G_CALLBACK (panel_place_menu_item_volumes_changed),
							     menuitem);
	menuitem->priv->mount_added_id = g_signal_connect (menuitem->priv->volume_monitor,
							   "mount-added",
							   G_CALLBACK (panel_place_menu_item_mounts_changed),
							   menuitem);
	menuitem->priv->mount_changed_id = g_signal_connect (menuitem->priv->volume_monitor,
							     "mount-changed",
							     G_CALLBACK (panel_place_menu_item_mounts_changed),
							     menuitem);
	menuitem->priv->mount_removed_id = g_signal_connect (menuitem->priv->volume_monitor,
							     "mount-removed",
							     G_CALLBACK (panel_place_menu_item_mounts_changed),
							     menuitem);

}
Example #19
0
File: init.c Project: UIKit0/eXtace
void save_config(GtkWidget *widget)
{
	gchar *filename;
	ConfigFile *cfgfile;
	gint x;
	gint y;
	filename = g_strconcat(g_get_home_dir(), "/.eXtace/config", NULL);
	cfgfile = cfg_open_file(filename);
	if (!cfgfile)
		cfgfile = cfg_new();

	cfg_write_int(cfgfile, "Global", "major_ver", _MAJOR_);
	cfg_write_int(cfgfile, "Global", "minor_ver", _MINOR_);
	cfg_write_int(cfgfile, "Global", "micro_ver", _MICRO_);
	if (Color_map.filename)
		cfg_write_string(cfgfile, "Global", "last_colormap", Color_map.filename);
	else
		cfg_write_string(cfgfile, "Global", "last_colormap",g_strconcat(g_get_home_dir(),"/.eXtace/ColorMaps/","Default",NULL));
	cfg_write_int(cfgfile, "Global", "mode", mode);
	cfg_write_int(cfgfile, "Global", "data_source", data_source);
	cfg_write_int(cfgfile, "Global", "decimation_factor", decimation_factor);
	cfg_write_int(cfgfile, "Global", "fft_signal_source", fft_signal_source);
	cfg_write_float(cfgfile, "Global", "scope_zoom", scope_zoom);
	cfg_write_int(cfgfile, "Global", "refresh_rate", refresh_rate);
	cfg_write_int(cfgfile, "Global", "landflip", landflip);
	cfg_write_int(cfgfile, "Global", "spikeflip", spikeflip);
	cfg_write_boolean(cfgfile, "Global", "outlined", outlined);
	cfg_write_int(cfgfile, "Global", "sub_mode_3D", sub_mode_3D);
	cfg_write_int(cfgfile, "Global", "scope_sub_mode", scope_sub_mode);
	cfg_write_boolean(cfgfile, "Global", "dir_win_present", dir_win_present);
	cfg_write_int(cfgfile, "Global", "nsamp", nsamp);
	cfg_write_int(cfgfile, "Global", "window_func", window_func);
	cfg_write_int(cfgfile, "Global", "win_width", win_width);
	cfg_write_int(cfgfile, "Global", "axis_type", axis_type);
	cfg_write_int(cfgfile, "Global", "bands", bands);
	cfg_write_int(cfgfile, "Global", "lag", lag);
	cfg_write_float(cfgfile, "Global", "noise_floor", noise_floor);
	cfg_write_int(cfgfile, "Global", "seg_height", seg_height);
	cfg_write_int(cfgfile, "Global", "seg_space", seg_space);
	cfg_write_boolean(cfgfile, "Global", "bar_decay", bar_decay);
	cfg_write_boolean(cfgfile, "Global", "peak_decay", peak_decay);
	cfg_write_boolean(cfgfile, "Global", "stabilized", stabilized);
	cfg_write_boolean(cfgfile, "Global", "show_graticule", show_graticule);
	cfg_write_int(cfgfile, "Global", "decay_speed", bar_decay_speed);
	cfg_write_int(cfgfile, "Global", "peak_decay_speed", peak_decay_speed);
	cfg_write_int(cfgfile, "Global", "peak_hold_time", peak_hold_time);
	cfg_write_int(cfgfile, "Global", "tape_scroll", tape_scroll);
	cfg_write_int(cfgfile, "Global", "xdet_scroll", xdet_scroll);
	cfg_write_int(cfgfile, "Global", "zdet_scroll", zdet_scroll);
	cfg_write_float(cfgfile, "Global", "xdet_start", xdet_start);
	cfg_write_float(cfgfile, "Global", "xdet_end", xdet_end);
	cfg_write_float(cfgfile, "Global", "ydet_start", ydet_start);
	cfg_write_float(cfgfile, "Global", "ydet_end", ydet_end);
	cfg_write_float(cfgfile, "Global", "x3d_start", x3d_start);
	cfg_write_float(cfgfile, "Global", "x3d_end", x3d_end);
	cfg_write_float(cfgfile, "Global", "y3d_start", y3d_start);
	cfg_write_float(cfgfile, "Global", "y3d_end", y3d_end);
	cfg_write_float(cfgfile, "Global", "multiplier", multiplier);
	cfg_write_int(cfgfile, "Global", "horiz_spec_start", horiz_spec_start);
	cfg_write_int(cfgfile, "Global", "vert_spec_start", vert_spec_start);
	cfg_write_int(cfgfile, "Global", "x3d_scroll", x3d_scroll);
	cfg_write_int(cfgfile, "Global", "z3d_scroll", z3d_scroll);
	cfg_write_boolean(cfgfile, "Global", "show_leader", show_leader);
	cfg_write_int(cfgfile, "Global", "scope_sync_source", scope_sync_source);
	cfg_write_boolean(cfgfile, "Global", "landtilt",landtilt);
	cfg_write_boolean(cfgfile, "Global", "spiketilt", spiketilt);
	cfg_write_float(cfgfile, "Global", "low_freq", low_freq);
	cfg_write_float(cfgfile, "Global", "high_freq", high_freq);
	cfg_write_int(cfgfile, "Window", "width", width);
	cfg_write_int(cfgfile, "Window", "height", height+22);
	gdk_window_get_root_origin(widget->window, &x, &y);
	cfg_write_int(cfgfile, "Window", "main_x_origin", x);
	cfg_write_int(cfgfile, "Window", "main_y_origin", y);
	//    cfg_write_boolean(cfgfile, "Window", "grad_win_present", grad_win_present);
	if (grad_win_present)
	{
		gdk_window_get_root_origin((gpointer) grad_win_ptr->window, &x, &y);
		cfg_write_int(cfgfile, "Window", "grad_x_origin", x);
		cfg_write_int(cfgfile, "Window", "grad_y_origin", y);
	}
	if (dir_win_present)
	{
		gdk_window_get_root_origin((gpointer) dir_win_ptr->window, &x, &y);
		cfg_write_int(cfgfile, "Window", "dir_x_origin", x);
		cfg_write_int(cfgfile, "Window", "dir_y_origin", y);
	}

	cfg_write_file(cfgfile, filename);
	cfg_free(cfgfile);

	g_free(filename);

}
Example #20
0
static void
panel_place_menu_item_append_gtk_bookmarks (GtkWidget *menu)
{
	typedef struct {
		char *full_uri;
		char *label;
	} PanelBookmark;

	GtkWidget   *add_menu;
	char        *filename;
	GIOChannel  *io_channel;
	GHashTable  *table;
	int          i;
	GSList      *lines = NULL;
	GSList      *add_bookmarks, *l;
	PanelBookmark *bookmark;

	filename = g_build_filename (g_get_home_dir (),
				     BOOKMARKS_FILENAME, NULL);

	io_channel = g_io_channel_new_file (filename, "r", NULL);
	g_free (filename);

	if (!io_channel)
		return;

	/* We use a hard limit to avoid having users shooting their
	 * own feet, and to avoid crashing the system if a misbehaving
	 * application creates a big bookmars file.
	 */
	for (i = 0; i < MAX_BOOKMARK_ITEMS; i++) {
		char      *contents;
		gsize      length;
		gsize      terminator_pos;
		GIOStatus  status;

		status = g_io_channel_read_line (io_channel, &contents, &length, &terminator_pos, NULL);

		if (status != G_IO_STATUS_NORMAL)
			break;

		if (length == 0)
			break;

		/* Clear the line terminator (\n), if any */
		if (terminator_pos > 0)
			contents[terminator_pos] = '\0';

		lines = g_slist_prepend (lines, contents);
	}

	g_io_channel_shutdown (io_channel, FALSE, NULL);
	g_io_channel_unref (io_channel);

	if (!lines)
		return;

	lines = g_slist_reverse (lines);

	table = g_hash_table_new (g_str_hash, g_str_equal);
	add_bookmarks = NULL;

	for (l = lines; l; l = l->next) {
		char *line = (char*) l->data;

		if (line[0] && !g_hash_table_lookup (table, line)) {
			GFile    *file;
			char     *space;
			char     *label;
			gboolean  keep;

			g_hash_table_insert (table, line, line);

			space = strchr (line, ' ');
			if (space) {
				*space = '\0';
				label = g_strdup (space + 1);
			} else {
				label = NULL;
			}

			keep = FALSE;

			if (g_str_has_prefix (line, "x-caja-search:"))
				keep = TRUE;

			if (!keep) {
				file = g_file_new_for_uri (line);
				keep = !g_file_is_native (file) ||
				       g_file_query_exists (file, NULL);
				g_object_unref (file);
			}

			if (!keep) {
				if (label)
					g_free (label);
				continue;
			}

			bookmark = g_malloc (sizeof (PanelBookmark));
			bookmark->full_uri = g_strdup (line);
			bookmark->label = label;
			add_bookmarks = g_slist_prepend (add_bookmarks, bookmark);
		}
	}

	g_hash_table_destroy (table);
	g_slist_foreach (lines, (GFunc) g_free, NULL);
	g_slist_free (lines);

	add_bookmarks = g_slist_reverse (add_bookmarks);

	if (g_slist_length (add_bookmarks) <= MAX_ITEMS_OR_SUBMENU) {
		add_menu = menu;
	} else {
		GtkWidget *item;

		item = gtk_image_menu_item_new ();
		setup_menu_item_with_icon (item, panel_menu_icon_get_size (),
					   PANEL_ICON_BOOKMARKS, NULL, NULL,
					   _("Bookmarks"));

		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
		gtk_widget_show (item);

		add_menu = create_empty_menu ();
		gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), add_menu);
	}

	for (l = add_bookmarks; l; l = l->next) {
		char *display_name;
		char *tooltip;
		char *label;
		char *icon;
		GFile *file;
		GIcon *gicon;

		bookmark = l->data;

		file = g_file_new_for_uri (bookmark->full_uri);
		display_name = g_file_get_parse_name (file);
		g_object_unref (file);
		/* Translators: %s is a URI */
		tooltip = g_strdup_printf (_("Open '%s'"), display_name);
		g_free (display_name);

		label = NULL;
		if (bookmark->label) {
			label = g_strdup (g_strstrip (bookmark->label));
			if (!label [0]) {
				g_free (label);
				label = NULL;
			}
		}

		if (!label) {
			label = panel_util_get_label_for_uri (bookmark->full_uri);

			if (!label) {
				g_free (tooltip);
				g_free (bookmark->full_uri);
				if (bookmark->label)
					g_free (bookmark->label);
				g_free (bookmark);
				continue;
			}
		}

		icon = panel_util_get_icon_for_uri (bookmark->full_uri);
		/*FIXME: we should probably get a GIcon if possible, so that we
		 * have customized icons for cd-rom, eg */
		if (!icon)
			icon = g_strdup (PANEL_ICON_FOLDER);

		gicon = g_themed_icon_new_with_default_fallbacks (icon);

		//FIXME: drag and drop will be broken for x-caja-search uris
		panel_menu_items_append_place_item (icon, gicon,
						    label,
						    tooltip,
						    add_menu,
						    G_CALLBACK (activate_uri),
						    bookmark->full_uri);

		g_free (icon);
		g_object_unref (gicon);
		g_free (tooltip);
		g_free (label);
		g_free (bookmark->full_uri);
		if (bookmark->label)
			g_free (bookmark->label);
		g_free (bookmark);
	}

	g_slist_free (add_bookmarks);
}
Example #21
0
void bluefish_exit_request() {

	GList *tmplist;
	
	gboolean tmpb;
	DEBUG_MSG("winefish_exit_request, started\n");
	/* if we have modified documents we have to do something, file_close_all_cb()
	does exactly want we want to do */
	tmplist = return_allwindows_documentlist();
	tmpb = (tmplist && test_docs_modified(tmplist));
	g_list_free(tmplist);
	tmplist = g_list_first(main_v->bfwinlist);
	while (tmplist) {
		/* if there is a project, we anyway want to save & close the project */
		if (BFWIN(tmplist->data)->project) {
			if (!project_save_and_close(BFWIN(tmplist->data))) {
				/* cancelled or error! */
				DEBUG_MSG("winefish_exit_request, project_save_and_close returned FALSE\n");
				return;
			}
		}
		if (tmpb) {
			file_close_all_cb(NULL, BFWIN(tmplist->data));
		}
		tmplist = g_list_next(tmplist);
	}
	/* if we still have modified documents we don't do a thing,
	 if we don't have them we can quit */
	if (tmpb) {
		tmplist = return_allwindows_documentlist();
		tmpb = (tmplist && test_docs_modified(tmplist));
		g_list_free(tmplist);
		if (tmpb) {
			return;
		}
	}
/*	gtk_widget_hide(main_v->main_window);*/
	
	tmplist = g_list_first(gtk_window_list_toplevels());
	gchar *role=NULL;
	while (tmplist) {
		/* BUG#38 */
		if (GTK_IS_WIDGET(tmplist->data)) {
			role = g_strdup(gtk_window_get_role ((GtkWindow*)tmplist->data));
			gtk_widget_hide(GTK_WIDGET(tmplist->data));
			if (role && strncmp(role,"html_dialog",11) ==0) {
				window_destroy(GTK_WIDGET(tmplist->data));
			}
		}
		/* g_print("type = %s, role=%s\n", GTK_OBJECT_TYPE_NAME((GtkObject*) tmplist->data), role); */
		tmplist = g_list_next(tmplist);
	}
	g_free(role);

	flush_queue();

	rcfile_save_all();
	{
		gchar *filename = g_strconcat(g_get_home_dir(), "/.winefish/dir_history", NULL);
		put_stringlist_limited(filename, main_v->recent_directories, main_v->props.max_dir_history);
		g_free(filename);
	}
	
	gtk_main_quit();
}
Example #22
0
int
main(int argc, char* argv[])
{
	_debug_ = 0;

	samplecat_init();

	gtk_init_check(&argc, &argv);
	type_init();
	pixmaps_init();
	icon_theme_init();

	Window win;
	GLXContext ctx;
	GLboolean fullscreen = GL_FALSE;
	static int width = 400, height = 300;

	int i; for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-verbose") == 0) {
			_debug_ = 1;
		}
#if 0
		else if (strcmp(argv[i], "-swap") == 0 && i + 1 < argc) {
			swap_interval = atoi( argv[i+1] );
			do_swap_interval = GL_TRUE;
			i++;
		}
		else if (strcmp(argv[i], "-forcegetrate") == 0) {
			/* This option was put in because some DRI drivers don't support the
			 * full GLX_OML_sync_control extension, but they do support
			 * glXGetMscRateOML.
			 */
			force_get_rate = GL_TRUE;
		}
#endif
		else if (strcmp(argv[i], "-fullscreen") == 0) {
			fullscreen = GL_TRUE;
		}
		else if (strcmp(argv[i], "-help") == 0) {
			printf("Usage:\n");
			printf("  glx [options]\n");
			printf("Options:\n");
			printf("  -help                   Print this information\n");
			printf("  -verbose                Output info to stdout\n");
			printf("  -swap N                 Swap no more than once per N vertical refreshes\n");
			printf("  -forcegetrate           Try to use glXGetMscRateOML function\n");
			printf("  -fullscreen             Full-screen window\n");
			return 0;
		}
	}

	Display* dpy = XOpenDisplay(NULL);
	if(!dpy){
		printf("Error: couldn't open display %s\n", XDisplayName(NULL));
		return -1;
	}

	int screen = DefaultScreen(dpy);
	make_window(dpy, "Samplcecat", (XDisplayWidth(dpy, screen) - width) / 2, (XDisplayHeight(dpy, screen) - height) / 2, width, height, fullscreen, &win, &ctx);

	agl_get_extensions();

	glx_init(dpy);

	g_main_loop_new(NULL, true);

	scene = (AGlRootActor*)agl_actor__new_root_(CONTEXT_TYPE_GLX);

	void scene_needs_redraw(AGlScene* scene, gpointer _){ need_draw = true; }
	scene->draw = scene_needs_redraw;

	gboolean add_content(gpointer _)
	{ 
		app->config_ctx.filename = g_strdup_printf("%s/.config/" PACKAGE "/" PACKAGE, g_get_home_dir());
		config_load(&app->config_ctx, &app->config);

		if (app->config.database_backend && can_use(samplecat.model->backends, app->config.database_backend)) {
			#define list_clear(L) g_list_free(L); L = NULL;
			list_clear(samplecat.model->backends);
			samplecat_model_add_backend(app->config.database_backend);
		}

		db_init(
#ifdef USE_MYSQL
			&app->config.mysql
#else
			NULL
#endif
		);
		if (!db_connect()) {
			g_warning("cannot connect to any database.\n");
			return EXIT_FAILURE;
		}

		samplecat_list_store_do_search((SamplecatListStore*)samplecat.store);

		Waveform* w = NULL;

		WaveformCanvas* wfc = wf_context_new(scene);

		agl_actor__add_child((AGlActor*)scene, actors.bg = background_actor(NULL));
		actors.bg->region.x2 = 1;
		actors.bg->region.y2 = 1;

		agl_actor__add_child((AGlActor*)scene, actors.search = search_view(NULL));
		agl_actor__add_child((AGlActor*)scene, actors.list = list_view(NULL));

		agl_actor__add_child((AGlActor*)scene, actors.wave = (AGlActor*)wf_canvas_add_new_actor(wfc, w));

		void scene_set_size(AGlActor* scene)
		{
			#define SPACING 2
			int vspace = scene->region.y2 - 40;
			int y = 20;

			int h = search_view_height((SearchView*)actors.search);
			actors.search->region = (AGliRegion){20, y, scene->region.x2 - 20, y + h};
			agl_actor__set_size(actors.search);
			vspace -= h + SPACING;
			y += h + SPACING;

			actors.list->region = (AGliRegion){20, y, scene->region.x2 - 20, y + vspace / 2};
			vspace -= vspace / 2;
			y += vspace;
			agl_actor__set_size(actors.list); // clear cache

			actors.wave->region = (AGliRegion){
				20,
				y,
				scene->region.x2 - 20,
				y + vspace
			};
			wf_actor_set_rect((WaveformActor*)actors.wave, &(WfRectangle){
				0.0,
				0.0,
				agl_actor__width(actors.wave),
				agl_actor__height(actors.wave)
			});

			need_draw = true;
		}
Example #23
0
int
main(int argc, char *argv[])
{
	GError *error = NULL;

#ifdef ENABLE_NLS
	bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);
#endif

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

	/* Create configuration dir ~/.chimara */
	gchar *configdir = g_build_filename(g_get_home_dir(), ".chimara", NULL);
	if(!g_file_test(configdir, G_FILE_TEST_IS_DIR)
		&& g_mkdir(configdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
		g_error(_("Cannot create configuration directory ~/.chimara"));
	g_free(configdir);

	/* Initialize settings file; it can be overridden by a "chimara-config" file
	 in the current directory */
	gchar *keyfile;
	if(g_file_test("chimara-config", G_FILE_TEST_IS_REGULAR))
		keyfile = g_strdup("chimara-config");
	else
		keyfile = g_build_filename(g_get_home_dir(), ".chimara", "config", NULL);
	GSettingsBackend *backend = g_keyfile_settings_backend_new(keyfile, "/org/chimara-if/player/", NULL);
	prefs_settings = g_settings_new_with_backend("org.chimara-if.player.preferences", backend);
	state_settings = g_settings_new_with_backend("org.chimara-if.player.state", backend);
	g_free(keyfile);

	if( !create_window() ) {
		error_dialog(NULL, NULL, "Error while building interface.");
		return 1;
	}
	gtk_widget_show_all(window);

	g_object_unref( G_OBJECT(uimanager) );

	if(argc == 3) {
		g_object_set(glk, "graphics-file", argv[2], NULL);
	}
	if(argc >= 2) {
		if( !chimara_if_run_game(CHIMARA_IF(glk), argv[1], &error) ) {
	   		error_dialog(GTK_WINDOW(window), error, "Error starting Glk library: ");
			return 1;
		}
	}

    gdk_threads_enter();
	gtk_main();
	gdk_threads_leave();

	chimara_glk_stop(CHIMARA_GLK(glk));
	chimara_glk_wait(CHIMARA_GLK(glk));

	g_object_unref( G_OBJECT(builder) );

	return 0;
}
Example #24
0
int main(int argc, char **argv)
{
  enum op op = OP_UPDATE;
  int i, len;
  int ret = 0;
  gchar **groups;
  gchar *channeldir;
  GKeyFile *kf;
  struct channel_configuration *defaults;
  enclosure_filter *filter = NULL;
  GError *error = NULL;
  GOptionContext *context;

  static GOptionEntry options[] =
  {
    {"catchup",      'c', 0, G_OPTION_ARG_NONE,     &catchup,           "catch up with channels and exit"},
    {"list",         'l', 0, G_OPTION_ARG_NONE,     &list,              "list available enclosures that have not yet been downloaded and exit"},
    {"version",      'V', 0, G_OPTION_ARG_NONE,     &show_version,      "print version and exit"},

    {"resume",       'r', 0, G_OPTION_ARG_NONE,     &resume,            "resume aborted downloads"},
    {"rcfile",       'C', 0, G_OPTION_ARG_FILENAME, &rcfile,            "override the default configuration file name"},

    {"debug",        'd', 0, G_OPTION_ARG_NONE,     &show_debug_info,   "print connection debug information"},
    {"verbose",      'v', 0, G_OPTION_ARG_NONE,     &verbose,           "print detailed progress information"},
    {"progress-bar", 'p', 0, G_OPTION_ARG_NONE,     &show_progress_bar, "print progress bar"},

    {"new-only",     'n', 0, G_OPTION_ARG_NONE,     &new_only,          "only process new channels"},
    {"quiet",        'q', 0, G_OPTION_ARG_NONE,     &quiet,             "only print error messages"},
    {"first-only",   '1', 0, G_OPTION_ARG_NONE,     &first_only,        "only process the most recent item from each channel"},
#ifdef ENABLE_GREGEX
    {"filter",       'f', 0, G_OPTION_ARG_STRING,   &filter_regex,      "only process items whose enclosure names match a regular expression"},
#endif /* ENABLE_GREGEX */

    { NULL }
  };

  context = g_option_context_new("CHANNELS");
  g_option_context_add_main_entries(context, options, NULL);

  if (!g_option_context_parse(context, &argc, &argv, &error)) {
    g_print("option parsing failed: %s\n", error->message);
    exit(1);
  }

  /* Do some additional sanity checking of options. */
  if ((verbose && quiet) || (show_progress_bar && quiet)) {
    g_print("option parsing failed: options are incompatible.\n");
    exit(1);
  }

  if ((catchup && list) || (catchup && show_version) || (list && show_version)) {
    g_print("option parsing failed: --catchup, --list and --version options are incompatible.\n");
    exit(1);
  }

  /* Decide on the action to take */
  if (show_version) {
    version();
    exit(0);
  }

  if (catchup)
    op = OP_CATCHUP;

  if (list)
    op = OP_LIST;

  if (filter_regex) {
#ifdef ENABLE_GREGEX
    filter = enclosure_filter_new(filter_regex, FALSE);
    g_free(filter_regex);
#else /* !ENABLE_GREGEX */
    g_print("option parsing failed: filters not supported by this build.\n");
    exit(1);
#endif /* ENABLE_GREGEX */
  }

  if (verbose && new_only)
    g_print("Fetching new channels only...\n");

  LIBXML_TEST_VERSION;

  /* Build the channel directory path and ensure that it exists. */
  channeldir = g_build_filename(g_get_home_dir(), ".castget", NULL);

  if (!g_file_test(channeldir, G_FILE_TEST_IS_DIR)) {
    if (g_mkdir(channeldir, 0755) < 0) {
      perror("Error creating channel directory");
      return 1;
    }
  }

  /* Try opening configuration file. */
  if (!rcfile)
    /* Supply default path name. */
    rcfile = g_build_filename(g_get_home_dir(), ".castgetrc", NULL);

  kf = _configuration_file_open(rcfile);

  if (kf) {
    /* Read defaults. */
    if (g_key_file_has_group(kf, "*")) {
      /* Verify the keys in the global configuration. */
      if (channel_configuration_verify_keys(kf, "*") < 0)
        return -1;

      defaults = channel_configuration_new(kf, "*", NULL);
    } else
      defaults = NULL;

    /* Perform actions. */
    if (optind < argc) {
      while (optind < argc)
        _process_channel(channeldir, kf, argv[optind++], op, defaults,
                         filter);
    } else {
      groups = g_key_file_get_groups(kf, NULL);

      for (i = 0; groups[i]; i++)
        if (strcmp(groups[i], "*"))
          _process_channel(channeldir, kf, groups[i], op, defaults,
                           filter);

      g_strfreev(groups);
    }

    /* Clean up defaults. */
    if (defaults)
      channel_configuration_free(defaults);
  } else
    ret = 1;

  /* Clean-up. */
  g_free(channeldir);

  if (filter)
    enclosure_filter_free(filter);

  g_free(rcfile);

  if (kf)
    _configuration_file_close(kf);

  xmlCleanupParser();

  return ret;
}
void get_plugin_dir(char *buf)
{
    sprintf(buf, "%s/%s", g_get_home_dir(), PLUGIN_DIR);
}
Example #26
0
static XdgDirEntry *
parse_xdg_dirs (const char *config_file)
{
    GArray *array;
    char *config_file_free = NULL;
    XdgDirEntry dir;
    char *data;
    char **lines;
    char *p, *d;
    int i;
    char *type_start, *type_end;
    char *value, *unescaped;
    gboolean relative;

    array = g_array_new (TRUE, TRUE, sizeof (XdgDirEntry));

    if (config_file == NULL)
    {
        config_file_free = g_build_filename (g_get_user_config_dir (),
                                             "user-dirs.dirs", NULL);
        config_file = (const char *)config_file_free;
    }

    if (g_file_get_contents (config_file, &data, NULL, NULL))
    {
        lines = g_strsplit (data, "\n", 0);
        g_free (data);
        for (i = 0; lines[i] != NULL; i++)
        {
            p = lines[i];
            while (g_ascii_isspace (*p))
                p++;

            if (*p == '#')
                continue;

            value = strchr (p, '=');
            if (value == NULL)
                continue;
            *value++ = 0;

            g_strchug (g_strchomp (p));
            if (!g_str_has_prefix (p, "XDG_"))
                continue;
            if (!g_str_has_suffix (p, "_DIR"))
                continue;
            type_start = p + 4;
            type_end = p + strlen (p) - 4;

            while (g_ascii_isspace (*value))
                value++;

            if (*value != '"')
                continue;
            value++;

            relative = FALSE;
            if (g_str_has_prefix (value, "$HOME"))
            {
                relative = TRUE;
                value += 5;
                while (*value == '/')
                    value++;
            }
            else if (*value != '/')
                continue;

            d = unescaped = g_malloc (strlen (value) + 1);
            while (*value && *value != '"')
            {
                if ((*value == '\\') && (*(value + 1) != 0))
                    value++;
                *d++ = *value++;
            }
            *d = 0;

            *type_end = 0;
            dir.type = g_strdup (type_start);
            if (relative)
            {
                dir.path = g_build_filename (g_get_home_dir (), unescaped, NULL);
                g_free (unescaped);
            }
            else
                dir.path = unescaped;

            g_array_append_val (array, dir);
        }

        g_strfreev (lines);
    }

    g_free (config_file_free);

    return (XdgDirEntry *)g_array_free (array, FALSE);
}
Example #27
0
/**
 * gimp_directory:
 *
 * Returns the user-specific GIMP settings directory. If the
 * environment variable GIMP2_DIRECTORY exists, it is used. If it is
 * an absolute path, it is used as is.  If it is a relative path, it
 * is taken to be a subdirectory of the home directory. If it is a
 * relative path, and no home directory can be determined, it is taken
 * to be a subdirectory of gimp_data_directory().
 *
 * The usual case is that no GIMP2_DIRECTORY environment variable
 * exists, and then we use the GIMPDIR subdirectory of the home
 * directory. If no home directory exists, we use a per-user
 * subdirectory of gimp_data_directory().  In any case, we always
 * return some non-empty string, whether it corresponds to an existing
 * directory or not.
 *
 * The returned string is owned by GIMP and must not be modified or
 * freed. The returned string is in the encoding used for filenames by
 * GLib, which isn't necessarily UTF-8. (On Windows it always is
 * UTF-8.)
 *
 * Returns: The user-specific GIMP settings directory.
 **/
const gchar *
gimp_directory (void)
{
  static gchar *gimp_dir = NULL;

  const gchar  *env_gimp_dir;
  const gchar  *home_dir;

  if (gimp_dir)
    return gimp_dir;

  env_gimp_dir = g_getenv ("GIMP2_DIRECTORY");
  home_dir     = g_get_home_dir ();

  if (env_gimp_dir)
    {
      if (g_path_is_absolute (env_gimp_dir))
        {
          gimp_dir = g_strdup (env_gimp_dir);
        }
      else
        {
          if (home_dir)
            {
              gimp_dir = g_build_filename (home_dir,
                                           env_gimp_dir,
                                           NULL);
            }
          else
            {
              gimp_dir = g_build_filename (gimp_data_directory (),
                                           env_gimp_dir, NULL);
            }
        }
    }
  else
    {
      if (home_dir)
        {
          gimp_dir = g_build_filename (home_dir, GIMPDIR, NULL);
        }
      else
        {
          gchar *user_name = g_strdup (g_get_user_name ());
          gchar *subdir_name;

#ifdef G_OS_WIN32
          gchar *p = user_name;

          while (*p)
            {
              /* Replace funny characters in the user name with an
               * underscore. The code below also replaces some
               * characters that in fact are legal in file names, but
               * who cares, as long as the definitely illegal ones are
               * caught.
               */
              if (!g_ascii_isalnum (*p) && !strchr ("-.,@=", *p))
                *p = '_';
              p++;
            }
#endif

#ifndef G_OS_WIN32
          g_message ("warning: no home directory.");
#endif
          subdir_name = g_strconcat (GIMPDIR ".", user_name, NULL);
          gimp_dir = g_build_filename (gimp_data_directory (),
                                       subdir_name,
                                       NULL);
          g_free (user_name);
          g_free (subdir_name);
        }
    }

  return gimp_dir;
}
Example #28
0
char *
nautilus_get_home_directory_uri (void)
{
    return  g_filename_to_uri (g_get_home_dir (), NULL, NULL);
}
static gboolean
write_theme_to_disk (MateThemeMetaInfo  *theme_info,
		     const gchar         *theme_name,
		     const gchar         *theme_description,
		     gboolean		  save_background,
		     GError             **error)
{
	gchar* dir;
	gchar* theme_name_dir;
	GFile* tmp_file;
	GFile* target_file;
	GOutputStream* output;

	gchar* str;
	gchar* current_background;

	GSettings* settings;
	const gchar* theme_header = ""
		"[Desktop Entry]\n"
		"Name=%s\n"
		"Type=X-GNOME-Metatheme\n"
		"Comment=%s\n"
		"\n"
		"[X-GNOME-Metatheme]\n"
		"GtkTheme=%s\n"
		"MetacityTheme=%s\n"
		"IconTheme=%s\n";

  theme_name_dir = str_remove_slash (theme_name);
  dir = g_build_filename (g_get_home_dir (), ".themes", theme_name_dir, "index.theme~", NULL);
  g_free (theme_name_dir);

  tmp_file = g_file_new_for_path (dir);
  dir [strlen (dir) - 1] = '\000';
  target_file = g_file_new_for_path (dir);
  g_free (dir);

  /* start making the theme file */
  str = g_strdup_printf(theme_header, theme_name, theme_description, theme_info->gtk_theme_name, theme_info->marco_theme_name, theme_info->icon_theme_name);

  output = G_OUTPUT_STREAM (g_file_replace (tmp_file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
  g_output_stream_write (output, str, strlen (str), NULL, NULL);
  g_free (str);

  if (theme_info->gtk_color_scheme) {
    gchar *a, *tmp;
    tmp = g_strdup (theme_info->gtk_color_scheme);
    for (a = tmp; *a != '\0'; a++)
      if (*a == '\n')
        *a = ',';
    str = g_strdup_printf ("GtkColorScheme=%s\n", tmp);
    g_output_stream_write (output, str, strlen (str), NULL, NULL);

    g_free (str);
    g_free (tmp);
  }

  if (theme_info->cursor_theme_name) {
#ifdef HAVE_XCURSOR
    str = g_strdup_printf ("CursorTheme=%s\n"
                           "CursorSize=%i\n",
                           theme_info->cursor_theme_name,
                           theme_info->cursor_size);
#else
    str = g_strdup_printf ("CursorFont=%s\n", theme_info->cursor_theme_name);
#endif
    g_output_stream_write (output, str, strlen (str), NULL, NULL);
    g_free (str);
  }

  if (theme_info->notification_theme_name) {
    str = g_strdup_printf ("NotificationTheme=%s\n", theme_info->notification_theme_name);
    g_output_stream_write (output, str, strlen (str), NULL, NULL);
    g_free (str);
  }

  if (save_background) {
    settings = g_settings_new (WP_SCHEMA);
    current_background = g_settings_get_string (settings, WP_FILE_KEY);

    if (current_background != NULL) {
      str = g_strdup_printf ("BackgroundImage=%s\n", current_background);

      g_output_stream_write (output, str, strlen (str), NULL, NULL);

      g_free (current_background);
      g_free (str);
    }
    g_object_unref (settings);
  }

  g_file_move (tmp_file, target_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL);
  g_output_stream_close (output, NULL, NULL);

  g_object_unref (tmp_file);
  g_object_unref (target_file);

  return TRUE;
}
Example #30
0
void _fm_path_init ()
{
    // Root Path...
    root_path = _fm_path_new_internal (NULL, "/", 1,
                                       FM_PATH_IS_NATIVE
                                       | FM_PATH_IS_LOCAL);
    
    // Home Path...
    home_path = _fm_path_new_internal_for_string (g_get_home_dir (),
                                                  FM_PATH_IS_NATIVE
                                                  | FM_PATH_IS_LOCAL);
    // Desktop Path...
    desktop_path = _fm_path_new_internal_for_string (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP),
                                                     FM_PATH_IS_ROOT
                                                     | FM_PATH_IS_SPECIAL
                                                     | FM_PATH_IS_DESKTOP
                                                     | FM_PATH_IS_NATIVE
                                                     | FM_PATH_IS_LOCAL);

    // Trash Can Root...
    computer_path = _fm_path_new_internal (NULL, "computer:///", 12,
                                           FM_PATH_IS_COMPUTER
                                           | FM_PATH_IS_SPECIAL
                                           | FM_PATH_IS_VIRTUAL
                                           | FM_PATH_IS_LOCAL);
    
    // Trash Can Root...
    trash_path = _fm_path_new_internal (NULL, "trash:///", 9,
                                        FM_PATH_IS_TRASH
                                        | FM_PATH_IS_SPECIAL
                                        | FM_PATH_IS_VIRTUAL
                                        | FM_PATH_IS_LOCAL);
    
    // User Documents...
    documents_path = _fm_path_new_internal_for_string (g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS),
                                                       FM_PATH_IS_ROOT
                                                       | FM_PATH_IS_SPECIAL
                                                       | FM_PATH_IS_DOCUMENTS
                                                       | FM_PATH_IS_NATIVE
                                                       | FM_PATH_IS_LOCAL);

    // User Download...
    download_path = _fm_path_new_internal_for_string (g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD),
                                                      FM_PATH_IS_ROOT
                                                      | FM_PATH_IS_SPECIAL
                                                      | FM_PATH_IS_DOWNLOAD
                                                      | FM_PATH_IS_NATIVE
                                                      | FM_PATH_IS_LOCAL);

    // User Music...
    music_path = _fm_path_new_internal_for_string (g_get_user_special_dir (G_USER_DIRECTORY_MUSIC),
                                                   FM_PATH_IS_ROOT
                                                   | FM_PATH_IS_SPECIAL
                                                   | FM_PATH_IS_MUSIC
                                                   | FM_PATH_IS_NATIVE
                                                   | FM_PATH_IS_LOCAL);

    // User Pictures...
    pictures_path = _fm_path_new_internal_for_string (g_get_user_special_dir (G_USER_DIRECTORY_PICTURES),
                                                      FM_PATH_IS_ROOT
                                                      | FM_PATH_IS_SPECIAL
                                                      | FM_PATH_IS_PICTURES
                                                      | FM_PATH_IS_NATIVE
                                                      | FM_PATH_IS_LOCAL);

    // User Videos...
    videos_path = _fm_path_new_internal_for_string (g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS),
                                                    FM_PATH_IS_ROOT
                                                    | FM_PATH_IS_SPECIAL
                                                    | FM_PATH_IS_VIDEOS
                                                    | FM_PATH_IS_NATIVE
                                                    | FM_PATH_IS_LOCAL);

    // Applications Root...
    apps_root_path = _fm_path_new_internal (NULL, "menu://Applications/", 20,
                                            FM_PATH_IS_XDG_MENU
                                            | FM_PATH_IS_VIRTUAL);
}