Changeset 36fa5fe45a5f19487d82bff9bb2c33e39175041a
- Timestamp:
- 04/12/08 20:07:45 (5 years ago)
- Parents:
- 6eef44e8de0bbc7a63172c7ad06877a8dda58917
- Children:
- b5b6b61caca9af9f79824bc52bcfaee7c585d287
- git-committer:
- Armin Burgmeier <armin@arbur.net> / 2008-04-12T20:07:45Z+0200
- Files:
-
- 9 added
- 44 removed
- 29 modified
- 3 moved
-
.gitignore (modified) (1 diff)
-
ChangeLog (modified) (1 diff)
-
Makefile.am (modified) (2 diffs)
-
configure.ac (modified) (4 diffs)
-
contrib/Makefile.am (added)
-
contrib/artwork/Makefile.am (added)
-
contrib/artwork/chat.svg (deleted)
-
contrib/gobby-0.0.20050522.ebuild (deleted)
-
inc/.gitignore (modified) (1 diff)
-
inc/Makefile.am (added)
-
inc/application_state.hpp (deleted)
-
inc/buffer_def.hpp (deleted)
-
inc/chat.hpp (deleted)
-
inc/colorsel.hpp (deleted)
-
inc/config.hpp (modified) (18 diffs)
-
inc/default_accumulator.hpp (moved) (moved from inc/historyentry.hpp) (2 diffs)
-
inc/document.hpp (deleted)
-
inc/document_settings.hpp (deleted)
-
inc/dragdrop.hpp (modified) (2 diffs)
-
inc/encoding.hpp (modified) (1 diff)
-
inc/entrydialog.hpp (deleted)
-
inc/fileentry.hpp (deleted)
-
inc/finddialog.hpp (modified) (5 diffs)
-
inc/folder.hpp (modified) (2 diffs)
-
inc/gselector.hpp (deleted)
-
inc/hostdialog.hpp (deleted)
-
inc/hostprogressdialog.hpp (deleted)
-
inc/i18n.hpp (moved) (moved from inc/common.hpp) (3 diffs)
-
inc/ipc.hpp (deleted)
-
inc/joindialog.hpp (deleted)
-
inc/joinprogressdialog.hpp (deleted)
-
inc/logview.hpp (deleted)
-
inc/passworddialog.hpp (deleted)
-
inc/progressdialog.hpp (deleted)
-
inc/regex.hpp (deleted)
-
inc/serialize.hpp (added)
-
inc/statusbar.hpp (modified) (1 diff)
-
inc/togglewindow.hpp (deleted)
-
inc/unix.hpp (deleted)
-
inc/window.hpp (modified) (7 diffs)
-
pixmaps/Makefile.am (added)
-
po/POTFILES.in (modified) (1 diff)
-
src/.gitignore (added)
-
src/Makefile.am (added)
-
src/application_state.cpp (deleted)
-
src/browser.cpp (modified) (2 diffs)
-
src/buffer_def.cpp (deleted)
-
src/chat.cpp (deleted)
-
src/colorsel.cpp (deleted)
-
src/config.cpp (modified) (9 diffs)
-
src/document.cpp (deleted)
-
src/document_settings.cpp (deleted)
-
src/dragdrop.cpp (modified) (2 diffs)
-
src/encoding.cpp (modified) (1 diff)
-
src/encoding_selector.cpp (modified) (1 diff)
-
src/entrydialog.cpp (deleted)
-
src/fileentry.cpp (deleted)
-
src/finddialog.cpp (modified) (13 diffs)
-
src/folder.cpp (modified) (1 diff)
-
src/gotodialog.cpp (modified) (4 diffs)
-
src/gselector.cpp (deleted)
-
src/header.cpp (modified) (1 diff)
-
src/historyentry.cpp (deleted)
-
src/hostdialog.cpp (deleted)
-
src/hostprogressdialog.cpp (deleted)
-
src/i18n.cpp (moved) (moved from src/common.cpp) (2 diffs)
-
src/icon.cpp (modified) (2 diffs)
-
src/initialdialog.cpp (modified) (1 diff)
-
src/ipc.cpp (deleted)
-
src/joindialog.cpp (deleted)
-
src/joinprogressdialog.cpp (deleted)
-
src/logview.cpp (deleted)
-
src/main.cpp (modified) (6 diffs)
-
src/passworddialog.cpp (deleted)
-
src/preferencesdialog.cpp (modified) (1 diff)
-
src/progressdialog.cpp (deleted)
-
src/regex.cpp (deleted)
-
src/resolv.cpp (modified) (1 diff)
-
src/serialize.cpp (added)
-
src/statusbar.cpp (modified) (1 diff)
-
src/togglewindow.cpp (deleted)
-
src/unix.cpp (deleted)
-
src/window.cpp (modified) (6 diffs)
-
test/test_document.cpp (deleted)
-
win32/Makefile.am (added)
Legend:
- Unmodified
- Added
- Removed
-
.gitignore
rc623d52 r36fa5fe 16 16 autom4te.cache 17 17 .deps 18 compile -
ChangeLog
r6eef44e r36fa5fe 1 2008-04-12 Armin Burgmeier <armin@0x539.de> 2 3 * contrib/gobby-0.0.20050522.ebuild: 4 * contrib/artwork/chat.svg: 5 * test/test_document.cpp: Removed, these are outdated. 6 7 * inc/default_accumulator.hpp: 8 * inc/serialize.hpp: 9 * src/serialize.cpp: Added. These are basically copies from net6, but 10 in the Gobby namespace. 11 12 * inc/i18n.hpp: 13 * src/i18n.cpp: Moved from inc/common.hpp or src/common.cpp, 14 respectively. 15 16 * inc/application_state.hpp: 17 * inc/buffer_def.hpp: 18 * inc/chat.hpp: 19 * inc/colorsel.hpp: 20 * inc/historyentry.hpp: 21 * inc/document.hpp: 22 * inc/document_settings.hpp: 23 * inc/entrydialog.hpp: 24 * inc/fileentry.hpp: 25 * inc/gselector.hpp: 26 * inc/hostdialog.hpp: 27 * inc/hostprogressdialog.hpp: 28 * inc/ipc.hpp: 29 * inc/joindialog.hpp: 30 * inc/joinprogressdialog.hpp: 31 * inc/logview.hpp: 32 * inc/passworddialog.hpp: 33 * inc/progressdialog.hpp: 34 * inc/regex.hpp: 35 * inc/togglewindow.hpp: 36 * inc/unix.hpp: 37 * src/application_state.cpp: 38 * src/buffer_def.cpp: 39 * src/chat.cpp: 40 * src/colorsel.cpp: 41 * src/document.cpp: 42 * src/document_settings.cpp: 43 * src/entrydialog.cpp: 44 * src/fileentry.cpp: 45 * src/gselector.cpp: 46 * src/historyentry.cpp: 47 * src/hostdialog.cpp: 48 * src/hostprogressdialog.cpp: 49 * src/ipc.cpp: 50 * src/joindialog.cpp: 51 * src/joinprogressdialog.cpp: 52 * src/logview.cpp: 53 * src/passworddialog.cpp: 54 * src/preferencesdialog.cpp: 55 * src/progressdialog.cpp: 56 * src/regex.cpp: 57 * src/togglewindow.cpp: 58 * src/unix.cpp: Removed. They are no longer required for infinote, or 59 at least not in a such way that a complete rewrite would not be easier 60 anyway. 61 62 * inc/config.hpp: 63 * inc/dragdrop.hpp: 64 * inc/encoding.hpp: 65 * inc/finddialog.hpp: 66 * inc/folder.hpp: 67 * inc/statusbar.hpp: 68 * inc/window.hpp: 69 * src/browser.cpp: 70 * src/config.cpp: 71 * src/dragdrop.cpp: 72 * src/encoding.cpp: 73 * src/encoding_selector.cpp: 74 * src/finddialog.cpp: 75 * src/folder.cpp: 76 * src/gotodialog.cpp: 77 * src/header.cpp: 78 * src/icon.cpp: 79 * src/initialdialog.cpp: 80 * src/main.cpp: 81 * src/resolv.cpp: 82 * src/statusbar.cpp: 83 * src/window.cpp: Removed any occurences of net6/obby stuff, replaced 84 by equivalent functionlity if possible. 85 86 * po/POTFILES.in: Removed source files, added a TODO comment to readd 87 them as soon as the required files are ready. 88 89 * Makefile.am: 90 * contrib/Makefile.am: 91 * contrib/artwork/Makefile.am: 92 * inc/Makefile.am: 93 * pixmaps/Makefile.am: 94 * src/Makefile.am: 95 * win32/Makefile.am: Hierarchical build instead of only a top-level 96 Makefile.am, so that each Makefile.am is smaller and easier to use. 97 98 * configure.ac: Remove dependency on net6 and obby. 99 1 100 2008-04-12 Armin Burgmeier <armin@0x539.de> 2 101 -
Makefile.am
r00f0fd0 r36fa5fe 1 SUBDIRS = m4 . po1 SUBDIRS = m4 contrib pixmaps win32 inc src . po 2 2 3 3 # Tell aclocal where to find `.m4' files. … … 8 8 bin_PROGRAMS = gobby 9 9 10 gobby_LDADD = $(gobby_LIBS) $(gtksourceview_LIBS) 11 gobby_CPPFLAGS = $(gobby_CFLAGS) $(gtksourceview_CFLAGS) 12 gobby_CPPFLAGS += -I../inc/ -DLOCALE_DIR=\""$(datadir)/locale"\" 13 14 if WITH_AVAHI 15 gobby_LDADD += $(avahi_LIBS) 16 gobby_CPPFLAGS += $(avahi_CFLAGS) 10 if WIN32 11 gobby_LDADD = $(gobby_LIBS) src/libgobby.a -lole32 -luuid 12 gobby_LDFLAGS = -Wl,--enable-runtime-pseudo-reloc -mwindows win32/gobby.res 13 else 14 gobby_LDADD = $(gobby_LIBS) src/libgobby.a 17 15 endif 18 16 19 if WITH_GNOME 20 gobby_LDADD += $(gnome_LIBS) 21 gobby_CPPFLAGS += $(gnome_CFLAGS) 22 endif 23 24 if WIN32 25 gobby_LDADD += -lole32 -luuid 26 gobby_LDFLAGS = -Wl,--enable-runtime-pseudo-reloc -mwindows win32/gobby.res 27 endif 28 29 noinst_HEADERS = inc/icon.hpp 30 if WIN32 31 else 32 noinst_HEADERS += inc/unix.hpp 33 endif 34 noinst_HEADERS += inc/gselector.hpp 35 noinst_HEADERS += inc/browser.hpp 36 noinst_HEADERS += inc/ipc.hpp 37 noinst_HEADERS += inc/colorutil.hpp 38 noinst_HEADERS += inc/config.hpp 39 noinst_HEADERS += inc/common.hpp 40 noinst_HEADERS += inc/encoding.hpp 41 noinst_HEADERS += inc/resolv.hpp 42 noinst_HEADERS += inc/regex.hpp 43 noinst_HEADERS += inc/application_state.hpp 44 noinst_HEADERS += inc/encoding_selector.hpp 45 noinst_HEADERS += inc/historyentry.hpp 46 noinst_HEADERS += inc/fileentry.hpp 47 noinst_HEADERS += inc/logview.hpp 48 noinst_HEADERS += inc/colorsel.hpp 49 noinst_HEADERS += inc/preferences.hpp 50 noinst_HEADERS += inc/toolwindow.hpp 51 noinst_HEADERS += inc/togglewindow.hpp 52 noinst_HEADERS += inc/header.hpp 53 noinst_HEADERS += inc/statusbar.hpp 54 noinst_HEADERS += inc/document.hpp 55 noinst_HEADERS += inc/buffer_def.hpp 56 noinst_HEADERS += inc/docwindow.hpp 57 noinst_HEADERS += inc/folder.hpp 58 noinst_HEADERS += inc/document_settings.hpp 59 noinst_HEADERS += inc/chat.hpp 60 noinst_HEADERS += inc/preferencesdialog.hpp 61 noinst_HEADERS += inc/initialdialog.hpp 62 noinst_HEADERS += inc/passworddialog.hpp 63 noinst_HEADERS += inc/hostdialog.hpp 64 noinst_HEADERS += inc/joindialog.hpp 65 noinst_HEADERS += inc/progressdialog.hpp 66 noinst_HEADERS += inc/joinprogressdialog.hpp 67 noinst_HEADERS += inc/hostprogressdialog.hpp 68 noinst_HEADERS += inc/entrydialog.hpp 69 noinst_HEADERS += inc/finddialog.hpp 70 noinst_HEADERS += inc/gotodialog.hpp 71 noinst_HEADERS += inc/dragdrop.hpp 72 noinst_HEADERS += inc/window.hpp 73 74 if WIN32 75 win32/gobby.res: win32/gobby.rc 76 $(WINDRES) -i win32/gobby.rc --input-format=rc -o win32/gobby.res -O coff 77 BUILT_SOURCES = win32/gobby.res 78 endif 79 80 gobby_SOURCES = src/icon.cpp 81 if WIN32 82 else 83 gobby_SOURCES += src/unix.cpp 84 endif 85 gobby_SOURCES += src/gselector.cpp 86 gobby_SOURCES += src/browser.cpp 87 gobby_SOURCES += src/ipc.cpp 88 gobby_SOURCES += src/colorutil.cpp 89 gobby_SOURCES += src/config.cpp 90 gobby_SOURCES += src/common.cpp 91 gobby_SOURCES += src/encoding.cpp 92 gobby_SOURCES += src/resolv.cpp 93 gobby_SOURCES += src/regex.cpp 94 gobby_SOURCES += src/application_state.cpp 95 gobby_SOURCES += src/encoding_selector.cpp 96 gobby_SOURCES += src/historyentry.cpp 97 gobby_SOURCES += src/fileentry.cpp 98 gobby_SOURCES += src/logview.cpp 99 gobby_SOURCES += src/colorsel.cpp 100 gobby_SOURCES += src/preferences.cpp 101 gobby_SOURCES += src/toolwindow.cpp 102 gobby_SOURCES += src/togglewindow.cpp 103 gobby_SOURCES += src/header.cpp 104 gobby_SOURCES += src/statusbar.cpp 105 gobby_SOURCES += src/document.cpp 106 gobby_SOURCES += src/buffer_def.cpp 107 gobby_SOURCES += src/docwindow.cpp 108 gobby_SOURCES += src/folder.cpp 109 gobby_SOURCES += src/document_settings.cpp 110 gobby_SOURCES += src/chat.cpp 111 gobby_SOURCES += src/preferencesdialog.cpp 112 gobby_SOURCES += src/initialdialog.cpp 113 gobby_SOURCES += src/passworddialog.cpp 114 gobby_SOURCES += src/hostdialog.cpp 115 gobby_SOURCES += src/joindialog.cpp 116 gobby_SOURCES += src/progressdialog.cpp 117 gobby_SOURCES += src/joinprogressdialog.cpp 118 gobby_SOURCES += src/hostprogressdialog.cpp 119 gobby_SOURCES += src/entrydialog.cpp 120 gobby_SOURCES += src/finddialog.cpp 121 gobby_SOURCES += src/gotodialog.cpp 122 gobby_SOURCES += src/dragdrop.cpp 123 gobby_SOURCES += src/window.cpp 124 gobby_SOURCES += src/main.cpp 125 126 appicondir = $(datadir)/pixmaps 127 pixmapdir = $(datadir)/pixmaps/gobby 128 gobby_CPPFLAGS += -DAPPICON_DIR=\""$(appicondir)"\" 129 gobby_CPPFLAGS += -DPIXMAPS_DIR=\""$(pixmapdir)"\" 130 dist_appicon_DATA = pixmaps/gobby.png 131 dist_pixmap_DATA = pixmaps/userlist.png 132 dist_pixmap_DATA += pixmaps/doclist.png 133 dist_pixmap_DATA += pixmaps/chat.png 134 135 if WITH_GNOME 136 # GNOME-specific installation. 137 desktopdir = $(datadir)/applications 138 desktop_DATA = contrib/gobby.desktop 139 endif 140 141 EXTRA_DIST = contrib/artwork/CREDITS 142 EXTRA_DIST += contrib/artwork/gobby.svg 143 EXTRA_DIST += contrib/artwork/gobby.xpm.gz 144 EXTRA_DIST += contrib/gobby.desktop 145 EXTRA_DIST += win32/gobby.ico 146 EXTRA_DIST += win32/gobby.rc 147 148 check_PROGRAMS = document 149 TESTS = document 150 151 document_SOURCES = test/test_document.cpp 152 document_SOURCES += src/document.cpp 153 document_SOURCES += src/gselector.cpp 154 document_LDADD = $(gobby_LIBS) $(gtksourceview_LIBS) 155 document_CPPFLAGS = $(gobby_CFLAGS) $(gtksourceview_CFLAGS) 156 17 gobby_SOURCES = -
configure.ac
r1f3ebdc r36fa5fe 19 19 AC_PROG_LN_S 20 20 AC_PROG_MAKE_SET 21 AC_PROG_RANLIB 22 AM_PROG_CC_C_O 21 23 AC_CACHE_SAVE 22 24 … … 35 37 AM_CONDITIONAL(WIN32, test x$win32 = xtrue) 36 38 37 required_libs="libxml++-2.6 g tkmm-2.4 >= 2.12.0 gthread-2.0 net6-1.3 obby-0.4 >= 0.4.5gtksourceview-2.0 libinfinity-1.0 libinftext-1.0 libinfgtk-1.0 libinftextgtk-1.0"39 required_libs="libxml++-2.6 glibmm-2.4 >= 2.16.0 gtkmm-2.4 >= 2.12.0 gthread-2.0 gtksourceview-2.0 libinfinity-1.0 libinftext-1.0 libinfgtk-1.0 libinftextgtk-1.0" 38 40 39 41 # Checks for libraries. … … 57 59 AC_CACHE_SAVE 58 60 59 # Check for Zeroconf support in obby.60 PKG_CHECK_MODULES([obby], [obby-0.4])61 AC_CHECK_LIB(obby, obby_has_zeroconf, [obby_has_zeroconf=yes],62 [obby_has_zeroconf=no], [$pkg_cv_obby_LIBS])63 if test "x$ac_cv_lib_obby_obby_has_zeroconf" = "xyes" ; then64 # obby's pkg-config script takes care of any additional dependencies65 AC_DEFINE([WITH_ZEROCONF], 1, [Define whether to use Zeroconf])66 fi67 AM_CONDITIONAL(WITH_ZEROCONF, test x$ac_cv_lib_obby_obby_has_zeroconf = xyes)68 69 # Check for a specific Zeroconf support in obby, namely Avahi.70 AC_CHECK_LIB(obby, obby_has_avahi, [obby_has_avahi=yes],71 [obby_has_avahi=no], [$pkg_cv_obby_LIBS])72 if test "x$ac_cv_lib_obby_obby_has_avahi" = "xyes" ; then73 AC_DEFINE([WITH_AVAHI], 1,74 [Define whether to use Avahi as Zeroconf backend])75 PKG_CHECK_MODULES([avahi], [avahi-glib])76 fi77 AM_CONDITIONAL(WITH_AVAHI, test x$ac_cv_lib_obby_obby_has_avahi = xyes)78 79 # Check if we are running on OS X, for special link handling.80 if test "x$build_vendor" = "xapple" ; then81 AC_DEFINE([OSX], 1, [Define whether we are running on Mac OS X.])82 fi83 AC_CACHE_SAVE84 85 61 # Glib i18n/gettext support. 86 62 ALL_LINGUAS="ca de es fr ko it pl pt pt_BR ru sv zh_CN" … … 91 67 AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["${GETTEXT_PACKAGE}"], [gettext domain]) 92 68 93 AC_CONFIG_FILES([Makefile]) 94 AC_OUTPUT([po/Makefile.in m4/Makefile]) 69 AC_OUTPUT([ 70 Makefile 71 m4/Makefile 72 po/Makefile.in 95 73 74 inc/Makefile 75 src/Makefile 76 77 contrib/Makefile 78 contrib/artwork/Makefile 79 pixmaps/Makefile 80 win32/Makefile 81 ]) 82 -
inc/.gitignore
rc623d52 r36fa5fe 1 1 features.hpp 2 2 features.hpp.in 3 features.hpp.in~ 3 4 stamp-h1 -
inc/config.hpp
r54c07dd r36fa5fe 20 20 #define _GOBBY_CONFIG_HPP_ 21 21 22 #include "serialize.hpp" 23 22 24 #include <map> 23 25 #include <memory> 24 #include <net6/non_copyable.hpp>25 #include <net6/serialise.hpp>26 26 #include <glibmm/error.h> 27 27 #include <glibmm/ustring.h> … … 35 35 { 36 36 37 class Config : private net6::non_copyable37 class Config 38 38 { 39 39 public: … … 51 51 /** @brief Abstract base class for configuration file entries. 52 52 */ 53 class Entry : private net6::non_copyable53 class Entry 54 54 { 55 55 public: … … 80 80 const Glib::ustring& name, 81 81 const DataType& value, 82 const seriali se::context_base_to<DataType>& ctx =83 seriali se::default_context_to<DataType>()82 const serialize::context_base_to<DataType>& ctx = 83 serialize::default_context_to<DataType>() 84 84 ); 85 85 … … 89 89 template<typename DataType> 90 90 DataType get( 91 const seriali se::context_base_from<DataType>& ctx =92 seriali se::default_context_from<DataType>()91 const serialize::context_base_from<DataType>& ctx = 92 serialize::default_context_from<DataType>() 93 93 ) const; 94 94 95 95 protected: 96 seriali se::data m_data;96 serialize::data m_data; 97 97 }; 98 98 … … 110 110 const Glib::ustring& name, 111 111 const DataType& value, 112 const seriali se::context_base_to<DataType>& ctx =113 seriali se::default_context_to<DataType>()112 const serialize::context_base_to<DataType>& ctx = 113 serialize::default_context_to<DataType>() 114 114 ); 115 115 … … 223 223 const Glib::ustring& name, 224 224 const DataType& default_value = DataType(), 225 const seriali se::context_base_from<DataType>& ctx =226 seriali se::default_context_from<DataType>()225 const serialize::context_base_from<DataType>& ctx = 226 serialize::default_context_from<DataType>() 227 227 ) const; 228 228 … … 238 238 const Glib::ustring& name, 239 239 const DataType& default_value = DataType(), 240 const seriali se::context_base_from<DataType>& ctx_from =241 seriali se::default_context_from<DataType>(),242 const seriali se::context_base_to<DataType>& ctx_to =243 seriali se::default_context_to<DataType>()240 const serialize::context_base_from<DataType>& ctx_from = 241 serialize::default_context_from<DataType>(), 242 const serialize::context_base_to<DataType>& ctx_to = 243 serialize::default_context_to<DataType>() 244 244 ); 245 245 … … 254 254 const Glib::ustring& name, 255 255 const DataType& value, 256 const seriali se::context_base_to<DataType>& ctx =257 seriali se::default_context_to<DataType>()256 const serialize::context_base_to<DataType>& ctx = 257 serialize::default_context_to<DataType>() 258 258 ); 259 259 … … 311 311 ValueEntry(const Glib::ustring& name, 312 312 const DataType& value, 313 const seriali se::context_base_to<DataType>& ctx):313 const serialize::context_base_to<DataType>& ctx): 314 314 Entry(name), m_data(value, ctx) 315 315 { … … 318 318 template<typename DataType> 319 319 DataType Config::ValueEntry:: 320 get(const seriali se::context_base_from<DataType>& from) const321 { 322 return m_data. ::serialise::data::as<DataType>(from);320 get(const serialize::context_base_from<DataType>& from) const 321 { 322 return m_data.Gobby::serialize::data::as<DataType>(from); 323 323 } 324 324 … … 327 327 TypedValueEntry(const Glib::ustring& name, 328 328 const DataType& value, 329 const seriali se::context_base_to<DataType>& ctx):329 const serialize::context_base_to<DataType>& ctx): 330 330 ValueEntry(name, value, ctx) 331 331 { … … 341 341 void Config::TypedValueEntry<DataType>::save(xmlpp::Element& elem) const 342 342 { 343 elem.set_child_text(m_data.seriali sed() );343 elem.set_child_text(m_data.serialized() ); 344 344 } 345 345 … … 400 400 get_value(const Glib::ustring& name, 401 401 const DataType& default_value, 402 const seriali se::context_base_from<DataType>& ctx) const402 const serialize::context_base_from<DataType>& ctx) const 403 403 { 404 404 const ValueEntry* entry = get_value_child(name); … … 411 411 supply_value(const Glib::ustring& name, 412 412 const DataType& default_value, 413 const seriali se::context_base_from<DataType>& ctx_from,414 const seriali se::context_base_to<DataType>& ctx_to)413 const serialize::context_base_from<DataType>& ctx_from, 414 const serialize::context_base_to<DataType>& ctx_to) 415 415 { 416 416 ValueEntry* entry = get_value_child(name); … … 425 425 set_value(const Glib::ustring& name, 426 426 const DataType& value, 427 const seriali se::context_base_to<DataType>& ctx)427 const serialize::context_base_to<DataType>& ctx) 428 428 { 429 429 Entry* entry = get_child(name); … … 433 433 } 434 434 435 } // namespace Gobby 436 437 namespace serialise 435 namespace serialize 438 436 { 439 437 … … 479 477 }; 480 478 481 } // namespace serialise 479 } // namespace serialize 480 481 } // namespace Gobby 482 482 483 483 #endif // _GOBBY_CONFIG_HPP_ -
inc/default_accumulator.hpp
rbfb82f7 r36fa5fe 1 1 /* gobby - A GTKmm driven libobby client 2 * Copyright (C) 2005 0x539 dev group2 * Copyright (C) 2005 - 2008 0x539 dev group 3 3 * 4 4 * This program is free software; you can redistribute it and/or … … 17 17 */ 18 18 19 #ifndef _GOBBY_HISTORYENTRY_HPP_ 20 #define _GOBBY_HISTORYENTRY_HPP_ 21 22 #include <list> 23 #include <gtkmm/entry.h> 19 #ifndef _GOBBY_DEFAULT_ACCUMULATOR_HPP_ 20 #define _GOBBY_DEFAULT_ACCUMULATOR_HPP_ 24 21 25 22 namespace Gobby 26 23 { 27 24 28 /** Entry field which allows to scroll in history using up and down arrows keys. 25 /** Accumulator for signals with return type that defaults to a value if no 26 * signal handler is connected. 29 27 */ 30 28 31 class HistoryEntry : public Gtk::Entry 32 {29 template<typename return_type, return_type default_return> 30 class default_accumulator { 33 31 public: 34 HistoryEntry(); 35 virtual ~HistoryEntry(); 32 typedef return_type result_type; 36 33 37 void clear_history(); 38 39 protected: 40 virtual void on_activate(); 41 virtual bool on_key_press_event(GdkEventKey* event); 42 43 void scroll_down(); 44 void scroll_up(); 45 46 std::list<Glib::ustring> m_history; 47 std::list<Glib::ustring>::iterator m_pos; 34 template<typename iterator> 35 result_type operator()(iterator begin, iterator end) const { 36 return_type result = default_return; 37 for(; begin != end; ++ begin) 38 result = *begin; 39 return result; 40 } 48 41 }; 49 42 50 } 51 52 #endif // _GOBBY_ HISTORYENTRY_HPP_43 } // namespace Gobby 44 45 #endif // _GOBBY_DEFAULT_ACCUMULATOR_HPP_ -
inc/dragdrop.hpp
r3e869ac r36fa5fe 21 21 22 22 #include <sigc++/trackable.h> 23 #include <net6/non_copyable.hpp>24 23 25 24 namespace Gobby … … 31 30 */ 32 31 33 class DragDrop: public sigc::trackable , private net6::non_copyable32 class DragDrop: public sigc::trackable 34 33 { 35 34 public: -
inc/encoding.hpp
rfe534f33 r36fa5fe 20 20 #define _GOBBY_ENCODING_HPP_ 21 21 22 #include <list> 23 #include <gtkmm/textview.h> 22 #include <glibmm/ustring.h> 23 24 #include <vector> 25 #include <string> 24 26 25 27 namespace Gobby -
inc/finddialog.hpp
rc2b92c8 r36fa5fe 20 20 #define _GOBBY_FINDDIALOG_HPP_ 21 21 22 #include "docwindow.hpp" 23 #include "toolwindow.hpp" 24 22 25 #include <gtkmm/window.h> 23 26 #include <gtkmm/separator.h> … … 29 32 #include <gtkmm/radiobutton.h> 30 33 #include <gtkmm/frame.h> 31 32 #include "toolwindow.hpp"33 #include "regex.hpp"34 34 35 35 namespace Gobby … … 84 84 Gtk::TextIter& match_end); 85 85 86 void update_regex();87 void compile_regex();88 89 86 Gobby::Window& m_gobby; 90 87 … … 106 103 Gtk::CheckButton m_check_whole_word; 107 104 Gtk::CheckButton m_check_case; 108 Gtk::CheckButton m_check_regex;109 105 110 106 Gtk::Frame m_frame_direction; … … 118 114 Gtk::Button m_btn_replace_all; 119 115 Gtk::Button m_btn_close; 120 121 regex m_regex;122 bool m_regex_changed;123 116 }; 124 117 -
inc/folder.hpp
r6eef44e r36fa5fe 21 21 22 22 #include <sigc++/signal.h> 23 #include <net6/default_accumulator.hpp>24 23 #include <gtksourceview/gtksourcelanguagemanager.h> 25 24 #include <gtkmm/notebook.h> 26 25 26 #include "docwindow.hpp" 27 27 #include "preferences.hpp" 28 #include "d ocwindow.hpp"28 #include "default_accumulator.hpp" 29 29 30 30 namespace Gobby … … 39 39 40 40 typedef sigc::signal<bool, DocWindow&>:: 41 accumulated< net6::default_accumulator<bool, true> >41 accumulated<default_accumulator<bool, true> > 42 42 SignalDocumentCloseRequest; 43 43 -
inc/i18n.hpp
rc603f7c r36fa5fe 17 17 */ 18 18 19 #ifndef _GOBBY_COMMON_HPP_ 20 #define _GOBBY_COMMON_HPP_ 21 22 #include "net6/gettext_package.hpp" 19 #ifndef _GOBBY_I18N_HPP_ 20 #define _GOBBY_I18N_HPP_ 23 21 24 22 namespace Gobby 25 23 { 26 27 /** Initalises gettext for usage with Gobby. Translations a looked up in the28 * given catalog.29 */30 void init_gettext(net6::gettext_package& package);31 24 32 25 /** Translates a message from the gobby catalog. … … 34 27 const char* _(const char* msgid); 35 28 36 /** Translate plurali sed message from the gobby catalog.29 /** Translate pluralized message from the gobby catalog. 37 30 */ 38 31 const char* ngettext(const char* msgid, … … 42 35 } 43 36 44 #endif // _GOBBY_ COMMON_HPP_37 #endif // _GOBBY_I18N_HPP_ 45 38 -
inc/statusbar.hpp
r6eef44e r36fa5fe 20 20 #define _GOBBY_STATUSBAR_HPP_ 21 21 22 #include "folder.hpp" 23 24 #include <gtkmm/box.h> 25 #include <gtkmm/statusbar.h> 26 22 27 #include <glibmm/ustring.h> 23 #include <gtkmm/box.h>24 #include <gtkmm/label.h>25 #include <gtkmm/frame.h>26 #include <gtkmm/statusbar.h>27 #include <obby/user.hpp>28 #include "document.hpp"29 #include "buffer_def.hpp"30 #include "header.hpp"31 #include "folder.hpp"32 28 33 29 namespace Gobby -
inc/window.hpp
r6eef44e r36fa5fe 32 32 #include "icon.hpp" 33 33 #include "config.hpp" 34 #include "application_state.hpp"35 #include "ipc.hpp"36 34 #include "header.hpp" 37 35 #include "docwindow.hpp" 38 #include "buffer_def.hpp"39 #include "hostdialog.hpp"40 #include "joindialog.hpp"41 36 #include "finddialog.hpp" 42 37 #include "gotodialog.hpp" … … 44 39 #include "initialdialog.hpp" 45 40 #include "folder.hpp" 46 #include "document_settings.hpp"47 41 #include "browser.hpp" 48 42 #include "statusbar.hpp" 49 43 #include "dragdrop.hpp" 50 #ifdef WITH_ZEROCONF51 #include <obby/zeroconf.hpp>52 #endif53 #ifdef WITH_AVAHI54 #include <obby/zeroconf_avahi.hpp>55 #include <avahi-glib/glib-watch.h>56 #endif57 44 58 45 namespace Gobby … … 65 52 ~Window(); 66 53 67 /** Offers a pointer to the currently visible document. If the user 68 * is not subscribed to a document, NULL is returned. 69 */ 70 DocWindow* get_current_document(); 54 const Folder& get_folder() const { return m_folder; } 55 Folder& get_folder() { return m_folder; } 71 56 72 /** @brief Opens a session with the current default settings.73 *74 * If initial_dialog is true a dialog to turn the host parameters is75 * opened, otherwise the default settings are taken.76 *77 * If the session opening failed, a dialog appears where the user78 * might adjust settings or abort.79 *80 * This function must not be called when a buffer is already open.81 */82 bool session_open(bool initial_dialog);83 84 /** @brief Joins a session with the current default settings.85 *86 * If initial_dialog is true a dialog to turn the join parameters is87 * opened, otherwise the default settings are used.88 *89 * If the session join failed, a dialog appears where the user90 * might adjust settings or abort.91 *92 * This function must not be called when a buffer is already open.93 */94 bool session_join(bool initial_dialog);95 96 /** Opens a document containing the content of a file mounted on the97 * local filesystem.98 */99 void open_local_file(const Glib::ustring& file,100 const std::string& encoding);101 102 /** Saves an existing document to the given path.103 */104 void save_local_file(DocWindow& doc,105 const Glib::ustring& file,106 const std::string& encoding);107 57 protected: 108 58 // Gtk::Window overrides … … 113 63 void on_initial_dialog_hide(); 114 64 115 // Start/End obby session116 void obby_start();117 void obby_end();118 119 // Header UI handler120 void on_session_create();121 void on_session_join();122 void on_session_save();123 void on_session_quit();124 125 void on_document_create();126 void on_document_open();127 void on_document_save();128 bool handle_document_save();129 void on_document_save_as();130 bool handle_document_save_as();131 void on_document_close();132 133 void on_edit_search();134 void on_edit_search_replace();135 void on_edit_goto_line();136 void on_edit_preferences();137 138 void on_user_set_password();139 void on_user_set_colour();140 141 void on_view_preferences();142 void on_view_language(GtkSourceLanguage* language);143 144 void on_window_chat();145 #if 0146 // Folder UI handler147 void on_folder_document_add(DocWindow& window);148 void on_folder_document_remove(DocWindow& window);149 void on_folder_document_close_request(DocWindow& window);150 void on_folder_tab_switched(DocWindow& window);151 #endif152 void on_settings_document_insert(LocalDocumentInfo& info);153 154 void on_about();155 void on_quit();156 157 // Obby signal handlers158 void on_obby_close();159 160 void on_obby_user_join(const obby::user& user);161 void on_obby_user_part(const obby::user& user);162 void on_obby_user_colour(const obby::user& user);163 void on_obby_user_colour_failed();164 void on_obby_document_insert(DocumentInfo& document);165 void on_obby_document_remove(DocumentInfo& document);166 167 // IPC signal handlers168 void on_ipc_file(const std::string& file);169 170 // Helper functions171 void apply_preferences();172 void update_title_bar();173 void close_document(DocWindow& doc);174 void display_error(const Glib::ustring& message,175 const Gtk::MessageType type = Gtk::MESSAGE_ERROR);176 177 bool session_join_impl(const Glib::ustring& host,178 unsigned int port,179 const Glib::ustring& name,180 const Gdk::Color& color);181 182 bool session_open_impl(unsigned int port,183 const Glib::ustring& name,184 const Gdk::Color& color,185 const Glib::ustring& password,186 const Glib::ustring& session);187 188 65 // Config 189 66 Config& m_config; … … 191 68 Preferences m_preferences; 192 69 const IconManager& m_icon_mgr; 193 194 // Paths195 std::string m_last_path;196 std::string m_prev_session;197 198 std::string m_local_file_path;199 std::string m_local_encoding;200 70 201 71 // GUI … … 206 76 Gtk::Frame m_frame_text; 207 77 208 ApplicationState m_application_state;209 DocumentSettings m_document_settings;210 211 78 Header m_header; 212 79 Folder m_folder; … … 214 81 Browser m_browser; 215 82 216 std::auto_ptr<FindDialog> m_finddialog; 217 std::auto_ptr<GotoDialog> m_gotodialog; 218 219 sigc::connection m_conn_chat_realize; 220 221 /** Drag+Drop handler 222 */ 83 // TODO: Can't we use this directly now that the session is 84 // "always open"? 223 85 std::auto_ptr<DragDrop> m_dnd; 224 225 /** Local IPC handler226 */227 std::auto_ptr<Ipc::LocalInstance> m_ipc;228 std::queue<std::string> m_file_queue;229 86 230 87 // Dialogs 231 88 std::auto_ptr<InitialDialog> m_initial_dlg; 232 89 std::auto_ptr<PreferencesDialog> m_preferences_dlg; 233 std::auto_ptr<HostDialog> m_host_dlg; 234 std::auto_ptr<JoinDialog> m_join_dlg; 235 236 // obby 237 std::auto_ptr<LocalBuffer> m_buffer; 238 #ifdef WITH_ZEROCONF 239 std::auto_ptr<obby::zeroconf_base> m_zeroconf; 240 #endif 241 #ifdef WITH_AVAHI 242 AvahiGLibPoll* m_glib_poll; 243 #endif 244 sigc::connection m_timer_conn; 90 std::auto_ptr<FindDialog> m_finddialog; 91 std::auto_ptr<GotoDialog> m_gotodialog; 245 92 }; 246 93 -
po/POTFILES.in
r492197d r36fa5fe 1 1 # source files 2 2 3 src/application_state.cpp 4 src/buffer_def.cpp 5 src/chat.cpp 6 src/colorsel.cpp 7 src/common.cpp 8 src/config.cpp 9 src/document.cpp 10 src/documentlist.cpp 11 src/document_settings.cpp 12 src/docwindow.cpp 13 src/dragdrop.cpp 14 src/encoding.cpp 15 src/encoding_selector.cpp 16 src/entrydialog.cpp 17 src/fileentry.cpp 18 src/finddialog.cpp 19 src/folder.cpp 20 src/gotodialog.cpp 21 src/gselector.cpp 22 src/header.cpp 23 src/historyentry.cpp 24 src/hostdialog.cpp 25 src/hostprogressdialog.cpp 26 src/icon.cpp 27 src/ipc.cpp 28 src/joindialog.cpp 29 src/joinprogressdialog.cpp 30 src/logview.cpp 31 src/main.cpp 32 src/passworddialog.cpp 33 src/preferences.cpp 34 src/preferencesdialog.cpp 35 src/progressdialog.cpp 36 src/regex.cpp 37 src/statusbar.cpp 38 src/togglewindow.cpp 39 src/toolwindow.cpp 40 src/unix.cpp 41 src/userlist.cpp 42 src/window.cpp 3 # TODO -
src/browser.cpp
r6eef44e r36fa5fe 18 18 19 19 #include "browser.hpp" 20 #include "common.hpp" 21 22 #include <obby/format_string.hpp> 20 #include "i18n.hpp" 21 23 22 #include <libinfinity/inf-config.h> 24 23 #include <libinfinity/common/inf-discovery-avahi.h> … … 194 193 // Translators: That's a Unicode horizontal ellipsis character, 195 194 // not three dots. 196 obby::format_string status_str("Resolving %0%âŠ");197 status_str << host;198 195 StatusBar::MessageHandle message_handle = 199 m_status_bar.add_message(StatusBar::INFO, 200 status_str.str(), 0); 196 m_status_bar.add_message( 197 StatusBar::INFO, Glib::ustring::compose( 198 _("Resolving %0âŠ"), host), 0); 201 199 202 200 m_resolv_map[resolv_handle].message_handle = message_handle; -
src/config.cpp
r5bc7ec4 r36fa5fe 17 17 */ 18 18 19 #include "config.hpp" 20 #include "i18n.hpp" 21 22 #include <glibmm/miscutils.h> 23 #include <glibmm/fileutils.h> 24 #include <glibmm/exception.h> 25 #include <libxml++/parsers/domparser.h> 26 #include <libxml++/exceptions/exception.h> 27 19 28 // For mkdir / CreateDirectory 20 29 #ifdef WIN32 … … 29 38 #include <stdexcept> 30 39 31 #include <glibmm/miscutils.h>32 #include <glibmm/fileutils.h>33 #include <glibmm/exception.h>34 #include <libxml++/parsers/domparser.h>35 #include <libxml++/exceptions/exception.h>36 37 #include "config.hpp"38 39 40 namespace 40 41 { … … 42 43 void create_directory(const char* path) 43 44 { 45 using namespace Gobby; 44 46 #ifdef WIN32 45 47 if(CreateDirectoryA(path, NULL) == FALSE) … … 66 68 throw Gobby::Config::Error( 67 69 Gobby::Config::Error::PATH_CREATION_FAILED, 68 "Could not create directory " + 69 std::string(path) + ": " + error_message 70 ); 70 Glib::ustring::compose( 71 _("Could not create directory " 72 "\"%1\": %2"), std::string(path), 73 error_message)); 71 74 } 72 75 #else … … 75 78 throw Gobby::Config::Error( 76 79 Gobby::Config::Error::PATH_CREATION_FAILED, 77 "Could not create directory " + 78 std::string(path) + ": " + strerror(errno) 79 ); 80 Glib::ustring::compose( 81 _("Could not create directory " 82 "\"%1\": %2"), std::string(path), 83 strerror(errno))); 80 84 } 81 85 #endif … … 338 342 } 339 343 340 std::string serialise::default_context_to<Gdk::Color>::344 std::string Gobby::serialize::default_context_to<Gdk::Color>:: 341 345 to_string(const data_type& from) const 342 346 { … … 350 354 } 351 355 352 serialise::default_context_from<Gdk::Color>::data_type353 serialise::default_context_from<Gdk::Color>::356 Gobby::serialize::default_context_from<Gdk::Color>::data_type 357 Gobby::serialize::default_context_from<Gdk::Color>:: 354 358 from_string(const std::string& from) const 355 359 { … … 372 376 } 373 377 374 std::string serialise::default_context_to<Glib::ustring>::378 std::string Gobby::serialize::default_context_to<Glib::ustring>:: 375 379 to_string(const data_type& from) const 376 380 { … … 378 382 } 379 383 380 serialise::default_context_from<Glib::ustring>::data_type381 serialise::default_context_from<Glib::ustring>::384 Gobby::serialize::default_context_from<Glib::ustring>::data_type 385 Gobby::serialize::default_context_from<Glib::ustring>:: 382 386 from_string(const std::string& from) const 383 387 { -
src/dragdrop.cpp
rddc15e4 r36fa5fe 176 176 DragQueryFileA(drop, i, buf, size + 1); 177 177 178 m_window.open_local_file( 178 // TODO: User still needs to select where to store 179 // that file in the directory. 180 /*m_window.open_local_file( 179 181 buf, 180 182 Gobby::EncodingSelector::AUTO_DETECT 181 ); 183 );*/ 182 184 183 185 delete[] buf; … … 240 242 } 241 243 242 window.open_local_file( 244 // TODO: User still needs to select where to store 245 // that file in the directory. 246 /*window.open_local_file( 243 247 filename, 244 248 Gobby::EncodingSelector::AUTO_DETECT 245 ); 249 );*/ 246 250 } 247 251 } -
src/encoding.cpp
rfe534f33 r36fa5fe 17 17 */ 18 18 19 #include <cstdlib>20 #include "common.hpp"21 19 #include "encoding.hpp" 20 #include "i18n.hpp" 21 22 #include <glibmm/convert.h> 22 23 23 24 namespace -
src/encoding_selector.cpp
r38afe53 r36fa5fe 17 17 */ 18 18 19 #include "encoding_selector.hpp" 20 #include "encoding.hpp" 21 #include "i18n.hpp" 22 23 #include <gtkmm/liststore.h> 19 24 #include <stdexcept> 20 #include <gtkmm/liststore.h>21 22 #include "common.hpp"23 #include "encoding.hpp"24 #include "encoding_selector.hpp"25 25 26 26 const std::string Gobby::EncodingSelector::AUTO_DETECT = "Auto Detect"; -
src/finddialog.cpp
r6eef44e r36fa5fe 17 17 */ 18 18 19 #include "finddialog.hpp" 20 #include "window.hpp" 21 #include "i18n.hpp" 22 23 #include <gtkmm/messagedialog.h> 24 #include <gtkmm/textbuffer.h> 25 #include <gtkmm/stock.h> 19 26 #include <gtksourceview/gtksourceiter.h> 20 #include <gtkmm/stock.h>21 #include <gtkmm/messagedialog.h>22 23 #include "common.hpp"24 #include "document.hpp"25 #include "window.hpp"26 #include "finddialog.hpp"27 27 28 28 namespace … … 45 45 m_check_whole_word(_("Match whole word only")), 46 46 m_check_case(_("Match case")), 47 m_check_regex(_("Match as regular expression")),48 47 m_frame_direction(_("Direction")), 49 48 m_radio_up(m_group_direction, _("_Up"), true), … … 52 51 m_btn_replace(_("_Replace") ), 53 52 m_btn_replace_all(_("Replace _all") ), 54 m_btn_close(Gtk::Stock::CLOSE), 55 m_regex("") 53 m_btn_close(Gtk::Stock::CLOSE) 56 54 { 57 55 Gtk::Image* replace_img = Gtk::manage( … … 97 95 m_box_options.pack_start(m_check_whole_word, Gtk::PACK_EXPAND_WIDGET); 98 96 m_box_options.pack_start(m_check_case, Gtk::PACK_EXPAND_WIDGET); 99 m_box_options.pack_start(m_check_regex, Gtk::PACK_EXPAND_WIDGET);100 97 101 98 m_frame_direction.add(m_box_direction); … … 109 106 m_box_btns.pack_start(m_btn_replace_all, Gtk::PACK_EXPAND_PADDING); 110 107 m_box_btns.pack_start(m_btn_close, Gtk::PACK_EXPAND_PADDING); 111 112 m_entry_find.signal_changed().connect(113 sigc::mem_fun(*this, &FindDialog::update_regex));114 m_check_case.signal_toggled().connect(115 sigc::mem_fun(*this, &FindDialog::update_regex));116 m_check_regex.signal_toggled().connect(117 sigc::mem_fun(*this, &FindDialog::update_regex));118 108 119 109 m_entry_find.signal_activate().connect( … … 142 132 show_all_children(); 143 133 144 m_check_regex.hide();145 134 set_search_only(true); 146 135 } … … 167 156 void Gobby::FindDialog::on_find() 168 157 { 169 if(m_check_regex.get_active() && m_regex_changed)170 compile_regex();171 172 158 DocWindow* doc = get_document(); 173 159 if(doc == NULL) return; … … 179 165 if(!result) 180 166 { 181 obby::format_string str( 182 _("\"%0%\" has not been found in the document.") 183 ); 184 185 str << m_entry_find.get_text(); 167 Glib::ustring str = Glib::ustring::compose( 168 "\"%1\" has not been found in the document", 169 m_entry_find.get_text()); 186 170 187 171 Gtk::MessageDialog dlg( 188 172 *this, 189 str .str(),173 str, 190 174 false, 191 175 Gtk::MESSAGE_INFO, … … 200 184 void Gobby::FindDialog::on_replace() 201 185 { 202 if(m_check_regex.get_active() && m_regex_changed)203 compile_regex();204 205 186 DocWindow* doc = get_document(); 206 187 if(doc == NULL) return; … … 239 220 void Gobby::FindDialog::on_replace_all() 240 221 { 241 if(m_check_regex.get_active() && m_regex_changed)242 compile_regex();243 244 222 DocWindow* doc = get_document(); 245 223 if(doc == NULL) return; … … 267 245 else 268 246 { 269 obby::format_string str( 270 ngettext( 271 "%0% occurence has been replaced", 272 "%0% occurences have been replaced", 273 replace_count 274 ) 275 ); 276 277 str << replace_count; 278 msg = str.str(); 247 msg = Glib::ustring::compose( 248 ngettext("%1 occurence has been replaced", 249 "%1 occurences have been replaced", 250 replace_count), replace_count); 279 251 } 280 252 … … 293 265 Gobby::DocWindow* Gobby::FindDialog::get_document() 294 266 { 295 DocWindow* doc = m_gobby.get_ current_document();267 DocWindow* doc = m_gobby.get_folder().get_current_document(); 296 268 297 269 if(doc == NULL) … … 391 363 Gtk::TextIter& match_end) 392 364 { 393 if(m_check_regex.get_active() ) 394 { 395 Glib::RefPtr<Gtk::TextBuffer> buf = from.get_buffer(); 396 397 Gtk::TextIter start_pos, limit; 398 if(m_radio_up.get_active() ) 399 { 400 limit = from; 401 402 if(to == NULL) 403 start_pos = buf->begin(); 404 else 405 start_pos = *to; 406 } 407 else if(m_radio_down.get_active() ) 408 { 409 start_pos = from; 410 411 if(to == NULL) 412 limit = buf->end(); 413 else 414 limit = *to; 415 } 416 417 Gtk::TextIter begin = buf->end(), end = buf->end(); 418 Gtk::TextIter cur_line = start_pos, next_line = start_pos; 419 for(;;) 420 { 421 next_line.forward_line(); 422 423 // Get current line of text 424 Glib::ustring line = cur_line.get_slice(next_line); 425 426 // Trim trailing text after limit 427 if(limit.get_line() == cur_line.get_line() ) 428 { 429 if(!limit.ends_line() ) 430 { 431 line.erase( 432 limit.get_line_offset() - 433 cur_line.get_line_offset() 434 ); 435 } 436 } 437 438 regex::match_options options = 439 regex::match_options::NONE; 440 441 if(!cur_line.starts_line() ) 442 options |= regex::match_options::NOT_BOL; 443 444 if(cur_line.get_line() == limit.get_line() && 445 !limit.ends_line() ) 446 options |= regex::match_options::NOT_EOL; 447 448 std::pair<std::size_t, std::size_t> pos; 449 bool result = m_regex.find( 450 line.c_str(), 451 pos, 452 options 453 ); 454 455 if(result == true) 456 { 457 begin = end = cur_line; 458 begin.set_line_index( 459 begin.get_line_index() + pos.first 460 ); 461 462 end.set_line_index( 463 end.get_line_index() + pos.second 464 ); 465 466 // Match after limit 467 if(end > limit) break; 468 469 // First match is result if searching forward 470 if(m_radio_down.get_active() ) 471 { 472 match_start = begin; 473 match_end = end; 474 475 return true; 476 } 477 } 478 479 cur_line = next_line; 480 if(cur_line > limit || cur_line == buf->end() ) 481 break; 482 } 483 484 if(m_radio_up.get_active() ) 485 { 486 // No match for backward search 487 if(begin == buf->end() && end == buf->end() ) 488 return false; 489 490 match_start = begin; 491 match_end = end; 492 493 return true; 494 } 495 496 // No match for forward search 497 return false; 498 } 499 else 500 { 501 GtkSourceSearchFlags flags = GtkSourceSearchFlags(0); 502 if(!m_check_case.get_active() ) 503 flags = GTK_SOURCE_SEARCH_CASE_INSENSITIVE; 504 505 gtk_source_iter_search_func search_func = 506 gtk_source_iter_forward_search; 507 508 if(m_radio_up.get_active() ) 509 search_func = gtk_source_iter_backward_search; 510 511 Glib::ustring find_str = m_entry_find.get_text(); 512 GtkTextIter match_start_gtk, match_end_gtk; 513 gboolean result = search_func( 514 from.gobj(), 515 find_str.c_str(), 516 flags, 517 &match_start_gtk, 518 &match_end_gtk, 519 to != NULL ? to->gobj() : NULL 520 ); 521 522 if(result == TRUE) 523 { 524 match_start = Gtk::TextIter(&match_start_gtk); 525 match_end = Gtk::TextIter(&match_end_gtk); 526 527 return true; 528 } 529 530 return false; 531 } 532 } 533 534 void Gobby::FindDialog::update_regex() 535 { 536 if (m_check_regex.get_active()) 537 m_regex_changed = true; 538 else 539 m_regex_changed = false; 540 } 541 542 void Gobby::FindDialog::compile_regex() 543 { 544 if (m_check_case.get_active()) 545 { 546 m_regex.reset( 547 m_entry_find.get_text().c_str(), 548 regex::compile_options::EXTENDED 549 ); 550 } 551 else 552 { 553 m_regex.reset( 554 m_entry_find.get_text().c_str(), 555 regex::compile_options::EXTENDED | 556 regex::compile_options::IGNORE_CASE 557 ); 558 } 559 560 m_regex_changed = false; 561 } 562 365 GtkSourceSearchFlags flags = GtkSourceSearchFlags(0); 366 if(!m_check_case.get_active() ) 367 flags = GTK_SOURCE_SEARCH_CASE_INSENSITIVE; 368 369 gtk_source_iter_search_func search_func = 370 gtk_source_iter_forward_search; 371 372 if(m_radio_up.get_active() ) 373 search_func = gtk_source_iter_backward_search; 374 375 Glib::ustring find_str = m_entry_find.get_text(); 376 GtkTextIter match_start_gtk, match_end_gtk; 377 gboolean result = search_func( 378 from.gobj(), 379 find_str.c_str(), 380 flags, 381 &match_start_gtk, 382 &match_end_gtk, 383 to != NULL ? to->gobj() : NULL 384 ); 385 386 if(result == TRUE) 387 { 388 match_start = Gtk::TextIter(&match_start_gtk); 389 match_end = Gtk::TextIter(&match_end_gtk); 390 391 return true; 392 } 393 394 return false; 395 } -
src/folder.cpp
r6eef44e r36fa5fe 17 17 */ 18 18 19 #include <stdexcept>20 #include <gdk/gdkkeysyms.h> 19 #include "folder.hpp" 20 21 21 #include <gtkmm/box.h> 22 22 #include <gtkmm/button.h> 23 23 #include <gtkmm/stock.h> 24 25 #include "document.hpp" 26 #include "folder.hpp" 24 #include <gdk/gdkkeysyms.h> 25 #include <stdexcept> 27 26 28 27 namespace 29 28 { 30 class KeyMap : private net6::non_copyable29 class KeyMap 31 30 { 32 31 public: -
src/gotodialog.cpp
r6eef44e r36fa5fe 17 17 */ 18 18 19 #include <gtkmm/stock.h>20 #include <gtkmm/messagedialog.h>21 22 #include "common.hpp"23 #include "document.hpp"24 19 #include "gotodialog.hpp" 25 20 #include "window.hpp" 21 #include "i18n.hpp" 22 23 #include <gtkmm/messagedialog.h> 24 #include <gtkmm/textbuffer.h> 25 #include <gtkmm/stock.h> 26 26 27 27 Gobby::GotoDialog::GotoDialog(Gobby::Window& parent): … … 41 41 m_btn_goto.set_image(*goto_img); 42 42 43 // TODO: Change this value according to line count in current document ?43 // TODO: Change this value according to line count in current document! 44 44 m_ent_line.set_range(1, 0x7fffffff); 45 45 m_ent_line.set_increments(1, 10); … … 84 84 m_ent_line.grab_focus(); 85 85 86 Gobby::DocWindow* window = m_window.get_current_document(); 86 Gobby::DocWindow* window = 87 m_window.get_folder().get_current_document(); 87 88 if(window != NULL) 88 89 { 89 Glib::RefPtr<Gtk::TextBuffer> buffer = 90 Glib::wrap(GTK_TEXT_BUFFER(window->get_text_buffer()), true); 90 Glib::RefPtr<Gtk::TextBuffer> buffer = 91 Glib::wrap(GTK_TEXT_BUFFER(window->get_text_buffer()), 92 true); 91 93 Gtk::TextIter cursor = buffer->get_insert()->get_iter(); 92 94 … … 100 102 void Gobby::GotoDialog::on_goto() 101 103 { 102 Gobby::DocWindow* window = m_window.get_current_document(); 104 Gobby::DocWindow* window = 105 m_window.get_folder().get_current_document(); 103 106 if(window != NULL) 104 107 { 105 108 int value = m_ent_line.get_value_as_int(); 106 Glib::RefPtr<Gtk::TextBuffer> buffer = 107 Glib::wrap(GTK_TEXT_BUFFER(window->get_text_buffer()), true); 109 Glib::RefPtr<Gtk::TextBuffer> buffer = 110 Glib::wrap(GTK_TEXT_BUFFER(window->get_text_buffer()), 111 true); 108 112 Gtk::TextIter begin = buffer->get_iter_at_line(value - 1); 109 113 window->set_selection(begin, begin); -
src/header.cpp
r00f0fd0 r36fa5fe 17 17 */ 18 18 19 #include <gtkmm/stock.h>20 #include <obby/format_string.hpp>21 22 #include "common.hpp"23 19 #include "header.hpp" 24 20 #include "icon.hpp" 25 26 #include <iostream> 21 #include "i18n.hpp" 22 23 #include <gtkmm/stock.h> 24 27 25 namespace { 28 26 Glib::ustring ui_desc = -
src/i18n.cpp
rc603f7c r36fa5fe 17 17 */ 18 18 19 #include "common.hpp" 19 #include "i18n.hpp" 20 #include "features.hpp" 20 21 21 namespace 22 { 23 net6::gettext_package* local_package; 24 } 25 26 void Gobby::init_gettext(net6::gettext_package& package) 27 { 28 local_package = &package; 29 } 22 #include <libintl.h> 30 23 31 24 const char* Gobby::_(const char* msgid) 32 25 { 33 return local_package->gettext(msgid);26 return dgettext(GETTEXT_PACKAGE, msgid); 34 27 } 35 28 … … 38 31 unsigned long int n) 39 32 { 40 return local_package->ngettext(msgid, msgid_plural, n);33 return dngettext(GETTEXT_PACKAGE, msgid, msgid_plural, n); 41 34 } -
src/icon.cpp
r7dac53b r36fa5fe 1 /* IconZZzzzzzzzzz */ 1 /* gobby - A GTKmm driven libobby client 2 * Copyright (C) 2005, 2006 0x539 dev group 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public 15 * License along with this program; if not, write to the Free 16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 */ 2 18 3 19 #include <glib/gtypes.h> 4 20 #include <gtkmm/stockitem.h> 5 #include " common.hpp"21 #include "i18n.hpp" 6 22 #include "icon.hpp" 7 23 … … 75 91 m_icon_factory->add_default(); 76 92 } 77 -
src/initialdialog.cpp
r1f3ebdc r36fa5fe 17 17 */ 18 18 19 #include "initialdialog.hpp" 20 #include "colorutil.hpp" 21 #include "i18n.hpp" 22 #include "features.hpp" 23 19 24 #include <gtkmm/stock.h> 20 25 #include <gtkmm/alignment.h> 21 #include "features.hpp"22 #include "common.hpp"23 #include "colorutil.hpp"24 #include "initialdialog.hpp"25 26 26 27 namespace -
src/main.cpp
r2270de3 r36fa5fe 17 17 */ 18 18 19 #include <iostream> 19 #include "window.hpp" 20 #include "config.hpp" 21 #include "icon.hpp" 22 #include "features.hpp" 23 20 24 #include <gtkmm/main.h> 21 25 #include <gtkmm/messagedialog.h> … … 23 27 #include <glibmm/optiongroup.h> 24 28 #include <glibmm/optioncontext.h> 25 #include "common.hpp"26 #include "ipc.hpp"27 #include "icon.hpp"28 #include "config.hpp"29 #include "encoding_selector.hpp"30 #include "window.hpp"31 #include "features.hpp"32 29 33 #ifdef WITH_GNOME 34 # include <libgnomevfs/gnome-vfs-init.h> 35 #endif 30 #include <iostream> 36 31 37 void handle_exception(const Glib::ustring& message) 32 namespace 38 33 { 39 Gtk::MessageDialog dlg("Unhandled exception: " + message, false, 40 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); 41 dlg.run(); 42 std::cerr << "Unhandled exception: " << message << std::endl; 43 } 34 void handle_exception(const Glib::ustring& message) 35 { 36 Gtk::MessageDialog dlg("Unhandled exception", false, 37 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); 38 dlg.set_secondary_text(message); 39 dlg.run(); 44 40 45 std::auto_ptr<Gobby::Ipc::RemoteConnection> 46 open_files(Gobby::Window& wnd, 47 const std::vector<std::string>& files, 48 bool disable_ipc, 49 bool do_join) 50 { 51 std::auto_ptr<Gobby::Ipc::RemoteConnection> conn; 52 53 // Neither do NPC when we want to join a session 54 if(!disable_ipc && !do_join) 55 { 56 try 57 { 58 // Try to connect to other gobby instance 59 Gobby::Ipc::RemoteInstance instance; 60 61 conn.reset( 62 new Gobby::Ipc::RemoteConnection(instance) 63 ); 64 } 65 catch(Gobby::Ipc::Error& e) 66 { 67 if(e.code() != Gobby::Ipc::Error::NO_REMOTE_INSTANCE) 68 throw e; 69 } 41 std::cerr << "Unhandled exception: " << message << std::endl; 70 42 } 71 72 if(conn.get() != NULL)73 {74 // Found one, send files. Finish from mainloop as soon as75 // all the files have been sent.76 conn->done_event().connect(sigc::ptr_fun(&Gtk::Main::quit));77 78 for(std::vector<std::string>::const_iterator iter =79 files.begin();80 iter != files.end();81 ++ iter)82 {83 conn->send_file(iter->c_str() );84 }85 }86 else87 {88 // No other gobby found, so open the files locally89 wnd.show();90 91 bool result = do_join ?92 wnd.session_join(false) :93 wnd.session_open(false);94 95 // First, open a session with default settings96 if(result)97 {98 // And pass files99 for(std::vector<std::string>::const_iterator iter =100 files.begin();101 iter != files.end();102 ++ iter)103 {104 wnd.open_local_file(105 *iter,106 Gobby::EncodingSelector::AUTO_DETECT107 );108 }109 }110 }111 112 return conn;113 43 } 114 44 … … 116 46 { 117 47 g_thread_init(NULL); 118 // if(!Glib::thread_supported()) 119 // Glib::thread_init(); 48 gnutls_global_init(); 120 49 121 50 setlocale(LC_ALL, ""); 122 net6::gettext_package gobby_package(GETTEXT_PACKAGE, LOCALE_DIR);123 Gobby::init_gettext(gobby_package);51 bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); 52 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); 124 53 125 54 bool new_instance = false; 126 55 Glib::ustring join; 127 56 128 Glib::OptionGroup opt_group_gobby("gobby", "Gobby options", "Options related directly to gobby"); 129 Glib::OptionEntry opt_new_instance; 130 opt_new_instance.set_short_name('n'); 131 opt_new_instance.set_long_name("new-instance"); 132 opt_new_instance.set_description( 133 "Do not try to contact already running gobby instance" 134 ); 135 136 Glib::OptionEntry opt_join; 137 opt_join.set_short_name('j'); 138 opt_join.set_long_name("join"); 139 opt_join.set_arg_description("HOST:PORT"); 140 opt_join.set_description("Join a session on the given host"); 141 142 opt_group_gobby.add_entry(opt_new_instance, new_instance); 143 opt_group_gobby.add_entry(opt_join, join); 144 145 Glib::OptionContext opt_ctx("[file1] [file2] [...]"); 57 Glib::OptionContext opt_ctx; 146 58 opt_ctx.set_help_enabled(true); 147 59 opt_ctx.set_ignore_unknown_options(false); 148 149 opt_ctx.set_main_group(opt_group_gobby);150 60 151 61 // I would rather like to have Gtk::Main on the stack, but I see … … 164 74 } 165 75 166 net6::main netkit; 167 168 #ifdef WITH_GNOME 169 gnome_vfs_init(); 170 #endif 171 172 // Get files to open 173 std::vector<std::string> files(argc - 1); 174 for(int i = 1; i < argc; ++ i) 175 { 176 // Make absolute filenames to understand the files 177 // from everywhere when we send them to another process 178 if(!Glib::path_is_absolute(argv[i])) 179 { 180 files[i - 1] = Glib::build_filename( 181 Glib::get_current_dir(), 182 argv[i] 183 ); 184 } 185 else 186 { 187 files[i - 1] = argv[i]; 188 } 189 } 190 191 Gobby::IconManager icon_mgr; 76 Gobby::IconManager icon_manager; 192 77 193 78 // Set default icon 194 79 std::list<Glib::RefPtr<Gdk::Pixbuf> > icon_list; 195 icon_list.push_back(icon_m gr.gobby);80 icon_list.push_back(icon_manager.gobby); 196 81 Gtk::Window::set_default_icon_list(icon_list); 197 82 … … 199 84 Gobby::Config config(Glib::get_home_dir() + "/.gobby/config.xml"); 200 85 201 // Set join parameters if we want to join a session202 if(!join.empty())203 {204 Glib::ustring::size_type pos = join.rfind(':');205 if(pos == std::string::npos) pos = join.length();206 207 Gobby::Config::ParentEntry& entry =208 config.get_root()["session"];209 210 entry.set_value("join_host", join.substr(0, pos));211 if(pos < join.length())212 {213 entry.set_value(214 "join_port",215 std::strtoul(216 join.substr(pos + 1).c_str(),217 NULL,218 10219 )220 );221 }222 }223 224 86 // Create window 225 Gobby::Window wnd(icon_mgr, config); 226 227 // Open files passed by command line. Need to keep rem_conn, 228 // otherwise the connection would be dropped through 229 // Gobby::Ipc::RemoteConnection's destructor. 230 std::auto_ptr<Gobby::Ipc::RemoteConnection> rem_conn; 231 if(!files.empty() ) 232 rem_conn = open_files(wnd, files, new_instance, !join.empty()); 233 else 234 { 235 wnd.show(); 236 237 if(!join.empty()) 238 wnd.session_join(false); 239 } 87 Gobby::Window wnd(icon_manager, config); 88 wnd.show(); 240 89 241 90 // Cannot use just kit.run(wnd) since this would show wnd. If we … … 243 92 // the window to be shown. 244 93 wnd.signal_hide().connect(sigc::ptr_fun(&Gtk::Main::quit) ); 245 246 94 kit->run(); 247 95 248 #ifdef WITH_GNOME 249 //gnome_vfs_shutdown(); // Prints error messages. 250 // I don't know where they come from... 251 #endif 252 96 //gnutls_global_deinit(); 253 97 return 0; 254 98 } -
src/preferencesdialog.cpp
r00f0fd0 r36fa5fe 17 17 */ 18 18 19 #include "preferencesdialog.hpp" 20 #include "colorutil.hpp" 21 #include "i18n.hpp" 22 23 #include <gtkmm/messagedialog.h> 24 #include <gtkmm/stock.h> 19 25 #include <stdexcept> 20 #include <gtkmm/stock.h>21 #include <gtkmm/messagedialog.h>22 23 #include <obby/format_string.hpp>24 25 #include "common.hpp"26 #include "colorutil.hpp"27 #include "preferencesdialog.hpp"28 26 29 27 namespace -
src/resolv.cpp
r6eef44e r36fa5fe 18 18 19 19 #include "resolv.hpp" 20 #include "common.hpp"21 20 22 21 #include <glibmm/main.h> -
src/statusbar.cpp
r6eef44e r36fa5fe 19 19 #include "statusbar.hpp" 20 20 21 #include <gtkmm/frame.h> 21 22 #include <gtkmm/stock.h> 22 23 -
src/window.cpp
r6eef44e r36fa5fe 17 17 */ 18 18 19 #include <stdexcept> 20 #include <fstream> 21 #include <ostream> 22 23 #include <glibmm/miscutils.h> 24 #include <gtkmm/main.h> 25 #include <gtkmm/aboutdialog.h> 26 #include <gtkmm/messagedialog.h> 27 #include <gtkmm/filechooserdialog.h> 28 #include <gtkmm/stock.h> 29 30 #include <obby/format_string.hpp> 31 #include <obby/client_buffer.hpp> 32 #include <obby/host_buffer.hpp> 33 34 #include "common.hpp" 35 #include "encoding.hpp" 36 #include "encoding_selector.hpp" 19 #include "window.hpp" 37 20 #include "docwindow.hpp" 38 #include "passworddialog.hpp" 39 #include "entrydialog.hpp" 40 #include "preferencesdialog.hpp" 41 #include "joinprogressdialog.hpp" 42 #include "hostprogressdialog.hpp" 43 #include "window.hpp" 21 #include "icon.hpp" 44 22 #include "features.hpp" 45 #include "icon.hpp"46 #include "colorsel.hpp"47 23 48 24 #include <libinftextgtk/inf-text-gtk-buffer.h> … … 78 54 Gobby::Window::Window(const IconManager& icon_mgr, Config& config): 79 55 Gtk::Window(Gtk::WINDOW_TOPLEVEL), m_config(config), 80 m_lang_manager(gtk_source_language_manager_ new()),56 m_lang_manager(gtk_source_language_manager_get_default()), 81 57 m_preferences(m_config), m_icon_mgr(icon_mgr), 82 m_application_state(APPLICATION_NONE),83 m_document_settings(*this),84 58 m_header(m_preferences, m_lang_manager), 85 59 m_folder(m_preferences, m_lang_manager), 86 60 m_statusbar(m_folder), 87 61 m_browser(*this, &TEXT_PLUGIN, m_statusbar, m_preferences) 88 #ifdef WITH_AVAHI89 ,m_glib_poll(avahi_glib_poll_new(NULL, G_PRIORITY_DEFAULT))90 #endif91 62 { 92 #if 093 // Header94 m_header.action_app_session_create->signal_activate().connect(95 sigc::mem_fun(*this, &Window::on_session_create) );96 m_header.action_app_session_join->signal_activate().connect(97 sigc::mem_fun(*this, &Window::on_session_join) );98 m_header.action_app_session_save->signal_activate().connect(99 sigc::mem_fun(*this, &Window::on_session_save) );100 m_header.action_app_session_quit->signal_activate().connect(101 sigc::mem_fun(*this, &Window::on_session_quit) );102 m_header.action_app_quit->signal_activate().connect(103 sigc::mem_fun(*this, &Window::on_quit) );104 105 m_header.action_session_document_create->signal_activate().connect(106 sigc::mem_fun(*this, &Window::on_document_create) );107 m_header.action_session_document_open->signal_activate().connect(108 sigc::mem_fun(*this, &Window::on_document_open) );109 m_header.action_session_document_save->signal_activate().connect(110 sigc::mem_fun(*this, &Window::on_document_save) );111 m_header.action_session_document_save_as->signal_activate().connect(112 sigc::mem_fun(*this, &Window::on_document_save_as) );113 m_header.action_session_document_close->signal_activate().connect(114 sigc::mem_fun(*this, &Window::on_document_close) );115 116 m_header.action_edit_search->signal_activate().connect(117 sigc::mem_fun(*this, &Window::on_edit_search) );118 m_header.action_edit_search_replace->signal_activate().connect(119 sigc::mem_fun(*this, &Window::on_edit_search_replace) );120 m_header.action_edit_goto_line->signal_activate().connect(121 sigc::mem_fun(*this, &Window::on_edit_goto_line) );122 m_header.action_edit_preferences->signal_activate().connect(123 sigc::mem_fun(*this, &Window::on_edit_preferences) );124 125 m_header.action_user_set_colour->signal_activate().connect(126 sigc::mem_fun(*this, &Window::on_user_set_colour) );127 m_header.action_user_set_password->signal_activate().connect(128 sigc::mem_fun(*this, &Window::on_user_set_password) );129 130 m_header.action_edit_document_preferences->signal_activate().connect(131 sigc::mem_fun(*this, &Window::on_view_preferences) );132 133 m_header.action_window_chat->signal_activate().connect(134 sigc::mem_fun(*this, &Window::on_window_chat) );135 136 m_header.action_help_about->signal_activate().connect(137 sigc::mem_fun(*this, &Window::on_about) );138 #endif139 63 m_browser.show(); 140 141 #if 0142 // Folder143 m_folder.document_add_event().connect(144 sigc::mem_fun(*this, &Window::on_folder_document_add) );145 m_folder.document_remove_event().connect(146 sigc::mem_fun(*this, &Window::on_folder_document_remove) );147 m_folder.document_close_request_event().connect(148 sigc::mem_fun(*this, &Window::on_folder_document_close_request) );149 m_folder.tab_switched_event().connect(150 sigc::mem_fun(*this, &Window::on_folder_tab_switched) );151 #endif152 // Settings153 m_document_settings.document_insert_event().connect(154 sigc::mem_fun(*this, &Window::on_settings_document_insert) );155 64 156 65 // Build UI … … 172 81 add(m_mainbox); 173 82 174 // Apply initial preferences175 apply_preferences();176 177 Config::ParentEntry& windows = config.get_root()["windows"];178 m_application_state.modify(APPLICATION_INITIAL, APPLICATION_NONE);179 180 83 show_all_children(); 181 84 182 85 set_title("Gobby"); 183 86 set_default_size(640, 480); 184 185 #ifdef WITH_ZEROCONF186 // Initialise Zeroconf187 try188 {189 #ifdef WITH_AVAHI190 m_zeroconf.reset(new obby::zeroconf_avahi(avahi_glib_poll_get(m_glib_poll)));191 #else192 m_zeroconf.reset(new obby::zeroconf);193 // Periodically check for events when not using Avahi Glib Poll194 Glib::signal_timeout().connect(sigc::bind(sigc::mem_fun(*m_zeroconf.get(), &zeroconf_base::select), 0), 1500);195 #endif196 }197 catch(std::runtime_error&)198 {199 std::cerr << _("Zeroconf initialisation failed. Probably you "200 "need to run avahi-daemon or mDNSResponder, depending "201 "on the library you use, as root prior to Gobby. "202 "Zeroconf support is deactivated for this session.");203 std::cerr << std::endl;204 m_zeroconf.reset();205 }206 #endif207 87 } 208 88 209 89 Gobby::Window::~Window() 210 90 { 211 if(m_buffer.get() && m_buffer->is_open() )212 obby_end();213 214 91 // Serialise preferences into config 215 92 m_preferences.serialise(m_config); 216 217 /* Free explictely to make sure that the avahi poll is no longer218 * referenced when we free it */219 #ifdef WITH_ZEROCONF220 m_zeroconf.reset(NULL);221 #endif222 223 #ifdef WITH_AVAHI224 avahi_glib_poll_free(m_glib_poll);225 #endif226 93 } 227 94 228 95 bool Gobby::Window::on_delete_event(GdkEventAny* event) 229 96 { 97 #if 0 230 98 if(m_buffer.get() == NULL) return false; 231 99 if(!m_buffer->is_open() ) return false; … … 253 121 254 122 return dlg.run() != Gtk::RESPONSE_YES; 123 #endif 124 return false; 255 125 } 256 126 … … 260 130 261 131 m_paned.set_position(m_paned.get_width() * 2 / 5); 262 263 // Create new IPC instance264 try265 {266 m_ipc.reset(new Ipc::LocalInstance);267 m_ipc->file_event().connect(268 sigc::mem_fun(*this, &Window::on_ipc_file)269 );270 }271 catch(net6::error& e)272 {273 // Whatever...274 display_error(e.what() );275 }276 132 } 277 133 … … 297 153 m_config.get_root()["initial"].set_value("run", true); 298 154 } 299 300 void Gobby::Window::obby_start()301 {302 // Connect to obby events303 m_buffer->user_join_event().connect(304 sigc::mem_fun(*this, &Window::on_obby_user_join) );305 m_buffer->user_part_event().connect(306 sigc::mem_fun(*this, &Window::on_obby_user_part) );307 m_buffer->user_colour_event().connect(308 sigc::mem_fun(*this, &Window::on_obby_user_colour) );309 m_buffer->user_colour_failed_event().connect(310 sigc::mem_fun(*this, &Window::on_obby_user_colour_failed) );311 312 m_buffer->document_insert_event().connect(313 sigc::mem_fun(*this, &Window::on_obby_document_insert) );314 m_buffer->document_remove_event().connect(315 sigc::mem_fun(*this, &Window::on_obby_document_remove) );316 317 // Accept drag and drop of files into the gobby window318 m_dnd.reset(new DragDrop(*this) );319 320 // Delegate start of obby session321 m_document_settings.obby_start(*m_buffer);322 323 // Forward user joins324 const obby::user_table& table = m_buffer->get_user_table();325 for(obby::user_table::iterator iter =326 table.begin(obby::user::flags::NONE, obby::user::flags::NONE);327 iter != table.end(obby::user::flags::NONE, obby::user::flags::NONE);328 ++ iter)329 {330 on_obby_user_join(*iter);331 }332 333 // Send documents to components334 Buffer::document_iterator iter = m_buffer->document_begin();335 for(; iter != m_buffer->document_end(); ++ iter)336 on_obby_document_insert(*iter);337 338 // Set last page as active one because it is currently shown anyway.339 //if(m_buffer->document_count() > 0)340 // m_folder.set_current_page(m_buffer->document_count() - 1);341 342 // Clear location of previous session file, this is a new session343 m_prev_session = "";344 345 // Current document has changed, update titlebar346 update_title_bar();347 348 // Show up document list if obby buffer contains documents349 if(m_buffer->document_count() > 0)350 {351 }352 353 ApplicationFlags inc_flags = APPLICATION_SESSION;354 ApplicationFlags exc_flags = APPLICATION_INITIAL | APPLICATION_DOCUMENT;355 356 if(dynamic_cast<ClientBuffer*>(m_buffer.get()) != NULL)357 exc_flags |= APPLICATION_HOST;358 else359 inc_flags |= APPLICATION_HOST;360 361 m_application_state.modify(inc_flags, exc_flags);362 }363 364 void Gobby::Window::obby_end()365 {366 // Nothing to do if no buffer is open367 if(m_buffer.get() == NULL)368 {369 throw std::logic_error(370 "Gobby::Window::obby_end:\n"371 "Buffer not available"372 );373 }374 375 m_application_state.modify(APPLICATION_NONE, APPLICATION_SESSION);376 377 if(m_buffer->is_open() )378 {379 // TODO: Virtual close call in obby?380 ClientBuffer* client_buf =381 dynamic_cast<ClientBuffer*>(m_buffer.get());382 HostBuffer* host_buf =383 dynamic_cast<HostBuffer*>(m_buffer.get());384 385 if(client_buf != NULL) client_buf->disconnect();386 if(host_buf != NULL) host_buf->close();387 }388 389 // Remove DND handler390 m_dnd.reset(NULL);391 392 // Tell GUI components that the session ended393 m_document_settings.obby_end();394 395 #ifdef WITH_ZEROCONF396 if(m_zeroconf.get() )397 m_zeroconf->unpublish_all();398 #endif399 }400 401 void Gobby::Window::on_session_create()402 {403 session_open(true);404 }405 406 void Gobby::Window::on_session_join()407 {408 session_join(true);409 }410 411 void Gobby::Window::on_session_save()412 {413 Gtk::CheckButton m_chk_default_ext(414 _("Use default .obby extension if none is given")415 );416 417 Gtk::FileChooserDialog dlg(418 *this,419 _("Save obby session"),420 Gtk::FILE_CHOOSER_ACTION_SAVE421 );422 423 m_chk_default_ext.set_active(true);424 dlg.get_vbox()->pack_start(m_chk_default_ext, Gtk::PACK_SHRINK);425 // This option confuses the overwrite confirmation :/426 //m_chk_default_ext.show();427 428 #ifdef GTKMM_GEQ_28429 dlg.set_do_overwrite_confirmation(true);430 #endif431 432 // Use the location of a previously saved session, if any433 if(!m_prev_session.empty() )434 {435 dlg.set_filename(m_prev_session);436 }437 else438 {439 // Use the last used path for this dialog, if we have any440 if(!m_last_path.empty() )441 dlg.set_current_folder(m_last_path);442 }443 444 dlg.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);445 dlg.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);446 447 if(dlg.run() == Gtk::RESPONSE_OK)448 {449 // Use current folder as standard folder for other dialogs450 m_last_path = dlg.get_current_folder();451 // Get selected filename452 std::string filename = dlg.get_filename();453 454 // Append .obby extension if none is given455 /*if(m_chk_default_ext.get_active() )456 if(filename.find('.') == std::string::npos)457 filename += ".obby";*/458 459 // Save document460 try461 {462 m_buffer->serialise(filename);463 m_prev_session = filename;464 }465 catch(std::exception& e)466 {467 display_error(e.what() );468 }469 }470 }471 472 void Gobby::Window::on_session_quit()473 {474 obby_end();475 }476 477 void Gobby::Window::on_about()478 {479 Gtk::AboutDialog dlg;480 dlg.set_name("Gobby");481 dlg.set_version(PACKAGE_VERSION);482 dlg.set_comments(_("A collaborative text editor"));483 484 dlg.set_copyright(485 "Copyright (C) 2005-2007 0x539 dev group <crew@0x539.de>"486 );487 488 dlg.set_logo(m_icon_mgr.gobby);489 490 std::deque<Glib::ustring> authors;491 authors.push_back("Developers:");492 authors.push_back(" Armin Burgmeier <armin@0x539.de>");493 authors.push_back(" Philipp Kern <phil@0x539.de>");494 authors.push_back("");495 authors.push_back("Contributors:");496 authors.push_back(" Benjamin Herr <ben@0x539.de>");497 498 std::deque<Glib::ustring> artists;499 artists.push_back("Logo:");500 artists.push_back(" Thomas Glatt <tom@0x539.de>");501 artists.push_back("");502 artists.push_back("Additional artwork:");503 artists.push_back(" Thomas Glatt <tom@0x539.de>");504 artists.push_back(" Benjamin Herr <ben@0x539.de>");505 506 dlg.set_authors(authors);507 dlg.set_artists(artists);508 509 dlg.set_translator_credits(510 "French translation:\n"511 " Peer Janssen <peer@baden-online.de>\n"512 " Mohammed Adnene Trojette <adn@diwi.org>\n"513 "\n"514 "Spanish translation:\n"515 " Mario Palomo Torrero <mpalomo@ihman.com>\n"516 "\n"517 "Swedish translation:\n"518 " Daniel Nylander <po@danielnylander.se>\n"519 "\n"520 "German translation:\n"521 " Philipp Kern <phil@0x539.de>\n"522 " Armin Burgmeier <armin@0x539.de>\n"523 " Thomas Glatt <tom@0x539.de>\n"524 );525 526 dlg.set_license(527 "This program is free software; you can redistribute it\n"528 "and/or modify it under the terms of the GNU General Public\n"529 "License as published by the Free Software Foundation; either\n"530 "version 2 of the License, or (at your option) any later\n"531 "version.\n"532 "\n"533 "This program is distributed in the hope that it will be\n"534 "useful, but WITHOUT ANY WARRANTY; without even the implied\n"535 "warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\n"536 "PURPOSE. See the GNU General Public License for more details."537 );538 dlg.run();539 }540 541 #if 0542 void Gobby::Window::on_folder_document_add(DocWindow& window)543 {544 // Select newly created page if not automatically opened545 if(!m_document_settings.get_automatically_opened(window.get_info() ))546 {547 m_folder.set_current_page(m_folder.page_num(window) );548 window.grab_focus();549 }550 551 // Unset modifified flag when locally opened552 if(!m_local_file_path.empty())553 {554 gtk_text_buffer_set_modified(555 GTK_TEXT_BUFFER(window.get_document().get_buffer()), FALSE);556 }557 558 if(m_folder.get_n_pages() == 1)559 {560 // There have not been any documents before561 m_application_state.modify(562 APPLICATION_DOCUMENT,563 APPLICATION_NONE564 );565 566 m_folder.set_show_tabs(false);567 }568 else569 {570 m_folder.set_show_tabs(true);571 }572 }573 574 void Gobby::Window::on_folder_document_remove(DocWindow& window)575 {576 // Update title bar if there are no more documents left577 // (folder_tab_switched is not emitted in this case)578 if(m_folder.get_n_pages() == 0)579 {580 update_title_bar();581 582 m_application_state.modify(583 APPLICATION_NONE,584 APPLICATION_DOCUMENT585 );586 }587 else if(m_folder.get_n_pages() == 1)588 {589 m_folder.set_show_tabs(false);590 }591 }592 593 void Gobby::Window::on_folder_document_close_request(DocWindow& window)594 {595 close_document(window);596 }597 598 void Gobby::Window::on_folder_tab_switched(DocWindow& window)599 {600 // Update title bar601 update_title_bar();602 }603 #endif604 605 void Gobby::Window::on_settings_document_insert(LocalDocumentInfo& info)606 {607 // Set the path from which this document was opened,608 // if we opened that file.609 if(info.get_owner() == &m_buffer->get_self() &&610 !m_local_file_path.empty() )611 {612 // " " is newly created, so we do not need a path613 if(m_local_file_path != " ")614 {615 m_document_settings.set_path(info, m_local_file_path);616 }617 618 m_document_settings.set_original_encoding(619 info,620 m_local_encoding621 );622 }623 else624 {625 // File was opened remotely, so we do not know anything626 // about the original encoding, so assume it's UTF-8.627 m_document_settings.set_original_encoding(info, "UTF-8");628 }629 }630 631 void Gobby::Window::on_document_create()632 {633 EntryDialog dlg(*this, _("Create document"), _("Enter document name"));634 dlg.set_check_valid_entry(true);635 636 if(dlg.run() == Gtk::RESPONSE_OK)637 {638 // " " means a newly created file639 m_local_file_path = " ";640 m_local_encoding = "UTF-8";641 // Create new document642 m_buffer->document_create(dlg.get_text(), "UTF-8", "");643 644 // Clear local path645 m_local_file_path.clear();646 m_local_encoding.clear();647 }648 }649 650 void Gobby::Window::on_document_open()651 {652 // Create FileChooser653 EncodingFileChooserDialog dlg(654 *this,655 _("Open new document"),656 Gtk::FILE_CHOOSER_ACTION_OPEN657 );658 659 dlg.get_selector().set_encoding(EncodingSelector::AUTO_DETECT);660 661 // Use the last used path for this dialog, if we have any662 if(!m_last_path.empty() )663 dlg.set_current_folder(m_last_path);664 665 // Create buttons to close it666 dlg.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);667 dlg.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);668 669 // Allow multi selection670 dlg.set_select_multiple(true);671 672 // Show FileChooser673 if(dlg.run() == Gtk::RESPONSE_OK)674 {675 // Use current folder as standard folder for later dialogs676 m_last_path = dlg.get_current_folder();677 // Open chosen files678 std::list<Glib::ustring> list = dlg.get_filenames();679 for(std::list<Glib::ustring>::iterator iter = list.begin();680 iter != list.end();681 ++ iter)682 {683 open_local_file(684 *iter,685 dlg.get_selector().get_encoding()686 );687 }688 }689 }690 691 void Gobby::Window::on_document_save()692 {693 handle_document_save();694 }695 696 bool Gobby::Window::handle_document_save()697 {698 // Get page699 DocWindow* doc = get_current_document();700 if(doc == NULL)701 {702 throw std::logic_error(703 "Gobby::Window::on_document_save:\n"704 "No document opened"705 );706 }707 #if 0708 // Is there already a path for this document?709 std::string path = m_document_settings.get_path(doc->get_info() );710 if(!path.empty() )711 {712 // Yes, so save the document there713 save_local_file(714 *doc,715 path,716 m_document_settings.get_original_encoding(717 doc->get_info()718 )719 );720 return true;721 }722 else723 {724 // Open save as dialog otherwise725 return handle_document_save_as();726 }727 #endif728 }729 730 void Gobby::Window::on_document_save_as()731 {732 handle_document_save_as();733 }734 735 bool Gobby::Window::handle_document_save_as()736 {737 // Get page738 DocWindow* doc = get_current_document();739 if(doc == NULL)740 {741 throw std::logic_error(742 "Gobby::Window::on_document_save_as:\n"743 "No document opened"744 );745 }746 747 // Setup dialog748 EncodingFileChooserDialog dlg(749 *this,750 _("Save current document"),751 Gtk::FILE_CHOOSER_ACTION_SAVE752 );753 754 #if 0755 // TODO: Preselect document's encoding756 dlg.get_selector().set_encoding(757 m_document_settings.get_original_encoding(doc->get_info())758 );759 760 #ifdef GTKMM_GEQ_28761 dlg.set_do_overwrite_confirmation(true);762 #endif763 764 std::string path = m_document_settings.get_path(doc->get_info() );765 766 // Does the document have already a path?767 if(!path.empty() )768 {769 // Yes, so set it as filename770 dlg.set_filename(path);771 }772 else773 {774 // No, so use the last path a filesel dialog was closed with775 if(!m_last_path.empty() )776 dlg.set_current_folder(m_last_path);777 778 // Set current title as proposed file name779 dlg.set_current_name(doc->get_info().get_title() );780 }781 782 // Add buttons to close the dialog783 dlg.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);784 dlg.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);785 dlg.set_default_response(Gtk::RESPONSE_OK);786 787 if(dlg.run() == Gtk::RESPONSE_OK)788 {789 // Use current folder as standard folder for other dialogs790 m_last_path = dlg.get_current_folder();791 // Save document792 save_local_file(793 *doc,794 dlg.get_filename(),795 dlg.get_selector().get_encoding()796 );797 return true;798 }799 return false;800 #endif801 }802 803 void Gobby::Window::on_document_close()804 {805 // Get current page806 Widget* page = m_folder.get_nth_page(m_folder.get_current_page() );807 // Close it808 close_document(*static_cast<DocWindow*>(page) );809 }810 811 void Gobby::Window::on_edit_search()812 {813 if(m_finddialog.get() == NULL)814 m_finddialog.reset(new FindDialog(*this));815 816 m_finddialog->set_search_only(true);817 m_finddialog->present();818 }819 820 void Gobby::Window::on_edit_search_replace()821 {822 if(m_finddialog.get() == NULL)823 m_finddialog.reset(new FindDialog(*this));824 825 m_finddialog->set_search_only(false);826 m_finddialog->present();827 }828 829 void Gobby::Window::on_edit_goto_line()830 {831 if(m_gotodialog.get() == NULL)832 m_gotodialog.reset(new GotoDialog(*this));833 834 m_gotodialog->present();835 }836 837 void Gobby::Window::on_edit_preferences()838 {839 if(m_preferences_dlg.get() == NULL)840 m_preferences_dlg.reset(841 new PreferencesDialog(*this, m_preferences));842 843 m_preferences_dlg->present();844 }845 846 void Gobby::Window::on_user_set_password()847 {848 // Build password dialog with info849 PasswordDialog dlg(*this, _("Set user password") );850 dlg.set_info(_(851 "Set a user password for your user account. When you try to "852 "login next time with this user, you will be prompted for your "853 "password."854 ) );855 856 // Run it857 if(dlg.run() == Gtk::RESPONSE_OK)858 {859 dynamic_cast<ClientBuffer*>(860 m_buffer.get() )->set_password(dlg.get_password() );861 }862 }863 864 void Gobby::Window::on_user_set_colour()865 {866 // Simple ColorSelectionDialog867 ColorSelectionDialog dlg(m_config.get_root() );868 const obby::user& user = m_buffer->get_self();869 Gdk::Color color;870 871 color.set_red(user.get_colour().get_red() * 65535 / 255);872 color.set_green(user.get_colour().get_green() * 65535 / 255);873 color.set_blue(user.get_colour().get_blue() * 65535 / 255);874 dlg.get_colorsel()->set_current_color(color);875 876 // Run it877 if(dlg.run() == Gtk::RESPONSE_OK)878 {879 // Convert GDK color to obby color, set new color880 Gdk::Color color = dlg.get_colorsel()->get_current_color();881 m_buffer->set_colour(882 obby::colour(883 color.get_red() * 255 / 65535,884 color.get_green() * 255 / 65535,885 color.get_blue() * 255 / 65535886 )887 );888 }889 }890 891 void Gobby::Window::on_view_preferences()892 {893 #if 0894 // Get current page895 DocWindow* doc = get_current_document();896 if(doc == NULL)897 {898 throw std::logic_error(899 "Gobby::Window::on_view_preferences:\n"900 "No window opened"901 );902 }903 904 // Add preferences dialog905 PreferencesDialog dlg(*this,906 doc->get_preferences(),907 m_lang_manager,908 true909 );910 911 // Label text912 obby::format_string str(_(913 "These preferences affect only the currently active document "914 "\"%0%\". If you want to change global preferences, use the "915 "preferences menu item in the \"Edit\" menu."916 ) );917 918 // Get title919 str << doc->get_info().get_suffixed_title();920 921 // Info label922 Gtk::Label lbl_info(str.str() );923 924 // TODO: How to get the label to use all available space?925 lbl_info.set_line_wrap(true);926 lbl_info.set_alignment(Gtk::ALIGN_LEFT);927 928 // Add it into the dialog929 dlg.get_vbox()->pack_start(lbl_info, Gtk::PACK_SHRINK);930 dlg.get_vbox()->reorder_child(lbl_info, 0); // Push to top of dialog931 lbl_info.show();932 933 // Show the dialog934 if(dlg.run() == Gtk::RESPONSE_OK)935 {936 // Apply new preferences to the document937 Preferences prefs;938 dlg.set(prefs);939 doc->set_preferences(prefs);940 }941 #endif942 }943 944 void945 Gobby::Window::on_view_language(GtkSourceLanguage* language)946 {947 // Set language of current document948 DocWindow* doc = get_current_document();949 if(doc == NULL)950 {951 throw std::logic_error(952 "Gobby::Window::on_view_language:\n"953 "No window opened"954 );955 }956 957 doc->set_language(language);958 }959 960 void Gobby::Window::on_window_chat()961 {962 }963 964 void Gobby::Window::on_quit()965 {966 if(on_delete_event(NULL) == false)967 {968 // Quit session969 if(m_buffer.get() != NULL && m_buffer->is_open() )970 obby_end();971 // End program972 Gtk::Main::quit();973 }974 }975 976 void Gobby::Window::on_obby_close()977 {978 display_error(_("Connection lost"));979 on_session_quit();980 }981 982 /*void Gobby::Window::on_obby_encrypted()983 {984 display_error("Connection now encrypted");985 }*/986 987 void Gobby::Window::on_obby_user_join(const obby::user& user)988 {989 // Tell user join to components990 //m_folder.obby_user_join(user);991 }992 993 void Gobby::Window::on_obby_user_part(const obby::user& user)994 {995 // Tell user part to components996 //m_folder.obby_user_part(user);997 }998 999 void Gobby::Window::on_obby_user_colour(const obby::user& user)1000 {1001 //m_folder.obby_user_colour(user);1002 }1003 1004 void Gobby::Window::on_obby_user_colour_failed()1005 {1006 display_error(_("Colour change failed: Colour already in use") );1007 }1008 1009 void Gobby::Window::on_obby_document_insert(DocumentInfo& document)1010 {1011 LocalDocumentInfo& local_doc =1012 dynamic_cast<LocalDocumentInfo&>(document);1013 1014 //m_folder.obby_document_insert(local_doc);1015 }1016 1017 void Gobby::Window::on_obby_document_remove(DocumentInfo& document)1018 {1019 LocalDocumentInfo& local_doc =1020 dynamic_cast<LocalDocumentInfo&>(document);1021 1022 //m_folder.obby_document_remove(local_doc);1023 }1024 1025 void Gobby::Window::on_ipc_file(const std::string& file)1026 {1027 // Open local file directly if buffer is open1028 if(m_buffer.get() != NULL && m_buffer->is_open() )1029 {1030 open_local_file(file, EncodingSelector::AUTO_DETECT);1031 return;1032 }1033 1034 // Otherwise, push the file back into the file queue.1035 bool was_empty = m_file_queue.empty();1036 m_file_queue.push(file);1037 1038 // If the file queue is empty, open a new session. The queue will1039 // be cleared either if the session has finished (either with success1040 // or not).1041 1042 // TODO: Find a better condition for when the session is currently1043 // being opened. Checking whether the file queue is empty is not1044 // good because the user might manually open a session while an1045 // IPC file request comes in...1046 if(was_empty)1047 {1048 session_open(false);1049 }1050 }1051 1052 Gobby::DocWindow* Gobby::Window::get_current_document()1053 {1054 if(m_folder.get_n_pages() == 0) return NULL;1055 1056 Widget* page = m_folder.get_nth_page(m_folder.get_current_page() );1057 return static_cast<DocWindow*>(page);1058 }1059 1060 void Gobby::Window::apply_preferences()1061 {1062 }1063 1064 void Gobby::Window::update_title_bar()1065 {1066 // No document1067 if(m_folder.get_n_pages() == 0)1068 {1069 set_title("Gobby");1070 return;1071 }1072 1073 // Get currently active document1074 const DocWindow& window = *get_current_document();1075 // Get title of current document1076 const Glib::ustring& file = window.get_title();1077 // Get path of current document1078 Glib::ustring path;// = m_document_settings.get_path(window.get_info() );1079 1080 // Show path in title, if we know it1081 if(!path.empty() )1082 {1083 // Replace home dir by ~1084 Glib::ustring home = Glib::get_home_dir();1085 if(path.compare(0, home.length(), home) == 0)1086 path.replace(0, home.length(), "~");1087 1088 // Set title with file and path1089 obby::format_string title_str("%0% (%1%)");1090 title_str << file << Glib::path_get_dirname(path);1091 set_title(title_str.str() );1092 }1093 else1094 {1095 // Path not known: Set title with file only1096 obby::format_string title_str("%0%");1097 title_str << file;1098 set_title(title_str.str() );1099 }1100 }1101 1102 namespace1103 {1104 // convert2unix converts a given string from any special line endings1105 // (DOS or old-style Macintosh) to Unix line endings. It does no1106 // book-keeping about the encountered endings but ensures that no1107 // CR characters are left in the string.1108 void convert2unix(std::string& str)1109 {1110 for(std::string::size_type i = 0; i < str.length(); ++ i)1111 // Convert DOS CRLF to a single LF1112 if(i < str.length() - 1 &&1113 str[i] == '\r' && str[i+1] == '\n')1114 str.erase(i, 1);1115 // Convert Macintosh CR to LF1116 else if(str[i] == '\r')1117 str[i] = '\n';1118 }1119 }1120 1121 bool Gobby::Window::session_join(bool initial_dialog)1122 {1123 if(m_buffer.get() && m_buffer->is_open() )1124 {1125 throw std::logic_error(1126 "Gobby::Window::session_join:\n"1127 "Buffer is already open"1128 );1129 }1130 1131 if(m_join_dlg.get() == NULL)1132 {1133 #ifndef WITH_ZEROCONF1134 m_join_dlg.reset(1135 new JoinDialog(*this, m_config.get_root()["session"])1136 );1137 #else1138 m_join_dlg.reset(1139 new JoinDialog(1140 *this,1141 m_config.get_root()["session"],1142 m_zeroconf.get()1143 )1144 );1145 #endif1146 }1147 1148 int response = Gtk::RESPONSE_OK;1149 if(initial_dialog) response = m_join_dlg->run();1150 1151 while(response == Gtk::RESPONSE_OK)1152 {1153 // Read settings1154 Glib::ustring host = m_join_dlg->get_host();1155 unsigned int port = m_join_dlg->get_port();1156 Glib::ustring name = m_join_dlg->get_name();1157 Gdk::Color color = m_join_dlg->get_color();1158 1159 if(session_join_impl(host, port, name, color) )1160 break;1161 else1162 response = m_join_dlg->run();1163 }1164 1165 m_join_dlg->hide();1166 return (m_buffer.get() && m_buffer->is_open() );1167 }1168 1169 bool Gobby::Window::session_open(bool initial_dialog)1170 {1171 if(m_buffer.get() && m_buffer->is_open() )1172 {1173 throw std::logic_error(1174 "Gobby::Window::session_open:\n"1175 "Buffer is already open"1176 );1177 }1178 1179 if(m_host_dlg.get() == NULL)1180 {1181 m_host_dlg.reset(1182 new HostDialog(*this, m_config.get_root()["session"])1183 );1184 }1185 1186 int response = Gtk::RESPONSE_OK;1187 if(initial_dialog) response = m_host_dlg->run();1188 1189 while(response == Gtk::RESPONSE_OK)1190 {1191 // Read setting1192 unsigned int port = m_host_dlg->get_port();1193 Glib::ustring name = m_host_dlg->get_name();1194 Gdk::Color color = m_host_dlg->get_color();1195 Glib::ustring password = m_host_dlg->get_password();1196 Glib::ustring session = m_host_dlg->get_session();1197 1198 if(session_open_impl(port, name, color, password, session) )1199 break;1200 else1201 response = m_host_dlg->run();1202 }1203 1204 // Process file queue (files that have been queued for opening1205 // after session creation).1206 m_host_dlg->hide();1207 while(!m_file_queue.empty() )1208 {1209 std::string str = m_file_queue.front();1210 m_file_queue.pop();1211 1212 if(m_buffer.get() && m_buffer->is_open() )1213 open_local_file(str, EncodingSelector::AUTO_DETECT);1214 }1215 1216 return (m_buffer.get() && m_buffer->is_open() );1217 }1218 1219 bool Gobby::Window::session_join_impl(const Glib::ustring& host,1220 unsigned int port,1221 const Glib::ustring& name,1222 const Gdk::Color& color)1223 {1224 JoinProgressDialog prgdlg(1225 *this,1226 m_config.get_root()["session"],1227 host,1228 port,1229 name,1230 color1231 );1232 1233 if(prgdlg.run() == Gtk::RESPONSE_OK)1234 {1235 prgdlg.hide();1236 1237 // Get buffer1238 std::auto_ptr<ClientBuffer> buffer = prgdlg.get_buffer();1239 1240 buffer->set_enable_keepalives(true);1241 1242 buffer->close_event().connect(1243 sigc::mem_fun(*this, &Window::on_obby_close) );1244 1245 obby::format_string str(_("Connected to %0%:%1%") );1246 str << host << port;1247 1248 // Start session1249 m_buffer = buffer;1250 obby_start();1251 1252 // Session is open, no need to reshow join dialog1253 return true;1254 }1255 else1256 {1257 return false;1258 }1259 }1260 1261 bool Gobby::Window::session_open_impl(unsigned int port,1262 const Glib::ustring& name,1263 const Gdk::Color& color,1264 const Glib::ustring& password,1265 const Glib::ustring& session)1266 {1267 // Set up host with hostprogressdialog1268 HostProgressDialog prgdlg(*this, m_config, port, name, color, session);1269 1270 if(prgdlg.run() == Gtk::RESPONSE_OK)1271 {1272 prgdlg.hide();1273 1274 // Get buffer1275 std::auto_ptr<HostBuffer> buffer =1276 prgdlg.get_buffer();1277 1278 // Set password1279 buffer->set_global_password(password);1280 buffer->set_enable_keepalives(true);1281 #ifdef WITH_ZEROCONF1282 // Publish the newly created session via Zeroconf1283 // if Howl is not deactivated1284 if(m_zeroconf.get() )1285 m_zeroconf->publish(name, port);1286 #endif1287 1288 obby::format_string str(_("Serving on port %0%") );1289 str << port;1290 1291 m_buffer = buffer;1292 1293 // Start session1294 obby_start();1295 // Remember session file1296 m_prev_session = Glib::filename_from_utf8(session);1297 // Session is open, no need to reshow host dialog1298 return true;1299 }1300 else1301 {1302 // Session opening did not succeed1303 return false;1304 }1305 }1306 1307 void Gobby::Window::open_local_file(const Glib::ustring& file,1308 const std::string& encoding)1309 {1310 #if 01311 try1312 {1313 // Set local file path for the document_insert callback1314 m_local_file_path = file;1315 m_local_encoding = encoding;1316 1317 std::string utf8_content;1318 if(encoding == EncodingSelector::AUTO_DETECT)1319 {1320 std::string detected_encoding;1321 1322 utf8_content = Encoding::convert_to_utf8(1323 Glib::file_get_contents(file),1324 detected_encoding1325 );1326 1327 m_local_encoding = detected_encoding;1328 }1329 else1330 {1331 utf8_content = Glib::convert(1332 Glib::file_get_contents(file),1333 "UTF-8",1334 encoding1335 );1336 }1337 1338 convert2unix(utf8_content);1339 1340 m_buffer->document_create(1341 Glib::path_get_basename(file), "UTF-8", utf8_content1342 );1343 1344 // Clear local path1345 m_local_file_path.clear();1346 m_local_encoding.clear();1347 }1348 catch(Glib::Exception& e)1349 {1350 // Show errors while opening the file (e.g. if it doesn't exist)1351 display_error(e.what() );1352 }1353 #endif1354 }1355 1356 void Gobby::Window::save_local_file(DocWindow& doc,1357 const Glib::ustring& file,1358 const std::string& encoding)1359 {1360 #if 01361 try1362 {1363 Glib::RefPtr<Glib::IOChannel> channel = Glib::IOChannel::create_from_file(file, "w");1364 channel->set_encoding("");1365 1366 // Save content into file1367 std::string conv_content = doc.get_content().raw();1368 if(encoding != "UTF-8")1369 {1370 conv_content = Glib::convert(1371 conv_content,1372 encoding,1373 "UTF-8"1374 );1375 }1376 1377 channel->write(conv_content);1378 channel->close();1379 1380 m_document_settings.set_path(doc.get_info(), file);1381 1382 m_document_settings.set_original_encoding(1383 doc.get_info(),1384 encoding1385 );1386 1387 // Update title bar according to new path1388 update_title_bar();1389 // Unset modifified flag1390 gtk_text_buffer_set_modified(1391 GTK_TEXT_BUFFER(doc.get_text_buffer()),1392 FALSE);1393 }1394 catch(Glib::Error& e)1395 {1396 display_error(e.what() );1397 }1398 catch(std::exception& e)1399 {1400 display_error(e.what() );1401 }1402 #endif1403 }1404 1405 void Gobby::Window::close_document(DocWindow& window)1406 {1407 #if 01408 /* Cannot unsubscribe when not subscribed (e.g. unsubscription request1409 * has already been sent. */1410 if(window.get_info().get_subscription_state() !=1411 Gobby::LocalDocumentInfo::SUBSCRIBED)1412 {1413 return;1414 }1415 1416 // Check for the document being modified1417 if(window.get_modified() )1418 {1419 // Setup confirmation strings1420 obby::format_string primary_str(1421 _("Save changes to document \"%0%\" before closing?")1422 );1423 1424 // TODO: Tell that resubscription is not possible when the1425 // session is closed (unless you are host).1426 1427 std::string secondary_str;1428 if(m_buffer.get() != NULL && m_buffer->is_open() )1429 {1430 secondary_str = _(1431 "If you don't save, changes will be "1432 "discarded, but may still be retrieved if "1433 "you re-subscribe to the document as long "1434 "as the session remains open."1435 );1436 }1437 else1438 {1439 secondary_str = _(1440 "If you don't save, changes will be "1441 "discarded."1442 );1443 }1444 1445 primary_str << window.get_info().get_suffixed_title();1446 1447 // Setup dialog1448 Gtk::MessageDialog dlg(*this, primary_str.str(), false,1449 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE, true);1450 1451 // Set secondary text1452 dlg.set_secondary_text(secondary_str);1453 1454 // Add button to allow the user to save the dialog1455 dlg.add_button(_("Close without saving"), Gtk::RESPONSE_REJECT);1456 dlg.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);1457 dlg.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT)->1458 grab_focus();1459 1460 // Show the dialog1461 int result = dlg.run();1462 // Hide it because we cannot back up to it if a later dialog1463 // is cancelled.1464 dlg.hide();1465 1466 switch(result)1467 {1468 case Gtk::RESPONSE_REJECT:1469 /* Close the document */1470 break;1471 case Gtk::RESPONSE_ACCEPT:1472 /* Save the document before closing it */1473 m_folder.set_current_page(m_folder.page_num(window) );1474 if(!handle_document_save() )1475 return;1476 break;1477 case Gtk::RESPONSE_CANCEL:1478 case Gtk::RESPONSE_DELETE_EVENT:1479 /* Do not close the document */1480 return;1481 break;1482 default:1483 throw std::logic_error("Gobby::Window::close_document");1484 break;1485 }1486 }1487 1488 window.get_info().unsubscribe();1489 #endif1490 }1491 1492 void Gobby::Window::display_error(const Glib::ustring& message,1493 const Gtk::MessageType type)1494 {1495 Gtk::MessageDialog dlg(*this, message, false, type,1496 Gtk::BUTTONS_OK, true);1497 dlg.run();1498 }
