added the GUI for incremental backups (don't use it yet, it crashes)

This commit is contained in:
fgerlits 2006-04-04 18:15:12 +00:00
parent 2546341d70
commit 85d66b8c3a
13 changed files with 560 additions and 8 deletions

View file

@ -43,6 +43,7 @@
#include <stdexcept>
#include <cctype>
#include <XmlRpcValue.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
@ -55,6 +56,8 @@ namespace Storage {
namespace LiveSupport {
namespace Core {
using namespace boost::posix_time;
/* ================================================================ constants */
@ -137,6 +140,16 @@ class SearchCriteria
*/
SearchConditionListType searchConditions;
/**
* The mtime to use for "ls:mtime".
*/
Ptr<const ptime>::Ref mtimeValue;
/**
* The comparison operator to use for "ls:mtime".
*/
std::string mtimeComparisonOperator;
/**
* The maximum number of conditions to be returned.
*/
@ -252,6 +265,18 @@ class SearchCriteria
const std::string & value)
throw(std::invalid_argument);
/**
* Add a search condition specifying the mtime (modified-at time).
*
* @param comparisonOperator one of "=", "partial", "prefix",
* "<", "<=", ">" or ">="
* @param value the value of the mtime to compare to
*/
void
addMtimeCondition(const std::string & comparisonOperator,
Ptr<const ptime>::Ref value)
throw(std::invalid_argument);
/**
* Add a search condition.
*

View file

@ -162,7 +162,7 @@ class TimeConversion
* @return a struct tm, holding the same time.
*/
static void
ptimeToTm(Ptr<ptime>::Ref convertFrom, struct tm & convertTo)
ptimeToTm(Ptr<const ptime>::Ref convertFrom, struct tm & convertTo)
throw ();
/**

View file

@ -33,9 +33,11 @@
#include "configure.h"
#endif
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Core/SearchCriteria.h"
using namespace LiveSupport::Core;
using namespace boost::posix_time;
/* =================================================== local data structures */
@ -86,6 +88,28 @@ SearchCriteria :: addCondition(const std::string & key,
}
/*------------------------------------------------------------------------------
* Add a search condition specifying the mtime (modified-at time).
*----------------------------------------------------------------------------*/
void
SearchCriteria :: addMtimeCondition(const std::string & comparisonOperator,
Ptr<const ptime>::Ref value)
throw(std::invalid_argument)
{
std::string lowerCaseOp = lowerCase(comparisonOperator);
if (lowerCaseOp == "="
|| lowerCaseOp == "partial" || lowerCaseOp == "prefix"
|| lowerCaseOp == "<" || lowerCaseOp == "<="
|| lowerCaseOp == ">" || lowerCaseOp == ">=") {
mtimeComparisonOperator = lowerCaseOp;
mtimeValue = value;
} else {
throw std::invalid_argument("bad comparison operator argument");
}
}
/*------------------------------------------------------------------------------
* Convert to an XmlRpc::XmlRpcValue.
*----------------------------------------------------------------------------*/
@ -111,6 +135,19 @@ SearchCriteria :: operator XmlRpc::XmlRpcValue() const
condition["val"] = it->value;
conditionList[i] = condition;
}
if (mtimeValue) {
int i = conditionList.size();
struct tm * mtimeStructTm;
TimeConversion::ptimeToTm(mtimeValue, *mtimeStructTm);
XmlRpc::XmlRpcValue condition;
condition["cat"] = "ls:mtime";
condition["op"] = mtimeComparisonOperator;
condition["val"] = XmlRpc::XmlRpcValue(mtimeStructTm);
conditionList[i] = condition;
}
returnValue["conditions"] = conditionList;
if (limit) {
@ -121,6 +158,7 @@ SearchCriteria :: operator XmlRpc::XmlRpcValue() const
returnValue["offset"] = offset;
}
std::cerr << returnValue << std::endl;
return returnValue;
}

View file

@ -105,7 +105,8 @@ TimeConversion :: tmToPtime(const struct tm *time)
* Convert a boost::ptime to a struct tm
*----------------------------------------------------------------------------*/
void
TimeConversion :: ptimeToTm(Ptr<ptime>::Ref convertFrom, struct tm & convertTo)
TimeConversion :: ptimeToTm(Ptr<const ptime>::Ref convertFrom,
struct tm & convertTo)
throw ()
{
date date = convertFrom->date();

View file

@ -147,7 +147,8 @@ WIDGETS_LIB_OBJS = ${TMP_DIR}/ImageButton.o \
${TMP_DIR}/Colors.o \
${TMP_DIR}/DialogWindow.o \
${TMP_DIR}/ScrolledWindow.o \
${TMP_DIR}/ScrolledNotebook.o
${TMP_DIR}/ScrolledNotebook.o \
${TMP_DIR}/DateTimeChooserWindow.o
TEST_EXE_OBJS = ${TMP_DIR}/TestWindow.o \
${TMP_DIR}/main.o

View file

@ -0,0 +1,160 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport 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 LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision$
Location : $URL: svn+ssh://fgerlits@code.campware.org/home/svn/repo/livesupport/trunk/livesupport/src/modules/widgets/include/LiveSupport/Widgets/DateTimeChooserWindow.h $
------------------------------------------------------------------------------*/
#ifndef DateTimeChooserWindow_h
#define DateTimeChooserWindow_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <gtkmm/calendar.h>
#include <gtkmm/main.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/LocalizedObject.h"
#include "LiveSupport/Widgets/EntryBin.h"
#include "LiveSupport/Widgets/WhiteWindow.h"
namespace LiveSupport {
namespace Widgets {
using namespace LiveSupport::Core;
using namespace boost::posix_time;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A dialog window for choosing a date/time.
*
* The constructor is called with a resource bundle. The resource bundle
* is expected to contain keys named cancelButtonLabel, okButtonLabel,
* hourLabel and minuteLabel.
*
* The return value of the run() method is a boost::posix_time::ptime value.
* The DateTimeChooserWindow object is not destroyed when it returns from
* run(); it is the responsibility of the caller to delete it (or it can be
* reused a few times first).
*
* @author $Author: fgerlits $
* @version $Revision$
*/
class DateTimeChooserWindow : public WhiteWindow,
public LocalizedObject
{
private:
/**
* The calendar where the date is chosen.
*/
Gtk::Calendar * calendar;
/**
* The entry field for the hour.
*/
EntryBin * hourEntry;
/**
* The entry field for the minute.
*/
EntryBin * minuteEntry;
/**
* The return value; set to 0 if the user pressed Cancel.
*/
Ptr<ptime>::Ref chosenDateTime;
protected:
/**
* The event handler for the Cancel button clicked.
*/
void
onCancelButtonClicked(void) throw ();
/**
* The event handler for the OK button clicked.
*/
void
onOkButtonClicked(void) throw ();
public:
/**
* Constructor.
*
* @param bundle a resource bundle containing the localized
* button labels
*/
DateTimeChooserWindow(Ptr<ResourceBundle>::Ref bundle) throw ();
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~DateTimeChooserWindow(void) throw ()
{
}
/**
* Run the window and return the date/time selected.
* The returned value may be a 0 pointer (if the user pressed Cancel),
* and it may be not_a_date_time, if the user's selection is invalid.
*/
Ptr<const ptime>::Ref
run(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Widgets
} // namespace LiveSupport
#endif // DateTimeChooserWindow_h

View file

@ -58,6 +58,7 @@
#include "LiveSupport/Widgets/EntryBin.h"
#include "LiveSupport/Widgets/DialogWindow.h"
#include "LiveSupport/Widgets/ZebraTreeView.h"
#include "LiveSupport/Widgets/DateTimeChooserWindow.h"
namespace LiveSupport {
@ -374,6 +375,19 @@ class WidgetFactory :
Ptr<ResourceBundle>::Ref bundle,
int buttons = DialogWindow::okButton)
throw ();
/**
* Create a DateTimeChooserWindow.
* It lets the user select a date/time.
* It is the reponsibility of the caller to dispose of the created
* object properly.
*
* @param bundle localization for the button(s).
* @return the DateTimeChooserWindow object.
*/
DateTimeChooserWindow *
createDateTimeChooserWindow(Ptr<ResourceBundle>::Ref bundle)
throw ();
};

View file

@ -0,0 +1,175 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport 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 LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: fgerlits $
Version : $Revision$
Location : $URL: svn+ssh://fgerlits@code.campware.org/home/svn/repo/livesupport/trunk/livesupport/src/modules/widgets/src/DateTimeChooserWindow.cxx $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Widgets/WidgetFactory.h"
#include "LiveSupport/Widgets/Colors.h"
#include "LiveSupport/Widgets/Button.h"
#include "LiveSupport/Widgets/DateTimeChooserWindow.h"
using namespace LiveSupport::Widgets;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Constructor.
*----------------------------------------------------------------------------*/
DateTimeChooserWindow :: DateTimeChooserWindow(Ptr<ResourceBundle>::Ref bundle)
throw ()
: WhiteWindow("",
Colors::White,
WidgetFactory::getInstance()->getWhiteWindowCorners(),
WhiteWindow::isModal | WhiteWindow::isBornHidden),
LocalizedObject(bundle)
{
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
Gtk::Label * hourLabel;
Gtk::Label * minuteLabel;
Button * cancelButton;
Button * okButton;
try {
set_title(*getResourceUstring("windowTitle"));
hourLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("hourLabel")));
minuteLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("minuteLabel")));
cancelButton = Gtk::manage(wf->createButton(
*getResourceUstring("cancelButtonLabel")));
okButton = Gtk::manage(wf->createButton(
*getResourceUstring("okButtonLabel")));
} catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl;
std::exit(1);
}
calendar = Gtk::manage(new Gtk::Calendar());
hourEntry = Gtk::manage(wf->createEntryBin());
minuteEntry = Gtk::manage(wf->createEntryBin());
cancelButton->signal_clicked().connect(sigc::mem_fun(*this,
&DateTimeChooserWindow::onCancelButtonClicked));
okButton->signal_clicked().connect(sigc::mem_fun(*this,
&DateTimeChooserWindow::onOkButtonClicked));
Gtk::ButtonBox * buttonBox = Gtk::manage(new Gtk::HButtonBox(
Gtk::BUTTONBOX_END, 5));
buttonBox->pack_start(*cancelButton);
buttonBox->pack_start(*okButton);
Gtk::Box * entryBox = Gtk::manage(new Gtk::HBox());
entryBox->pack_start(*hourLabel, Gtk::PACK_SHRINK, 5);
entryBox->pack_start(*hourEntry, Gtk::PACK_EXPAND_WIDGET, 5);
entryBox->pack_start(*minuteLabel, Gtk::PACK_SHRINK, 5);
entryBox->pack_start(*minuteEntry, Gtk::PACK_EXPAND_WIDGET, 5);
Gtk::Box * layout = Gtk::manage(new Gtk::VBox());
layout->pack_start(*calendar, Gtk::PACK_EXPAND_WIDGET, 5);
layout->pack_start(*entryBox, Gtk::PACK_SHRINK, 5);
layout->pack_start(*buttonBox, Gtk::PACK_SHRINK, 5);
set_default_size(200, 300);
add(*layout);
}
/*------------------------------------------------------------------------------
* Event handler for the Cancel button clicked
*----------------------------------------------------------------------------*/
void
DateTimeChooserWindow :: onCancelButtonClicked(void) throw ()
{
chosenDateTime.reset();
hide();
}
/*------------------------------------------------------------------------------
* Event handler for the OK button clicked.
*----------------------------------------------------------------------------*/
void
DateTimeChooserWindow :: onOkButtonClicked(void) throw ()
{
std::stringstream dateTime;
guint year;
guint month;
guint day;
calendar->get_date(year, month, day);
dateTime << std::setfill('0') << std::setw(4)
<< year
<< std::setfill('0') << std::setw(2)
<< month + 1
<< std::setfill('0') << std::setw(2)
<< day;
Glib::ustring hour = hourEntry ->get_text().substr(0,2);
Glib::ustring minute = minuteEntry->get_text().substr(0,2);
dateTime << "T"
<< std::setfill('0') << std::setw(2)
<< hour
<< std::setfill('0') << std::setw(2)
<< minute
<< "00";
chosenDateTime.reset(new ptime(from_iso_string(dateTime.str())));
hide();
}
/*------------------------------------------------------------------------------
* Show the window and return the button clicked.
*----------------------------------------------------------------------------*/
Ptr<const ptime>::Ref
DateTimeChooserWindow :: run(void) throw ()
{
show_all();
Gtk::Main::run(*this);
return chosenDateTime;
}

View file

@ -673,3 +673,14 @@ WidgetFactory :: createDialogWindow(Ptr<Glib::ustring>::Ref message,
return new DialogWindow(message, buttons, bundle);
}
/*------------------------------------------------------------------------------
* Create a date/time chooser window.
*----------------------------------------------------------------------------*/
DateTimeChooserWindow *
WidgetFactory :: createDateTimeChooserWindow(Ptr<ResourceBundle>::Ref bundle)
throw ()
{
return new DateTimeChooserWindow(bundle);
}

View file

@ -39,13 +39,13 @@
#include <gtkmm/stock.h>
#include <gtkmm/paned.h>
#include "LiveSupport/Widgets/ScrolledWindow.h"
#include "BackupView.h"
using namespace LiveSupport::Core;
using namespace LiveSupport::Widgets;
using namespace LiveSupport::GLiveSupport;
using namespace boost::posix_time;
/* =================================================== local data structures */
@ -67,26 +67,54 @@ BackupView :: BackupView (Ptr<GLiveSupport>::Ref gLiveSupport,
: LocalizedObject(bundle),
gLiveSupport(gLiveSupport)
{
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
Gtk::Label * backupTitleLabel;
Gtk::Label * mtimeLabel;
Gtk::Button * chooseTimeButton;
Gtk::Button * resetTimeButton;
try {
backupTitleLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("backupTitleLabel")));
*getResourceUstring("backupTitleLabel")));
mtimeLabel = Gtk::manage(new Gtk::Label(
*getResourceUstring("mtimeTextLabel")));
chooseTimeButton = Gtk::manage(wf->createButton(
*getResourceUstring("chooseTimeButtonLabel")));
resetTimeButton = Gtk::manage(wf->createButton(
*getResourceUstring("resetTimeButtonLabel")));
} catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl;
std::exit(1);
}
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
chooseTimeButton->signal_clicked().connect(sigc::mem_fun(
*this, &BackupView::onChooseTimeButtonClicked ));
resetTimeButton->signal_clicked().connect(sigc::mem_fun(
*this, &BackupView::onResetTimeButtonClicked ));
backupTitleEntry = Gtk::manage(wf->createEntryBin());
mtimeEntry = Gtk::manage(wf->createEntryBin());
mtimeEntry->getEntry()->set_editable(false);
mtimeEntry->getEntry()->set_alignment(0.5);
mtimeEntry->getEntry()->set_width_chars(20);
writeMtimeEntry();
Gtk::Box * backupTitleBox = Gtk::manage(new Gtk::HBox);
backupTitleBox->pack_start(*backupTitleLabel, Gtk::PACK_SHRINK, 5);
backupTitleBox->pack_start(*backupTitleEntry, Gtk::PACK_SHRINK, 5);
Gtk::Box * mtimeBox = Gtk::manage(new Gtk::HBox);
mtimeBox->pack_start(*mtimeLabel, Gtk::PACK_SHRINK, 5);
mtimeBox->pack_start(*mtimeEntry, Gtk::PACK_SHRINK, 5);
mtimeBox->pack_start(*chooseTimeButton, Gtk::PACK_SHRINK, 5);
mtimeBox->pack_start(*resetTimeButton, Gtk::PACK_SHRINK, 5);
Gtk::Box * criteriaView = constructCriteriaView();
Gtk::Box * topPane = Gtk::manage(new Gtk::VBox);
topPane->pack_start(*backupTitleBox, Gtk::PACK_SHRINK, 5);
topPane->pack_start(*mtimeBox, Gtk::PACK_SHRINK, 5);
topPane->pack_start(*criteriaView, Gtk::PACK_EXPAND_WIDGET, 5);
Gtk::Box * bottomPane = constructBackupListView();
@ -96,6 +124,9 @@ BackupView :: BackupView (Ptr<GLiveSupport>::Ref gLiveSupport,
twoPanedView->pack2(*bottomPane, Gtk::PACK_EXPAND_WIDGET, 5);
add(*twoPanedView);
dateTimeChooserWindow.reset(wf->createDateTimeChooserWindow(
gLiveSupport->getBundle("dateTimeChooserWindow") ));
}
@ -185,6 +216,32 @@ BackupView :: constructBackupListView(void) throw ()
}
/*------------------------------------------------------------------------------
* Event handler for the time chooser button being clicked.
*----------------------------------------------------------------------------*/
void
BackupView :: onChooseTimeButtonClicked(void) throw ()
{
Ptr<const ptime>::Ref userMtime = dateTimeChooserWindow->run();
if (userMtime && *userMtime != not_a_date_time) {
mtime = userMtime;
writeMtimeEntry();
}
}
/*------------------------------------------------------------------------------
* Event handler for the "reset time" button being clicked.
*----------------------------------------------------------------------------*/
void
BackupView :: onResetTimeButtonClicked(void) throw ()
{
mtime.reset();
writeMtimeEntry();
}
/*------------------------------------------------------------------------------
* Initiate the creation of a new backup.
*----------------------------------------------------------------------------*/
@ -194,6 +251,10 @@ BackupView :: onCreateBackup(void) throw ()
Ptr<Glib::ustring>::Ref title = readTitle();
Ptr<SearchCriteria>::Ref criteria = criteriaEntry->getSearchCriteria();
if (mtime) {
criteria->addMtimeCondition(">=", mtime);
}
try {
backupList->add(title, criteria);
@ -336,3 +397,17 @@ BackupView :: readTitle(void) throw ()
return title;
}
/*------------------------------------------------------------------------------
* Format and write the contents of mtime into the mtimeEntry.
*----------------------------------------------------------------------------*/
void
BackupView :: writeMtimeEntry(void) throw ()
{
if (mtime) {
mtimeEntry->set_text(to_simple_string(*mtime));
} else {
mtimeEntry->set_text("-");
}
}

View file

@ -41,11 +41,14 @@
#endif
#include <gtkmm/box.h>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/LocalizedObject.h"
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Widgets/Button.h"
#include "LiveSupport/Widgets/ScrolledWindow.h"
#include "LiveSupport/Widgets/DateTimeChooserWindow.h"
#include "AdvancedSearchEntry.h"
#include "BackupList.h"
#include "GLiveSupport.h"
@ -55,6 +58,7 @@ namespace GLiveSupport {
using namespace LiveSupport::Core;
using namespace LiveSupport::Widgets;
using namespace boost::posix_time;
/* ================================================================ constants */
@ -94,6 +98,21 @@ class BackupView : public Gtk::VBox,
*/
EntryBin * backupTitleEntry;
/**
* The "modified since" time for the backup.
*/
Ptr<const ptime>::Ref mtime;
/**
* The entry field holding the "modified since" time for the backup.
*/
EntryBin * mtimeEntry;
/**
* The window for entering the "modified since" time.
*/
Ptr<DateTimeChooserWindow>::Ref dateTimeChooserWindow;
/**
* The object for entering the backup criteria.
*/
@ -139,7 +158,13 @@ class BackupView : public Gtk::VBox,
*/
Ptr<Glib::ustring>::Ref
readTitle(void) throw ();
/**
* Format and write the contents of mtime into the mtimeEntry.
*/
void
writeMtimeEntry(void) throw ();
protected:
/**
@ -147,6 +172,18 @@ class BackupView : public Gtk::VBox,
*/
Ptr<GLiveSupport>::Ref gLiveSupport;
/**
* Event handler for the time chooser button being clicked.
*/
void
onChooseTimeButtonClicked(void) throw ();
/**
* Event handler for the "reset time" button being clicked.
*/
void
onResetTimeButtonClicked(void) throw ();
/**
* Initiate the creation of a new backup.
*/

View file

@ -163,7 +163,7 @@ OptionsWindow :: OptionsWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
// show everything
set_name(windowName);
set_default_size(700, 400);
set_default_size(700, 450);
set_modal(false);
property_window_position().set_value(Gtk::WIN_POS_NONE);

View file

@ -280,6 +280,10 @@ root:table
dateColumnLabel:string { "Date" }
statusColumnLabel:string { "Status" }
mtimeTextLabel:string { "Modified since:" }
chooseTimeButtonLabel:string { "Choose time" }
resetTimeButtonLabel:string { "Reset" }
backupButtonLabel:string { "Backup" }
deleteButtonLabel:string { "Delete" }
saveButtonLabel:string { "Save" }
@ -291,6 +295,17 @@ root:table
backupErrorMsg:string { "Backup error: " }
}
dateTimeChooserWindow:table
{
windowTitle:string { "Select the date and time" }
cancelButtonLabel:string { "Cancel" }
okButtonLabel:string { "OK" }
hourLabel:string { "hour:" }
minuteLabel:string { "minute:" }
}
metadataTypes:table
{
title:string { "Title" }