Back to index

bamf  0.2.120
Classes | Defines | Typedefs | Enumerations | Functions
bamf-factory.h File Reference
#include <glib-object.h>
#include <libbamf/bamf-view.h>
#include <libbamf/bamf-application.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _BamfFactory
struct  _BamfFactoryClass

Defines

#define BAMF_TYPE_FACTORY   (bamf_factory_get_type ())
#define BAMF_FACTORY(obj)
#define BAMF_FACTORY_CLASS(klass)
#define BAMF_IS_FACTORY(obj)
#define BAMF_IS_FACTORY_CLASS(klass)
#define BAMF_FACTORY_GET_CLASS(obj)

Typedefs

typedef struct _BamfFactory
typedef struct _BamfFactoryClass
typedef struct _BamfFactoryPrivate

Enumerations

enum  BamfFactoryViewType {
  BAMF_FACTORY_VIEW, BAMF_FACTORY_WINDOW, BAMF_FACTORY_APPLICATION, BAMF_FACTORY_INDICATOR,
  BAMF_FACTORY_NONE
}

Functions

GType bamf_factory_get_type (void) G_GNUC_CONST
BamfView * _bamf_factory_view_for_path (BamfFactory *factory, const char *path)
BamfView * _bamf_factory_view_for_path_type (BamfFactory *factory, const char *path, BamfFactoryViewType type)
BamfView * _bamf_factory_view_for_path_type_str (BamfFactory *factory, const char *path, const char *type)
BamfApplication * _bamf_factory_app_for_file (BamfFactory *factory, const char *path, gboolean create)
BamfFactory * _bamf_factory_get_default (void)

Class Documentation

struct _BamfFactory

Definition at line 66 of file bamf-factory.h.

Class Members
GObject parent
BamfFactoryPrivate * priv
struct _BamfFactoryClass

Definition at line 73 of file bamf-factory.h.

Class Members
GObjectClass parent_class

Define Documentation

#define BAMF_FACTORY (   obj)
Value:
(G_TYPE_CHECK_INSTANCE_CAST ((obj),\
        BAMF_TYPE_FACTORY, BamfFactory))

Definition at line 38 of file bamf-factory.h.

#define BAMF_FACTORY_CLASS (   klass)
Value:
(G_TYPE_CHECK_CLASS_CAST ((klass),\
        BAMF_TYPE_FACTORY, BamfFactoryClass))

Definition at line 41 of file bamf-factory.h.

#define BAMF_FACTORY_GET_CLASS (   obj)
Value:
(G_TYPE_INSTANCE_GET_CLASS ((obj),\
        BAMF_TYPE_FACTORY, BamfFactoryClass))

Definition at line 50 of file bamf-factory.h.

#define BAMF_IS_FACTORY (   obj)
Value:
(G_TYPE_CHECK_INSTANCE_TYPE ((obj),\
        BAMF_TYPE_FACTORY))

Definition at line 44 of file bamf-factory.h.

#define BAMF_IS_FACTORY_CLASS (   klass)
Value:
(G_TYPE_CHECK_CLASS_TYPE ((klass),\
        BAMF_TYPE_FACTORY))

Definition at line 47 of file bamf-factory.h.

Definition at line 36 of file bamf-factory.h.


Typedef Documentation

typedef struct _BamfFactory

Definition at line 53 of file bamf-factory.h.

typedef struct _BamfFactoryClass

Definition at line 54 of file bamf-factory.h.

typedef struct _BamfFactoryPrivate

Definition at line 55 of file bamf-factory.h.


Enumeration Type Documentation

Enumerator:
BAMF_FACTORY_VIEW 
BAMF_FACTORY_WINDOW 
BAMF_FACTORY_APPLICATION 
BAMF_FACTORY_INDICATOR 
BAMF_FACTORY_NONE 

Definition at line 57 of file bamf-factory.h.


Function Documentation

BamfApplication* _bamf_factory_app_for_file ( BamfFactory *  factory,
const char *  path,
gboolean  create 
)

Definition at line 131 of file bamf-factory.c.

{
  BamfApplication *result = NULL, *app;
  GList *l;
  
  /* check if result is available in known local_views */
  for (l = factory->priv->local_views; l; l = l->next)
    {
      if (!BAMF_IS_APPLICATION (l->data))
        continue;

      app = BAMF_APPLICATION (l->data);
      if (g_strcmp0 (bamf_application_get_desktop_file (app), path) == 0)
        {
          result = app;
          break;
        }
    }
  
  /* else create new */
  if (!result && create)
    {
      /* delay registration until match time */
      result = bamf_application_new_favorite (path);
      if (result)
        factory->priv->local_views = g_list_prepend (factory->priv->local_views, result);
    }
  
  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BamfFactory* _bamf_factory_get_default ( void  )

Definition at line 354 of file bamf-factory.c.

{
  
  if (BAMF_IS_FACTORY (factory))
    return factory;
  
  factory = (BamfFactory *) g_object_new (BAMF_TYPE_FACTORY, NULL);
  return factory;
}

Here is the caller graph for this function:

BamfView* _bamf_factory_view_for_path ( BamfFactory *  factory,
const char *  path 
)

Definition at line 193 of file bamf-factory.c.

Here is the call graph for this function:

Here is the caller graph for this function:

BamfView* _bamf_factory_view_for_path_type ( BamfFactory *  factory,
const char *  path,
BamfFactoryViewType  type 
)

Definition at line 209 of file bamf-factory.c.

{
  GHashTable *views;
  BamfView *view;
  GList *l;
  gboolean created = FALSE;

  g_return_val_if_fail (BAMF_IS_FACTORY (factory), NULL);
  
  if (!path || path[0] == '\0')
    return NULL;
  
  views = factory->priv->views;
  view = g_hash_table_lookup (views, path);
  
  if (BAMF_IS_VIEW (view))
    return view;

  if (type == BAMF_FACTORY_NONE)
    {
      view = g_object_new (BAMF_TYPE_VIEW, NULL);
      _bamf_view_set_path (view, path);
      type = compute_factory_type_by_str (bamf_view_get_view_type (view));
      g_object_unref (view);
      view = NULL;
    }

  switch (type)
  {
    case BAMF_FACTORY_VIEW:
      view = g_object_new (BAMF_TYPE_VIEW, NULL);
      break;
    case BAMF_FACTORY_WINDOW:
      view = BAMF_VIEW (bamf_window_new (path));
      break;
    case BAMF_FACTORY_APPLICATION:
      view = BAMF_VIEW (bamf_application_new (path));
      break;
    case BAMF_FACTORY_INDICATOR:
      view = BAMF_VIEW (bamf_indicator_new (path));
      break;
    case BAMF_FACTORY_NONE:
      view = NULL;
  }

  created = TRUE;
  BamfView *matched_view = NULL;

  if (BAMF_IS_APPLICATION (view))
    {
      /* handle case where a favorite exists and this matches it */
      const char *local_desktop_file = bamf_application_get_desktop_file (BAMF_APPLICATION (view));
      GList *local_children = bamf_view_get_children (view);

      for (l = factory->priv->local_views; l; l = l->next)
        {
          if (!BAMF_IS_APPLICATION (l->data))
            continue;

          BamfView *list_view = BAMF_VIEW (l->data);
          BamfApplication *list_app = BAMF_APPLICATION (l->data);

          const char *list_desktop_file = bamf_application_get_desktop_file (list_app);

          /* We try to match applications by desktop files */
          if (local_desktop_file && g_strcmp0 (local_desktop_file, list_desktop_file) == 0)
            {
              matched_view = list_view;
              break;
            }

          /* If the primary search doesn't give out any result, we fallback
           * to children window comparison */
          if (!matched_view)
            {
              GList *list_children, *ll;
              list_children = _bamf_application_get_cached_xids (list_app);

              for (ll = local_children; ll; ll = ll->next)
                {
                  if (!BAMF_IS_WINDOW (ll->data))
                    continue;

                  guint32 local_xid = bamf_window_get_xid (BAMF_WINDOW (ll->data));

                  if (g_list_find (list_children, GUINT_TO_POINTER (local_xid)))
                    {
                      matched_view = list_view;
                      break;
                    }
                }
            }
        }

      g_list_free (local_children);
    }
  else if (BAMF_IS_WINDOW (view))
    {
      guint32 local_xid = bamf_window_get_xid (BAMF_WINDOW (view));

      for (l = factory->priv->local_views; l; l = l->next)
        {
          if (!BAMF_IS_WINDOW (l->data))
            continue;

          BamfView *list_view = BAMF_VIEW (l->data);
          BamfWindow *list_win = BAMF_WINDOW (l->data);

          guint32 list_xid = bamf_window_get_xid (list_win);

          /* We try to match windows by xid */
          if (local_xid != 0 && local_xid == list_xid)
            {
              matched_view = list_view;
              break;
            }
        }
    }

  if (matched_view)
    {
      created = FALSE;
      g_object_unref (view);

      view = matched_view;
      _bamf_view_set_path (view, path);
      g_object_ref_sink (view);
    }

  if (view)
    {
      bamf_factory_register_view (factory, view, path);
      
      if (created)
        {
          factory->priv->local_views = g_list_prepend (factory->priv->local_views, view);
          g_object_ref_sink (view);
        }
    }

  return view;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BamfView* _bamf_factory_view_for_path_type_str ( BamfFactory *  factory,
const char *  path,
const char *  type 
)

Definition at line 199 of file bamf-factory.c.

{
  g_return_val_if_fail (BAMF_IS_FACTORY (factory), NULL);
  BamfFactoryViewType factory_type = compute_factory_type_by_str (type);

  return _bamf_factory_view_for_path_type (factory, path, factory_type);
}

Here is the call graph for this function:

Here is the caller graph for this function:

GType bamf_factory_get_type ( void  )