gboolean trg_destination_combo_has_text(TrgDestinationCombo * combo)
{
    const gchar *text =
        gtk_entry_get_text(trg_destination_combo_get_entry
                           (TRG_DESTINATION_COMBO(combo)));
    return strlen(text) > 0;
}
static void
gtk_combo_box_entry_active_changed(GtkComboBox * combo_box,
                                   gpointer user_data)
{
    GtkTreeModel *model;
    GtkTreeIter iter;
    gboolean editableEntry = TRUE;

    if (gtk_combo_box_get_active_iter(combo_box, &iter)) {
        GtkEntry *entry =
            trg_destination_combo_get_entry(TRG_DESTINATION_COMBO
                                            (combo_box));

        if (entry) {
            GValue value = { 0, };
            guint type;

            model = gtk_combo_box_get_model(combo_box);

            gtk_tree_model_get_value(model, &iter, DEST_COLUMN_LABEL,
                                     &value);
            gtk_tree_model_get(model, &iter, DEST_COLUMN_TYPE, &type, -1);

            g_object_set_property(G_OBJECT(entry), "text", &value);
            g_value_unset(&value);

            if (type == DEST_LABEL)
                editableEntry = FALSE;
        }
    }
#if GTK_CHECK_VERSION( 3, 0, 0 )
    gtk_editable_set_editable(GTK_EDITABLE
                              (trg_destination_combo_get_entry
                               (TRG_DESTINATION_COMBO(combo_box))),
                              editableEntry);
#else
    gtk_entry_set_editable(trg_destination_combo_get_entry
                           (TRG_DESTINATION_COMBO(combo_box)),
                           editableEntry);
#endif
}
static GObject *trg_torrent_move_dialog_constructor(GType type,
                                                    guint
                                                    n_construct_properties,
                                                    GObjectConstructParam *
                                                    construct_params)
{
    GObject *object = G_OBJECT_CLASS
        (trg_torrent_move_dialog_parent_class)->constructor(type,
                                                            n_construct_properties,
                                                            construct_params);
    TrgTorrentMoveDialogPrivate *priv =
        TRG_TORRENT_MOVE_DIALOG_GET_PRIVATE(object);

    gint count;
    gchar *msg;

    GtkWidget *w, *t;
    guint row = 0;

    t = hig_workarea_create();

    w = priv->location_combo =
        trg_destination_combo_new(priv->client,
                                  TRG_PREFS_KEY_LAST_MOVE_DESTINATION);
    g_signal_connect(trg_destination_combo_get_entry
                     (TRG_DESTINATION_COMBO(w)), "changed",
                     G_CALLBACK(location_changed), object);
    hig_workarea_add_row(t, &row, _("Location:"), w, NULL);

    priv->move_check =
        hig_workarea_add_wide_checkbutton(t, &row, _("Move"), TRUE);

    gtk_window_set_destroy_with_parent(GTK_WINDOW(object), TRUE);

    gtk_dialog_add_button(GTK_DIALOG(object), GTK_STOCK_CLOSE,
                          GTK_RESPONSE_CANCEL);
    priv->move_button =
        gtk_dialog_add_button(GTK_DIALOG(object), _("Move"),
                              GTK_RESPONSE_ACCEPT);

    gtk_widget_set_sensitive(priv->move_button,
                             trg_destination_combo_has_text
                             (TRG_DESTINATION_COMBO
                              (priv->location_combo)));

    gtk_container_set_border_width(GTK_CONTAINER(object), GUI_PAD);

    gtk_dialog_set_default_response(GTK_DIALOG(object),
                                    GTK_RESPONSE_ACCEPT);

    gtk_dialog_set_alternative_button_order(GTK_DIALOG(object),
                                            GTK_RESPONSE_ACCEPT,
                                            GTK_RESPONSE_CANCEL, -1);

    gtk_container_set_border_width(GTK_CONTAINER(t), GUI_PAD);

    gtk_box_pack_start(GTK_BOX
                       (gtk_dialog_get_content_area(GTK_DIALOG(object))),
                       t, TRUE, TRUE, 0);

    count =
        gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection
                                               (GTK_TREE_VIEW
                                                (priv->treeview)));
    priv->ids = build_json_id_array(priv->treeview);

    if (count == 1) {
        JsonObject *json;
        const gchar *name;

        get_torrent_data(trg_client_get_torrent_table(priv->client),
                         trg_mw_get_selected_torrent_id(priv->win), &json,
                         NULL);
        name = torrent_get_name(json);
        msg = g_strdup_printf(_("Move %s"), name);
    } else {
        msg = g_strdup_printf(_("Move %d torrents"), count);
    }

    gtk_window_set_transient_for(GTK_WINDOW(object),
                                 GTK_WINDOW(priv->win));
    gtk_window_set_title(GTK_WINDOW(object), msg);

    g_signal_connect(G_OBJECT(object),
                     "response",
                     G_CALLBACK(trg_torrent_move_response_cb), priv->win);

    return object;
}