summary refs log blame commit diff stats
path: root/src/gtk2-prefs/callbacks.cpp
blob: 383dcde99f8b34b04702609c89b52129f8852596 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                                            































































































































































































































                                                                                                                         
/* GTK+ Preference Tool
 * Copyright (C) 2003-2005 Alex Shaduri.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>
#include <iostream>

#include "callbacks.h"
#include "interface.h"
#include "support.h"

#include "main.h"



extern GtkWidget* g_main_window;

void
on_main_showpreviewtoggle_toggled               (GtkToggleButton *togglebutton,
                                        gpointer         user_data)
{
	if (gtk_toggle_button_get_active (togglebutton)) {
		gtk_widget_show(lookup_widget(g_main_window, "main_previewhbox"));
		gtk_button_set_label(GTK_BUTTON(togglebutton), "Hide preview <<");
		gtk_window_resize(GTK_WINDOW(g_main_window), 700, 330);
	} else {
		gtk_widget_hide(lookup_widget(g_main_window, "main_previewhbox"));
		gtk_button_set_label(GTK_BUTTON(togglebutton), "Show preview >>");
		gtk_window_resize(GTK_WINDOW(g_main_window), 300, 330);
	}

}


/*
extern GtkWidget* g_fontsel_dialog;


void
on_fontsel_dialog_response             (GtkDialog       *dialog,
                                        gint             id,
                                        gpointer         user_data)
{

	switch(id) {
		case GTK_RESPONSE_OK:
		{
			const char* font = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG(dialog));
			std::string f = (font ? font : "");
			set_theme(get_selected_theme(), f);
			break;
		}
//		case GTK_RESPONSE_CANCEL:
//			gtk_widget_destroy(g_fontsel_dialog);
//			g_fontsel_dialog = 0;
//			return;

	}
	gtk_widget_destroy(g_fontsel_dialog);
	g_fontsel_dialog = 0;

}


gboolean
on_fontsel_dialog_delete_event         (GtkWidget       *widget,
                                        GdkEvent        *event,
                                        gpointer         user_data)
{
	gtk_widget_destroy(g_fontsel_dialog);
	g_fontsel_dialog = 0;

	return FALSE;
}


void
on_main_fontselectbutton_clicked       (GtkButton       *button,
                                        gpointer         user_data)
{
	g_fontsel_dialog = create_fontsel_dialog();
	gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(g_fontsel_dialog), get_current_font().c_str());
	gtk_widget_show(g_fontsel_dialog);
}
*/





void
on_main_ok_button_clicked              (GtkButton       *button,
                                        gpointer         user_data)
{
	if (save_current_theme())
		gtk_main_quit();
}


void
on_main_cancel_button_clicked          (GtkButton       *button,
                                        gpointer         user_data)
{
	gtk_main_quit();
}


void
on_main_reset_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
	set_theme(get_orig_theme(), get_orig_font());
}


gboolean
on_main_window_delete_event            (GtkWidget       *widget,
                                        GdkEvent        *event,
                                        gpointer         user_data)
{
	program_shutdown();
	return true;
}


void
on_main_use_default_font_radio_toggled (GtkToggleButton *togglebutton,
                                        gpointer         user_data)
{
	bool default_font = gtk_toggle_button_get_active(togglebutton);

	gtk_widget_set_sensitive(lookup_widget(g_main_window, "main_font_selector_button"), !default_font);

	apply_theme(get_selected_theme(), get_selected_font());
}


void
on_main_font_selector_button_font_set  (GtkFontButton   *fontbutton,
                                        gpointer         user_data)
{
	apply_theme(get_selected_theme(), get_selected_font());
}


void
on_new2_activate                       (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_open2_activate                      (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_save2_activate                      (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_save_as2_activate                   (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_quit2_activate                      (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_cut2_activate                       (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_copy2_activate                      (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_paste2_activate                     (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_delete2_activate                    (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}


void
on_about2_activate                     (GtkMenuItem     *menuitem,
                                        gpointer         user_data)
{

}
an>, (commit,)) conn.commit() conn.close() @ganarchy.command() @click.argument('project-title') def set_project_title(project_title): """Sets the project title""" import re conn = sqlite3.connect(data_home + "/ganarchy.db") c = conn.cursor() c.execute('''UPDATE config SET project_title=?''', (project_title,)) conn.commit() conn.close() @ganarchy.group() def repo(): """Modifies repos to track""" @repo.command() @click.argument('url') def add(url): """Adds a repo to track""" conn = sqlite3.connect(data_home + "/ganarchy.db") c = conn.cursor() c.execute('''INSERT INTO repos VALUES (?, 0)''', (url,)) conn.commit() conn.close() @repo.command() @click.argument('url') def enable(url): """Enables tracking of a repo""" conn = sqlite3.connect(data_home + "/ganarchy.db") c = conn.cursor() c.execute('''UPDATE repos SET active=1 WHERE url=?''', (url,)) conn.commit() conn.close() @repo.command() @click.argument('url') def disable(url): """Disables tracking of a repo""" conn = sqlite3.connect(data_home + "/ganarchy.db") c = conn.cursor() c.execute('''UPDATE repos SET active=0 WHERE url=?''', (url,)) conn.commit() conn.close() @repo.command() @click.argument('url') def remove(url): """Stops tracking a repo""" click.confirm("WARNING: This operation does not delete the commits associated with the given repo! Are you sure you want to continue? This operation cannot be undone.") conn = sqlite3.connect(data_home + "/ganarchy.db") c = conn.cursor() c.execute('''DELETE FROM repos WHERE url=?''', (url,)) c.execute('''DELETE FROM repo_history WHERE url=?''', (url,)) conn.commit() conn.close() @ganarchy.command() def cron_target(): """Runs ganarchy as a cron target""" def handle_target(url, project_commit): branchname = hashlib.sha256(url.encode("utf-8")).hexdigest() try: pre_hash = subprocess.check_output(["git", "-C", cache_home, "show", branchname, "-s", "--format=%H", "--"], stderr=subprocess.DEVNULL).decode("utf-8").strip() except subprocess.CalledProcessError: pre_hash = None try: subprocess.check_output(["git", "-C", cache_home, "fetch", "-q", url, "+HEAD:" + branchname], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: # This may error for various reasons, but some are important: dead links, etc click.echo(e.output, err=True) return None post_hash = subprocess.check_output(["git", "-C", cache_home, "show", branchname, "-s", "--format=%H", "--"], stderr=subprocess.DEVNULL).decode("utf-8").strip() if not pre_hash: pre_hash = post_hash try: count = int(subprocess.check_output(["git", "-C", cache_home, "rev-list", "--count", pre_hash + ".." + post_hash, "--"]).decode("utf-8").strip()) except subprocess.CalledProcessError: count = 0 # force-pushed try: subprocess.check_call(["git", "-C", cache_home, "merge-base", "--is-ancestor", project_commit, branchname], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) return count, post_hash, subprocess.check_output(["git", "-C", cache_home, "show", branchname, "-s", "--format=%B", "--"], stderr=subprocess.DEVNULL).decode("utf-8", "replace") except subprocess.CalledProcessError: return None os.makedirs(cache_home, exist_ok=True) subprocess.call(["git", "-C", cache_home, "init", "-q"]) conn = sqlite3.connect(data_home + "/ganarchy.db") c = conn.cursor() c.execute('''SELECT git_commit, project_title FROM config''') (project_commit, project_title) = c.fetchone() entries = [] generate_html = [] for (url,) in c.execute("""SELECT url FROM repos WHERE active == 1"""): result = handle_target(url, project_commit) if result is not None: count, post_hash, msg = result entries.append((url, count, post_hash)) generate_html.append((url, msg, count)) c.executemany('''INSERT INTO repo_history VALUES (NULL, ?, ?, ?)''', entries) conn.commit() generate_html.sort(key=lambda x: x[2]) # sort by count html_entries = [] for (url, msg, count) in generate_html: history = c.execute('''SELECT count FROM repo_history WHERE url == ? ORDER BY entry ASC''', (url,)).fetchall() # TODO process history into SVG html_entries.append((url, msg, "")) template = jinja2.Template(TEMPLATE) click.echo(template.render(project_title = project_title, repos = html_entries)) if __name__ == "__main__": ganarchy()