File: linkWizard.c

package info (click to toggle)
screem 0.2.1-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 3,748 kB
  • ctags: 2,270
  • sloc: ansic: 26,366; sh: 7,453; makefile: 512; sed: 93; perl: 18
file content (187 lines) | stat: -rw-r--r-- 5,016 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*  Screem:  linkWizard.c,
 *  The link wizard, converted to being a g_module  
 *
 *  Copyright (C) 1999  David A Knight
 *
 *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  For contact information with the author of this source code please see
 *  the AUTHORS file.  If there is no AUTHORS file present then check the
 *  about box under the help menu for a contact address
 */

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

#include <gmodule.h>
#include <gnome.h>

#include <glade/glade.h>

#include "site.h"
#include "page.h"
#include "editor.h"

#include "link.xpm"

extern GtkWidget *app;
extern Site *current_site;
extern Page *current_page;

static GladeXML *xml;
static GtkWidget *dialog = NULL;

void linkWizard();
void link_wizard_delete( GtkWidget *widget, GdkEvent *event, gpointer data );
void link_wizard_clicked( GtkWidget *widget, gint button, gpointer data );


G_MODULE_EXPORT const gchar*
g_module_check_init( GModule *module )
{
	g_print("linkWizard: check-init\n");
	return NULL;
}

G_MODULE_EXPORT void
g_module_unload( GModule *module )
{
	g_print( "linkWizard: unloaded\n" );
}

G_MODULE_EXPORT void 
init() 
{
	GtkWidget *linkButton;
	GtkWidget *toolbar;

	GnomeUIInfo menuinfo[] = { 
		{
			GNOME_APP_UI_ITEM, N_( "Link..." ),
			N_( "Insert a link" ),
			linkWizard, NULL, NULL,
			GNOME_APP_PIXMAP_STOCK,
			GNOME_STOCK_MENU_BLANK,
			0,
			GDK_CONTROL_MASK, NULL
		},
		GNOMEUIINFO_END
	};


	toolbar = gtk_object_get_data( GTK_OBJECT( app ), "wizardbar" );

	/* place menu item after image under insert */
	gnome_app_insert_menus( GNOME_APP( app ),
				_("_Insert/"), menuinfo);

	/* place a button on the wizards toolbar */
	linkButton = gnome_pixmap_new_from_xpm_d( LINK_XPM );
	gtk_toolbar_append_item( GTK_TOOLBAR( toolbar ), "",
				 _("Link Wizard"), "", linkButton ,
				 linkWizard, 0 );

	g_print( "linkWizard: initialised\n" );
}

/******************************************************************/
void link_wizard_delete( GtkWidget *widget, GdkEvent *event, gpointer data )
{
        dialog = NULL;
}
/******************************************************************/
void link_wizard_clicked( GtkWidget *widget, gint button, gpointer data )
{
	gchar *text;
	gchar *protocol = NULL;
	gchar *target_text;
	gint pos;

	GtkWidget *toggle;
	GtkWidget *ltext;
	GtkWidget *link;
	GtkWidget *target;

	if( button < 2 ) { /* applied or ok'ed */
		toggle = glade_xml_get_widget( xml, "http" );
		if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( toggle )) )
			protocol = "http://";

		toggle = glade_xml_get_widget( xml, "ftp" );
		if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( toggle )) )
			protocol = "ftp://";

		toggle = glade_xml_get_widget( xml, "mailto" );
		if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( toggle ) ))
			protocol = "mailto:";
		
		if( ! protocol )
			protocol = "";

		link = glade_xml_get_widget( xml, "link_to" );
		ltext = glade_xml_get_widget( xml, "link_text" );
		target = glade_xml_get_widget( xml, "target_text" );

		target_text = gtk_entry_get_text( GTK_ENTRY( target ) );
		if( strcmp( "", target_text ) ) {
			target_text = g_strdup_printf( " target=\"%s\"",
						       target_text );
		} else {
			target_text = g_strdup( "" );
		}

		text = g_strdup_printf( "<a href=\"%s%s\"%s>%s</a>", protocol,
					gtk_entry_get_text( GTK_ENTRY(link) ),
					target_text,
					gtk_entry_get_text(GTK_ENTRY(ltext)) );

		pos = screem_editor_get_pos();
                screem_editor_insert( pos, text );
		screem_editor_set_pos( pos + strlen( text ) );
		
		g_free( text );
		g_free( target_text );
	}
	if( button == 2 || button == 0 ) { /* ok or close clicked */
                gtk_widget_destroy( widget );
		dialog = NULL;
		g_free( data );
        }
}
/******************************************************************/
void linkWizard()
{
  	Page *page;

	if( current_site )
		page = screem_site_get_current_page( current_site );
	else
		page = current_page;
	
	g_return_if_fail( page != NULL );
	
        if( dialog ) {
                gdk_window_raise( dialog->window );
                gdk_window_show( dialog->window );
                return;
        }

	xml = glade_xml_new( GLADE_PATH"/linkWizard.glade", 
			     "link_wizard_dialog" );
	glade_xml_signal_autoconnect( xml );

	dialog = glade_xml_get_widget( xml, "link_wizard_dialog" );
}