Recieve new log messages in gl-journal-model.c

For the past two weeks, according to my previous plan, I made progress in the gl-journal-model.c file. In this place, I set up a function that receives the signal and a function that processes the signal. It looks interesting. In this way, we can see the data and signals sent from gl-journal.c, which can already be received by me.

这里写图片描述

Static void
on_new_entry_added (GlJournal *journal,
                    GlJournalEntry *entry,
                    gpointer user_data)
{
 GlJournalModel *model;

 model = GL_JOURNAL_MODEL (user_data);

 g_ptr_array_add (model->entries, entry);
 g_print ("%s\n", gl_journal_entry_get_message (entry));
 g_list_model_items_changed (G_LIST_MODEL (model),
 model->entries->len - 1, 0, 1);
}

 static void
 Gl_journal_model_init (GlJournalModel *model)
 {
     Model->batch_size = 50;
     Model->journal = gl_journal_new ();
     Model->entries = g_ptr_array_new_with_free_func (g_object_unref);

     g_signal_connect (model->journal, "entry-added",
     G_CALLBACK (on_new_entry_added), model);

     Gl_journal_model_fetch_more_entries (model, FALSE);
 }

I added the printed code to this on_new_entry_added function. I can see that the latest log message has been correctly displayed on the screen. This is cool, but there seems to be some completely duplicate information. This will continue to be modified, no matter what. Some progress has been made and the issue will be fixed next week.
Learned some knowledge:
how to set Signal establishment
G_signal_emit ()
Void
G_signal_emit (gpointer instance,
Guint signal_id,
GQuark detail,
…);
Emits a signal.
Note that g_signal_emit() resets the return value to the default if no handlers are connected, in contrast to g_signal_emitv().

G_signal_connect(instance, detailed_signal, c_handler, data)
*Connects a GCallback function to a signal for a particular object.
The handler will be called before the default handler of the signal.
See memory management of signal handlers for details on how to handle the return value and memory management of data*
Parameters
Instance the instance to connect to.
Detailed_signal a string of the form “signal-name::detail”.
C_handler the GCallback to connect.
Data data to pass to c_handler calls.
Returns
The handler ID, of type gulong (always greater than 0 for successful connections)

Another point is to improve the performance of the program. After the program starts, it will not read all the log messages immediately. It will be set by a model->batch_size = 50; read 50 rows, when the scroll wheel slides down, Will trigger a load event, this is the program will call gl_journal_model_fetch_idle (), to get the system log, and display in the model. This is really a cool idea.

Ok, the next few weeks of the task is very clear, it is not enough to get a new log message, to get the correct new log message. There is also a way to try to display it correctly on the model.

June 30, 2018

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值