Back to index

unity  6.0.0
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes
unity::IconLoader::Impl::IconLoaderTask Struct Reference
Collaboration diagram for unity::IconLoader::Impl::IconLoaderTask:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::shared_ptr
< IconLoaderTask
Ptr

Public Member Functions

 IconLoaderTask (IconLoaderRequestType type_, std::string const &data_, unsigned size_, std::string const &key_, IconLoaderCallback slot_, Handle handle_, Impl *self_)
 ~IconLoaderTask ()
void InvokeSlot ()
bool Process ()
bool ProcessIconNameTask ()
bool ProcessGIconTask ()
bool ProcessURITask ()
void PushSchedulerJob ()

Static Public Member Functions

static gboolean LoaderJobFunc (GIOSchedulerJob *job, GCancellable *canc, gpointer data)
static gboolean LoadIconComplete (gpointer data)

Public Attributes

IconLoaderRequestType type
std::string data
unsigned int size
std::string key
IconLoaderCallback slot
Handle handle
Implimpl
GtkIconInfo * icon_info
glib::Object< GdkPixbuf > result
glib::Error error
std::list< IconLoaderTask::Ptrshadow_tasks

Detailed Description

Definition at line 76 of file IconLoader.cpp.


Member Typedef Documentation

Definition at line 78 of file IconLoader.cpp.


Constructor & Destructor Documentation

unity::IconLoader::Impl::IconLoaderTask::IconLoaderTask ( IconLoaderRequestType  type_,
std::string const &  data_,
unsigned  size_,
std::string const &  key_,
IconLoaderCallback  slot_,
Handle  handle_,
Impl self_ 
) [inline]

Definition at line 92 of file IconLoader.cpp.

      : type(type_), data(data_), size(size_), key(key_)
      , slot(slot_), handle(handle_), impl(self_)
      , icon_info(nullptr)
      {}

Definition at line 104 of file IconLoader.cpp.

    {
      if (icon_info)
        ::gtk_icon_info_free(icon_info);
    }

Member Function Documentation

Definition at line 110 of file IconLoader.cpp.

    {
      slot(data, size, result);

      // notify shadow tasks
      for (auto shadow_task : shadow_tasks)
      {
        shadow_task->slot(shadow_task->data, shadow_task->size, result);
        impl->task_map_.erase(shadow_task->handle);
      }

      shadow_tasks.clear();
    }

Here is the caller graph for this function:

static gboolean unity::IconLoader::Impl::IconLoaderTask::LoaderJobFunc ( GIOSchedulerJob *  job,
GCancellable *  canc,
gpointer  data 
) [inline, static]

Definition at line 247 of file IconLoader.cpp.

    {
      auto task = static_cast<IconLoaderTask*>(data);

      // careful here this is running in non-main thread
      if (task->icon_info)
      {
        task->result = ::gtk_icon_info_load_icon(task->icon_info, &task->error);
      }
      else if (task->type == REQUEST_TYPE_URI)
      {
        glib::Object<GFile> file(::g_file_new_for_uri(task->data.c_str()));
        glib::String contents;
        gsize length = 0;

        if (::g_file_load_contents(file, canc, &contents, &length,
                                 nullptr, &task->error))
        {
          glib::Object<GInputStream> stream(
              ::g_memory_input_stream_new_from_data(contents.Value(), length, nullptr));

          task->result = ::gdk_pixbuf_new_from_stream_at_scale(stream,
                                                               -1,
                                                               task->size,
                                                               TRUE,
                                                               canc,
                                                               &task->error);
          ::g_input_stream_close(stream, canc, nullptr);
        }
      }

      ::g_io_scheduler_job_send_to_mainloop_async (job, LoadIconComplete, task, nullptr);

      return FALSE;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean unity::IconLoader::Impl::IconLoaderTask::LoadIconComplete ( gpointer  data) [inline, static]

Definition at line 284 of file IconLoader.cpp.

    {
      auto task = static_cast<IconLoaderTask*>(data);
      auto impl = task->impl;

      if (GDK_IS_PIXBUF(task->result.RawPtr()))
      {
        impl->cache_[task->key] = task->result;
      }
      else
      {
        if (task->result)
          task->result = nullptr;

        LOG_WARNING(logger) << "Unable to load icon " << task->data
                            << " at size " << task->size << ": " << task->error;
      }

      impl->finished_tasks_.push_back(task);

      if (!impl->coalesce_timeout_)
      {
        // we're using lower priority than the GIOSchedulerJob uses to deliver
        // results to the mainloop
        auto prio = static_cast<glib::Source::Priority>(glib::Source::Priority::DEFAULT_IDLE + 40);
        impl->coalesce_timeout_.reset(new glib::Timeout(40, prio));
        impl->coalesce_timeout_->Run(sigc::mem_fun(impl, &Impl::CoalesceTasksCb));
      }

      return FALSE;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 124 of file IconLoader.cpp.

    {
      // Check the cache again, as previous tasks might have wanted the same
      if (impl->CacheLookup(key, data, size, slot))
        return true;

      LOG_DEBUG(logger) << "Processing  " << data << " at size " << size;

      // Rely on the compiler to tell us if we miss a new type
      switch (type)
      {
        case REQUEST_TYPE_ICON_NAME:
          return ProcessIconNameTask();
        case REQUEST_TYPE_GICON_STRING:
          return ProcessGIconTask();
        case REQUEST_TYPE_URI:
          return ProcessURITask();
      }

      LOG_WARNING(logger) << "Request type " << type
                          << " is not supported (" << data
                          << " " << size << ")";
      result = nullptr;
      InvokeSlot();

      return true;
    }

Here is the call graph for this function:

Definition at line 175 of file IconLoader.cpp.

    {
      glib::Error error;
      glib::Object<GIcon> icon(::g_icon_new_for_string(data.c_str(), &error));

      if (G_IS_FILE_ICON(icon.RawPtr()))
      {
        // [trasfer none]
        GFile* file = ::g_file_icon_get_file(G_FILE_ICON(icon.RawPtr()));
        glib::String uri(::g_file_get_uri(file));

        type = REQUEST_TYPE_URI;
        data = uri.Str();

        return ProcessURITask();
      }
      else if (G_IS_ICON(icon.RawPtr()))
      {
        GtkIconInfo* info = ::gtk_icon_theme_lookup_by_gicon(impl->theme_, icon, size,
                                                             static_cast<GtkIconLookupFlags>(0));
        if (info)
        {
          icon_info = info;
          PushSchedulerJob();

          return false;
        }
        else
        {
          // There is some funkiness in some programs where they install
          // their icon to /usr/share/icons/hicolor/apps/, but they
          // name the Icon= key as `foo.$extension` which breaks loading
          // So we can try and work around that here.

          if (boost::iends_with(data, ".png") ||
              boost::iends_with(data, ".xpm") ||
              boost::iends_with(data, ".gif") ||
              boost::iends_with(data, ".jpg"))
          {
            data = data.substr(0, data.size() - 4);
            return ProcessIconNameTask();
          }
          else
          {
            LOG_WARNING(logger) << "Unable to load icon " << data
                                << " at size " << size;
          }
        }
      }
      else
      {
        LOG_WARNING(logger) << "Unable to load icon " << data
                            << " at size " << size << ": " << error;
      }

      InvokeSlot();
      return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 152 of file IconLoader.cpp.

    {
      GtkIconInfo* info = ::gtk_icon_theme_lookup_icon(impl->theme_, data.c_str(),
                                                       size, static_cast<GtkIconLookupFlags>(0));
      if (info)
      {
        icon_info = info;
        PushSchedulerJob();

        return false;
      }
      else
      {
        LOG_WARNING(logger) << "Unable to load icon " << data
                            << " at size " << size;
      }

      result = nullptr;
      InvokeSlot();

      return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 234 of file IconLoader.cpp.

    {
      PushSchedulerJob();

      return false;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 241 of file IconLoader.cpp.

    {
      ::g_io_scheduler_push_job (LoaderJobFunc, this, nullptr, G_PRIORITY_HIGH_IDLE, nullptr);
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 81 of file IconLoader.cpp.

Definition at line 89 of file IconLoader.cpp.

Definition at line 85 of file IconLoader.cpp.

Definition at line 87 of file IconLoader.cpp.

Definition at line 86 of file IconLoader.cpp.

Definition at line 83 of file IconLoader.cpp.

Definition at line 88 of file IconLoader.cpp.

Definition at line 90 of file IconLoader.cpp.

Definition at line 82 of file IconLoader.cpp.

Definition at line 84 of file IconLoader.cpp.

Definition at line 80 of file IconLoader.cpp.


The documentation for this struct was generated from the following file: