]> www.fi.muni.cz Git - evince.git/blobdiff - backend/ev-link.c
Fix for the bug #325067 with more intelligent selection of current link in
[evince.git] / backend / ev-link.c
index 48ffca574352d48da1c4a99fba33d682cb2c8df8..a325c3525788badbe1921341668a8996e2921f89 100644 (file)
@@ -29,7 +29,14 @@ enum {
        PROP_TITLE,
        PROP_TYPE,
        PROP_PAGE,
-       PROP_URI
+       PROP_URI,
+       PROP_LEFT,
+       PROP_TOP,
+       PROP_BOTTOM,
+       PROP_RIGHT,
+       PROP_ZOOM,
+       PROP_FILENAME,
+       PROP_PARAMS
 };
 
 
@@ -45,8 +52,15 @@ struct _EvLinkClass {
 struct _EvLinkPrivate {
        char *title;
        char *uri;
+       char *filename;
+       char *params;
        EvLinkType type;
        int page;
+       double top;
+       double left;
+       double bottom;
+       double right;
+       double zoom;
 };
 
 G_DEFINE_TYPE (EvLink, ev_link, G_TYPE_OBJECT)
@@ -63,7 +77,13 @@ ev_link_type_get_type (void)
                static const GEnumValue values[] = {
                        { EV_LINK_TYPE_TITLE, "EV_LINK_TYPE_TITLE", "title" },
                        { EV_LINK_TYPE_PAGE, "EV_LINK_TYPE_PAGE", "page" },
+                       { EV_LINK_TYPE_PAGE_XYZ, "EV_LINK_TYPE_PAGE_XYZ", "page-xyz" },
+                       { EV_LINK_TYPE_PAGE_FIT, "EV_LINK_TYPE_PAGE_FIT", "page-fit" },
+                       { EV_LINK_TYPE_PAGE_FITH, "EV_LINK_TYPE_PAGE_FITH", "page-fith" },
+                       { EV_LINK_TYPE_PAGE_FITV, "EV_LINK_TYPE_PAGE_FITV", "page-fitv" },
+                       { EV_LINK_TYPE_PAGE_FITR, "EV_LINK_TYPE_PAGE_FITR", "page-fitr" },
                        { EV_LINK_TYPE_EXTERNAL_URI, "EV_LINK_TYPE_EXTERNAL_URI", "external" },
+                       { EV_LINK_TYPE_LAUNCH, "EV_LINK_TYPE_LAUNCH", "launch" },
                        { 0, NULL, NULL }
                 };
 
@@ -81,22 +101,6 @@ ev_link_get_title (EvLink *self)
        return self->priv->title;
 }
 
-void
-ev_link_set_title (EvLink* self, const char *title)
-{
-       g_assert (EV_IS_LINK (self));
-
-       if (self->priv->title != NULL) {
-               g_free (self->priv->title);
-       }
-       if (title)
-               self->priv->title = g_strdup (title);
-       else
-               self->priv->title = NULL;
-
-       g_object_notify (G_OBJECT (self), "title");
-}
-
 const char *
 ev_link_get_uri (EvLink *self)
 {
@@ -105,21 +109,6 @@ ev_link_get_uri (EvLink *self)
        return self->priv->uri;
 }
 
-void
-ev_link_set_uri (EvLink* self, const char *uri)
-{
-       g_assert (EV_IS_LINK (self));
-       g_assert (uri != NULL);
-
-       if (self->priv->uri != NULL) {
-               g_free (self->priv->uri);
-       }
-
-       self->priv->uri = g_strdup (uri);
-
-       g_object_notify (G_OBJECT (self), "uri");
-}
-
 EvLinkType
 ev_link_get_link_type (EvLink *self)
 {
@@ -128,32 +117,68 @@ ev_link_get_link_type (EvLink *self)
        return self->priv->type;
 }
 
-void
-ev_link_set_link_type (EvLink* self, EvLinkType type)
+int
+ev_link_get_page (EvLink *self)
 {
-       g_assert (EV_IS_LINK (self));
+       g_return_val_if_fail (EV_IS_LINK (self), -1);
+       
+       return self->priv->page;
+}
 
-       self->priv->type = type;
+double
+ev_link_get_top (EvLink *self)
+{
+       g_return_val_if_fail (EV_IS_LINK (self), 0);
+       
+       return self->priv->top;
+}
 
-       g_object_notify (G_OBJECT (self), "type");
+double
+ev_link_get_left (EvLink *self)
+{
+       g_return_val_if_fail (EV_IS_LINK (self), 0);
+       
+       return self->priv->left;
 }
 
-int
-ev_link_get_page (EvLink *self)
+double
+ev_link_get_bottom (EvLink *self)
 {
        g_return_val_if_fail (EV_IS_LINK (self), 0);
        
-       return self->priv->page;
+       return self->priv->bottom;
 }
 
-void
-ev_link_set_page (EvLink* self, int page)
+double
+ev_link_get_right (EvLink *self)
+{
+       g_return_val_if_fail (EV_IS_LINK (self), 0);
+       
+       return self->priv->right;
+}
+
+const char *
+ev_link_get_filename (EvLink *link)
 {
-       g_assert (EV_IS_LINK (self));
+       g_return_val_if_fail (EV_IS_LINK (link), NULL);
 
-       self->priv->page = page;
+       return link->priv->filename;
+}
+
+const char *
+ev_link_get_params (EvLink *link)
+{
+       g_return_val_if_fail (EV_IS_LINK (link), NULL);
 
-       g_object_notify (G_OBJECT (self), "page");
+       return link->priv->params;
+}
+
+double
+ev_link_get_zoom (EvLink *self)
+{
+       g_return_val_if_fail (EV_IS_LINK (self), 0);
+       
+       return self->priv->zoom;
 }
 
 static void
@@ -177,6 +202,25 @@ ev_link_get_property (GObject *object, guint prop_id, GValue *value,
        case PROP_PAGE:
                g_value_set_int (value, self->priv->page);
                break;
+       case PROP_TOP:
+               g_value_set_double (value, self->priv->top);
+               break;
+       case PROP_LEFT:
+               g_value_set_double (value, self->priv->left);
+               break;
+       case PROP_BOTTOM:
+               g_value_set_double (value, self->priv->bottom);
+               break;
+       case PROP_RIGHT:
+               g_value_set_double (value, self->priv->left);
+               break;
+       case PROP_ZOOM:
+               g_value_set_double (value, self->priv->zoom);
+               break;
+       case PROP_FILENAME:
+               g_value_set_string (value, self->priv->filename);
+       case PROP_PARAMS:
+               g_value_set_string (value, self->priv->params);
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
                                                   prop_id,
@@ -189,23 +233,45 @@ static void
 ev_link_set_property (GObject *object, guint prop_id, const GValue *value,
                      GParamSpec *param_spec)
 {
-       EvLink *self;
-       
-       self = EV_LINK (object);
+       EvLink *link = EV_LINK (object);
        
        switch (prop_id) {
        case PROP_TITLE:
-               ev_link_set_title (self, g_value_get_string (value));
+               link->priv->title = g_strdup (g_value_get_string (value));      
                break;
        case PROP_URI:
-               ev_link_set_uri (self, g_value_get_string (value));
+               link->priv->uri = g_strdup (g_value_get_string (value));
                break;
        case PROP_TYPE:
-               ev_link_set_link_type (self, g_value_get_enum (value));
+               link->priv->type = g_value_get_enum (value);
                break;
        case PROP_PAGE:
-               ev_link_set_page (self, g_value_get_int (value));
+               link->priv->page = g_value_get_int (value);
+               break;
+       case PROP_TOP:
+               link->priv->top = g_value_get_double (value);
+               break;
+       case PROP_LEFT:
+               link->priv->left = g_value_get_double (value);
+               break;
+       case PROP_BOTTOM:
+               link->priv->bottom = g_value_get_double (value);
                break;
+       case PROP_RIGHT:
+               link->priv->right = g_value_get_double (value);
+               break;
+       case PROP_ZOOM:
+               link->priv->zoom = g_value_get_double (value);
+               break;
+       case PROP_FILENAME:
+               g_free (link->priv->filename);
+               link->priv->filename = g_strdup (g_value_get_string (value));
+               break;
+       case PROP_PARAMS:
+               g_free (link->priv->params);
+               link->priv->params = g_strdup (g_value_get_string (value));
+               break;
+
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object,
                                                   prop_id,
@@ -228,6 +294,21 @@ ev_window_dispose (GObject *object)
                priv->title = NULL;
        }
 
+       if (priv->uri) {
+               g_free (priv->uri);
+               priv->uri = NULL;
+       }
+
+       if (priv->filename) {
+               g_free (priv->filename);
+               priv->filename = NULL;
+       }
+
+       if (priv->params) {
+               g_free (priv->params);
+               priv->params = NULL;
+       }
+
        G_OBJECT_CLASS (ev_link_parent_class)->dispose (object);
 }
 
@@ -235,7 +316,7 @@ static void
 ev_link_init (EvLink *ev_link)
 {
        ev_link->priv = EV_LINK_GET_PRIVATE (ev_link);
-
+       ev_link->priv->page = -1;
        ev_link->priv->type = EV_LINK_TYPE_TITLE;
 }
 
@@ -257,16 +338,32 @@ ev_link_class_init (EvLinkClass *ev_window_class)
                                                              "Link Title",
                                                              "The link title",
                                                              NULL,
-                                                             G_PARAM_READWRITE));
-
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (g_object_class,
                                         PROP_URI,
                                         g_param_spec_string ("uri",
                                                              "Link URI",
                                                              "The link URI",
                                                              NULL,
-                                                             G_PARAM_READWRITE));
-
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (g_object_class,
+                                        PROP_FILENAME,
+                                        g_param_spec_string ("filename",
+                                                             "Filename",
+                                                             "The link filename",
+                                                             NULL,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (g_object_class,
+                                        PROP_PARAMS,
+                                        g_param_spec_string ("params",
+                                                             "Params",
+                                                             "The link params",
+                                                             NULL,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (g_object_class,
                                         PROP_TYPE,
                                         g_param_spec_enum  ("type",
@@ -274,17 +371,69 @@ ev_link_class_init (EvLinkClass *ev_window_class)
                                                             "The link type",
                                                             EV_TYPE_LINK_TYPE,
                                                             EV_LINK_TYPE_TITLE,
-                                                            G_PARAM_READWRITE));
-
+                                                            G_PARAM_READWRITE |
+                                                            G_PARAM_CONSTRUCT_ONLY));
        g_object_class_install_property (g_object_class,
                                         PROP_PAGE,
                                         g_param_spec_int ("page",
                                                           "Link Page",
                                                           "The link page",
-                                                           0,
+                                                           -1,
                                                            G_MAXINT,
                                                            0,
-                                                           G_PARAM_READWRITE));
+                                                           G_PARAM_READWRITE |
+                                                           G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (g_object_class,
+                                        PROP_LEFT,
+                                        g_param_spec_double ("left",
+                                                             "Left coordinate",
+                                                             "The left coordinate",
+                                                             -G_MAXDOUBLE,
+                                                             G_MAXDOUBLE,
+                                                             0,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (g_object_class,
+                                        PROP_TOP,
+                                        g_param_spec_double ("top",
+                                                             "Top coordinate",
+                                                             "The top coordinate",
+                                                             -G_MAXDOUBLE,
+                                                             G_MAXDOUBLE,
+                                                             0,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (g_object_class,
+                                        PROP_BOTTOM,
+                                        g_param_spec_double ("bottom",
+                                                             "Bottom coordinate",
+                                                             "The bottom coordinate",
+                                                             -G_MAXDOUBLE,
+                                                             G_MAXDOUBLE,
+                                                             0,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (g_object_class,
+                                        PROP_RIGHT,
+                                        g_param_spec_double ("right",
+                                                             "Right coordinate",
+                                                             "The right coordinate",
+                                                             -G_MAXDOUBLE,
+                                                             G_MAXDOUBLE,
+                                                             0,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
+
+       g_object_class_install_property (g_object_class,
+                                        PROP_ZOOM,
+                                        g_param_spec_double ("zoom",
+                                                             "Zoom",
+                                                             "Zoom",
+                                                             0,
+                                                             G_MAXDOUBLE,
+                                                             0,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT_ONLY));
 }
 
 EvLink *
@@ -306,6 +455,79 @@ ev_link_new_page (const char *title, int page)
                                      NULL));
 }
 
+EvLink *
+ev_link_new_page_xyz (const char *title,
+                     int         page,
+                     double      left,
+                     double      top,
+                     double      zoom)
+{
+       return EV_LINK (g_object_new (EV_TYPE_LINK,
+                                     "title", title,
+                                     "page", page,
+                                     "type", EV_LINK_TYPE_PAGE_XYZ,
+                                     "left", left,
+                                     "top", top,
+                                     "zoom", zoom,
+                                     NULL));
+}
+
+EvLink *
+ev_link_new_page_fit (const char *title,
+                     int         page)
+{
+       return EV_LINK (g_object_new (EV_TYPE_LINK,
+                                     "title", title,
+                                     "page", page,
+                                     "type", EV_LINK_TYPE_PAGE_FIT,
+                                     NULL));
+}
+
+EvLink *
+ev_link_new_page_fith (const char *title,
+                      int         page,
+                      double      top)
+{
+       return EV_LINK (g_object_new (EV_TYPE_LINK,
+                                     "title", title,
+                                     "page", page,
+                                     "type", EV_LINK_TYPE_PAGE_FITH,
+                                     "top", top,
+                                     NULL));
+}
+
+EvLink *
+ev_link_new_page_fitv (const char *title,
+                      int         page,
+                      double      left)
+{
+       return EV_LINK (g_object_new (EV_TYPE_LINK,
+                                     "title", title,
+                                     "page", page,
+                                     "type", EV_LINK_TYPE_PAGE_FITV,
+                                     "left", left,
+                                     NULL));
+}
+
+EvLink *
+ev_link_new_page_fitr (const char     *title,
+                      int             page,
+                      double          left,
+                      double          bottom,
+                      double          right,
+                      double          top)
+{
+       return EV_LINK (g_object_new (EV_TYPE_LINK,
+                                     "title", title,
+                                     "page", page,
+                                     "type", EV_LINK_TYPE_PAGE_FITR,
+                                     "left", left,
+                                     "bottom", bottom,
+                                     "right", right,
+                                     "top", top,
+                                     NULL));
+}
+
 EvLink *
 ev_link_new_external (const char *title, const char *uri)
 {
@@ -316,7 +538,18 @@ ev_link_new_external (const char *title, const char *uri)
                                      NULL));
 }
 
-
+EvLink *
+ev_link_new_launch (const char *title,
+                   const char *filename,
+                   const char *params)
+{
+       return EV_LINK (g_object_new (EV_TYPE_LINK,
+                                     "title", title,
+                                     "filename", filename,
+                                     "params", params,
+                                     "type", EV_LINK_TYPE_LAUNCH,
+                                     NULL));
+}
 
 static void
 ev_link_mapping_free_foreach (EvLinkMapping *mapping)