Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-window-title.c File Reference
#include <config.h>
#include "ev-window-title.h"
#include "ev-utils.h"
#include <string.h>
#include <gio/gio.h>
#include <glib/gi18n.h>
+ Include dependency graph for ev-window-title.c:

Go to the source code of this file.

Data Structures

struct  BadTitleEntry
 
struct  _EvWindowTitle
 

Macros

#define EV_BACKEND_PS   "PSDocument"
 
#define EV_BACKEND_PDF   "PdfDocument"
 

Functions

static char * get_filename_from_uri (const char *uri)
 
static void ev_window_title_sanitize_title (EvWindowTitle *window_title, char **title)
 
static void ev_window_title_update (EvWindowTitle *window_title)
 
EvWindowTitleev_window_title_new (EvWindow *window)
 
void ev_window_title_set_type (EvWindowTitle *window_title, EvWindowTitleType type)
 
static void document_destroyed_cb (EvWindowTitle *window_title, GObject *document)
 
void ev_window_title_set_document (EvWindowTitle *window_title, EvDocument *document)
 
void ev_window_title_set_uri (EvWindowTitle *window_title, const char *uri)
 
void ev_window_title_free (EvWindowTitle *window_title)
 

Variables

static const BadTitleEntry bad_extensions []
 
static const BadTitleEntry bad_prefixes []
 

Macro Definition Documentation

#define EV_BACKEND_PDF   "PdfDocument"

Definition at line 30 of file ev-window-title.c.

#define EV_BACKEND_PS   "PSDocument"

Definition at line 29 of file ev-window-title.c.

Function Documentation

static void document_destroyed_cb ( EvWindowTitle window_title,
GObject *  document 
)
static

Definition at line 194 of file ev-window-title.c.

196 {
197  window_title->document = NULL;
198  g_clear_pointer (&window_title->doc_title, g_free);
199 }

+ Here is the caller graph for this function:

void ev_window_title_free ( EvWindowTitle window_title)

Definition at line 249 of file ev-window-title.c.

250 {
251  if (window_title->document)
252  g_object_weak_unref (G_OBJECT (window_title->document), (GWeakNotify)document_destroyed_cb, window_title);
253  g_free (window_title->doc_title);
254  g_free (window_title->uri);
255  g_free (window_title);
256 }

+ Here is the caller graph for this function:

EvWindowTitle* ev_window_title_new ( EvWindow window)

Definition at line 172 of file ev-window-title.c.

173 {
174  EvWindowTitle *window_title;
175 
176  window_title = g_new0 (EvWindowTitle, 1);
177  window_title->window = window;
178  window_title->type = EV_WINDOW_TITLE_DOCUMENT;
179 
180  ev_window_title_update (window_title);
181 
182  return window_title;
183 }

+ Here is the caller graph for this function:

static void ev_window_title_sanitize_title ( EvWindowTitle window_title,
char **  title 
)
static

Definition at line 76 of file ev-window-title.c.

76  {
77  const gchar *backend;
78  int i;
79 
80  backend = G_OBJECT_TYPE_NAME (window_title->document);
81 
82  for (i = 0; i < G_N_ELEMENTS (bad_extensions); i++) {
83  if (g_ascii_strcasecmp (bad_extensions[i].backend, backend) == 0 &&
84  g_str_has_suffix (*title, bad_extensions[i].text)) {
85  char *new_title;
86  char *filename = get_filename_from_uri (window_title->uri);
87 
88  new_title = g_strndup (*title, strlen(*title) - strlen(bad_extensions[i].text));
89  g_free (*title);
90  *title = new_title;
91 
92  g_free (filename);
93  }
94  }
95  for (i = 0; i < G_N_ELEMENTS (bad_prefixes); i++) {
96  if (g_ascii_strcasecmp (bad_prefixes[i].backend, backend) == 0 &&
97  g_str_has_prefix (*title, bad_prefixes[i].text)) {
98  char *new_title;
99  int len = strlen(bad_prefixes[i].text);
100 
101  new_title = g_strdup_printf ("%s", (*title) + len);
102  g_free (*title);
103  *title = new_title;
104  }
105  }
106 }

+ Here is the caller graph for this function:

void ev_window_title_set_document ( EvWindowTitle window_title,
EvDocument document 
)

Definition at line 202 of file ev-window-title.c.

204 {
205  if (window_title->document == document)
206  return;
207 
208  if (window_title->document)
209  g_object_weak_unref (G_OBJECT (window_title->document), (GWeakNotify)document_destroyed_cb, window_title);
210  window_title->document = document;
211  g_object_weak_ref (G_OBJECT (window_title->document), (GWeakNotify)document_destroyed_cb, window_title);
212  g_clear_pointer (&window_title->doc_title, g_free);
213 
214  if (window_title->document != NULL) {
215  gchar *doc_title;
216 
217  doc_title = g_strdup (ev_document_get_title (window_title->document));
218 
219  /* Make sure we get a valid title back */
220  if (doc_title != NULL) {
221  doc_title = g_strstrip (doc_title);
222 
223  if (doc_title[0] != '\0' &&
224  g_utf8_validate (doc_title, -1, NULL)) {
225  window_title->doc_title = doc_title;
226  } else {
227  g_free (doc_title);
228  }
229  }
230  }
231 
232  ev_window_title_update (window_title);
233 }

+ Here is the caller graph for this function:

void ev_window_title_set_type ( EvWindowTitle window_title,
EvWindowTitleType  type 
)

Definition at line 186 of file ev-window-title.c.

187 {
188  window_title->type = type;
189 
190  ev_window_title_update (window_title);
191 }

+ Here is the caller graph for this function:

void ev_window_title_set_uri ( EvWindowTitle window_title,
const char *  uri 
)

Definition at line 236 of file ev-window-title.c.

238 {
239  if (g_strcmp0 (uri, window_title->uri) == 0)
240  return;
241 
242  g_free (window_title->uri);
243  window_title->uri = g_strdup (uri);
244 
245  ev_window_title_update (window_title);
246 }

+ Here is the caller graph for this function:

static void ev_window_title_update ( EvWindowTitle window_title)
static

Definition at line 109 of file ev-window-title.c.

110 {
111  GtkWindow *window = GTK_WINDOW (window_title->window);
112  GtkHeaderBar *toolbar = GTK_HEADER_BAR (ev_window_get_toolbar (EV_WINDOW (window)));
113  char *title = NULL, *p;
114  char *subtitle = NULL, *title_header = NULL;
115 
116  if (window_title->type == EV_WINDOW_TITLE_RECENT) {
117  gtk_header_bar_set_subtitle (toolbar, NULL);
118  gtk_window_set_title (window, _("Recent Documents"));
119  return;
120  }
121 
122  if (window_title->doc_title && window_title->uri) {
123  title = g_strdup (window_title->doc_title);
124  ev_window_title_sanitize_title (window_title, &title);
125 
126  subtitle = get_filename_from_uri (window_title->uri);
127 
128  title_header = title;
129  title = g_strdup_printf ("%s — %s", subtitle, title);
130 
131  for (p = title; *p; ++p) {
132  /* an '\n' byte is always ASCII, no need for UTF-8 special casing */
133  if (*p == '\n')
134  *p = ' ';
135  }
136  } else if (window_title->uri) {
137  title = get_filename_from_uri (window_title->uri);
138  } else if (!title) {
139  title = g_strdup (_("Document Viewer"));
140  }
141 
142  switch (window_title->type) {
144  gtk_window_set_title (window, title);
145  if (title_header && subtitle) {
146  gtk_header_bar_set_title (toolbar, title_header);
147  gtk_header_bar_set_subtitle (toolbar, subtitle);
148  }
149  break;
151  gchar *password_title;
152 
153  password_title = g_strdup_printf ("%s — %s", title, _("Password Required"));
154  gtk_window_set_title (window, password_title);
155  g_free (password_title);
156 
157  gtk_header_bar_set_title (toolbar, _("Password Required"));
158  gtk_header_bar_set_subtitle (toolbar, title);
159  }
160  break;
162  g_assert_not_reached ();
163  break;
164  }
165 
166  g_free (title);
167  g_free (subtitle);
168  g_free (title_header);
169 }

+ Here is the caller graph for this function:

static char* get_filename_from_uri ( const char *  uri)
static

Definition at line 61 of file ev-window-title.c.

62 {
63  char *filename;
64  char *basename;
65 
66  filename = g_uri_unescape_string (uri, NULL);
67  basename = g_path_get_basename (filename);
68  g_free(filename);
69 
70  return basename;
71 }

+ Here is the caller graph for this function:

Variable Documentation

const BadTitleEntry bad_extensions[]
static
Initial value:
= {
{ EV_BACKEND_PS, ".dvi" },
{ EV_BACKEND_PDF, ".doc" },
{ EV_BACKEND_PDF, ".dvi" },
{ EV_BACKEND_PDF, ".indd" },
{ EV_BACKEND_PDF, ".rtf" }
}

Definition at line 47 of file ev-window-title.c.

const BadTitleEntry bad_prefixes[]
static
Initial value:
= {
{ EV_BACKEND_PDF, "Microsoft Word - " },
{ EV_BACKEND_PDF, "Microsoft PowerPoint - " }
}

Definition at line 55 of file ev-window-title.c.