glade-project-properties.c 52.6 KB
Newer Older
1 2
/*
 * Copyright (C) 2013 Tristan Van Berkom.
3
 *               2020 Juan Pablo Ugarte.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Authors:
 *   Tristan Van Berkom <tvb@gnome.org>
21
 *   Juan Pablo Ugarte <juanpablougarte@gmail.com>
22 23 24 25 26 27 28 29 30 31
 */

#include <config.h>
#include <glib/gi18n-lib.h>

#include "glade-project-properties.h"
#include "glade-project.h"
#include "glade-command.h"
#include "glade-app.h"
#include "glade-utils.h"
32
#include "glade-private.h"
33 34

/* GObjectClass */
35
static void     glade_project_properties_dispose      (GObject                *object);
36 37
static void     glade_project_properties_finalize     (GObject                *object);
static void     glade_project_properties_set_property (GObject                *object,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
38 39 40
                                                       guint                   prop_id,
                                                       const GValue           *value,
                                                       GParamSpec             *pspec);
41 42 43

/* UI Callbacks */
static void     on_template_combo_box_changed         (GtkComboBox            *combo,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
44
                                                       GladeProjectProperties *properties);
45
static void     on_template_checkbutton_toggled       (GtkToggleButton        *togglebutton,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
46
                                                       GladeProjectProperties *properties);
47
static void     resource_default_toggled              (GtkWidget              *widget,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
48
                                                       GladeProjectProperties *properties);
49
static void     resource_relative_toggled             (GtkWidget              *widget,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
50
                                                       GladeProjectProperties *properties);
51
static void     resource_fullpath_toggled             (GtkWidget              *widget,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
52
                                                       GladeProjectProperties *properties);
53 54 55 56 57 58
static void     on_relative_path_entry_insert_text    (GtkEditable            *editable,
                                                       gchar                  *new_text,
                                                       gint                    new_text_length,
                                                       gint                   *position,
                                                       GladeProjectProperties *properties); 
static void     on_relative_path_entry_changed        (GtkEntry               *entry,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
59
                                                       GladeProjectProperties *properties);
60
static void     resource_full_path_set                (GtkFileChooserButton   *button,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
61
                                                       GladeProjectProperties *properties);
62
static void     verify_clicked                        (GtkWidget              *button,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
63
                                                       GladeProjectProperties *properties);
64
static void     on_domain_entry_changed               (GtkWidget              *entry,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
65
                                                       GladeProjectProperties *properties);
66
static void     target_combobox_changed               (GtkWidget              *widget,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
67
                                                       GladeProjectProperties *properties);
68 69
static void     on_glade_project_properties_hide      (GtkWidget              *widget,
                                                       GladeProjectProperties *properties);
70 71 72 73
static void     on_css_filechooser_file_set           (GtkFileChooserButton   *widget,
                                                       GladeProjectProperties *properties);
static void     on_css_checkbutton_toggled            (GtkWidget              *widget,
                                                       GladeProjectProperties *properties);
74 75 76 77 78
static void     on_license_comboboxtext_changed       (GtkComboBox *widget,
                                                       GladeProjectProperties *properties);

static void     on_license_data_changed               (GladeProjectProperties *properties);

79
/* Project callbacks */
80 81 82
static void     project_path_changed                  (GladeProject           *project,
                                                       GParamSpec             *pspec,
                                                       GladeProjectProperties *properties);
83
static void     project_resource_path_changed         (GladeProject           *project,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
84 85
                                                       GParamSpec             *pspec,
                                                       GladeProjectProperties *properties);
86
static void     project_template_changed              (GladeProject           *project,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
87 88
                                                       GParamSpec             *pspec,
                                                       GladeProjectProperties *properties);
89
static void     project_domain_changed                (GladeProject           *project,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
90 91
                                                       GParamSpec             *pspec,
                                                       GladeProjectProperties *properties);
92
static void     project_targets_changed               (GladeProject           *project,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
93
                                                       GladeProjectProperties *properties);
94
static void     project_license_changed               (GladeProject           *project,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
95 96
                                                       GParamSpec             *pspec,
                                                       GladeProjectProperties *properties);
97 98 99
static void     project_css_provider_path_changed     (GladeProject           *project,
                                                       GParamSpec             *pspec,
                                                       GladeProjectProperties *properties);
100

101 102 103 104 105 106 107 108 109
/* Toplevels model */
enum
{
  COLUMN_ICON_NAME,
  COLUMN_NAME,
  COLUMN_ID,
  COLUMN_WIDGET
};

110
typedef struct
111 112
{
  GladeProject *project;
113
  GtkListStore *toplevels;
114

115
  /* Properties */
116 117
  GtkWidget *project_wide_radio;
  GtkWidget *toplevel_contextual_radio;
118
  GtkWidget *toolkit_grid;
119 120 121 122 123 124 125 126 127 128

  GtkWidget *resource_default_radio;
  GtkWidget *resource_relative_radio;
  GtkWidget *resource_fullpath_radio;
  GtkWidget *relative_path_entry;
  GtkWidget *full_path_button;
  GtkWidget *domain_entry;
  GtkWidget *template_combobox;
  GtkWidget *template_checkbutton;

129 130 131
  GtkWidget *css_filechooser;
  GtkWidget *css_checkbutton;
  
132
  GHashTable *target_combos;
133 134 135 136 137 138 139 140 141

  /* License */
  GtkComboBox    *license_comboboxtext;
  GtkTextView    *license_textview;
  GtkEntryBuffer *name_entrybuffer;
  GtkEntryBuffer *description_entrybuffer;
  GtkTextBuffer  *authors_textbuffer;
  GtkTextBuffer  *copyright_textbuffer;
  GtkTextBuffer  *license_textbuffer;
142
  GtkTextBuffer  *warnings_textbuffer;
143
  
144
  gboolean ignore_ui_cb;
145 146 147 148 149 150 151 152
} GladeProjectPropertiesPrivate;


struct _GladeProjectProperties
{
  GtkDialog parent;

  GladeProjectPropertiesPrivate *priv; /* Unused */
153 154 155 156 157 158 159 160
};

enum
{
  PROP_0,
  PROP_PROJECT,
};

161
G_DEFINE_TYPE_WITH_PRIVATE (GladeProjectProperties, glade_project_properties, GTK_TYPE_DIALOG)
162
#define GLADE_PROJECT_PROPERTIES_PRIVATE(o) ((GladeProjectPropertiesPrivate *) glade_project_properties_get_instance_private((GladeProjectProperties*)o))
163 164 165 166 167 168 169

/********************************************************
 *                  Class/Instance Init                 *
 ********************************************************/
static void
glade_project_properties_init (GladeProjectProperties *properties)
{
170
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
171

172
  priv->target_combos = g_hash_table_new_full (g_str_hash, g_str_equal,
173 174 175 176 177 178 179 180 181 182 183 184 185 186
                                               g_free, NULL);

  gtk_widget_init_template (GTK_WIDGET (properties));
}

static void
glade_project_properties_class_init (GladeProjectPropertiesClass *klass)
{
  GObjectClass *gobject_class;
  GtkWidgetClass *widget_class;

  gobject_class = G_OBJECT_CLASS (klass);
  widget_class  = GTK_WIDGET_CLASS (klass);

187
  gobject_class->dispose = glade_project_properties_dispose;
188 189 190 191 192 193
  gobject_class->finalize = glade_project_properties_finalize;
  gobject_class->set_property = glade_project_properties_set_property;

  g_object_class_install_property
    (gobject_class, PROP_PROJECT,
     g_param_spec_object ("project", _("Project"),
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
194 195
                          _("The project this properties dialog was created for"),
                          GLADE_TYPE_PROJECT,
196
                          G_PARAM_WRITABLE));
197 198 199 200 201 202 203

  /* Setup the template GtkBuilder xml for this class
   */
  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/gladeui/glade-project-properties.ui");

  /* Define the relationship of the private entry and the entry defined in the xml
   */
204
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, toplevels);
205 206 207 208 209 210 211 212
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, resource_default_radio);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, resource_relative_radio);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, resource_fullpath_radio);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, relative_path_entry);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, full_path_button);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, domain_entry);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, template_checkbutton);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, template_combobox);
213
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, toolkit_grid);
214 215
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, css_filechooser);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, css_checkbutton);
216

217 218 219 220 221 222 223
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, license_comboboxtext);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, license_textview);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, name_entrybuffer);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, description_entrybuffer);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, authors_textbuffer);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, copyright_textbuffer);
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, license_textbuffer);
224
  gtk_widget_class_bind_template_child_private (widget_class, GladeProjectProperties, warnings_textbuffer);
225 226

  
227 228 229
  /* Declare the callback ports that this widget class exposes, to bind with <signal>
   * connections defined in the GtkBuilder xml
   */
230 231 232 233 234 235 236 237
  gtk_widget_class_bind_template_callback (widget_class, on_template_combo_box_changed);
  gtk_widget_class_bind_template_callback (widget_class, on_template_checkbutton_toggled);
  gtk_widget_class_bind_template_callback (widget_class, resource_default_toggled);
  gtk_widget_class_bind_template_callback (widget_class, resource_relative_toggled);
  gtk_widget_class_bind_template_callback (widget_class, resource_fullpath_toggled);
  gtk_widget_class_bind_template_callback (widget_class, resource_full_path_set);
  gtk_widget_class_bind_template_callback (widget_class, verify_clicked);
  gtk_widget_class_bind_template_callback (widget_class, on_domain_entry_changed);
238 239 240
  gtk_widget_class_bind_template_callback (widget_class, on_relative_path_entry_insert_text);
  gtk_widget_class_bind_template_callback (widget_class, on_relative_path_entry_changed);
  gtk_widget_class_bind_template_callback (widget_class, on_glade_project_properties_hide);  
241 242
  gtk_widget_class_bind_template_callback (widget_class, on_css_filechooser_file_set);
  gtk_widget_class_bind_template_callback (widget_class, on_css_checkbutton_toggled);
243 244
  gtk_widget_class_bind_template_callback (widget_class, on_license_comboboxtext_changed);
  gtk_widget_class_bind_template_callback (widget_class, on_license_data_changed);
245 246 247 248 249
}

/********************************************************
 *                     GObjectClass                     *
 ********************************************************/
250 251 252 253 254 255 256 257 258
static void
glade_project_properties_dispose (GObject *object)
{
  /* Unset project to disconnect callbacks */
  g_object_set (object, "project", NULL, NULL);

  G_OBJECT_CLASS (glade_project_properties_parent_class)->dispose (object);
}

259 260 261 262
static void
glade_project_properties_finalize (GObject *object)
{
  GladeProjectProperties        *properties = GLADE_PROJECT_PROPERTIES (object);
263
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
264

265
  g_hash_table_destroy (priv->target_combos);
266 267 268 269 270

  G_OBJECT_CLASS (glade_project_properties_parent_class)->finalize (object);
}

static void
271 272 273
combobox_populate_from_catalog (GladeProjectProperties *properties,
                                GtkWidget              *combobox,
                                GladeCatalog           *catalog)
274
{
275
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
276
  GladeProject *project = priv->project;
277 278
  gint minor, major, position;
  GList *targets;
279

280 281 282 283 284 285 286 287 288 289 290 291
  glade_project_get_target_version (project,
                                    glade_catalog_get_name (catalog),
                                    &major, &minor);

  for (targets = glade_catalog_get_targets (catalog), position = 0;
       targets; targets = targets->next, position++)
    {
      GladeTargetableVersion *version = targets->data;
      g_autofree gchar *name = g_strdup_printf ("%d.%d",
                                     version->major,
                                     version->minor);

292
      gtk_combo_box_text_insert (GTK_COMBO_BOX_TEXT(combobox), position, name, name);
293 294 295 296 297 298 299 300 301
      if (major == version->major && minor == version->minor)
        gtk_combo_box_set_active (GTK_COMBO_BOX(combobox), position);

      g_signal_connect (G_OBJECT (combobox), "changed",
                        G_CALLBACK (target_combobox_changed), properties);
      g_object_set_data (G_OBJECT (combobox), "catalog",
                         (gchar *) glade_catalog_get_name (catalog));
    }

302
  g_hash_table_insert (priv->target_combos,
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
                       g_strdup (glade_catalog_get_name (catalog)),
                       combobox);
}

static void
target_version_box_fill (GladeProjectProperties *properties)
{
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
  GtkWidget *grid = priv->toolkit_grid;
  GtkWidget *label, *combobox;
  static gint n_columns = 3;
  gint i, j, left;
  GList *list;


  /* Add stuff to the toolkit grid */
  for (list = glade_app_get_catalogs (), i = 0, j = 0; list;
       list = g_list_next (list))
321 322 323 324 325 326 327 328 329
    {
      GladeCatalog *catalog = list->data;

      /* Skip if theres only one option */
      if (g_list_length (glade_catalog_get_targets (catalog)) <= 1)
        continue;

      /* Special case to mark GTK+ in upper case */
      if (strcmp (glade_catalog_get_name (catalog), "gtk+") == 0)
330
        label = gtk_label_new ("GTK");
331 332 333
      else
        label = gtk_label_new (glade_catalog_get_name (catalog));

334 335 336
      left = (i % n_columns) * 2;
      gtk_widget_set_halign (label, GTK_ALIGN_START);
      gtk_grid_attach (GTK_GRID (grid), label, left, j, 1, 1);
337 338
      gtk_widget_show (label);

339 340 341 342 343
      combobox = gtk_combo_box_text_new ();
      gtk_widget_set_margin_end (combobox, 8);
      combobox_populate_from_catalog (properties, combobox, catalog);
      gtk_grid_attach (GTK_GRID (grid), combobox, left + 1, j, 1, 1);
      gtk_widget_show (combobox);
344

345 346 347
      i++;
      if (i % n_columns == 0)
        j++;
348 349 350 351 352 353
    }
}

static void
update_prefs_for_resource_path (GladeProjectProperties *properties)
{
354
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
355 356 357
  const gchar *resource_path;

  resource_path = glade_project_get_resource_path (priv->project);
358
  
359 360 361 362
  if (resource_path == NULL)
    {
      gtk_entry_set_text (GTK_ENTRY (priv->relative_path_entry), "");
      gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (priv->full_path_button));
363

364 365 366 367 368 369
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->resource_default_radio), TRUE);
      gtk_widget_set_sensitive (priv->full_path_button, FALSE);
      gtk_widget_set_sensitive (priv->relative_path_entry, FALSE);
    }
  else if (g_path_is_absolute (resource_path) &&
           g_file_test (resource_path, G_FILE_TEST_IS_DIR))
370
    {
371 372 373 374
      gtk_entry_set_text (GTK_ENTRY (priv->relative_path_entry), "");
      gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (priv->full_path_button),
                                        resource_path);

375 376
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->resource_fullpath_radio), TRUE);
      gtk_widget_set_sensitive (priv->full_path_button, TRUE);
377
      gtk_widget_set_sensitive (priv->relative_path_entry, FALSE);
378 379 380
    }
  else
    {
381 382 383 384 385
      if (g_strcmp0 (resource_path, gtk_entry_get_text (GTK_ENTRY (priv->relative_path_entry))))
        gtk_entry_set_text (GTK_ENTRY (priv->relative_path_entry), resource_path);

      gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (priv->full_path_button));

386 387
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->resource_relative_radio), TRUE);
      gtk_widget_set_sensitive (priv->relative_path_entry, TRUE);
388
      gtk_widget_set_sensitive (priv->full_path_button, FALSE);
389 390 391
    }
}

392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
static void
on_project_add_widget (GladeProject *project,
                       GladeWidget *widget,
                       GladeProjectProperties *properties)
{
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE (properties);
  GladeWidgetAdaptor *adaptor;
  const gchar *name;
  GtkTreeIter iter;

  if (glade_widget_get_parent (widget))
    return;

  adaptor = glade_widget_get_adaptor (widget);
  name = glade_widget_get_name (widget);

  gtk_list_store_append (priv->toplevels, &iter);
  gtk_list_store_set (priv->toplevels, &iter,
                      COLUMN_ICON_NAME,
                      glade_widget_adaptor_get_icon_name (adaptor),
                      COLUMN_NAME,
                      g_str_has_prefix (name, "__glade_unnamed") ?
                        glade_widget_adaptor_get_name (adaptor) : name,
                      COLUMN_ID,
                      name,
                      COLUMN_WIDGET,
                      widget,
                      -1);
}

static gboolean
get_iter_by_widget (GtkTreeModel *model, GladeWidget *widget, GtkTreeIter *iter)
{
  gboolean valid = gtk_tree_model_get_iter_first (model, iter);

  while (valid)
    {
      GladeWidget *gwidget;

      gtk_tree_model_get (model, iter, COLUMN_WIDGET, &gwidget, -1);
      g_object_unref (gwidget);

      if (widget == gwidget)
        return TRUE;

      valid = gtk_tree_model_iter_next (model, iter);
   }

  return FALSE;
}

static void
on_project_remove_widget (GladeProject *project,
                          GladeWidget *widget,
                          GladeProjectProperties *properties)
{
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE (properties);
  GtkTreeIter iter;

  if (glade_widget_get_parent (widget))
    return;

  if (get_iter_by_widget (GTK_TREE_MODEL (priv->toplevels), widget, &iter))
    gtk_list_store_remove (priv->toplevels, &iter);
}

static void
on_project_widget_name_change (GladeProject *project,
                               GladeWidget *widget,
                               GladeProjectProperties *properties)
{
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE (properties);
  GtkTreeIter iter;

  if (glade_widget_get_parent (widget))
    return;

  if (get_iter_by_widget (GTK_TREE_MODEL (priv->toplevels), widget, &iter))
    {
      GladeWidgetAdaptor *adaptor = glade_widget_get_adaptor (widget);
      const gchar *name = glade_widget_get_name (widget);

      gtk_list_store_set (priv->toplevels, &iter,
                          COLUMN_NAME,
                          g_str_has_prefix (name, "__glade_unnamed") ?
                            glade_widget_adaptor_get_name (adaptor) : name,
                          COLUMN_ID,
                          name,
                          -1);
    }
}

484 485
static void
glade_project_properties_set_project (GladeProjectProperties *properties,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
486
                                      GladeProject           *project)
487
{
488
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
489

490 491 492 493
#define PROJECT_DISCONNECT(func) g_signal_handlers_disconnect_by_func (priv->project, G_CALLBACK (func), properties)

  if (priv->project)
    {
494
      PROJECT_DISCONNECT (project_path_changed);
495 496 497 498 499 500 501 502 503 504 505
      PROJECT_DISCONNECT (project_resource_path_changed);
      PROJECT_DISCONNECT (project_template_changed);
      PROJECT_DISCONNECT (project_domain_changed);
      PROJECT_DISCONNECT (project_css_provider_path_changed);
      PROJECT_DISCONNECT (project_targets_changed);
      PROJECT_DISCONNECT (project_license_changed);
      PROJECT_DISCONNECT (on_project_add_widget);
      PROJECT_DISCONNECT (on_project_remove_widget);
      PROJECT_DISCONNECT (on_project_widget_name_change);
    }

506 507 508
  /* No strong reference, we belong to the project */
  priv->project = project;

509 510 511
  if (!priv->project)
    return;

512 513
  g_signal_connect (priv->project, "notify::path",
                    G_CALLBACK (project_path_changed), properties);
514
  g_signal_connect (priv->project, "notify::resource-path",
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
515
                    G_CALLBACK (project_resource_path_changed), properties);
516
  g_signal_connect (priv->project, "notify::template",
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
517
                    G_CALLBACK (project_template_changed), properties);
518
  g_signal_connect (priv->project, "notify::translation-domain",
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
519
                    G_CALLBACK (project_domain_changed), properties);
520
  g_signal_connect (priv->project, "notify::css-provider-path",
521
                    G_CALLBACK (project_css_provider_path_changed), properties);
522
  g_signal_connect (priv->project, "targets-changed",
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
523
                    G_CALLBACK (project_targets_changed), properties);
524
  g_signal_connect (priv->project, "notify::license",
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
525
                    G_CALLBACK (project_license_changed), properties);
526 527 528 529 530 531
  g_signal_connect (priv->project, "add-widget",
                    G_CALLBACK (on_project_add_widget), properties);
  g_signal_connect (priv->project, "remove-widget",
                    G_CALLBACK (on_project_remove_widget), properties);
  g_signal_connect (priv->project, "widget-name-changed",
                    G_CALLBACK (on_project_widget_name_change), properties);
532 533 534 535

  target_version_box_fill (properties);
  update_prefs_for_resource_path (properties);

536
  project_path_changed (project, NULL, properties);
537 538
  project_template_changed (project, NULL, properties);
  project_domain_changed (project, NULL, properties);
539
  project_css_provider_path_changed (project, NULL, properties);
540 541 542 543
}

static void
glade_project_properties_set_property (GObject *object,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
544 545 546
                                       guint prop_id,
                                       const GValue *value,
                                       GParamSpec *pspec)
547 548 549 550 551
{
  switch (prop_id)
    {
    case PROP_PROJECT:
      glade_project_properties_set_project (GLADE_PROJECT_PROPERTIES (object),
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
552
                                            g_value_get_object (value));
553 554 555 556 557 558 559 560 561 562 563
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}

/********************************************************
 *                     Callbacks                        *
 ********************************************************/
static void
564 565
target_combobox_changed (GtkWidget              *widget,
                         GladeProjectProperties *properties)
566
{
567
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
568 569 570
  g_autofree gchar *version = NULL;
  gchar *catalog;
  gint major, minor;
571

572 573 574
  if (priv->ignore_ui_cb)
    return;

575
  version = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (widget));
576
  catalog = g_object_get_data (G_OBJECT (widget), "catalog");
577 578 579

  if (sscanf (version, "%d.%d", &major, &minor) == 2)
    glade_command_set_project_target (priv->project, catalog, major, minor);
580 581 582 583
}

static void
resource_default_toggled (GtkWidget              *widget,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
584
                          GladeProjectProperties *properties)
585
{
586
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
587

588 589
  if (priv->ignore_ui_cb || 
      !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
590 591
    return;

592
  glade_command_set_project_resource_path (priv->project, NULL);
593 594 595 596
}

static void
resource_relative_toggled (GtkWidget              *widget,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
597
                           GladeProjectProperties *properties)
598
{
599
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
600 601 602
  GtkToggleButton *toggle = GTK_TOGGLE_BUTTON (widget);
  
  if (priv->ignore_ui_cb || !gtk_toggle_button_get_active (toggle))
603 604
    return;

605 606
  glade_command_set_project_resource_path (priv->project, NULL);
  gtk_toggle_button_set_active (toggle, TRUE);
607 608 609 610 611 612
  gtk_widget_set_sensitive (priv->relative_path_entry, TRUE);
  gtk_widget_set_sensitive (priv->full_path_button, FALSE);
}

static void
resource_fullpath_toggled (GtkWidget              *widget,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
613
                           GladeProjectProperties *properties)
614
{
615
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
616
  GtkToggleButton *toggle = GTK_TOGGLE_BUTTON (widget);
617

618
  if (priv->ignore_ui_cb || !gtk_toggle_button_get_active (toggle))
619 620
    return;

621 622
  glade_command_set_project_resource_path (priv->project, NULL);
  gtk_toggle_button_set_active (toggle, TRUE);
623 624 625 626 627
  gtk_widget_set_sensitive (priv->relative_path_entry, FALSE);
  gtk_widget_set_sensitive (priv->full_path_button, TRUE);
}

static void
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
on_relative_path_entry_insert_text (GtkEditable            *editable,
                                    gchar                  *new_text,
                                    gint                    new_text_length,
                                    gint                   *position,
                                    GladeProjectProperties *properties) 
{
  GString *fullpath = g_string_new (gtk_entry_get_text (GTK_ENTRY(editable)));

  g_string_insert (fullpath, *position, new_text);
  
  if (g_path_is_absolute (fullpath->str))
    g_signal_stop_emission_by_name (editable, "insert-text");
  
  g_string_free (fullpath, TRUE);
}

static void
on_relative_path_entry_changed (GtkEntry *entry, GladeProjectProperties *properties)
646
{
647
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
648

649 650 651 652
  if (priv->ignore_ui_cb)
    return;

  glade_command_set_project_resource_path (priv->project, gtk_entry_get_text (entry));
653 654 655 656 657
}

static void
resource_full_path_set (GtkFileChooserButton *button, GladeProjectProperties *properties)
{
658
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
659 660 661 662 663 664 665
  gchar *text;
  
  if (priv->ignore_ui_cb)
    return;
  
  text = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (button));
  glade_command_set_project_resource_path (priv->project, text);
666 667 668 669 670
  g_free (text);
}

static void
on_template_combo_box_changed (GtkComboBox            *combo,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
671
                               GladeProjectProperties *properties)
672
{
673
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
674 675
  GtkTreeIter iter;

676 677 678
  if (priv->ignore_ui_cb)
    return;
  
679 680 681 682 683
  if (gtk_combo_box_get_active_iter (combo, &iter))
    {
      GladeWidget *gwidget;

      gtk_tree_model_get (gtk_combo_box_get_model (combo), &iter,
684 685 686
                          COLUMN_WIDGET, &gwidget,
                          -1);
      g_object_unref (gwidget);
687 688 689 690 691 692 693 694 695

      glade_command_set_project_template (priv->project, gwidget);
    }
}

static void
on_template_checkbutton_toggled (GtkToggleButton        *togglebutton,
                                 GladeProjectProperties *properties)
{
696
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
697 698 699

  if (priv->ignore_ui_cb)
    return;
700
  
701
  if (gtk_toggle_button_get_active (togglebutton))
702
    {
703
      gboolean composite = FALSE;
704 705 706
      GList *l;

      for (l = glade_project_toplevels (priv->project); l; l = l->next)
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
707 708 709
        {
          GObject *object = l->data;
          GladeWidget *gwidget;
710

Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
711
          gwidget = glade_widget_get_from_gobject (object);
712

Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
713 714 715 716 717 718 719
          if (GTK_IS_WIDGET (object))
            {
              glade_command_set_project_template (priv->project, gwidget);
              composite = TRUE;
              break;
            }
        }
720 721

      if (!composite)
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
722
        gtk_toggle_button_set_active (togglebutton, FALSE);
723 724 725 726 727 728 729 730
    }
  else
    glade_command_set_project_template (priv->project, NULL);
}

static void
verify_clicked (GtkWidget *button, GladeProjectProperties *properties)
{
731
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
732 733

  if (glade_project_verify (priv->project, FALSE,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
734 735 736
                            GLADE_VERIFY_VERSIONS     |
                            GLADE_VERIFY_DEPRECATIONS |
                            GLADE_VERIFY_UNRECOGNIZED))
737
    {
738 739 740 741
      g_autofree gchar *name = NULL, *msg = NULL;

      name = glade_project_get_name (priv->project);
      msg = g_strdup_printf (_("Project %s has no deprecated widgets "
742
                               "or version mismatches."), name);
743 744

      gtk_text_buffer_set_text (priv->warnings_textbuffer, msg, -1);
745 746 747 748 749 750
    }
}

static void
on_domain_entry_changed (GtkWidget *entry, GladeProjectProperties *properties)
{
751
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
752

753 754 755
  if (priv->ignore_ui_cb)
    return;

756 757 758
  glade_command_set_project_domain (priv->project, gtk_entry_get_text (GTK_ENTRY (entry)));
}

759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
#define GNU_GPLv2_TEXT \
    "$(name) - $(description)\n" \
    "Copyright (C) $(copyright)\n" \
    "\n" \
    "This program is free software; you can redistribute it and/or\n" \
    "modify it under the terms of the GNU General Public License\n" \
    "as published by the Free Software Foundation; either version 2\n" \
    "of the License, or (at your option) any later version.\n" \
    "\n" \
    "This program is distributed in the hope that it will be useful,\n" \
    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" \
    "GNU General Public License for more details.\n" \
    "\n" \
    "You should have received a copy of the GNU General Public License\n" \
    "along with this program; if not, write to the Free Software\n" \
    "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\n"

#define GNU_LGPLv2_TEXT \
    "$(name) - $(description)\n" \
    "Copyright (C) $(copyright)\n" \
    "\n" \
    "This library is free software; you can redistribute it and/or\n" \
    "modify it under the terms of the GNU Lesser General Public\n" \
    "License as published by the Free Software Foundation; either\n" \
    "version 2.1 of the License, or (at your option) any later version.\n" \
    "\n" \
    "This library is distributed in the hope that it will be useful,\n" \
    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n" \
    "Lesser General Public License for more details.\n" \
    "\n" \
    "You should have received a copy of the GNU Lesser General Public\n" \
    "License along with this library; if not, write to the Free Software\n" \
    "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n"

#define GNU_GPLv3_TEXT \
    "Copyright (C) $(copyright)\n" \
    "\n" \
    "This file is part of $(name).\n" \
    "\n" \
    "$(name) is free software: you can redistribute it and/or modify\n" \
    "it under the terms of the GNU General Public License as published by\n" \
    "the Free Software Foundation, either version 3 of the License, or\n" \
    "(at your option) any later version.\n" \
    "\n" \
    "$(name) is distributed in the hope that it will be useful,\n" \
    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" \
    "GNU General Public License for more details.\n" \
    "\n" \
    "You should have received a copy of the GNU General Public License\n" \
    "along with $(name).  If not, see <http://www.gnu.org/licenses/>.\n"

#define GNU_LGPLv3_TEXT \
    "Copyright (C) $(copyright)\n" \
    "\n" \
    "This file is part of $(name).\n" \
    "\n" \
    "$(name) is free software: you can redistribute it and/or modify\n" \
    "it under the terms of the GNU Lesser General Public License as published by\n" \
    "the Free Software Foundation, either version 3 of the License, or\n" \
    "(at your option) any later version.\n" \
    "\n" \
    "$(name) is distributed in the hope that it will be useful,\n" \
    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \
    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n" \
    "GNU Lesser General Public License for more details.\n" \
    "\n" \
    "You should have received a copy of the GNU Lesser General Public License\n" \
    "along with $(name).  If not, see <http://www.gnu.org/licenses/>.\n"

#define BSD3c_TEXT \
    "Copyright (c) $(copyright)\n" \
    "All rights reserved.\n" \
    "\n" \
    "Redistribution and use in source and binary forms, with or without\n" \
    "modification, are permitted provided that the following conditions are met:\n" \
    "    * Redistributions of source code must retain the above copyright\n" \
    "      notice, this list of conditions and the following disclaimer.\n" \
    "    * Redistributions in binary form must reproduce the above copyright\n" \
    "      notice, this list of conditions and the following disclaimer in the\n" \
    "      documentation and/or other materials provided with the distribution.\n" \
    "    * Neither the name of the <organization> nor the\n" \
    "      names of its contributors may be used to endorse or promote products\n" \
    "      derived from this software without specific prior written permission.\n" \
    "\n" \
    "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n" \
    "ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n" \
    "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n" \
    "DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY\n" \
    "DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n" \
    "(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n" \
    "LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n" \
    "ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" \
    "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n" \
    "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
856

857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
#define BSD2c_TEXT \
    "Copyright (c) $(copyright)\n" \
    "All rights reserved.\n" \
    "\n" \
    "Redistribution and use in source and binary forms, with or without\n" \
    "modification, are permitted provided that the following conditions are met:\n" \
    "\n" \
    "1. Redistributions of source code must retain the above copyright notice, this\n" \
    "   list of conditions and the following disclaimer. \n" \
    "2. Redistributions in binary form must reproduce the above copyright notice,\n" \
    "   this list of conditions and the following disclaimer in the documentation\n" \
    "   and/or other materials provided with the distribution. \n" \
    "\n" \
    "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\n" \
    "ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n" \
    "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n" \
    "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\n" \
    "ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n" \
    "(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n" \
    "LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n" \
    "ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" \
    "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n" \
    "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
880

881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928
#define APACHE2_TEXT \
    "Copyright $(copyright)\n" \
    "\n" \
    "Licensed under the Apache License, Version 2.0 (the \"License\"); \n" \
    "you may not use this file except in compliance with the License. \n" \
    "You may obtain a copy of the License at \n" \
    "\n" \
    "    http://www.apache.org/licenses/LICENSE-2.0 \n" \
    "\n" \
    "Unless required by applicable law or agreed to in writing, software \n" \
    "distributed under the License is distributed on an \"AS IS\" BASIS, \n" \
    "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n" \
    "See the License for the specific language governing permissions and \n" \
    "limitations under the License. \n"

#define GNU_ALL_PERMISSIVE_TEXT \
    "Copyright (C) $(copyright)\n" \
    "\n" \
    "Copying and distribution of this file, with or without modification,\n" \
    "are permitted in any medium without royalty provided the copyright\n" \
    "notice and this notice are preserved.  This file is offered as-is,\n" \
    "without any warranty.\n"

#define MIT_TEXT \
    "The MIT License (MIT)\n" \
    "\n" \
    "Copyright (c) $(copyright)\n" \
    "\n" \
    "Permission is hereby granted, free of charge, to any person obtaining a copy\n" \
    "of this software and associated documentation files (the \"Software\"), to deal\n" \
    "in the Software without restriction, including without limitation the rights\n" \
    "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n" \
    "copies of the Software, and to permit persons to whom the Software is\n" \
    "furnished to do so, subject to the following conditions:\n" \
    "\n" \
    "The above copyright notice and this permission notice shall be included in\n" \
    "all copies or substantial portions of the Software.\n" \
    "\n" \
    "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n" \
    "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n" \
    "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n" \
    "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n" \
    "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n" \
    "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n" \
    "THE SOFTWARE.\n"

static gchar *
gpp_get_license_from_id (const gchar *id)
929
{
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
  if (!g_strcmp0 (id, "gplv2"))
    return GNU_GPLv2_TEXT;
  else if (!g_strcmp0 (id, "gplv3"))
    return GNU_GPLv3_TEXT;
  else if (!g_strcmp0 (id, "lgplv2"))
    return GNU_LGPLv2_TEXT;
  else if (!g_strcmp0 (id, "lgplv3"))
    return GNU_LGPLv3_TEXT;
  else if (!g_strcmp0 (id, "bsd2c"))
    return BSD2c_TEXT;
  else if (!g_strcmp0 (id, "bsd3c"))
    return BSD3c_TEXT;
  else if (!g_strcmp0 (id, "apache2"))
    return APACHE2_TEXT;
  else if (!g_strcmp0 (id, "mit"))
    return MIT_TEXT;
  else if (!g_strcmp0 (id, "all_permissive"))
    return GNU_ALL_PERMISSIVE_TEXT;
  else
    return NULL;
950 951
}

952 953
static gint
string_count_new_lines (const gchar *str)
954
{
955
  gint c = 0;
956

957 958 959 960 961 962 963
  while (*str)
    {
      if (*str == '\n')
        c++;
      str = g_utf8_next_char (str);
    }
  return c;
964 965 966
}

static void
967
gpp_update_license (GladeProjectProperties *properties, gchar *license)
968
{
969
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
970 971
  const gchar *name, *description;
  gchar *copyright, *authors;
972

973 974
  if (!license)
    return;
975

976 977 978 979 980 981 982 983 984 985 986
  /* get data */
  name = gtk_entry_buffer_get_text (priv->name_entrybuffer);
  description = gtk_entry_buffer_get_text (priv->description_entrybuffer);
  
  g_object_get (priv->copyright_textbuffer, "text", &copyright, NULL);
  g_object_get (priv->authors_textbuffer, "text", &authors, NULL);
  
  /* Now we can replace strings in the license template */
  license = _glade_util_strreplace (license, FALSE, "$(name)", name);
  license = _glade_util_strreplace (license, TRUE, "$(description)", description);
  license = _glade_util_strreplace (license, TRUE, "$(copyright)", copyright);
987

988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
  if (authors && *authors)
    {
      gchar *tmp = license;

      if (string_count_new_lines (authors))
        license = g_strconcat (license, "\n", "Authors:", "\n", authors, NULL);
      else
        license = g_strconcat (license, "\n", "Author:", " ", authors, NULL);

      g_free (tmp);
    }
  
  gtk_text_buffer_set_text (priv->license_textbuffer, license, -1);

  g_free (license);
  g_free (copyright);
  g_free (authors);
1005 1006 1007
}

static void
1008
on_license_data_changed (GladeProjectProperties *properties)
1009
{
1010 1011
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
  const gchar *id = gtk_combo_box_get_active_id (priv->license_comboboxtext);
1012
  gchar *license;
1013

1014 1015
  if ((license = gpp_get_license_from_id (id)))
    gpp_update_license (properties, license);
1016 1017 1018
}

static void
1019 1020
on_license_comboboxtext_changed (GtkComboBox            *widget,
                                 GladeProjectProperties *properties)
1021
{
1022
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
1023
  gchar *license;
1024

1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036
  if ((license = gpp_get_license_from_id (gtk_combo_box_get_active_id (widget))))
    {
      gpp_update_license (properties, license);
      gtk_text_view_set_editable (priv->license_textview, FALSE);
    }
  else
    {
      /* Other license */
      gtk_text_buffer_set_text (priv->license_textbuffer, "", -1);      
      gtk_text_view_set_editable (priv->license_textview, TRUE);
      gtk_widget_grab_focus (GTK_WIDGET (priv->license_textview));
    }
1037 1038 1039 1040 1041 1042
}

static void
on_glade_project_properties_hide (GtkWidget              *widget,
                                  GladeProjectProperties *properties)
{
1043
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
1044 1045 1046
  GtkTextIter start, end;
  gchar *license;

1047 1048 1049
  if (!priv->project)
    return;

1050 1051 1052 1053 1054 1055 1056 1057 1058
  gtk_text_buffer_get_bounds (priv->license_textbuffer, &start, &end);
  license = gtk_text_buffer_get_text (priv->license_textbuffer, &start, &end, FALSE);
  g_strstrip (license);

  glade_command_set_project_license (priv->project, (license[0] != '\0') ? license : NULL);

  g_free (license);
}

1059 1060 1061
static void
on_css_checkbutton_toggled (GtkWidget *widget, GladeProjectProperties *properties)
{
1062
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081

  if (priv->ignore_ui_cb)
    return;

  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
    {
      gtk_widget_set_sensitive (priv->css_filechooser, TRUE);
    }
  else
    {
      gtk_widget_set_sensitive (priv->css_filechooser, FALSE);
      glade_project_set_css_provider_path (priv->project, NULL);
    }
}

static void
on_css_filechooser_file_set (GtkFileChooserButton   *widget,
                             GladeProjectProperties *properties)
{
1082
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
1083 1084 1085 1086 1087 1088
  const gchar *path;

  if (priv->ignore_ui_cb)
    return;

  path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
1089

1090 1091 1092
  glade_project_set_css_provider_path (priv->project, path);
}

1093 1094 1095 1096 1097
/******************************************************
 *                   Project Callbacks                *
 ******************************************************/
static void
project_targets_changed (GladeProject           *project,
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
1098
                         GladeProjectProperties *properties)
1099
{
1100
  GladeProjectPropertiesPrivate *priv = GLADE_PROJECT_PROPERTIES_PRIVATE(properties);
1101
  GList *list;
1102 1103
  priv->ignore_ui_cb = TRUE;

1104 1105 1106 1107
  /* For each catalog */
  for (list = glade_app_get_catalogs (); list; list = g_list_next (list))
    {
      GladeCatalog *catalog = list->data;
1108
      GtkComboBox *combobox;
1109
      gint minor, major;
1110
      const gchar *name;
1111 1112 1113 1114 1115 1116

      /* Skip if theres only one option */
      if (g_list_length (glade_catalog_get_targets (catalog)) <= 1)
        continue;

      /* Fetch the version for this project */
1117 1118
      name = glade_catalog_get_name (catalog);
      glade_project_get_target_version (priv->project, name, &major, &minor);
1119 1120

      /* Fetch the radios for this catalog  */
1121 1122
      if (priv->target_combos &&
          (combobox = g_hash_table_lookup (priv->target_combos, name)) != NULL)
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
1123
        {
1124 1125 1126
          g_autofree gchar *id = NULL;
          id = g_strdup_printf ("%d.%d", major, minor);
          gtk_combo_box_set_active_id(GTK_COMBO_BOX(combobox), id);
Juan Pablo Ugarte's avatar
Juan Pablo Ugarte committed
1127
        }
1128
    }
1129 1130 1131 1132