Exemple #1
0
static GList *editor_add_desktop_dir(GList *list, const gchar *path)
{
	DIR *dp;
	struct dirent *dir;
	gchar *pathl;

	pathl = path_from_utf8(path);
	dp = opendir(pathl);
	g_free(pathl);
	if (!dp)
		{
		/* dir not found */
		return list;
		}
	while ((dir = readdir(dp)) != NULL)
		{
		gchar *namel = dir->d_name;

		if (g_str_has_suffix(namel, ".desktop"))
			{
			gchar *name = path_to_utf8(namel);
			gchar *dpath = g_build_filename(path, name, NULL);
			list = g_list_prepend(list, dpath);
			g_free(name);
			}
		}
	closedir(dp);
	return list;
}
Exemple #2
0
GList *editor_get_desktop_files(void)
{
	gchar *path;
	gchar *xdg_data_dirs;
	gchar *all_dirs;
	gchar **split_dirs;
	gint i;
	GList *list = NULL;

	xdg_data_dirs = getenv("XDG_DATA_DIRS");
	if (xdg_data_dirs && xdg_data_dirs[0])
		xdg_data_dirs = path_to_utf8(xdg_data_dirs);
	else
		xdg_data_dirs = g_strdup("/usr/share");

	all_dirs = g_strconcat(get_rc_dir(), ":", GQ_APP_DIR, ":", xdg_data_home_get(), ":", xdg_data_dirs, NULL);

	g_free(xdg_data_dirs);

	split_dirs = g_strsplit(all_dirs, ":", 0);

	g_free(all_dirs);

	for (i = 0; split_dirs[i]; i++);
	for (--i; i >= 0; i--)
		{
		path = g_build_filename(split_dirs[i], "applications", NULL);
		list = editor_add_desktop_dir(list, path);
		g_free(path);
		}

	g_strfreev(split_dirs);
	return list;
}
Exemple #3
0
void cOverworld_Manager::Load_Dir(const fs::path& dir, bool user_dir /* = false */)
{
    // set world directory
    vector<fs::path> subdirs = Get_Directory_Files(dir, "", true, false);
    std::sort(subdirs.begin(), subdirs.end());

    for (vector<fs::path>::iterator curdir = subdirs.begin(); curdir != subdirs.end(); ++curdir) {
        try {
            fs::path current_dir = *curdir;

            // only directories with an existing description
            if (File_Exists(current_dir / "description.xml")) {
                cOverworld* overworld = Get_from_Path(current_dir);

                // already available
                if (overworld) {
                    overworld->m_description->m_user = 2; // 2 = available in system *and* in user dir
                    continue;
                }

                overworld = cOverworld::Load_From_Directory(current_dir, user_dir);
                objects.push_back(overworld);
            }
        }
        catch (const std::exception& ex) {
            printf("%s %s\n", path_to_utf8(*curdir).c_str(), ex.what());
        }
    }
}
/* first we try the HOME environment var, if that doesn't work, we try getpwuid(). */
const gchar *homedir(void)
{
	static gchar *home = NULL;

	if (!home)
		{
		home = path_to_utf8(getenv("HOME"));
		}
	if (!home)
		{
		struct passwd *pw = getpwuid(getuid());
		if (pw) home = path_to_utf8(pw->pw_dir);
		}

	return home;
}
Exemple #5
0
void cFlyon::Set_Image_Dir(fs::path dir)
{
    if (dir.empty()) {
        return;
    }

    // if not image directory
    if (!File_Exists(pResource_Manager->Get_Game_Pixmaps_Directory() / dir / utf8_to_path("closed_1.settings")) && !File_Exists(pResource_Manager->Get_Game_Pixmaps_Directory() / dir / utf8_to_path("closed_1.png"))) {
        std::cerr   << "Warning: Flyon image files not found; does the flyon directory "
                    << path_to_utf8(dir) << " exist?" << std::endl;
        return;
    }

    m_img_dir = dir;

    // clear images
    Clear_Images();
    // set images
    Add_Image(pVideo->Get_Surface(m_img_dir / utf8_to_path("closed_1.png")));
    Add_Image(pVideo->Get_Surface(m_img_dir / utf8_to_path("closed_2.png")));
    Add_Image(pVideo->Get_Surface(m_img_dir / utf8_to_path("open_1.png")));
    Add_Image(pVideo->Get_Surface(m_img_dir / utf8_to_path("open_2.png")));
    // set start image
    Set_Image_Num(0, 1);

    Set_Animation(1);
    Set_Animation_Image_Range(0, 3);
    Set_Time_All(130, 1);
    Reset_Animation();
}
Exemple #6
0
static void tab_completion_read_dir(TabCompData *td, const gchar *path)
{
	DIR *dp;
	struct dirent *dir;
	GList *list = NULL;
	gchar *pathl;

	tab_completion_free_list(td);

	pathl = path_from_utf8(path);
	dp = opendir(pathl);
	if (!dp)
		{
		/* dir not found */
		g_free(pathl);
		return;
		}
	while ((dir = readdir(dp)) != NULL)
		{
		gchar *name = dir->d_name;
		if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0 &&
						(name[0] != '.' || options->file_filter.show_hidden_files))
			{
			gchar *abspath = g_build_filename(pathl, name, NULL);

			if (g_file_test(abspath, G_FILE_TEST_IS_DIR))
				{
				gchar *dname = g_strconcat(name, G_DIR_SEPARATOR_S, NULL);
				list = g_list_prepend(list, path_to_utf8(dname));
				g_free(dname);
				}
			else
				{
				list = g_list_prepend(list, path_to_utf8(name));
				}
			g_free(abspath);
			}
		}
	closedir(dp);

	td->dir_path = g_strdup(path);
	td->file_list = list;
	g_free(pathl);
}
gchar *get_current_dir(void)
{
	gchar *pathl;
	gchar *path8;

	pathl = g_get_current_dir();
	path8 = path_to_utf8(pathl);
	g_free(pathl);

	return path8;
}
Exemple #8
0
xmlpp::Element* cFlyon::Save_To_XML_Node(xmlpp::Element* p_element)
{
    xmlpp::Element* p_node = cEnemy::Save_To_XML_Node(p_element);

    Add_Property(p_node, "direction", Get_Direction_Name(m_start_direction));
    Add_Property(p_node, "image_dir", path_to_utf8(m_img_dir));
    Add_Property(p_node, "max_distance", static_cast<int>(m_max_distance));
    Add_Property(p_node, "speed", m_speed);

    return p_node;
}
Exemple #9
0
FileData *file_data_new(const gchar *path, struct stat *st)
{
	FileData *fd;

	fd = g_new0(FileData, 1);
	fd->path = path_to_utf8(path);
	fd->name = filename_from_path(fd->path);
	fd->size = st->st_size;
	fd->date = st->st_mtime;
	fd->pixbuf = NULL;

	return fd;
}
Exemple #10
0
GList *uri_pathlist_from_uris(gchar **uris)
{
	GList *list = NULL;
	guint i = 0;

	while (uris[i])
		{
		gchar *local_path = g_filename_from_uri(uris[i], NULL, NULL);
		gchar *path = path_to_utf8(local_path);
		g_free(local_path);
		list = g_list_prepend(list, path);
		i++;
		}

	return g_list_reverse(list);
}
Exemple #11
0
void cFlyon::Editor_Activate(void)
{
    // get window manager
    CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton();

    // direction
    CEGUI::Combobox* combobox = static_cast<CEGUI::Combobox*>(wmgr.createWindow("TaharezLook/Combobox", "editor_flyon_direction"));
    Editor_Add(UTF8_("Direction"), UTF8_("Direction it moves into."), combobox, 100, 110);

    combobox->addItem(new CEGUI::ListboxTextItem("up"));
    combobox->addItem(new CEGUI::ListboxTextItem("down"));
    combobox->addItem(new CEGUI::ListboxTextItem("left"));
    combobox->addItem(new CEGUI::ListboxTextItem("right"));

    combobox->setText(Get_Direction_Name(m_start_direction));
    combobox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&cFlyon::Editor_Direction_Select, this));

    // image dir
    CEGUI::Editbox* editbox = static_cast<CEGUI::Editbox*>(wmgr.createWindow("TaharezLook/Editbox", "editor_flyon_image_dir"));
    Editor_Add(UTF8_("Image directory"), UTF8_("Directory containing the images"), editbox, 200);

    editbox->setText(path_to_utf8(m_img_dir).c_str());
    editbox->subscribeEvent(CEGUI::Editbox::EventTextChanged, CEGUI::Event::Subscriber(&cFlyon::Editor_Image_Dir_Text_Changed, this));

    // max distance
    editbox = static_cast<CEGUI::Editbox*>(wmgr.createWindow("TaharezLook/Editbox", "editor_flyon_max_distance"));
    Editor_Add(UTF8_("Distance"), _("Movable Distance into its direction"), editbox, 90);

    editbox->setValidationString("^[+]?\\d*$");
    editbox->setText(int_to_string(static_cast<int>(m_max_distance)));
    editbox->subscribeEvent(CEGUI::Editbox::EventTextChanged, CEGUI::Event::Subscriber(&cFlyon::Editor_Max_Distance_Text_Changed, this));

    // speed
    editbox = static_cast<CEGUI::Editbox*>(wmgr.createWindow("TaharezLook/Editbox", "editor_flyon_speed"));
    Editor_Add(UTF8_("Speed"), UTF8_("Initial speed when jumping out"), editbox, 120);

    editbox->setValidationString("[+]?[0-9]*\\.?[0-9]*");
    editbox->setText(float_to_string(m_speed, 6, 0));
    editbox->subscribeEvent(CEGUI::Editbox::EventTextChanged, CEGUI::Event::Subscriber(&cFlyon::Editor_Speed_Text_Changed, this));

    // init
    Editor_Init();
}
Exemple #12
0
cFlyon::cFlyon(XmlAttributes& attributes, cSprite_Manager* sprite_manager)
    : cEnemy(sprite_manager)
{
    cFlyon::Init();

    // position
    Set_Pos(string_to_float(attributes["posx"]), string_to_float(attributes["posy"]), true);

    // image directory
    Set_Image_Dir(utf8_to_path(attributes.fetch("image_dir", path_to_utf8(m_img_dir))));

    // direction
    Set_Direction(Get_Direction_Id(attributes.fetch("direction", Get_Direction_Name(m_start_direction))));

    // max distance
    Set_Max_Distance(string_to_int(attributes.fetch("max_distance", int_to_string(m_max_distance))));

    // speed
    Set_Speed(string_to_float(attributes.fetch("speed", float_to_string(m_speed))));
}
Exemple #13
0
void cBackground::Save_To_XML_Node(xmlpp::Element* p_parent)
{
    if (m_type == BG_NONE)
        return;

    // <background>
    xmlpp::Element* p_node = p_parent->add_child("background");
    Add_Property(p_node, "type", m_type);

    // gradient
    if (m_type == BG_GR_HOR || m_type == BG_GR_VER) {
        // background color 1
        Add_Property(p_node, "bg_color_1_red", static_cast<int>(m_color_1.red));
        Add_Property(p_node, "bg_color_1_green", static_cast<int>(m_color_1.green));
        Add_Property(p_node, "bg_color_1_blue", static_cast<int>(m_color_1.blue));
        // background color 2
        Add_Property(p_node, "bg_color_2_red", static_cast<int>(m_color_2.red));
        Add_Property(p_node, "bg_color_2_green", static_cast<int>(m_color_2.green));
        Add_Property(p_node, "bg_color_2_blue", static_cast<int>(m_color_2.blue));
    }
    // image
    else if (m_type == BG_IMG_BOTTOM || m_type == BG_IMG_TOP || m_type == BG_IMG_ALL) {
        // position
        Add_Property(p_node, "posx", m_start_pos_x);
        Add_Property(p_node, "posy", m_start_pos_y);
        Add_Property(p_node, "posz", m_pos_z);

        // image filename
        Add_Property(p_node, "image", path_to_utf8(m_image_1_filename));
        // speed
        Add_Property(p_node, "speedx", m_speed_x);
        Add_Property(p_node, "speedy", m_speed_y);
        // constant velocity
        Add_Property(p_node, "const_velx", m_const_vel_x);
        Add_Property(p_node, "const_vely", m_const_vel_y);
    }
    else
        std::cerr << "Warning: Detected unknown background type '" << m_type << "' on saving." << std::endl;
    // </background>
}
Exemple #14
0
static gint path_list_real(const gchar *path, GList **files, GList **dirs,
			   gint follow_links)
{
	DIR *dp;
	struct dirent *dir;
	GList *f_list = NULL;
	GList *d_list = NULL;
	gchar *pathl;

	if (!path) return FALSE;

	pathl = path_from_utf8(path);
	dp = opendir(pathl);
	if (!dp)
		{
		/* dir not found */
		g_free(pathl);
		return FALSE;
		}

	/* root dir fix */
	if (pathl[0] == '/' && pathl[1] == '\0')
		{
		g_free(pathl);
		pathl = g_strdup("");
		}

	while ((dir = readdir(dp)) != NULL)
		{
		struct stat st_buf;
		gchar *name;
		gchar *filepath;
		gint result;

		name = dir->d_name;
		filepath = g_strconcat(pathl, "/", name, NULL);

		if (follow_links)
			{
			result = stat(filepath, &st_buf);
			}
		else
			{
			result = lstat(filepath, &st_buf);
			}

		if (result == 0)
			{
			gchar *path8;
			gchar *name8;

			name8 = path_to_utf8(name);
			path8 = g_strconcat(path, "/", name8, NULL);
			g_free(name8);

			if (dirs && S_ISDIR(st_buf.st_mode) &&
			    !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) )
				{
				d_list = g_list_prepend(d_list, path8);
				path8 = NULL;
				}
			else if (files &&
				 (S_ISREG(st_buf.st_mode) || (!follow_links && S_ISLNK(st_buf.st_mode))) )
				{
				f_list = g_list_prepend(f_list, path8);
				path8 = NULL;
				}
			g_free(path8);
			}

		g_free(filepath);
		}

	closedir(dp);

	g_free(pathl);

	if (dirs) *dirs = g_list_reverse(d_list);
	if (files) *files = g_list_reverse(f_list);

	return TRUE;
}
Exemple #15
0
static void dest_populate(Dest_Data *dd, const gchar *path)
{
	DIR *dp;
	struct dirent *dir;
	struct stat ent_sbuf;
	GList *path_list = NULL;
	GList *file_list = NULL;
	GList *list;
	GtkListStore *store;
	gchar *pathl;

	if (!path) return;

	pathl = path_from_utf8(path);
	dp = opendir(pathl);
	if (!dp)
		{
		/* dir not found */
		g_free(pathl);
		return;
		}
	while ((dir = readdir(dp)) != NULL)
		{
		if (!options->file_filter.show_dot_directory
		    && dir->d_name[0] == '.' && dir->d_name[1] == '\0')
			continue;
		if (dir->d_name[0] == '.' && dir->d_name[1] == '.' && dir->d_name[2] == '\0'
		    && pathl[0] == G_DIR_SEPARATOR && pathl[1] == '\0')
			continue; /* no .. for root directory */
		if (dd->show_hidden || !is_hidden(dir->d_name))
			{
			gchar *name = dir->d_name;
			gchar *filepath = g_build_filename(pathl, name, NULL);
			if (stat(filepath, &ent_sbuf) >= 0 && S_ISDIR(ent_sbuf.st_mode))
				{
				path_list = g_list_prepend(path_list, path_to_utf8(name));
				}
			else if (dd->f_view)
				{
				if (!dd->filter || (dd->filter && dest_check_filter(dd->filter, name)))
					file_list = g_list_prepend(file_list, path_to_utf8(name));
				}
			g_free(filepath);
			}
		}
	closedir(dp);
	g_free(pathl);

	path_list = g_list_sort(path_list, (GCompareFunc) dest_sort_cb);
	file_list = g_list_sort(file_list, (GCompareFunc) dest_sort_cb);

	store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dd->d_view)));
	gtk_list_store_clear(store);

	list = path_list;
	while (list)
		{
		GtkTreeIter iter;
		gchar *filepath;

		if (strcmp(list->data, ".") == 0)
			{
			filepath = g_strdup(path);
			}
		else if (strcmp(list->data, "..") == 0)
			{
			gchar *p;
			filepath = g_strdup(path);
			p = (gchar *)filename_from_path(filepath);
			if (p - 1 != filepath) p--;
			p[0] = '\0';
			}
		else
			{
			filepath = g_build_filename(path, list->data, NULL);
			}

		gtk_list_store_append(store, &iter);
		gtk_list_store_set(store, &iter, 0, list->data, 1, filepath, -1);

		g_free(filepath);
		list = list->next;
		}

	string_list_free(path_list);


	if (dd->f_view)
		{
		store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dd->f_view)));
		gtk_list_store_clear(store);

		list = file_list;
		while (list)
			{
			GtkTreeIter iter;
			gchar *filepath;
			const gchar *name = list->data;

			filepath = g_build_filename(path, name, NULL);

			gtk_list_store_append(store, &iter);
			gtk_list_store_set(store, &iter, 0, name, 1, filepath, -1);

			g_free(filepath);
			list = list->next;
			}

		string_list_free(file_list);
		}

	g_free(dd->path);
	dd->path = g_strdup(path);
}