aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-22 18:18:22 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-22 18:18:22 +0000
commit8e09d9a5cb1e19fd82f5c493598fd7dc0948b852 (patch)
treee5ba22cb8bd07f08b9597018469ec6534c6dc040
parent67b12f07f4fd66f17a16e9c293657b742ae7d839 (diff)
downloadpaludis-8e09d9a5cb1e19fd82f5c493598fd7dc0948b852.tar.gz
paludis-8e09d9a5cb1e19fd82f5c493598fd7dc0948b852.tar.xz
Make gtkpaludis more useful
-rw-r--r--src/gtkpaludis/Makefile.am9
-rw-r--r--src/gtkpaludis/categories_list.cc10
-rw-r--r--src/gtkpaludis/gtkpaludis.cc16
-rw-r--r--src/gtkpaludis/main_window.cc19
-rw-r--r--src/gtkpaludis/main_window.hh2
-rw-r--r--src/gtkpaludis/messages.cc8
-rw-r--r--src/gtkpaludis/messages.hh2
-rw-r--r--src/gtkpaludis/package_overview.cc5
-rw-r--r--src/gtkpaludis/packages_list.cc54
-rw-r--r--src/gtkpaludis/paludis_thread.cc40
-rw-r--r--src/gtkpaludis/paludis_thread.hh12
-rw-r--r--src/gtkpaludis/repositories_list.cc4
-rw-r--r--src/gtkpaludis/repositories_page.cc17
-rw-r--r--src/gtkpaludis/sync.cc84
-rw-r--r--src/gtkpaludis/sync.hh48
15 files changed, 264 insertions, 66 deletions
diff --git a/src/gtkpaludis/Makefile.am b/src/gtkpaludis/Makefile.am
index 08286e4..fa5a91c 100644
--- a/src/gtkpaludis/Makefile.am
+++ b/src/gtkpaludis/Makefile.am
@@ -18,17 +18,18 @@ if ENABLE_GTK
bin_PROGRAMS = gtkpaludis
gtkpaludis_SOURCES = \
+ categories_list.cc categories_list.hh \
command_line.cc command_line.hh \
main_window.cc main_window.hh \
- categories_list.cc categories_list.hh \
- packages_page.cc packages_page.hh \
- packages_list.cc packages_list.hh \
+ messages.cc messages.hh \
package_info.cc package_info.hh \
package_overview.cc package_overview.hh \
+ packages_list.cc packages_list.hh \
+ packages_page.cc packages_page.hh \
paludis_thread.cc paludis_thread.hh \
- messages.cc messages.hh \
repositories_list.cc repositories_list.hh \
repositories_page.cc repositories_page.hh \
+ sync.cc sync.hh \
gtkpaludis.cc
gtkpaludis_LDADD = \
diff --git a/src/gtkpaludis/categories_list.cc b/src/gtkpaludis/categories_list.cc
index 176c0ed..3db2547 100644
--- a/src/gtkpaludis/categories_list.cc
+++ b/src/gtkpaludis/categories_list.cc
@@ -92,24 +92,18 @@ namespace
{
std::set<CategoryNamePart> names;
- dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(),
- &MainWindow::push_status), "Loading category names..."));
+ StatusBarMessage m1(this, "Loading category names...");
for (PackageDatabase::RepositoryIterator
r(DefaultEnvironment::get_instance()->package_database()->begin_repositories()),
r_end(DefaultEnvironment::get_instance()->package_database()->end_repositories()) ; r != r_end ; ++r)
{
- dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(),
- &MainWindow::push_status), "Loading category names from '" +
- stringify((*r)->name()) + "'..."));
+ StatusBarMessage m2(this, "Loading category names from '" + stringify((*r)->name()) + "'...");
CategoryNamePartCollection::ConstPointer cats((*r)->category_names());
std::copy(cats->begin(), cats->end(), std::inserter(names, names.end()));
-
- dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::pop_status));
}
- dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::pop_status));
dispatch(sigc::bind<1>(sigc::mem_fun(_imp, &Implementation<CategoriesList>::add_categories), names));
}
}
diff --git a/src/gtkpaludis/gtkpaludis.cc b/src/gtkpaludis/gtkpaludis.cc
index 72d7644..7290b3a 100644
--- a/src/gtkpaludis/gtkpaludis.cc
+++ b/src/gtkpaludis/gtkpaludis.cc
@@ -172,10 +172,18 @@ main(int argc, char * argv[])
std::string::size_type last_slash(paludis_command.rfind('/'));
if (std::string::npos == last_slash)
last_slash = 0;
- if (0 == paludis_command.compare(last_slash, 3, "lt-"))
- paludis_command.erase(last_slash, 3);
- if (0 == paludis_command.compare(last_slash, 3, "gtk"))
- paludis_command.erase(last_slash, 3);
+ if (0 == paludis_command.compare(last_slash + 1, 13, "lt-gtkpaludis"))
+ {
+ /* i hate libtool */
+ paludis_command.erase(last_slash);
+ if (std::string::npos != ((last_slash = paludis_command.rfind('/'))))
+ paludis_command.erase(last_slash);
+ if (std::string::npos != ((last_slash = paludis_command.rfind('/'))))
+ paludis_command.erase(last_slash);
+ paludis_command.append("/paludis/paludis");
+ }
+ else if (0 == paludis_command.compare(last_slash + 1, 3, "gtk"))
+ paludis_command.erase(last_slash + 1, 3);
if (CommandLine::get_instance()->a_config_suffix.specified())
{
diff --git a/src/gtkpaludis/main_window.cc b/src/gtkpaludis/main_window.cc
index 5811a25..e00a005 100644
--- a/src/gtkpaludis/main_window.cc
+++ b/src/gtkpaludis/main_window.cc
@@ -27,6 +27,8 @@
#include <gtkmm/box.h>
#include <gtkmm/notebook.h>
#include <gtkmm/table.h>
+#include <gtkmm/messagedialog.h>
+#include <gtkmm/main.h>
#include <list>
@@ -155,3 +157,20 @@ MainWindow::show_messages_page()
_imp->main_notebook.set_current_page(_imp->messages_page_id);
}
+void
+MainWindow::show_exception(const std::string & what, const std::string & message, bool fatal)
+{
+ Gtk::MessageDialog dialog(*this, fatal ? "Fatal Error" : "Error", false, Gtk::MESSAGE_ERROR);
+ dialog.set_secondary_text(message + " (" + what + ")");
+ dialog.run();
+
+ if (fatal)
+ Gtk::Main::quit();
+}
+
+void
+MainWindow::message(const std::string & s)
+{
+ _imp->messages.message(s);
+}
+
diff --git a/src/gtkpaludis/main_window.hh b/src/gtkpaludis/main_window.hh
index 7bdd76f..b255e47 100644
--- a/src/gtkpaludis/main_window.hh
+++ b/src/gtkpaludis/main_window.hh
@@ -46,6 +46,8 @@ namespace gtkpaludis
void lock_controls();
void maybe_unlock_controls();
+ void show_exception(const std::string & what, const std::string & message, bool fatal);
+ void message(const std::string &);
void push_status(const std::string &);
void pop_status();
diff --git a/src/gtkpaludis/messages.cc b/src/gtkpaludis/messages.cc
index f2e025b..1480c38 100644
--- a/src/gtkpaludis/messages.cc
+++ b/src/gtkpaludis/messages.cc
@@ -24,6 +24,7 @@
#include <paludis/util/system.hh>
#include <cstdlib>
#include <fcntl.h>
+#include <unistd.h>
// for restoring Log's output stream
#include <iostream>
@@ -108,3 +109,10 @@ Messages::~Messages()
Log::get_instance()->set_log_stream(&std::cerr);
}
+void
+Messages::message(const std::string & s)
+{
+ std::string msg("=== " + s + " ===\n");
+ write(_imp->term_pty.slave_fd(), msg.c_str(), msg.length());
+}
+
diff --git a/src/gtkpaludis/messages.hh b/src/gtkpaludis/messages.hh
index 0028be3..9ff5ca7 100644
--- a/src/gtkpaludis/messages.hh
+++ b/src/gtkpaludis/messages.hh
@@ -32,6 +32,8 @@ namespace gtkpaludis
public:
Messages();
virtual ~Messages();
+
+ void message(const std::string &);
};
}
diff --git a/src/gtkpaludis/package_overview.cc b/src/gtkpaludis/package_overview.cc
index 8fa2de6..9857b5d 100644
--- a/src/gtkpaludis/package_overview.cc
+++ b/src/gtkpaludis/package_overview.cc
@@ -112,8 +112,7 @@ namespace
top_row[_imp->columns.col_left] = stringify(_pkg);
top_row[_imp->columns.col_right] = "";
- dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(),
- &MainWindow::push_status), "Querying package versions..."));
+ StatusBarMessage m1(this, "Querying package versions...");
PackageDatabaseEntryCollection::ConstPointer results(DefaultEnvironment::get_instance()->package_database()->query(
PackageDepAtom::Pointer(new PackageDepAtom(stringify(_pkg))), is_either));
@@ -135,8 +134,6 @@ namespace
(*r->second)[_imp->columns.col_right] = value;
}
- dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::pop_status));
-
dispatch(sigc::bind<1>(sigc::mem_fun(_imp, &Implementation<PackageOverview>::set_model), model));
}
}
diff --git a/src/gtkpaludis/packages_list.cc b/src/gtkpaludis/packages_list.cc
index de0c072..f4d2d3f 100644
--- a/src/gtkpaludis/packages_list.cc
+++ b/src/gtkpaludis/packages_list.cc
@@ -121,43 +121,39 @@ namespace
{
std::map<QualifiedPackageName, std::string> names;
- dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(),
- &MainWindow::push_status), "Loading package names..."));
-
- for (PackageDatabase::RepositoryIterator
- r(DefaultEnvironment::get_instance()->package_database()->begin_repositories()),
- r_end(DefaultEnvironment::get_instance()->package_database()->end_repositories()) ; r != r_end ; ++r)
{
- dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(),
- &MainWindow::push_status), "Loading package names from '" +
- stringify((*r)->name()) + "'..."));
+ StatusBarMessage m1(this, "Loading package names...");
- QualifiedPackageNameCollection::ConstPointer pkgs((*r)->package_names(_cat));
- for (QualifiedPackageNameCollection::Iterator p(pkgs->begin()), p_end(pkgs->end()) ;
- p != p_end ; ++p)
- names.insert(std::make_pair(*p, ""));
+ for (PackageDatabase::RepositoryIterator
+ r(DefaultEnvironment::get_instance()->package_database()->begin_repositories()),
+ r_end(DefaultEnvironment::get_instance()->package_database()->end_repositories()) ; r != r_end ; ++r)
+ {
+ StatusBarMessage m2(this, "Loading package names from '" + stringify((*r)->name()) + "'...");
- dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::pop_status));
+ QualifiedPackageNameCollection::ConstPointer pkgs((*r)->package_names(_cat));
+ for (QualifiedPackageNameCollection::Iterator p(pkgs->begin()), p_end(pkgs->end()) ;
+ p != p_end ; ++p)
+ names.insert(std::make_pair(*p, ""));
+ }
}
- dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::pop_status));
- dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(),
- &MainWindow::push_status), "Loading package descriptions..."));
-
- for (std::map<QualifiedPackageName, std::string>::iterator i(names.begin()), i_end(names.end()) ;
- i != i_end ; ++i)
{
- PackageDatabaseEntryCollection::ConstPointer results(DefaultEnvironment::get_instance()->package_database()->query(
- PackageDepAtom::Pointer(new PackageDepAtom(stringify(i->first))), is_either));
-
- if (results->empty())
- continue;
- i->second = DefaultEnvironment::get_instance()->package_database()->fetch_repository(
- results->last()->repository)->version_metadata(results->last()->name,
- results->last()->version)->description;
+ StatusBarMessage m1(this, "Loading package descriptions...");
+
+ for (std::map<QualifiedPackageName, std::string>::iterator i(names.begin()), i_end(names.end()) ;
+ i != i_end ; ++i)
+ {
+ PackageDatabaseEntryCollection::ConstPointer results(DefaultEnvironment::get_instance()->package_database()->query(
+ PackageDepAtom::Pointer(new PackageDepAtom(stringify(i->first))), is_either));
+
+ if (results->empty())
+ continue;
+ i->second = DefaultEnvironment::get_instance()->package_database()->fetch_repository(
+ results->last()->repository)->version_metadata(results->last()->name,
+ results->last()->version)->description;
+ }
}
- dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::pop_status));
dispatch(sigc::bind<1>(sigc::mem_fun(_list, &Implementation<PackagesList>::add_packages), names));
}
}
diff --git a/src/gtkpaludis/paludis_thread.cc b/src/gtkpaludis/paludis_thread.cc
index 6de4121..9d2f846 100644
--- a/src/gtkpaludis/paludis_thread.cc
+++ b/src/gtkpaludis/paludis_thread.cc
@@ -20,6 +20,7 @@
#include "paludis_thread.hh"
#include "main_window.hh"
#include <paludis/util/log.hh>
+#include <paludis/util/stringify.hh>
#include <glibmm/thread.h>
using namespace paludis;
@@ -107,8 +108,45 @@ PaludisThread::_thread_func(PaludisThread::Launchable::Pointer l)
{
{
Glib::Mutex::Lock lock(_imp->single_mutex);
- (*l)();
+ try
+ {
+ try
+ {
+ (*l)();
+ }
+ catch (const Exception &)
+ {
+ throw;
+ }
+ catch (const std::exception & e)
+ {
+ throw InternalError(PALUDIS_HERE, "Caught unexpected exception '" + stringify(e.what()) + "'");
+ }
+ }
+ catch (const InternalError & e)
+ {
+ _queue_add(sigc::bind<std::string, std::string, bool>(
+ sigc::mem_fun(MainWindow::get_instance(), &MainWindow::show_exception),
+ stringify(e.what()), e.message(), true));
+ }
+ catch (const Exception & e)
+ {
+ _queue_add(sigc::bind<std::string, std::string, bool>(
+ sigc::mem_fun(MainWindow::get_instance(), &MainWindow::show_exception),
+ stringify(e.what()), e.message(), false));
+ }
}
_queue_add(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::maybe_unlock_controls));
}
+PaludisThread::Launchable::StatusBarMessage::StatusBarMessage(Launchable * const l, const std::string & s) :
+ _l(l)
+{
+ _l->dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::push_status), s));
+}
+
+PaludisThread::Launchable::StatusBarMessage::~StatusBarMessage()
+{
+ _l->dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::pop_status));
+}
+
diff --git a/src/gtkpaludis/paludis_thread.hh b/src/gtkpaludis/paludis_thread.hh
index acbcbf8..600bf2f 100644
--- a/src/gtkpaludis/paludis_thread.hh
+++ b/src/gtkpaludis/paludis_thread.hh
@@ -45,11 +45,21 @@ namespace gtkpaludis
protected:
Launchable();
+ public:
void dispatch(const sigc::slot<void> &);
- public:
virtual ~Launchable();
virtual void operator() () = 0;
+
+ class StatusBarMessage
+ {
+ private:
+ Launchable * const _l;
+
+ public:
+ StatusBarMessage(Launchable * const, const std::string &);
+ ~StatusBarMessage();
+ };
};
friend class Launchable;
diff --git a/src/gtkpaludis/repositories_list.cc b/src/gtkpaludis/repositories_list.cc
index 9ecb5f5..f0cd721 100644
--- a/src/gtkpaludis/repositories_list.cc
+++ b/src/gtkpaludis/repositories_list.cc
@@ -92,15 +92,13 @@ namespace
{
std::set<RepositoryName> names;
- dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(),
- &MainWindow::push_status), "Loading repository names..."));
+ StatusBarMessage m1(this, "Loading repository names...");
for (PackageDatabase::RepositoryIterator
r(DefaultEnvironment::get_instance()->package_database()->begin_repositories()),
r_end(DefaultEnvironment::get_instance()->package_database()->end_repositories()) ; r != r_end ; ++r)
names.insert((*r)->name());
- dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::pop_status));
dispatch(sigc::bind<1>(sigc::mem_fun(_imp, &Implementation<RepositoriesList>::add_repositories), names));
}
}
diff --git a/src/gtkpaludis/repositories_page.cc b/src/gtkpaludis/repositories_page.cc
index 6163cac..f2822ff 100644
--- a/src/gtkpaludis/repositories_page.cc
+++ b/src/gtkpaludis/repositories_page.cc
@@ -21,6 +21,7 @@
#include "repositories_list.hh"
#include "paludis_thread.hh"
#include "main_window.hh"
+#include "sync.hh"
#include <paludis/environment/default/default_environment.hh>
#include <gtkmm/button.h>
@@ -110,18 +111,10 @@ namespace
void
Sync::operator() ()
{
- dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(),
- &MainWindow::push_status), "Syncing repository '" + stringify(_name) + "'..."));
-
- Repository::ConstPointer repo(DefaultEnvironment::get_instance()->package_database()->fetch_repository(_name));
- if (repo->syncable_interface)
- {
- dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::show_messages_page));
- repo->syncable_interface->sync();
- }
-
- dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::pop_status));
- dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::populate));
+ StatusBarMessage m1(this, "Syncing repository '" + stringify(_name) + "'...");
+ OurSyncTask task(this);
+ task.add_target(stringify(_name));
+ task.execute();
}
}
diff --git a/src/gtkpaludis/sync.cc b/src/gtkpaludis/sync.cc
new file mode 100644
index 0000000..385b587
--- /dev/null
+++ b/src/gtkpaludis/sync.cc
@@ -0,0 +1,84 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "sync.hh"
+#include "main_window.hh"
+#include <paludis/environment/default/default_environment.hh>
+
+using namespace paludis;
+using namespace gtkpaludis;
+
+OurSyncTask::OurSyncTask(PaludisThread::Launchable * const l) :
+ SyncTask(DefaultEnvironment::get_instance()),
+ _l(l)
+{
+}
+
+OurSyncTask::~OurSyncTask()
+{
+}
+
+void
+OurSyncTask::on_sync_all_pre()
+{
+ _l->dispatch(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::show_messages_page));
+ _l->dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::message),
+ stringify("Starting sync")));
+}
+
+void
+OurSyncTask::on_sync_pre(const RepositoryName & r)
+{
+ _l->dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::message),
+ stringify("Syncing '" + stringify(r) + "'")));
+}
+
+void
+OurSyncTask::on_sync_post(const RepositoryName &)
+{
+}
+
+void
+OurSyncTask::on_sync_skip(const RepositoryName & r)
+{
+ _l->dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::message),
+ stringify("Sync of '" + stringify(r) + "' skipped")));
+}
+
+void
+OurSyncTask::on_sync_fail(const RepositoryName & r, const SyncFailedError &)
+{
+ _l->dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::message),
+ stringify("Sync of '" + stringify(r) + "' failed")));
+}
+
+void
+OurSyncTask::on_sync_succeed(const RepositoryName & r)
+{
+ _l->dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::message),
+ stringify("Sync of '" + stringify(r) + "' succeeded")));
+}
+
+void
+OurSyncTask::on_sync_all_post()
+{
+ _l->dispatch(sigc::bind<1>(sigc::mem_fun(MainWindow::get_instance(), &MainWindow::message),
+ stringify("Sync completed")));
+}
+
diff --git a/src/gtkpaludis/sync.hh b/src/gtkpaludis/sync.hh
new file mode 100644
index 0000000..5243b96
--- /dev/null
+++ b/src/gtkpaludis/sync.hh
@@ -0,0 +1,48 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_SRC_GTKPALUDIS_SYNC_HH
+#define PALUDIS_GUARD_SRC_GTKPALUDIS_SYNC_HH 1
+
+#include <paludis/tasks/sync_task.hh>
+#include <src/gtkpaludis/paludis_thread.hh>
+
+namespace gtkpaludis
+{
+ class OurSyncTask :
+ public paludis::SyncTask
+ {
+ private:
+ PaludisThread::Launchable * const _l;
+
+ public:
+ OurSyncTask(PaludisThread::Launchable * const l);
+ virtual ~OurSyncTask();
+
+ virtual void on_sync_all_pre();
+ virtual void on_sync_pre(const paludis::RepositoryName &);
+ virtual void on_sync_post(const paludis::RepositoryName &);
+ virtual void on_sync_skip(const paludis::RepositoryName &);
+ virtual void on_sync_fail(const paludis::RepositoryName &, const paludis::SyncFailedError &);
+ virtual void on_sync_succeed(const paludis::RepositoryName &);
+ virtual void on_sync_all_post();
+ };
+}
+
+#endif