plugin-ui.cpp
上传用户:hongyu5696
上传日期:2018-01-22
资源大小:391k
文件大小:96k
源码类别:

PlugIns编程

开发平台:

Unix_Linux

  1. #include "plugin.h"
  2. #include <errno.h>
  3. extern int errno;
  4. extern int DEBUG;
  5. #include <X11/xpm.h>
  6. #include <X11/cursorfont.h>
  7. #ifdef X_ENABLED
  8. #include "../pixmaps/logo.xpm"
  9. #include "../pixmaps/progress_left.xpm"
  10. #include "../pixmaps/progress_middle.xpm"
  11. #include "../pixmaps/progress_right.xpm"
  12. #include "../pixmaps/progress_fill.xpm"
  13. #endif
  14. #ifdef GTK_ENABLED
  15. #include <gdk/gdkkeysyms.h>
  16. // 16 x 12 button pixmaps
  17. #include "../pixmaps/play_down_small.xpm"
  18. #include "../pixmaps/play_up_small.xpm"
  19. #include "../pixmaps/pause_down_small.xpm"
  20. #include "../pixmaps/pause_up_small.xpm"
  21. #include "../pixmaps/stop_down_small.xpm"
  22. #include "../pixmaps/stop_up_small.xpm"
  23. #include "../pixmaps/ff_down_small.xpm"
  24. #include "../pixmaps/ff_up_small.xpm"
  25. #include "../pixmaps/rew_down_small.xpm"
  26. #include "../pixmaps/rew_up_small.xpm"
  27. #include "../pixmaps/fs_down_small.xpm"
  28. #include "../pixmaps/fs_up_small.xpm"
  29. // default src button
  30. #include "../pixmaps/start.xpm"
  31. #endif
  32. #define BUTTON_WIDTH 43
  33. #define BUTTON_HEIGHT 32
  34. #define SMALL_BUTTON_WIDTH 21
  35. #define SMALL_BUTTON_HEIGHT 16
  36. #define BORDER               10
  37. #define LOGO_WIDTH          257
  38. #define LOGO_HEIGHT          48
  39. #ifndef HAVE_X11_XPM
  40. #error libXpm has not been found. Compilation cannot continue
  41. #endif
  42. #ifdef X_ENABLED
  43. unsigned long GetFontAtom(Display * dpy, XFontStruct * fs, char *atomname)
  44. {
  45.     unsigned long val;
  46.     Atom atom = XInternAtom(dpy, atomname, True);
  47.     XGetFontProperty(fs, atom, &val);
  48.     return val;
  49. }
  50. #endif
  51. void Initialize(Display * dpy, Drawable d, nsPluginInstance * instance,
  52. GC gc)
  53. {
  54. #ifdef X_ENABLED
  55.     Cursor guicursor;
  56.     XSetWindowAttributes attrs;
  57.     char **missing_charset_list_return;
  58.     int missing_charset_count_return;
  59.     char *def_string_return;
  60.     XpmCreatePixmapFromData(dpy, d, logo_xpm, &instance->logo,
  61.     &instance->logomask, NULL);
  62.     XpmCreatePixmapFromData(dpy, d, progress_left_xpm,
  63.     &instance->progress_left,
  64.     &instance->progress_leftmask, NULL);
  65.     XpmCreatePixmapFromData(dpy, d, progress_middle_xpm,
  66.     &instance->progress_middle,
  67.     &instance->progress_middlemask, NULL);
  68.     XpmCreatePixmapFromData(dpy, d, progress_right_xpm,
  69.     &instance->progress_right,
  70.     &instance->progress_rightmask, NULL);
  71.     XpmCreatePixmapFromData(dpy, d, progress_fill_xpm,
  72.     &instance->progress_fill,
  73.     &instance->progress_fillmask, NULL);
  74.     if (!instance->font) {
  75. XFontStruct *fstr;
  76. char *family;
  77. unsigned long size = 14;
  78. char *italic;
  79. char *bold;
  80. char fontname[256];
  81. fstr = XQueryFont(dpy, XGContextFromGC(gc));
  82. family = XGetAtomName(dpy, GetFontAtom(dpy, fstr, "FAMILY_NAME"));
  83. bold = XGetAtomName(dpy, GetFontAtom(dpy, fstr, "WEIGHT_NAME"));
  84. italic = XGetAtomName(dpy, GetFontAtom(dpy, fstr, "SLANT"));
  85. size = GetFontAtom(dpy, fstr, "PIXEL_SIZE");
  86. XFreeFontInfo(NULL, fstr, 0);
  87.     
  88. sprintf(fontname, "-*-%s-%s-%s-*--%d-*",
  89. family, bold, italic, (int) size);
  90. instance->font = XCreateFontSet(dpy,
  91. fontname,
  92. &missing_charset_list_return,
  93. &missing_charset_count_return,
  94. &def_string_return);
  95.     }
  96.     guicursor = XCreateFontCursor(dpy, XC_watch);
  97.     attrs.cursor = guicursor;
  98.     XChangeWindowAttributes(dpy, d, CWCursor, &attrs);
  99. #endif
  100. }
  101. void InitPixbufs(nsPluginInstance * instance)
  102. {
  103. #ifdef GTK2_ENABLED
  104.     instance->pb_sm_play_up =
  105. gdk_pixbuf_new_from_xpm_data((const char **) play_up_small);
  106.     instance->pb_sm_play_down =
  107. gdk_pixbuf_new_from_xpm_data((const char **) play_down_small);
  108.     instance->pb_sm_pause_up =
  109. gdk_pixbuf_new_from_xpm_data((const char **) pause_up_small);
  110.     instance->pb_sm_pause_down =
  111. gdk_pixbuf_new_from_xpm_data((const char **) pause_down_small);
  112.     instance->pb_sm_stop_up =
  113. gdk_pixbuf_new_from_xpm_data((const char **) stop_up_small);
  114.     instance->pb_sm_stop_down =
  115. gdk_pixbuf_new_from_xpm_data((const char **) stop_down_small);
  116.     instance->pb_sm_ff_up =
  117. gdk_pixbuf_new_from_xpm_data((const char **) ff_up_small);
  118.     instance->pb_sm_ff_down =
  119. gdk_pixbuf_new_from_xpm_data((const char **) ff_down_small);
  120.     instance->pb_sm_rew_up =
  121. gdk_pixbuf_new_from_xpm_data((const char **) rew_up_small);
  122.     instance->pb_sm_rew_down =
  123. gdk_pixbuf_new_from_xpm_data((const char **) rew_down_small);
  124.     instance->pb_sm_fs_up =
  125. gdk_pixbuf_new_from_xpm_data((const char **) fs_up_small);
  126.     instance->pb_sm_fs_down =
  127. gdk_pixbuf_new_from_xpm_data((const char **) fs_down_small);
  128. #endif
  129. #ifdef GTK1_ENABLED
  130.     instance->pb_sm_play_up =
  131. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  132.      NULL, NULL, play_up_small);
  133.     instance->pb_sm_play_down =
  134. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  135.      NULL, NULL, play_down_small);
  136.     instance->pb_sm_pause_up =
  137. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  138.      NULL, NULL, pause_up_small);
  139.     instance->pb_sm_pause_down =
  140. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  141.      NULL, NULL, pause_down_small);
  142.     instance->pb_sm_stop_up =
  143. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  144.      NULL, NULL, stop_up_small);
  145.     instance->pb_sm_stop_down =
  146. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  147.      NULL, NULL, stop_down_small);
  148.     instance->pb_sm_ff_up =
  149. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  150.      NULL, NULL, ff_up_small);
  151.     instance->pb_sm_ff_down =
  152. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  153.      NULL, NULL, ff_down_small);
  154.     instance->pb_sm_rew_up =
  155. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  156.      NULL, NULL, rew_up_small);
  157.     instance->pb_sm_rew_down =
  158. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  159.      NULL, NULL, rew_down_small);
  160.     instance->pb_sm_fs_up =
  161. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  162.      NULL, NULL, fs_up_small);
  163.     instance->pb_sm_fs_down =
  164. gdk_pixmap_create_from_xpm_d(instance->gtkwidget->window,
  165.      NULL, NULL, fs_down_small);
  166. #endif
  167. }
  168. void DrawLogo(Display * dpy, Drawable d, nsPluginInstance * instance,
  169.       GC gc)
  170. {
  171. #ifdef X_ENABLED
  172.     XGCValues values;
  173.     values.clip_mask = instance->logomask;
  174.     values.clip_x_origin = 0;
  175.     values.clip_y_origin = 0;
  176.     XChangeGC(dpy, gc, GCClipMask | GCClipXOrigin | GCClipYOrigin,
  177.       &values);
  178.     XCopyArea(dpy, instance->logo, d, gc, 0, 0, LOGO_WIDTH, LOGO_HEIGHT, 0,
  179.       0);
  180.     values.clip_mask = (Pixmap) NULL;
  181.     XChangeGC(dpy, gc, GCClipMask | GCClipXOrigin | GCClipYOrigin,
  182.       &values);
  183. #endif
  184. }
  185. void DrawProgressBG(Display * dpy, Window w, nsPluginInstance * instance,
  186.     int x, int y, int width, int height)
  187. {
  188. #ifdef X_ENABLED
  189.     XGCValues values;
  190.     GC border_gc;
  191.     border_gc = XCreateGC(dpy, w, GCForeground, &values);
  192.     values.clip_mask = instance->progress_leftmask;
  193.     values.clip_x_origin = x - 10;
  194.     values.clip_y_origin = y - 10;
  195.     XChangeGC(dpy, border_gc, GCClipMask | GCClipXOrigin | GCClipYOrigin,
  196.       &values);
  197.     XCopyArea(dpy, instance->progress_left, (Drawable) w, border_gc, 0, 0,
  198.       10, 31, x - 10, y - 10);
  199.     values.clip_mask = (Pixmap) NULL;
  200.     XChangeGC(dpy, border_gc, GCClipMask | GCClipXOrigin | GCClipYOrigin,
  201.       &values);
  202.     XSetTile(dpy, border_gc, instance->progress_middle);
  203.     XSetFillStyle(dpy, border_gc, FillTiled);
  204.     XSetTSOrigin(dpy, border_gc, x, y - 10);
  205.     XFillRectangle(dpy, w, border_gc, x, y - 10, width, 31);
  206.     XSetFillStyle(dpy, border_gc, FillSolid);
  207.     values.clip_mask = instance->progress_rightmask;
  208.     values.clip_x_origin = x + width;
  209.     values.clip_y_origin = y - 10;
  210.     XChangeGC(dpy, border_gc, GCClipMask | GCClipXOrigin | GCClipYOrigin,
  211.       &values);
  212.     XCopyArea(dpy, instance->progress_right, (Drawable) w, border_gc, 0, 0,
  213.       10, 31, x + width, y - 10);
  214.     values.clip_mask = (Pixmap) NULL;
  215.     XChangeGC(dpy, border_gc, GCClipMask | GCClipXOrigin | GCClipYOrigin,
  216.       &values);
  217.     XFreeGC(dpy, border_gc);
  218. #endif
  219. }
  220. void DrawProgress(Display * dpy, Window w, nsPluginInstance * instance,
  221.   int x, int y, int width, int height, int percent)
  222. {
  223. #ifdef X_ENABLED
  224.     GC progress_gc;
  225.     int pixelpercent;
  226.     XGCValues values;
  227.     if (percent > 100)
  228. percent = 100;
  229.     progress_gc = XCreateGC(dpy, w, GCForeground, &values);
  230.     XSetTile(dpy, progress_gc, instance->progress_fill);
  231.     XSetFillStyle(dpy, progress_gc, FillTiled);
  232.     XSetTSOrigin(dpy, progress_gc, x, y);
  233.     pixelpercent = (int) ((width - x) * (percent / 100.));
  234.     XFillRectangle(dpy, w, progress_gc, x, y, pixelpercent, height);
  235.     XSetFillStyle(dpy, progress_gc, FillSolid);
  236.     XFreeGC(dpy, progress_gc);
  237. #endif
  238. }
  239. void DrawUI(Widget w, nsPluginInstance * instance, char *message,
  240.     int FullRedraw, int percent)
  241. {
  242. #ifdef X_ENABLED
  243.     GC black_gc, white_gc;
  244.     XGCValues values;
  245.     const char *id = "downloadplug-in v" PACKAGE_VERSION;
  246.     unsigned int id_width;
  247.     int top, font_height, loops;
  248.     int term, chop;
  249.     int PercentRedraw;
  250.     if (0) {
  251. printf("Widget: %in", (int) w);
  252. printf("Message: %sn", message);
  253.     }
  254.     if (DEBUG > 1)
  255. printf("state = %i, height = %i width = %in", instance->state,
  256.        instance->movie_height, instance->movie_width);
  257.     if (w == NULL)
  258. return;
  259.     if (instance->state < STATE_READY)
  260. return;
  261.     if (message == NULL)
  262. return;
  263.     if (instance->display == NULL)
  264. return;
  265.     if (instance->state == STATE_PLAYING && instance->movie_height > 0
  266. && instance->movie_width > 0)
  267. return;
  268.     sprintf(instance->lastmessage, "%s", message);
  269.     values.foreground =
  270. BlackPixel((Display *) instance->display,
  271.    DefaultScreen((Display *) instance->display));
  272.     black_gc =
  273. XCreateGC((Display *) instance->display,
  274.   (Drawable) instance->window, GCForeground, &values);
  275.     values.foreground =
  276. WhitePixel((Display *) instance->display,
  277.    DefaultScreen((Display *) instance->display));
  278.     white_gc =
  279. XCreateGC((Display *) instance->display,
  280.   (Drawable) instance->window, GCForeground, &values);
  281.     PercentRedraw = FALSE;
  282.     if (percent != -1 && instance->lastpercent != -1
  283. && instance->lastpercent > percent)
  284. PercentRedraw = TRUE;
  285.     if (instance->font == NULL) {
  286. FullRedraw = TRUE;
  287. Initialize((Display *) instance->display,
  288.    (Drawable) instance->window, instance, black_gc);
  289.     }
  290.     XFontSetExtents *extent;
  291.     extent = XExtentsOfFontSet(instance->font);
  292.     font_height = extent->max_logical_extent.height;
  293.     id_width = XmbTextEscapement(instance->font, id, strlen(id));
  294.     if (FullRedraw || instance->window_height <= 80) {
  295. XFillRectangle((Display *) instance->display,
  296.        (Drawable) instance->window, white_gc, 0, 0,
  297.        instance->window_width, instance->window_height);
  298.     } else {
  299. XFillRectangle((Display *) instance->display,
  300.        (Drawable) instance->window, white_gc, BORDER,
  301.        LOGO_HEIGHT, instance->window_width - BORDER * 2,
  302.        instance->window_height - font_height -
  303.        LOGO_HEIGHT - BORDER - 10);
  304.     }
  305.     if (instance->window_height > 80
  306. && instance->window_width > id_width + BORDER * 2) {
  307. top = BORDER * 2 + LOGO_HEIGHT;
  308. loops = 0;
  309. if (FullRedraw) {
  310.     DrawLogo((Display *) instance->display,
  311.      (Drawable) instance->window, instance, black_gc);
  312.     XmbDrawString((Display *) instance->display,
  313.   (Drawable) instance->window, instance->font,
  314.   black_gc,
  315.   instance->window_width - id_width - BORDER,
  316.   instance->window_height - font_height, id,
  317.   strlen(id));
  318. }
  319. if ((FullRedraw || PercentRedraw)
  320.     && instance->window_width > id_width + BORDER * 3 + 100)
  321.     // The height is set to 11 (my value for font_height)
  322.     // since the progress image only has 11 pixels of space
  323.     DrawProgressBG((Display *) instance->display,
  324.    (Drawable) instance->window,
  325.    instance,
  326.    BORDER,
  327.    instance->window_height - font_height - BORDER,
  328.    instance->window_width - id_width - BORDER * 3,
  329.    11);
  330. // Loop a max of 10 times in case of problems (like too small of a width)
  331. while (strlen(message) != 0 && loops < 10) {
  332.     chop = 0;
  333.     term = 0;
  334.     while (XmbTextEscapement
  335.    (instance->font, message,
  336.     strlen(message) - chop) + BORDER * 2 >
  337.    (int) instance->window_width)
  338. chop++;
  339.     if (strchr(message, 'n') != NULL &&
  340. (int) (strchr(message, 'n') - message) <
  341. (int) (strlen(message) - chop)) {
  342. chop = strlen(message) - (strchr(message, 'n') - message);
  343. term = 1;
  344.     }
  345.     XmbDrawString((Display *) instance->display,
  346.   (Drawable) instance->window, instance->font,
  347.   black_gc, BORDER, top, message,
  348.   strlen(message) - chop);
  349.     message += strlen(message) - chop + term;
  350.     top += font_height;
  351.     loops++;
  352.     if (top > (int) instance->window_height - font_height - BORDER)
  353. break;
  354. }
  355. // Make sure we have at least 100 px in addition to the id tag and borders
  356. if (percent != -1
  357.     && instance->window_width > id_width + BORDER * 3 + 100)
  358.     DrawProgress((Display *) instance->display,
  359.  (Drawable) instance->window,
  360.  instance,
  361.  BORDER,
  362.  instance->window_height - font_height - BORDER,
  363.  instance->window_width - id_width - BORDER * 3,
  364.  11, percent);
  365. else if (FullRedraw && instance->lastpercent != -1
  366.  && instance->window_width > id_width + BORDER * 3 + 100)
  367.     DrawProgress((Display *) instance->display,
  368.  (Drawable) instance->window,
  369.  instance,
  370.  BORDER,
  371.  instance->window_height - font_height - BORDER,
  372.  instance->window_width - id_width - BORDER * 3,
  373.  11, instance->lastpercent);
  374.     } else {
  375. XmbDrawString((Display *) instance->display,
  376.       (Drawable) instance->window, instance->font,
  377.       black_gc, BORDER, 15, message, strlen(message));
  378.     }
  379.     if (percent != -1)
  380. instance->lastpercent = percent;
  381.     XFreeGC((Display *) instance->display, black_gc);
  382.     XFreeGC((Display *) instance->display, white_gc);
  383.     XFlush((Display *) instance->display);
  384.     usleep(100);
  385. #endif
  386. }
  387. void FreeUI(Display * dpy, nsPluginInstance * instance)
  388. {
  389. #ifdef X_ENABLED
  390.     if (instance->font)
  391. XFreeFontSet(dpy, instance->font);
  392.     // Free all the pixmaps used by the GUI
  393.     if (instance->progress_left)
  394. XFreePixmap(dpy, instance->progress_left);
  395.     if (instance->progress_leftmask)
  396. XFreePixmap(dpy, instance->progress_leftmask);
  397.     if (instance->progress_middle)
  398. XFreePixmap(dpy, instance->progress_middle);
  399.     if (instance->progress_middlemask)
  400. XFreePixmap(dpy, instance->progress_middlemask);
  401.     if (instance->progress_right)
  402. XFreePixmap(dpy, instance->progress_right);
  403.     if (instance->progress_rightmask)
  404. XFreePixmap(dpy, instance->progress_rightmask);
  405.     if (instance->progress_fill)
  406. XFreePixmap(dpy, instance->progress_fill);
  407.     if (instance->progress_fillmask)
  408. XFreePixmap(dpy, instance->progress_fillmask);
  409.     if (instance->logo)
  410. XFreePixmap(dpy, instance->logo);
  411.     if (instance->logomask)
  412. XFreePixmap(dpy, instance->logomask);
  413.     // Don't free the font since we didn't create it
  414.     instance->logo = (Pixmap) NULL;
  415.     instance->logomask = (Pixmap) NULL;
  416.     instance->progress_left = (Pixmap) NULL;
  417.     instance->progress_leftmask = (Pixmap) NULL;
  418.     instance->progress_middle = (Pixmap) NULL;
  419.     instance->progress_middlemask = (Pixmap) NULL;
  420.     instance->progress_right = (Pixmap) NULL;
  421.     instance->progress_rightmask = (Pixmap) NULL;
  422.     instance->progress_fill = (Pixmap) NULL;
  423.     instance->progress_fillmask = (Pixmap) NULL;
  424.     instance->font = (XFontSet) NULL;
  425. #endif
  426. }
  427. void RedrawCB(Widget widget, XtPointer client_data, XtPointer call_data)
  428. {
  429.     char message[1024];
  430.     nsPluginInstance *instance = (nsPluginInstance *) client_data;
  431.     if (DEBUG)
  432. printf("redrawing windown");
  433.     if (instance->noredraw)
  434. return;
  435.     if (instance != NULL) {
  436. if (instance->lastmessage != NULL) {
  437.     if (strlen(instance->lastmessage) != 0) {
  438. if (instance->state >= STATE_GETTING_PLAYLIST) {
  439.     strcpy(message, instance->lastmessage);
  440. #ifdef X_ENABLED
  441.     DrawUI(instance->widget, instance, message, 1, -1);
  442. #endif
  443. }
  444.     }
  445. }
  446.     }
  447. }
  448. #ifdef GTK_ENABLED
  449. void play_callback(GtkWidget * widget, GdkEventExpose * event,
  450.    nsPluginInstance * instance)
  451. {
  452.     if (DEBUG)
  453. printf("play clickdn");
  454.     if (instance == NULL)
  455. return;
  456.     if (instance->panel_drawn == 0 && instance->controlsvisible == 1)
  457. return;
  458.     if (instance->controlsvisible == 1) {
  459. if (instance->panel_height > 16)
  460.     instance->panel_height = 16;
  461. instance->redrawbuttons = 1;
  462. gtk_container_remove(GTK_CONTAINER(instance->play_event_box),
  463.      instance->image_play);
  464. gtk_container_remove(GTK_CONTAINER(instance->pause_event_box),
  465.      instance->image_pause);
  466. gtk_container_remove(GTK_CONTAINER(instance->stop_event_box),
  467.      instance->image_stop);
  468. #ifdef GTK2_ENABLED
  469. instance->image_play =
  470.     gtk_image_new_from_pixbuf(instance->pb_sm_play_down);
  471. instance->image_pause =
  472.     gtk_image_new_from_pixbuf(instance->pb_sm_pause_up);
  473. instance->image_stop =
  474.     gtk_image_new_from_pixbuf(instance->pb_sm_stop_up);
  475. #endif
  476. #ifdef GTK1_ENABLED
  477. instance->image_play =
  478.     gtk_pixmap_new(instance->pb_sm_play_down, NULL);
  479. instance->image_pause =
  480.     gtk_pixmap_new(instance->pb_sm_pause_up, NULL);
  481. instance->image_stop =
  482.     gtk_pixmap_new(instance->pb_sm_stop_up, NULL);
  483. #endif
  484. gtk_container_add(GTK_CONTAINER(instance->play_event_box),
  485.   instance->image_play);
  486. gtk_container_add(GTK_CONTAINER(instance->pause_event_box),
  487.   instance->image_pause);
  488. gtk_container_add(GTK_CONTAINER(instance->stop_event_box),
  489.   instance->image_stop);
  490. if (instance->showbuttons) {
  491.     gtk_widget_show(instance->image_play);
  492.     gtk_widget_show(instance->image_pause);
  493.     gtk_widget_show(instance->image_stop);
  494.     gtk_widget_show(instance->play_event_box);
  495.     gtk_widget_show(instance->pause_event_box);
  496.     gtk_widget_show(instance->stop_event_box);
  497. }
  498. gtk_widget_show(instance->fixed_container);
  499. if (instance->drawing_area != NULL) {
  500.     gtk_widget_hide(GTK_WIDGET(instance->drawing_area));
  501.     gtk_widget_show(GTK_WIDGET(instance->drawing_area));
  502. }
  503. if (GTK_IS_WIDGET(instance->src_event_box)
  504.     && instance->targetplayer == 0) {
  505.     gtk_widget_hide(instance->src_event_box);
  506. }
  507. gdk_flush();
  508.     }
  509.     if (widget != NULL)
  510. instance->Play();
  511. }
  512. void pause_callback(GtkWidget * widget, GdkEventExpose * event,
  513.     nsPluginInstance * instance)
  514. {
  515.     if (DEBUG)
  516. printf("pause clickdn");
  517.     if (instance == NULL)
  518. return;
  519.     if (instance->panel_drawn == 0 && instance->controlsvisible == 1)
  520. return;
  521.     if (instance->controlsvisible == 1) {
  522. if (instance->panel_height > 16)
  523.     instance->panel_height = 16;
  524. gtk_container_remove(GTK_CONTAINER(instance->play_event_box),
  525.      instance->image_play);
  526. gtk_container_remove(GTK_CONTAINER(instance->pause_event_box),
  527.      instance->image_pause);
  528. gtk_container_remove(GTK_CONTAINER(instance->stop_event_box),
  529.      instance->image_stop);
  530. #ifdef GTK2_ENABLED
  531. instance->image_play =
  532.     gtk_image_new_from_pixbuf(instance->pb_sm_play_up);
  533. instance->image_pause =
  534.     gtk_image_new_from_pixbuf(instance->pb_sm_pause_down);
  535. instance->image_stop =
  536.     gtk_image_new_from_pixbuf(instance->pb_sm_stop_up);
  537. #endif
  538. #ifdef GTK1_ENABLED
  539. instance->image_play =
  540.     gtk_pixmap_new(instance->pb_sm_play_up, NULL);
  541. instance->image_pause =
  542.     gtk_pixmap_new(instance->pb_sm_pause_down, NULL);
  543. instance->image_stop =
  544.     gtk_pixmap_new(instance->pb_sm_stop_up, NULL);
  545. #endif
  546. gtk_container_add(GTK_CONTAINER(instance->play_event_box),
  547.   instance->image_play);
  548. gtk_container_add(GTK_CONTAINER(instance->pause_event_box),
  549.   instance->image_pause);
  550. gtk_container_add(GTK_CONTAINER(instance->stop_event_box),
  551.   instance->image_stop);
  552. if (instance->showbuttons) {
  553.     gtk_widget_show(instance->image_play);
  554.     gtk_widget_show(instance->image_pause);
  555.     gtk_widget_show(instance->image_stop);
  556.     gtk_widget_show(instance->play_event_box);
  557.     gtk_widget_show(instance->pause_event_box);
  558.     gtk_widget_show(instance->stop_event_box);
  559. }
  560. gtk_widget_show(instance->fixed_container);
  561. if (instance->drawing_area != NULL)
  562.     gtk_widget_show(GTK_WIDGET(instance->drawing_area));
  563. gdk_flush();
  564.     }
  565.     if (widget != NULL)
  566. instance->Pause();
  567. }
  568. void stop_callback(GtkWidget * widget, GdkEventExpose * event,
  569.    nsPluginInstance * instance)
  570. {
  571.     if (DEBUG)
  572. printf("stop clickdn");
  573.     if (instance == NULL)
  574. return;
  575.     if (instance->mInitialized == FALSE)
  576. return;
  577.     if (instance->panel_drawn == 0 && instance->controlsvisible == 1)
  578. return;
  579.     if (instance->controlsvisible == 1) {
  580. if (instance->panel_height > 16)
  581.     instance->panel_height = 16;
  582. gtk_container_remove(GTK_CONTAINER(instance->play_event_box),
  583.      instance->image_play);
  584. gtk_container_remove(GTK_CONTAINER(instance->pause_event_box),
  585.      instance->image_pause);
  586. gtk_container_remove(GTK_CONTAINER(instance->stop_event_box),
  587.      instance->image_stop);
  588. #ifdef GTK2_ENABLED
  589. instance->image_play =
  590.     gtk_image_new_from_pixbuf(instance->pb_sm_play_up);
  591. instance->image_pause =
  592.     gtk_image_new_from_pixbuf(instance->pb_sm_pause_up);
  593. instance->image_stop =
  594.     gtk_image_new_from_pixbuf(instance->pb_sm_stop_down);
  595. #endif
  596. #ifdef GTK1_ENABLED
  597. instance->image_play =
  598.     gtk_pixmap_new(instance->pb_sm_play_up, NULL);
  599. instance->image_pause =
  600.     gtk_pixmap_new(instance->pb_sm_pause_up, NULL);
  601. instance->image_stop =
  602.     gtk_pixmap_new(instance->pb_sm_stop_down, NULL);
  603. #endif
  604. gtk_container_add(GTK_CONTAINER(instance->play_event_box),
  605.   instance->image_play);
  606. gtk_container_add(GTK_CONTAINER(instance->pause_event_box),
  607.   instance->image_pause);
  608. gtk_container_add(GTK_CONTAINER(instance->stop_event_box),
  609.   instance->image_stop);
  610. if (instance->showbuttons) {
  611.     gtk_widget_show(instance->image_play);
  612.     gtk_widget_show(instance->image_pause);
  613.     gtk_widget_show(instance->image_stop);
  614.     gtk_widget_show(instance->play_event_box);
  615.     gtk_widget_show(instance->pause_event_box);
  616.     gtk_widget_show(instance->stop_event_box);
  617. }
  618. gtk_widget_show(instance->fixed_container);
  619. gtk_widget_hide(GTK_WIDGET(instance->progress_bar));
  620. if (instance->drawing_area != NULL) {
  621.     gtk_widget_hide(GTK_WIDGET(instance->drawing_area));
  622.     snprintf(instance->lastmessage, 1024, _("Stopped"));
  623.     g_idle_add(gtkgui_message, instance);
  624.     gtk_widget_hide(GTK_WIDGET(instance->mediaprogress_bar));
  625. }
  626. if (instance->showlogo)
  627.     if (GTK_IS_WIDGET(instance->image))
  628. gtk_widget_show(GTK_WIDGET(instance->image));
  629. if (!instance->hidestatus)
  630.     if (GTK_IS_WIDGET(instance->status))
  631. gtk_widget_show(GTK_WIDGET(instance->status));
  632. gdk_flush();
  633.     }
  634.     if (widget != NULL)
  635. instance->Stop();
  636. }
  637. void ff_callback(GtkWidget * widget, GdkEventExpose * event,
  638.  nsPluginInstance * instance)
  639. {
  640.     if (instance == NULL)
  641. return;
  642.     if (instance->panel_drawn == 0 && instance->controlsvisible == 1)
  643. return;
  644.     if (instance->controlsvisible == 1 && instance->mmsstream == 0) {
  645. if (instance->panel_height > 16)
  646.     instance->panel_height = 16;
  647. gtk_container_remove(GTK_CONTAINER(instance->ff_event_box),
  648.      instance->image_ff);
  649. #ifdef GTK2_ENABLED
  650. instance->image_ff =
  651.     gtk_image_new_from_pixbuf(instance->pb_sm_ff_down);
  652. #endif
  653. #ifdef GTK1_ENABLED
  654. instance->image_ff = gtk_pixmap_new(instance->pb_sm_ff_down, NULL);
  655. #endif
  656. gtk_container_add(GTK_CONTAINER(instance->ff_event_box),
  657.   instance->image_ff);
  658. if (instance->showbuttons) {
  659.     gtk_widget_show(instance->image_ff);
  660.     gtk_widget_show(instance->ff_event_box);
  661. }
  662. gdk_flush();
  663. instance->FastForward();
  664. usleep(500);
  665. gtk_container_remove(GTK_CONTAINER(instance->ff_event_box),
  666.      instance->image_ff);
  667. #ifdef GTK2_ENABLED
  668. instance->image_ff =
  669.     gtk_image_new_from_pixbuf(instance->pb_sm_ff_up);
  670. #endif
  671. #ifdef GTK1_ENABLED
  672. instance->image_ff = gtk_pixmap_new(instance->pb_sm_ff_up, NULL);
  673. #endif
  674. gtk_container_add(GTK_CONTAINER(instance->ff_event_box),
  675.   instance->image_ff);
  676. if (instance->showbuttons) {
  677.     gtk_widget_show(instance->image_ff);
  678.     gtk_widget_show(instance->ff_event_box);
  679. }
  680.     }
  681. }
  682. void rew_callback(GtkWidget * widget, GdkEventExpose * event,
  683.   nsPluginInstance * instance)
  684. {
  685.     if (instance == NULL)
  686. return;
  687.     if (instance->panel_drawn == 0 && instance->controlsvisible == 1)
  688. return;
  689.     if (instance->controlsvisible == 1 && instance->mmsstream == 0) {
  690. if (instance->panel_height > 16)
  691.     instance->panel_height = 16;
  692. gtk_container_remove(GTK_CONTAINER(instance->rew_event_box),
  693.      instance->image_rew);
  694. #ifdef GTK2_ENABLED
  695. instance->image_rew =
  696.     gtk_image_new_from_pixbuf(instance->pb_sm_rew_down);
  697. #endif
  698. #ifdef GTK1_ENABLED
  699. instance->image_rew =
  700.     gtk_pixmap_new(instance->pb_sm_rew_down, NULL);
  701. #endif
  702. gtk_container_add(GTK_CONTAINER(instance->rew_event_box),
  703.   instance->image_rew);
  704. if (instance->showbuttons) {
  705.     gtk_widget_show(instance->image_rew);
  706.     gtk_widget_show(instance->rew_event_box);
  707. }
  708. gdk_flush();
  709. instance->FastReverse();
  710. usleep(500);
  711. gtk_container_remove(GTK_CONTAINER(instance->rew_event_box),
  712.      instance->image_rew);
  713. #ifdef GTK2_ENABLED
  714. instance->image_rew =
  715.     gtk_image_new_from_pixbuf(instance->pb_sm_rew_up);
  716. #endif
  717. #ifdef GTK1_ENABLED
  718. instance->image_rew = gtk_pixmap_new(instance->pb_sm_rew_up, NULL);
  719. #endif
  720. gtk_container_add(GTK_CONTAINER(instance->rew_event_box),
  721.   instance->image_rew);
  722. if (instance->showbuttons) {
  723.     gtk_widget_show(instance->image_rew);
  724.     gtk_widget_show(instance->rew_event_box);
  725. }
  726.     }
  727. }
  728. void fs_callback(GtkWidget * widget, GdkEventExpose * event,
  729.  nsPluginInstance * instance)
  730. {
  731.     if (DEBUG)
  732. printf("fs_callback clickedn");
  733.     if (instance == NULL)
  734. return;
  735.     if (instance->panel_drawn == 0 && instance->controlsvisible == 1)
  736. return;
  737.     if (instance->controlsvisible == 1) {
  738. if (instance->panel_height > 16)
  739.     instance->panel_height = 16;
  740. gtk_container_remove(GTK_CONTAINER(instance->fs_event_box),
  741.      instance->image_fs);
  742. if (widget != NULL)
  743.     instance->SetFullscreen(!instance->fullscreen);
  744. if (instance->fullscreen == 0) {
  745. #ifdef GTK2_ENABLED
  746.     instance->image_fs =
  747. gtk_image_new_from_pixbuf(instance->pb_sm_fs_up);
  748. #endif
  749. #ifdef GTK1_ENABLED
  750.     instance->image_fs =
  751. gtk_pixmap_new(instance->pb_sm_fs_up, NULL);
  752. #endif
  753. } else {
  754. #ifdef GTK2_ENABLED
  755.     instance->image_fs =
  756. gtk_image_new_from_pixbuf(instance->pb_sm_fs_down);
  757. #endif
  758. #ifdef GTK1_ENABLED
  759.     instance->image_fs =
  760. gtk_pixmap_new(instance->pb_sm_fs_down, NULL);
  761. #endif
  762. }
  763. gtk_container_add(GTK_CONTAINER(instance->fs_event_box),
  764.   instance->image_fs);
  765. if (instance->showfsbutton && instance->showbuttons) {
  766.     gtk_widget_show(instance->image_fs);
  767.     gtk_widget_show(instance->fs_event_box);
  768. }
  769. gtk_widget_show(instance->fixed_container);
  770. gdk_flush();
  771.     }
  772. }
  773. gboolean keyboard_callback(GtkWidget * widget, GdkEventKey * event,
  774.    nsPluginInstance * instance)
  775. {
  776.     if (DEBUG)
  777. printf("In keyboard_callback with %in", event->keyval);
  778.     if ((event->keyval == GDK_P) || (event->keyval == GDK_p)
  779. || (event->keyval == GDK_space)) {
  780. if (instance->paused) {
  781.     play_callback(widget, (GdkEventExpose *) NULL, instance);
  782. } else {
  783.     pause_callback(widget, (GdkEventExpose *) NULL, instance);
  784. }
  785. return TRUE;
  786.     }
  787.     if ((event->keyval == GDK_S) || (event->keyval == GDK_s)) {
  788. stop_callback(widget, (GdkEventExpose *) NULL, instance);
  789. return TRUE;
  790.     }
  791.     if ((event->keyval == GDK_less) || (event->keyval == GDK_comma)) {
  792. rew_callback(widget, (GdkEventExpose *) NULL, instance);
  793. return TRUE;
  794.     }
  795.     if ((event->keyval == GDK_greater) || (event->keyval == GDK_period)) {
  796. ff_callback(widget, (GdkEventExpose *) NULL, instance);
  797. return TRUE;
  798.     }
  799.     if ((event->keyval == GDK_F) || (event->keyval == GDK_f)) {
  800. fs_callback(widget, (GdkEventExpose *) NULL, instance);
  801. return TRUE;
  802.     }
  803.     return FALSE;
  804. }
  805. gboolean mouse_callback(GtkWidget * widget, GdkEventButton * event,
  806. nsPluginInstance * instance)
  807. {
  808.     char buffer1[1024];
  809.     char buffer2[1024];
  810.     char *p;
  811.     if (DEBUG)
  812. printf("In mouse_callbackn");
  813.     if (event->type == GDK_BUTTON_PRESS) {
  814. if (DEBUG)
  815.     printf("button press # %in", event->button);
  816. if (event->button == 1) {
  817.     if (instance->mouseClickCallback != NULL)
  818. NPN_GetURL(instance->mInstance,
  819.    instance->mouseClickCallback, "_self");
  820. }
  821. if (instance->mouseDownCallback != NULL) {
  822.     strlcpy(buffer1, instance->mouseDownCallback, 1024);
  823.     p = index(buffer1, '(');
  824.     if (p == NULL) {
  825. p = buffer1 + strlen(buffer1);
  826.     }
  827.     *p = '';
  828.     snprintf(buffer2, 1024, "%s(%i);", buffer1, event->button);
  829.     NPN_MemFree(instance->mouseDownCallback);
  830.     instance->mouseDownCallback =
  831. (char *) NPN_MemAlloc(strlen(buffer2));
  832.     strlcpy(instance->mouseDownCallback, buffer2, strlen(buffer2));
  833.     NPN_GetURL(instance->mInstance,
  834.        instance->mouseDownCallback, "_self");
  835. }
  836.     }
  837.     if (event->type == GDK_BUTTON_RELEASE) {
  838. if (DEBUG)
  839.     printf("button released # %in", event->button);
  840. if (instance->mouseUpCallback != NULL) {
  841.     strlcpy(buffer1, instance->mouseUpCallback, 1024);
  842.     p = index(buffer1, '(');
  843.     if (p == NULL) {
  844. p = buffer1 + strlen(buffer1);
  845.     }
  846.     *p = '';
  847.     snprintf(buffer2, 1024, "%s(%i);", buffer1, event->button);
  848.     NPN_MemFree(instance->mouseUpCallback);
  849.     instance->mouseUpCallback =
  850. (char *) NPN_MemAlloc(strlen(buffer2));
  851.     strlcpy(instance->mouseUpCallback, buffer2, strlen(buffer2));
  852.     NPN_GetURL(instance->mInstance,
  853.        instance->mouseUpCallback, "_self");
  854. }
  855.     }
  856.     return FALSE;
  857. }
  858. gboolean mediaprogress_callback(GtkWidget * widget, GdkEventButton * event,
  859. nsPluginInstance * instance)
  860. {
  861.     GtkRequisition *req;
  862.     float percent;
  863.     float bytepercent;
  864.     float seektime;
  865.     req = (GtkRequisition *) NPN_MemAlloc(sizeof(GtkRequisition));
  866.     gtk_widget_size_request(widget, req);
  867.     percent = event->x / req->width;
  868.     if (instance->currentnode != NULL) {
  869. if (instance->currentnode->totalbytes != 0) {
  870.     bytepercent =
  871. (float) instance->currentnode->bytes /
  872. (float) instance->currentnode->totalbytes;
  873.     if (percent > bytepercent) {
  874. percent = bytepercent - 0.05;
  875.     }
  876. }
  877.     }
  878.     seektime = instance->mediaLength * percent;
  879.     if (DEBUG) {
  880. printf("widget size: %i x %in", req->width, req->height);
  881. printf("mouse click at %f x %fn", event->x, event->y);
  882. printf("percent = %fnseektime = %fn", percent, seektime);
  883.     }
  884.     if (seektime > 0)
  885. instance->Seek(seektime);
  886.     NPN_MemFree(req);
  887.     return TRUE;
  888. }
  889. gboolean mousenotify_callback(GtkWidget * widget, GdkEventCrossing * event,
  890.       nsPluginInstance * instance)
  891. {
  892.     if (event->type == GDK_ENTER_NOTIFY) {
  893. if (instance->mouseEnterCallback != NULL)
  894.     NPN_GetURL(instance->mInstance,
  895.        instance->mouseEnterCallback, "_self");
  896.     }
  897.     if (event->type == GDK_LEAVE_NOTIFY) {
  898. if (instance->mouseLeaveCallback != NULL)
  899.     NPN_GetURL(instance->mInstance,
  900.        instance->mouseLeaveCallback, "_self");
  901.     }
  902.     return FALSE;
  903. }
  904. gboolean gtkgui_draw(void *data)
  905. {
  906.     nsPluginInstance *instance;
  907.     GtkTooltips *tooltip;
  908.     instance = (nsPluginInstance *) data;
  909.     int width, height;
  910.     int multiplier;
  911.     int win_height, win_width;
  912.     if (instance == NULL)
  913. return FALSE;
  914.     if (DEBUG > 1)
  915. printf("panel_height = %inDrawn = %in", instance->panel_height,
  916.        instance->panel_drawn);
  917.     if (instance->mode == NP_EMBED && instance->window == 0)
  918. return FALSE;
  919.     if (instance->mode == NP_EMBED) {
  920. win_height = instance->embed_height;
  921. win_width = instance->embed_width;
  922.     } else {
  923. win_height = instance->window_height;
  924. win_width = instance->window_width;
  925.     }
  926.     if (instance->targetplayer == 1) {
  927. win_height = instance->movie_height + 16;
  928. win_width = instance->movie_width;
  929. if (instance->showcontrols && instance->movie_height)
  930.     instance->panel_height = 16;
  931.     }
  932.     if (instance->panel_drawn == 0 && instance->window != 0) {
  933. if (instance->mode == NP_FULL)
  934.     instance->panel_height = instance->window_height;
  935. if (instance->panel_height > 16)
  936.     instance->panel_height = 16;
  937. if (instance->panel_height <= 0)
  938.     if (instance->showcontrols) {
  939. instance->panel_height = 16;
  940.     } else {
  941. instance->panel_height = 0;
  942.     }
  943. if (DEBUG) {
  944.     printf("drawing paneln height = %i panel= %in",
  945.    win_height, instance->panel_height);
  946.     printf("showbuttons = %inshowcontrols = %in",
  947.    instance->showbuttons, instance->showcontrols);
  948. }
  949. if (instance->panel_height > 0 && instance->showcontrols == 1) {
  950. #ifdef GTK2_ENABLED
  951.     if (instance->autostart) {
  952. instance->image_play =
  953.     gtk_image_new_from_pixbuf(instance->pb_sm_play_down);
  954. instance->image_stop =
  955.     gtk_image_new_from_pixbuf(instance->pb_sm_stop_up);
  956.     } else {
  957. instance->image_play =
  958.     gtk_image_new_from_pixbuf(instance->pb_sm_play_up);
  959. instance->image_stop =
  960.     gtk_image_new_from_pixbuf(instance->pb_sm_stop_down);
  961.     }
  962.     instance->image_pause =
  963. gtk_image_new_from_pixbuf(instance->pb_sm_pause_up);
  964.     instance->image_ff =
  965. gtk_image_new_from_pixbuf(instance->pb_sm_ff_up);
  966.     instance->image_rew =
  967. gtk_image_new_from_pixbuf(instance->pb_sm_rew_up);
  968.     instance->image_fs =
  969. gtk_image_new_from_pixbuf(instance->pb_sm_fs_up);
  970. #endif
  971. #ifdef GTK1_ENABLED
  972.     if (instance->autostart) {
  973. instance->image_play =
  974.     gtk_pixmap_new(instance->pb_sm_play_down, NULL);
  975. instance->image_stop =
  976.     gtk_pixmap_new(instance->pb_sm_stop_up, NULL);
  977.     } else {
  978. instance->image_play =
  979.     gtk_pixmap_new(instance->pb_sm_play_up, NULL);
  980. instance->image_stop =
  981.     gtk_pixmap_new(instance->pb_sm_stop_down, NULL);
  982.     }
  983.     instance->image_pause =
  984. gtk_pixmap_new(instance->pb_sm_pause_up, NULL);
  985.     instance->image_ff =
  986. gtk_pixmap_new(instance->pb_sm_ff_up, NULL);
  987.     instance->image_rew =
  988. gtk_pixmap_new(instance->pb_sm_rew_up, NULL);
  989.     instance->image_fs =
  990. gtk_pixmap_new(instance->pb_sm_fs_up, NULL);
  991. #endif
  992.     width = SMALL_BUTTON_WIDTH;
  993.     height = SMALL_BUTTON_HEIGHT;
  994. #ifdef GTK2_ENABLED
  995.     g_signal_connect(G_OBJECT(instance->gtkwidget),
  996.      "key_press_event",
  997.      G_CALLBACK(keyboard_callback), instance);
  998. #endif
  999. #ifdef GTK1_ENABLED
  1000.     gtk_signal_connect(GTK_OBJECT(instance->gtkwidget),
  1001.        "key-press-event",
  1002.        GTK_SIGNAL_FUNC(keyboard_callback),
  1003.        instance);
  1004. #endif
  1005.     multiplier = 0;
  1006.     // rewind
  1007.     if ((instance->mmsstream == 0 && win_width > 126)
  1008. || instance->targetplayer == 1) {
  1009. instance->rew_event_box = gtk_event_box_new();
  1010. tooltip = gtk_tooltips_new();
  1011. gtk_tooltips_set_tip(tooltip, instance->rew_event_box,
  1012.      _("Rewind"), NULL);
  1013. gtk_widget_set_events(instance->rew_event_box,
  1014.       GDK_BUTTON_PRESS_MASK);
  1015. #ifdef GTK2_ENABLED
  1016. g_signal_connect(G_OBJECT(instance->rew_event_box),
  1017.  "button_press_event",
  1018.  G_CALLBACK(rew_callback), instance);
  1019. gtk_widget_set_size_request(GTK_WIDGET
  1020.     (instance->rew_event_box),
  1021.     width, height);
  1022. #endif
  1023. #ifdef GTK1_ENABLED
  1024. gtk_signal_connect(GTK_OBJECT(instance->rew_event_box),
  1025.    "button_press_event",
  1026.    GTK_SIGNAL_FUNC(rew_callback),
  1027.    instance);
  1028. gtk_widget_set_usize(GTK_WIDGET(instance->rew_event_box),
  1029.      width, height);
  1030. #endif
  1031. gtk_container_add(GTK_CONTAINER(instance->rew_event_box),
  1032.   instance->image_rew);
  1033. gtk_fixed_put(GTK_FIXED(instance->fixed_container),
  1034.       instance->rew_event_box,
  1035.       width * multiplier++, win_height - height);
  1036. if (instance->showbuttons) {
  1037.     gtk_widget_show(instance->image_rew);
  1038.     gtk_widget_show(instance->rew_event_box);
  1039. }
  1040.     }
  1041.     // play
  1042.     instance->play_event_box = gtk_event_box_new();
  1043.     tooltip = gtk_tooltips_new();
  1044.     gtk_tooltips_set_tip(tooltip, instance->play_event_box,
  1045.  _("Play"), NULL);
  1046.     gtk_widget_set_events(instance->play_event_box,
  1047.   GDK_BUTTON_PRESS_MASK);
  1048. #ifdef GTK2_ENABLED
  1049.     g_signal_connect(G_OBJECT(instance->play_event_box),
  1050.      "button_press_event",
  1051.      G_CALLBACK(play_callback), instance);
  1052.     gtk_widget_set_size_request(GTK_WIDGET
  1053. (instance->play_event_box), width,
  1054. height);
  1055. #endif
  1056. #ifdef GTK1_ENABLED
  1057.     gtk_signal_connect(GTK_OBJECT(instance->play_event_box),
  1058.        "button_press_event",
  1059.        GTK_SIGNAL_FUNC(play_callback), instance);
  1060.     gtk_widget_set_usize(GTK_WIDGET(instance->play_event_box),
  1061.  width, height);
  1062. #endif
  1063.     gtk_container_add(GTK_CONTAINER(instance->play_event_box),
  1064.       instance->image_play);
  1065.     gtk_fixed_put(GTK_FIXED(instance->fixed_container),
  1066.   instance->play_event_box, width * multiplier++,
  1067.   win_height - height);
  1068.     if (instance->showbuttons) {
  1069. gtk_widget_show(instance->image_play);
  1070. gtk_widget_show(instance->play_event_box);
  1071.     }
  1072.     // pause
  1073.     instance->pause_event_box = gtk_event_box_new();
  1074.     tooltip = gtk_tooltips_new();
  1075.     gtk_tooltips_set_tip(tooltip, instance->pause_event_box,
  1076.  _("Pause"), NULL);
  1077.     gtk_widget_set_events(instance->pause_event_box,
  1078.   GDK_BUTTON_PRESS_MASK);
  1079. #ifdef GTK2_ENABLED
  1080.     g_signal_connect(G_OBJECT(instance->pause_event_box),
  1081.      "button_press_event",
  1082.      G_CALLBACK(pause_callback), instance);
  1083.     gtk_widget_set_size_request(GTK_WIDGET
  1084. (instance->pause_event_box), width,
  1085. height);
  1086. #endif
  1087. #ifdef GTK1_ENABLED
  1088.     gtk_signal_connect(GTK_OBJECT(instance->pause_event_box),
  1089.        "button_press_event",
  1090.        GTK_SIGNAL_FUNC(pause_callback), instance);
  1091.     gtk_widget_set_usize(GTK_WIDGET(instance->pause_event_box),
  1092.  width, height);
  1093. #endif
  1094.     gtk_container_add(GTK_CONTAINER(instance->pause_event_box),
  1095.       instance->image_pause);
  1096.     if (win_width > 126 || instance->targetplayer == 1) {
  1097. gtk_fixed_put(GTK_FIXED(instance->fixed_container),
  1098.       instance->pause_event_box,
  1099.       width * multiplier++, win_height - height);
  1100. if (instance->showbuttons) {
  1101.     gtk_widget_show(instance->image_pause);
  1102.     gtk_widget_show(instance->pause_event_box);
  1103. }
  1104.     }
  1105.     // stop
  1106.     instance->stop_event_box = gtk_event_box_new();
  1107.     tooltip = gtk_tooltips_new();
  1108.     gtk_tooltips_set_tip(tooltip, instance->stop_event_box,
  1109.  _("Stop"), NULL);
  1110.     gtk_widget_set_events(instance->stop_event_box,
  1111.   GDK_BUTTON_PRESS_MASK);
  1112. #ifdef GTK2_ENABLED
  1113.     g_signal_connect(G_OBJECT(instance->stop_event_box),
  1114.      "button_press_event",
  1115.      G_CALLBACK(stop_callback), instance);
  1116.     gtk_widget_set_size_request(GTK_WIDGET
  1117. (instance->stop_event_box), width,
  1118. height);
  1119. #endif
  1120. #ifdef GTK1_ENABLED
  1121.     gtk_signal_connect(GTK_OBJECT(instance->stop_event_box),
  1122.        "button_press_event",
  1123.        GTK_SIGNAL_FUNC(stop_callback), instance);
  1124.     gtk_widget_set_usize(GTK_WIDGET(instance->stop_event_box),
  1125.  width, height);
  1126. #endif
  1127.     gtk_container_add(GTK_CONTAINER(instance->stop_event_box),
  1128.       instance->image_stop);
  1129.     gtk_fixed_put(GTK_FIXED(instance->fixed_container),
  1130.   instance->stop_event_box, width * multiplier++,
  1131.   win_height - height);
  1132.     if (instance->showbuttons) {
  1133. gtk_widget_show(instance->image_stop);
  1134. gtk_widget_show(instance->stop_event_box);
  1135.     }
  1136.     // fastforward
  1137.     if ((instance->mmsstream == 0 && win_width > 126)
  1138. || instance->targetplayer == 1) {
  1139. instance->ff_event_box = gtk_event_box_new();
  1140. tooltip = gtk_tooltips_new();
  1141. gtk_tooltips_set_tip(tooltip, instance->ff_event_box,
  1142.      _("Fast Forward"), NULL);
  1143. gtk_widget_set_events(instance->ff_event_box,
  1144.       GDK_BUTTON_PRESS_MASK);
  1145. #ifdef GTK2_ENABLED
  1146. g_signal_connect(G_OBJECT(instance->ff_event_box),
  1147.  "button_press_event",
  1148.  G_CALLBACK(ff_callback), instance);
  1149. gtk_widget_set_size_request(GTK_WIDGET
  1150.     (instance->ff_event_box),
  1151.     width, height);
  1152. #endif
  1153. #ifdef GTK1_ENABLED
  1154. gtk_signal_connect(GTK_OBJECT(instance->ff_event_box),
  1155.    "button_press_event",
  1156.    GTK_SIGNAL_FUNC(ff_callback), instance);
  1157. gtk_widget_set_usize(GTK_WIDGET(instance->ff_event_box),
  1158.      width, height);
  1159. #endif
  1160. gtk_container_add(GTK_CONTAINER(instance->ff_event_box),
  1161.   instance->image_ff);
  1162. gtk_fixed_put(GTK_FIXED(instance->fixed_container),
  1163.       instance->ff_event_box, width * multiplier++,
  1164.       win_height - height);
  1165. if (instance->showbuttons) {
  1166.     gtk_widget_show(instance->image_ff);
  1167.     gtk_widget_show(instance->ff_event_box);
  1168. }
  1169.     }
  1170. //          if ((int) (width * multiplier + 10) <
  1171. //              (int) (win_width - 10 - width)) {
  1172.     instance->mediaprogress_bar =
  1173. GTK_PROGRESS_BAR(gtk_progress_bar_new());
  1174.     gtk_widget_set_events(GTK_WIDGET
  1175.   (instance->mediaprogress_bar),
  1176.   GDK_BUTTON_PRESS_MASK);
  1177. #ifdef GTK2_ENABLED
  1178.     g_signal_connect(G_OBJECT(instance->mediaprogress_bar),
  1179.      "button_press_event",
  1180.      G_CALLBACK(mediaprogress_callback), instance);
  1181.     gtk_widget_set_size_request(GTK_WIDGET
  1182. (instance->mediaprogress_bar),
  1183. (win_width -
  1184.  width * multiplier - 20 - width),
  1185. height - 2);
  1186. #endif
  1187. #ifdef GTK1_ENABLED
  1188.     gtk_signal_connect(GTK_OBJECT(instance->mediaprogress_bar),
  1189.        "button_press_event",
  1190.        GTK_SIGNAL_FUNC(mediaprogress_callback),
  1191.        instance);
  1192.     gtk_widget_set_usize(GTK_WIDGET
  1193.  (instance->mediaprogress_bar),
  1194.  (win_width -
  1195.   width * multiplier - 20 - width),
  1196.  height - 2);
  1197. #endif
  1198.     gtk_fixed_put(GTK_FIXED(instance->fixed_container),
  1199.   GTK_WIDGET(instance->mediaprogress_bar),
  1200.   (width * multiplier + 10),
  1201.   win_height - height + 1);
  1202.     gtk_widget_realize(GTK_WIDGET(instance->mediaprogress_bar));
  1203. //          }
  1204.     if (instance->mode == NP_EMBED && instance->noembed == 0)
  1205. gtk_widget_hide(GTK_WIDGET(instance->progress_bar));
  1206.     // fullscreen
  1207.     instance->fs_event_box = gtk_event_box_new();
  1208.     tooltip = gtk_tooltips_new();
  1209.     gtk_tooltips_set_tip(tooltip, instance->fs_event_box,
  1210.  _("Full Screen"), NULL);
  1211.     gtk_widget_set_events(instance->fs_event_box,
  1212.   GDK_BUTTON_PRESS_MASK);
  1213. #ifdef GTK2_ENABLED
  1214.     g_signal_connect(G_OBJECT(instance->fs_event_box),
  1215.      "button_press_event",
  1216.      G_CALLBACK(fs_callback), instance);
  1217.     gtk_widget_set_size_request(GTK_WIDGET(instance->fs_event_box),
  1218. width, height);
  1219. #endif
  1220. #ifdef GTK1_ENABLED
  1221.     gtk_signal_connect(GTK_OBJECT(instance->fs_event_box),
  1222.        "button_press_event",
  1223.        GTK_SIGNAL_FUNC(fs_callback), instance);
  1224.     gtk_widget_set_usize(GTK_WIDGET(instance->fs_event_box), width,
  1225.  height);
  1226. #endif
  1227.     gtk_container_add(GTK_CONTAINER(instance->fs_event_box),
  1228.       instance->image_fs);
  1229.     if (win_width > 126 || instance->targetplayer == 1) {
  1230. gtk_fixed_put(GTK_FIXED(instance->fixed_container),
  1231.       instance->fs_event_box,
  1232.       win_width - width, win_height - height);
  1233. if (instance->showfsbutton && instance->showbuttons) {
  1234.     gtk_widget_show(instance->image_fs);
  1235.     gtk_widget_show(instance->fs_event_box);
  1236. }
  1237.     }
  1238.     gtk_widget_show(instance->fixed_container);
  1239.     if (instance->targetplayer == 0)
  1240. gtk_widget_show(instance->gtkwidget);
  1241.     instance->controlsvisible = 1;
  1242.     instance->panel_drawn = 1;
  1243. }
  1244.     }
  1245.     return FALSE;
  1246. }
  1247. gboolean gtkgui_message(void *data)
  1248. {
  1249.     nsPluginInstance *instance;
  1250.     if (DEBUG > 1)
  1251. printf("in gtkgui_messagen");
  1252.     instance = (nsPluginInstance *) data;
  1253.     if (instance == NULL)
  1254. return FALSE;
  1255.     if (instance->mInitialized == FALSE)
  1256. return FALSE;
  1257.     if (instance->status != NULL && instance->lastmessage != NULL)
  1258. if (GTK_IS_LABEL(instance->status))
  1259.     gtk_label_set_text(instance->status, instance->lastmessage); //GTK_LABEL
  1260.     if (instance->js_state == JS_STATE_TRANSITIONING) {
  1261. if (GTK_IS_WIDGET(instance->image) && instance->showlogo)
  1262.     gtk_widget_show(GTK_WIDGET(instance->image));
  1263. if (GTK_IS_WIDGET(instance->status) && (!(instance->hidestatus)))
  1264.     gtk_widget_show(GTK_WIDGET(instance->status));
  1265.     }
  1266.     return FALSE;
  1267. }
  1268. gboolean gtkgui_progress(void *data)
  1269. {
  1270.     nsPluginInstance *instance;
  1271.     if (DEBUG > 1)
  1272. printf("in gtkgui_progressn");
  1273.     instance = (nsPluginInstance *) data;
  1274.     if (instance == NULL)
  1275. return FALSE;
  1276.     if (instance->progress_bar != NULL) {
  1277. if (GTK_IS_PROGRESS_BAR(instance->progress_bar)) {
  1278.     if ((instance->percent > 0.0) && (instance->percent < 1.0)) {
  1279. if (instance->movie_height == 0
  1280.     && instance->movie_width == 0)
  1281.     if (!(instance->hidestatus))
  1282. gtk_widget_show(GTK_WIDGET
  1283. (instance->progress_bar));
  1284. gtk_progress_bar_update(instance->progress_bar,
  1285. instance->percent);
  1286.     }
  1287.     if (instance->percent >= 0.99 || instance->percent == 0)
  1288. gtk_widget_hide(GTK_WIDGET(instance->progress_bar));
  1289. }
  1290.     }
  1291.     if (instance->js_state == JS_STATE_TRANSITIONING) {
  1292. if (GTK_IS_WIDGET(instance->image) && instance->showlogo)
  1293.     gtk_widget_show(GTK_WIDGET(instance->image));
  1294. if (GTK_IS_WIDGET(instance->status) && (!(instance->hidestatus)))
  1295.     gtk_widget_show(GTK_WIDGET(instance->status));
  1296.     }
  1297.     return FALSE;
  1298. }
  1299. gboolean gtkgui_resize(void *data)
  1300. {
  1301.     nsPluginInstance *instance;
  1302.     int new_width, new_height;
  1303.     instance = (nsPluginInstance *) data;
  1304.     if (instance == NULL)
  1305. return FALSE;
  1306.     if (instance->mInitialized == FALSE)
  1307. return FALSE;
  1308.     new_width = instance->movie_width;
  1309.     new_height = instance->movie_height;
  1310.     if (DEBUG > 1)
  1311. printf("in resize methodnNew size is %i x %in",
  1312.        instance->movie_width, instance->movie_height);
  1313.     if (instance->drawing_area != NULL) {
  1314. if (GTK_IS_WIDGET(instance->drawing_area)) {
  1315.     if (GTK_IS_WIDGET(instance->progress_bar))
  1316. gtk_widget_hide(GTK_WIDGET(instance->progress_bar));
  1317.     if (instance->mode == NP_FULL) {
  1318. if ((instance->movie_width + 10 >= instance->window_width)
  1319.     || (instance->movie_height + 100 >=
  1320. instance->window_height)) {
  1321.     if (instance->fullscreen == 0) {
  1322. if (GTK_IS_CONTAINER(instance->fixed_container)) {
  1323.     if (GTK_IS_WIDGET(instance->image))
  1324. gtk_widget_hide(GTK_WIDGET
  1325. (instance->image));
  1326.     if (GTK_IS_WIDGET(instance->status))
  1327. gtk_widget_hide(GTK_WIDGET
  1328. (instance->status));
  1329.     if (GTK_IS_WIDGET(instance->mediaprogress_bar))
  1330. gtk_widget_hide(GTK_WIDGET
  1331. (instance->
  1332.  mediaprogress_bar));
  1333.     instance->showtracker = 0;
  1334.     if (gtk_widget_get_parent_window(instance->drawing_area) == NULL) { 
  1335. gtk_fixed_put(GTK_FIXED
  1336.       (instance->fixed_container),
  1337.       instance->drawing_area, 0, 0);
  1338.     }
  1339. }
  1340.     }
  1341. }
  1342. if (instance->showcontrols) {
  1343.     if (instance->movie_width > instance->window_width
  1344. || instance->movie_height >
  1345. (instance->window_height - 17)) {
  1346. if (instance->movie_width > instance->window_width) {
  1347.     new_width = instance->window_width;
  1348.     new_height =
  1349. (instance->window_width *
  1350.  (instance->movie_height -
  1351.   17)) / instance->movie_width;
  1352. }
  1353. if (instance->movie_height >
  1354.     (instance->window_height - 17)) {
  1355.     new_height = (instance->window_height - 17);
  1356.     new_width =
  1357. ((instance->window_height -
  1358.   17) * instance->movie_width) /
  1359. instance->movie_height;
  1360. }
  1361.     } else {
  1362. new_width = instance->movie_width;
  1363. new_height = instance->movie_height;
  1364.     }
  1365. } else {
  1366.     if (instance->movie_width > instance->window_width
  1367. || instance->movie_height >
  1368. instance->window_height) {
  1369. if (instance->movie_width > instance->window_width) {
  1370.     new_width = instance->window_width;
  1371.     new_height =
  1372. (instance->window_width *
  1373.  instance->movie_height) /
  1374. instance->movie_width;
  1375. }
  1376. if (instance->movie_height >
  1377.     instance->window_height) {
  1378.     new_height = instance->window_height;
  1379.     new_width =
  1380. (instance->window_height *
  1381.  instance->movie_width) /
  1382. instance->movie_height;
  1383. }
  1384.     } else {
  1385. new_width = instance->movie_width;
  1386. new_height = instance->movie_height;
  1387.     }
  1388. }
  1389. gtk_widget_set_usize(instance->drawing_area,
  1390.      new_width, new_height);
  1391. if ((instance->movie_width + 10) >= instance->window_width
  1392.     || (instance->movie_height + 100) >=
  1393.     instance->window_height) {
  1394.     gtk_fixed_put(GTK_FIXED(instance->fixed_container),
  1395.   instance->drawing_area, 0, 0);
  1396.     if (GTK_IS_WIDGET(instance->image))
  1397. gtk_widget_hide(GTK_WIDGET(instance->image));
  1398.     if (GTK_IS_WIDGET(instance->status))
  1399. gtk_widget_hide(GTK_WIDGET(instance->status));
  1400.     if (GTK_IS_WIDGET(instance->mediaprogress_bar))
  1401. gtk_widget_hide(GTK_WIDGET
  1402. (instance->mediaprogress_bar));
  1403. } else {
  1404.     if (gtk_widget_get_parent_window(instance->drawing_area) == NULL) { 
  1405. gtk_fixed_put(GTK_FIXED
  1406.       (instance->fixed_container),
  1407.       instance->drawing_area, 10, 100);
  1408.     }
  1409.     if (GTK_IS_WIDGET(instance->image))
  1410. gtk_widget_show(GTK_WIDGET(instance->image));
  1411.     if (GTK_IS_WIDGET(instance->status))
  1412. gtk_widget_show(GTK_WIDGET(instance->status));
  1413. }
  1414.     } else {
  1415. if (instance->targetplayer && instance->showcontrols) {
  1416.     gtk_widget_set_usize(instance->drawing_area,
  1417.  instance->movie_width,
  1418.  instance->movie_height + 16);
  1419. } else {
  1420.     if (instance->showcontrols) {
  1421. if (instance->movie_height >
  1422.     (instance->window_height - 16)) {
  1423.     gtk_widget_set_usize(GTK_WIDGET
  1424.  (instance->drawing_area),
  1425.  instance->movie_width,
  1426.  instance->window_height -
  1427.  16);
  1428. } else {
  1429.     gtk_widget_set_usize(GTK_WIDGET
  1430.  (instance->drawing_area),
  1431.  instance->movie_width,
  1432.  instance->movie_height);
  1433. }
  1434.     } else {
  1435. gtk_widget_set_usize(GTK_WIDGET
  1436.      (instance->drawing_area),
  1437.      instance->movie_width,
  1438.      instance->movie_height);
  1439.     }
  1440. }
  1441.     }
  1442. }
  1443.     }
  1444.     if (instance->targetplayer == 1) {
  1445. #ifdef GTK2_ENABLED
  1446. gtk_widget_set_size_request(instance->gtkwidget,
  1447.     instance->movie_width,
  1448.     instance->movie_height);
  1449. gtk_widget_set_size_request(instance->drawing_area,
  1450.     instance->movie_width,
  1451.     instance->movie_height);
  1452. gtk_window_resize(GTK_WINDOW(instance->gtkwidget),
  1453.   instance->movie_width,
  1454.   instance->movie_height + 16);
  1455. #endif
  1456. #ifdef GTK1_ENABLED
  1457. gtk_widget_set_usize(instance->gtkwidget,
  1458.      instance->movie_width,
  1459.      instance->movie_height + 16);
  1460. gtk_widget_set_usize(instance->drawing_area,
  1461.      instance->movie_width,
  1462.      instance->movie_height + 16);
  1463. #endif
  1464. instance->redrawbuttons = 1;
  1465. gtkgui_updatebuttons(data);
  1466.     }
  1467.     return FALSE;
  1468. }
  1469. gboolean gtkgui_stop(void *data)
  1470. {
  1471.     nsPluginInstance *instance;
  1472.     if (DEBUG > 1)
  1473. printf("in gtkgui_stopn");
  1474.     instance = (nsPluginInstance *) data;
  1475.     if (instance == NULL)
  1476. return FALSE;
  1477.     if (instance->mInitialized == FALSE)
  1478. return FALSE;
  1479.     if (instance->cancelled == 1)
  1480. return FALSE;
  1481.     stop_callback(NULL, NULL, instance);
  1482.     instance->SetFullscreen(0);
  1483.     if (DEBUG > 1)
  1484. printf("completed gtkgui_stopn");
  1485.     gtkgui_resize(data);
  1486.     gtk_widget_hide(instance->drawing_area);
  1487.     return FALSE;
  1488. }
  1489. gboolean gtkgui_save_enable(void *data)
  1490. {
  1491.     nsPluginInstance *instance;
  1492. #ifdef GTK2_ENABLED
  1493.     char *filename;
  1494.     char newlabel[1024];
  1495.     GtkLabel *label;
  1496. #endif
  1497.     if (DEBUG > 1)
  1498. printf("in gtkgui_save_enablen");
  1499.     instance = (nsPluginInstance *) data;
  1500.     if (instance == NULL)
  1501. return FALSE;
  1502.     if (instance->mInitialized == FALSE)
  1503. return FALSE;
  1504.     if (instance->currentnode == NULL)
  1505. return FALSE;
  1506.     if (instance->js_state != JS_STATE_PLAYING)
  1507. return FALSE;
  1508.     if (!isMms(instance->currentnode->url, instance->nomediacache)) {
  1509. pthread_mutex_lock(&(instance->playlist_mutex));
  1510. if (DEBUG > 1)
  1511.     printf("Save Enable called retrieved = %in",
  1512.    instance->currentnode->retrieved);
  1513. #ifdef GTK2_ENABLED
  1514. filename = getURLFilename(instance->currentnode->url);
  1515. if (filename != NULL) {
  1516.     snprintf(newlabel, 1024, _("Save as %s/%s"),
  1517.      instance->download_dir, filename);
  1518.     NPN_MemFree(filename);
  1519. } else {
  1520.     snprintf(newlabel, 1024, _("Save"));
  1521. }
  1522. if (GTK_IS_BIN(instance->menuitem_save)) {
  1523.     label =
  1524. GTK_LABEL(gtk_bin_get_child
  1525.   (GTK_BIN(instance->menuitem_save)));
  1526.     gtk_label_set_text(label, newlabel);
  1527. }
  1528. #endif
  1529. pthread_mutex_unlock(&(instance->playlist_mutex));
  1530. gtk_widget_set_sensitive(GTK_WIDGET(instance->menuitem_save),
  1531.  instance->currentnode->retrieved);
  1532.     } else {
  1533. #ifdef GTK2_ENABLED
  1534. snprintf(newlabel, 1024, _("Append URL to %s/playlist"),
  1535.  instance->download_dir);
  1536. label =
  1537.     GTK_LABEL(gtk_bin_get_child(GTK_BIN(instance->menuitem_save)));
  1538. gtk_label_set_text(label, newlabel);
  1539. #endif
  1540. gtk_widget_set_sensitive(GTK_WIDGET(instance->menuitem_save),
  1541.  TRUE);
  1542.     }
  1543.     return FALSE;
  1544. }
  1545. gboolean gtkgui_drawMediaProgress(void *data)
  1546. {
  1547.     nsPluginInstance *instance;
  1548.     int hour = 0, min = 0, length_hour = 0, length_min = 0;
  1549.     long int seconds, length_seconds;
  1550.     char display[35];
  1551.     if (DEBUG > 1)
  1552. printf("in drawMediaProgress methodn");
  1553.     instance = (nsPluginInstance *) data;
  1554.     if (instance == NULL)
  1555. return FALSE;
  1556.     if (instance->mInitialized == FALSE)
  1557. return FALSE;
  1558.     if (instance->mediaprogress_bar != NULL) {
  1559. if (GTK_IS_PROGRESS_BAR(instance->mediaprogress_bar)) {
  1560.     if (((int) instance->mediaLength > 0)
  1561. && (instance->mediaPercent <= 100)) {
  1562. if (instance->controlsvisible && instance->showtracker) {
  1563.     gtk_widget_show(GTK_WIDGET
  1564.     (instance->mediaprogress_bar));
  1565.     gtk_progress_bar_update(instance->mediaprogress_bar,
  1566.     instance->mediaPercent /
  1567.     100.0);
  1568. #ifdef GTK2_ENABLED
  1569.     if (((int) instance->mediaTime > 0)
  1570. && (instance->showtime == 1)) {
  1571. seconds = (int) instance->mediaTime;
  1572. if (seconds >= 3600) {
  1573.     hour = seconds / 3600;
  1574.     seconds = seconds - (hour * 3600);
  1575. }
  1576. if (seconds >= 60) {
  1577.     min = seconds / 60;
  1578.     seconds = seconds - (min * 60);
  1579. }
  1580. length_seconds = (int) instance->mediaLength;
  1581. if (length_seconds >= 3600) {
  1582.     length_hour = length_seconds / 3600;
  1583.     length_seconds =
  1584. length_seconds - (length_hour * 3600);
  1585. }
  1586. if (length_seconds >= 60) {
  1587.     length_min = length_seconds / 60;
  1588.     length_seconds =
  1589. length_seconds - (length_min * 60);
  1590. }
  1591. if ((int) (instance->percent * 100) > 0
  1592.     && (int) (instance->percent * 100) < 99
  1593.     && instance->mmsstream == 0) {
  1594.     if (hour == 0 && length_hour == 0) {
  1595. snprintf(display, 30,
  1596.  _
  1597.  ("%2i:%02i / %2i:%02i | %2i%% 342226274"),
  1598.  min, (int) seconds, length_min,
  1599.  (int) length_seconds,
  1600.  (int) (instance->percent * 100));
  1601.     } else {
  1602. snprintf(display, 30,
  1603.  _
  1604.  ("%i:%02i:%02i / %i:%02i:%02i | %2i%% 342226274"),
  1605.  hour, min, (int) seconds,
  1606.  length_hour, length_min,
  1607.  (int) length_seconds,
  1608.  (int) (instance->percent * 100));
  1609.     }
  1610. } else {
  1611.     if (hour == 0 && length_hour == 0) {
  1612. snprintf(display, 30,
  1613.  "%2i:%02i / %2i:%02i", min,
  1614.  (int) seconds, length_min,
  1615.  (int) length_seconds);
  1616.     } else {
  1617. snprintf(display, 30,
  1618.  "%i:%02i:%02i / %i:%02i:%02i",
  1619.  hour, min, (int) seconds,
  1620.  length_hour, length_min,
  1621.  (int) length_seconds);
  1622.     }
  1623. }
  1624. gtk_progress_bar_set_text(instance->
  1625.   mediaprogress_bar,
  1626.   display);
  1627.     } else {
  1628. if ((int) (instance->percent * 100) > 0
  1629.     && (int) (instance->percent * 100) < 99
  1630.     && instance->mmsstream == 0) {
  1631.     snprintf(display, 30, _("%2i%% 342226274"),
  1632.      (int) (instance->percent * 100));
  1633.     if (gtk_progress_bar_get_text
  1634. (instance->mediaprogress_bar) != NULL)
  1635. gtk_progress_bar_set_text(instance->
  1636.   mediaprogress_bar,
  1637.   display);
  1638. } else {
  1639.     if (gtk_progress_bar_get_text
  1640. (instance->mediaprogress_bar) != NULL)
  1641. gtk_progress_bar_set_text(instance->
  1642.   mediaprogress_bar,
  1643.   NULL);
  1644. }
  1645.     }
  1646. #endif
  1647. } else {
  1648.     gtk_widget_hide(GTK_WIDGET
  1649.     (instance->mediaprogress_bar));
  1650. }
  1651.     } else {
  1652. gtk_widget_hide(GTK_WIDGET(instance->mediaprogress_bar));
  1653.     }
  1654. }
  1655.     }
  1656.     if (instance->movie_width != 0 && instance->movie_height != 0) {
  1657. if (GTK_IS_WIDGET(instance->progress_bar))
  1658.     gtk_widget_hide(GTK_WIDGET(instance->progress_bar));
  1659.     }
  1660.     return FALSE;
  1661. }
  1662. gboolean gtkgui_refreshbuttonstate(void *data)
  1663. {
  1664.     nsPluginInstance *instance;
  1665.     if (DEBUG > 1)
  1666. printf("in refreshbuttonstate methodn");
  1667.     instance = (nsPluginInstance *) data;
  1668.     if (instance == NULL)
  1669. return FALSE;
  1670.     if (instance->mInitialized == FALSE)
  1671. return FALSE;
  1672.     if (instance->panel_drawn == 1 && instance->controlsvisible) {
  1673. if (instance->mmsstream == 0) {
  1674.     if (instance->rew_event_box != NULL) {
  1675. if (instance->showcontrols && instance->showbuttons
  1676.     && instance->controlsvisible) {
  1677.     if (instance->redrawbuttons)
  1678. gtk_widget_hide(GTK_WIDGET
  1679. (instance->rew_event_box));
  1680.     gtk_widget_show(GTK_WIDGET(instance->rew_event_box));
  1681. }
  1682.     }
  1683. } else {
  1684.     if (GTK_IS_WIDGET(instance->rew_event_box))
  1685. gtk_widget_hide(GTK_WIDGET(instance->rew_event_box));
  1686. }
  1687. if (instance->mmsstream == 0) {
  1688.     if (instance->ff_event_box != NULL) {
  1689. if (instance->showcontrols && instance->showbuttons
  1690.     && instance->controlsvisible) {
  1691.     if (instance->redrawbuttons)
  1692. gtk_widget_hide(GTK_WIDGET
  1693. (instance->ff_event_box));
  1694.     gtk_widget_show(GTK_WIDGET(instance->ff_event_box));
  1695. }
  1696.     }
  1697. } else {
  1698.     if (GTK_IS_WIDGET(instance->ff_event_box))
  1699. gtk_widget_hide(GTK_WIDGET(instance->ff_event_box));
  1700. }
  1701. if (instance->showcontrols && instance->showbuttons
  1702.     && instance->controlsvisible) {
  1703.     if (instance->redrawbuttons) {
  1704. gtk_widget_hide(GTK_WIDGET(instance->play_event_box));
  1705. gtk_widget_hide(GTK_WIDGET(instance->pause_event_box));
  1706. gtk_widget_hide(GTK_WIDGET(instance->stop_event_box));
  1707. gtk_widget_hide(GTK_WIDGET(instance->fs_event_box));
  1708.     }
  1709.     gtk_widget_show(GTK_WIDGET(instance->play_event_box));
  1710.     gtk_widget_show(GTK_WIDGET(instance->pause_event_box));
  1711.     gtk_widget_show(GTK_WIDGET(instance->stop_event_box));
  1712.     gtk_widget_show(GTK_WIDGET(instance->fs_event_box));
  1713. }
  1714.     }
  1715.     instance->redrawbuttons = 0;
  1716. //    gtk_widget_queue_draw_area(instance->gtkwidget,0,0,instance->embed_width,instance->embed_height);
  1717.     return FALSE;
  1718. }
  1719. gboolean gtkgui_updatebuttons(void *data)
  1720. {
  1721.     nsPluginInstance *instance;
  1722.     int height, width, multiplier;
  1723.     int win_height, win_width;
  1724.     if (DEBUG > 1)
  1725. printf("in updatebuttons methodn");
  1726.     instance = (nsPluginInstance *) data;
  1727.     if (instance == NULL)
  1728. return FALSE;
  1729.     if (instance->mInitialized == FALSE)
  1730. return FALSE;
  1731.     if (instance->mode == NP_EMBED) {
  1732. win_height = instance->embed_height;
  1733. win_width = instance->embed_width;
  1734.     } else {
  1735. win_height = instance->window_height;
  1736. win_width = instance->window_width;
  1737.     }
  1738.     if (instance->targetplayer) {
  1739. win_height = instance->movie_height + 16;
  1740. win_width = instance->movie_width;
  1741.     }
  1742.     if (DEBUG)
  1743. printf("buttons are at %i x %in", win_height, win_width);
  1744.     if (instance->panel_drawn == 1) {
  1745. height = 16;
  1746. width = 21;
  1747. multiplier = 0;
  1748. if (instance->mmsstream == 0) {
  1749.     if (instance->rew_event_box != NULL) {
  1750. if (instance->showcontrols && instance->showbuttons) {
  1751.     gtk_widget_show(GTK_WIDGET(instance->rew_event_box));
  1752.     gtk_fixed_move(GTK_FIXED
  1753.    (instance->fixed_container),
  1754.    GTK_WIDGET(instance->rew_event_box),
  1755.    width * multiplier++,
  1756.    win_height - height);
  1757. }
  1758.     }
  1759. } else {
  1760.     if (GTK_IS_WIDGET(instance->rew_event_box)) {
  1761.      gtk_widget_hide(GTK_WIDGET(instance->rew_event_box));
  1762.     }
  1763. }
  1764. gtk_fixed_move(GTK_FIXED(instance->fixed_container),
  1765.        GTK_WIDGET(instance->play_event_box),
  1766.        width * multiplier++, win_height - height);
  1767. gtk_fixed_move(GTK_FIXED(instance->fixed_container),
  1768.        GTK_WIDGET(instance->pause_event_box),
  1769.        width * multiplier++, win_height - height);
  1770. gtk_fixed_move(GTK_FIXED(instance->fixed_container),
  1771.        GTK_WIDGET(instance->stop_event_box),
  1772.        width * multiplier++, win_height - height);
  1773. if (instance->mmsstream == 0) {
  1774.     if (instance->ff_event_box != NULL) {
  1775. if (instance->showcontrols && instance->showbuttons) {
  1776.     gtk_widget_show(GTK_WIDGET(instance->rew_event_box));
  1777.     gtk_fixed_move(GTK_FIXED
  1778.    (instance->fixed_container),
  1779.    GTK_WIDGET(instance->ff_event_box),
  1780.    width * multiplier++,
  1781.    win_height - height);
  1782. }
  1783.     }
  1784. } else {
  1785.     if (GTK_IS_WIDGET(instance->ff_event_box)) {
  1786.      gtk_widget_hide(GTK_WIDGET(instance->ff_event_box));
  1787.     }
  1788. }
  1789. gtk_fixed_move(GTK_FIXED(instance->fixed_container),
  1790.        GTK_WIDGET(instance->mediaprogress_bar),
  1791.        (width * multiplier + 10), win_height - height + 2);
  1792. gtk_fixed_move(GTK_FIXED(instance->fixed_container),
  1793.        GTK_WIDGET(instance->fs_event_box),
  1794.        (win_width - width), win_height - height + 2);
  1795. gtk_widget_show(GTK_WIDGET(instance->mediaprogress_bar));
  1796. gtk_widget_set_usize(GTK_WIDGET(instance->mediaprogress_bar),
  1797.      win_width - (width * (multiplier + 1) +
  1798.   20), height - 4);
  1799.     }
  1800.     return FALSE;
  1801. }
  1802. gboolean gtkgui_updatefullscreen(void *data)
  1803. {
  1804.     nsPluginInstance *instance;
  1805.     if (DEBUG > 1)
  1806. printf("in updatefullscreen methodn");
  1807.     instance = (nsPluginInstance *) data;
  1808.     if (instance == NULL)
  1809. return FALSE;
  1810.     if (instance->mInitialized == FALSE)
  1811. return FALSE;
  1812.     instance->SetFullscreen(instance->fullscreen);
  1813.     return FALSE;
  1814. }
  1815. gint popup_handler(GtkWidget * widget, GdkEvent * event)
  1816. {
  1817.     GtkMenu *menu;
  1818.     GdkEventButton *event_button;
  1819.     if (DEBUG)
  1820. printf("popup menu callbackn");
  1821.     menu = GTK_MENU(widget);
  1822.     if (DEBUG)
  1823. printf("event type # %in", event->type);
  1824.     if (event->type == GDK_BUTTON_PRESS) {
  1825. event_button = (GdkEventButton *) event;
  1826. if (DEBUG)
  1827.     printf("button press # %in", event_button->button);
  1828. if (event_button->button == 3) {
  1829.     gtk_menu_popup(menu, NULL, NULL, NULL, NULL,
  1830.    event_button->button, event_button->time);
  1831.     return TRUE;
  1832. }
  1833.     }
  1834.     return FALSE;
  1835. }
  1836. void menuitem_play_callback(GtkMenuItem * menuitem,
  1837.     nsPluginInstance * instance)
  1838. {
  1839.     play_callback(GTK_WIDGET(menuitem), NULL, instance);
  1840. }
  1841. void menuitem_pause_callback(GtkMenuItem * menuitem,
  1842.      nsPluginInstance * instance)
  1843. {
  1844.     pause_callback(GTK_WIDGET(menuitem), NULL, instance);
  1845. }
  1846. void menuitem_stop_callback(GtkMenuItem * menuitem,
  1847.     nsPluginInstance * instance)
  1848. {
  1849.     stop_callback(GTK_WIDGET(menuitem), NULL, instance);
  1850. }
  1851. void menuitem_showcontrols_callback(GtkCheckMenuItem * menuitem,
  1852.     nsPluginInstance * instance)
  1853. {
  1854. #ifdef GTK2_ENABLED
  1855.     instance->SetShowControls(gtk_check_menu_item_get_active(menuitem));
  1856. #endif
  1857. #ifdef GTK1_ENABLED
  1858.     instance->SetShowControls(menuitem->active);
  1859. #endif
  1860. }
  1861. void menuitem_fullscreen_callback(GtkCheckMenuItem * menuitem,
  1862.   nsPluginInstance * instance)
  1863. {
  1864. #ifdef GTK2_ENABLED
  1865.     instance->SetFullscreen(gtk_check_menu_item_get_active(menuitem));
  1866. #endif
  1867. #ifdef GTK1_ENABLED
  1868.     instance->SetFullscreen(menuitem->active);
  1869. #endif
  1870. }
  1871. void store_filename(GtkWidget * widget, nsPluginInstance * instance)
  1872. {
  1873.     const gchar *filename;
  1874.     FILE *fin, *fout;
  1875.     char buffer[1000];
  1876.     int count;
  1877.     Node *n, *lastplayed;
  1878.     if (instance->mInitialized == FALSE)
  1879. return;
  1880.     pthread_mutex_lock(&(instance->playlist_mutex));
  1881.     lastplayed = NULL;
  1882.     if (instance->currentnode != NULL) {
  1883. lastplayed = instance->currentnode;
  1884.     } else {
  1885. n = instance->list;
  1886. while (n != NULL) {
  1887.     if (n->played == 1)
  1888. lastplayed = n;
  1889.     n = n->next;
  1890. }
  1891.     }
  1892.     if (DEBUG)
  1893. printf("lastplayed = %pn", lastplayed);
  1894.     if (lastplayed != NULL) {
  1895. filename =
  1896.     gtk_file_selection_get_filename(GTK_FILE_SELECTION
  1897.     (instance->file_selector));
  1898. if (DEBUG)
  1899.     printf("filename = %sn", filename);
  1900. if (filename) {
  1901.     if (lastplayed->retrieved == 1) {
  1902. if (DEBUG) {
  1903.     printf("lastplayed->fname = %sn", lastplayed->fname);
  1904. }
  1905. if (rename(lastplayed->fname, filename) == 0) {
  1906.     snprintf(lastplayed->fname, 1024, "%s", filename);
  1907.     lastplayed->remove = 0;
  1908. } else {
  1909.     // rename failed (probably cross partitions), copy the file
  1910.     fin = fopen(lastplayed->fname, "rb");
  1911.     fout = fopen(filename, "wb");
  1912.     if (fin != NULL && fout != NULL) {
  1913. while (!feof(fin)) {
  1914.     count = fread(buffer, 1, 1000, fin);
  1915.     fwrite(buffer, 1, count, fout);
  1916. }
  1917. fclose(fout);
  1918. fclose(fin);
  1919.     }
  1920. }
  1921.     }
  1922. }
  1923.     }
  1924.     pthread_mutex_unlock(&(instance->playlist_mutex));
  1925.     gtk_widget_destroy(instance->file_selector);
  1926.     instance->file_selector = NULL;
  1927. }
  1928. void menuitem_save_callback(GtkMenuItem * menuitem,
  1929.     nsPluginInstance * instance)
  1930. {
  1931.     const gchar *filename;
  1932.     char mmsplaylist[1024];
  1933.     FILE *playlist;
  1934.     Node *n, *lastplayed;
  1935.     if (instance->mInitialized == FALSE)
  1936. return;
  1937.     pthread_mutex_lock(&(instance->playlist_mutex));
  1938.     lastplayed = NULL;
  1939.     if (instance->currentnode != NULL) {
  1940. lastplayed = instance->currentnode;
  1941.     } else {
  1942. n = instance->list;
  1943. while (n != NULL) {
  1944.     if (n->played == 1)
  1945. lastplayed = n;
  1946.     n = n->next;
  1947. }
  1948.     }
  1949.     if (lastplayed != NULL) {
  1950. filename = getURLFilename(lastplayed->url);
  1951. if (filename) {
  1952.     instance->file_selector =
  1953. gtk_file_selection_new
  1954. (_("Save As..."));
  1955.     gtk_file_selection_set_filename(GTK_FILE_SELECTION
  1956.     (instance->file_selector),
  1957.     filename);
  1958. #ifdef GTK2_ENABLED
  1959.     g_signal_connect(GTK_FILE_SELECTION(instance->file_selector)->
  1960.      ok_button, "clicked",
  1961.      G_CALLBACK(store_filename), instance);
  1962.     g_signal_connect_swapped(GTK_FILE_SELECTION
  1963.      (instance->file_selector)->ok_button,
  1964.      "clicked",
  1965.      G_CALLBACK(gtk_widget_destroy),
  1966.      instance->file_selector);
  1967.     g_signal_connect_swapped(GTK_FILE_SELECTION
  1968.      (instance->file_selector)->
  1969.      cancel_button, "clicked",
  1970.      G_CALLBACK(gtk_widget_destroy),
  1971.      instance->file_selector);
  1972. #endif
  1973. #ifdef GTK1_ENABLED
  1974.     gtk_signal_connect(GTK_OBJECT
  1975.        (GTK_FILE_SELECTION
  1976. (instance->file_selector)->ok_button),
  1977.        "clicked", GTK_SIGNAL_FUNC(store_filename),
  1978.        instance);
  1979.     gtk_signal_connect_object(GTK_OBJECT
  1980.       (GTK_FILE_SELECTION
  1981.        (instance->file_selector)->
  1982.        ok_button), "clicked",
  1983.       GTK_SIGNAL_FUNC(gtk_widget_destroy),
  1984.       GTK_OBJECT(instance->file_selector));
  1985.     gtk_signal_connect_object(GTK_OBJECT
  1986.       (GTK_FILE_SELECTION
  1987.        (instance->file_selector)->
  1988.        cancel_button), "clicked",
  1989.       GTK_SIGNAL_FUNC(gtk_widget_destroy),
  1990.       GTK_OBJECT(instance->file_selector));
  1991. #endif
  1992.     /* Display that dialog */
  1993.     gtk_widget_show(instance->file_selector);
  1994. }
  1995. if (lastplayed->mmsstream) {
  1996.     snprintf(mmsplaylist, sizeof(mmsplaylist),
  1997.      "%s/playlist", instance->download_dir);
  1998.     playlist = fopen(mmsplaylist, "a");
  1999.     if (playlist != NULL) {
  2000. fprintf(playlist, "%sn", instance->list->url);
  2001. fclose(playlist);
  2002.     }
  2003. }
  2004.     }
  2005.     pthread_mutex_unlock(&(instance->playlist_mutex));
  2006. }
  2007. void menuitem_copy_callback(GtkMenuItem * menuitem,
  2008.     nsPluginInstance * instance)
  2009. {
  2010.     Node *n, *lastplayed;
  2011.     char *localurl;
  2012. #ifdef GTK2_ENABLED
  2013.     GtkClipboard *clipboard;
  2014. #endif
  2015. #ifdef GTK1_ENABLED
  2016.     GtkWidget *ge;
  2017. #endif
  2018.     localurl = (char *) malloc(1024);
  2019.     lastplayed = NULL;
  2020.     if (instance->currentnode != NULL) {
  2021. lastplayed = instance->currentnode;
  2022.     } else {
  2023. n = instance->list;
  2024. while (n != NULL) {
  2025.     if (n->played == 1)
  2026. lastplayed = n;
  2027.     n = n->next;
  2028. }
  2029.     }
  2030.     if (lastplayed != NULL) {
  2031. fullyQualifyURL(instance, lastplayed->url, localurl);
  2032. #ifdef GTK2_ENABLED
  2033. clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
  2034. gtk_clipboard_set_text(clipboard, localurl, -1);
  2035. clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
  2036. gtk_clipboard_set_text(clipboard, localurl, -1);
  2037. #endif
  2038. #ifdef GTK1_ENABLED
  2039. ge = gtk_entry_new_with_max_length(strlen(localurl));
  2040. gtk_entry_set_text((GtkEntry *) ge, localurl);
  2041. gtk_editable_select_region((GtkEditable *) ge, 0,
  2042.    strlen(localurl));
  2043. gtk_editable_copy_clipboard((GtkEditable *) ge);
  2044. #endif
  2045.     }
  2046. }
  2047. gint CloseConfig(GtkWidget * widget, nsPluginInstance * instance)
  2048. {
  2049.     if (GTK_IS_WIDGET(instance->conf_window))
  2050. gtk_widget_destroy(instance->conf_window);
  2051.     instance->conf_window = NULL;
  2052.     return (FALSE);
  2053. }
  2054. gint CloseConfigEvent(GtkWidget * widget, GdkEvent * event,
  2055.       nsPluginInstance * instance)
  2056. {
  2057.     if (GTK_IS_WIDGET(instance->conf_window))
  2058. gtk_widget_destroy(instance->conf_window);
  2059.     instance->conf_window = NULL;
  2060.     return (FALSE);
  2061. }
  2062. #ifdef GTK2_ENABLED
  2063. gint ApplyConfig(GtkWidget * widget, nsPluginInstance * instance)
  2064. {
  2065.     FILE *input;
  2066.     FILE *output;
  2067.     char config_name[1000];
  2068.     char tmp_name[1000];
  2069.     char buffer[1000];
  2070.     int ret;
  2071.     instance->cachesize =
  2072. (int) gtk_range_get_value(GTK_RANGE(instance->conf_cachesize));
  2073.     instance->cache_percent = (int)
  2074. gtk_range_get_value(GTK_RANGE(instance->conf_cachepercent));
  2075. #ifdef GTK24_ENABLED
  2076.     if (instance->vo != NULL)
  2077. free(instance->vo);
  2078.     instance->vo =
  2079. strdup(gtk_entry_get_text
  2080.        (GTK_ENTRY(GTK_BIN(instance->conf_vo)->child)));
  2081.     if (instance->ao != NULL)
  2082. free(instance->ao);
  2083.     instance->ao =
  2084. strdup(gtk_entry_get_text
  2085.        (GTK_ENTRY(GTK_BIN(instance->conf_ao)->child)));
  2086.     if (instance->download_dir != NULL)
  2087. free(instance->download_dir);
  2088.     instance->download_dir =
  2089. strdup(gtk_entry_get_text
  2090.        (GTK_ENTRY(GTK_BIN(instance->conf_dir)->child)));
  2091. #endif
  2092.     instance->showtime =
  2093. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2094.      (instance->conf_showtime));
  2095.     instance->enable_wmp =
  2096. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2097.      (instance->conf_enable_wmp));
  2098.     instance->enable_qt =
  2099. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2100.      (instance->conf_enable_qt));
  2101.     instance->enable_rm =
  2102. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2103.      (instance->conf_enable_rm));
  2104.     instance->enable_gmp =
  2105. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2106.      (instance->conf_enable_gmp));
  2107.     instance->enable_dvx =
  2108. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2109.      (instance->conf_enable_dvx));
  2110.     instance->enable_mpeg =
  2111. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2112.      (instance->conf_enable_mpeg));
  2113.     instance->enable_mp3 =
  2114. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2115.      (instance->conf_enable_mp3));
  2116.     instance->enable_ogg =
  2117. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2118.      (instance->conf_enable_ogg));
  2119.     instance->enable_midi =
  2120. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2121.      (instance->conf_enable_midi));
  2122.     instance->enable_pls =
  2123. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2124.      (instance->conf_enable_pls));
  2125.     instance->enable_smil =
  2126. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2127.      (instance->conf_enable_smil));
  2128.     instance->enable_helix =
  2129. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2130.      (instance->conf_enable_helix));
  2131.     instance->nomediacache =
  2132. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2133.      (instance->conf_nomediacache));
  2134.     instance->rtsp_use_tcp =
  2135. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2136.      (instance->conf_rtsptcp));
  2137.     instance->rtsp_use_http =
  2138. gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2139.      (instance->conf_rtsphttp));
  2140.     instance->nopauseonhide =
  2141. !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
  2142.       (instance->conf_pauseonhide));
  2143.     gtk_widget_destroy(instance->conf_window);
  2144.     instance->conf_window = NULL;
  2145.     // write the setting to the conf file now
  2146.     snprintf(config_name, 1000, "%s", getenv("HOME"));
  2147.     strlcat(config_name, "/.download/downloadplug-in.conf", 1000);
  2148.     snprintf(tmp_name, 1000, "%s", getenv("HOME"));
  2149.     strlcat(tmp_name, "/.download/downloadplug-in.conf.tmp", 1000);
  2150.     if (DEBUG) {
  2151. printf("config %sn", config_name);
  2152. printf("tmp %sn", tmp_name);
  2153.     }
  2154.     input = fopen(config_name, "r");
  2155.     output = fopen(tmp_name, "w");
  2156.     if (input != NULL && output != NULL) {
  2157. if (DEBUG)
  2158.     printf("update existing confign");
  2159. if (strlen(instance->vo) > 0)
  2160.     fprintf(output, "vo=%sn", instance->vo);
  2161. if (strlen(instance->ao) > 0)
  2162.     fprintf(output, "ao=%sn", instance->ao);
  2163. fprintf(output, "cachesize=%in", instance->cachesize);
  2164. fprintf(output, "cache-percent=%in", instance->cache_percent);
  2165. if (strlen(instance->download_dir) > 0)
  2166.     fprintf(output, "dload-dir=%sn", instance->download_dir);
  2167. fprintf(output, "showtime=%in", instance->showtime);
  2168. fprintf(output, "enable-wmp=%in", instance->enable_wmp);
  2169. fprintf(output, "enable-qt=%in", instance->enable_qt);
  2170. fprintf(output, "enable-rm=%in", instance->enable_rm);
  2171. fprintf(output, "enable-gmp=%in", instance->enable_gmp);
  2172. fprintf(output, "enable-dvx=%in", instance->enable_dvx);
  2173. fprintf(output, "enable-mpeg=%in", instance->enable_mpeg);
  2174. fprintf(output, "enable-mp3=%in", instance->enable_mp3);
  2175. fprintf(output, "enable-ogg=%in", instance->enable_ogg);
  2176. fprintf(output, "enable-midi=%in", instance->enable_midi);
  2177. fprintf(output, "enable-pls=%in", instance->enable_pls);
  2178. fprintf(output, "enable-smil=%in", instance->enable_smil);
  2179. fprintf(output, "enable-helix=%in", instance->enable_helix);
  2180. fprintf(output, "nomediacache=%in", instance->nomediacache);
  2181. fprintf(output, "nopauseonhide=%in", instance->nopauseonhide);
  2182. fprintf(output, "rtsp-use-tcp=%in", instance->rtsp_use_tcp);
  2183. fprintf(output, "rtsp-use-http=%in", instance->rtsp_use_http);
  2184. while (fgets(buffer, sizeof(buffer), input) != NULL) {
  2185.     if (strncasecmp(buffer, "vo", 2) == 0) {
  2186.     } else if (strncasecmp(buffer, "ao", 2) == 0) {
  2187.     } else if (strncasecmp(buffer, "cachesize", 9) == 0) {
  2188.     } else if (strncasecmp(buffer, "cache-percent", 13) == 0) {
  2189.     } else if (strncasecmp(buffer, "dload-dir", 9) == 0) {
  2190.     } else if (strncasecmp(buffer, "showtime", 8) == 0) {
  2191.     } else if (strncasecmp(buffer, "enable-wmp", 10) == 0) {
  2192.     } else if (strncasecmp(buffer, "enable-qt", 9) == 0) {
  2193.     } else if (strncasecmp(buffer, "enable-rm", 9) == 0) {
  2194.     } else if (strncasecmp(buffer, "enable-mpeg", 11) == 0) {
  2195.     } else if (strncasecmp(buffer, "enable-mp3", 10) == 0) {
  2196.     } else if (strncasecmp(buffer, "enable-midi", 11) == 0) {
  2197.     } else if (strncasecmp(buffer, "enable-pls", 10) == 0) {
  2198.     } else if (strncasecmp(buffer, "enable-ogg", 10) == 0) {
  2199.     } else if (strncasecmp(buffer, "enable-gmp", 10) == 0) {
  2200.     } else if (strncasecmp(buffer, "enable-dvx", 10) == 0) {
  2201.     } else if (strncasecmp(buffer, "enable-smil", 11) == 0) {
  2202.     } else if (strncasecmp(buffer, "enable-helix", 12) == 0) {
  2203.     } else if (strncasecmp(buffer, "nomediacache", 12) == 0) {
  2204.     } else if (strncasecmp(buffer, "nopauseonhide", 13) == 0) {
  2205.     } else if (strncasecmp(buffer, "rtsp-use-tcp", 12) == 0) {
  2206.     } else if (strncasecmp(buffer, "rtsp-use-http", 13) == 0) {
  2207.     } else {
  2208. fprintf(output, "%s", buffer);
  2209.     }
  2210. }
  2211. fclose(input);
  2212. fclose(output);
  2213. ret = unlink(config_name);
  2214. if (ret == 0) {
  2215.     ret = rename(tmp_name, config_name);
  2216.     if (ret == -1) {
  2217. ret = errno;
  2218. if (DEBUG) {
  2219.     printf("Unable to rename the file %s to %sn",
  2220.    tmp_name, config_name);
  2221.     printf("Error code: %i - %sn", ret, strerror(ret));
  2222. }
  2223.     }
  2224. } else {
  2225.     ret = errno;
  2226.     if (DEBUG) {
  2227. printf("Unable to delete the file %sn", config_name);
  2228. printf("Error code: %i - %sn", ret, strerror(ret));
  2229.     }
  2230. }
  2231.     } else {
  2232. if (DEBUG)
  2233.     printf("write new config filen");
  2234. if (output != NULL) {
  2235.     if (strlen(instance->vo) > 0)
  2236. fprintf(output, "vo=%sn", instance->vo);
  2237.     if (strlen(instance->ao) > 0)
  2238. fprintf(output, "ao=%sn", instance->ao);
  2239.     fprintf(output, "cachesize=%in", instance->cachesize);
  2240.     fprintf(output, "cache-percent=%in", instance->cache_percent);
  2241.     if (strlen(instance->download_dir) > 0)
  2242. fprintf(output, "dload-dir=%sn", instance->download_dir);
  2243.     fprintf(output, "showtime=%in", instance->showtime);
  2244.     fprintf(output, "enable-wmp=%in", instance->enable_wmp);
  2245.     fprintf(output, "enable-qt=%in", instance->enable_qt);
  2246.     fprintf(output, "enable-rm=%in", instance->enable_rm);
  2247.     fprintf(output, "enable-gmp=%in", instance->enable_gmp);
  2248.     fprintf(output, "enable-dvx=%in", instance->enable_dvx);
  2249.     fprintf(output, "enable-mpeg=%in", instance->enable_mpeg);
  2250.     fprintf(output, "enable-mp3=%in", instance->enable_mp3);
  2251.     fprintf(output, "enable-midi=%in", instance->enable_midi);
  2252.     fprintf(output, "enable-pls=%in", instance->enable_pls);
  2253.     fprintf(output, "enable-ogg=%in", instance->enable_ogg);
  2254.     fprintf(output, "enable-smil=%in", instance->enable_smil);
  2255.     fprintf(output, "enable-helix=%in", instance->enable_helix);
  2256.     fprintf(output, "nomediacache=%in", instance->nomediacache);
  2257.     fprintf(output, "nopauseonhide=%in", instance->nopauseonhide);
  2258.     fprintf(output, "rtsp-use-tcp=%in", instance->rtsp_use_tcp);
  2259.     fprintf(output, "rtsp-use-http=%in", instance->rtsp_use_http);
  2260.     fclose(output);
  2261.     ret = rename(tmp_name, config_name);
  2262.     if (ret == -1) {
  2263. ret = errno;
  2264. if (DEBUG) {
  2265.     printf("Unable to rename the file %s to %sn",
  2266.    tmp_name, config_name);
  2267.     printf("Error code: %i - %sn", ret, strerror(ret));
  2268. }
  2269.     }
  2270. }
  2271.     }
  2272.     snprintf(buffer, 1000, "%s", getenv("HOME"));
  2273.     strlcat(buffer, "/.mozilla/pluginreg.dat", 1000);
  2274.     unlink(buffer);
  2275.     snprintf(buffer, 1000, "%s", getenv("HOME"));
  2276.     strlcat(buffer, "/.firefox/pluginreg.dat", 1000);
  2277.     unlink(buffer);
  2278.     snprintf(buffer, 1000, "%s", getenv("HOME"));
  2279.     strlcat(buffer, "/.mozilla/firefox/pluginreg.dat", 1000);
  2280.     unlink(buffer);
  2281.     NPN_ReloadPlugins(FALSE);
  2282.     return (FALSE);
  2283. }
  2284. void menuitem_config_callback(GtkMenuItem * menuitem,
  2285.       nsPluginInstance * instance)
  2286. {
  2287.     GtkWidget *conf_vbox;
  2288.     GtkWidget *conf_hbutton_box;
  2289.     GtkWidget *conf_ok;
  2290.     GtkWidget *conf_cancel;
  2291.     GtkWidget *conf_table;
  2292.     GtkWidget *conf_label;
  2293.     int row = 0;
  2294.     if (instance->conf_window != NULL)
  2295. return;
  2296.     instance->conf_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  2297.     gtk_widget_realize(instance->conf_window);
  2298.     gtk_window_set_resizable(GTK_WINDOW(instance->conf_window), FALSE);
  2299.     conf_vbox = gtk_vbox_new(FALSE, 10);
  2300.     conf_hbutton_box = gtk_hbutton_box_new();
  2301.     conf_table = gtk_table_new(20, 2, FALSE);
  2302.     gtk_container_add(GTK_CONTAINER(conf_vbox), conf_table);
  2303.     gtk_container_add(GTK_CONTAINER(conf_vbox), conf_hbutton_box);
  2304.     gtk_container_add(GTK_CONTAINER(instance->conf_window), conf_vbox);
  2305.     gtk_window_set_title(GTK_WINDOW(instance->conf_window),
  2306.  _("downloadplug-in configuration"));
  2307.     gtk_container_set_border_width(GTK_CONTAINER
  2308.    (instance->conf_window), 5);
  2309.     g_signal_connect(GTK_OBJECT(instance->conf_window), "delete_event",
  2310.      GTK_SIGNAL_FUNC(CloseConfigEvent), instance);
  2311. #ifdef GTK24_ENABLED
  2312.     instance->conf_vo = gtk_combo_box_entry_new_text();
  2313.     if (instance->conf_vo != NULL) {
  2314. gtk_combo_box_append_text(GTK_COMBO_BOX(instance->conf_vo), "gl");
  2315. gtk_combo_box_append_text(GTK_COMBO_BOX(instance->conf_vo), "x11");
  2316. gtk_combo_box_append_text(GTK_COMBO_BOX(instance->conf_vo), "xv");
  2317. if (instance->vo != NULL) {
  2318.     if (strcmp(instance->vo, "gl") == 0)
  2319. gtk_combo_box_set_active(GTK_COMBO_BOX
  2320.  (instance->conf_vo), 0);
  2321.     if (strcmp(instance->vo, "x11") == 0)
  2322. gtk_combo_box_set_active(GTK_COMBO_BOX
  2323.  (instance->conf_vo), 1);
  2324.     if (strcmp(instance->vo, "xv") == 0)
  2325. gtk_combo_box_set_active(GTK_COMBO_BOX
  2326.  (instance->conf_vo), 2);
  2327.     if (gtk_combo_box_get_active(GTK_COMBO_BOX(instance->conf_vo))
  2328. == -1) {
  2329. gtk_combo_box_append_text(GTK_COMBO_BOX
  2330.   (instance->conf_vo),
  2331.   instance->vo);
  2332. gtk_combo_box_set_active(GTK_COMBO_BOX
  2333.  (instance->conf_vo), 3);
  2334.     }
  2335. }
  2336.     }
  2337.     instance->conf_ao = gtk_combo_box_entry_new_text();
  2338.     if (instance->conf_ao != NULL) {
  2339. gtk_combo_box_append_text(GTK_COMBO_BOX(instance->conf_ao),
  2340.   "alsa");
  2341. gtk_combo_box_append_text(GTK_COMBO_BOX(instance->conf_ao),
  2342.   "arts");
  2343. gtk_combo_box_append_text(GTK_COMBO_BOX(instance->conf_ao), "esd");
  2344. gtk_combo_box_append_text(GTK_COMBO_BOX(instance->conf_ao),
  2345.   "jack");
  2346. gtk_combo_box_append_text(GTK_COMBO_BOX(instance->conf_ao), "oss");
  2347. if (instance->ao != NULL) {
  2348.     if (strcmp(instance->ao, "alsa") == 0)
  2349. gtk_combo_box_set_active(GTK_COMBO_BOX
  2350.  (instance->conf_ao), 0);
  2351.     if (strcmp(instance->ao, "arts") == 0)
  2352. gtk_combo_box_set_active(GTK_COMBO_BOX
  2353.  (instance->conf_ao), 1);
  2354.     if (strcmp(instance->ao, "esd") == 0)
  2355. gtk_combo_box_set_active(GTK_COMBO_BOX
  2356.  (instance->conf_ao), 2);
  2357.     if (strcmp(instance->ao, "jack") == 0)
  2358. gtk_combo_box_set_active(GTK_COMBO_BOX
  2359.  (instance->conf_ao), 3);
  2360.     if (strcmp(instance->ao, "oss") == 0)
  2361. gtk_combo_box_set_active(GTK_COMBO_BOX
  2362.  (instance->conf_ao), 4);
  2363.     if (gtk_combo_box_get_active(GTK_COMBO_BOX(instance->conf_ao))
  2364. == -1) {
  2365. gtk_combo_box_append_text(GTK_COMBO_BOX
  2366.   (instance->conf_ao),
  2367.   instance->ao);
  2368. gtk_combo_box_set_active(GTK_COMBO_BOX
  2369.  (instance->conf_ao), 4);
  2370.     }
  2371. }
  2372.     }
  2373.     instance->conf_dir = gtk_combo_box_entry_new_text();
  2374.     if (instance->conf_dir != NULL) {
  2375. gtk_combo_box_append_text(GTK_COMBO_BOX(instance->conf_dir),
  2376.   "$HOME");
  2377. if (instance->download_dir != NULL) {
  2378.     if (strcmp(instance->download_dir, "$HOME") == 0)
  2379. gtk_combo_box_set_active(GTK_COMBO_BOX
  2380.  (instance->conf_dir), 0);
  2381.     if (gtk_combo_box_get_active(GTK_COMBO_BOX(instance->conf_dir))
  2382. == -1) {
  2383. gtk_combo_box_append_text(GTK_COMBO_BOX
  2384.   (instance->conf_dir),
  2385.   instance->download_dir);
  2386. gtk_combo_box_set_active(GTK_COMBO_BOX
  2387.  (instance->conf_dir), 1);
  2388.     }
  2389. }
  2390.     }
  2391. #endif
  2392.     conf_ok = gtk_button_new_with_label(_("OK"));
  2393.     g_signal_connect(GTK_OBJECT(conf_ok), "clicked",
  2394.      GTK_SIGNAL_FUNC(ApplyConfig), instance);
  2395.     conf_cancel = gtk_button_new_with_label(_("Cancel"));
  2396.     g_signal_connect(GTK_OBJECT(conf_cancel), "clicked",
  2397.      GTK_SIGNAL_FUNC(CloseConfig), instance);
  2398. #ifdef GTK24_ENABLED
  2399.     conf_label = gtk_label_new(_("Video Output:"));
  2400.     gtk_misc_set_alignment(GTK_MISC(conf_label), 0.0, 0.0);
  2401.     gtk_table_attach_defaults(GTK_TABLE(conf_table), conf_label, 0, 1,
  2402.       0, 1);
  2403.     gtk_widget_show(conf_label);
  2404.     gtk_table_attach_defaults(GTK_TABLE(conf_table), instance->conf_vo,
  2405.       1, 2, 0, 1);
  2406.     conf_label = gtk_label_new(_("Audio Output:"));
  2407.     gtk_misc_set_alignment(GTK_MISC(conf_label), 0.0, 0.0);
  2408.     gtk_table_attach_defaults(GTK_TABLE(conf_table), conf_label, 0, 1,
  2409.       1, 2);
  2410.     gtk_widget_show(conf_label);
  2411.     gtk_misc_set_alignment(GTK_MISC(conf_label), 0.0, 0.0);
  2412.     gtk_table_attach_defaults(GTK_TABLE(conf_table), instance->conf_ao,
  2413.       1, 2, 1, 2);
  2414.     conf_label = gtk_label_new(_("Save to Location:"));
  2415.     gtk_table_attach_defaults(GTK_TABLE(conf_table), conf_label, 0, 1,
  2416.       2, 3);
  2417.     gtk_widget_show(conf_label);
  2418.     gtk_misc_set_alignment(GTK_MISC(conf_label), 0.0, 0.0);
  2419.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2420.       instance->conf_dir, 1, 2, 2, 3);
  2421. #endif
  2422.     conf_label = gtk_label_new(_("Minimum Cache Size:"));
  2423.     gtk_misc_set_alignment(GTK_MISC(conf_label), 0.0, 0.0);
  2424.     gtk_table_attach_defaults(GTK_TABLE(conf_table), conf_label, 0, 1,
  2425.       3, 4);
  2426.     gtk_widget_show(conf_label);
  2427.     instance->conf_cachesize = gtk_hscale_new_with_range(0, 32767, 512);
  2428.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2429.       instance->conf_cachesize, 1, 2, 3, 4);
  2430.     gtk_range_set_value(GTK_RANGE(instance->conf_cachesize),
  2431. instance->cachesize);
  2432.     gtk_widget_show(instance->conf_cachesize);
  2433.     conf_label = gtk_label_new(_("Percent of Media to Cache:"));
  2434.     gtk_misc_set_alignment(GTK_MISC(conf_label), 0.0, 0.0);
  2435.     gtk_table_attach_defaults(GTK_TABLE(conf_table), conf_label, 0, 1,
  2436.       4, 5);
  2437.     gtk_widget_show(conf_label);
  2438.     instance->conf_cachepercent = gtk_hscale_new_with_range(0, 100, 5);
  2439.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2440.       instance->conf_cachepercent, 1, 2, 4, 5);
  2441.     gtk_range_set_value(GTK_RANGE(instance->conf_cachepercent),
  2442. instance->cache_percent);
  2443.     gtk_widget_show(instance->conf_cachepercent);
  2444.     row = 5;
  2445.     instance->conf_showtime =
  2446. gtk_check_button_new_with_label(_("Show time in progress bar"));
  2447.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2448.       instance->conf_showtime, 1, 2, row, row + 1);
  2449.     row++;
  2450.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2451.  (instance->conf_showtime),
  2452.  instance->showtime);
  2453.     gtk_widget_show(instance->conf_showtime);
  2454.     instance->conf_enable_wmp =
  2455. gtk_check_button_new_with_label(_
  2456. ("Enable Windows Media Player Support"));
  2457.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2458.       instance->conf_enable_wmp, 1, 2, row,
  2459.       row + 1);
  2460.     row++;
  2461.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2462.  (instance->conf_enable_wmp),
  2463.  instance->enable_wmp);
  2464.     gtk_widget_show(instance->conf_enable_wmp);
  2465.     instance->conf_enable_qt =
  2466. gtk_check_button_new_with_label(_("Enable QuickTime Support"));
  2467.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2468.       instance->conf_enable_qt, 1, 2, row,
  2469.       row + 1);
  2470.     row++;
  2471.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2472.  (instance->conf_enable_qt),
  2473.  instance->enable_qt);
  2474.     gtk_widget_show(instance->conf_enable_qt);
  2475.     instance->conf_enable_rm =
  2476. gtk_check_button_new_with_label(_("Enable RealMedia Support"));
  2477.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2478.       instance->conf_enable_rm, 1, 2, row,
  2479.       row + 1);
  2480.     row++;
  2481.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2482.  (instance->conf_enable_rm),
  2483.  instance->enable_rm);
  2484.     gtk_widget_show(instance->conf_enable_rm);
  2485.     instance->conf_enable_smil =
  2486. gtk_check_button_new_with_label(_
  2487. ("Enable SMIL Support (Effects QuickTime and RealMedia)"));
  2488.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2489.       instance->conf_enable_smil, 1, 2, row,
  2490.       row + 1);
  2491.     row++;
  2492.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2493.  (instance->conf_enable_smil),
  2494.  instance->enable_smil);
  2495.     gtk_widget_show(instance->conf_enable_smil);
  2496.     instance->conf_enable_helix =
  2497. gtk_check_button_new_with_label(_("Enable Helix Emulation"));
  2498.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2499.       instance->conf_enable_helix, 1, 2, row,
  2500.       row + 1);
  2501.     row++;
  2502.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2503.  (instance->conf_enable_helix),
  2504.  instance->enable_helix);
  2505.     gtk_widget_show(instance->conf_enable_helix);
  2506.     instance->conf_enable_gmp =
  2507. gtk_check_button_new_with_label(_
  2508. ("Enable Google Media Player Support"));
  2509.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2510.       instance->conf_enable_gmp, 1, 2, row,
  2511.       row + 1);
  2512.     row++;
  2513.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2514.  (instance->conf_enable_gmp),
  2515.  instance->enable_gmp);
  2516.     gtk_widget_show(instance->conf_enable_gmp);
  2517.     instance->conf_enable_mpeg =
  2518. gtk_check_button_new_with_label(_("Enable MPEG Support"));
  2519.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2520.       instance->conf_enable_mpeg, 1, 2, row,
  2521.       row + 1);
  2522.     row++;
  2523.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2524.  (instance->conf_enable_mpeg),
  2525.  instance->enable_mpeg);
  2526.     gtk_widget_show(instance->conf_enable_mpeg);
  2527.     instance->conf_enable_mp3 =
  2528. gtk_check_button_new_with_label(_
  2529. ("Enable MP3 Support (Requires MPEG Support)"));
  2530.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2531.       instance->conf_enable_mp3, 1, 2, row,
  2532.       row + 1);
  2533.     row++;
  2534.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2535.  (instance->conf_enable_mp3),
  2536.  instance->enable_mp3);
  2537.     gtk_widget_show(instance->conf_enable_mp3);
  2538.     instance->conf_enable_ogg =
  2539. gtk_check_button_new_with_label(_("Enable Ogg Support"));
  2540.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2541.       instance->conf_enable_ogg, 1, 2, row,
  2542.       row + 1);
  2543.     row++;
  2544.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2545.  (instance->conf_enable_ogg),
  2546.  instance->enable_ogg);
  2547.     gtk_widget_show(instance->conf_enable_ogg);
  2548.     instance->conf_enable_midi =
  2549. gtk_check_button_new_with_label(_("Enable MIDI Support"));
  2550.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2551.       instance->conf_enable_midi, 1, 2, row,
  2552.       row + 1);
  2553.     row++;
  2554.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2555.  (instance->conf_enable_midi),
  2556.  instance->enable_midi);
  2557.     gtk_widget_show(instance->conf_enable_midi);
  2558.     instance->conf_enable_pls =
  2559. gtk_check_button_new_with_label(_("Enable Shoutcast PLS Support"));
  2560.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2561.       instance->conf_enable_pls, 1, 2, row,
  2562.       row + 1);
  2563.     row++;
  2564.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2565.  (instance->conf_enable_pls),
  2566.  instance->enable_pls);
  2567.     gtk_widget_show(instance->conf_enable_pls);
  2568.     instance->conf_enable_dvx =
  2569. gtk_check_button_new_with_label(_("Enable DivX Support"));
  2570.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2571.       instance->conf_enable_dvx, 1, 2, row,
  2572.       row + 1);
  2573.     row++;
  2574.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2575.  (instance->conf_enable_dvx),
  2576.  instance->enable_dvx);
  2577.     gtk_widget_show(instance->conf_enable_dvx);
  2578.     instance->conf_nomediacache =
  2579. gtk_check_button_new_with_label(_
  2580. ("Play media directly from site (No Caching)"));
  2581.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2582.       instance->conf_nomediacache, 1, 2, row,
  2583.       row + 1);
  2584.     row++;
  2585.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2586.  (instance->conf_nomediacache),
  2587.  instance->nomediacache);
  2588.     gtk_widget_show(instance->conf_nomediacache);
  2589.     instance->conf_rtsptcp =
  2590. gtk_check_button_new_with_label(_
  2591. ("Connect to RTSP Media over TCP"));
  2592.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2593.       instance->conf_rtsptcp, 1, 2, row, row + 1);
  2594.     row++;
  2595.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2596.  (instance->conf_rtsptcp),
  2597.  instance->rtsp_use_tcp);
  2598.     gtk_widget_show(instance->conf_rtsptcp);
  2599.     instance->conf_rtsphttp =
  2600. gtk_check_button_new_with_label(_("Use HTTP instead of RTSP"));
  2601.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2602.       instance->conf_rtsphttp, 1, 2, row, row + 1);
  2603.     row++;
  2604.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2605.  (instance->conf_rtsphttp),
  2606.  instance->rtsp_use_http);
  2607.     gtk_widget_show(instance->conf_rtsphttp);
  2608.     instance->conf_pauseonhide =
  2609. gtk_check_button_new_with_label(_("Pause Video when hidden"));
  2610.     gtk_table_attach_defaults(GTK_TABLE(conf_table),
  2611.       instance->conf_pauseonhide, 1, 2, row,
  2612.       row + 1);
  2613.     row++;
  2614.     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON
  2615.  (instance->conf_pauseonhide),
  2616.  !instance->nopauseonhide);
  2617.     gtk_widget_show(instance->conf_pauseonhide);
  2618.     gtk_container_add(GTK_CONTAINER(conf_hbutton_box), conf_ok);
  2619.     gtk_container_add(GTK_CONTAINER(conf_hbutton_box), conf_cancel);
  2620. #ifdef GTK24_ENABLED
  2621.     if (instance->conf_vo != NULL)
  2622. gtk_widget_show(instance->conf_vo);
  2623.     if (instance->conf_ao != NULL)
  2624. gtk_widget_show(instance->conf_ao);
  2625.     if (instance->conf_dir != NULL)
  2626. gtk_widget_show(instance->conf_dir);
  2627. #endif
  2628.     gtk_widget_show(conf_ok);
  2629.     gtk_widget_show(conf_cancel);
  2630.     gtk_widget_show(conf_table);
  2631.     gtk_widget_show(conf_hbutton_box);
  2632.     gtk_widget_show(conf_vbox);
  2633.     gtk_widget_show(instance->conf_window);
  2634. }
  2635. gboolean window_visible(GtkWidget * widget, GdkEvent * event,
  2636. nsPluginInstance * instance)
  2637. {
  2638.     //if (DEBUG)
  2639.     //      printf("**************nnnn in window_visible %innnnn******************n",GTK_WIDGET_VISIBLE(widget));
  2640.     // only pause if video is present, if we have streaming audio we want to keep playing
  2641.     if (instance->cancelled == 0) {
  2642. if (event->type == GDK_VISIBILITY_NOTIFY) {
  2643.     if (((GdkEventVisibility *) event)->state ==
  2644. GDK_VISIBILITY_FULLY_OBSCURED) {
  2645. if (instance->paused == 0 && instance->threadsignaled
  2646.     && instance->nopauseonhide == 0) {
  2647.     if (instance->movie_width != 0
  2648. && instance->movie_height != 0) {
  2649. instance->Pause();
  2650. instance->paused_wheninvisible = 1;
  2651.     }
  2652. }
  2653. if (instance->onHiddenCallback != NULL)
  2654.     NPN_GetURL(instance->mInstance,
  2655.        instance->onHiddenCallback, "_self");
  2656.     } else {
  2657. if (instance->paused_wheninvisible == 1
  2658.     && instance->threadsignaled
  2659.     && instance->nopauseonhide == 0) {
  2660.     if (instance->movie_width != 0
  2661. && instance->movie_height != 0) {
  2662. instance->Play();
  2663. instance->paused_wheninvisible = 0;
  2664.     }
  2665. }
  2666. if (instance->onVisibleCallback != NULL)
  2667.     NPN_GetURL(instance->mInstance,
  2668.        instance->onVisibleCallback, "_self");
  2669.     }
  2670. }
  2671.     }
  2672.     return (FALSE);
  2673. }
  2674. gboolean load_href_callback(GtkWidget * widget, GdkEventExpose * event,
  2675.     nsPluginInstance * instance)
  2676. {
  2677.     Node *n;
  2678.     GdkEventButton *event_button;
  2679.     if (DEBUG)
  2680. printf("image clickedn");
  2681.     if (event->type == GDK_BUTTON_PRESS) {
  2682. event_button = (GdkEventButton *) event;
  2683. if (event_button->button == 3) {
  2684.     gtk_menu_popup(instance->popup_menu, NULL, NULL, NULL,
  2685.    NULL, event_button->button, event_button->time);
  2686.     return TRUE;
  2687. }
  2688. if (event_button->button == 1) {
  2689.     n = instance->list;
  2690.     while (n != NULL) {
  2691. if (strcmp(n->url, instance->href) == 0)
  2692.     break;
  2693. else
  2694.     n = n->next;
  2695.     }
  2696.     if (n == NULL) {
  2697. n = newNode();
  2698. snprintf(n->url, 1024, "%s", instance->href);
  2699. n->frombutton = 1;
  2700. addToEnd(instance->td->list, n);
  2701. NPN_GetURL(instance->mInstance, instance->href, NULL);
  2702. if (instance->targetplayer == 0)
  2703.     gtk_widget_hide(instance->src_event_box);
  2704.     } else {
  2705. if (instance->targetplayer == 0)
  2706.     gtk_widget_hide(instance->src_event_box);
  2707. n->play = 1;
  2708. instance->Play();
  2709.     }
  2710.     if (instance->targetplayer == 1)
  2711. gtk_widget_show(instance->gtkwidget);
  2712.     return TRUE;
  2713. }
  2714.     }
  2715.     return FALSE;
  2716. }
  2717. #endif
  2718. #endif // GTK_ENABLED
  2719. int srcToButton(char *url, nsPluginInstance * instance)
  2720. {
  2721. #ifndef GTK2_ENABLED
  2722.     return FALSE;
  2723. #endif
  2724. #ifdef GTK2_ENABLED
  2725.     gchar *command;
  2726.     GError *error = NULL;
  2727.     int exit_status;
  2728.     gchar *dirname = NULL;
  2729.     gchar *filename = NULL;
  2730.     gboolean result;
  2731.     GtkWidget *fixed_button_container;
  2732.     if (DEBUG)
  2733. printf("In srcToButtonn");
  2734.     // try to load the file natively
  2735.     instance->pb_src = gdk_pixbuf_new_from_file(url, &error);
  2736.     if (instance->pb_src == NULL) {
  2737. // setup tmp directory
  2738. dirname =
  2739.     g_strdup_printf("%s", tempnam("/tmp", "downloadplug-inXXXXXX"));
  2740. filename = g_strdup_printf("%s/00000001.jpg", dirname);
  2741. // run download and try to get the first frame and convert it to a jpeg
  2742. command =
  2743.     g_strdup_printf("download -vo jpeg:outdir=%s -frames 1 %s",
  2744.     dirname, url);
  2745. if (!g_spawn_command_line_sync
  2746.     (command, NULL, NULL, &exit_status, &error))
  2747.     printf("Error when running When running command: %sn%sn",
  2748.    command, error->message);
  2749. if (fexists(filename)) {
  2750.     error = NULL;
  2751.     instance->pb_src = gdk_pixbuf_new_from_file(filename, &error);
  2752. } else {
  2753.     instance->pb_src =
  2754. gdk_pixbuf_new_from_xpm_data((const char **) start);
  2755. }
  2756.     }
  2757.     if (instance->pb_src != NULL) {
  2758. if (instance->targetplayer == 0) {
  2759.     instance->src_event_box = gtk_event_box_new();
  2760.     instance->image_src =
  2761. gtk_image_new_from_pixbuf(instance->pb_src);
  2762.     gtk_container_add(GTK_CONTAINER(instance->src_event_box),
  2763.       instance->image_src);
  2764.     g_signal_connect(G_OBJECT(instance->src_event_box),
  2765.      "button_press_event",
  2766.      G_CALLBACK(load_href_callback), instance);
  2767.     gtk_fixed_put(GTK_FIXED(instance->fixed_container),
  2768.   instance->src_event_box, 0, 0);
  2769.     gtk_widget_set_size_request(GTK_WIDGET
  2770. (instance->src_event_box),
  2771. instance->embed_width,
  2772. instance->embed_height);
  2773.     gtk_widget_show(GTK_WIDGET(instance->image_src));
  2774.     gtk_widget_show(instance->src_event_box);
  2775.     gtk_widget_show(instance->fixed_container);
  2776. } else {
  2777.     gtk_widget_add_events(instance->button_window,
  2778.   GDK_BUTTON_PRESS_MASK);
  2779.     gtk_widget_realize(instance->button_window);
  2780.     instance->src_event_box = gtk_event_box_new();
  2781.     instance->image_src =
  2782. gtk_image_new_from_pixbuf(instance->pb_src);
  2783.     g_signal_connect(G_OBJECT(instance->src_event_box),
  2784.      "button_press_event",
  2785.      G_CALLBACK(load_href_callback), instance);
  2786.     gtk_widget_set_size_request(GTK_WIDGET
  2787. (instance->src_event_box),
  2788. instance->embed_width,
  2789. instance->embed_height);
  2790.     gtk_container_add(GTK_CONTAINER(instance->src_event_box),
  2791.       instance->image_src);
  2792.     fixed_button_container = gtk_fixed_new();
  2793.     gtk_widget_set_size_request(GTK_WIDGET
  2794. (fixed_button_container),
  2795. instance->embed_width,
  2796. instance->embed_height);
  2797.     gtk_container_add(GTK_CONTAINER(instance->button_window),
  2798.       fixed_button_container);
  2799.     gtk_fixed_put(GTK_FIXED(fixed_button_container),
  2800.   instance->src_event_box, 0, 0);
  2801.     gtk_widget_show(GTK_WIDGET(instance->image_src));
  2802.     gtk_widget_show(instance->src_event_box);
  2803.     gtk_widget_show(fixed_button_container);
  2804.     gtk_widget_show(instance->button_window);
  2805.     g_idle_add(gtkgui_draw, instance);
  2806. }
  2807. result = TRUE;
  2808.     } else {
  2809. if (instance->targetplayer == 1)
  2810.     gtk_widget_show(instance->gtkwidget);
  2811. result = FALSE;
  2812.     }
  2813.     if (filename != NULL) {
  2814. remove(filename);
  2815. g_free(filename);
  2816.     }
  2817.     if (dirname != NULL) {
  2818. remove(dirname);
  2819. g_free(dirname);
  2820.     }
  2821.     return result;
  2822. #endif
  2823. }
  2824. #ifdef GTK_ENABLED
  2825. gboolean target_hide_callback(GtkWidget * widget, GdkEvent * event,
  2826.       nsPluginInstance * instance)
  2827. {
  2828.     if (DEBUG)
  2829. printf("Hiding gtkwidget, windown");
  2830.     gtk_widget_hide(GTK_WIDGET(instance->gtkwidget));
  2831.     instance->Quit();
  2832.     return TRUE;
  2833. }
  2834. #endif // GTK_ENABLED