[libsoupmm] Add Soup::Date



commit 085531fef711bc7a41e16c733aa627bef2670f17
Author: Siavash Safi <siavash siavashs org>
Date:   Fri Oct 30 19:20:16 2009 +0330

    Add Soup::Date
    
    * codegen/m4/convert_libsoup.m4: Add conversion for DateFormat
    * libsoup/.gitignore: Add date.{h,cc}
    * libsoup/libsoupmm.h: Include date.h
    * libsoup/src/date.{hg,ccg}: Wrap SoupDate
    * libsoup/src/filelist.am: Add date.{hg,ccg}

 codegen/m4/convert_libsoup.m4 |    1 +
 libsoup/.gitignore            |    2 +
 libsoup/libsoupmm.h           |    1 +
 libsoup/src/date.ccg          |   57 +++++++++++++++++++++++++++++++++++++++++
 libsoup/src/date.hg           |   44 +++++++++++++++++++++++++++++++
 libsoup/src/filelist.am       |    2 +-
 6 files changed, 106 insertions(+), 1 deletions(-)
---
diff --git a/codegen/m4/convert_libsoup.m4 b/codegen/m4/convert_libsoup.m4
index 1d79466..28e657c 100644
--- a/codegen/m4/convert_libsoup.m4
+++ b/codegen/m4/convert_libsoup.m4
@@ -32,5 +32,6 @@ _CONVERSION(`SoupURI*',`URI',($2)($3))
 _CONVERSION(`return-char*',`std::string',`Glib::convert_return_gchar_ptr_to_stdstring($3)')
 _CONVERSION(`GMainContext*',`Glib::RefPtr<Glib::MainContext>',`Glib::wrap($3)')
 
+_CONV_ENUM(Soup,DateFormat)
 _CONV_ENUM(Soup,HTTPVersion)
 _CONV_ENUM(Soup,MemoryUse)
diff --git a/libsoup/.gitignore b/libsoup/.gitignore
index 4984724..80600bf 100644
--- a/libsoup/.gitignore
+++ b/libsoup/.gitignore
@@ -10,6 +10,8 @@
 /libsoupmm/cookie-jar.h
 /libsoupmm/cookie-jar-text.cc
 /libsoupmm/cookie-jar-text.h
+/libsoupmm/date.cc
+/libsoupmm/date.h
 /libsoupmm/enums.cc
 /libsoupmm/enums.h
 /libsoupmm/message.cc
diff --git a/libsoup/libsoupmm.h b/libsoup/libsoupmm.h
index c026f9f..64ef5b7 100644
--- a/libsoup/libsoupmm.h
+++ b/libsoup/libsoupmm.h
@@ -28,6 +28,7 @@
 #include <libsoupmm/cookie.h>
 #include <libsoupmm/cookie-jar.h>
 #include <libsoupmm/cookie-jar-text.h>
+#include <libsoupmm/date.h>
 #include <libsoupmm/enums.h>
 #include <libsoupmm/form.h>
 #include <libsoupmm/message.h>
diff --git a/libsoup/src/date.ccg b/libsoup/src/date.ccg
new file mode 100644
index 0000000..5f93b58
--- /dev/null
+++ b/libsoup/src/date.ccg
@@ -0,0 +1,57 @@
+/* Copyright (c) 2009  Siavash Safi <siavashs siavashs org>
+ *
+ * This file is part of libsoupmm.
+ *
+ * libsoupmm is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 2.1 of the License,
+ * or (at your option) any later version.
+ *
+ * libsoupmm 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libsoup/soup-date.h>
+
+namespace Soup
+{
+
+Date::Date(int offset_seconds)
+{
+  gobject_ = soup_date_new_from_now(offset_seconds);
+}
+
+Date::Date(int year, int month, int day, int hour, int minute, int second)
+{
+  gobject_ = soup_date_new(year, month, day, hour, minute, second);
+}
+
+Date::Date(const std::string& date_string)
+{
+  gobject_ = soup_date_new_from_string(date_string.c_str());
+}
+
+Date::Date(time_t when)
+{
+  gobject_ = soup_date_new_from_time_t(when);
+}
+
+Glib::TimeVal
+Date::to_timeval() const
+{
+  GTimeVal ctime;
+  Glib::TimeVal time;
+
+  soup_date_to_timeval(gobject_, &ctime);
+
+  time = ctime;
+
+  return time;
+}
+
+} // namespace Soup
diff --git a/libsoup/src/date.hg b/libsoup/src/date.hg
new file mode 100644
index 0000000..5614b0b
--- /dev/null
+++ b/libsoup/src/date.hg
@@ -0,0 +1,44 @@
+/* Copyright (c) 2009  Siavash Safi <siavashs siavashs org>
+ *
+ * This file is part of libsoupmm.
+ *
+ * libsoupmm is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 2.1 of the License,
+ * or (at your option) any later version.
+ *
+ * libsoupmm 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+_DEFS(libsoupmm,libsoup)
+
+namespace Soup
+{
+
+_WRAP_ENUM(DateFormat, SoupDateFormat, NO_GTYPE)
+
+class Date
+{
+  _CLASS_BOXEDTYPE(Date, SoupDate, soup_date_new, soup_date_copy, soup_date_free)
+  _CUSTOM_DEFAULT_CTOR
+  _IGNORE(soup_date_copy, soup_date_free, soup_uri_equal)
+
+public:
+  explicit Date(int offset_seconds=0);
+  explicit Date(int year, int month, int day, int hour, int minute, int second);
+  explicit Date(const std::string& date_string);
+  explicit Date(time_t when);
+
+  _WRAP_METHOD(std::string to_string(DateFormat format) const, soup_date_to_string)
+  _WRAP_METHOD(time_t to_time_t() const, soup_date_to_time_t)
+  Glib::TimeVal to_timeval() const;
+  _WRAP_METHOD(bool is_past() const, soup_date_is_past)
+};
+
+} // namespace Soup
diff --git a/libsoup/src/filelist.am b/libsoup/src/filelist.am
index b377ec5..801c452 100644
--- a/libsoup/src/filelist.am
+++ b/libsoup/src/filelist.am
@@ -8,5 +8,5 @@ files_defs =			\
 	libsoup_signals.defs	\
 	libsoup_docs.xml
 
-files_hg  = address.hg auth.hg cookie.hg cookie-jar.hg cookie-jar-text.hg enums.hg message.hg message-body.hg server.hg session.hg uri.hg
+files_hg  = address.hg auth.hg cookie.hg cookie-jar.hg cookie-jar-text.hg date.hg enums.hg message.hg message-body.hg server.hg session.hg uri.hg
 files_ccg = $(files_hg:.hg=.ccg)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]