/** recursively read the menu hierarchy */
MenuEntry *menu_read(MenuEntry *parent, const char *name)
{
	static int id = 0;

	if ((name != NULL) && (config_has_section(name))) {
		MenuEntry *me = calloc(1, sizeof(MenuEntry)); // auto-NULL elements

		if (me == NULL)
			return NULL;
		// set common entries
		me->id = id++;
		me->name = strdup(name);
		if (me->name == NULL) {
			//menu_free(me);
			return NULL;
		}

		me->displayname = strdup(config_get_string(name, "DisplayName", 0, name));
		if (me->displayname == NULL) {
			//menu_free(me);
			return NULL;
		}

		me->parent = parent;
		me->next = NULL;
		me->children = NULL;
		me->numChildren = 0;

		if (config_get_string(name, "Entry", 0, NULL) != NULL) {
			MenuEntry **addr = &me->children;
			const char *entryname;

			// it is a sub-menu
			me->type = MT_MENU;

			// read menu entries
			while ((entryname = config_get_string(name, "Entry", me->numChildren, NULL)) != NULL) {
				MenuEntry *entry = menu_read(me, entryname);

				if (entry == NULL) {
					//menu_free(me);
					return NULL;
				}

				me->numChildren++;

				*addr = entry;
				addr = &entry->next;
			}
		}
		else if (config_get_string(name, "Exec", 0, NULL) != NULL) {
			MenuEntry **addr = &me->children;
			const char *entryname;

			// it's a command to execute
			me->type = MT_EXEC;

			me->data.exec.command = strdup(config_get_string(name, "Exec", 0, ""));
			if (me->data.exec.command == NULL) {
				//menu_free(me);
				return NULL;
			}
			me->data.exec.feedback = config_get_bool(name, "Feedback", 0, 0);

			// try to read parameters
			while ((entryname = config_get_string(name, "Parameter", me->numChildren, NULL)) != NULL) {
				MenuEntry *entry = menu_read(me, entryname);

				if (entry == NULL) {
					//menu_free(me);
					return NULL;
				}

				me->numChildren++;

				*addr = entry;
				addr = &entry->next;
			}

			// automagically add an "Apply ?" action
			if ((me->numChildren > 0) && (addr != NULL))
				*addr = menu_read(me, NULL);
		}
		else if (config_get_string(name, "Type", 0, NULL) != NULL) {
			// it's a command parameter
			const char *type;

			type = config_get_string(name, "Type", 0, "");

			if (strcasecmp(type, "slider") == 0) {
				char buf[35];

				me->type = MT_ARG_SLIDER;

				me->data.slider.value = config_get_int(name, "Value", 0, 0);
				me->data.slider.minval = config_get_int(name, "MinValue", 0, 0);
				me->data.slider.maxval = config_get_int(name, "MaxValue", 0, 1000);

				sprintf(buf, "%d", me->data.slider.minval);
				me->data.slider.mintext = strdup(config_get_string(name, "MinText", 0, buf));
				sprintf(buf, "%d", me->data.slider.maxval);
				me->data.slider.maxtext = strdup(config_get_string(name, "MaxText", 0, buf));

				me->data.slider.stepsize = config_get_int(name, "StepSize", 0, 1);
			}
			else if (strcasecmp(type, "ring") == 0) {
				const char *tmp;
				int numStrings = 0;
				int i = 0;

				me->type = MT_ARG_RING;

				me->data.ring.value = config_get_int(name, "Value", 0, 0);
				numStrings = config_has_key(name, "String");
				me->data.ring.strings = calloc(sizeof(char *), numStrings+1);
				me->data.ring.strings[numStrings] = NULL;

				while ((tmp = config_get_string(name, "String", i, NULL)) != NULL) {
					me->data.ring.strings[i] = strdup(tmp);
					i++;
				}
				me->data.ring.strings[i] = NULL;
			}
			else if (strcasecmp(type, "numeric") == 0) {
				me->type = MT_ARG_NUMERIC;

				me->data.numeric.value = config_get_int(name, "Value", 0, 0);
				me->data.numeric.minval = config_get_int(name, "MinValue", 0, 0);
				me->data.numeric.maxval = config_get_int(name, "MaxValue", 0, 1000);
			}
			else if (strcasecmp(type, "alpha") == 0) {
				me->type = MT_ARG_ALPHA;

				me->data.alpha.value = strdup(config_get_string(name, "Value", 0, ""));
				me->data.alpha.minlen = config_get_int(name, "MinLength", 0, 0);
				me->data.alpha.maxlen = config_get_int(name, "MaxLength", 0, 100);
				me->data.alpha.allowed = strdup(config_get_string(name, "AllowedChars", 0,
										  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
			}
			else if (strcasecmp(type, "ip") == 0) {
				me->type = MT_ARG_IP;

				me->data.ip.value = strdup(config_get_string(name, "Value", 0, ""));
				me->data.ip.v6 = config_get_bool(name, "Value", 0, 0);
			}
			else if (strcasecmp(type, "checkbox") == 0) {
				const char *tmp;

				me->type = MT_ARG_CHECKBOX;

				me->data.checkbox.allow_gray = config_get_bool(name, "AllowGray", 0, 0);
				me->data.checkbox.value = (me->data.checkbox.allow_gray)
				                          ? config_get_tristate(name, "Value", 0, "gray", 0)
				                          : config_get_bool(name, "Value", 0, 0);
				// get replacement strings for different values
				tmp = config_get_string(name, "OffText", 0, NULL);
				me->data.checkbox.map[0] = (tmp != NULL) ? strdup(tmp) : NULL;
				tmp = config_get_string(name, "OnText", 0, NULL);
				me->data.checkbox.map[1] = (tmp != NULL) ? strdup(tmp) : NULL;
				tmp = config_get_string(name, "GrayText", 0, NULL);
				me->data.checkbox.map[2] = (tmp != NULL) ? strdup(tmp) : NULL;
			}
			else {
				report(RPT_DEBUG, "illegal parameter type");
				//menu_free(me);
				return NULL;
			}
		}
		else {
			report(RPT_DEBUG, "unknown menu entry type");
			//menu_free(me);
			return NULL;
		}

		return me;
	}
	else {
		/* the magic stuff: if name is NULL and parent is an EXEC entry,
		 * then generate an Action entry with the name "Apply" */
		if ((name == NULL) && (parent != NULL) && (parent->type = MT_EXEC)) {
			MenuEntry *me = calloc(1, sizeof(MenuEntry)); // auto-NULL elements

			if (me == NULL)
				return NULL;
			// set common entries
			me->id = id++;
			me->name = malloc(strlen(parent->name) + 10);
			if (me->name == NULL) {
				//menu_free(me);
				return NULL;
			}
			strcpy(me->name, "Apply_");
			strcat(me->name, parent->name);

			me->displayname = strdup("Apply!");
			if (me->displayname == NULL) {
				//menu_free(me);
				return NULL;
			}

			me->parent = parent;
			me->next = NULL;
			me->children = NULL;
			me->numChildren = 0;
			me->type = MT_ARG_ACTION | MT_AUTOMATIC;

			return me;
		}
	}

	return NULL;
}
Esempio n. 2
0
core_info_list_t *core_info_list_new(const char *modules_path)
{
   size_t i;
   core_info_t *core_info = NULL;
   core_info_list_t *core_info_list = NULL;
   struct string_list *contents = (struct string_list*)dir_list_new(modules_path, EXT_EXECUTABLES, false);
   if (!contents)
      return NULL;

   core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
   if (!core_info_list)
      goto error;

   core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
   if (!core_info)
      goto error;

   core_info_list->list = core_info;
   core_info_list->count = contents->size;

   for (i = 0; i < contents->size; i++)
   {
      char info_path_base[PATH_MAX], info_path[PATH_MAX];
      core_info[i].path = strdup(contents->elems[i].data);

      if (!core_info[i].path)
         break;

      fill_pathname_base(info_path_base, contents->elems[i].data, sizeof(info_path_base));
      path_remove_extension(info_path_base);

#if defined(RARCH_MOBILE) || defined(RARCH_CONSOLE)
      char *substr = strrchr(info_path_base, '_');
      if (substr)
         *substr = '\0';
#endif

      strlcat(info_path_base, ".info", sizeof(info_path_base));

      fill_pathname_join(info_path, (*g_settings.libretro_info_path) ? g_settings.libretro_info_path : modules_path,
            info_path_base, sizeof(info_path));

      core_info[i].data = config_file_new(info_path);

      if (core_info[i].data)
      {
         unsigned count = 0;
         config_get_string(core_info[i].data, "display_name", &core_info[i].display_name);
         config_get_string(core_info[i].data, "systemname", &core_info[i].systemname);
         config_get_uint(core_info[i].data, "firmware_count", &count);
         core_info[i].firmware_count = count;
         if (config_get_string(core_info[i].data, "supported_extensions", &core_info[i].supported_extensions) &&
               core_info[i].supported_extensions)
            core_info[i].supported_extensions_list = string_split(core_info[i].supported_extensions, "|");

         if (config_get_string(core_info[i].data, "authors", &core_info[i].authors) &&
               core_info[i].authors)
            core_info[i].authors_list = string_split(core_info[i].authors, "|");

         if (config_get_string(core_info[i].data, "permissions", &core_info[i].permissions) &&
               core_info[i].permissions)
            core_info[i].permissions_list = string_split(core_info[i].permissions, "|");
         if (config_get_string(core_info[i].data, "notes", &core_info[i].notes) &&
               core_info[i].notes)
            core_info[i].note_list = string_split(core_info[i].notes, "|");
      }

      if (!core_info[i].display_name)
         core_info[i].display_name = strdup(path_basename(core_info[i].path));
   }

   core_info_list_resolve_all_extensions(core_info_list);
   core_info_list_resolve_all_firmware(core_info_list);

   dir_list_free(contents);
   return core_info_list;

error:
   if (contents)
      dir_list_free(contents);
   core_info_list_free(core_info_list);
   return NULL;
}
Esempio n. 3
0
core_info_list_t *core_info_list_new(const char *modules_path)
{
   struct string_list *contents = dir_list_new(modules_path, EXT_EXECUTABLES, false);
   size_t all_ext_len, i;

   core_info_t *core_info = NULL;
   core_info_list_t *core_info_list = NULL;

   if (!contents)
      return NULL;

   core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
   if (!core_info_list)
      goto error;

   core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
   if (!core_info)
      goto error;

   core_info_list->list = core_info;
   core_info_list->count = contents->size;

   for (i = 0; i < contents->size; i++)
   {
      char info_path_base[PATH_MAX], info_path[PATH_MAX];
      core_info[i].path = strdup(contents->elems[i].data);

      if (!core_info[i].path)
         break;

      fill_pathname_base(info_path_base, contents->elems[i].data, sizeof(info_path_base));
      path_remove_extension(info_path_base);

#if defined(RARCH_MOBILE) || defined(RARCH_CONSOLE)
      char *substr = strrchr(info_path_base, '_');
      if (substr)
         *substr = '\0';
#endif

      strlcat(info_path_base, ".info", sizeof(info_path_base));

      fill_pathname_join(info_path, (*g_settings.libretro_info_path) ? g_settings.libretro_info_path : modules_path,
            info_path_base, sizeof(info_path));

      core_info[i].data = config_file_new(info_path);

      if (core_info[i].data)
      {
         config_get_string(core_info[i].data, "display_name", &core_info[i].display_name);
         if (config_get_string(core_info[i].data, "supported_extensions", &core_info[i].supported_extensions) &&
               core_info[i].supported_extensions)
            core_info[i].supported_extensions_list = string_split(core_info[i].supported_extensions, "|");

         if (config_get_string(core_info[i].data, "authors", &core_info[i].authors) &&
               core_info[i].authors)
            core_info[i].authors_list = string_split(core_info[i].authors, "|");
      }

      if (!core_info[i].display_name)
         core_info[i].display_name = strdup(path_basename(core_info[i].path));
   }

   all_ext_len = 0;
   for (i = 0; i < core_info_list->count; i++)
   {
      all_ext_len += core_info_list->list[i].supported_extensions ?
         (strlen(core_info_list->list[i].supported_extensions) + 2) : 0;
   }

   if (all_ext_len)
   {
      all_ext_len += strlen("|zip");
      core_info_list->all_ext = (char*)calloc(1, all_ext_len);
   }

   if (core_info_list->all_ext)
   {
      for (i = 0; i < core_info_list->count; i++)
      {
         if (core_info_list->list[i].supported_extensions)
         {
            strlcat(core_info_list->all_ext, core_info_list->list[i].supported_extensions, all_ext_len);
            strlcat(core_info_list->all_ext, "|", all_ext_len);
         }
      }
      strlcat(core_info_list->all_ext, "|zip", all_ext_len);
   }

   dir_list_free(contents);
   return core_info_list;

error:
   if (contents)
      dir_list_free(contents);
   core_info_list_free(core_info_list);
   return NULL;
}
Esempio n. 4
0
/**
 * TimeDate Screen displays current time and date, uptime, OS ver...
 *
 *\verbatim
 *
 * +--------------------+	+--------------------+
 * |## Linux 2.6.11 ###@|	|### TIME: myhost ##@|
 * |Up xxx days hh:mm:ss|	|17.05.2005 11:32:57a|
 * |  Wed May 17, 1998  |	+--------------------+
 * |11:32:57a  100% idle|
 * +--------------------+
 *
 *\endverbatim
 *
 * \param rep        Time since last screen update
 * \param display    1 if screen is visible or data should be updated
 * \param flags_ptr  Mode flags
 * \return  Always 0
 */
int
time_screen(int rep, int display, int *flags_ptr)
{
	char now[40];
	char today[40];
	int xoffs;
	int days, hour, min, sec;
	static int heartbeat = 0;
	static const char *timeFormat = NULL;
	static const char *dateFormat = NULL;
	time_t thetime;
	struct tm *rtime;
	double uptime, idle;

	if ((*flags_ptr & INITIALIZED) == 0) {
		*flags_ptr |= INITIALIZED;

		/* get config values */
		timeFormat = config_get_string("TimeDate", "TimeFormat", 0, "%H:%M:%S");
		dateFormat = config_get_string("TimeDate", "DateFormat", 0, "%b %d %Y");

		sock_send_string(sock, "screen_add T\n");
		sock_printf(sock, "screen_set T -name {Time Screen: %s}\n", get_hostname());
		sock_send_string(sock, "widget_add T title title\n");
		sock_send_string(sock, "widget_add T one string\n");
		if (lcd_hgt >= 4) {
			sock_send_string(sock, "widget_add T two string\n");
			sock_send_string(sock, "widget_add T three string\n");

			/* write title bar: OS name, OS version, hostname */
			sock_printf(sock, "widget_set T title {%s %s: %s}\n",
				get_sysname(), get_sysrelease(), get_hostname());
		}
		else {
			/* write title bar: hostname */
			sock_printf(sock, "widget_set T title {TIME: %s}\n", get_hostname());
		}
	}

	/* toggle colon display */
	heartbeat ^= 1;

	time(&thetime);
	rtime = localtime(&thetime);

	if (strftime(today, sizeof(today), dateFormat, rtime) == 0)
		*today = '\0';
	if (strftime(now, sizeof(now), timeFormat, rtime) == 0)
		*now = '\0';
	tickTime(now, heartbeat);

	if (lcd_hgt >= 4) {
		char tmp[40];	/* should be large enough */

		machine_get_uptime(&uptime, &idle);

		/* display the uptime... */
		days = (int) uptime / 86400;
		hour = ((int) uptime % 86400) / 3600;
		min  = ((int) uptime % 3600) / 60;
		sec  = ((int) uptime % 60);

		if (lcd_wid >= 20)
			sprintf(tmp, "Up %3d day%s %02d:%02d:%02d",
				days, ((days != 1) ? "s" : ""), hour, min, sec);
		else
			sprintf(tmp, "Up %dd %02d:%02d:%02d", days, hour, min, sec);

		xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
		if (display)
			sock_printf(sock, "widget_set T one %i 2 {%s}\n", xoffs, tmp);

		/* display the date */
		xoffs = (lcd_wid > strlen(today)) ? ((lcd_wid - strlen(today)) / 2) + 1 : 1;
		if (display)
			sock_printf(sock, "widget_set T two %i 3 {%s}\n", xoffs, today);

		/* display the time & idle time... */
		sprintf(tmp, "%s %3i%% idle", now, (int) idle);
		xoffs = (lcd_wid > strlen(tmp)) ? ((lcd_wid - strlen(tmp)) / 2) + 1 : 1;
		if (display)
			sock_printf(sock, "widget_set T three %i 4 {%s}\n", xoffs, tmp);
	}
	else {			/* 2 line version of the screen */
		xoffs = (lcd_wid > (strlen(today) + strlen(now) + 1))
			? ((lcd_wid - ((strlen(today) + strlen(now) + 1))) / 2) + 1 : 1;
		if (display)
			sock_printf(sock, "widget_set T one %i 2 {%s %s}\n", xoffs, today, now);
	}

	return 0;
}				/* End time_screen() */
Esempio n. 5
0
static core_info_list_t *core_info_list_new(const char *path,
      const char *libretro_info_dir,
      const char *exts,
      bool dir_show_hidden_files)
{
   size_t i;
   core_info_t *core_info           = NULL;
   core_info_list_t *core_info_list = NULL;
   const char       *path_basedir   = libretro_info_dir;
   struct string_list *contents     = string_list_new();
   bool                          ok = dir_list_append(contents, path, exts,
         false, dir_show_hidden_files, false, false);

#if defined(__WINRT__) || defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
   /* UWP: browse the optional packages for additional cores */
   struct string_list *core_packages = string_list_new();
   uwp_fill_installed_core_packages(core_packages);
   for (i = 0; i < core_packages->size; i++)
   {
      dir_list_append(contents, core_packages->elems[i].data, exts,
            false, dir_show_hidden_files, false, false);
   }
   string_list_free(core_packages);
#else
   /* Keep the old 'directory not found' behavior */
   if (!ok)
   {
      string_list_free(contents);
      contents = NULL;
   }
#endif

   if (!contents)
      return NULL;

   core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
   if (!core_info_list)
      goto error;

   core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
   if (!core_info)
      goto error;

   core_info_list->list  = core_info;
   core_info_list->count = contents->size;

   for (i = 0; i < contents->size; i++)
   {
      size_t info_path_size = PATH_MAX_LENGTH * sizeof(char);
      char *info_path       = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));

      info_path[0]          = '\0';

      if (
            core_info_list_iterate(info_path, info_path_size,
               path_basedir, contents, i)
            && path_is_valid(info_path))
      {
         char *tmp           = NULL;
         bool tmp_bool       = false;
         unsigned count      = 0;
         config_file_t *conf = config_file_new(info_path);

         free(info_path);

         if (!conf)
            continue;

         if (config_get_string(conf, "display_name", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].display_name = strdup(tmp);
            free(tmp);
            tmp = NULL;
         }
         if (config_get_string(conf, "display_version", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].display_version = strdup(tmp);
            free(tmp);
            tmp = NULL;
         }
         if (config_get_string(conf, "corename", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].core_name = strdup(tmp);
            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "systemname", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].systemname = strdup(tmp);
            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "systemid", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].system_id = strdup(tmp);
            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "manufacturer", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].system_manufacturer = strdup(tmp);
            free(tmp);
            tmp = NULL;
         }

         config_get_uint(conf, "firmware_count", &count);

         core_info[i].firmware_count = count;

         if (config_get_string(conf, "supported_extensions", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].supported_extensions      = strdup(tmp);
            core_info[i].supported_extensions_list =
               string_split(core_info[i].supported_extensions, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "authors", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].authors      = strdup(tmp);
            core_info[i].authors_list =
               string_split(core_info[i].authors, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "permissions", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].permissions      = strdup(tmp);
            core_info[i].permissions_list =
               string_split(core_info[i].permissions, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "license", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].licenses      = strdup(tmp);
            core_info[i].licenses_list =
               string_split(core_info[i].licenses, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "categories", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].categories      = strdup(tmp);
            core_info[i].categories_list =
               string_split(core_info[i].categories, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "database", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].databases      = strdup(tmp);
            core_info[i].databases_list =
               string_split(core_info[i].databases, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "notes", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].notes     = strdup(tmp);
            core_info[i].note_list = string_split(core_info[i].notes, "|");

            free(tmp);
            tmp = NULL;
         }

         if (tmp)
            free(tmp);
         tmp    = NULL;

         if (config_get_bool(conf, "supports_no_game",
               &tmp_bool))
            core_info[i].supports_no_game = tmp_bool;

         if (config_get_bool(conf, "database_match_archive_member",
               &tmp_bool))
            core_info[i].database_match_archive_member = tmp_bool;

         core_info[i].config_data = conf;
      }
      else
         free(info_path);

      if (!string_is_empty(contents->elems[i].data))
         core_info[i].path = strdup(contents->elems[i].data);

      if (!core_info[i].display_name)
         core_info[i].display_name =
            strdup(path_basename(core_info[i].path));
   }

   if (core_info_list)
   {
      core_info_list_resolve_all_extensions(core_info_list);
      core_info_list_resolve_all_firmware(core_info_list);
   }

   string_list_free(contents);
   return core_info_list;

error:
   if (contents)
      string_list_free(contents);
   core_info_list_free(core_info_list);
   return NULL;
}
bool OBSBasic::AddProfile(bool create_new, const char *title, const char *text,
		const char *init_text)
{
	std::string newName;
	std::string newDir;
	ConfigFile config;

	if (!GetProfileName(this, newName, newDir, title, text, init_text))
		return false;

	std::string curDir = config_get_string(App()->GlobalConfig(),
			"Basic", "ProfileDir");

	char newPath[512];
	int ret = GetConfigPath(newPath, 512, "obs-studio/basic/profiles/");
	if (ret <= 0) {
		blog(LOG_WARNING, "Failed to get profiles config path");
		return false;
	}

	strcat(newPath, newDir.c_str());

	if (os_mkdir(newPath) < 0) {
		blog(LOG_WARNING, "Failed to create profile directory '%s'",
				newDir.c_str());
		return false;
	}

	if (!create_new)
		CopyProfile(curDir.c_str(), newPath);

	strcat(newPath, "/basic.ini");

	if (config.Open(newPath, CONFIG_OPEN_ALWAYS) != 0) {
		blog(LOG_ERROR, "Failed to open new config file '%s'",
				newDir.c_str());
		return false;
	}

	config_set_string(App()->GlobalConfig(), "Basic", "Profile",
			newName.c_str());
	config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir",
			newDir.c_str());

	config_set_string(config, "General", "Name", newName.c_str());
	config.SaveSafe("tmp");
	config.Swap(basicConfig);
	InitBasicConfigDefaults();
	RefreshProfiles();

	if (create_new)
		ResetProfileData();

	blog(LOG_INFO, "Created profile '%s' (%s, %s)", newName.c_str(),
			create_new ? "clean" : "duplicate", newDir.c_str());
	blog(LOG_INFO, "------------------------------------------------");

	config_save_safe(App()->GlobalConfig(), "tmp", nullptr);
	UpdateTitleBar();

	if (api) {
		api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED);
		api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
	}
	return true;
}
Esempio n. 7
0
static core_info_list_t *core_info_list_new(const char *path)
{
   size_t i;
   core_info_t *core_info           = NULL;
   core_info_list_t *core_info_list = NULL;
   struct string_list *contents     = dir_list_new_special(
                                      path, DIR_LIST_CORES, NULL);
   settings_t             *settings = config_get_ptr();
   const char       *path_basedir   = !string_is_empty(settings->paths.path_libretro_info) ?
      settings->paths.path_libretro_info : settings->paths.directory_libretro;

   if (!contents)
      return NULL;


   core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
   if (!core_info_list)
      goto error;

   core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
   if (!core_info)
      goto error;

   core_info_list->list  = core_info;
   core_info_list->count = contents->size;

   for (i = 0; i < contents->size; i++)
   {
      size_t info_path_size = PATH_MAX_LENGTH * sizeof(char);
      char *info_path       = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));

      info_path[0]          = '\0';

      if (
            core_info_list_iterate(info_path, info_path_size,
               path_basedir, contents, i)
            && path_is_valid(info_path))
      {
         char *tmp           = NULL;
         bool tmp_bool       = false;
         unsigned count      = 0;
         config_file_t *conf = config_file_new(info_path);

         free(info_path);

         if (!conf)
            continue;

         if (config_get_string(conf, "display_name", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].display_name = strdup(tmp);
            free(tmp);
            tmp = NULL;
         }
         if (config_get_string(conf, "corename", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].core_name = strdup(tmp);
            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "systemname", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].systemname = strdup(tmp);
            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "manufacturer", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].system_manufacturer = strdup(tmp);
            free(tmp);
            tmp = NULL;
         }

         config_get_uint(conf, "firmware_count", &count);

         core_info[i].firmware_count = count;

         if (config_get_string(conf, "supported_extensions", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].supported_extensions      = strdup(tmp);
            core_info[i].supported_extensions_list =
               string_split(core_info[i].supported_extensions, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "authors", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].authors      = strdup(tmp);
            core_info[i].authors_list =
               string_split(core_info[i].authors, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "permissions", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].permissions      = strdup(tmp);
            core_info[i].permissions_list =
               string_split(core_info[i].permissions, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "license", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].licenses      = strdup(tmp);
            core_info[i].licenses_list =
               string_split(core_info[i].licenses, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "categories", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].categories      = strdup(tmp);
            core_info[i].categories_list =
               string_split(core_info[i].categories, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "database", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].databases      = strdup(tmp);
            core_info[i].databases_list =
               string_split(core_info[i].databases, "|");

            free(tmp);
            tmp = NULL;
         }

         if (config_get_string(conf, "notes", &tmp)
               && !string_is_empty(tmp))
         {
            core_info[i].notes     = strdup(tmp);
            core_info[i].note_list = string_split(core_info[i].notes, "|");

            free(tmp);
            tmp = NULL;
         }

         if (tmp)
            free(tmp);
         tmp    = NULL;

         if (config_get_bool(conf, "supports_no_game",
               &tmp_bool))
            core_info[i].supports_no_game = tmp_bool;

         if (config_get_bool(conf, "database_match_archive_member",
               &tmp_bool))
            core_info[i].database_match_archive_member = tmp_bool;

         core_info[i].config_data = conf;
      }
      else
         free(info_path);

      if (!string_is_empty(contents->elems[i].data))
         core_info[i].path = strdup(contents->elems[i].data);

      if (!core_info[i].display_name)
         core_info[i].display_name =
            strdup(path_basename(core_info[i].path));
   }

   if (core_info_list)
   {
      core_info_list_resolve_all_extensions(core_info_list);
      core_info_list_resolve_all_firmware(core_info_list);
   }

   dir_list_free(contents);
   return core_info_list;

error:
   if (contents)
      dir_list_free(contents);
   core_info_list_free(core_info_list);
   return NULL;
}
Esempio n. 8
0
File: fds.c Progetto: Aleyr/nesemu2
int cart_load_fds(cart_t *ret,memfile_t *file)
{
	u8 header[16];
	u32 size;
	char biosfile[1024];

	//clear the string
	memset(biosfile,0,1024);

	//parse the bios path
	config_get_eval_string(biosfile,"path.bios");

	//append the path seperator
	str_appendchar(biosfile,PATH_SEPERATOR);

	//append the bios filename
	strcat(biosfile,config_get_string("nes.fds.bios"));

	//try to load bios from the bios directory
	if(loadbios(ret,biosfile) != 0) {

		//see if bios is in the current directory
		if(loadbios(ret,config_get_string("nes.fds.bios")) != 0) {
			return(1);
		}
	}

	//get length of file
	size = memfile_size(file);

	//read the header
	memfile_read(header,1,16,file);

	//check if this is raw fds disk
	if(memcmp(header,fdsident2,15) == 0) {

		//check if the file is a valid size
		if((size % 65500) != 0) {
			log_printf("cart_load_fds:  fds disk image size not multiple of 65500, aborting\n");
			return(1);
		}

		//set number of disk sides
//		ret->disksides = size / 65500;

		//skip back to the beginning
		memfile_rewind(file);
	}

	//check if this is 16-byte header fds disk
	else if(memcmp(header,fdsident,4) == 0) {

		//set number of disk sides
//		ret->disksides = header[4];
		size -= 16;

	}

	//set mapper id to fds mapper
	ret->mapperid = B_FDS;

	//setup the disk data pointers
	ret->disk.size = size;
	ret->disk.data = (u8*)mem_alloc(size);
	ret->diskoriginal.size = size;
	ret->diskoriginal.data = (u8*)mem_alloc(size);

	//read disk data into pointer
	memfile_read(ret->disk.data,1,size,file);

	//copy to original disk data pointer
	memcpy(ret->diskoriginal.data,ret->disk.data,size);

	log_printf("cart_load_fds:  loaded disk, %d sides (%d bytes)\n",ret->disk.size / 65500,size);
	return(0);
}
Esempio n. 9
0
static const char *get_btsnoop_log_path(void) {
  return config_get_string(config, CONFIG_DEFAULT_SECTION, BTSNOOP_LOG_PATH_KEY, "/data/misc/bluedroid/btsnoop_hci.log");
}
Esempio n. 10
0
static core_info_list_t *core_info_list_new(void)
{
   size_t i;
   core_info_t *core_info           = NULL;
   core_info_list_t *core_info_list = NULL;
   struct string_list *contents     = NULL;
   settings_t *settings             = config_get_ptr();

   if (!settings)
      return NULL;

   contents = dir_list_new_special(
         settings->directory.libretro,
         DIR_LIST_CORES, NULL);

   if (!contents)
      return NULL;

   core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
   if (!core_info_list)
      goto error;

   core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
   if (!core_info)
      goto error;

   core_info_list->list = core_info;
   core_info_list->count = contents->size;

   for (i = 0; i < contents->size; i++)
   {
      config_file_t *conf = core_info_list_iterate(contents, i);

      if (conf)
      {
         bool tmp_bool  = false;
         unsigned count = 0;

         config_get_string(conf, "display_name",
               &core_info[i].display_name);
         config_get_string(conf, "corename",
               &core_info[i].core_name);
         config_get_string(conf, "systemname",
               &core_info[i].systemname);
         config_get_string(conf, "manufacturer",
               &core_info[i].system_manufacturer);
         config_get_uint(conf, "firmware_count", &count);
         core_info[i].firmware_count = count;
         if (config_get_string(conf, "supported_extensions",
                  &core_info[i].supported_extensions) &&
               core_info[i].supported_extensions)
            core_info[i].supported_extensions_list =
               string_split(core_info[i].supported_extensions, "|");

         if (config_get_string(conf, "authors",
                  &core_info[i].authors) &&
               core_info[i].authors)
            core_info[i].authors_list =
               string_split(core_info[i].authors, "|");

         if (config_get_string(conf, "permissions",
                  &core_info[i].permissions) &&
               core_info[i].permissions)
            core_info[i].permissions_list =
               string_split(core_info[i].permissions, "|");

         if (config_get_string(conf, "license",
                  &core_info[i].licenses) &&
               core_info[i].licenses)
            core_info[i].licenses_list =
               string_split(core_info[i].licenses, "|");

         if (config_get_string(conf, "categories",
                  &core_info[i].categories) &&
               core_info[i].categories)
            core_info[i].categories_list =
               string_split(core_info[i].categories, "|");

         if (config_get_string(conf, "database",
                  &core_info[i].databases) &&
               core_info[i].databases)
            core_info[i].databases_list =
               string_split(core_info[i].databases, "|");

         if (config_get_string(conf, "notes",
                  &core_info[i].notes) &&
               core_info[i].notes)
            core_info[i].note_list = string_split(core_info[i].notes, "|");

         if (config_get_bool(conf, "supports_no_game",
               &tmp_bool))
            core_info[i].supports_no_game = tmp_bool;

         core_info[i].config_data = conf;
      }

      core_info[i].path = strdup(contents->elems[i].data);

      if (!core_info[i].display_name)
         core_info[i].display_name =
            strdup(path_basename(core_info[i].path));
   }

   core_info_list_resolve_all_extensions(core_info_list);
   core_info_list_resolve_all_firmware(core_info_list);

   dir_list_free(contents);
   return core_info_list;

error:
   if (contents)
      dir_list_free(contents);
   core_info_list_free(core_info_list);
   return NULL;
}
Esempio n. 11
0
int
menuscreens_init(void)
{
	const char *tmp;

	debug(RPT_DEBUG, "%s()", __FUNCTION__);

	/*
	 * Get keys from config file: MenuKey, EnterKey, UpKey, DownKey,
	 * LeftKey, RightKey. For a working menu at least 3 are necessary:
	 * MenuKey, EnterKey, UpKey/DownKey.
	 */
	keymask = 0;
	menu_key = enter_key = NULL;
	tmp = config_get_string("menu", "MenuKey", 0, NULL);
	if (tmp != NULL) {
		menu_key = strdup(tmp);
		keymask |= MENUTOKEN_MENU;
	}
	tmp = config_get_string("menu", "EnterKey", 0, NULL);
	if (tmp != NULL) {
		enter_key = strdup(tmp);
		keymask |= MENUTOKEN_ENTER;
	}

	up_key = down_key = NULL;
	tmp = config_get_string("menu", "UpKey", 0, NULL);
	if (tmp != NULL) {
		up_key = strdup(tmp);
		keymask |= MENUTOKEN_UP;
	}
	tmp = config_get_string("menu", "DownKey", 0, NULL);
	if (tmp != NULL) {
		down_key = strdup(tmp);
		keymask |= MENUTOKEN_DOWN;
	}

	left_key = right_key = NULL;
	tmp = config_get_string("menu", "LeftKey", 0, NULL);
	if (tmp != NULL) {
		left_key = strdup(tmp);
		keymask |= MENUTOKEN_LEFT;
	}
	tmp = config_get_string("menu", "RightKey", 0, NULL);
	if (tmp != NULL) {
		right_key = strdup(tmp);
		keymask |= MENUTOKEN_RIGHT;
	}

	/* Now reserve the keys that were defined */
	if (menu_key != NULL)
		input_reserve_key(menu_key, true, NULL);
	if (enter_key != NULL)
		input_reserve_key(enter_key, false, NULL);
	if (up_key != NULL)
		input_reserve_key(up_key, false, NULL);
	if (down_key != NULL)
		input_reserve_key(down_key, false, NULL);
	if (left_key != NULL)
		input_reserve_key(left_key, false, NULL);
	if (right_key != NULL)
		input_reserve_key(right_key, false, NULL);

	/* Create screen */
	menuscreen = screen_create("_menu_screen", NULL);
	if (menuscreen != NULL)
		menuscreen->priority = PRI_HIDDEN;
	active_menuitem = NULL;

	screenlist_add(menuscreen);

	/* Build menu */
	menuscreen_create_menu();

	return 0;
}
Esempio n. 12
0
GtkWidget *create_menubar(GtkWidget *window)
{
  GtkItemFactory *item_factory;
  GtkAccelGroup *accel_group;
  struct dirent **namelist;
  int n;
  const char *script_path=config_get_string(CONFIG_PATH_SCRIPT);
  GtkItemFactoryEntry fentry;
  struct menu_script* menu_item;
  char *dot;


  /* Make an accelerator group (shortcut keys) */
  accel_group = gtk_accel_group_new ();

  /* Make an ItemFactory (that makes a menubar) */
  item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
                                       accel_group);

  /* This function generates the menu items. Pass the item factory,
     the number of items in the array, the array itself, and any
     callback data for the the menu items. */
  gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);

  if (script_path)
  {
    n = scandir(script_path, &namelist, select_lua, alphasort);
    if (n > 0)
    {
      while(n--) 
      {
	log_printf(LOG_INFO,"Adding %s script to menu", namelist[n]->d_name);

        menu_item=(struct menu_script *)malloc(sizeof(struct menu_script));
	menu_item->script_name = (char* )malloc(strlen(namelist[n]->d_name)+11);
	strcpy(menu_item->script_name,"/Analyser/");
	strcat(menu_item->script_name,namelist[n]->d_name);
	dot = rindex(menu_item->script_name,'.');
	if (dot)
	  *dot=0;
	menu_item->script_file = strdup(namelist[n]->d_name);
	menu_item->prev=SCRIPTS;
	SCRIPTS = menu_item;

	fentry.path=menu_item->script_name;
	fentry.callback=G_CALLBACK(gui_run_script_cb);
	fentry.callback_action=0;
	fentry.item_type="<StockItem>";
	fentry.extra_data=GTK_STOCK_PROPERTIES;
	gtk_item_factory_create_item(item_factory,&fentry,menu_item,2);
      }
      free(namelist);
    }
    else
      log_printf(LOG_WARNING,"No scripts found in %s",script_path);
  }

  /* FIXME: namelist must be deallocated but it holds pointer data for the callback */

  /* Attach the new accelerator group to the window. */
  gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);

  /* Finally, return the actual menu bar created by the item factory. */
  return gtk_item_factory_get_widget (item_factory, "<main>");
}
Esempio n. 13
0
void menu_cb(GtkWidget *w, gint info)
{
  char command[PATH_MAX+32]; /* we should malloc this */
  GtkWidget *filew;
  GtkWidget *dialog;

  switch(info) {
	case 1: 
	  cardtree_delete(CARDTREE,NULL);
	  RUN_LUA_COMMAND("card.CLA=0");
	  log_printf(LOG_INFO,"Cleared card data tree");
	  break;

	case 2:
	  filew = gtk_file_chooser_dialog_new ("Open File",
					       NULL,
					       GTK_FILE_CHOOSER_ACTION_OPEN,
					       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
					       NULL);
	  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (filew), 
					       config_get_string(CONFIG_PATH_OPEN_SAVE));
	  if (gtk_dialog_run (GTK_DIALOG (filew)) == GTK_RESPONSE_ACCEPT)
	  {
	    char *filename;
	    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filew));
	    sprintf(command,"ui.tree_load('%s')",filename);
	    RUN_LUA_COMMAND(command);
	    g_free (filename);
	    filename = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER (filew));
	    config_set_string(CONFIG_PATH_OPEN_SAVE,filename);
	    g_free(filename);
	  }
	  gtk_widget_destroy (filew);
	  break;

	case 3:
	  filew = gtk_file_chooser_dialog_new ("Save File",
 					       NULL,
					       GTK_FILE_CHOOSER_ACTION_SAVE,
					       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					       GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
					       NULL);
	  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (filew), TRUE);
	  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (filew), 
					       config_get_string(CONFIG_PATH_OPEN_SAVE));
	  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (filew), "card.xml");
	  
	  if (gtk_dialog_run (GTK_DIALOG (filew)) == GTK_RESPONSE_ACCEPT)
	  {
	    char *filename;
	    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filew));
	    sprintf(command,"ui.tree_save('%s')",filename);
	    RUN_LUA_COMMAND(command);
	    g_free (filename);
	    filename = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER (filew));
	    config_set_string(CONFIG_PATH_OPEN_SAVE,filename);
	    g_free(filename);
	  }
	  gtk_widget_destroy (filew);
	  break;

	case 4:
	  filew = gtk_file_chooser_dialog_new ("Load script",
					       NULL,
					       GTK_FILE_CHOOSER_ACTION_OPEN,
					       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
					       NULL);
	  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (filew), 
					       config_get_string(CONFIG_PATH_LOAD_SCRIPT));
	  if (gtk_dialog_run (GTK_DIALOG (filew)) == GTK_RESPONSE_ACCEPT)
	  {
	    char *filename;
	    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filew));
	    RUN_LUA_SCRIPT(filename);
	    g_free (filename);
	    filename = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER (filew));
	    config_set_string(CONFIG_PATH_LOAD_SCRIPT,filename);
	    g_free(filename);
	  }
	  gtk_widget_destroy (filew);
	  break;

 
	case 11:
	  RUN_LUA_COMMAND("card.connect()");
	  break;

	case 12:
	  RUN_LUA_COMMAND("card.warm_reset()");
	  break;

	case 13:
	  RUN_LUA_COMMAND("card.disconnect()");
	  break;

	case 99:
	  dialog = gtk_message_dialog_new (NULL,
					   GTK_DIALOG_DESTROY_WITH_PARENT,
				       	   GTK_MESSAGE_INFO,
					   GTK_BUTTONS_OK,
					   "%s",
					   "cardpeek, version 0.1\nCopyright 2009, by 'L1L1'\nLicenced under the GPL 3");
	  gtk_dialog_run (GTK_DIALOG (dialog));
	  gtk_widget_destroy (dialog);

	default:
	  log_printf(LOG_INFO,"menu option : %i",info);
  }
}
Esempio n. 14
0
/**
 * Initialize lineinfo and featureinfo arrays
 */
void ccsnap_line_init() {
   int i;
   cc_uint32_t tmpInt;
   char tempStr[MAX_URL_LENGTH];
   char maskStr[MAX_EXTERNAL_NUMBER_MASK_SIZE];

   /* clean up structure if need be */
   ccsnap_line_pre_init();

   memset(lineInfo, 0, MAX_CONFIG_LINES*sizeof(cc_line_info_t));
   memset(featureInfo, 0, MAX_CONFIG_LINES*sizeof(cc_feature_info_t));
   for (i=1;i<=MAX_CONFIG_LINES;i++) {
      config_get_line_value(CFGID_LINE_FEATURE, &tmpInt, sizeof(tmpInt), i);
      if ( tmpInt == cfgLineFeatureDN ) {
          lineInfo[i].button = i;
          lineInfo[i].line_type = tmpInt;
          config_get_line_value(CFGID_LINE_INDEX,  &tmpInt, sizeof(tmpInt), i);
          lineInfo[i].line_id = tmpInt;
          config_get_line_value(CFGID_LINE_DISPLAYNAME_STRING, tempStr,
                          MAX_URL_LENGTH, i);
          lineInfo[i].dn = strlib_malloc(tempStr, strlen(tempStr));
          config_get_line_value(CFGID_LINE_NAME_STRING, tempStr,
                          MAX_URL_LENGTH, i);
          lineInfo[i].name = strlib_malloc(tempStr, strlen(tempStr));
          config_get_line_value(CFGID_LINE_CFWDALL, tempStr,
                          MAX_URL_LENGTH, i);
          lineInfo[i].cfwd_dest = strlib_malloc(tempStr, strlen(tempStr));
          config_get_line_value(CFGID_LINE_SPEEDDIAL_NUMBER_STRING, tempStr,
                          MAX_URL_LENGTH, i);
          memset(maskStr, 0, sizeof(maskStr));
          config_get_string(CFGID_CCM_EXTERNAL_NUMBER_MASK, maskStr, MAX_EXTERNAL_NUMBER_MASK_SIZE);
          if (strlen(maskStr) > 0) {
              lineInfo[i].externalNumber = CCAPI_ApplyTranslationMask(lineInfo[i].name, maskStr);
              CCAPP_DEBUG("Setting lineInfo[i].externalNumber to %s\n", lineInfo[i].externalNumber);
          } else {
              lineInfo[i].externalNumber = strlib_empty();
          }
      } else {
          lineInfo[i].line_id = MAX_CONFIG_LINES+1; // invalid line id
          lineInfo[i].button = i;
          lineInfo[i].dn = strlib_empty();
          lineInfo[i].name = strlib_empty();
          lineInfo[i].cfwd_dest = strlib_empty();
          lineInfo[i].externalNumber = strlib_empty();
      }
      capset_get_idleset(CC_MODE_CCM, lineInfo[i].allowed_features);

      // get feature again because it might have been changed if it is a DN
      // and the tmpInt might have a different value
      config_get_line_value(CFGID_LINE_FEATURE, &tmpInt, sizeof(tmpInt), i);

      // features which have no properties
      if ( tmpInt == cfgLineFeatureAllCalls ||
    		  tmpInt == cfgLineFeatureMaliciousCallID ||
    		  tmpInt == cfgLineFeatureRedial || tmpInt == cfgLineFeatureAnswerOldest || tmpInt == cfgLineFeatureServices ) {
    	  featureInfo[i].feature_id = tmpInt;
    	  featureInfo[i].button = i;
          featureInfo[i].speedDialNumber = strlib_empty();
          featureInfo[i].contact = strlib_empty();
          featureInfo[i].name = strlib_empty();
          featureInfo[i].retrievalPrefix = strlib_empty();
          featureInfo[i].featureOptionMask = 0;
      } else if ( tmpInt == cfgLineFeatureSpeedDialBLF || tmpInt == cfgLineFeatureSpeedDial){
    	  featureInfo[i].feature_id = tmpInt;
    	  featureInfo[i].button = i;
          config_get_line_value(CFGID_LINE_SPEEDDIAL_NUMBER_STRING, tempStr,
                          MAX_URL_LENGTH, i);
          featureInfo[i].speedDialNumber = strlib_malloc(tempStr, strlen(tempStr));
          featureInfo[i].contact = strlib_empty();
          config_get_line_value(CFGID_LINE_NAME_STRING, tempStr,
                          MAX_URL_LENGTH, i);
          featureInfo[i].name = strlib_malloc(tempStr, strlen(tempStr));
          featureInfo[i].retrievalPrefix = strlib_empty();
          config_get_line_value(CFGID_LINE_FEATURE_OPTION_MASK,  &tmpInt, sizeof(tmpInt), i);
          featureInfo[i].featureOptionMask = tmpInt;
          featureInfo[i].blf_state = CC_SIP_BLF_UNKNOWN;
      } else {
          featureInfo[i].feature_id = 0;
          featureInfo[i].button = MAX_CONFIG_LINES+1; // invalid button value
          featureInfo[i].speedDialNumber = strlib_empty();
          featureInfo[i].contact = strlib_empty();
          featureInfo[i].name = strlib_empty();
          featureInfo[i].retrievalPrefix = strlib_empty();
          featureInfo[i].featureOptionMask = 0;
      }
   }
}
Esempio n. 15
0
static bool load_body(ALLEGRO_CONFIG *cfg, const char *fullname,
		Body *body, char **primary_name)
{
	const char *name;
	char *type;

	/* Just checking */
	if (al_get_first_config_entry(cfg, fullname, NULL) == NULL)
	{
		log_err("Section %s not in file\n", fullname);
		return false;
	}

	/* Fill in some common parameters */
	if (!config_get_double(cfg, fullname, "Mass", &body->mass, false))
		return false;

	if (!config_get_double(cfg, fullname, "Gravitational parameter",
			&body->grav_param, true))
	{
		body->grav_param = GRAV_CONST * body->mass;
	}

	if (!config_get_double(cfg, fullname, "Radius", &body->radius, false))
		return false;

	/* Figure out what kind of object it is */
	config_get_string(cfg, fullname, "Type", &type, true);
	if (type == NULL)
		body->type = BODY_UNKNOWN;
	else if (strcmp(type, "Star") == 0)
		body->type = BODY_STAR;
	else if (strcmp(type, "Planet") == 0)
		body->type = BODY_PLANET;
	else if (strcmp(type, "Moon") == 0)
		body->type = BODY_PLANET;
	else if (strcmp(type, "Comet") == 0)
		body->type = BODY_COMET;
	else
	{
		log_err("Unknown type: %s\n", type);
		ralloc_free(type);
		return false;
	}
	ralloc_free(type);

	/* Does it have a primary or not? 
	 * Full names are of the form of "Primary/Name"
	 * We search backwards to allow for things like "Sol/Earth/Moon" */
	if ((name = strrchr(fullname, '/')) == NULL)
	{
		/* This is a body without a primary */
		body->name = ralloc_strdup(body->ctx, fullname);
		body->type = (body->type == BODY_UNKNOWN ? BODY_STAR : body->type);
		body->primary = NULL;
		*primary_name = NULL;
	} else if (name == fullname) /* No primary name, eg: sec = "/Earth" */
	{
		log_err("Malformed name: %s", fullname);
		return false;
	} else
	{
		const char *c;
		for (c = name - 1; c >= fullname && *c != '/'; c--);
		c++;

		body->name = ralloc_strdup(body->ctx, name + 1);
		body->type = (body->type == BODY_UNKNOWN ? BODY_PLANET : body->type);
		body->primary = NULL; /* Fill in later */
		*primary_name = ralloc_strndup(body->ctx, c, name - c);
	}

	body->num_satellites = 0;
	body->satellite = NULL;

	/* Bodies without primaries can't orbit another body */
	if (*primary_name == NULL)
		return true;

	if (!config_get_double(cfg, fullname, "Ecc", &body->orbit.Ecc, false) ||
	    !config_get_double(cfg, fullname, "SMa", &body->orbit.SMa, false) ||
	    !config_get_double(cfg, fullname, "Inc", &body->orbit.Inc, false) ||
	    !config_get_double(cfg, fullname, "LAN", &body->orbit.LAN, false) ||
	    !config_get_double(cfg, fullname, "APe", &body->orbit.APe, false) ||
	    !config_get_double(cfg, fullname, "MnA", &body->orbit.MnA, false))
	{
		log_err("Couldn't load orbital elements of %s\n", fullname);
		return false;
	}

	return true;
}
Esempio n. 16
0
OBSAdvAudioCtrl::OBSAdvAudioCtrl(QGridLayout *, obs_source_t *source_)
	: source(source_)
{
	QHBoxLayout *hlayout;
	signal_handler_t *handler = obs_source_get_signal_handler(source);
	const char *sourceName = obs_source_get_name(source);
	float vol = obs_source_get_volume(source);
	uint32_t flags = obs_source_get_flags(source);
	uint32_t mixers = obs_source_get_audio_mixers(source);

	forceMonoContainer             = new QWidget();
	mixerContainer                 = new QWidget();
	balanceContainer               = new QWidget();
	labelL                         = new QLabel();
	labelR                         = new QLabel();
	nameLabel                      = new QLabel();
	volume                         = new QDoubleSpinBox();
	forceMono                      = new QCheckBox();
	balance                        = new BalanceSlider();
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
	monitoringType                 = new QComboBox();
#endif
	syncOffset                     = new QSpinBox();
	mixer1                         = new QCheckBox();
	mixer2                         = new QCheckBox();
	mixer3                         = new QCheckBox();
	mixer4                         = new QCheckBox();
	mixer5                         = new QCheckBox();
	mixer6                         = new QCheckBox();

	volChangedSignal.Connect(handler, "volume", OBSSourceVolumeChanged,
			this);
	syncOffsetSignal.Connect(handler, "audio_sync", OBSSourceSyncChanged,
			this);
	flagsSignal.Connect(handler, "update_flags", OBSSourceFlagsChanged,
			this);
	mixersSignal.Connect(handler, "audio_mixers", OBSSourceMixersChanged,
			this);

	hlayout = new QHBoxLayout();
	hlayout->setContentsMargins(0, 0, 0, 0);
	forceMonoContainer->setLayout(hlayout);
	hlayout = new QHBoxLayout();
	hlayout->setContentsMargins(0, 0, 0, 0);
	mixerContainer->setLayout(hlayout);
	hlayout = new QHBoxLayout();
	hlayout->setContentsMargins(0, 0, 0, 0);
	balanceContainer->setLayout(hlayout);
	balanceContainer->setMinimumWidth(100);

	labelL->setText("L");

	labelR->setText("R");

	nameLabel->setMinimumWidth(170);
	nameLabel->setText(QT_UTF8(sourceName));
	nameLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);

	volume->setMinimum(MIN_DB - 0.1);
	volume->setMaximum(MAX_DB);
	volume->setSingleStep(0.1);
	volume->setDecimals(1);
	volume->setSuffix(" dB");
	volume->setValue(obs_mul_to_db(vol));

	if (volume->value() < MIN_DB)
		volume->setSpecialValueText("-inf dB");

	forceMono->setChecked((flags & OBS_SOURCE_FLAG_FORCE_MONO) != 0);

	forceMonoContainer->layout()->addWidget(forceMono);
	forceMonoContainer->layout()->setAlignment(forceMono,
			Qt::AlignHCenter | Qt::AlignVCenter);

	balance->setOrientation(Qt::Horizontal);
	balance->setMinimum(0);
	balance->setMaximum(100);
	balance->setTickPosition(QSlider::TicksAbove);
	balance->setTickInterval(50);

	OBSBasic *main = reinterpret_cast<OBSBasic*>(App()->GetMainWindow());

	const char *speakers = config_get_string(main->Config(), "Audio",
			"ChannelSetup");

	if (strcmp(speakers, "Mono") == 0)
		balance->setEnabled(false);
	else
		balance->setEnabled(true);

	float bal = obs_source_get_balance_value(source) * 100.0f;
	balance->setValue((int)bal);

	int64_t cur_sync = obs_source_get_sync_offset(source);
	syncOffset->setMinimum(-950);
	syncOffset->setMaximum(20000);
	syncOffset->setValue(int(cur_sync / NSEC_PER_MSEC));

	int idx;
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
	monitoringType->addItem(QTStr("Basic.AdvAudio.Monitoring.None"),
			(int)OBS_MONITORING_TYPE_NONE);
	monitoringType->addItem(QTStr("Basic.AdvAudio.Monitoring.MonitorOnly"),
			(int)OBS_MONITORING_TYPE_MONITOR_ONLY);
	monitoringType->addItem(QTStr("Basic.AdvAudio.Monitoring.Both"),
			(int)OBS_MONITORING_TYPE_MONITOR_AND_OUTPUT);
	int mt = (int)obs_source_get_monitoring_type(source);
	idx = monitoringType->findData(mt);
	monitoringType->setCurrentIndex(idx);
#endif

	mixer1->setText("1");
	mixer1->setChecked(mixers & (1<<0));
	mixer2->setText("2");
	mixer2->setChecked(mixers & (1<<1));
	mixer3->setText("3");
	mixer3->setChecked(mixers & (1<<2));
	mixer4->setText("4");
	mixer4->setChecked(mixers & (1<<3));
	mixer5->setText("5");
	mixer5->setChecked(mixers & (1<<4));
	mixer6->setText("6");
	mixer6->setChecked(mixers & (1<<5));

	speaker_layout sl = obs_source_get_speaker_layout(source);
 
	if (sl == SPEAKERS_STEREO) {
		balanceContainer->layout()->addWidget(labelL);
		balanceContainer->layout()->addWidget(balance);
		balanceContainer->layout()->addWidget(labelR);
		balanceContainer->setMaximumWidth(170);
	}

	mixerContainer->layout()->addWidget(mixer1);
	mixerContainer->layout()->addWidget(mixer2);
	mixerContainer->layout()->addWidget(mixer3);
	mixerContainer->layout()->addWidget(mixer4);
	mixerContainer->layout()->addWidget(mixer5);
	mixerContainer->layout()->addWidget(mixer6);

	QWidget::connect(volume, SIGNAL(valueChanged(double)),
			this, SLOT(volumeChanged(double)));
	QWidget::connect(forceMono, SIGNAL(clicked(bool)),
			this, SLOT(downmixMonoChanged(bool)));
	QWidget::connect(balance, SIGNAL(valueChanged(int)),
			this, SLOT(balanceChanged(int)));
	QWidget::connect(balance, SIGNAL(doubleClicked()),
			this, SLOT(ResetBalance()));
	QWidget::connect(syncOffset, SIGNAL(valueChanged(int)),
			this, SLOT(syncOffsetChanged(int)));
#if defined(_WIN32) || defined(__APPLE__) || HAVE_PULSEAUDIO
	QWidget::connect(monitoringType, SIGNAL(currentIndexChanged(int)),
			this, SLOT(monitoringTypeChanged(int)));
#endif
	QWidget::connect(mixer1, SIGNAL(clicked(bool)),
			this, SLOT(mixer1Changed(bool)));
	QWidget::connect(mixer2, SIGNAL(clicked(bool)),
			this, SLOT(mixer2Changed(bool)));
	QWidget::connect(mixer3, SIGNAL(clicked(bool)),
			this, SLOT(mixer3Changed(bool)));
	QWidget::connect(mixer4, SIGNAL(clicked(bool)),
			this, SLOT(mixer4Changed(bool)));
	QWidget::connect(mixer5, SIGNAL(clicked(bool)),
			this, SLOT(mixer5Changed(bool)));
	QWidget::connect(mixer6, SIGNAL(clicked(bool)),
			this, SLOT(mixer6Changed(bool)));

	setObjectName(sourceName);
}
Esempio n. 17
0
/* reads and parses configuration file */
static int
process_configfile(char *configfile)
{
	debug(RPT_DEBUG, "%s()", __FUNCTION__);

	/* Read server settings*/

	if (config_read_file(configfile) != 0) {
		report(RPT_CRIT, "Could not read config file: %s", configfile);
		return -1;
	}

	if (bind_port == UNSET_INT)
		bind_port = config_get_int("Server", "Port", 0, UNSET_INT);

	if (strcmp(bind_addr, UNSET_STR) == 0)
		strncpy(bind_addr, config_get_string("Server", "Bind", 0, UNSET_STR), sizeof(bind_addr));

	if (strcmp(user, UNSET_STR) == 0)
		strncpy(user, config_get_string("Server", "User", 0, UNSET_STR), sizeof(user));

	if (default_duration == UNSET_INT) {
		default_duration = (config_get_float("Server", "WaitTime", 0, 0) * 1e6 / TIME_UNIT);
		if (default_duration == 0)
			default_duration = UNSET_INT;
		else if (default_duration * TIME_UNIT < 2e6) {
			report(RPT_WARNING, "Waittime should be at least 2 (seconds). Set to 2 seconds.");
			default_duration = 2e6 / TIME_UNIT;
		}
	}

	if (foreground_mode == UNSET_INT) {
		int fg = config_get_bool("Server", "Foreground", 0, UNSET_INT);

		if (fg != UNSET_INT)
			foreground_mode = fg;
	}

	if (rotate_server_screen == UNSET_INT) {
		rotate_server_screen = config_get_tristate("Server", "ServerScreen", 0, "blank", UNSET_INT);
	}

	if (backlight == UNSET_INT) {
		backlight = config_get_tristate("Server", "Backlight", 0, "open", UNSET_INT);
	}

	if (heartbeat == UNSET_INT) {
		heartbeat = config_get_tristate("Server", "Heartbeat", 0, "open", UNSET_INT);
	}

	if (autorotate == UNSET_INT) {
		autorotate = config_get_bool("Server", "AutoRotate", 0, DEFAULT_AUTOROTATE);
	}

	if (titlespeed == UNSET_INT) {
		int speed = config_get_int("Server", "TitleSpeed", 0, DEFAULT_TITLESPEED);

		/* set titlespeed */
		titlespeed = (speed <= TITLESPEED_NO)
			     ? TITLESPEED_NO
			     : min(speed, TITLESPEED_MAX);
	}

	if (report_dest == UNSET_INT) {
		int rs = config_get_bool("Server", "ReportToSyslog", 0, UNSET_INT);

		if (rs != UNSET_INT)
			report_dest = (rs) ? RPT_DEST_SYSLOG : RPT_DEST_STDERR;
	}
	if (report_level == UNSET_INT) {
		report_level = config_get_int("Server", "ReportLevel", 0, UNSET_INT);
	}


	/* Read drivers */

	 /* If drivers have been specified on the command line, then do not
	 * use the driver list from the config file.
	 */
	if (num_drivers == 0) {
		/* loop over all the Driver= directives to read the driver names */
		while (1) {
			const char *s = config_get_string("Server", "Driver", num_drivers, NULL);
			if (s == NULL)
				break;
			if (s[0] != '\0') {
				drivernames[num_drivers] = strdup(s);
				if (drivernames[num_drivers] == NULL) {
					report(RPT_ERR, "alloc error storing driver name: %s", s);
					exit(EXIT_FAILURE);
				}
				num_drivers++;
			}
		}
	}

	return 0;
}
Esempio n. 18
0
struct master *add_master_dialog (struct master *m) {
	GtkWidget *window;
	GtkWidget *main_vbox;
	GtkWidget *table;
	GtkWidget *option_menu;
	GtkWidget *hbox;
	GtkWidget *label;
	GtkWidget *button;
	GtkWidget *hseparator;
	char *typestr;
	enum master_query_type i;
	struct master *master_to_edit;
	char *windowtitle;

	master_name_result = NULL;
	master_addr_result = NULL;
	current_master_query_type = MASTER_NATIVE;

	master_to_edit = NULL;
	master_to_add = NULL;

	for (i=MASTER_NATIVE;i<MASTER_NUM_QUERY_TYPES;i++)
		master_query_type_radios[i]=NULL;

	master_to_edit = m;

	if (master_to_edit) {
		current_master_query_type = master_to_edit->master_type;
		master_type = master_to_edit->type;
	}
	else {
		// Get last game type added (stored in master_okbutton_callback)
		typestr = config_get_string ("/" CONFIG_FILE "/Add Master/game");
		if (typestr) {
			master_type = id2type (typestr);
			g_free (typestr);
		}
		else {
			master_type = QW_SERVER;
		}
	}

	if (master_to_edit) {
		windowtitle=_("Rename Master");
	}
	else {
		windowtitle=_("Add Master");
	}
	window = dialog_create_modal_transient_window(windowtitle, TRUE, FALSE, NULL);
	main_vbox = gtk_vbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (window), main_vbox);

	table = gtk_table_new (2, 2, FALSE);
	gtk_table_set_row_spacings (GTK_TABLE (table), 2);
	gtk_table_set_col_spacings (GTK_TABLE (table), 4);
	gtk_container_set_border_width (GTK_CONTAINER (table), 16);
	gtk_box_pack_start (GTK_BOX (main_vbox), table, FALSE, FALSE, 0);

	/* Master Name (Description) */

	label = gtk_label_new (_("Master Name"));
	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, 
			GTK_FILL, GTK_FILL, 0, 0);
	gtk_widget_show (label);

	hbox = gtk_hbox_new (FALSE, 4);
	gtk_table_attach_defaults (GTK_TABLE (table), hbox, 1, 2, 0, 1);

	master_name_combo = gtk_combo_new ();
	gtk_widget_set_usize (master_name_combo, 200, -1);
	gtk_box_pack_start (GTK_BOX (hbox), master_name_combo, TRUE, TRUE, 0);
	gtk_entry_set_max_length (GTK_ENTRY (GTK_COMBO (master_name_combo)->entry), 256);
	gtk_combo_set_case_sensitive (GTK_COMBO (master_name_combo), TRUE);
	gtk_combo_set_use_arrows_always (GTK_COMBO (master_name_combo), TRUE);
	gtk_combo_disable_activate (GTK_COMBO (master_name_combo));
	gtk_signal_connect(
			GTK_OBJECT (GTK_COMBO (master_name_combo)->entry), "activate",
			GTK_SIGNAL_FUNC (master_okbutton_callback), GTK_OBJECT (window));

	GTK_WIDGET_SET_FLAGS (GTK_COMBO (master_name_combo)->entry, GTK_CAN_FOCUS);
	GTK_WIDGET_UNSET_FLAGS (GTK_COMBO (master_name_combo)->button, GTK_CAN_FOCUS);
	gtk_widget_grab_focus (GTK_COMBO (master_name_combo)->entry);

	gtk_widget_show (master_name_combo);

	if (master_history_name->items)
		combo_set_vals (master_name_combo, master_history_name->items, "");

	if (master_to_edit) {
		gtk_entry_set_text(GTK_ENTRY (GTK_COMBO (master_name_combo)->entry), master_to_edit->name);
	}


	/* Master Type Option Menu */

	option_menu = create_server_type_menu (master_type, create_server_type_menu_filter_configured, GTK_SIGNAL_FUNC(select_master_type_callback));

	gtk_box_pack_start (GTK_BOX (hbox), option_menu, FALSE, FALSE, 0);

	if (master_to_edit) {
		gtk_widget_set_state (option_menu, GTK_STATE_NORMAL);
		gtk_widget_set_sensitive (GTK_WIDGET(option_menu),FALSE);
	}

	gtk_widget_show (option_menu);

	gtk_widget_show (hbox);

	/* Master Address */

	label = gtk_label_new (_("Master Address"));
	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, 
			GTK_FILL, GTK_FILL, 0, 0);
	gtk_widget_show (label);

	master_addr_combo = gtk_combo_new ();
	gtk_table_attach_defaults (GTK_TABLE (table), master_addr_combo, 1, 2, 1, 2);
	gtk_entry_set_max_length (GTK_ENTRY (GTK_COMBO (master_addr_combo)->entry), 4096);
	gtk_combo_set_case_sensitive (GTK_COMBO (master_addr_combo), TRUE);
	gtk_combo_set_use_arrows_always (GTK_COMBO (master_addr_combo), TRUE);
	gtk_combo_disable_activate (GTK_COMBO (master_addr_combo));
	gtk_signal_connect (
			GTK_OBJECT (GTK_COMBO (master_addr_combo)->entry), "activate",
			GTK_SIGNAL_FUNC (master_okbutton_callback), GTK_OBJECT (window));
	gtk_signal_connect (
			GTK_OBJECT (GTK_COMBO (master_addr_combo)->list),
			"selection-changed",
			GTK_SIGNAL_FUNC
			(master_address_from_history_selected_callback),NULL);

	GTK_WIDGET_SET_FLAGS (GTK_COMBO (master_addr_combo)->entry, GTK_CAN_FOCUS);
	GTK_WIDGET_UNSET_FLAGS (GTK_COMBO (master_addr_combo)->button, GTK_CAN_FOCUS);
	// gtk_widget_grab_focus (GTK_COMBO (master_addr_combo)->entry);

	gtk_widget_show (master_addr_combo);

	if (master_history_addr->items)
		combo_set_vals (master_addr_combo, master_history_addr->items, "");

	if (master_to_edit) {
		char* url = master_to_url(master_to_edit);
		gtk_entry_set_text(GTK_ENTRY (GTK_COMBO (master_addr_combo)->entry), url);
		gtk_widget_set_state (master_addr_combo, GTK_STATE_NORMAL);
		gtk_widget_set_sensitive (GTK_WIDGET(master_addr_combo),FALSE);
		g_free(url);
	}

	gtk_widget_show (table);

	/* query type */
	hbox = gtk_hbox_new (TRUE, 8);
	for (i=MASTER_NATIVE;i<MASTER_NUM_QUERY_TYPES;i++) {
		master_query_type_radios[i] =
			gtk_radio_button_new_with_label_from_widget(
					i==MASTER_NATIVE?NULL:GTK_RADIO_BUTTON(master_query_type_radios[MASTER_NATIVE]),
					_(master_designation[i]));
		if (master_to_edit) {
			gtk_widget_set_sensitive (GTK_WIDGET(master_query_type_radios[i]),FALSE);
		}
		gtk_signal_connect(GTK_OBJECT (master_query_type_radios[i]), "toggled",
				GTK_SIGNAL_FUNC (master_type_radio_callback), (gpointer)i);

		gtk_widget_show (master_query_type_radios[i]);
		gtk_box_pack_start (GTK_BOX (hbox),master_query_type_radios[i], FALSE, FALSE, 0);
	}
	if (master_to_edit) {
		master_activate_radio_for_type(current_master_query_type);
	}
	else if (!games[master_type].default_master_port &&
			current_master_query_type == MASTER_NATIVE) {
		gtk_widget_set_state (master_query_type_radios[MASTER_NATIVE], GTK_STATE_NORMAL);
		gtk_widget_set_sensitive
			(GTK_WIDGET(master_query_type_radios[MASTER_NATIVE]),FALSE);
		gtk_toggle_button_set_active
			(GTK_TOGGLE_BUTTON(master_query_type_radios[MASTER_GAMESPY]),TRUE);
	}

	gtk_widget_show (hbox);
	gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);

	/* Separator */

	hseparator = gtk_hseparator_new ();
	gtk_box_pack_start (GTK_BOX (main_vbox), hseparator, FALSE, FALSE, 0);
	gtk_widget_show (hseparator);

	/* Buttons */

	hbox = gtk_hbox_new (FALSE, 8);
	gtk_container_set_border_width (GTK_CONTAINER (hbox), 8);
	gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);

	/* Cancel Button */

	button = gtk_button_new_with_label (_("Cancel"));
	gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
	gtk_widget_set_usize (button, 80, -1);
	gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (window));
	GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
	gtk_widget_show (button);

	/* OK Button */

	button = gtk_button_new_with_label ("OK");
	gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
	gtk_widget_set_usize (button, 80, -1);
	gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC(master_okbutton_callback), window);
	GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
	gtk_widget_grab_default (button);
	gtk_widget_show (button);

	gtk_widget_show (hbox);

	gtk_widget_show (main_vbox);
	gtk_widget_show (window);

	gtk_main ();

	unregister_window (window);

	return master_to_add;
}
void OBSBasic::on_actionRemoveProfile_triggered()
{
	std::string newName;
	std::string newPath;
	ConfigFile config;

	std::string oldDir = config_get_string(App()->GlobalConfig(),
			"Basic", "ProfileDir");
	std::string oldName = config_get_string(App()->GlobalConfig(),
			"Basic", "Profile");

	auto cb = [&](const char *name, const char *filePath)
	{
		if (strcmp(oldName.c_str(), name) != 0) {
			newName = name;
			newPath = filePath;
			return false;
		}

		return true;
	};

	EnumProfiles(cb);

	/* this should never be true due to menu item being grayed out */
	if (newPath.empty())
		return;

	QString text = QTStr("ConfirmRemove.Text");
	text.replace("$1", QT_UTF8(oldName.c_str()));

	QMessageBox::StandardButton button = QMessageBox::question(this,
			QTStr("ConfirmRemove.Title"), text);
	if (button == QMessageBox::No)
		return;

	size_t newPath_len = newPath.size();
	newPath += "/basic.ini";

	if (config.Open(newPath.c_str(), CONFIG_OPEN_ALWAYS) != 0) {
		blog(LOG_ERROR, "ChangeProfile: Failed to load file '%s'",
				newPath.c_str());
		return;
	}

	newPath.resize(newPath_len);

	const char *newDir = strrchr(newPath.c_str(), '/') + 1;

	config_set_string(App()->GlobalConfig(), "Basic", "Profile",
			newName.c_str());
	config_set_string(App()->GlobalConfig(), "Basic", "ProfileDir",
			newDir);

	config.Swap(basicConfig);
	InitBasicConfigDefaults();
	ResetProfileData();
	DeleteProfile(oldName.c_str(), oldDir.c_str());
	RefreshProfiles();
	config_save_safe(App()->GlobalConfig(), "tmp", nullptr);

	blog(LOG_INFO, "Switched to profile '%s' (%s)",
			newName.c_str(), newDir);
	blog(LOG_INFO, "------------------------------------------------");

	UpdateTitleBar();

	if (api) {
		api->on_event(OBS_FRONTEND_EVENT_PROFILE_LIST_CHANGED);
		api->on_event(OBS_FRONTEND_EVENT_PROFILE_CHANGED);
	}
}
Esempio n. 20
0
TEST_F(ConfigTest, config_has_key_in_default_section) {
  config_t *config = config_new(CONFIG_FILE);
  EXPECT_TRUE(config_has_key(config, CONFIG_DEFAULT_SECTION, "first_key"));
  EXPECT_STREQ(config_get_string(config, CONFIG_DEFAULT_SECTION, "first_key", "meow"), "value");
  config_free(config);
}
Esempio n. 21
0
/**
 * OldTime Screen displays current time and date...
 *
 *\verbatim
 *
 * +--------------------+	+--------------------+
 * |## DATE & TIME ####@|	|### TIME: myhost ##@|
 * |       myhost       |	|2005-05-17 11:32:57a|
 * |11:32:75a Wednesday,|	+--------------------+
 * |       May 17, 2005 |
 * +--------------------+
 *
 * Alternate 2-line version without the title bar:
 *
 * +----------------+
 * |   2012-12-27  @|
 * |    15:07:01    |
 * +----------------+
 *
 *\endverbatim
 *
 * \param rep        Time since last screen update
 * \param display    1 if screen is visible or data should be updated
 * \param flags_ptr  Mode flags
 * \return  Always 0
 */
int
clock_screen(int rep, int display, int *flags_ptr)
{
	char now[40];
	char today[40];
	int xoffs;
	static int heartbeat = 0;
	static int showTitle = 1;
	static const char *timeFormat = NULL;
	static const char *dateFormat = NULL;
	time_t thetime;
	struct tm *rtime;

	if ((*flags_ptr & INITIALIZED) == 0) {
		char tmp[257];	/* should be large enough for host name */

		*flags_ptr |= INITIALIZED;

		/* get config values */
		timeFormat = config_get_string("OldTime", "TimeFormat", 0, "%H:%M:%S");
		dateFormat = config_get_string("OldTime", "DateFormat", 0, "%b %d %Y");
		showTitle = config_get_bool("OldTime", "ShowTitle", 0, 1);

		sock_send_string(sock, "screen_add O\n");
		sock_printf(sock, "screen_set O -name {Old Clock Screen: %s}\n", get_hostname());
		if (!showTitle)
			sock_send_string(sock, "screen_set O -heartbeat off\n");
		sock_send_string(sock, "widget_add O one string\n");
		if (lcd_hgt >= 4) {
			sock_send_string(sock, "widget_add O title title\n");
			sock_send_string(sock, "widget_add O two string\n");
			sock_send_string(sock, "widget_add O three string\n");

			sock_printf(sock, "widget_set O title {DATE & TIME}\n");

			sprintf(tmp, "%s", get_hostname());
			xoffs = (lcd_wid > strlen(tmp)) ? (((lcd_wid - strlen(tmp)) / 2) + 1) : 1;
			sock_printf(sock, "widget_set O one %i 2 {%s}\n", xoffs, tmp);
		}
		else {
			if (showTitle) {
				sock_send_string(sock, "widget_add O title title\n");
				sock_printf(sock, "widget_set O title {TIME: %s}\n", get_hostname());
			}
			else {
				sock_send_string(sock, "widget_add O two string\n");
			}
		}
	}

	/* toggle colon display */
	heartbeat ^= 1;

	time(&thetime);
	rtime = localtime(&thetime);

	if (strftime(today, sizeof(today), dateFormat, rtime) == 0)
		*today = '\0';
	if (strftime(now, sizeof(now), timeFormat, rtime) == 0)
		*now = '\0';
	tickTime(now, heartbeat);

	if (lcd_hgt >= 4) {	/* 4-line version of the screen */
		xoffs = (lcd_wid > strlen(today)) ? ((lcd_wid - strlen(today)) / 2) + 1 : 1;
		if (display)
			sock_printf(sock, "widget_set O two %i 3 {%s}\n", xoffs, today);

		xoffs = (lcd_wid > strlen(now)) ? ((lcd_wid - strlen(now)) / 2) + 1 : 1;
		if (display)
			sock_printf(sock, "widget_set O three %i 4 {%s}\n", xoffs, now);
	}
	else {			/* 2-line version of the screen */
		if (showTitle) {
			xoffs = (lcd_wid > (strlen(today) + strlen(now) + 1))
				? ((lcd_wid - ((strlen(today) + strlen(now) + 1))) / 2) + 1 : 1;
			if (display)
				sock_printf(sock, "widget_set O one %i 2 {%s %s}\n", xoffs, today, now);
		}
		else {
			xoffs = (lcd_wid > strlen(today)) ? ((lcd_wid - strlen(today)) / 2) + 1 : 1;
			if (display)
				sock_printf(sock, "widget_set O one %i 1 {%s}\n", xoffs, today);
			xoffs = (lcd_wid > strlen(now)) ? ((lcd_wid - strlen(now)) / 2) + 1 : 1;
			if (display)
				sock_printf(sock, "widget_set O two %i 2 {%s}\n", xoffs, now);
		}
	}

	return 0;
}				/* End clock_screen() */
Esempio n. 22
0
void core_info_get_name(const char *path, char *s, size_t len)
{
   size_t i;
   core_info_t *core_info = NULL;
   core_info_list_t *core_info_list = NULL;
   settings_t *settings = config_get_ptr();
   struct string_list *contents = dir_list_new_special(NULL, DIR_LIST_CORES);

   if (!contents)
      return;

   core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
   if (!core_info_list)
      goto error;

   core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
   if (!core_info)
      goto error;

   core_info_list->list = core_info;
   core_info_list->count = contents->size;

   for (i = 0; i < contents->size; i++)
   {
      char info_path_base[PATH_MAX_LENGTH] = {0};
      char info_path[PATH_MAX_LENGTH]      = {0};

      core_info[i].path = strdup(contents->elems[i].data);

      if (!core_info[i].path)
         break;

      if (strcmp(core_info[i].path, path) != 0)
            continue;

      fill_pathname_base(info_path_base, contents->elems[i].data,
            sizeof(info_path_base));
      path_remove_extension(info_path_base);

#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP))
      char *substr = strrchr(info_path_base, '_');
      if (substr)
         *substr = '\0';
#endif

      strlcat(info_path_base, ".info", sizeof(info_path_base));

      fill_pathname_join(info_path, (*settings->libretro_info_path) ?
            settings->libretro_info_path : settings->libretro_directory,
            info_path_base, sizeof(info_path));

      core_info[i].data = config_file_new(info_path);

      if (core_info[i].data)
         config_get_string(core_info[i].data, "corename",
               &core_info[i].core_name);

      strlcpy(s, core_info[i].core_name, len);
   }

error:
   if (contents)
      dir_list_free(contents);
   contents = NULL;
   core_info_list_free(core_info_list);
}
Esempio n. 23
0
char *
seafile_session_config_get_string (SeafileSession *session,
                                   const char *key)
{
    return (config_get_string (session->config_db, key));
}
Esempio n. 24
0
core_info_list_t *core_info_list_new(void)
{
   size_t i;
   core_info_t *core_info = NULL;
   core_info_list_t *core_info_list = NULL;
   settings_t *settings = config_get_ptr();
   struct string_list *contents = dir_list_new_special(NULL, DIR_LIST_CORES);

   if (!contents)
      return NULL;

   core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
   if (!core_info_list)
      goto error;

   core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
   if (!core_info)
      goto error;

   core_info_list->list = core_info;
   core_info_list->count = contents->size;

   for (i = 0; i < contents->size; i++)
   {
      char info_path_base[PATH_MAX_LENGTH] = {0};
      char info_path[PATH_MAX_LENGTH]      = {0};
      core_info[i].path = strdup(contents->elems[i].data);

      if (!core_info[i].path)
         break;

      fill_pathname_base(info_path_base, contents->elems[i].data,
            sizeof(info_path_base));
      path_remove_extension(info_path_base);

#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP))
      char *substr = strrchr(info_path_base, '_');
      if (substr)
         *substr = '\0';
#endif

      strlcat(info_path_base, ".info", sizeof(info_path_base));

      fill_pathname_join(info_path, (*settings->libretro_info_path) ?
            settings->libretro_info_path : settings->libretro_directory,
            info_path_base, sizeof(info_path));

      core_info[i].data = config_file_new(info_path);

      if (core_info[i].data)
      {
         unsigned count = 0;
         config_get_string(core_info[i].data, "display_name",
               &core_info[i].display_name);
         config_get_string(core_info[i].data, "corename",
               &core_info[i].core_name);
         config_get_string(core_info[i].data, "systemname",
               &core_info[i].systemname);
         config_get_string(core_info[i].data, "manufacturer",
               &core_info[i].system_manufacturer);
         config_get_uint(core_info[i].data, "firmware_count", &count);
         core_info[i].firmware_count = count;
         if (config_get_string(core_info[i].data, "supported_extensions",
                  &core_info[i].supported_extensions) &&
               core_info[i].supported_extensions)
            core_info[i].supported_extensions_list =
               string_split(core_info[i].supported_extensions, "|");

         if (config_get_string(core_info[i].data, "authors",
                  &core_info[i].authors) &&
               core_info[i].authors)
            core_info[i].authors_list =
               string_split(core_info[i].authors, "|");

         if (config_get_string(core_info[i].data, "permissions",
                  &core_info[i].permissions) &&
               core_info[i].permissions)
            core_info[i].permissions_list =
               string_split(core_info[i].permissions, "|");

         if (config_get_string(core_info[i].data, "license",
                  &core_info[i].licenses) &&
               core_info[i].licenses)
            core_info[i].licenses_list =
               string_split(core_info[i].licenses, "|");

         if (config_get_string(core_info[i].data, "categories",
                  &core_info[i].categories) &&
               core_info[i].categories)
            core_info[i].categories_list =
               string_split(core_info[i].categories, "|");

         if (config_get_string(core_info[i].data, "database",
                  &core_info[i].databases) &&
               core_info[i].databases)
            core_info[i].databases_list =
               string_split(core_info[i].databases, "|");

         if (config_get_string(core_info[i].data, "notes",
                  &core_info[i].notes) &&
               core_info[i].notes)
            core_info[i].note_list = string_split(core_info[i].notes, "|");

         config_get_bool(core_info[i].data, "supports_no_game",
               &core_info[i].supports_no_game);
      }

      if (!core_info[i].display_name)
         core_info[i].display_name = strdup(path_basename(core_info[i].path));
   }

   core_info_list_resolve_all_extensions(core_info_list);
   core_info_list_resolve_all_firmware(core_info_list);

   dir_list_free(contents);
   return core_info_list;

error:
   if (contents)
      dir_list_free(contents);
   core_info_list_free(core_info_list);
   return NULL;
}
Esempio n. 25
0
void core_info_get_name(const char *path, char *s, size_t len,
      const char *path_info, const char *dir_cores,
      const char *exts, bool dir_show_hidden_files,
      bool get_display_name)
{
   size_t i;
   const char       *path_basedir   = !string_is_empty(path_info) ?
      path_info : dir_cores;
   struct string_list *contents     = dir_list_new(
         dir_cores, exts, false, dir_show_hidden_files, false, false);
   const char *core_path_basename   = path_basename(path);

   if (!contents)
      return;

   for (i = 0; i < contents->size; i++)
   {
      size_t path_size                = PATH_MAX_LENGTH * sizeof(char);
      char *info_path                 = NULL;
      config_file_t *conf             = NULL;
      char *new_core_name             = NULL;
      const char *current_path        = contents->elems[i].data;

      if (!string_is_equal(path_basename(current_path), core_path_basename))
         continue;

      info_path                       = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
      info_path[0]                    = '\0';

      if (!core_info_list_iterate(info_path,
               path_size, path_basedir, contents, i)
            && path_is_valid(info_path))
      {
         free(info_path);
         continue;
      }

      conf                            = config_file_new(info_path);

      if (!conf)
      {
         free(info_path);
         continue;
      }

      if (config_get_string(conf, get_display_name ? "display_name" : "corename",
            &new_core_name))
      {
         strlcpy(s, new_core_name, len);
         free(new_core_name);
      }

      config_file_free(conf);
      free(info_path);
      break;
   }

   if (contents)
      dir_list_free(contents);
   contents = NULL;
}
Esempio n. 26
0
File: scripts.c Progetto: IR4T4/xqf
void scripts_load() {
	GSList* dir;
	GList* s;
	unsigned i;
	char path[PATH_MAX];

	if (!scriptdata) {
		g_datalist_init(&scriptdata);
	}

	/*
	   g_datalist_get_data(&scriptdata, "foo");
	   g_datalist_set_data_full(&scriptdata,"foo",value,g_free);
	*/

	for (dir = scriptdirs; dir; dir = g_slist_next(dir)) {
		GList* s = dir_to_list(dir->data, script_filter);
		scripts = merge_sorted_string_lists(scripts, s);
	}

	for (s = scripts; s; s = g_list_next(s)) {
		unsigned version;
		config_section_iterator* sit;
		Script* script;
		const char* filename = s->data;
		char* errtitle = _("Script error");

		// already known?
		if (g_datalist_get_data(&scriptdata, filename)) {
			continue;
		}

		script = script_new();

		snprintf(path, sizeof(path), "/scripts/%s/General", filename);
		config_push_prefix(path);

		version = config_get_int("xqf version");
		script->summary = config_get_string("summary");
		script->author = config_get_string("author");
		script->license = config_get_string("license");

		config_pop_prefix();

		if (version > MAX_SCRIPT_VERSION) {
			dialog_ok(errtitle, _("Script %s has version %d, xqf only supports version %d."),
					filename, version, MAX_SCRIPT_VERSION);
			script_free(script);
			continue;
		}

		if (!script->summary) {
			dialog_ok(errtitle, _("Script %s missing summary."), filename);
			script_free(script);
			continue;
		}
		if (!script->author) {
			dialog_ok(errtitle, _("Script %s missing author."), filename);
			script_free(script);
			continue;
		}
		if (!script->license) {
			dialog_ok(errtitle, _("Script %s missing license."), filename);
			script_free(script);
			continue;
		}

		script->name = g_strdup(filename);

		snprintf(path, sizeof(path), "/scripts/%s/Action", filename);
		config_push_prefix(path);

		for (i = 0; i < NUM_ACTIONS; ++i) {
			gboolean on = config_get_bool(action_key[i]);
			if (on) {
				action[i] = g_slist_prepend(action[i], script);
			}
		}

		config_pop_prefix();

		// treat script property 'enabled' as option as it has a widget
		// so it's easier to handle later
		{
			ScriptOption* opt;
			snprintf(path, sizeof(path), "/" CONFIG_FILE "/scripts/%s/enabled=false", filename);

			opt = scriptoption_new("bool");
			opt->enable = config_get_bool(path);
			// Translator: whether this plugin script is enabled
			opt->name = _("Enabled");
			opt->section = g_strdup("enabled");
			script->options = g_slist_prepend(script->options, opt);
		}

		snprintf(path, sizeof(path), "/scripts/%s", filename);
		sit = config_init_section_iterator(path);

		while (sit) {
			char* sname = NULL;

			sit = config_section_iterator_next(sit, &sname);

			if (strlen(sname) > 7 && !strncmp(sname, "option ", 7)) {
				char* typestr;
				char* name;
				ScriptOption* opt;
				char settings_path[PATH_MAX];

				snprintf(settings_path, sizeof(settings_path), "/" CONFIG_FILE "/scripts/%s/%s", filename, sname);

				snprintf(path, sizeof(path), "/scripts/%s/%s", filename, sname);
				config_push_prefix(path);

				typestr = config_get_string("type");
				name = config_get_string("name");

				opt = scriptoption_new(typestr);

				g_free(typestr);

				if (!opt || !name) {
					xqf_warning("script %s: invalid option %s", filename, sname+7);
					goto next;
				}

				opt->name = name;
				opt->section = sname;

				switch(opt->type) {
					case SCRIPT_OPTION_TYPE_LIST:
						{
							config_key_iterator* it;

							it = config_init_iterator(path);

							if (!opt->list) {
								opt->list = g_ptr_array_new();
							}

							while (it) {
								char* key = NULL;
								char* val = NULL;

								it = config_iterator_next(it, &key, &val);

								if (!strncmp(key, "value",5)) {
									g_ptr_array_add(opt->list, val);
								}
								else {
									g_free(val);
								}

								g_free(key);
							}
						}
					// fall through
					case SCRIPT_OPTION_TYPE_STRING:
					case SCRIPT_OPTION_TYPE_INT:
						{
							char* defval = NULL;
							char* curval = NULL;

							defval = config_get_string("default");
							curval = config_get_string(settings_path);

							if (curval) {
								opt->defval = g_strdup(curval);
							}
							else if (defval) {
								opt->defval = g_strdup(defval);
							}

							g_free(defval);
							g_free(curval);
						}
						break;
					case SCRIPT_OPTION_TYPE_BOOL:
						{
							gboolean defval;
							gboolean curval;
							int is_deflt = 0;

							defval = config_get_bool("default=false");
							curval = config_get_bool_with_default(settings_path, &is_deflt);

							if (is_deflt) {
								opt->enable = defval;
							}
							else {
								opt->enable = curval;
							}
						}
						break;

					case SCRIPT_OPTION_TYPE_INVALID:
						xqf_error("unreachable code");
						break;
				}

				script->options = g_slist_prepend(script->options, opt);

next:
				config_pop_prefix();
			}
		}

		script->options = g_slist_reverse(script->options);

		g_datalist_set_data_full(&scriptdata, filename, script, (GDestroyNotify)script_free);

		snprintf(path, sizeof(path), "/scripts/%s", filename);
		config_drop_file(path);
	}
}
Esempio n. 27
0
/**
 * Reads and parses configuration file.
 * \param configfile  The configfile to read or NULL for the default config.
 * \retval 1 if configfile was read,
 * \retval 0 if default configfile doesn't exist
 * \retval <0 on error
 */
static int
process_configfile(char *configfile)
{
	int k;
	const char *tmp;

	debug(RPT_DEBUG, "%s(%s)", __FUNCTION__, (configfile) ? configfile : "<null>");

	/* Read config settings */

	if (configfile == NULL) {
		struct stat statbuf;

		/*
		 * if default config file does not exist, do not consider
		 * this an error and continue
		 */
		if ((lstat(DEFAULT_CONFIGFILE, &statbuf) == -1) && (errno = ENOENT))
			return 0;

		configfile = DEFAULT_CONFIGFILE;
	}

	if (config_read_file(configfile) != 0) {
		report(RPT_CRIT, "Could not read config file: %s", configfile);
		return -1;
	}

	if (server == NULL) {
		server = strdup(config_get_string(progname, "Server", 0, DEFAULT_SERVER));
	}
	if (port == UNSET_INT) {
		port = config_get_int(progname, "Port", 0, LCDPORT);
	}

	if (report_level == UNSET_INT) {
		report_level = config_get_int(progname, "ReportLevel", 0, RPT_WARNING);
	}
	if (report_dest == UNSET_INT) {
		if (config_get_bool(progname, "ReportToSyslog", 0, 0)) {
			report_dest = RPT_DEST_SYSLOG;
		}
		else {
			report_dest = RPT_DEST_STDERR;
		}
	}
	if (foreground != TRUE) {
		foreground = config_get_bool(progname, "Foreground", 0, FALSE);
	}
	if (pidfile == NULL) {
		pidfile = strdup(config_get_string(progname, "PidFile", 0, DEFAULT_PIDFILE));
	}
	if (islow < 0) {
		islow = config_get_int(progname, "Delay", 0, -1);
	}

	if ((tmp = config_get_string(progname, "DisplayName", 0, NULL)) != NULL)
		displayname = strdup(tmp);

	/*
	 * check for config file variables to override all the sequence
	 * defaults
	 */
	for (k = 0; sequence[k].which != 0; k++) {
		if (sequence[k].longname != NULL) {
			sequence[k].on_time = config_get_int(sequence[k].longname, "OnTime", 0, sequence[k].on_time);
			sequence[k].off_time = config_get_int(sequence[k].longname, "OffTime", 0, sequence[k].off_time);
			sequence[k].show_invisible = config_get_bool(sequence[k].longname, "ShowInvisible", 0, sequence[k].show_invisible);
			if (config_get_bool(sequence[k].longname, "Active", 0, sequence[k].flags & ACTIVE))
				sequence[k].flags |= ACTIVE;
			else
				sequence[k].flags &= (~ACTIVE);
		}
	}

	return 1;
}
Esempio n. 28
0
static void
fluidsynth_file_decode(struct decoder *decoder, const char *path_fs)
{
	static const struct audio_format audio_format = {
		.sample_rate = 48000,
		.bits = 16,
		.channels = 2,
	};
	char setting_sample_rate[] = "synth.sample-rate";
	/*
	char setting_verbose[] = "synth.verbose";
	char setting_yes[] = "yes";
	*/
	const char *soundfont_path;
	fluid_settings_t *settings;
	fluid_synth_t *synth;
	fluid_player_t *player;
	char *path_dup;
	int ret;
	Timer *timer;
	enum decoder_command cmd;

	soundfont_path =
		config_get_string("soundfont",
				  "/usr/share/sounds/sf2/FluidR3_GM.sf2");

	/* set up fluid settings */

	settings = new_fluid_settings();
	if (settings == NULL)
		return;

	fluid_settings_setnum(settings, setting_sample_rate, 48000);

	/*
	fluid_settings_setstr(settings, setting_verbose, setting_yes);
	*/

	/* create the fluid synth */

	synth = new_fluid_synth(settings);
	if (synth == NULL) {
		delete_fluid_settings(settings);
		return;
	}

	ret = fluid_synth_sfload(synth, soundfont_path, true);
	if (ret < 0) {
		g_warning("fluid_synth_sfload() failed");
		delete_fluid_synth(synth);
		delete_fluid_settings(settings);
		return;
	}

	/* create the fluid player */

	player = new_fluid_player(synth);
	if (player == NULL) {
		delete_fluid_synth(synth);
		delete_fluid_settings(settings);
		return;
	}

	/* temporarily duplicate the path_fs string, because
	   fluidsynth wants a writable string */
	path_dup = g_strdup(path_fs);
	ret = fluid_player_add(player, path_dup);
	g_free(path_dup);
	if (ret != 0) {
		g_warning("fluid_player_add() failed");
		delete_fluid_player(player);
		delete_fluid_synth(synth);
		delete_fluid_settings(settings);
		return;
	}

	/* start the player */

	ret = fluid_player_play(player);
	if (ret != 0) {
		g_warning("fluid_player_play() failed");
		delete_fluid_player(player);
		delete_fluid_synth(synth);
		delete_fluid_settings(settings);
		return;
	}

	/* set up a timer for synchronization; fluidsynth always
	   decodes in real time, which forces us to synchronize */
	/* XXX is there any way to switch off real-time decoding? */

	timer = timer_new(&audio_format);
	timer_start(timer);

	/* initialization complete - announce the audio format to the
	   MPD core */

	decoder_initialized(decoder, &audio_format, false, -1);

	do {
		int16_t buffer[2048];
		const unsigned max_frames = G_N_ELEMENTS(buffer) / 2;

		/* synchronize with the fluid player */

		timer_add(timer, sizeof(buffer));
		timer_sync(timer);

		/* read samples from fluidsynth and send them to the
		   MPD core */

		ret = fluid_synth_write_s16(synth, max_frames,
					    buffer, 0, 2,
					    buffer, 1, 2);
		/* XXX how do we see whether the player is done?  We
		   can't access the private attribute
		   player->status */
		if (ret != 0)
			break;

		cmd = decoder_data(decoder, NULL, buffer, sizeof(buffer),
				   0, 0, NULL);
	} while (cmd == DECODE_COMMAND_NONE);

	/* clean up */

	timer_free(timer);

	fluid_player_stop(player);
	fluid_player_join(player);

	delete_fluid_player(player);
	delete_fluid_synth(synth);
	delete_fluid_settings(settings);
}

static struct tag *
fluidsynth_tag_dup(const char *file)
{
	struct tag *tag = tag_new();

	/* to be implemented */
	(void)file;

	return tag;
}

static const char *const fluidsynth_suffixes[] = {
	"mid",
	NULL
};

const struct decoder_plugin fluidsynth_decoder_plugin = {
	.name = "fluidsynth",
	.init = fluidsynth_init,
	.file_decode = fluidsynth_file_decode,
	.tag_dup = fluidsynth_tag_dup,
	.suffixes = fluidsynth_suffixes,
};
Esempio n. 29
0
void plugins_init() {
    GString* module_name = NULL;
    GModule* module;

    gchar* audio_output;

    char** search_path;
    gsize search_path_size;
    char** plugins;
    gsize plugins_size;
    void (*plugin_init)();
    void (*plugin_close)();

    int i;

    module_name = g_string_sized_new(80);
    if (!module_name)
        g_error("Can't allocate memory.");

    search_path = config_get_string_list("plugins_search_path", &search_path_size);

    /* Load audio plugin */
    audio_output = config_get_string("audio_output");
    g_string_printf(module_name, "libspop_audio_%s", audio_output);

    module = plugin_open(module_name->str, search_path, search_path_size);
    if (!module)
        g_error("Can't load %s audio plugin: %s", audio_output, g_module_error());

    if (!g_module_symbol(module, "audio_delivery", (void**) &g_audio_delivery_func))
        g_error("Can't find symbol in audio plugin: %s", g_module_error());

    /* Now load other plugins */
    plugins = config_get_string_list("plugins", &plugins_size);
    for (i=0; i < plugins_size; i++) {
        g_strstrip(plugins[i]);
        g_info("Loading plugin %s...", plugins[i]);

        /* Load the module and the symbols (spop_<module>_init and spop_<module>_close) */
        g_string_printf(module_name, "libspop_plugin_%s", plugins[i]);
        module = plugin_open(module_name->str, search_path, search_path_size);
        if (!module) {
            g_warning("Can't load plugin \"%s\": %s", plugins[i], g_module_error());
            continue;
        }

        g_string_printf(module_name, "spop_%s_init", plugins[i]);
        if (!g_module_symbol(module, module_name->str, (void**) &plugin_init)) {
            g_warning("Can't find symbol \"%s\" in module \"%s\": %s", module_name->str, plugins[i], g_module_error());
            continue;
        }

        g_string_printf(module_name, "spop_%s_close", plugins[i]);
        if (g_module_symbol(module, module_name->str, (void**) &plugin_close))
            g_plugins_close_functions = g_list_prepend(g_plugins_close_functions, plugin_close);
        else
            g_info("Module \"%s\" does not have a \"%s\" symbol: %s", plugins[i], module_name->str, g_module_error());

        /* Really init the plugin (hoping it will not blow up) */
        plugin_init();

        g_debug("Plugin %s loaded and initialized", plugins[i]);
    }
    g_string_free(module_name, TRUE);
    g_strfreev(plugins);
    g_strfreev(search_path);
}
Esempio n. 30
0
File: main.c Progetto: harbop/spop
/**********************
 *** Initialization ***
 **********************/
int main(int argc, char** argv) {
    gboolean daemon_mode = TRUE;
    const char* username;
    const char* password;
    GMainLoop* main_loop;

    /* Parse command line options */
    int opt;
    while ((opt = getopt(argc, argv, "dfhv")) != -1) {
        switch (opt) {
        case 'd':
            debug_mode = TRUE;
        case 'v':
            verbose_mode = TRUE;
        case 'f':
            daemon_mode = FALSE; break;
        default:
            printf("Usage: spopd [options]\n"
                   "Options:\n"
                   "  -d        debug mode (implies -f and -v)\n"
                   "  -f        run in foreground (default: fork to background)\n"
                   "  -v        verbose mode (implies -f)\n"
                   "  -h        display this message\n");
            return 0;
        }
    }

    g_set_application_name("spop " SPOP_VERSION);
    g_set_prgname("spop");
    g_type_init();

    printf("%s\n", copyright_notice);

    /* Log handler */
    logging_init();

    if (!daemon_mode) {
        /* Stay in foreground: do everything here */
        if (debug_mode)
            g_info("Running in debug mode");
    }
    else {
        /* Run in daemon mode: fork to background */
        printf("Switching to daemon mode...\n");
        if (daemon(0, 0) != 0)
            g_error("Error while forking process: %s", g_strerror(errno));

    }

    /* Init essential stuff */
    main_loop = g_main_loop_new(NULL, FALSE);
    exit_handler_init();

    /* Read username and password */
    username = config_get_string("spotify_username");
    password = config_get_string("spotify_password");

    /* Init plugins */
    plugins_init();

    /* Init login */
    session_init();
    session_login(username, password);

    /* Init various subsystems */
    interface_init();

    /* Event loop */
    g_main_loop_run(main_loop);

    return 0;
}