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