...
 
Commits (10)
......@@ -2,29 +2,29 @@
# Moody #
This software is in alpha: it still has some rough edges.
For example there is still no support for folders in master.
For example the username setup require restarting the app; I ignore why.
See [CONTRIBUTING.md](/CONTRIBUTING.md) for informations about how it works.
## Quick Install ##
For Arch Linux, there is the [https://aur.archlinux.org/packages/epfl-moody-git/](epfl-moody-git) AUR package.
For Arch Linux, there is the [epfl-moody-git](https://aur.archlinux.org/packages/epfl-moody-git/) AUR package.
Fedora and Debian packages are planned.
### Flatpak ###
(for it to work, you may need to [install flatpak](https://flatpak.org/setup/))
You can also install using flatpak, which should work for every Linux distribution
```sh
flatpak-builder --install-deps-from=flatpak --install --user --force-clean _flatbuild ch.gnugen.Moody.json
```
For some reason, you may need to install elfutils `sudo apt install elfutils`
Flatpak will build libhandy and myhtml from their repositry, and use libsoup and libsecret
Flatpak will build libhandy and myhtml from their repository, and use libsoup and libsecret
from the Gnome runtime.
You can also install it system-wide by removing the `--user` flags.
you may need to [https://flatpak.org/setup/](install flatpak) for it to work
## Build it Yourself ##
### Gnome Builder ###
......@@ -36,7 +36,7 @@ and ask it to clone the repositry. Have a look at the code while it gets the dep
Alternatively, you can install it system-wide outside of the flatpak sandbox;
You first need to install [https://github.com/lexborisov/myhtml](myhtml)
You first need to install [myhtml](https://github.com/lexborisov/myhtml)
or the modest rendering engine; libhandy, libsecret and libsoup.
You may find these in your repos.
......
......@@ -5,10 +5,14 @@
#define USERNAME "afontain"
#define CACHE_ROOT @CACHE_ROOT@
#mesondefine CACHE_ROOT
// how verbose the http requests are: 0–none, 1–headers only, 2–headers and beginning of text 3+–dump all
// how verbose the http requests are:
// 0 – none
// 1 – headers only
// 2 – headers and beginning of response text
// 3+ – dump all
#define LOGGING_REQUESTS 0
#define APP_NAME "ch.gnugen.Moody"
......
......@@ -9,7 +9,7 @@ src_inc = include_directories('src')
config_h = configuration_data()
config_h.set_quoted('GETTEXT_PACKAGE', 'moody')
config_h.set_quoted('CACHE_ROOT', meson.source_root())
#config_h.set_quoted('CACHE_ROOT', meson.source_root())
config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
configure_file(
......
......@@ -32,8 +32,8 @@ enum resource_type {
};
struct Courses {
struct Course *courses;
size_t course_count;
struct Course *courses;
};
struct Course {
......
......@@ -32,7 +32,8 @@ struct _GuiWindow
{
GtkApplicationWindow parent_instance;
GSettings *settings;
const gchar *username;
gboolean use_cache;
HdyLeaflet *header_box;
HdyLeaflet *content_box;
......@@ -52,16 +53,23 @@ struct _GuiWindow
G_DEFINE_TYPE (GuiWindow, gui_window, GTK_TYPE_APPLICATION_WINDOW)
enum {
PROP_0, PROP_WIN_USERNAME, PROP_WIN_PASSWORD, PROP_WIN_USE_CACHE, N_WIN_PROPERTIES
};
GParamSpec *gui_window_properties[N_WIN_PROPERTIES] = { NULL, };
static void update_moodle_index (GuiWindow *self);
static void
initialize_moodle_provider (GuiWindow *self)
{
gchar *username, *password;
username = g_settings_get_string (self->settings, "username");
if (!moodle_password_get (username, &password))
gchar *password;
if (!moodle_password_get (self->username, &password))
g_error ("Could not get password\n");
moodle_provider_init (MOODLE_MODE_ONLINE, username, password);
g_print ("username: %s, password: %s\n", self->username, password); //FIXME
moodle_provider_init (MOODLE_MODE_ONLINE, self->username, password);
}
static void
......@@ -69,9 +77,8 @@ pass_changed_cb (gpointer ptr, const gchar *username, const gchar *password)
{
GuiWindow *self = HDY_GUI_WINDOW (ptr);
g_settings_set_string (self->settings, "username", username);
if (!moodle_password_set (username, password)) {
g_object_set (self, "username", username, NULL);
if (!moodle_password_set (self->username, password)) {
g_warning ("Could not set password\n");
}
......@@ -86,8 +93,7 @@ activate_ask_pass (GSimpleAction *simple,
gpointer ptr)
{
GuiWindow *self = ptr;
const gchar *current_username = g_settings_get_string (self->settings, "username");
self->dialog = gui_pass_dialog_new (GTK_WINDOW (self), current_username, pass_changed_cb, ptr);
self->dialog = gui_pass_dialog_new (GTK_WINDOW (self), self->username, pass_changed_cb, ptr);
gtk_widget_show (GTK_WIDGET (self->dialog));
}
......@@ -289,6 +295,7 @@ gui_window_new (GtkApplication *application)
return g_object_new (HDY_TYPE_GUI_WINDOW, "application", application, NULL);
}
static void
gui_window_finalize (GObject *object)
{
......@@ -297,6 +304,51 @@ gui_window_finalize (GObject *object)
G_OBJECT_CLASS (gui_window_parent_class)->finalize (object);
}
static void
gui_window_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GuiWindow *self = HDY_GUI_WINDOW (object);
switch (property_id) {
case PROP_WIN_USERNAME:
self->username = g_value_get_string (value);
break;
case PROP_WIN_USE_CACHE:
self->use_cache = g_value_get_boolean (value);
break;
default:
// We don't have any other property...
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
}
static void
gui_window_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GuiWindow *self = HDY_GUI_WINDOW (object);
switch (property_id) {
case PROP_WIN_USERNAME:
if (!self->username)
g_warning ("That read isn't going well\n");
g_value_set_string (value, self->username);
break;
case PROP_WIN_USE_CACHE:
g_value_set_boolean (value, self->use_cache);
break;
default:
// We don't have any other property...
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
g_print ("prop set\n");//FIXME
}
static void
gui_window_class_init (GuiWindowClass *class)
{
......@@ -305,6 +357,24 @@ gui_window_class_init (GuiWindowClass *class)
object_class->finalize = &gui_window_finalize;
gui_window_properties[PROP_WIN_USERNAME] =
g_param_spec_string ("username", "username",
"The username we use to connect to moodle. At EPFL, this is your gaspard account.",
NULL,
G_PARAM_WRITABLE|G_PARAM_READABLE);
gui_window_properties[PROP_WIN_USE_CACHE] =
g_param_spec_boolean ("use_cache", "use_cache",
"Whether to save to disk the responses the moodle provider gets",
TRUE,
G_PARAM_WRITABLE|G_PARAM_READABLE);
object_class->set_property = &gui_window_set_property;
object_class->get_property = &gui_window_get_property;
g_object_class_install_properties (object_class,
N_WIN_PROPERTIES,
gui_window_properties);
gtk_widget_class_set_template_from_resource (widget_class, "/ch/gnugen/Moody/ui/gui-window.ui");
gtk_widget_class_bind_template_child (widget_class, GuiWindow, header_box);
gtk_widget_class_bind_template_child (widget_class, GuiWindow, content_box);
......@@ -324,7 +394,6 @@ gui_window_class_init (GuiWindowClass *class)
}
static void
update_moodle_index (GuiWindow *self)
{
......@@ -350,10 +419,6 @@ gui_window_init (GuiWindow *self)
self->dialog = NULL;
gtk_widget_init_template (GTK_WIDGET (self));
self->settings = g_settings_new (APP_NAME);
initialize_moodle_provider (self);
const GActionEntry entries[] = {
{ "ask-pass", activate_ask_pass },
//{ "print-string", activate_print_string, "s" }
......@@ -362,8 +427,17 @@ gui_window_init (GuiWindow *self)
entries, G_N_ELEMENTS (entries),
self);
GSettings *settings = g_settings_new (APP_NAME);
g_settings_bind (settings, "username",
self, "username",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (settings, "use-cache",
self, "use-cache",
G_SETTINGS_BIND_DEFAULT);
initialize_moodle_provider (self);
hdy_leaflet_set_visible_child_name (self->content_box, "content");
update_header_bar (self);
update_moodle_index (self);
}
......@@ -18,7 +18,6 @@
#include <myhtml/myhtml.h>
#include <assert.h>
#include <stdlib.h>
#include "moodle-parser.h"
#include "data-struct.h"
#include "config.h"
......@@ -219,8 +218,7 @@ moodle_parse_course_list (const gchar *html, gsize html_size, const gchar *filen
myhtml_collection_destroy (hrefs);
myhtml_tree_destroy (tree);
struct Courses courses_struct = {courses, count};
return courses_struct;
return (struct Courses) {count, courses};
}
......@@ -279,8 +277,7 @@ moodle_extract_week (gchar *week_name, myhtml_tree_t *tree, myhtml_tree_node_t *
}
}
struct Week week = {week_name, resource_count, resources};
return week;
return (struct Week) {week_name, resource_count, resources};
}
......
......@@ -16,11 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <libsoup/soup.h>
#include "moodle-provider.h"
#include "moodle-parser.h"
#include "password.h"
#include "utils.h"
#include "config.h"
......