[gnote] Remove use of shared_ptr for main window
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Remove use of shared_ptr for main window
- Date: Sat, 8 Dec 2012 18:32:46 +0000 (UTC)
commit a945769f199f36d8d100eb3e4e51a5cd8fadb4d2
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Sat Dec 8 20:30:09 2012 +0200
Remove use of shared_ptr for main window
Fix segfaults when using tray menu.
Fixes bug 688558.
src/addins/backlinks/backlinkmenuitem.cpp | 2 +-
src/dbus/remotecontrol.cpp | 4 +-
src/gnote.cpp | 63 ++++++++++++++---------------
src/gnote.hpp | 9 ++--
src/noterenamedialog.cpp | 2 +-
src/recentchanges.cpp | 19 ++-------
src/recentchanges.hpp | 12 +-----
src/synchronization/syncdialog.cpp | 2 +-
src/tray.cpp | 4 +-
src/watchers.cpp | 2 +-
10 files changed, 49 insertions(+), 70 deletions(-)
---
diff --git a/src/addins/backlinks/backlinkmenuitem.cpp b/src/addins/backlinks/backlinkmenuitem.cpp
index b830c2f..e5cb010 100644
--- a/src/addins/backlinks/backlinkmenuitem.cpp
+++ b/src/addins/backlinks/backlinkmenuitem.cpp
@@ -56,7 +56,7 @@ void BacklinkMenuItem::on_activate()
find.property_visible() = true;
find.set_search_text(m_title_search);
- gnote::NoteRecentChanges::Ptr window = gnote::NoteRecentChanges::get_owning(*this);
+ gnote::NoteRecentChanges *window = gnote::NoteRecentChanges::get_owning(*this);
if(!window) {
window = gnote::Gnote::obj().new_main_window();
}
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index 7c9b0eb..9dcf145 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -154,7 +154,7 @@ namespace gnote {
void RemoteControl::DisplaySearchWithText(const std::string& search_text)
{
- NoteRecentChanges::Ptr recent_changes = Gnote::obj().get_main_window();
+ NoteRecentChanges *recent_changes = Gnote::obj().get_main_window();
recent_changes->set_search_text(search_text);
recent_changes->present();
}
@@ -409,7 +409,7 @@ void RemoteControl::on_note_saved(const Note::Ptr & note)
void RemoteControl::present_note(const Note::Ptr & note)
{
- NoteRecentChanges::Ptr window = Gnote::obj().get_window_for_note();
+ NoteRecentChanges *window = Gnote::obj().get_window_for_note();
window->present_note(note);
window->present();
}
diff --git a/src/gnote.cpp b/src/gnote.cpp
index af2da20..cee2478 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -368,7 +368,7 @@ namespace gnote {
about.set_documenters(documenters);
about.set_translator_credits(translators);
// about.set_icon_name("gnote");
- NoteRecentChanges::Ptr recent_changes = get_main_window();
+ NoteRecentChanges *recent_changes = get_main_window();
if(recent_changes && recent_changes->get_visible()) {
about.set_transient_for(*recent_changes);
recent_changes->present();
@@ -376,56 +376,55 @@ namespace gnote {
about.run();
}
- NoteRecentChanges::Ptr Gnote::new_main_window()
+ NoteRecentChanges *Gnote::new_main_window()
{
- NoteRecentChanges::Ptr win = NoteRecentChanges::create(default_note_manager());
- std::list<NoteRecentChanges::Ptr>::iterator pos = m_main_windows.insert(m_main_windows.end(), win);
- win->signal_hide().connect(boost::bind(sigc::mem_fun(*this, &Gnote::on_main_window_closed), pos));
+ NoteRecentChanges *win = manage(new NoteRecentChanges(default_note_manager()));
+ win->signal_hide().connect(sigc::mem_fun(*this, &Gnote::on_main_window_closed));
add_window(*win);
return win;
}
- NoteRecentChanges::Ptr Gnote::get_main_window()
+ NoteRecentChanges *Gnote::get_main_window()
{
- for(std::list<NoteRecentChanges::Ptr>::iterator iter = m_main_windows.begin();
- iter != m_main_windows.end(); ++iter) {
- return *iter;
+ std::vector<Gtk::Window*> windows = Gtk::Window::list_toplevels();
+ for(std::vector<Gtk::Window*>::iterator iter = windows.begin();
+ iter != windows.end(); ++iter) {
+ NoteRecentChanges *rc = dynamic_cast<NoteRecentChanges*>(*iter);
+ if(rc) {
+ return rc;
+ }
}
- NoteRecentChanges::Ptr win = new_main_window();
- return win;
+ return new_main_window();
}
- void Gnote::on_main_window_closed(std::list<NoteRecentChanges::Ptr>::iterator pos)
+ void Gnote::on_main_window_closed()
{
- remove_window(**pos);
- m_main_windows.erase(pos);
-
// if background mode, we need to have a window, to prevent quit
- if(m_is_background && !m_main_windows.size()) {
+ if(m_is_background && !Gtk::Window::list_toplevels().size()) {
new_main_window();
}
}
- NoteRecentChanges::Ptr Gnote::get_window_for_note()
+ NoteRecentChanges *Gnote::get_window_for_note()
{
- NoteRecentChanges::Ptr window;
- //Find first visible window or any window otherwise
- for(std::list<NoteRecentChanges::Ptr>::iterator iter = m_main_windows.begin();
- iter != m_main_windows.end(); ++iter) {
- if((*iter)->get_visible()) {
- window = *iter;
- break;
- }
- if(!window) {
- window = *iter;
+ std::vector<Gtk::Window*> windows = Gtk::Window::list_toplevels();
+ NoteRecentChanges *window = NULL;
+ for(std::vector<Gtk::Window*>::iterator iter = windows.begin(); iter != windows.end(); ++iter) {
+ NoteRecentChanges *rc = dynamic_cast<NoteRecentChanges*>(*iter);
+ if(rc) {
+ window = rc;
+ if(rc->get_visible()) {
+ return rc;
+ }
}
}
- if(!window) {
- window = new_main_window();
+
+ if(window) {
+ return window;
}
- return window;
+ return new_main_window();
}
void Gnote::open_search_all()
@@ -502,7 +501,7 @@ namespace gnote {
rc->new_note();
}
else {
- NoteRecentChanges::Ptr recent_changes = get_main_window();
+ NoteRecentChanges *recent_changes = get_main_window();
recent_changes->new_note();
recent_changes->present();
}
@@ -511,7 +510,7 @@ namespace gnote {
void Gnote::open_note(const Note::Ptr & note)
{
- NoteRecentChanges::Ptr main_window = get_window_for_note();
+ NoteRecentChanges *main_window = get_window_for_note();
main_window->present_note(note);
main_window->present();
}
diff --git a/src/gnote.hpp b/src/gnote.hpp
index 5d17bde..da3ef43 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -131,9 +131,9 @@ public:
void on_show_preferences_action(const Glib::VariantBase&);
void on_show_help_action(const Glib::VariantBase&);
void on_show_about_action(const Glib::VariantBase&);
- NoteRecentChanges::Ptr new_main_window();
- NoteRecentChanges::Ptr get_main_window();
- NoteRecentChanges::Ptr get_window_for_note();
+ NoteRecentChanges *new_main_window();
+ NoteRecentChanges *get_main_window();
+ NoteRecentChanges *get_window_for_note();
void open_search_all();
void open_note_sync_window(const Glib::VariantBase&);
@@ -180,7 +180,7 @@ private:
void common_init();
void end_main(bool bus_aquired, bool name_acquired);
void on_sync_dialog_response(int response_id);
- void on_main_window_closed(std::list<NoteRecentChanges::Ptr>::iterator pos);
+ void on_main_window_closed();
void make_app_actions();
void add_app_actions(const std::vector<Glib::RefPtr<Gio::SimpleAction> > & actions);
void make_app_menu();
@@ -197,7 +197,6 @@ private:
PreferencesDialog *m_prefsdlg;
GnoteCommandLine cmd_line;
sync::SyncDialog::Ptr m_sync_dlg;
- std::list<NoteRecentChanges::Ptr> m_main_windows;
};
diff --git a/src/noterenamedialog.cpp b/src/noterenamedialog.cpp
index d0405cd..7be0589 100644
--- a/src/noterenamedialog.cpp
+++ b/src/noterenamedialog.cpp
@@ -362,7 +362,7 @@ void NoteRenameDialog::on_notes_view_row_activated(
return;
Gtk::Widget *parent = get_parent();
- NoteRecentChanges::Ptr window;
+ NoteRecentChanges *window = NULL;
if(parent) {
window = NoteRecentChanges::get_owning(*parent);
}
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 58cb988..5eab0ac 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -138,17 +138,11 @@ namespace gnote {
}
- NoteRecentChanges::Ptr NoteRecentChanges::get_owning(Gtk::Widget & widget)
+ NoteRecentChanges *NoteRecentChanges::get_owning(Gtk::Widget & widget)
{
- Ptr owner;
Gtk::Container *container = widget.get_parent();
if(!container) {
- try {
- return dynamic_cast<NoteRecentChanges &>(widget).shared_from_this();
- }
- catch(std::bad_cast &) {
- return owner;
- }
+ return dynamic_cast<NoteRecentChanges*>(&widget);
}
Gtk::Container *cntr = container->get_parent();
@@ -157,12 +151,7 @@ namespace gnote {
cntr = container->get_parent();
}
- NoteRecentChanges *recent_changes = dynamic_cast<NoteRecentChanges*>(container);
- if(recent_changes) {
- owner = recent_changes->shared_from_this();
- }
-
- return owner;
+ return dynamic_cast<NoteRecentChanges*>(container);
}
@@ -173,7 +162,7 @@ namespace gnote {
void NoteRecentChanges::on_open_note_new_window(const Note::Ptr & note)
{
- NoteRecentChanges::Ptr window = Gnote::obj().new_main_window();
+ NoteRecentChanges *window = Gnote::obj().new_main_window();
window->present();
window->present_note(note);
}
diff --git a/src/recentchanges.hpp b/src/recentchanges.hpp
index 0e6c257..ed748d3 100644
--- a/src/recentchanges.hpp
+++ b/src/recentchanges.hpp
@@ -40,19 +40,12 @@ typedef utils::ForcedPresentWindow NoteRecentChangesParent;
class NoteRecentChanges
: public NoteRecentChangesParent
- , public std::tr1::enable_shared_from_this<NoteRecentChanges>
, public utils::EmbeddableWidgetHost
{
public:
- typedef std::tr1::shared_ptr<NoteRecentChanges> Ptr;
- typedef std::tr1::weak_ptr<NoteRecentChanges> WeakPtr;
-
- static Ptr create(NoteManager& m)
- {
- return Ptr(new NoteRecentChanges(m));
- }
- static Ptr get_owning(Gtk::Widget & widget);
+ static NoteRecentChanges *get_owning(Gtk::Widget & widget);
+ NoteRecentChanges(NoteManager& m);
virtual ~NoteRecentChanges();
void set_search_text(const std::string & value);
void present_note(const Note::Ptr & note);
@@ -67,7 +60,6 @@ public:
return m_mapped;
}
protected:
- NoteRecentChanges(NoteManager& m);
virtual void on_show();
virtual bool on_map_event(GdkEventAny *evt);
private:
diff --git a/src/synchronization/syncdialog.cpp b/src/synchronization/syncdialog.cpp
index 5d71093..dd7b8c1 100644
--- a/src/synchronization/syncdialog.cpp
+++ b/src/synchronization/syncdialog.cpp
@@ -788,7 +788,7 @@ void SyncDialog::rename_note(const Note::Ptr & note, const std::string & newTitl
void SyncDialog::present_note(const Note::Ptr & note)
{
- NoteRecentChanges::Ptr window = Gnote::obj().get_window_for_note();
+ NoteRecentChanges *window = Gnote::obj().get_window_for_note();
window->present_note(note);
window->present();
}
diff --git a/src/tray.cpp b/src/tray.cpp
index a63765c..ad0be9b 100644
--- a/src/tray.cpp
+++ b/src/tray.cpp
@@ -93,7 +93,7 @@ namespace gnote {
{
if(!m_inhibit_activate) {
if(m_note) {
- NoteRecentChanges::Ptr window = Gnote::obj().get_window_for_note();
+ NoteRecentChanges *window = Gnote::obj().get_window_for_note();
window->present_note(m_note);
window->present();
}
@@ -333,7 +333,7 @@ namespace gnote {
if (note->is_pinned()) {
show = true;
}
- else if ((note->is_opened() && note->get_window()->get_mapped()) ||
+ else if ((note->is_opened() && note->get_window()->host()) ||
(note->change_date().is_valid() && (note->change_date() > days_ago)) ||
(list_size < min_size)) {
if (list_size <= max_size)
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 13a4e3b..249401b 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -913,7 +913,7 @@ namespace gnote {
// also works around the bug.
if (link) {
DBG_OUT ("Opening note '%s' on click...", link_name.c_str());
- NoteRecentChanges::Ptr window = NoteRecentChanges::get_owning(const_cast<NoteEditor&>(editor));
+ NoteRecentChanges *window = NoteRecentChanges::get_owning(const_cast<NoteEditor&>(editor));
if(!window) {
window = Gnote::obj().new_main_window();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]