Mercurial > pidgin.yaz
comparison finch/libgnt/gnttextview.c @ 18426:841670dd24e1
Utility function to start the pager with the contents of a textview.
The default pager is 'less', and the default key-combination to trigger it
is 'a-v'. These can be changed like:
[pager]
path=/some/other/pager
key=a-e
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Tue, 03 Jul 2007 11:17:35 +0000 |
parents | e659842fe66d |
children | 09db6fec9dce |
comparison
equal
deleted
inserted
replaced
18425:84d318eadc62 | 18426:841670dd24e1 |
---|---|
18 * You should have received a copy of the GNU General Public License | 18 * You should have received a copy of the GNU General Public License |
19 * along with this program; if not, write to the Free Software | 19 * along with this program; if not, write to the Free Software |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 */ | 21 */ |
22 | 22 |
23 #include "gntstyle.h" | |
23 #include "gnttextview.h" | 24 #include "gnttextview.h" |
24 #include "gntutils.h" | 25 #include "gntutils.h" |
25 | 26 |
27 #include <stdlib.h> | |
26 #include <string.h> | 28 #include <string.h> |
27 | 29 |
28 enum | 30 enum |
29 { | 31 { |
30 SIGS = 1, | 32 SIGS = 1, |
791 void gnt_text_view_set_flag(GntTextView *view, GntTextViewFlag flag) | 793 void gnt_text_view_set_flag(GntTextView *view, GntTextViewFlag flag) |
792 { | 794 { |
793 view->flags |= flag; | 795 view->flags |= flag; |
794 } | 796 } |
795 | 797 |
798 static gboolean | |
799 check_for_pager_cb(GntWidget *widget, const char *key, GntTextView *view) | |
800 { | |
801 static const char *combin = NULL; | |
802 char *argv[] = {NULL, NULL, NULL}; | |
803 static char path[1024]; | |
804 static int len = -1; | |
805 FILE *file; | |
806 | |
807 if (combin == NULL) { | |
808 combin = gnt_key_translate(gnt_style_get_from_name("pager", "key")); | |
809 if (combin == NULL) | |
810 combin = "\033" "v"; | |
811 len = g_snprintf(path, sizeof(path), "%s" G_DIR_SEPARATOR_S "gnt", g_get_tmp_dir()); | |
812 } else { | |
813 g_snprintf(path + len, sizeof(path) - len, "XXXXXX"); | |
814 } | |
815 | |
816 if (strcmp(key, combin)) { | |
817 return FALSE; | |
818 } | |
819 | |
820 file = fdopen(g_mkstemp(path), "wb"); | |
821 if (!file) | |
822 return FALSE; | |
823 | |
824 fprintf(file, "%s", view->string->str); | |
825 fclose(file); | |
826 argv[0] = gnt_style_get_from_name("pager", "path"); | |
827 argv[0] = argv[0] ? argv[0] : getenv("PAGER"); | |
828 argv[0] = argv[0] ? argv[0] : "less"; | |
829 argv[1] = path; | |
830 return gnt_giveup_console(NULL, argv, NULL, NULL, NULL, NULL); | |
831 } | |
832 | |
833 void gnt_text_view_attach_pager_widget(GntTextView *view, GntWidget *pager) | |
834 { | |
835 g_signal_connect(pager, "key_pressed", G_CALLBACK(check_for_pager_cb), view); | |
836 } | |
837 |