/[aleader]/aleader/aleader/apptranscript.c
ViewVC logotype

Diff of /aleader/aleader/apptranscript.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by jpritikin, Thu Aug 14 03:40:43 2003 UTC revision 1.13 by jpritikin, Thu Oct 9 03:18:59 2003 UTC
# Line 48  static const char TranscriptMIME[] = "ap Line 48  static const char TranscriptMIME[] = "ap
48  struct _AppTranscriptClass {  struct _AppTranscriptClass {
49    LeadrDocClass parent_class;    LeadrDocClass parent_class;
50    
   // AppIpName  
   void (*name_changed)(AppTranscript *tx, AppIpName *nm, gpointer);  
   
51    // AppIp    // AppIp
52    void (*ip_modified) (AppTranscript *tx, AppIp *ip, gpointer);    void (*ip_modified) (AppTranscript *tx, AppIp *ip, gpointer);
53    void (*ip_set_span) (AppTranscript *tx,    void (*ip_set_span) (AppTranscript *tx,
# Line 88  enum { Line 85  enum {
85    
86  enum {  enum {
87    NAME_CHANGED,    NAME_CHANGED,
88      TOPIC_CHANGED,
89    IP_SET_SPAN,    IP_SET_SPAN,
90    IP_MODIFIED,    IP_MODIFIED,
91    IP_SPAN_MODIFIED,    IP_SPAN_MODIFIED,
# Line 201  _ts_save_insert (AppTranscript *tx, GtkT Line 199  _ts_save_insert (AppTranscript *tx, GtkT
199  void  void
200  app_ip_name_changed (AppIpName *nm)  app_ip_name_changed (AppIpName *nm)
201  {  {
202    g_signal_emit (app_ip_name_get_transcript (nm),    AppTranscript *tx = app_ip_name_get_transcript (nm);
203                   signals[NAME_CHANGED], 0, nm);    g_signal_emit (tx, signals[NAME_CHANGED], 0, nm);
204      leadr_doc_set_modified (LEADR_DOC (tx));
205  }  }
206    
207    void
208    leadr_topic_changed (LeadrTopic *tpc)
209    {
210      AppTranscript *tx = leadr_topic_get_transcript (tpc);
211      g_signal_emit (tx, signals[TOPIC_CHANGED], 0, tpc);
212      leadr_doc_set_modified (LEADR_DOC (tx));
213    }
214    
215  gboolean  gboolean
216  app_transcript_can_edit (AppTranscript *tx, gint what)  app_transcript_can_edit (AppTranscript *tx, gint what)
# Line 270  typedef struct { Line 276  typedef struct {
276    AppTranscript *tx;    AppTranscript *tx;
277    gint version;    gint version;
278    GHashTable *nameht;    GHashTable *nameht;
279      GHashTable *topicht;
280    GHashTable *ipht;    GHashTable *ipht;
281    GHashTable *taght;    GHashTable *taght;
282    GtkTextIter iter;    GtkTextIter iter;
# Line 423  tl_start_element (GMarkupParseContext *c Line 430  tl_start_element (GMarkupParseContext *c
430            }            }
431        }        }
432      }      }
433      else if (EQ (element_name, "topic"))
434        {
435          const gchar *id = attr_get_string (cx, "id", NULL);
436          const gchar *name = attr_get_string (cx, "is", NULL);
437          if (id && name) {
438            const gchar *note = attr_get_string (cx, "note", NULL);
439            g_hash_table_insert (cx->topicht, g_strdup (id),
440                                 leadr_topic_new (tx, name, note));
441          }
442        }
443    else if (EQ (element_name, "notes"))    else if (EQ (element_name, "notes"))
444      {      {
445        if (cx->got_notes_section)        if (cx->got_notes_section)
# Line 534  tl_start_element (GMarkupParseContext *c Line 551  tl_start_element (GMarkupParseContext *c
551             "notes", attr_get_string (cx, "notes", NULL),             "notes", attr_get_string (cx, "notes", NULL),
552             NULL);             NULL);
553    
554            nkey = attr_get_string (cx, "topic", NULL);
555            if (nkey) {
556              LeadrTopic *tpc = g_hash_table_lookup (cx->topicht, nkey);
557              if (tpc)
558                g_object_set (cx->ip, "topic", tpc, NULL);
559            }
560    
561          ready = g_new (tl_app_ip, 1);          ready = g_new (tl_app_ip, 1);
562          ready->ip = cx->ip;          ready->ip = cx->ip;
563          ready->start = gtk_text_buffer_create_mark (tx->text, NULL, &cx->iter, TRUE);          ready->start = gtk_text_buffer_create_mark (tx->text, NULL, &cx->iter, TRUE);
# Line 689  app_transcript_load (const gchar *pathna Line 713  app_transcript_load (const gchar *pathna
713    
714    cx.tx = model;    cx.tx = model;
715    cx.nameht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);    cx.nameht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
716      cx.topicht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
717    cx.ipht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);    cx.ipht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
718    cx.taght = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);    cx.taght = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
719    
# Line 741  app_transcript_load (const gchar *pathna Line 766  app_transcript_load (const gchar *pathna
766    g_ring_free (cx.ipring);    g_ring_free (cx.ipring);
767    g_markup_parse_context_free(pcx);    g_markup_parse_context_free(pcx);
768    g_hash_table_destroy (cx.nameht);    g_hash_table_destroy (cx.nameht);
769      g_hash_table_destroy (cx.topicht);
770    g_hash_table_destroy (cx.ipht);    g_hash_table_destroy (cx.ipht);
771    g_hash_table_destroy (cx.taght);   // leak possible XXX    g_hash_table_destroy (cx.taght);   // leak possible XXX
772    
# Line 963  _tx_stringify (LeadrDoc *doc, Line 989  _tx_stringify (LeadrDoc *doc,
989    
990    for (gint xx=0; xx < g_ptr_set_len (tx->names_by_alpha); xx++)    for (gint xx=0; xx < g_ptr_set_len (tx->names_by_alpha); xx++)
991      {      {
992        AppIpName *nm;        AppIpName *nm = g_ptr_set_at (tx->names_by_alpha, xx);
       const gint numsize = 16;  
       gchar num[numsize];  
   
       nm = g_ptr_set_at (tx->names_by_alpha, xx);  
993    
994        g_snprintf (num, numsize, "%d", xx);        gchar num[16];
995          g_snprintf (num, sizeof (num), "%d", xx);
996    
997        xml_empty (cx.buf, "name",        xml_empty (cx.buf, "name",
998                   "id", num,                   "id", num,
# Line 982  _tx_stringify (LeadrDoc *doc, Line 1005  _tx_stringify (LeadrDoc *doc,
1005        g_string_append_c (cx.buf, '\n');        g_string_append_c (cx.buf, '\n');
1006      }      }
1007    
1008      for (gint xx=0; xx < g_ptr_set_len (tx->topics); xx++) {
1009        LeadrTopic *tpc = g_ptr_set_at (tx->topics, xx);
1010    
1011        gchar num[16];
1012        g_snprintf (num, sizeof (num), "%d", xx);
1013    
1014        xml_empty (cx.buf, "topic",
1015                   "id", num,
1016                   "is", leadr_topic_get_name (tpc),
1017                   "note", leadr_topic_get_note (tpc),
1018                   NULL);
1019    
1020        g_string_append_c (cx.buf, '\n');
1021      }
1022    
1023    if (tx->notes) {    if (tx->notes) {
1024      xml_start (cx.buf, "notes", NULL);      xml_start (cx.buf, "notes", NULL);
1025      xml_escape (cx.buf, tx->notes);      xml_escape (cx.buf, tx->notes);
# Line 1669  static gint names_by_alpha_ptr_cmp (AppI Line 1707  static gint names_by_alpha_ptr_cmp (AppI
1707  static gint names_by_alpha_key_cmp (gchar *n1, AppIpName *n2)  static gint names_by_alpha_key_cmp (gchar *n1, AppIpName *n2)
1708  { return ge_utf8_casefold_collate (n1, app_ip_name_get (n2)); }  { return ge_utf8_casefold_collate (n1, app_ip_name_get (n2)); }
1709    
1710  static gint  static gint topic_cmp (LeadrTopic *t1, LeadrTopic *t2)
 names_by_use_cmp (AppIpName *n1, AppIpName *n2)  
1711  {  {
1712    gint cmp;    return ge_utf8_casefold_collate (leadr_topic_get_name (t1),
1713                                       leadr_topic_get_name (t2));
   cmp = app_ip_name_get_use (n2) - app_ip_name_get_use (n1);  
   if (cmp) return cmp;  
   
   return ge_utf8_casefold_collate (app_ip_name_get (n1),  
                                    app_ip_name_get (n2));  
1714  }  }
1715    
1716    static gint topic_key_cmp (gchar *t1, LeadrTopic *t2)
1717    { return ge_utf8_casefold_collate (t1, leadr_topic_get_name (t2)); }
1718    
1719  static gint  static gint
1720  _style_compare (GtkTextTag *t1, GtkTextTag *t2, gpointer ign)  _style_compare (GtkTextTag *t1, GtkTextTag *t2, gpointer ign)
1721  {  {
# Line 1967  _tx_dispose (GObject *object) Line 2002  _tx_dispose (GObject *object)
2002    
2003    tx->name_unset = NULL;    tx->name_unset = NULL;
2004    
2005    while (g_ptr_set_len (tx->names_by_alpha))    while (g_ptr_set_len (tx->names_by_alpha)) {
2006      {      AppIpName *nm =
2007        AppIpName *nm =        g_ptr_set_at (tx->names_by_alpha,
2008          g_ptr_set_at (tx->names_by_alpha,                      g_ptr_set_len (tx->names_by_alpha) - 1);
2009                        g_ptr_set_len (tx->names_by_alpha) - 1);      g_object_unref (nm);
2010        g_object_unref (nm);    }
2011      }    while (g_ptr_set_len (tx->topics)) {
2012        LeadrTopic *tpc =
2013          g_ptr_set_at (tx->topics, g_ptr_set_len (tx->topics) - 1);
2014        g_object_unref (tpc);
2015      }
2016    
2017    // it's quicker to remove the last element    // it's quicker to remove the last element
2018    while (g_ptr_set_len (tx->sync_by_time))    while (g_ptr_set_len (tx->sync_by_time))
# Line 2053  app_transcript_init (AppTranscript *cx) Line 2092  app_transcript_init (AppTranscript *cx)
2092                  "key-compare", names_by_alpha_key_cmp,                  "key-compare", names_by_alpha_key_cmp,
2093                  NULL);                  NULL);
2094    
   cx->names_by_use = g_ptr_set_new ((GCompareDataFunc) names_by_use_cmp, NULL);  
   
2095    cx->name_unset =    cx->name_unset =
2096      app_ip_name_new (cx, _("(unset)"), IP_NAME_UNSET,      app_ip_name_new (cx, _("(unset)"), IP_NAME_UNSET,
2097                       "This name is used as a placeholder before some "                       "This name is a placeholder used before some "
2098                       "other name is assigned.");                       "other name is assigned.");
2099    cx->name_any =    cx->name_any =
2100      app_ip_name_new (cx, _("Someone"), IP_NAME_ANY,      app_ip_name_new (cx, _("Someone"), IP_NAME_ANY,
2101                       "This name is a wildcard.  It represents any single "                       "This name is a wildcard.  It represents any single "
2102                       "person or group of people.  It may also represent "                       "person or group of people.  It may also represent "
2103                       "a vehicle, such as a car or ship.  Use this name "                       "a vehicle, such as a car or ship.  Use this name "
2104                       "when any more-specific name is not available.");                       "when no more-specific name is available.");
2105    
2106      cx->topics =
2107        (*g_ptr_set_factory) ((GCompareDataFunc) topic_cmp, NULL);
2108      g_object_set (cx->topics, "key-compare", topic_key_cmp, NULL);
2109    
2110    cx->ip_by_start =    cx->ip_by_start =
2111      (*g_ptr_set_factory) ((GCompareDataFunc) app_ip_compare_start, NULL);      (*g_ptr_set_factory) ((GCompareDataFunc) app_ip_compare_start, NULL);
# Line 2156  app_transcript_finalize (GObject *object Line 2197  app_transcript_finalize (GObject *object
2197    g_object_unref (tx->styles);    g_object_unref (tx->styles);
2198    
2199    g_object_unref (tx->names_by_alpha);    g_object_unref (tx->names_by_alpha);
2200    g_object_unref (tx->names_by_use);    g_object_unref (tx->topics);
2201    
2202    g_object_unref (tx->ip_by_start);    g_object_unref (tx->ip_by_start);
2203    
# Line 2238  _transcript_real_set_exam_state (AppTran Line 2279  _transcript_real_set_exam_state (AppTran
2279    g_object_notify (G_OBJECT (tx), "state");    g_object_notify (G_OBJECT (tx), "state");
2280  }  }
2281    
 static void  
 real_name_changed (AppTranscript *tx, AppIpName *nm, gpointer _ign)  
 {  
   leadr_doc_set_modified (LEADR_DOC (tx));  
 }  
   
2282  static gboolean  static gboolean
2283  _transcript_can_edit (AppTranscript *tx, gint what, gpointer _ud)  _transcript_can_edit (AppTranscript *tx, gint what, gpointer _ud)
2284  { return TRUE; }  { return TRUE; }
# Line 2281  app_transcript_class_init (AppTranscript Line 2316  app_transcript_class_init (AppTranscript
2316    doc_class->stringify     = _tx_stringify;    doc_class->stringify     = _tx_stringify;
2317    doc_class->open_exemplar = _tx_open_exemplar;    doc_class->open_exemplar = _tx_open_exemplar;
2318    
   klass->name_changed = real_name_changed;  
2319    klass->ip_set_span = _transcript_real_set_span;    klass->ip_set_span = _transcript_real_set_span;
2320    klass->ip_modified = _transcript_ip_modified;    klass->ip_modified = _transcript_ip_modified;
2321    klass->set_exam_state = _transcript_real_set_exam_state;    klass->set_exam_state = _transcript_real_set_exam_state;
# Line 2359  app_transcript_class_init (AppTranscript Line 2393  app_transcript_class_init (AppTranscript
2393      g_signal_new ("name-changed",      g_signal_new ("name-changed",
2394                    G_OBJECT_CLASS_TYPE (klass),                    G_OBJECT_CLASS_TYPE (klass),
2395                    G_SIGNAL_RUN_LAST,                    G_SIGNAL_RUN_LAST,
2396                    G_STRUCT_OFFSET(AppTranscriptClass, name_changed),                    0,
2397                    NULL, NULL,                    NULL, NULL,
2398                    aleader_marshal_VOID__OBJECT,                    aleader_marshal_VOID__OBJECT,
2399                    G_TYPE_NONE,                    G_TYPE_NONE,
2400                    1,                    1,
2401                    APP_IP_NAME_TYPE);                    APP_IP_NAME_TYPE);
2402    
2403      signals[TOPIC_CHANGED] =
2404        g_signal_new ("topic-changed",
2405                      G_OBJECT_CLASS_TYPE (klass),
2406                      G_SIGNAL_RUN_LAST,
2407                      0,
2408                      NULL, NULL,
2409                      aleader_marshal_VOID__OBJECT,
2410                      G_TYPE_NONE,
2411                      1,
2412                      LEADR_TOPIC_TYPE);
2413    
2414    signals[IP_SET_SPAN] =    signals[IP_SET_SPAN] =
2415      g_signal_new ("ip-set-span",      g_signal_new ("ip-set-span",
2416                    G_OBJECT_CLASS_TYPE (klass),                    G_OBJECT_CLASS_TYPE (klass),

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26