Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 24.72 KB | None | 0 0
  1. /* db.c generated by valac 0.11.6, the Vala compiler
  2.  * generated from db.vala, do not modify */
  3.  
  4. /*
  5.  *  Copyright 2010 Colomban Wendling  <ban(at)herbesfolles(dot)org>
  6.  *
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20.  *
  21.  */
  22.  
  23. #include <glib.h>
  24. #include <glib-object.h>
  25. #include <geanyplugin.h>
  26. #include <gtk/gtk.h>
  27. #include <postgresql/libpq-fe.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <glib/gstdio.h>
  31. #include <stdio.h>
  32.  
  33.  
  34. #define TYPE_PLUGIN_QUERY_WINDOW (plugin_query_window_get_type ())
  35. #define PLUGIN_QUERY_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PLUGIN_QUERY_WINDOW, PluginQueryWindow))
  36. #define PLUGIN_QUERY_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PLUGIN_QUERY_WINDOW, PluginQueryWindowClass))
  37. #define IS_PLUGIN_QUERY_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PLUGIN_QUERY_WINDOW))
  38. #define IS_PLUGIN_QUERY_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PLUGIN_QUERY_WINDOW))
  39. #define PLUGIN_QUERY_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PLUGIN_QUERY_WINDOW, PluginQueryWindowClass))
  40.  
  41. typedef struct _PluginQueryWindow PluginQueryWindow;
  42. typedef struct _PluginQueryWindowClass PluginQueryWindowClass;
  43. typedef struct _PluginQueryWindowPrivate PluginQueryWindowPrivate;
  44. #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
  45. #define _PQfinish0(var) ((var == NULL) ? NULL : (var = (PQfinish (var), NULL)))
  46. #define _PQclear0(var) ((var == NULL) ? NULL : (var = (PQclear (var), NULL)))
  47. #define _g_free0(var) (var = (g_free (var), NULL))
  48. #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
  49.  
  50. struct _PluginQueryWindow {
  51.     GtkWindow parent_instance;
  52.     PluginQueryWindowPrivate * priv;
  53. };
  54.  
  55. struct _PluginQueryWindowClass {
  56.     GtkWindowClass parent_class;
  57. };
  58.  
  59. struct _PluginQueryWindowPrivate {
  60.     GtkTreeView* results;
  61.     GtkTextView* text_view;
  62.     gint col_count;
  63.     gboolean data_loaded;
  64.     PGconn* pgconn;
  65.     PGresult* pgresult;
  66. };
  67.  
  68.  
  69. extern GeanyPlugin* geany_plugin;
  70. GeanyPlugin* geany_plugin = NULL;
  71. extern GeanyData* geany_data;
  72. GeanyData* geany_data = NULL;
  73. extern GeanyFunctions* geany_functions;
  74. GeanyFunctions* geany_functions = NULL;
  75. extern GSList* G_destroy_widget_stack;
  76. GSList* G_destroy_widget_stack = NULL;
  77. static gpointer plugin_query_window_parent_class = NULL;
  78.  
  79. GType plugin_query_window_get_type (void) G_GNUC_CONST;
  80. #define PLUGIN_QUERY_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_PLUGIN_QUERY_WINDOW, PluginQueryWindowPrivate))
  81. enum  {
  82.     PLUGIN_QUERY_WINDOW_DUMMY_PROPERTY
  83. };
  84. PluginQueryWindow* plugin_query_window_new (void);
  85. PluginQueryWindow* plugin_query_window_construct (GType object_type);
  86. static void _lambda0_ (PluginQueryWindow* self);
  87. static void plugin_query_window_on_open_clicked (PluginQueryWindow* self);
  88. static void __lambda0__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self);
  89. static void _lambda1_ (PluginQueryWindow* self);
  90. static gboolean plugin_query_window_db_connect (PluginQueryWindow* self, const gchar* host, const gchar* user, const gchar* password, const gchar* dbname);
  91. static void __lambda1__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self);
  92. static void _lambda2_ (PluginQueryWindow* self);
  93. static void plugin_query_window_perform_query (PluginQueryWindow* self);
  94. static void __lambda2__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self);
  95. static void _lambda3_ (PluginQueryWindow* self);
  96. static void __lambda3__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self);
  97. static void _lambda4_ (PluginQueryWindow* self);
  98. static gint plugin_query_window_plugin_db_disconnect (PluginQueryWindow* self);
  99. static void __lambda4__gtk_object_destroy (GtkObject* _sender, gpointer self);
  100. static void plugin_query_window_open_file (PluginQueryWindow* self, const gchar* filename);
  101. static void plugin_query_window_update_results (PluginQueryWindow* self);
  102. static void plugin_query_window_finalize (GObject* obj);
  103. gint plugin_version_check (gint abi_version);
  104. void plugin_set_info (PluginInfo* info);
  105. void plugin_init (GeanyData* data);
  106. static void _lambda5_ (void);
  107. static void __lambda5__gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self);
  108. void plugin_cleanup (void);
  109.  
  110.  
  111. static void _lambda0_ (PluginQueryWindow* self) {
  112.     plugin_query_window_on_open_clicked (self);
  113. }
  114.  
  115.  
  116. static void __lambda0__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self) {
  117.     _lambda0_ (self);
  118. }
  119.  
  120.  
  121. static void _lambda1_ (PluginQueryWindow* self) {
  122.     plugin_query_window_db_connect (self, "localhost", "webuser", "webuser", "fulcrum");
  123. }
  124.  
  125.  
  126. static void __lambda1__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self) {
  127.     _lambda1_ (self);
  128. }
  129.  
  130.  
  131. static void _lambda2_ (PluginQueryWindow* self) {
  132.     plugin_query_window_perform_query (self);
  133. }
  134.  
  135.  
  136. static void __lambda2__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self) {
  137.     _lambda2_ (self);
  138. }
  139.  
  140.  
  141. static void _lambda3_ (PluginQueryWindow* self) {
  142.     gtk_object_destroy ((GtkObject*) self);
  143. }
  144.  
  145.  
  146. static void __lambda3__gtk_tool_button_clicked (GtkToolButton* _sender, gpointer self) {
  147.     _lambda3_ (self);
  148. }
  149.  
  150.  
  151. static void _lambda4_ (PluginQueryWindow* self) {
  152.     plugin_query_window_plugin_db_disconnect (self);
  153. }
  154.  
  155.  
  156. static void __lambda4__gtk_object_destroy (GtkObject* _sender, gpointer self) {
  157.     _lambda4_ (self);
  158. }
  159.  
  160.  
  161. PluginQueryWindow* plugin_query_window_construct (GType object_type) {
  162.     PluginQueryWindow * self = NULL;
  163.     GtkToolButton* _tmp0_ = NULL;
  164.     GtkToolButton* open_button;
  165.     GtkToolButton* _tmp1_ = NULL;
  166.     GtkToolButton* connect_button;
  167.     GtkToolButton* _tmp2_ = NULL;
  168.     GtkToolButton* execute_button;
  169.     GtkToolButton* _tmp3_ = NULL;
  170.     GtkToolButton* close_button;
  171.     GtkToolbar* _tmp4_ = NULL;
  172.     GtkToolbar* toolbar;
  173.     GtkTextView* _tmp5_ = NULL;
  174.     GtkTextView* _tmp6_;
  175.     GtkTextBuffer* _tmp7_ = NULL;
  176.     GtkScrolledWindow* _tmp8_ = NULL;
  177.     GtkScrolledWindow* query_scroll;
  178.     GtkTreeView* _tmp9_ = NULL;
  179.     GtkTreeView* _tmp10_;
  180.     GtkScrolledWindow* _tmp11_ = NULL;
  181.     GtkScrolledWindow* result_scroll;
  182.     GtkVBox* _tmp12_ = NULL;
  183.     GtkVBox* vbox;
  184.     self = (PluginQueryWindow*) g_object_new (object_type, NULL);
  185.     gtk_window_set_title ((GtkWindow*) self, "Query Window");
  186.     ((GtkWindow*) self)->position = (guint) GTK_WIN_POS_CENTER;
  187.     gtk_window_set_default_size ((GtkWindow*) self, 800, 500);
  188.     ((GtkWindow*) self)->position = (guint) GTK_WIN_POS_CENTER;
  189.     self->priv->data_loaded = FALSE;
  190.     _tmp0_ = (GtkToolButton*) gtk_tool_button_new_from_stock (GTK_STOCK_OPEN);
  191.     open_button = g_object_ref_sink (_tmp0_);
  192.     gtk_tool_button_set_label (open_button, "Open Query");
  193.     g_signal_connect_object (open_button, "clicked", (GCallback) __lambda0__gtk_tool_button_clicked, self, 0);
  194.     _tmp1_ = (GtkToolButton*) gtk_tool_button_new_from_stock (GTK_STOCK_CONNECT);
  195.     connect_button = g_object_ref_sink (_tmp1_);
  196.     gtk_tool_button_set_label (connect_button, "Connect to DB");
  197.     g_signal_connect_object (connect_button, "clicked", (GCallback) __lambda1__gtk_tool_button_clicked, self, 0);
  198.     _tmp2_ = (GtkToolButton*) gtk_tool_button_new_from_stock (GTK_STOCK_EXECUTE);
  199.     execute_button = g_object_ref_sink (_tmp2_);
  200.     gtk_tool_button_set_label (execute_button, "Execute Query");
  201.     g_signal_connect_object (execute_button, "clicked", (GCallback) __lambda2__gtk_tool_button_clicked, self, 0);
  202.     _tmp3_ = (GtkToolButton*) gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
  203.     close_button = g_object_ref_sink (_tmp3_);
  204.     gtk_tool_button_set_label (close_button, "Close Window");
  205.     g_signal_connect_object (close_button, "clicked", (GCallback) __lambda3__gtk_tool_button_clicked, self, 0);
  206.     _tmp4_ = (GtkToolbar*) gtk_toolbar_new ();
  207.     toolbar = g_object_ref_sink (_tmp4_);
  208.     gtk_toolbar_set_style (toolbar, GTK_TOOLBAR_BOTH);
  209.     gtk_container_add ((GtkContainer*) toolbar, (GtkWidget*) open_button);
  210.     gtk_container_add ((GtkContainer*) toolbar, (GtkWidget*) connect_button);
  211.     gtk_container_add ((GtkContainer*) toolbar, (GtkWidget*) execute_button);
  212.     gtk_container_add ((GtkContainer*) toolbar, (GtkWidget*) close_button);
  213.     _tmp5_ = (GtkTextView*) gtk_text_view_new ();
  214.     _tmp6_ = g_object_ref_sink (_tmp5_);
  215.     _g_object_unref0 (self->priv->text_view);
  216.     self->priv->text_view = _tmp6_;
  217.     _tmp7_ = gtk_text_view_get_buffer (self->priv->text_view);
  218.     g_object_set (_tmp7_, "text", "select * from projects;", NULL);
  219.     _tmp8_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
  220.     query_scroll = g_object_ref_sink (_tmp8_);
  221.     gtk_scrolled_window_set_policy (query_scroll, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  222.     gtk_container_add ((GtkContainer*) query_scroll, (GtkWidget*) self->priv->text_view);
  223.     _tmp9_ = (GtkTreeView*) gtk_tree_view_new ();
  224.     _tmp10_ = g_object_ref_sink (_tmp9_);
  225.     _g_object_unref0 (self->priv->results);
  226.     self->priv->results = _tmp10_;
  227.     _tmp11_ = (GtkScrolledWindow*) gtk_scrolled_window_new (NULL, NULL);
  228.     result_scroll = g_object_ref_sink (_tmp11_);
  229.     gtk_scrolled_window_set_policy (result_scroll, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  230.     gtk_container_add ((GtkContainer*) result_scroll, (GtkWidget*) self->priv->results);
  231.     _tmp12_ = (GtkVBox*) gtk_vbox_new (FALSE, 0);
  232.     vbox = g_object_ref_sink (_tmp12_);
  233.     gtk_box_pack_start ((GtkBox*) vbox, (GtkWidget*) toolbar, FALSE, TRUE, (guint) 0);
  234.     gtk_box_pack_start ((GtkBox*) vbox, (GtkWidget*) query_scroll, TRUE, TRUE, (guint) 0);
  235.     gtk_box_pack_start ((GtkBox*) vbox, (GtkWidget*) result_scroll, TRUE, TRUE, (guint) 0);
  236.     gtk_container_add ((GtkContainer*) self, (GtkWidget*) vbox);
  237.     plugin_query_window_db_connect (self, "localhost", "webuser", "webuser", "fulcrum");
  238.     g_signal_connect_object ((GtkObject*) self, "destroy", (GCallback) __lambda4__gtk_object_destroy, self, 0);
  239.     gtk_widget_show_all ((GtkWidget*) self);
  240.     _g_object_unref0 (vbox);
  241.     _g_object_unref0 (result_scroll);
  242.     _g_object_unref0 (query_scroll);
  243.     _g_object_unref0 (toolbar);
  244.     _g_object_unref0 (close_button);
  245.     _g_object_unref0 (execute_button);
  246.     _g_object_unref0 (connect_button);
  247.     _g_object_unref0 (open_button);
  248.     return self;
  249. }
  250.  
  251.  
  252. PluginQueryWindow* plugin_query_window_new (void) {
  253.     return plugin_query_window_construct (TYPE_PLUGIN_QUERY_WINDOW);
  254. }
  255.  
  256.  
  257. static void plugin_query_window_on_open_clicked (PluginQueryWindow* self) {
  258.     GtkFileChooserDialog* _tmp0_ = NULL;
  259.     GtkFileChooserDialog* file_chooser;
  260.     gint _tmp1_;
  261.     g_return_if_fail (self != NULL);
  262.     _tmp0_ = (GtkFileChooserDialog*) gtk_file_chooser_dialog_new ("Open File", (GtkWindow*) self, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
  263.     file_chooser = g_object_ref_sink (_tmp0_);
  264.     _tmp1_ = gtk_dialog_run ((GtkDialog*) file_chooser);
  265.     if (_tmp1_ == GTK_RESPONSE_ACCEPT) {
  266.         gchar* _tmp2_ = NULL;
  267.         gchar* _tmp3_;
  268.         _tmp2_ = gtk_file_chooser_get_filename ((GtkFileChooser*) file_chooser);
  269.         _tmp3_ = _tmp2_;
  270.         plugin_query_window_open_file (self, _tmp3_);
  271.         _g_free0 (_tmp3_);
  272.     }
  273.     gtk_object_destroy ((GtkObject*) file_chooser);
  274.     _g_object_unref0 (file_chooser);
  275. }
  276.  
  277.  
  278. static void plugin_query_window_open_file (PluginQueryWindow* self, const gchar* filename) {
  279.     gchar* text = NULL;
  280.     gchar* _tmp0_ = NULL;
  281.     GtkTextBuffer* _tmp1_ = NULL;
  282.     GError * _inner_error_ = NULL;
  283.     g_return_if_fail (self != NULL);
  284.     g_return_if_fail (filename != NULL);
  285.     g_file_get_contents (filename, &_tmp0_, NULL, &_inner_error_);
  286.     _g_free0 (text);
  287.     text = _tmp0_;
  288.     if (_inner_error_ != NULL) {
  289.         _g_free0 (text);
  290.         goto __catch0_g_error;
  291.     }
  292.     _tmp1_ = gtk_text_view_get_buffer (self->priv->text_view);
  293.     g_object_set (_tmp1_, "text", text, NULL);
  294.     _g_free0 (text);
  295.     goto __finally0;
  296.     __catch0_g_error:
  297.     {
  298.         GError * e;
  299.         e = _inner_error_;
  300.         _inner_error_ = NULL;
  301.         fprintf (stderr, "Error: %s\n", e->message);
  302.         _g_error_free0 (e);
  303.     }
  304.     __finally0:
  305.     if (_inner_error_ != NULL) {
  306.         g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
  307.         g_clear_error (&_inner_error_);
  308.         return;
  309.     }
  310. }
  311.  
  312.  
  313. static void plugin_query_window_perform_query (PluginQueryWindow* self) {
  314.     GtkTextBuffer* _tmp0_ = NULL;
  315.     gchar* _tmp1_ = NULL;
  316.     gchar* query;
  317.     gchar* _tmp2_;
  318.     g_return_if_fail (self != NULL);
  319.     _tmp0_ = gtk_text_view_get_buffer (self->priv->text_view);
  320.     query = (g_object_get (_tmp0_, "text", &_tmp1_, NULL), _tmp1_);
  321.     _tmp2_ = g_strconcat ("trying to execute query: ", query, NULL);
  322.     msgwin_status_add ("%s", _tmp2_);
  323.     _g_free0 (_tmp2_);
  324.     if (g_strcmp0 (query, "") != 0) {
  325.         PGresult* _tmp3_ = NULL;
  326.         PGresult* _tmp4_;
  327.         _tmp3_ = PQexec (self->priv->pgconn, query);
  328.         _tmp4_ = _tmp3_;
  329.         _PQclear0 (self->priv->pgresult);
  330.         self->priv->pgresult = _tmp4_;
  331.         plugin_query_window_update_results (self);
  332.     } else {
  333.         GtkWindow* _tmp5_ = NULL;
  334.         GtkWindow* window;
  335.         GtkButton* _tmp6_ = NULL;
  336.         GtkButton* button;
  337.         _tmp5_ = (GtkWindow*) gtk_window_new (GTK_WINDOW_TOPLEVEL);
  338.         window = g_object_ref_sink (_tmp5_);
  339.         gtk_window_set_title (window, "Error");
  340.         gtk_window_set_default_size (window, 300, 50);
  341.         window->position = (guint) GTK_WIN_POS_CENTER;
  342.         _tmp6_ = (GtkButton*) gtk_button_new_with_label ("Please enter a query");
  343.         button = g_object_ref_sink (_tmp6_);
  344.         gtk_container_add ((GtkContainer*) window, (GtkWidget*) button);
  345.         gtk_widget_show_all ((GtkWidget*) window);
  346.         _g_object_unref0 (button);
  347.         _g_object_unref0 (window);
  348.     }
  349.     _g_free0 (query);
  350. }
  351.  
  352.  
  353. static gpointer _g_object_ref0 (gpointer self) {
  354.     return self ? g_object_ref (self) : NULL;
  355. }
  356.  
  357.  
  358. static void plugin_query_window_update_results (PluginQueryWindow* self) {
  359.     gint _tmp2_;
  360.     gint nFields;
  361.     GType* _tmp3_ = NULL;
  362.     GType* cols;
  363.     gint cols_length1;
  364.     gint _cols_size_;
  365.     GtkListStore* _tmp5_ = NULL;
  366.     GtkListStore* listmodel;
  367.     GtkTreeIter iter = {0};
  368.     g_return_if_fail (self != NULL);
  369.     if (self->priv->data_loaded) {
  370.         {
  371.             gint i;
  372.             i = self->priv->col_count;
  373.             {
  374.                 gboolean _tmp0_;
  375.                 _tmp0_ = TRUE;
  376.                 while (TRUE) {
  377.                     GtkTreeViewColumn* _tmp1_ = NULL;
  378.                     if (!_tmp0_) {
  379.                         i--;
  380.                     }
  381.                     _tmp0_ = FALSE;
  382.                     if (!(i >= 0)) {
  383.                         break;
  384.                     }
  385.                     _tmp1_ = gtk_tree_view_get_column (self->priv->results, i);
  386.                     gtk_tree_view_remove_column (self->priv->results, _tmp1_);
  387.                 }
  388.             }
  389.         }
  390.     }
  391.     _tmp2_ = PQnfields (self->priv->pgresult);
  392.     nFields = _tmp2_;
  393.     _tmp3_ = g_new0 (GType, nFields);
  394.     cols = _tmp3_;
  395.     cols_length1 = nFields;
  396.     _cols_size_ = nFields;
  397.     {
  398.         gint i;
  399.         i = 0;
  400.         {
  401.             gboolean _tmp4_;
  402.             _tmp4_ = TRUE;
  403.             while (TRUE) {
  404.                 if (!_tmp4_) {
  405.                     i++;
  406.                 }
  407.                 _tmp4_ = FALSE;
  408.                 if (!(i < nFields)) {
  409.                     break;
  410.                 }
  411.                 cols[i] = G_TYPE_STRING;
  412.             }
  413.         }
  414.     }
  415.     _tmp5_ = gtk_list_store_newv (cols_length1, cols);
  416.     listmodel = _tmp5_;
  417.     gtk_tree_view_set_model (self->priv->results, (GtkTreeModel*) listmodel);
  418.     {
  419.         gint i;
  420.         i = 0;
  421.         {
  422.             gboolean _tmp6_;
  423.             _tmp6_ = TRUE;
  424.             while (TRUE) {
  425.                 const gchar* _tmp7_ = NULL;
  426.                 GtkCellRendererText* _tmp8_ = NULL;
  427.                 GtkCellRendererText* _tmp9_;
  428.                 GtkTreeViewColumn* _tmp10_ = NULL;
  429.                 GtkTreeViewColumn* _tmp11_;
  430.                 GtkTreeViewColumn* column;
  431.                 const gchar* _tmp12_ = NULL;
  432.                 gchar* _tmp13_;
  433.                 gchar* _tmp14_;
  434.                 if (!_tmp6_) {
  435.                     i++;
  436.                 }
  437.                 _tmp6_ = FALSE;
  438.                 if (!(i < nFields)) {
  439.                     break;
  440.                 }
  441.                 _tmp7_ = PQfname (self->priv->pgresult, i);
  442.                 _tmp8_ = (GtkCellRendererText*) gtk_cell_renderer_text_new ();
  443.                 _tmp9_ = g_object_ref_sink (_tmp8_);
  444.                 gtk_tree_view_insert_column_with_attributes (self->priv->results, -1, _tmp7_, (GtkCellRenderer*) _tmp9_, "text", 0, NULL);
  445.                 _g_object_unref0 (_tmp9_);
  446.                 _tmp10_ = gtk_tree_view_get_column (self->priv->results, i);
  447.                 _tmp11_ = _g_object_ref0 (_tmp10_);
  448.                 column = _tmp11_;
  449.                 gtk_tree_view_column_set_resizable (column, TRUE);
  450.                 _tmp12_ = gtk_tree_view_column_get_title (column);
  451.                 _tmp13_ = g_strconcat ("Setting ", _tmp12_, NULL);
  452.                 _tmp14_ = g_strconcat (_tmp13_, " to resizable", NULL);
  453.                 msgwin_status_add ("%s", _tmp14_);
  454.                 _g_free0 (_tmp14_);
  455.                 _g_free0 (_tmp13_);
  456.                 _g_object_unref0 (column);
  457.             }
  458.         }
  459.     }
  460.     {
  461.         gint i;
  462.         i = 0;
  463.         {
  464.             gboolean _tmp15_;
  465.             _tmp15_ = TRUE;
  466.             while (TRUE) {
  467.                 gint _tmp16_;
  468.                 GtkTreeIter _tmp17_ = {0};
  469.                 if (!_tmp15_) {
  470.                     i++;
  471.                 }
  472.                 _tmp15_ = FALSE;
  473.                 _tmp16_ = PQntuples (self->priv->pgresult);
  474.                 if (!(i < _tmp16_)) {
  475.                     break;
  476.                 }
  477.                 gtk_list_store_append (listmodel, &_tmp17_);
  478.                 iter = _tmp17_;
  479.                 {
  480.                     gint j;
  481.                     j = 0;
  482.                     {
  483.                         gboolean _tmp18_;
  484.                         _tmp18_ = TRUE;
  485.                         while (TRUE) {
  486.                             const gchar* _tmp19_ = NULL;
  487.                             gchar* _tmp20_;
  488.                             gchar* myval;
  489.                             gchar* _tmp21_;
  490.                             if (!_tmp18_) {
  491.                                 j++;
  492.                             }
  493.                             _tmp18_ = FALSE;
  494.                             if (!(j < nFields)) {
  495.                                 break;
  496.                             }
  497.                             _tmp19_ = PQgetvalue (self->priv->pgresult, i, j);
  498.                             _tmp20_ = g_strdup ((const gchar*) _tmp19_);
  499.                             myval = _tmp20_;
  500.                             _tmp21_ = g_strconcat ("Result:", myval, NULL);
  501.                             msgwin_status_add ("%s", _tmp21_);
  502.                             // ^^ does work. The value from the db shows up in the status window
  503.                             _g_free0 (_tmp21_);
  504.                             gtk_list_store_set (listmodel, &iter, j, myval, -1);
  505.                             // ^^ doesn't work, puts the column number into the column instead of teh db val
  506.                            
  507.                             //gtk_list_store_set (listmodel, &iter, j, "test", -1);
  508.                             // ^^ does work. "test" is put into  the column
  509.                             _g_free0 (myval);
  510.                         }
  511.                     }
  512.                 }
  513.             }
  514.         }
  515.     }
  516.     self->priv->data_loaded = TRUE;
  517.     self->priv->col_count = nFields;
  518.     _g_object_unref0 (listmodel);
  519.     cols = (g_free (cols), NULL);
  520. }
  521.  
  522.  
  523. static gboolean plugin_query_window_db_connect (PluginQueryWindow* self, const gchar* host, const gchar* user, const gchar* password, const gchar* dbname) {
  524.     gboolean result = FALSE;
  525.     gchar* _tmp0_;
  526.     gchar* conninfo;
  527.     PGconn* _tmp9_ = NULL;
  528.     PGconn* _tmp10_;
  529.     ConnStatusType _tmp11_;
  530.     g_return_val_if_fail (self != NULL, FALSE);
  531.     g_return_val_if_fail (host != NULL, FALSE);
  532.     g_return_val_if_fail (user != NULL, FALSE);
  533.     g_return_val_if_fail (password != NULL, FALSE);
  534.     g_return_val_if_fail (dbname != NULL, FALSE);
  535.     _tmp0_ = g_strdup ("");
  536.     conninfo = _tmp0_;
  537.     if (g_strcmp0 (host, "") != 0) {
  538.         gchar* _tmp1_;
  539.         gchar* _tmp2_;
  540.         _tmp1_ = g_strconcat (" host=", host, NULL);
  541.         _tmp2_ = g_strconcat (conninfo, _tmp1_, NULL);
  542.         _g_free0 (conninfo);
  543.         conninfo = _tmp2_;
  544.         _g_free0 (_tmp1_);
  545.     }
  546.     if (g_strcmp0 (user, "") != 0) {
  547.         gchar* _tmp3_;
  548.         gchar* _tmp4_;
  549.         _tmp3_ = g_strconcat (" user=", user, NULL);
  550.         _tmp4_ = g_strconcat (conninfo, _tmp3_, NULL);
  551.         _g_free0 (conninfo);
  552.         conninfo = _tmp4_;
  553.         _g_free0 (_tmp3_);
  554.     }
  555.     if (g_strcmp0 (password, "") != 0) {
  556.         gchar* _tmp5_;
  557.         gchar* _tmp6_;
  558.         _tmp5_ = g_strconcat (" password=", password, NULL);
  559.         _tmp6_ = g_strconcat (conninfo, _tmp5_, NULL);
  560.         _g_free0 (conninfo);
  561.         conninfo = _tmp6_;
  562.         _g_free0 (_tmp5_);
  563.     }
  564.     if (g_strcmp0 (dbname, "") != 0) {
  565.         gchar* _tmp7_;
  566.         gchar* _tmp8_;
  567.         _tmp7_ = g_strconcat (" dbname=", dbname, NULL);
  568.         _tmp8_ = g_strconcat (conninfo, _tmp7_, NULL);
  569.         _g_free0 (conninfo);
  570.         conninfo = _tmp8_;
  571.         _g_free0 (_tmp7_);
  572.     }
  573.     _tmp9_ = PQconnectdb (conninfo);
  574.     _tmp10_ = _tmp9_;
  575.     _PQfinish0 (self->priv->pgconn);
  576.     self->priv->pgconn = _tmp10_;
  577.     _tmp11_ = PQstatus (self->priv->pgconn);
  578.     if (_tmp11_ != CONNECTION_OK) {
  579.         const gchar* _tmp12_ = NULL;
  580.         _tmp12_ = PQerrorMessage (self->priv->pgconn);
  581.         fprintf (stderr, "Connection to database failed: %s", _tmp12_);
  582.         result = FALSE;
  583.         _g_free0 (conninfo);
  584.         return result;
  585.     }
  586.     result = TRUE;
  587.     _g_free0 (conninfo);
  588.     return result;
  589. }
  590.  
  591.  
  592. static gint plugin_query_window_plugin_db_disconnect (PluginQueryWindow* self) {
  593.     gint result = 0;
  594.     g_return_val_if_fail (self != NULL, 0);
  595.     result = 1;
  596.     return result;
  597. }
  598.  
  599.  
  600. static void plugin_query_window_class_init (PluginQueryWindowClass * klass) {
  601.     plugin_query_window_parent_class = g_type_class_peek_parent (klass);
  602.     g_type_class_add_private (klass, sizeof (PluginQueryWindowPrivate));
  603.     G_OBJECT_CLASS (klass)->finalize = plugin_query_window_finalize;
  604. }
  605.  
  606.  
  607. static void plugin_query_window_instance_init (PluginQueryWindow * self) {
  608.     self->priv = PLUGIN_QUERY_WINDOW_GET_PRIVATE (self);
  609. }
  610.  
  611.  
  612. static void plugin_query_window_finalize (GObject* obj) {
  613.     PluginQueryWindow * self;
  614.     self = PLUGIN_QUERY_WINDOW (obj);
  615.     _g_object_unref0 (self->priv->results);
  616.     _g_object_unref0 (self->priv->text_view);
  617.     _PQfinish0 (self->priv->pgconn);
  618.     _PQclear0 (self->priv->pgresult);
  619.     G_OBJECT_CLASS (plugin_query_window_parent_class)->finalize (obj);
  620. }
  621.  
  622.  
  623. GType plugin_query_window_get_type (void) {
  624.     static volatile gsize plugin_query_window_type_id__volatile = 0;
  625.     if (g_once_init_enter (&plugin_query_window_type_id__volatile)) {
  626.         static const GTypeInfo g_define_type_info = { sizeof (PluginQueryWindowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) plugin_query_window_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (PluginQueryWindow), 0, (GInstanceInitFunc) plugin_query_window_instance_init, NULL };
  627.         GType plugin_query_window_type_id;
  628.         plugin_query_window_type_id = g_type_register_static (GTK_TYPE_WINDOW, "PluginQueryWindow", &g_define_type_info, 0);
  629.         g_once_init_leave (&plugin_query_window_type_id__volatile, plugin_query_window_type_id);
  630.     }
  631.     return plugin_query_window_type_id__volatile;
  632. }
  633.  
  634.  
  635. static gint __geany_vala_plugin_VERSION_CHECK (gint abi_version, gint api_required) {
  636.     gint result = 0;
  637.     if (abi_version != GEANY_ABI_VERSION) {
  638.         result = -1;
  639.         return result;
  640.     }
  641.     if (GEANY_API_VERSION < api_required) {
  642.         result = api_required;
  643.         return result;
  644.     }
  645.     result = 0;
  646.     return result;
  647. }
  648.  
  649.  
  650. gint plugin_version_check (gint abi_version) {
  651.     gint result = 0;
  652.     gint _tmp0_;
  653.     _tmp0_ = __geany_vala_plugin_VERSION_CHECK (abi_version, 185);
  654.     result = _tmp0_;
  655.     return result;
  656. }
  657.  
  658.  
  659. static void __geany_vala_plugin_SET_INFO (PluginInfo *self, const gchar* name, const gchar* description, const gchar* version, const gchar* author) {
  660.     g_return_if_fail (name != NULL);
  661.     (*self).name = name;
  662.     (*self).description = description;
  663.     (*self).version = version;
  664.     (*self).author = author;
  665. }
  666.  
  667.  
  668. void plugin_set_info (PluginInfo* info) {
  669.     __geany_vala_plugin_SET_INFO (info, "Database Plugin", "A plugin for Geany to view databases", "0.1", "Mike Thorn");
  670. }
  671.  
  672.  
  673. static void _lambda5_ (void) {
  674.     PluginQueryWindow* _tmp0_ = NULL;
  675.     PluginQueryWindow* _tmp1_;
  676.     _tmp0_ = plugin_query_window_new ();
  677.     _tmp1_ = g_object_ref_sink (_tmp0_);
  678.     _g_object_unref0 (_tmp1_);
  679. }
  680.  
  681.  
  682. static void __lambda5__gtk_menu_item_activate (GtkMenuItem* _sender, gpointer self) {
  683.     _lambda5_ ();
  684. }
  685.  
  686.  
  687. void plugin_init (GeanyData* data) {
  688.     GtkMenuItem* item = NULL;
  689.     GtkWidget* _tmp0_ = NULL;
  690.     GtkWidget* _tmp1_;
  691.     GtkMenuShell* menu;
  692.     GtkMenuItem* _tmp4_ = NULL;
  693.     GtkMenuItem* _tmp5_;
  694.     g_return_if_fail (data != NULL);
  695.     _tmp0_ = ui_lookup_widget ((GtkWidget*) geany_data->main_widgets->window, "menu_document1_menu");
  696.     menu = (_tmp1_ = _tmp0_, GTK_IS_MENU_SHELL (_tmp1_) ? ((GtkMenuShell*) _tmp1_) : NULL);
  697.     if (menu == NULL) {
  698.         menu = geany_data->main_widgets->tools_menu;
  699.     } else {
  700.         GtkSeparatorMenuItem* _tmp2_ = NULL;
  701.         GtkMenuItem* _tmp3_;
  702.         _tmp2_ = (GtkSeparatorMenuItem*) gtk_separator_menu_item_new ();
  703.         _tmp3_ = (GtkMenuItem*) g_object_ref_sink (_tmp2_);
  704.         _g_object_unref0 (item);
  705.         item = _tmp3_;
  706.         gtk_menu_shell_append (menu, (GtkWidget*) item);
  707.         G_destroy_widget_stack = g_slist_append (G_destroy_widget_stack, (GtkWidget*) item);
  708.         gtk_widget_show ((GtkWidget*) item);
  709.     }
  710.     _tmp4_ = (GtkMenuItem*) gtk_menu_item_new_with_label ("Query Window");
  711.     _tmp5_ = g_object_ref_sink (_tmp4_);
  712.     _g_object_unref0 (item);
  713.     item = _tmp5_;
  714.     g_signal_connect (item, "activate", (GCallback) __lambda5__gtk_menu_item_activate, NULL);
  715.     gtk_menu_shell_append (menu, (GtkWidget*) item);
  716.     G_destroy_widget_stack = g_slist_append (G_destroy_widget_stack, (GtkWidget*) item);
  717.     gtk_widget_show ((GtkWidget*) item);
  718.     _g_object_unref0 (item);
  719. }
  720.  
  721.  
  722. void plugin_cleanup (void) {
  723.     {
  724.         GSList* w_collection;
  725.         GSList* w_it;
  726.         w_collection = G_destroy_widget_stack;
  727.         for (w_it = w_collection; w_it != NULL; w_it = w_it->next) {
  728.             GtkWidget* w;
  729.             w = (GtkWidget*) w_it->data;
  730.             {
  731.                 gtk_object_destroy ((GtkObject*) w);
  732.             }
  733.         }
  734.     }
  735. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement