Exemplo n.º 1
0
/**
 * @brief Inserts a character into a string, at a given position
 * @param string a string. If @a string is NULL, a new string is created
 * @param pos the position where to insert the char
 * @param c the character to insert into the string
 * @return Returns the string
 */
Etk_String *etk_string_insert_char(Etk_String *string, int pos, char c)
{
   int i;

   if (!string)
      return etk_string_insert_char(etk_string_new(NULL), pos, c);
   if (c == '\0')
      return etk_string_truncate(string, pos);

   pos = ETK_CLAMP(pos, 0, string->length);
   if (string->length + 1 > string->allocated_length)
   {
      string->string = realloc(string->string, SIZE_TO_ALLOC(string->length + 1) + 1);
      string->allocated_length = SIZE_TO_ALLOC(string->length + 1);
   }
   for (i = string->length - 1; i >= pos; i--)
      string->string[i + 1] = string->string[i];

   string->string[pos] = c;
   string->length++;
   string->string[string->length] = '\0';

   etk_object_notify(ETK_OBJECT(string), "string");
   return string;
}
Exemplo n.º 2
0
/**
 * @brief Creates a new string and copies the text from @a string
 * @param string the string to copy
 * @return Returns the new copied string
 */
Etk_String *etk_string_copy(const Etk_String *string)
{
   if (!string)
      return etk_string_new(NULL);
   else
      return etk_string_new_sized(string->string, string->allocated_length);
}
Exemplo n.º 3
0
/* Sets the folder displayed in the iconbox */
static void _etk_test_iconbox_folder_set(Etk_Iconbox *iconbox, const char *folder)
{
   Eina_List *files;
   Eina_List *l;
   char *filename;
   char file_path[PATH_MAX];
   Etk_Iconbox_Icon *iicon;

   if (!iconbox)
      return;
   if (!folder && !(folder = getenv("HOME")))
      return;
   if (!(files = ecore_file_ls(folder)))
      return;

   etk_iconbox_clear(iconbox);
   etk_iconbox_append(iconbox, etk_theme_icon_path_get(), "actions/go-up_48", "..");

   /* First, add the folders */
   EINA_LIST_FOREACH(files, l, filename)
   {
      if (filename[0] == '.')
         continue;

      snprintf(file_path, PATH_MAX, "%s/%s", folder, filename);
      if (!ecore_file_is_dir(file_path))
         continue;

      iicon = etk_iconbox_append(iconbox, etk_theme_icon_path_get(), "places/folder_48", filename);
      
      if (!ecore_file_can_read(file_path))
         etk_iconbox_icon_emblem_set_from_stock(iicon, "unreadable");
      else if (!ecore_file_can_write(file_path))
         etk_iconbox_icon_emblem_set_from_stock(iicon, "readonly");
   }

   /* Then the files */
   EINA_LIST_FOREACH(files, l, filename)
   {
      const char *ext;
      char *icon = NULL;
      int i;

      if (filename[0] == '.')
         continue;

      snprintf(file_path, PATH_MAX, "%s/%s", folder, filename);
      if (ecore_file_is_dir(file_path))
         continue;

      if ((ext = strrchr(filename, '.')) && (ext = ext + 1))
      {
         for (i = 0; i < _etk_test_iconbox_num_types; i++)
         {
            if (strcasecmp(ext, _etk_test_iconbox_types[i].extension) == 0)
            {
               icon = _etk_test_iconbox_types[i].icon;
               break;
            }
         }
      }

      iicon = etk_iconbox_append(iconbox, etk_theme_icon_path_get(), icon ? icon : "mimetypes/text-x-generic_48", filename);
      if (!ecore_file_can_read(file_path))
         etk_iconbox_icon_emblem_set_from_stock(iicon, "unreadable");
      else if (!ecore_file_can_write(file_path))
         etk_iconbox_icon_emblem_set_from_stock(iicon, "readonly");
      else if (ecore_file_can_exec(file_path))
         etk_iconbox_icon_emblem_set_from_stock(iicon, "system");
   }

   EINA_LIST_FREE(files, filename)
     free(filename);

   if (!_etk_test_iconbox_current_folder)
      _etk_test_iconbox_current_folder = etk_string_new(NULL);
   etk_string_set(_etk_test_iconbox_current_folder, folder);
   etk_window_title_set(ETK_WINDOW(win), folder);
}