[feat] add notification for completed download (not tested) and the notification does not show correct information
This commit is contained in:
53
src/get.c
53
src/get.c
@@ -13,15 +13,28 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <libsoup/soup.h>
|
||||
#include "teleportapp.h"
|
||||
|
||||
static SoupSession *session;
|
||||
static GMainLoop *loop;
|
||||
static gboolean debug;
|
||||
|
||||
|
||||
int callback (SoupMessage *msg, const gchar *output_file_path);
|
||||
|
||||
static void
|
||||
finished (SoupSession *session, SoupMessage *msg, gpointer loop)
|
||||
finished (SoupSession *session, SoupMessage *msg, gpointer target)
|
||||
{
|
||||
g_main_loop_quit (loop);
|
||||
|
||||
//GVariant *target array: {originDevice, url, filename}
|
||||
callback(msg,
|
||||
(char *) g_variant_get_string (
|
||||
g_variant_get_child_value ((GVariant *) target, 0), NULL));
|
||||
create_finished_notification ((char *) g_variant_get_string (
|
||||
g_variant_get_child_value ((GVariant *) target, 0), NULL),
|
||||
0,
|
||||
g_variant_get_string (
|
||||
g_variant_get_child_value ((GVariant *) target, 2), NULL),
|
||||
target);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -47,21 +60,32 @@ get (char *url, const gchar *output_file_path)
|
||||
g_object_unref (logger);
|
||||
}
|
||||
|
||||
loop = g_main_loop_new (NULL, TRUE);
|
||||
|
||||
SoupMessage *msg;
|
||||
const char *header;
|
||||
const char *name;
|
||||
FILE *output_file = NULL;
|
||||
|
||||
msg = soup_message_new ("GET", url);
|
||||
soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
|
||||
|
||||
g_object_ref (msg);
|
||||
soup_session_queue_message (session, msg, finished, loop);
|
||||
// soup_session_queue_message (session, msg, finished, NULL);
|
||||
g_main_loop_run (loop);
|
||||
//soup_session_queue_message (session, msg, finished, loop);
|
||||
GVariantBuilder *builder;
|
||||
GVariant *target;
|
||||
|
||||
builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
|
||||
g_variant_builder_add (builder, "s", "devicename");
|
||||
g_variant_builder_add (builder, "s", url);
|
||||
g_variant_builder_add (builder, "s", output_file_path);
|
||||
target = g_variant_new ("as", builder);
|
||||
g_variant_builder_unref (builder);
|
||||
|
||||
soup_session_queue_message (session, msg, finished, target);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int callback (SoupMessage *msg, const gchar *output_file_path) {
|
||||
const char *name;
|
||||
FILE *output_file = NULL;
|
||||
name = soup_message_get_uri (msg)->path;
|
||||
|
||||
if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code))
|
||||
@@ -90,8 +114,6 @@ get (char *url, const gchar *output_file_path)
|
||||
}
|
||||
}
|
||||
|
||||
g_main_loop_unref (loop);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -109,10 +131,3 @@ do_downloading (const char *originDevice, const char *url, const char *filename)
|
||||
get (g_strdup(url), g_strdup_printf("./test_download/%s", g_uri_escape_string(filename, NULL, TRUE)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*int main () {
|
||||
get ("http://juliansparber.com/index.html", "./test_download");
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -17,6 +17,11 @@ void do_nothing_callback(GSimpleAction *simple,
|
||||
GVariant *parameter,
|
||||
gpointer user_data);
|
||||
|
||||
void open_file_callback (GSimpleAction *simple,
|
||||
GVariant *parameter,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
enum {
|
||||
NOTIFY_USER, NOTIFY_FINISED, N_SIGNALS
|
||||
};
|
||||
@@ -24,7 +29,9 @@ enum {
|
||||
static GActionEntry app_entries[] =
|
||||
{
|
||||
{ "save", save_file_callback, "as", NULL, NULL },
|
||||
{ "decline", do_nothing_callback, "as", NULL, NULL }
|
||||
{ "decline", do_nothing_callback, "as", NULL, NULL },
|
||||
{ "do-nothing", do_nothing_callback, "as", NULL, NULL },
|
||||
{ "open-file", open_file_callback, "as", NULL, NULL }
|
||||
};
|
||||
|
||||
static TeleportAppWindow *win;
|
||||
@@ -51,6 +58,12 @@ void do_nothing_callback (GSimpleAction *simple,
|
||||
gpointer user_data) {
|
||||
}
|
||||
|
||||
void open_file_callback (GSimpleAction *simple,
|
||||
GVariant *parameter,
|
||||
gpointer user_data) {
|
||||
g_print("Open file\n");
|
||||
}
|
||||
|
||||
void create_user_notification (const char *file_name, const int file_size, const char *origin_device, GVariant *target) {
|
||||
GNotification *notification = g_notification_new ("Teleport");
|
||||
g_notification_set_body (notification,
|
||||
@@ -60,7 +73,7 @@ void create_user_notification (const char *file_name, const int file_size, const
|
||||
g_format_size (file_size)));
|
||||
GIcon *icon = g_themed_icon_new ("dialog-information");
|
||||
g_notification_set_icon (notification, icon);
|
||||
g_notification_set_default_action_and_target_value (notification, "app.decline", target);
|
||||
g_notification_set_default_action_and_target_value (notification, "app.do-nothing", target);
|
||||
g_notification_add_button_with_target_value (notification, "Decline", "app.decline", target);
|
||||
g_notification_add_button_with_target_value (notification, "Save", "app.save", target);
|
||||
g_application_send_notification (application, NULL, notification);
|
||||
@@ -68,15 +81,16 @@ void create_user_notification (const char *file_name, const int file_size, const
|
||||
g_object_unref (notification);
|
||||
//the example says I have to unref it but it gives a critival error
|
||||
//https://developer.gnome.org/glib/stable/gvariant-format-strings.html
|
||||
//g_variant_unref (value);
|
||||
//g_variant_unref (target);
|
||||
}
|
||||
|
||||
static void create_finished_notification (const char *file_name, const int file_size, const char *origin_device) {
|
||||
void create_finished_notification (const char *origin, const int filesize, const char *filename, GVariant *target) {
|
||||
GNotification *notification = g_notification_new ("Teleport");
|
||||
g_notification_set_body (notification, g_strdup_printf("Transfer %s from %s is complete)", file_name, origin_device));
|
||||
g_notification_set_body (notification, g_strdup_printf("Transfer of %s from %s is complete", filename, origin));
|
||||
GIcon *icon = g_themed_icon_new ("dialog-information");
|
||||
g_notification_set_icon (notification, icon);
|
||||
g_notification_add_button (notification, "Open", "app.reply-5-minutes");
|
||||
g_notification_set_default_action_and_target_value (notification, "app.do-nothing", target);
|
||||
g_notification_add_button_with_target_value (notification, "Open", "app.open-file", target);
|
||||
g_application_send_notification (application, NULL, notification);
|
||||
g_object_unref (icon);
|
||||
g_object_unref (notification);
|
||||
@@ -134,7 +148,7 @@ teleport_app_activate (GApplication *app) {
|
||||
g_print("Data: %d\n", teleport_peer_get_port(peerList, 0, NULL));
|
||||
*/
|
||||
|
||||
GVariantBuilder *builder;
|
||||
/*GVariantBuilder *builder;
|
||||
GVariant *value;
|
||||
|
||||
builder = g_variant_builder_new (G_VARIANT_TYPE ("as"));
|
||||
@@ -144,7 +158,9 @@ teleport_app_activate (GApplication *app) {
|
||||
value = g_variant_new ("as", builder);
|
||||
g_variant_builder_unref (builder);
|
||||
|
||||
create_user_notification ("sdfdsff", 2000, "sdfdsfdsf", value);
|
||||
create_finished_notification ("USER", 2000, "FILENAME", value);
|
||||
*/
|
||||
do_downloading("Julian", "https://sparber.net", "juliansfile");
|
||||
|
||||
run_http_server();
|
||||
run_avahi_publish_service((char *) g_get_host_name());
|
||||
|
||||
@@ -14,4 +14,9 @@ extern void create_user_notification (const char *,
|
||||
const char *,
|
||||
GVariant *);
|
||||
|
||||
extern void create_finished_notification (const char *,
|
||||
const int,
|
||||
const char *,
|
||||
GVariant *);
|
||||
|
||||
#endif /* __TELEPORTAPP_H */
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 238 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 529 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 252 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 36 KiB |
@@ -1,151 +0,0 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "teleportapp.h"
|
||||
#include "teleportpeer.h"
|
||||
#include "teleportappwin.h"
|
||||
#include "browser.h"
|
||||
#include "publish.h"
|
||||
#include "server.h"
|
||||
|
||||
enum {
|
||||
NOTIFY_USER, NOTIFY_FINISED, N_SIGNALS
|
||||
};
|
||||
|
||||
static TeleportAppWindow *win;
|
||||
static GApplication *application;
|
||||
static gint signalIds [N_SIGNALS];
|
||||
|
||||
struct _TeleportApp {
|
||||
GtkApplication parent;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (TeleportApp, teleport_app, GTK_TYPE_APPLICATION);
|
||||
|
||||
|
||||
static void create_user_notification (const char *file_name, const int file_size, const char *origin_device) {
|
||||
g_print("Create Notification");
|
||||
GNotification *notification = g_notification_new ("Teleport");
|
||||
g_notification_set_body (notification, g_strdup_printf("%s is sending %s (%d Byte)", origin_device, file_name, file_size));
|
||||
GIcon *icon = g_themed_icon_new ("dialog-information");
|
||||
g_notification_set_icon (notification, icon);
|
||||
g_notification_add_button (notification, "Decline", "app.reply-5-minutes");
|
||||
g_notification_add_button (notification, "Save", "app.reply-5-minutes");
|
||||
g_application_send_notification (application, NULL, notification);
|
||||
g_object_unref (icon);
|
||||
g_object_unref (notification);
|
||||
}
|
||||
|
||||
static void create_finished_notification (const char *file_name, const int file_size, const char *origin_device) {
|
||||
GNotification *notification = g_notification_new ("Teleport");
|
||||
g_notification_set_body (notification, g_strdup_printf("Transfer %s from %s is complete)", file_name, origin_device));
|
||||
GIcon *icon = g_themed_icon_new ("dialog-information");
|
||||
g_notification_set_icon (notification, icon);
|
||||
g_notification_add_button (notification, "Open", "app.reply-5-minutes");
|
||||
g_application_send_notification (application, NULL, notification);
|
||||
g_object_unref (icon);
|
||||
g_object_unref (notification);
|
||||
}
|
||||
|
||||
|
||||
gboolean mainLoopAddPeerCallback (gpointer peer) {
|
||||
//g_print("new New device name is %p\n", ((Peer *)peer));
|
||||
//g_print("new New device name is %s\n", ((Peer *)peer)->name);
|
||||
update_remote_device_list(win, (Peer *) peer);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
gboolean mainLoopRemovePeerCallback (gpointer peer) {
|
||||
update_remote_device_list_remove(win, (Peer *) peer);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
void callback_add_peer (GObject *instance, Peer *peer, TeleportAppWindow *win ) {
|
||||
g_idle_add(mainLoopAddPeerCallback, peer);
|
||||
}
|
||||
|
||||
void callback_remove_peer (GObject *instance, Peer *peer, TeleportAppWindow *win ) {
|
||||
g_idle_add(mainLoopRemovePeerCallback, peer);
|
||||
}
|
||||
|
||||
void callback_notify_user (GObject *instance, char *name, TeleportAppWindow *win ) {
|
||||
create_user_notification("icon.png", 2000, "Mark's laptop");
|
||||
}
|
||||
|
||||
static void
|
||||
teleport_app_init (TeleportApp *app) {
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
teleport_app_activate (GApplication *app) {
|
||||
//TeleportAppWindow *win;
|
||||
application = app;
|
||||
TeleportPeer *peerList = g_object_new (TELEPORT_TYPE_PEER, NULL);
|
||||
|
||||
win = teleport_app_window_new (TELEPORT_APP (app));
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
|
||||
g_signal_connect (peerList, "addpeer", (GCallback)callback_add_peer, win);
|
||||
g_signal_connect (peerList, "removepeer", (GCallback)callback_remove_peer, win);
|
||||
g_signal_connect (app, "notify_user", (GCallback)callback_notify_user, win);
|
||||
/*teleport_peer_add_peer(peerList, "julian", "192.168.0.1", 3000);
|
||||
g_print("Data: %s\n", teleport_peer_get_name(peerList, 0, NULL));
|
||||
g_print("Data: %s\n", teleport_peer_get_ip(peerList, 0, NULL));
|
||||
g_print("Data: %d\n", teleport_peer_get_port(peerList, 0, NULL));
|
||||
*/
|
||||
|
||||
create_user_notification ("sdfdsff", 2000, "sdfdsfdsf");
|
||||
run_http_server();
|
||||
run_avahi_publish_service("Angela's (self)");
|
||||
run_avahi_service(peerList);
|
||||
}
|
||||
|
||||
static void
|
||||
teleport_app_open (GApplication *app,
|
||||
GFile **files,
|
||||
gint n_files,
|
||||
const gchar *hint)
|
||||
{
|
||||
GList *windows;
|
||||
int i;
|
||||
|
||||
windows = gtk_application_get_windows (GTK_APPLICATION (app));
|
||||
if (windows)
|
||||
win = TELEPORT_APP_WINDOW (windows->data);
|
||||
else
|
||||
win = teleport_app_window_new (TELEPORT_APP (app));
|
||||
|
||||
for (i = 0; i < n_files; i++)
|
||||
teleport_app_window_open (win, files[i]);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (win));
|
||||
}
|
||||
|
||||
static void
|
||||
teleport_app_class_init (TeleportAppClass *class)
|
||||
{
|
||||
G_APPLICATION_CLASS (class)->activate = teleport_app_activate;
|
||||
G_APPLICATION_CLASS (class)->open = teleport_app_open;
|
||||
|
||||
signalIds[NOTIFY_USER] = g_signal_new ("notify_user",
|
||||
G_TYPE_OBJECT,
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
|
||||
0,
|
||||
NULL /* accumulator */,
|
||||
NULL /* accumulator data */,
|
||||
NULL /* C marshaller */,
|
||||
G_TYPE_NONE /* return_type */,
|
||||
1,
|
||||
G_TYPE_STRING);
|
||||
|
||||
|
||||
}
|
||||
|
||||
TeleportApp *
|
||||
teleport_app_new (void)
|
||||
{
|
||||
return g_object_new (TELEPORT_APP_TYPE,
|
||||
"application-id", "org.gtk.teleportapp",
|
||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||
NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user