Esempio n. 1
0
void test_spec_handler(struct spec_handler* handler, struct spec_handler_test* tests) {
	GNode* node;
	GNode* handler_node;
	GNode test_node;
	struct cc_oci_config config;
	struct spec_handler_test* test;
	int fd;

	ck_assert(! handler->handle_section(NULL, NULL));
	ck_assert(! handler->handle_section(&test_node, NULL));
	ck_assert(! handler->handle_section(NULL, &config));

	/**
	 * Create fake files for Kernel and image so
	 * path validation won't fail
	 */

	fd = g_creat("CONTAINER-KERNEL",0755);
	if (fd < 0) {
		g_critical ("failed to create file CONTAINER-KERNEL");
	} else {
		close(fd);
	}

	fd = g_creat("CLEAR-CONTAINERS.img",0755);
	if (fd < 0) {
		g_critical ("failed to create file CLEAR-CONTAINERS.img");
	} else {
		close(fd);
	}
	fd = g_creat("QEMU-LITE",0755);
	if (fd < 0) {
		g_critical ("failed to create file QEMU-LITE");
	} else {
		close(fd);
	}

	for (test=tests; test->file; test++) {
		memset(&config, 0, sizeof(config));
		cc_oci_json_parse(&node, test->file);
		handler_node = node_find_child(node, handler->name);
		ck_assert_msg(handler->handle_section(
		    handler_node, &config) == test->test_result,
		    test->file);
		cc_oci_config_free(&config);
		g_free_node(node);
	}

	if (g_remove("CONTAINER-KERNEL") < 0) {
		g_critical ("failed to remove file CONTAINER-KERNEL");
	}

	if (g_remove ("CLEAR-CONTAINERS.img") < 0) {
		g_critical ("failed to remove file CLEAR-CONTAINERS.img");
	}

	if (g_remove ("QEMU-LITE") < 0) {
		g_critical ("failed to remove file QEMU-LITE");
	}
}
Esempio n. 2
0
static void
do_upgrades_once (NautilusApplication *self)
{
	char *metafile_dir, *updated, *nautilus_dir, *xdg_dir;
	const gchar *message;
	int fd, res;

	if (!self->priv->no_desktop) {
		mark_desktop_files_trusted ();
	}

	metafile_dir = g_build_filename (g_get_home_dir (),
					 ".nautilus/metafiles", NULL);
	if (g_file_test (metafile_dir, G_FILE_TEST_IS_DIR)) {
		updated = g_build_filename (metafile_dir, "migrated-to-gvfs", NULL);
		if (!g_file_test (updated, G_FILE_TEST_EXISTS)) {
			g_spawn_command_line_async (LIBEXECDIR"/nautilus-convert-metadata --quiet", NULL);
			fd = g_creat (updated, 0600);
			if (fd != -1) {
				close (fd);
			}
		}
		g_free (updated);
	}
	g_free (metafile_dir);

	nautilus_dir = g_build_filename (g_get_home_dir (),
					 ".nautilus", NULL);
	xdg_dir = nautilus_get_user_directory ();
	if (g_file_test (nautilus_dir, G_FILE_TEST_IS_DIR)) {
		/* test if we already attempted to migrate first */
		updated = g_build_filename (nautilus_dir, "DEPRECATED-DIRECTORY", NULL);
		message = _("Nautilus 3.0 deprecated this directory and tried migrating "
			    "this configuration to ~/.config/nautilus");
		if (!g_file_test (updated, G_FILE_TEST_EXISTS)) {
			/* rename() works fine if the destination directory is
			 * empty.
			 */
			res = g_rename (nautilus_dir, xdg_dir);

			if (res == -1) {
				fd = g_creat (updated, 0600);
				if (fd != -1) {
					res = write (fd, message, strlen (message));
					close (fd);
				}
			}
		}

		g_free (updated);
	}

	g_free (nautilus_dir);
	g_free (xdg_dir);
}
Esempio n. 3
0
static void
migrate_profile (const char *old_dir,
                 const char *new_dir)
{
  char *parent_dir;
  char *updated;
  const char *message;

  if (g_file_test (new_dir, G_FILE_TEST_EXISTS) ||
      !g_file_test (old_dir, G_FILE_TEST_IS_DIR))
    return;

  /* Test if we already attempted to migrate first. */
  updated = g_build_filename (old_dir, "DEPRECATED-DIRECTORY", NULL);
  message = _("Epiphany 3.6 deprecated this directory and tried migrating "
              "this configuration to ~/.config/epiphany");

  parent_dir = g_path_get_dirname (new_dir);
  if (g_mkdir_with_parents (parent_dir, 0700) == 0) {
    int fd, res;

    /* rename() works fine if the destination directory is empty. */
    res = g_rename (old_dir, new_dir);
    if (res == -1 && !g_file_test (updated, G_FILE_TEST_EXISTS)) {
      fd = g_creat (updated, 0600);
      if (fd != -1) {
        res = write (fd, message, strlen (message));
        close (fd);
      }
    }
  }

  g_free (parent_dir);
  g_free (updated);
}
Esempio n. 4
0
void lock_report_pid ()
{
    gchar *lockpid_file = NULL;
    if (username == NULL) {
        username = lock_get_username ();
    }

    lockpid_file = g_strdup_printf ("%s%s%s", "/home/", username, "/.dlockpid");
    if (g_file_test (lockpid_file, G_FILE_TEST_EXISTS)) {

        g_debug ("remove old pid info before lock");
        g_remove (lockpid_file);
    }

    if (g_creat (lockpid_file, O_RDWR) == -1) {
        g_warning ("touch lockpid_file failed\n");
    }

    gchar *contents = g_strdup_printf ("%d", getpid ());

    g_file_set_contents (lockpid_file, contents, -1, NULL);

    g_free (contents);
    g_free (lockpid_file);
}
/**
 * gimp_config_writer_new_file:
 * @filename: a filename
 * @atomic: if %TRUE the file is written atomically
 * @header: text to include as comment at the top of the file
 * @error: return location for errors
 *
 * Creates a new #GimpConfigWriter and sets it up to write to
 * @filename. If @atomic is %TRUE, a temporary file is used to avoid
 * possible race conditions. The temporary file is then moved to
 * @filename when the writer is closed.
 *
 * Return value: a new #GimpConfigWriter or %NULL in case of an error
 *
 * Since: GIMP 2.4
 **/
GimpConfigWriter *
gimp_config_writer_new_file (const gchar  *filename,
                             gboolean      atomic,
                             const gchar  *header,
                             GError      **error)
{
  GimpConfigWriter *writer;
  gchar            *tmpname = NULL;
  gint              fd;

  g_return_val_if_fail (filename != NULL, NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  if (atomic)
    {
      tmpname = g_strconcat (filename, "XXXXXX", NULL);

      fd = g_mkstemp (tmpname);

      if (fd == -1)
        {
          g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
                       _("Could not create temporary file for '%s': %s"),
                       gimp_filename_to_utf8 (filename), g_strerror (errno));
          g_free (tmpname);
          return NULL;
        }
    }
  else
    {
      fd = g_creat (filename, 0644);

      if (fd == -1)
        {
          g_set_error (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_WRITE,
                       _("Could not open '%s' for writing: %s"),
                       gimp_filename_to_utf8 (filename), g_strerror (errno));
          return NULL;
        }
    }

  writer = g_slice_new0 (GimpConfigWriter);

  writer->fd       = fd;
  writer->filename = g_strdup (filename);
  writer->tmpname  = tmpname;
  writer->buffer   = g_string_new (NULL);

  if (header)
    {
      gimp_config_writer_comment (writer, header);
      gimp_config_writer_linefeed (writer);
    }

  return writer;
}
Esempio n. 6
0
File: m_file.c Progetto: camgunz/d2k
bool M_CreateFile(const char *path, int mode) {
  int fd = g_creat(path, S_IRUSR | S_IWUSR);

  if (fd == -1) {
    set_file_error_from_errno();
    return false;
  }

  return M_Close(fd);
}
Esempio n. 7
0
static void
mark_desktop_files_trusted (void)
{
	char *do_once_file;
	GFile *f, *c;
	GFileEnumerator *e;
	GFileInfo *info;
	const char *name;
	int fd;
	
	do_once_file = g_build_filename (g_get_user_data_dir (),
					 ".converted-launchers", NULL);

	if (g_file_test (do_once_file, G_FILE_TEST_EXISTS)) {
		goto out;
	}

	f = nautilus_get_desktop_location ();
	e = g_file_enumerate_children (f,
				       G_FILE_ATTRIBUTE_STANDARD_TYPE ","
				       G_FILE_ATTRIBUTE_STANDARD_NAME ","
				       G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE
				       ,
				       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
				       NULL, NULL);
	if (e == NULL) {
		goto out2;
	}
	
	while ((info = g_file_enumerator_next_file (e, NULL, NULL)) != NULL) {
		name = g_file_info_get_name (info);
		
		if (g_str_has_suffix (name, ".desktop") &&
		    !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE)) {
			c = g_file_get_child (f, name);
			nautilus_file_mark_desktop_file_trusted (c,
								 NULL, FALSE,
								 NULL, NULL);
			g_object_unref (c);
		}
		g_object_unref (info);
	}
	
	g_object_unref (e);
 out2:
	fd = g_creat (do_once_file, 0666);
	close (fd);
	
	g_object_unref (f);
 out:	
	g_free (do_once_file);
}
Esempio n. 8
0
bs_file_t local_file_create(struct back_storage *storage,const char *path){
	//HLOG_DEBUG("local -- enter func %s", __func__);
    char full_path[256];
    build_local_path(full_path,storage->dir,storage->fs_name,path);
    //HLOG_DEBUG("full path:%s", full_path);
    int fd = g_creat(full_path,00700);
#if 0
    bs_file_t file = (bs_file_t)g_malloc0(sizeof(int));
    if (NULL == file) {
	    g_message("%s - build local path error!\n", __func__);
	    g_free(full_path);
	    return NULL;
    }
    *(int*)file = fd;
#endif 
    bs_file_t file = (bs_file_t)GINT_TO_POINTER(fd); 
	//HLOG_DEBUG("local -- leave func %s", __func__);
    return file;
}
Esempio n. 9
0
static void
ev_migrate_metadata (void)
{
	gchar       *updated;
	gchar       *metadata;
	gchar       *dot_dir;
	const gchar *userdir;

	userdir = g_getenv ("MATE22_USER_DIR");
	if (userdir) {
		dot_dir = g_build_filename (userdir, "atril", NULL);
	} else {
		#if GLIB_CHECK_VERSION(2, 6, 0)
			dot_dir = g_build_filename(g_get_user_config_dir(), "atril", NULL);
		#else // glib version < 2.6.0
			dot_dir = g_build_filename(g_get_home_dir(), ".config", "atril", NULL);
		#endif
	}

	updated = g_build_filename (dot_dir, "migrated-to-gvfs", NULL);
	if (g_file_test (updated, G_FILE_TEST_EXISTS)) {
		/* Already migrated */
		g_free (updated);
		g_free (dot_dir);
		return;
	}

	metadata = g_build_filename (dot_dir, "ev-metadata.xml", NULL);
	if (g_file_test (metadata, G_FILE_TEST_EXISTS)) {
		if (convert_metadata (metadata)) {
			gint fd;

			fd = g_creat (updated, 0600);
			if (fd != -1) {
				close (fd);
			}
		}
	}

	g_free (dot_dir);
	g_free (updated);
	g_free (metadata);
}
Esempio n. 10
0
static void
pragha_preferences_load_from_file(PraghaPreferences *preferences)
{
	gboolean approximate_search, instant_search;
	gboolean shuffle, repeat, use_hint, restore_playlist, software_mixer;
	gboolean lateral_panel, show_album_art, show_status_bar;
	gboolean add_recursively, timer_remaining_mode;
	gchar *audio_sink, *audio_device, *audio_cd_device;
	gint library_style, sidebar_size;
	gboolean fuse_folders, sort_by_year;
	const gchar *user_config_dir;
	gchar *pragha_config_dir = NULL;
	GError *error = NULL;
	PraghaPreferencesPrivate *priv = preferences->priv;

	/* First check preferences folder or create it */

	user_config_dir = g_get_user_config_dir();
	pragha_config_dir = g_build_path(G_DIR_SEPARATOR_S, user_config_dir, "/pragha", NULL);

	if (g_file_test(pragha_config_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) == FALSE) {
		if (g_mkdir_with_parents (pragha_config_dir, S_IRWXU) == -1) {
			g_free(pragha_config_dir);
			g_critical("Unable to create preferences directory, err: %s", strerror(errno));
			return;
		}
		CDEBUG(DBG_INFO, "Created .config/pragha folder");
	}
	g_free(pragha_config_dir);

	/* Does /pragha/config exist ? */

	priv->rc_filepath = g_build_path(G_DIR_SEPARATOR_S, user_config_dir, "/pragha/config", NULL);

	if (g_file_test(priv->rc_filepath, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR) == FALSE) {
		if (g_creat(priv->rc_filepath, S_IRWXU) == -1) {
			g_free(priv->rc_filepath);
			priv->rc_filepath = NULL;
			g_critical("Unable to create config file, err: %s", strerror(errno));
			return;
		}
		CDEBUG(DBG_INFO, "Created .config/pragha/config file");
	}

	/* Open the preferences storage file */

	priv->rc_keyfile = g_key_file_new();

	if (!g_key_file_load_from_file(priv->rc_keyfile,
	                               priv->rc_filepath,
	                               G_KEY_FILE_NONE,
	                               &error)) {
		g_critical("Unable to load config file (Possible first start), err: %s", error->message);
		g_error_free(error);
		return;
	}

	/* Open last preferences */

	approximate_search = g_key_file_get_boolean(priv->rc_keyfile,
	                                            GROUP_GENERAL,
	                                            KEY_APPROXIMATE_SEARCH,
	                                            &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_approximate_search(preferences, approximate_search);
	}

	instant_search = g_key_file_get_boolean(priv->rc_keyfile,
	                                        GROUP_GENERAL,
	                                        KEY_INSTANT_SEARCH,
	                                        &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_instant_search(preferences, instant_search);
	}

	shuffle = g_key_file_get_boolean(priv->rc_keyfile,
	                                 GROUP_PLAYLIST,
	                                 KEY_SHUFFLE,
	                                 &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_shuffle(preferences, shuffle);
	}

	repeat = g_key_file_get_boolean(priv->rc_keyfile,
	                                GROUP_PLAYLIST,
	                                KEY_REPEAT,
	                                &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_repeat(preferences, repeat);
	}

	use_hint = g_key_file_get_boolean(priv->rc_keyfile,
	                                  GROUP_GENERAL,
	                                  KEY_USE_HINT,
	                                  &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_use_hint(preferences, use_hint);
	}

	library_style = g_key_file_get_integer(priv->rc_keyfile,
	                                       GROUP_LIBRARY,
	                                       KEY_LIBRARY_VIEW_ORDER,
	                                       &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_library_style(preferences, library_style);
	}

	sort_by_year = g_key_file_get_boolean(priv->rc_keyfile,
	                                      GROUP_LIBRARY,
	                                      KEY_SORT_BY_YEAR,
	                                      &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_sort_by_year(preferences, sort_by_year);
	}

	fuse_folders = g_key_file_get_boolean(priv->rc_keyfile,
	                                      GROUP_LIBRARY,
	                                      KEY_FUSE_FOLDERS,
	                                      &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_fuse_folders(preferences, fuse_folders);
	}

	restore_playlist = g_key_file_get_boolean(priv->rc_keyfile,
	                                          GROUP_PLAYLIST,
	                                          KEY_SAVE_PLAYLIST,
	                                          &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_restore_playlist(preferences, restore_playlist);
	}

	audio_sink = g_key_file_get_string(priv->rc_keyfile,
	                                   GROUP_AUDIO,
	                                   KEY_AUDIO_SINK,
	                                   &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_audio_sink(preferences, audio_sink);
	}

	audio_device = g_key_file_get_string(priv->rc_keyfile,
	                                     GROUP_AUDIO,
	                                     KEY_AUDIO_DEVICE,
	                                     &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_audio_device(preferences, audio_device);
	}

	software_mixer = g_key_file_get_boolean(priv->rc_keyfile,
	                                        GROUP_AUDIO,
	                                        KEY_SOFTWARE_MIXER,
	                                        &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_software_mixer(preferences, software_mixer);
	}

	audio_cd_device = g_key_file_get_string(priv->rc_keyfile,
	                                        GROUP_AUDIO,
	                                        KEY_AUDIO_CD_DEVICE,
	                                        &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_audio_cd_device(preferences, audio_cd_device);
	}

	lateral_panel = g_key_file_get_boolean(priv->rc_keyfile,
	                                       GROUP_WINDOW,
	                                       KEY_SIDEBAR,
	                                       &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_lateral_panel(preferences, lateral_panel);
	}

	sidebar_size = g_key_file_get_integer(priv->rc_keyfile,
	                                      GROUP_WINDOW,
	                                      KEY_SIDEBAR_SIZE,
	                                      &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_sidebar_size(preferences, sidebar_size);
	}

	show_album_art = g_key_file_get_boolean(priv->rc_keyfile,
	                                        GROUP_WINDOW,
	                                        KEY_SHOW_ALBUM_ART,
	                                        &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_show_album_art(preferences, show_album_art);
	}

	show_status_bar = g_key_file_get_boolean(priv->rc_keyfile,
	                                         GROUP_WINDOW,
	                                         KEY_STATUS_BAR,
	                                         &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_show_status_bar(preferences, show_status_bar);
	}

	add_recursively = g_key_file_get_boolean(priv->rc_keyfile,
	                                         GROUP_GENERAL,
	                                         KEY_ADD_RECURSIVELY_FILES,
	                                         &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_add_recursively(preferences, add_recursively);
	}

	timer_remaining_mode = g_key_file_get_boolean(priv->rc_keyfile,
	                                              GROUP_GENERAL,
	                                              KEY_TIMER_REMAINING_MODE,
	                                              &error);
	if (error) {
		g_error_free(error);
		error = NULL;
	}
	else {
		pragha_preferences_set_timer_remaining_mode(preferences, timer_remaining_mode);
	}

	g_free(audio_sink);
	g_free(audio_device);
	g_free(audio_cd_device);
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
	char qaulUserPath[MAX_PATH_LEN];
	char qaulTmpPath[MAX_PATH_LEN];
	char qaulTmpPath2[MAX_PATH_LEN];

	qaulConfigureCounter = 0;
	qaulTimerEvents = 0;
	qaulTimerSockets = 0;
	qaulTimerTopology = 0;
	network_interface_found = 0;

	// initialize glib types
	g_type_init();

	// set paths
	sprintf(qaulUserPath, "%s/.qaul", (char*)g_get_home_dir());
	printf ("qaul.net home directory is %s\n", qaulUserPath);

	// create qaul user directory
	if(!g_file_test(qaulUserPath, G_FILE_TEST_EXISTS))
	{
		// create directory
		// http://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html
		if(g_mkdir(qaulUserPath, S_IRUSR|S_IWUSR|S_IXUSR)== -1)
			printf("qaul.net home directory %s creation error.\n", qaulUserPath);
	}
	// check if we have to update
	sprintf(qaulTmpPath, "%s/%s", qaulUserPath, QAUL_VERSION);
	if(!g_file_test(qaulTmpPath, G_FILE_TEST_EXISTS))
	{
		printf("Update user folder to qaul.net version %s\n", QAUL_VERSION);
		// copy www folder
		sprintf(qaulTmpPath, "%s/www", QAUL_ROOT_PATH);
		sprintf(qaulTmpPath2, "%s/www", qaulUserPath);
		if(!qaul_copyDirectory(qaulTmpPath, qaulTmpPath2))
			printf("qaul copy directory error. source: %s target: %s\n", qaulTmpPath, qaulTmpPath2);
		// TODO: update data base
		// remove old data base if it exists
		sprintf(qaulTmpPath, "%s/qaullib.db", qaulUserPath);
		if(g_file_test(qaulTmpPath, G_FILE_TEST_EXISTS))
			if(g_remove(qaulTmpPath) == -1)
				printf("qaul.net database %s removal error\n", qaulTmpPath);
		// create qaul version file
		sprintf(qaulTmpPath, "%s/%s", qaulUserPath, QAUL_VERSION);
		if(!g_file_test(qaulTmpPath, G_FILE_TEST_EXISTS))
			if(!g_creat(qaulTmpPath, S_IRUSR|S_IWUSR) == -1)
				printf("qaul.net version file %s creation error\n", qaulTmpPath);
	}

	Qaullib_Init(qaulUserPath);
	// set configuration
	Qaullib_SetConf(QAUL_CONF_INTERFACE);
	// enable debug menu
	qaul_conf_debug = 1;

	if(!Qaullib_WebserverStart())
		printf("Webserver startup failed\n");

	// initialize dbus connection
	qaul_dbus_init(&network_dbus_connection);
	// start configuration timer
	qaulConfigureTimer = g_timeout_add(500, qaul_configure, NULL);

	// open window
	gtk_init(&argc,&argv);

    // Create a window that will contain the browser instance
    qaulMainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(qaulMainWindow), 400, 592);
    gtk_window_set_title(GTK_WINDOW(qaulMainWindow), "qaul.net - قول");
    sprintf(qaulTmpPath, "%s/app_icon.png", QAUL_ROOT_PATH);
    gtk_window_set_icon(GTK_WINDOW(qaulMainWindow), create_pixbuf(qaulTmpPath));

    // Create a browser instance
    WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());

    // Create a scrollable area, and put the browser instance into it
    GtkWidget *scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
            GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_container_add(GTK_CONTAINER(scrolledWindow), GTK_WIDGET(webView));

    // Set up callbacks so that if either the main window or the browser instance is
    // closed, the program will exit
    g_signal_connect(qaulMainWindow, "destroy", G_CALLBACK(destroyWindowCb), NULL);
    g_signal_connect(webView, "close-web-view", G_CALLBACK(closeWebViewCb), qaulMainWindow);

    // Put the scrollable area into the main window
    gtk_container_add(GTK_CONTAINER(qaulMainWindow), scrolledWindow);

    // Load a web page into the browser instance
    webkit_web_view_load_uri(webView, "http://127.0.0.1:8081/qaul.html");

    // Make sure that when the browser area becomes visible, it will get mouse
    // and keyboard events
    gtk_widget_grab_focus(GTK_WIDGET(webView));

    // Make sure the main window and all its contents are visible
    gtk_widget_show_all(qaulMainWindow);

    // Run the main GTK+ event loop
    gtk_main();

    return 0;
}
Esempio n. 12
0
void
gfpm_optimize_db (void)
{
	char *cmdline = NULL;
	char temp[40];

	/* disable the start button */
	gtk_widget_set_sensitive (gfpm_optimize_db_startbtn, FALSE);
	gtk_widget_set_sensitive (gfpm_optimize_db_closebtn, FALSE);

	/* check if another package manager is already running */
	if (g_file_test(LOCKFILE,G_FILE_TEST_EXISTS))
	{
		gfpm_error (_("Error"), _("Cannot optimize database. Another instance of pacman-g2 or gfpm is already running."));
		goto cleanup;
	}

	/* create a lock file */
	if (g_creat(LOCKFILE,S_IRWXU)==-1)
	{
		gfpm_error (_("Error"), _("Error creating lockfile. Failed to optimize package database"));
		goto cleanup;
	}

	/* generate checksums for the old database */
	gfpm_optimize_db_set_progress_status (_("generating checksums for the old database"));
	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(gfpm_optimize_db_progressbar), 0.1);
	while (gtk_events_pending()) gtk_main_iteration ();
	sleep (2);
	cmdline = g_strdup_printf ("find %s -type f | sort | xargs md5sum > %s", DBLOC, OLDSUM);
	system (cmdline);
	g_free (cmdline);

	/* copy the old database to a new directory */
	sprintf (temp, _("copying %s"), DBLOC);
	gfpm_optimize_db_set_progress_status (temp);
	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(gfpm_optimize_db_progressbar), 0.25);
	while (gtk_events_pending()) gtk_main_iteration ();
	sleep (2);
	cmdline = g_strdup_printf ("cp -a %s %s", DBLOC, TMPLOC);
	system (cmdline);
	g_free (cmdline);
	
	/* generate checksums for the new database */
	gfpm_optimize_db_set_progress_status (_("generating checksums for the new database"));
	cmdline = g_strdup_printf ("mv %s %s.bak", DBLOC, DBLOC);
	system (cmdline);
	g_free (cmdline);
	cmdline = g_strdup_printf ("mv %s %s", TMPLOC, DBLOC);
	system (cmdline);
	g_free (cmdline);
	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(gfpm_optimize_db_progressbar), 0.4);
	while (gtk_events_pending()) gtk_main_iteration ();
	cmdline = g_strdup_printf ("find %s -type f | sort | xargs md5sum > %s", DBLOC, NEWSUM);
	system (cmdline);
	g_free (cmdline);
	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(gfpm_optimize_db_progressbar), 0.6);
	while (gtk_events_pending()) gtk_main_iteration ();
	sleep (2);

	/* check integrity */
	gfpm_optimize_db_set_progress_status (_("performing integrity check"));
	cmdline = g_strdup_printf ("diff %s %s > /dev/null 2>&1", OLDSUM, NEWSUM);
	if (system(cmdline)!=0)
	{
		gfpm_error (_("Optimization failed"), _("Integrity check failed"));
		gfpm_optimize_db_set_progress_status (_("Failed."));
		g_free (cmdline);
		cmdline = g_strdup_printf ("rm -rf %s;mv %s.bak %s", DBLOC, DBLOC, DBLOC);
		system (cmdline);
		g_free (cmdline);
		goto cleanup;
	}
	g_free (cmdline);
	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(gfpm_optimize_db_progressbar), 0.85);
	while (gtk_events_pending()) gtk_main_iteration ();

	/* remove old database */
	gfpm_optimize_db_set_progress_status (_("removing old database"));
	cmdline = g_strdup_printf ("rm -rf %s.bak", DBLOC);
	system (cmdline);
	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(gfpm_optimize_db_progressbar), 0.95);
	while (gtk_events_pending()) gtk_main_iteration ();
	sleep (2);

	/* remove temp files */
	gfpm_optimize_db_set_progress_status (_("removing temporary files"));
	g_remove (OLDSUM);
	g_remove (NEWSUM);
	g_remove (LOCKFILE);
	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(gfpm_optimize_db_progressbar), 1.0);
	while (gtk_events_pending()) gtk_main_iteration ();
	sleep (2);
	gfpm_optimize_db_set_progress_status (_("Database optimized."));
	gfpm_message (_("Database optimized"), _("Your package database is now optimized."));

cleanup:
	gtk_widget_set_sensitive (gfpm_optimize_db_startbtn, TRUE);
	gtk_widget_set_sensitive (gfpm_optimize_db_closebtn, TRUE);

	return;
}