⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text_dialog.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  label211 = gtk_label_new(_("Text Encoder:"));  gtk_widget_show(label211);  gtk_table_attach(GTK_TABLE(table8), label211, 0, 1, 1, 2,                   (GtkAttachOptions)(GTK_FILL),                   (GtkAttachOptions)(0), 0, 0);  gtk_misc_set_alignment(GTK_MISC(label211), 0, 0.5);  label212 = gtk_label_new(_("Repeat Time:"));  gtk_widget_show(label212);  gtk_table_attach(GTK_TABLE(table8), label212, 0, 1, 2, 3,                   (GtkAttachOptions)(GTK_FILL),                   (GtkAttachOptions)(0), 0, 0);  gtk_misc_set_alignment(GTK_MISC(label212), 0, 0.5);  TextRepeatTimeSpinner_adj = gtk_adjustment_new(tp != NULL ?						 tp->GetFloatValue(CFG_TEXT_REPEAT_TIME_SECS) : 1, 0, 100, 1, 10, 10);  TextRepeatTimeSpinner = gtk_spin_button_new(GTK_ADJUSTMENT(TextRepeatTimeSpinner_adj), 1, 1);  gtk_widget_show(TextRepeatTimeSpinner);  gtk_table_attach(GTK_TABLE(table8), TextRepeatTimeSpinner, 1, 2, 2, 3,                   (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),                   (GtkAttachOptions)(0), 0, 0);  gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(TextRepeatTimeSpinner), TRUE);  label213 = gtk_label_new(_("Text Profile:"));  gtk_widget_show(label213);  gtk_table_attach(GTK_TABLE(table8), label213, 0, 1, 0, 1,                   (GtkAttachOptions)(GTK_FILL),                   (GtkAttachOptions)(0), 0, 0);  gtk_misc_set_alignment(GTK_MISC(label213), 0, 0.5);  TextProfileName = gtk_entry_new();  gtk_widget_show(TextProfileName);  gtk_table_attach(GTK_TABLE(table8), TextProfileName, 1, 2, 0, 1,                   (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),                   (GtkAttachOptions)(0), 0, 0);  label224 = gtk_label_new(_("Encoder Settings:"));  gtk_widget_show(label224);  gtk_table_attach(GTK_TABLE(table8), label224, 0, 1, 3, 4,                   (GtkAttachOptions)(GTK_FILL),                   (GtkAttachOptions)(0), 0, 0);  gtk_misc_set_alignment(GTK_MISC(label224), 0, 0.5);  TextEncoderSettingsButton = gtk_button_new();  gtk_widget_show(TextEncoderSettingsButton);  gtk_table_attach(GTK_TABLE(table8), TextEncoderSettingsButton, 1, 2, 3, 4,                   (GtkAttachOptions)(GTK_FILL),                   (GtkAttachOptions)(0), 0, 0);  alignment38 = gtk_alignment_new(0.5, 0.5, 0, 0);  gtk_widget_show(alignment38);  gtk_container_add(GTK_CONTAINER(TextEncoderSettingsButton), alignment38);  hbox117 = gtk_hbox_new(FALSE, 2);  gtk_widget_show(hbox117);  gtk_container_add(GTK_CONTAINER(alignment38), hbox117);  image43 = gtk_image_new_from_stock("gtk-preferences", GTK_ICON_SIZE_BUTTON);  gtk_widget_show(image43);  gtk_box_pack_start(GTK_BOX(hbox117), image43, FALSE, FALSE, 0);  label225 = gtk_label_new_with_mnemonic(_("Settings"));  gtk_widget_show(label225);  gtk_box_pack_start(GTK_BOX(hbox117), label225, FALSE, FALSE, 0);  dialog_action_area10 = GTK_DIALOG(TextProfileDialog)->action_area;  gtk_widget_show(dialog_action_area10);  gtk_button_box_set_layout(GTK_BUTTON_BOX(dialog_action_area10), GTK_BUTTONBOX_END);  cancelbutton8 = gtk_button_new_from_stock("gtk-cancel");  gtk_widget_show(cancelbutton8);  gtk_dialog_add_action_widget(GTK_DIALOG(TextProfileDialog), cancelbutton8, GTK_RESPONSE_CANCEL);  GTK_WIDGET_SET_FLAGS(cancelbutton8, GTK_CAN_DEFAULT);  okbutton10 = gtk_button_new_from_stock("gtk-ok");  gtk_widget_show(okbutton10);  gtk_dialog_add_action_widget(GTK_DIALOG(TextProfileDialog), okbutton10, GTK_RESPONSE_OK);  GTK_WIDGET_SET_FLAGS(okbutton10, GTK_CAN_DEFAULT);  g_signal_connect((gpointer) TextProfileDialog, "response",                    G_CALLBACK(on_TextProfileDialog_response),                    tp);  g_signal_connect((gpointer) TextProfileEncoder, "changed",                    G_CALLBACK(on_TextProfileEncoder_changed),                    tp);  g_signal_connect((gpointer) TextEncoderSettingsButton, "clicked",                    G_CALLBACK(on_TextEncoderSettingsButton_clicked),                    tp);  /* Store pointers to all widgets, for use by lookup_widget(). */  GLADE_HOOKUP_OBJECT_NO_REF(TextProfileDialog, TextProfileDialog, "TextProfileDialog");  GLADE_HOOKUP_OBJECT_NO_REF(TextProfileDialog, dialog_vbox11, "dialog_vbox11");  GLADE_HOOKUP_OBJECT(TextProfileDialog, table8, "table8");  GLADE_HOOKUP_OBJECT(TextProfileDialog, TextProfileEncoder, "TextProfileEncoder");  GLADE_HOOKUP_OBJECT(TextProfileDialog, label211, "label211");  GLADE_HOOKUP_OBJECT(TextProfileDialog, label212, "label212");  GLADE_HOOKUP_OBJECT(TextProfileDialog, TextRepeatTimeSpinner, "TextRepeatTimeSpinner");  GLADE_HOOKUP_OBJECT(TextProfileDialog, label213, "label213");  GLADE_HOOKUP_OBJECT(TextProfileDialog, TextProfileName, "TextProfileName");  GLADE_HOOKUP_OBJECT(TextProfileDialog, label224, "label224");  GLADE_HOOKUP_OBJECT(TextProfileDialog, TextEncoderSettingsButton, "TextEncoderSettingsButton");  GLADE_HOOKUP_OBJECT(TextProfileDialog, alignment38, "alignment38");  GLADE_HOOKUP_OBJECT(TextProfileDialog, hbox117, "hbox117");  GLADE_HOOKUP_OBJECT(TextProfileDialog, image43, "image43");  GLADE_HOOKUP_OBJECT(TextProfileDialog, label225, "label225");  GLADE_HOOKUP_OBJECT_NO_REF(TextProfileDialog, dialog_action_area10, "dialog_action_area10");  GLADE_HOOKUP_OBJECT(TextProfileDialog, cancelbutton8, "cancelbutton8");  GLADE_HOOKUP_OBJECT(TextProfileDialog, okbutton10, "okbutton10");  uint encoderIndex = 0;  uint ix = 0;  encoderNames = (const char **)malloc(text_encoder_table_size *				       sizeof(const char *));  for (ix = 0; ix < text_encoder_table_size; ix++) {    if (tp != NULL && 	strcasecmp(tp->GetStringValue(CFG_TEXT_ENCODING),		   text_encoder_table[ix].text_encoding) == 0) {      encoderIndex = ix;    }    encoderNames[ix] = text_encoder_table[ix].dialog_selection_name;  }  CreateOptionMenu(TextProfileEncoder,		   encoderNames, 		   text_encoder_table_size, 		   encoderIndex);  if (tp != NULL) {    gtk_entry_set_text(GTK_ENTRY(TextProfileName), 		       tp->GetStringValue(CFG_TEXT_PROFILE_NAME));    gtk_widget_set_sensitive(TextProfileName, false);  }  gtk_widget_show(TextProfileDialog);}/*************************************************************************** * Text File Dialog for running events ***************************************************************************/static guint timer_id = 0;static const GtkTargetEntry drop_types[] = {  { "text/plain", 0, 1 },  { "text/uri-list", 0, 2},  { "text/x-moz-url", 0, 3},  { "text/html", 0, 4},  { "UTF8_STRING", 0, 5},  { "STRING", 0, 6},};typedef struct text_line_offset_t {  text_line_offset_t *next_line;  uint index;  uint64_t offset;} text_line_offset_t;typedef struct text_file_data_t {  FILE *m_file;  char m_buffer[PATH_MAX]; // a nice large number  uint m_index; // line in file we're on  uint m_max_index;  text_line_offset_t *m_line_offset_head, *m_line_offset_tail;};static bool ReadNextLine (text_file_data_t *tptr){  off_t start;  start = ftello(tptr->m_file);  if (fgets(tptr->m_buffer, PATH_MAX, tptr->m_file) == NULL) {    tptr->m_max_index = tptr->m_index;    return false;  }  char *end = tptr->m_buffer + strlen(tptr->m_buffer) - 1;  while (isspace(*end) && end > tptr->m_buffer) {    *end = '\0';    end--;  }  debug_message("Read line %u %s", tptr->m_index, tptr->m_buffer);    if (tptr->m_line_offset_tail == NULL ||      tptr->m_line_offset_tail->index < tptr->m_index) {    text_line_offset_t *tlptr = MALLOC_STRUCTURE(text_line_offset_t);    tlptr->next_line = NULL;    tlptr->index = tptr->m_index;    tlptr->offset = start;    if (tptr->m_line_offset_head == NULL) {      tptr->m_line_offset_head = tptr->m_line_offset_tail = tlptr;    } else {      tptr->m_line_offset_tail->next_line = tlptr;      tptr->m_line_offset_tail = tlptr;    }    debug_message("Add to end");  }  tptr->m_index++;  return true;}static void GoToLine (text_file_data_t *tptr, text_line_offset_t *tlptr) {  debug_message("Go to line - %u offset "U64,		tlptr->index, tlptr->offset);  fseeko(tptr->m_file, tlptr->offset, SEEK_SET);  tptr->m_index = tlptr->index;  ReadNextLine(tptr);}static void GoToLine (text_file_data_t *tptr, uint index){  uint ix;  debug_message("go to line %u", index);  if (tptr->m_line_offset_tail != NULL) {    debug_message("tail index %u", index);  }  if (tptr->m_line_offset_tail != NULL &&      tptr->m_line_offset_tail->index >= index) {    debug_message("Looking for tail");    text_line_offset_t *tlptr;    for (ix = 0, tlptr = tptr->m_line_offset_head; ix < index; ix++) {      tlptr = tlptr->next_line;    }    if (tlptr->index != index) {      error_message("Seek not right %u %u", tlptr->index, index);    }    GoToLine(tptr, tlptr);    return;  }  uint start_index = 0;  if (tptr->m_line_offset_tail) {    start_index = tptr->m_line_offset_tail->index;    GoToLine(tptr, tptr->m_line_offset_tail);  }  for (ix = start_index; ix < index; ix++) {    if (ReadNextLine(tptr) == false)      return;  }}static void GoToLine (text_file_data_t *tptr, int index){  return GoToLine(tptr, (uint)index);}static gbooleanon_TextFileDialog_delete_event         (GtkWidget       *widget,                                        GdkEvent        *event,                                        gpointer         user_data){  // don't do anything - the main window will control this dialog  return TRUE;}static text_file_data_t *GetTextFileDataFromUserData (gpointer user_data){  GtkWidget *dialog = GTK_WIDGET(user_data);    return (text_file_data_t *)lookup_widget(dialog, "TextFileData");}static void DisplayLineInBuffer (gpointer user_data, 				 text_file_data_t *tptr){  GtkWidget *dialog = GTK_WIDGET(user_data);  GtkWidget *entry = lookup_widget(dialog, "LineEntry");  gtk_entry_set_text(GTK_ENTRY(entry), tptr->m_buffer);  debug_message("Set text to %s", tptr->m_buffer);}  static voidon_TextFileDialog_destroy         (GtkObject       *widget,				   gpointer         user_data){  text_file_data_t *tptr =     (text_file_data_t *)lookup_widget(GTK_WIDGET(widget), "TextFileData");  if (timer_id != 0)    gtk_timeout_remove(timer_id);  if (tptr != NULL) {    text_line_offset_t *tlptr = tptr->m_line_offset_head;    while (tlptr != NULL) {      tptr->m_line_offset_head = tlptr->next_line;      free(tlptr);      tlptr = tptr->m_line_offset_head;    }    free(tptr);  }}static voidon_StartButton_clicked                 (GtkButton       *button,                                        gpointer         user_data){  debug_message("start clicked");  text_file_data_t *tptr = GetTextFileDataFromUserData(user_data);  GoToLine(tptr, 0);  DisplayLineInBuffer(user_data, tptr);}static voidon_PrevButton_clicked                  (GtkButton       *button,                                        gpointer         user_data){  debug_message("prev clicked");  text_file_data_t *tptr = GetTextFileDataFromUserData(user_data);  uint index = tptr->m_index;  if (tptr->m_index > 2) index = tptr->m_index - 2;  else index = 0;  GoToLine(tptr, index);  DisplayLineInBuffer(user_data, tptr);}static voidon_NextButton_clicked                  (GtkButton       *button,                                        gpointer         user_data){  text_file_data_t *tptr = GetTextFileDataFromUserData(user_data);  ReadNextLine(tptr);  DisplayLineInBuffer(user_data, tptr);}static voidon_EndButton_clicked                   (GtkButton       *button,                                        gpointer         user_data){  text_file_data_t *tptr = GetTextFileDataFromUserData(user_data);  if (tptr->m_line_offset_tail != NULL) {    if (tptr->m_index < tptr->m_line_offset_tail->index) {      GoToLine(tptr, tptr->m_line_offset_tail);    }  }  while (ReadNextLine(tptr));  DisplayLineInBuffer(user_data, tptr);}gint on_TextDialog_timeout (gpointer user_data){  GtkWidget *dialog = GTK_WIDGET(user_data);  GtkWidget *wid = lookup_widget(dialog, "statusbar2");  gtk_statusbar_pop(GTK_STATUSBAR(wid), 0);  gtk_statusbar_push(GTK_STATUSBAR(wid), 0, "");  timer_id = 0;  return 0;}static voidon_SendButton_clicked                  (GtkButton       *button,                                        gpointer         user_data){  GtkWidget *dialog = GTK_WIDGET(user_data);  GtkWidget *wid = lookup_widget(dialog, "LineEntry");  const char *line = gtk_entry_get_text(GTK_ENTRY(wid));  if (AVFlow->GetTextSource() == NULL) {    error_message("no text source");    return;  }  AVFlow->GetTextSource()->SourceString(line);    char buffer[60];  snprintf(buffer, sizeof(buffer),"Wrote: %.25s...", line);  wid = lookup_widget(dialog, "statusbar2");  gtk_statusbar_pop(GTK_STATUSBAR(wid), 0);  gtk_statusbar_push(GTK_STATUSBAR(wid), 0, buffer);  if (timer_id != 0) {    gtk_timeout_remove(timer_id);  }  timer_id = gtk_timeout_add(3 * 1000, 			     on_TextDialog_timeout, 			     user_data);  text_file_data_t *tptr = GetTextFileDataFromUserData(user_data);  if (tptr != NULL) {    ReadNextLine(tptr);    DisplayLineInBuffer(user_data, tptr);  } }static voidon_LineEntry_activate  (GtkEntry *ent,			gpointer user_data){  on_SendButton_clicked(NULL, user_data);}static void on_drag_data_received_entry (GtkWidget *widget,					 GdkDragContext *context,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -