Пример #1
0
static void
on_changed( GtkEntry* entry, gpointer user_data )
{
    GtkEntryCompletion* completion;
    completion = gtk_entry_get_completion( entry );
    update_completion( entry, completion );
    gtk_entry_completion_complete( gtk_entry_get_completion(GTK_ENTRY(entry)) );
    seek_path_delayed( GTK_ENTRY( entry ), 0 );
}
Пример #2
0
static gboolean
xpath_update_completion(XpathExplorer *ttt,
	                   	xmlTreeModel * xmltreemodel,
						GtkEntry * xpath_entry)
{
	GtkListStore * xpath_result;
	GtkEntryCompletion * completion;
	gchar * xpath;

	if(ttt->model == NULL)
		return FALSE;

	xpath = gtk_entry_get_text(GTK_ENTRY(xpath_entry));	
	completion = gtk_entry_get_completion(xpath_entry);

	GString * xpath_full;
	xpath_full = g_string_new("");
	g_string_printf(xpath_full, "%s/*",xpath);

	xpath_result = xml_tree_model_get_xpath_results(ttt->model, xpath_full->str);
	gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(xpath_result));
	
	g_string_free(xpath_full, FALSE);
	
	return TRUE;
}
/**
 * hildon_touch_selector_entry_new_text:
 *
 * Creates a #HildonTouchSelectorEntry with a single text column that
 * can be populated conveniently through hildon_touch_selector_append_text(),
 * hildon_touch_selector_prepend_text(), hildon_touch_selector_insert_text().
 *
 * Returns: A new #HildonTouchSelectorEntry
 *
 * Since: 2.2
 **/
GtkWidget *
hildon_touch_selector_entry_new_text (void)
{
  GtkListStore *model;
  GtkWidget *selector;
  GtkEntryCompletion *completion;
  HildonTouchSelectorEntryPrivate *priv;
  HildonTouchSelectorColumn *column = NULL;

  selector = hildon_touch_selector_entry_new ();

  priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (selector);

  model = gtk_list_store_new (1, G_TYPE_STRING);
  completion = gtk_entry_get_completion (GTK_ENTRY (priv->entry));
  gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (model));
  column = hildon_touch_selector_append_text_column (HILDON_TOUCH_SELECTOR (selector),
                                                     GTK_TREE_MODEL (model), FALSE);
  g_object_unref (model);

  g_signal_connect (column, "notify::text-column", G_CALLBACK (_text_column_modified),
                    selector);
  hildon_touch_selector_entry_set_text_column (HILDON_TOUCH_SELECTOR_ENTRY (selector), 0);

  return selector;
}
Пример #4
0
static void
on_changed( GtkEntry* entry, gpointer user_data )
{
    GtkEntryCompletion* completion;
    completion = gtk_entry_get_completion( entry );
    update_completion( entry, completion );
}
Пример #5
0
void C4PropertyDlg::UpdateInputCtrl(C4Object *pObj) {
  int cnt;
#ifdef WITH_DEVELOPER_MODE

  GtkEntryCompletion *completion = gtk_entry_get_completion(GTK_ENTRY(entry));
  GtkListStore *store;

  // Uncouple list store from completion so that the completion is not
  // notified for every row we are going to insert. This enhances
  // performance significantly.
  if (!completion) {
    completion = gtk_entry_completion_new();
    store = gtk_list_store_new(1, G_TYPE_STRING);

    gtk_entry_completion_set_text_column(completion, 0);
    gtk_entry_set_completion(GTK_ENTRY(entry), completion);
    g_object_unref(G_OBJECT(completion));
  } else {
    store = GTK_LIST_STORE(gtk_entry_completion_get_model(completion));
    g_object_ref(G_OBJECT(store));
    gtk_entry_completion_set_model(completion, NULL);
  }

  GtkTreeIter iter;
  gtk_list_store_clear(store);
#endif  // WITH_DEVELOPER_MODE

  // add global and standard functions
  for (C4AulFunc *pFn = Game.ScriptEngine.GetFirstFunc(); pFn;
       pFn = Game.ScriptEngine.GetNextFunc(pFn))
    if (pFn->GetPublic()) {
      SCopy(pFn->Name, OSTR);
#ifdef WITH_DEVELOPER_MODE
      gtk_list_store_append(store, &iter);
      gtk_list_store_set(store, &iter, 0, OSTR, -1);
#endif
    }
// Add object script functions
  C4AulScriptFunc *pRef;
  // Object script available
  if (pObj && pObj->Def)
    // Scan all functions
    for (cnt = 0; pRef = pObj->Def->Script.GetSFunc(cnt); cnt++)
      // Public functions only
      if (pRef->Access = AA_PUBLIC) {
        // Add function
        SCopy(pRef->Name, OSTR);
#ifdef WITH_DEVELOPER_MODE
        gtk_list_store_append(store, &iter);
        gtk_list_store_set(store, &iter, 0, OSTR, -1);
#endif
      }

#if WITH_DEVELOPER_MODE
  // Reassociate list store with completion
  gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(store));
#endif
}
Пример #6
0
static GtkTreeModel *
gimp_container_entry_get_model (GimpContainerView *view)
{
  GtkEntryCompletion *completion;

  completion = gtk_entry_get_completion (GTK_ENTRY (view));

  if (completion)
    return gtk_entry_completion_get_model (completion);

  return NULL;
}
static void
_text_column_modified (GObject *pspec, GParamSpec *gobject, gpointer data)
{
  HildonTouchSelectorEntry *selector;
  HildonTouchSelectorEntryPrivate *priv;
  GtkEntryCompletion *completion;
  gint text_column = -1;

  g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_ENTRY (data));
  selector = HILDON_TOUCH_SELECTOR_ENTRY (data);

  priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (HILDON_TOUCH_SELECTOR_ENTRY(selector));
  completion = gtk_entry_get_completion (GTK_ENTRY (priv->entry));

  text_column = hildon_touch_selector_entry_get_text_column (selector);

  gtk_entry_completion_set_text_column (completion, text_column);
}
Пример #8
0
void
gnc_cbwe_add_completion (GtkComboBox *cbwe)
{
    GtkEntry *entry;
    GtkEntryCompletion *completion;
    GtkTreeModel *model;

    entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbwe)));
    completion = gtk_entry_get_completion(entry);
    if (completion)
        return;

    /* No completion yet? Set one up. */
    completion = gtk_entry_completion_new();
    model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbwe));
    gtk_entry_completion_set_model(completion, model);
    gtk_entry_completion_set_text_column(completion, 0);
    gtk_entry_completion_set_inline_completion(completion, TRUE);
    gtk_entry_set_completion(entry, completion);
    g_object_unref(completion);
}
Пример #9
0
void
gnc_cbwe_require_list_item (GtkComboBox *cbwe)
{
    GtkEntry *entry;
    GtkEntryCompletion *completion;
    GtkTreeModel *model;
    GtkTreeIter iter;
    gint index, id;

    /* Ensure completion is set up. */
    gnc_cbwe_add_completion(cbwe);

    /* If an item in the combo box isn't already selected, then force
     * select the first item. Take care, the combo box may not have been
     * filled yet.  */
    entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbwe)));
    completion = gtk_entry_get_completion(entry);
    index = gtk_combo_box_get_active(GTK_COMBO_BOX(cbwe));
    if (index == -1)
    {
        model = gtk_entry_completion_get_model(completion);
        if (gtk_tree_model_get_iter_first(model, &iter))
        {
            gtk_combo_box_set_active(GTK_COMBO_BOX(cbwe), 0);
            index = 0;
        }
    }
    g_object_set_data(G_OBJECT(cbwe), LAST_INDEX, GINT_TO_POINTER(index));

    /* Now the signals to make sure the user can't leave the
       widget without a valid match. */
    id = g_signal_connect(cbwe, "changed",
                          G_CALLBACK(gnc_cbwe_changed_cb), cbwe);
    g_signal_connect(completion, "match_selected",
                     G_CALLBACK(gnc_cbwe_match_selected_cb), cbwe);
    g_signal_connect(entry, "focus-out-event",
                     G_CALLBACK(gnc_cbwe_focus_out_cb), cbwe);

    g_object_set_data(G_OBJECT(cbwe), CHANGED_ID, GINT_TO_POINTER(id));
}
static void
hildon_touch_selector_entry_set_model (HildonTouchSelector * selector,
                                       gint column, GtkTreeModel *model)
{
  GtkEntryCompletion *completion;
  HildonTouchSelectorEntryPrivate *priv;
  gint text_column = -1;

  g_return_if_fail (HILDON_IS_TOUCH_SELECTOR_ENTRY (selector));
  g_return_if_fail (column == 0);
  g_return_if_fail (GTK_IS_TREE_MODEL (model));

  HILDON_TOUCH_SELECTOR_CLASS (hildon_touch_selector_entry_parent_class)->set_model (selector, column, model);

  priv = HILDON_TOUCH_SELECTOR_ENTRY_GET_PRIVATE (selector);

  completion = gtk_entry_get_completion (GTK_ENTRY (priv->entry));
  gtk_entry_completion_set_model (completion, model);

  text_column = hildon_touch_selector_entry_get_text_column (HILDON_TOUCH_SELECTOR_ENTRY (selector));

  gtk_entry_completion_set_text_column (completion, text_column);
}
Пример #11
0
static VALUE
entry_get_completion(VALUE self)
{
    return GOBJ2RVAL(gtk_entry_get_completion(_SELF(self)));
}
GtkWidget *
file_open_location_dialog_new (Gimp *gimp)
{
  GimpContext        *context;
  GtkWidget          *dialog;
  GtkWidget          *hbox;
  GtkWidget          *vbox;
  GtkWidget          *image;
  GtkWidget          *label;
  GtkWidget          *entry;
  GtkEntryCompletion *completion;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

  dialog = gimp_dialog_new (_("Open Location"),
                            "gimp-file-open-location",
                            NULL, 0,
                            gimp_standard_help_func,
                            GIMP_HELP_FILE_OPEN_LOCATION,

                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                            GTK_STOCK_OPEN,   GTK_RESPONSE_OK,

                            NULL);

  g_signal_connect (dialog, "response",
                    G_CALLBACK (file_open_location_response),
                    gimp);

  gtk_dialog_set_alternative_button_order (GTK_DIALOG(dialog),
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
                      hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);

  image = gtk_image_new_from_icon_name (GIMP_STOCK_WEB, GTK_ICON_SIZE_BUTTON);
  gtk_box_pack_start (GTK_BOX (vbox), image, FALSE, FALSE, 0);
  gtk_widget_show (image);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
  gtk_widget_show (vbox);

  label = gtk_label_new (_("Enter location (URI):"));
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  /* we don't want the context to affect the entry, so create
   * a scratch one instead of using e.g. the user context
   */
  context = gimp_context_new (gimp, "file-open-location-dialog", NULL);
  entry = gimp_container_entry_new (gimp->documents, context,
                                    GIMP_VIEW_SIZE_SMALL, 0);
  g_object_unref (context);

  completion = gtk_entry_get_completion (GTK_ENTRY (entry));
  gtk_entry_completion_set_match_func (completion,
                                       file_open_location_completion,
                                       NULL, NULL);

  gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
  gtk_widget_set_size_request (entry, 400, -1);
  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
  gtk_widget_show (entry);

  g_object_set_data (G_OBJECT (dialog), "location-entry", entry);

  return dialog;
}
Пример #13
0
 // Really change the completion model (which may be NULL).
 void UseModel(GtkListStore* store)
 {
     GtkEntryCompletion* const c = gtk_entry_get_completion(m_widgetEntry);
     gtk_entry_completion_set_model (c, GTK_TREE_MODEL(store));
     gtk_entry_completion_complete (c);
 }
/* Application property has changed */
static void _interface_tweaks_on_application_changed(InterfaceTweaks *self, MidoriApp *inApplication)
{
	g_return_if_fail(IS_INTERFACE_TWEAKS(self));
	g_return_if_fail(inApplication==NULL || MIDORI_IS_APP(inApplication));

	InterfaceTweaksPrivate				*priv=INTERFACE_TWEAKS(self)->priv;
	GtkNotebook							*notebook;
	MidoriBrowser						*browser;
	GList								*browsers, *browsersIter;
	GList								*tabs, *tabsIter;
	WebKitWebView						*webkitView;
	InterfaceTweaksLocationbarLookup	locationbar;

	/* Release resources on current application object */
	if(priv->application)
	{
		g_signal_handlers_disconnect_by_data(priv->application, self);

		browsers=midori_app_get_browsers(priv->application);
		for(browsersIter=browsers; browsersIter; browsersIter=g_list_next(browsersIter))
		{
			browser=MIDORI_BROWSER(browsersIter->data);
			g_signal_handlers_disconnect_by_data(browser, self);

			tabs=midori_browser_get_tabs(MIDORI_BROWSER(browsersIter->data));
			for(tabsIter=tabs; tabsIter; tabsIter=g_list_next(tabsIter))
			{
				g_signal_handlers_disconnect_by_data(tabsIter->data, self);

				webkitView=WEBKIT_WEB_VIEW(midori_view_get_web_view(MIDORI_VIEW(tabsIter->data)));
				g_signal_handlers_disconnect_by_data(webkitView, self);
			}
			g_list_free(tabs);

			notebook=NULL;
			g_object_get(browser, "notebook", &notebook, NULL);
			if(notebook)
			{
				g_signal_handlers_disconnect_by_data(notebook, self);
				g_object_unref(notebook);
			}

			_interface_tweaks_find_browser_locationbar(browser, &locationbar);
			if(locationbar.widget)
			{
				GtkEntry				*entry=GTK_ENTRY(locationbar.widget);
				GtkEntryCompletion		*completion;
				gulong					hookID;
				guint					keyPressSignalID;

				g_signal_handlers_disconnect_by_data(entry, self);

				completion=gtk_entry_get_completion(GTK_ENTRY(entry));
				if(completion)
				{
					g_signal_handlers_disconnect_by_data(completion, self);
					gtk_entry_set_completion(entry, NULL);
				}

				hookID=GPOINTER_TO_SIZE(g_object_get_data(G_OBJECT(entry), "interface-tweaks-hook-id"));
				if(hookID!=0)
				{
					keyPressSignalID=g_signal_lookup("key-press-event", GTK_TYPE_ENTRY);
					g_signal_remove_emission_hook(keyPressSignalID, hookID);

					hookID=0L;
					g_object_set_data(G_OBJECT(entry), "interface-tweaks-hook-id", GSIZE_TO_POINTER(hookID));
				}
			}
		}
		g_list_free(browsers);

		g_object_unref(priv->application);
		priv->application=NULL;
	}

	/* Set new application object */
	if(!inApplication) return;
	priv->application=g_object_ref(inApplication);

	/* Set up all current open browser windows */
	browsers=midori_app_get_browsers(priv->application);
	for(browsersIter=browsers; browsersIter; browsersIter=g_list_next(browsersIter))
	{
		_interface_tweaks_on_add_browser(self, MIDORI_BROWSER(browsersIter->data), priv->application);
	}
	g_list_free(browsers);

	/* Listen to new browser windows opened */
	g_signal_connect_swapped(priv->application, "add-browser", G_CALLBACK(_interface_tweaks_on_add_browser), self);

	/* Notify about property change */
	g_object_notify_by_pspec(G_OBJECT(self), InterfaceTweaksProperties[PROP_APPLICATION]);
}
Пример #15
0
static gboolean
on_key_press( GtkWidget *entry, GdkEventKey* evt, EntryData* edata )
{    
    int keymod = ( evt->state & ( GDK_SHIFT_MASK | GDK_CONTROL_MASK |
                 GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK ) );
                 
    if( evt->keyval == GDK_KEY_Tab && !keymod )
    {
        gtk_entry_completion_insert_prefix( gtk_entry_get_completion(GTK_ENTRY(entry)) );
        gtk_editable_set_position( (GtkEditable*)entry, -1 );
        return TRUE;
    }
    else if ( ( evt->keyval == GDK_KEY_Up || evt->keyval == GDK_KEY_Down ) && !keymod )
    {
        const char* text = gtk_entry_get_text( GTK_ENTRY( entry ) );
        if ( text[0] != '$' && text[0] != '+' && text[0] != '&' && text[0] != '!' 
                                                            && text[0] != '\0' )
            return FALSE;  // pass non-command arrows to completion
        
        char* line = NULL;
        GList* l;
        if ( evt->keyval == GDK_KEY_Up )
        {
            if ( edata->current )
            {
                if ( text[0] != '\0' && strcmp( edata->current->data, text ) )
                {
                    if ( edata->editing )
                        g_free( edata->editing );
                    edata->editing = g_strdup( text );
                    l = g_list_last( edata->history );
                    line = (char*)l->data;
                    edata->current = l;
                }
                else if ( edata->current->prev )
                {
                    line = (char*)edata->current->prev->data;
                    edata->current = edata->current->prev;
                }
            }
            else if ( edata->history )
            {
                if ( edata->editing && ( text[0] == '\0' || !strcmp( text, "$ " ) ) )
                    line = edata->editing;
                else
                {
                    l = g_list_last( edata->history );
                    line = (char*)l->data;
                    edata->current = l;
                    
                    if ( text[0] != '\0' && strcmp( text, "$ " ) )
                    {
                        if ( edata->editing )
                            g_free( edata->editing );
                        edata->editing = g_strdup( text );
                    }
                }
            }
        }
        else  // GDK_Down
        {
            if ( edata->current && edata->current->next )
            {
                if ( strcmp( edata->current->data, text ) )
                {
                    if ( text[0] != '\0' )
                    {
                        if ( edata->editing )
                            g_free( edata->editing );
                        edata->editing = strdup( text );
                    }
                    line = "$ ";
                    edata->current = NULL;
                }
                else
                {
                    line = (char*)edata->current->next->data;
                    edata->current = edata->current->next;
                }
            }
            else if ( !strcmp( text, "$ " ) || text[0] == '\0' )
            {
                if ( edata->editing && strcmp( text, edata->editing ) )
                    line = edata->editing;
                else
                    line = "$ ";
                edata->current = NULL;
            }
            else
            {
                if ( edata->current && !strcmp( text, edata->current->data ) )
                    line = edata->editing ? edata->editing : "$ ";
                else
                {
                    if ( edata->editing )
                        g_free( edata->editing );
                    edata->editing = strdup( text );
                    line = "$ ";
                }
                edata->current = NULL;
            }
        }
        if ( line )
        {
            gtk_entry_set_text( GTK_ENTRY( entry ), line );
            gtk_editable_set_position( (GtkEditable*)entry, -1 );
        }
        return TRUE;
    }
    else if ( evt->keyval == GDK_KEY_Escape && !keymod )
    {
        const char* text = gtk_entry_get_text( GTK_ENTRY( entry ) );
        if ( text[0] == '$' || text[0] == '+' || text[0] == '&'
                    || text[0] == '!' || text[0] == '\0' || text[0] == ' ' )
        {
            const char* line;
            const char* text = gtk_entry_get_text( GTK_ENTRY( entry ) );
            const char* cwd = ptk_file_browser_get_cwd( edata->browser );
            if ( !strcmp( text, "$ " ) || text[0] == '\0' )
                line = cwd;
            /*
            else if ( !strcmp( text, cwd ) )
            {
                if ( edata->editing && strcmp( text, edata->editing ) )
                    line = edata->editing;
                else
                    line = "$ ";
            }
            */
            else
            {
                if ( edata->editing )
                    g_free( edata->editing );
                edata->editing = strdup( text );
                line = "$ ";
            }
            gtk_entry_set_text( GTK_ENTRY( entry ), line );
            gtk_editable_set_position( (GtkEditable*)entry, -1 );
            edata->current = NULL;
            return TRUE;   
        }
    }
    else if ( evt->keyval == GDK_KEY_BackSpace && keymod == 1 ) // shift
    {
        gtk_entry_set_text( GTK_ENTRY( entry ), "" );
        return TRUE;
    }
    return FALSE;
}
Пример #16
0
/**  The focus left the general search edit widget, so reset the widget to
 *   its last known good value.  If the widget value contained a valid
 *   value then this is a noop.  Otherwise the widget will be reset
 *   to the last user selected value.  This latter state will occur
 *   if the user has typed characters directly into the widget but not
 *   selected a completion.
 *
 *   @param entry The entry widget in which the user is typing.
 *
 *   @param event Unused.
 *
 *   @param gsl A pointer to a general search widget. */
static gboolean
gnc_gsl_focus_out_cb (GtkEntry         *entry,
                      GdkEventFocus    *event,
                      GNCGeneralSearch *gsl)
{
    const gchar	*text;
    GtkEntryCompletion *completion;
    GtkTreeModel *model;
    GtkTreeIter iter;
    gchar *lc_text, *tree_string, *lc_tree_string;
    gboolean match, valid_iter;
    QofObject *qofobject;
    gpointer selected_item = NULL;

    /* Attempt to match the current text to a qofobject. */
    completion = gtk_entry_get_completion(entry);
    model = gtk_entry_completion_get_model(completion);

    /* Return if completion tree is empty */
    valid_iter = gtk_tree_model_get_iter_first(model, &iter);
    if (!valid_iter)
        return FALSE;

    text = gtk_entry_get_text(entry);
    lc_text = g_utf8_strdown(text, -1);

    /* The last, valid selected entry can match the entered text
     * No need to search further in that case */
    if (gsl->selected_item)
    {
        GNCGeneralSearchPrivate *	priv;

        priv = _PRIVATE(gsl);
        tree_string = g_strdup(qof_object_printable(priv->type, gsl->selected_item));
        lc_tree_string = g_utf8_strdown(tree_string, -1);
        match = g_utf8_collate(lc_text, lc_tree_string) == 0;
        g_free(tree_string);
        g_free(lc_tree_string);
        if (match)
            selected_item = gsl->selected_item;
    }

    /* Otherwise, find a match in the completion list */
    while (valid_iter && !selected_item)
    {
        gtk_tree_model_get(model, &iter, GSL_COLUMN_TEXT, &tree_string, -1);
        lc_tree_string = g_utf8_strdown(tree_string, -1);
        match = g_utf8_collate(lc_text, lc_tree_string) == 0;
        g_free(tree_string);
        g_free(lc_tree_string);
        if (match)
        {
            gtk_tree_model_get(model, &iter, GSL_COLUMN_QOFOBJECT, &qofobject, -1);
            selected_item = qofobject;
        }
        else
            valid_iter = gtk_tree_model_iter_next(model, &iter);
    }

    g_free(lc_text);
    gnc_general_search_set_selected (gsl, selected_item);
    return FALSE;
}
static void
cc_date_time_panel_init (CcDateTimePanel *self)
{
  CcDateTimePanelPrivate *priv;
  GtkWidget *widget;
  GError *error;
  GtkTreeModelSort *city_modelsort;
  int ret;
  const char *date_grid_name;
  char *tmp;

  priv = self->priv = DATE_TIME_PANEL_PRIVATE (self);
  g_resources_register (cc_datetime_get_resource ());

  priv->cancellable = g_cancellable_new ();
  error = NULL;
  priv->dtm = timedate1_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                                                G_DBUS_PROXY_FLAGS_NONE,
                                                "org.freedesktop.timedate1",
                                                "/org/freedesktop/timedate1",
                                                priv->cancellable,
                                                &error);
  if (priv->dtm == NULL) {
        g_warning ("could not get proxy for DateTimeMechanism: %s", error->message);
        g_clear_error (&error);
        return;
  }

  priv->builder = gtk_builder_new ();
  ret = gtk_builder_add_from_resource (priv->builder,
                                       "/org/gnome/control-center/datetime/datetime.ui",
                                       &error);

  if (ret == 0)
    {
      g_warning ("Could not load ui: %s", error ? error->message : "No reason");
      if (error)
        g_error_free (error);
      return;
    }

  switch (date_endian_get_default (FALSE)) {
  case DATE_ENDIANESS_BIG:
    date_grid_name = "big";
    break;
  case DATE_ENDIANESS_LITTLE:
    date_grid_name = "little";
    break;
  case DATE_ENDIANESS_MIDDLE:
    date_grid_name = "middle";
    break;
  case DATE_ENDIANESS_YDM:
    date_grid_name = "ydm";
    break;
  default:
    g_assert_not_reached ();
  }

  tmp = g_strdup_printf ("/org/gnome/control-center/datetime/%s.ui", date_grid_name);
  ret = gtk_builder_add_from_resource (priv->builder, tmp, NULL);
  g_free (tmp);

  gtk_box_pack_end (GTK_BOX (W ("time-box")), W ("date_grid"), FALSE, TRUE, 0);

  /* add the lock button */
  priv->permission = polkit_permission_new_sync (DATETIME_PERMISSION, NULL, NULL, NULL);
  if (priv->permission != NULL)
    {
      g_signal_connect (priv->permission, "notify",
                        G_CALLBACK (on_permission_changed), self);
      on_permission_changed (priv->permission, NULL, self);
    }
  else
    {
      g_warning ("Your system does not have the '%s' PolicyKit files installed. Please check your installation",
                 DATETIME_PERMISSION);
    }

  priv->date = g_date_time_new_now_local ();

  /* Top level windows from GtkBuilder that need to be destroyed explicitly */
  priv->toplevels = g_list_append (priv->toplevels, W ("datetime-dialog"));
  priv->toplevels = g_list_append (priv->toplevels, W ("timezone-dialog"));

  setup_timezone_dialog (self);
  setup_datetime_dialog (self);

  setup_listbox (self, W ("listbox1"));
  setup_listbox (self, W ("listbox2"));

  /* set up network time switch */
  bind_switch_to_row (self,
                      W ("network_time_switch"),
                      W ("datetime-button"));
  g_object_bind_property (priv->dtm, "ntp",
                          W ("network_time_switch"), "active",
                          G_BINDING_SYNC_CREATE);
  g_signal_connect (W("network_time_switch"), "notify::active",
                    G_CALLBACK (change_ntp), self);

  gtk_widget_set_visible (W ("auto-datetime-row"), is_ntp_available (self));

  /* Timezone settings */
  bind_switch_to_row (self,
                      W ("auto_timezone_switch"),
                      W ("timezone-button"));

  priv->datetime_settings = g_settings_new (DATETIME_SCHEMA);
  g_settings_bind (priv->datetime_settings, AUTO_TIMEZONE_KEY,
                   W ("auto_timezone_switch"), "active",
                   G_SETTINGS_BIND_DEFAULT);

  /* Clock settings */
  priv->clock_settings = g_settings_new (CLOCK_SCHEMA);

  widget = W ("vbox_datetime");
  gtk_container_add (GTK_CONTAINER (self), widget);

  /* setup the time itself */
  priv->clock_tracker = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL);
  g_signal_connect (priv->clock_tracker, "notify::clock", G_CALLBACK (on_clock_changed), self);

  clock_settings_changed_cb (priv->clock_settings, CLOCK_FORMAT_KEY, self);
  g_signal_connect (priv->clock_settings, "changed::" CLOCK_FORMAT_KEY,
                    G_CALLBACK (clock_settings_changed_cb), self);

  g_signal_connect (W("format_combobox"), "notify::active-id",
                    G_CALLBACK (change_clock_settings), self);

  update_time (self);

  load_regions_model (GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
                                                              "city-liststore")));

  city_modelsort = GTK_TREE_MODEL_SORT (gtk_builder_get_object (priv->builder, "city-modelsort"));
  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (city_modelsort), CITY_COL_CITY_HUMAN_READABLE,
                                        GTK_SORT_ASCENDING);

  /* After the initial setup, so we can be sure that
   * the model is filled up */
  get_initial_timezone (self);

  widget = (GtkWidget*) gtk_builder_get_object (self->priv->builder,
                                                "timezone-searchentry");
  g_signal_connect (gtk_entry_get_completion (GTK_ENTRY (widget)),
                    "match-selected", G_CALLBACK (city_changed_cb), self);

  g_signal_connect (self->priv->map, "location-changed",
                    G_CALLBACK (location_changed_cb), self);

  /* Watch changes of timedated remote service properties */
  g_signal_connect (priv->dtm, "g-properties-changed",
                    G_CALLBACK (on_timedated_properties_changed), self);
  g_signal_connect_swapped (priv->dtm, "notify::can-ntp",
                            G_CALLBACK (on_can_ntp_changed), self);
  g_signal_connect_swapped (priv->dtm, "notify::timezone",
                            G_CALLBACK (on_timezone_changed), self);
  /* We ignore UTC <--> LocalRTC changes at the moment */

  priv->filechooser_settings = g_settings_new (FILECHOOSER_SCHEMA);
}