[fix] changed path to app to julian's home instate oft tobias's should change that completly
This commit is contained in:
50
src/get.c
50
src/get.c
@@ -24,16 +24,6 @@ finished (SoupSession *session, SoupMessage *msg, gpointer loop)
|
|||||||
g_main_loop_quit (loop);
|
g_main_loop_quit (loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
|
||||||
concat(const char *s1, const char *s2)
|
|
||||||
{
|
|
||||||
char *result = malloc(strlen(s1)+strlen(s2)+1);//+1 for the zero-terminator
|
|
||||||
//in real code you would check for errors in malloc here
|
|
||||||
strcpy(result, s1);
|
|
||||||
strcat(result, s2);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
get (char *url, const gchar *output_file_path)
|
get (char *url, const gchar *output_file_path)
|
||||||
{
|
{
|
||||||
@@ -59,9 +49,9 @@ get (char *url, const gchar *output_file_path)
|
|||||||
|
|
||||||
loop = g_main_loop_new (NULL, TRUE);
|
loop = g_main_loop_new (NULL, TRUE);
|
||||||
|
|
||||||
const char *name;
|
|
||||||
SoupMessage *msg;
|
SoupMessage *msg;
|
||||||
const char *header;
|
const char *header;
|
||||||
|
const char *name;
|
||||||
FILE *output_file = NULL;
|
FILE *output_file = NULL;
|
||||||
|
|
||||||
msg = soup_message_new ("GET", url);
|
msg = soup_message_new ("GET", url);
|
||||||
@@ -80,18 +70,23 @@ get (char *url, const gchar *output_file_path)
|
|||||||
if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
|
if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
|
||||||
g_print ("%s: %d %s\n", name, msg->status_code, msg->reason_phrase);
|
g_print ("%s: %d %s\n", name, msg->status_code, msg->reason_phrase);
|
||||||
} else if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
|
} else if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
|
||||||
g_print ("###########Name: %s\n", concat(output_file_path, name));
|
//if there is no file name and path the page will not get saved
|
||||||
output_file = fopen (concat(output_file_path, "name"), "w");
|
if (output_file_path == NULL) {
|
||||||
if (!output_file)
|
g_print ("Got a file offered form a other peer. Will not save anything.\n");
|
||||||
g_printerr ("Error trying to create file %s.\n", output_file_path);
|
}
|
||||||
|
else {
|
||||||
|
output_file = fopen (output_file_path, "w");
|
||||||
|
if (!output_file)
|
||||||
|
g_printerr ("Error trying to create file %s.\n", output_file_path);
|
||||||
|
|
||||||
if (output_file) {
|
if (output_file) {
|
||||||
fwrite (msg->response_body->data,
|
fwrite (msg->response_body->data,
|
||||||
1,
|
1,
|
||||||
msg->response_body->length,
|
msg->response_body->length,
|
||||||
output_file);
|
output_file);
|
||||||
|
|
||||||
fclose (output_file);
|
fclose (output_file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,20 +95,17 @@ get (char *url, const gchar *output_file_path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//int do_get_request (char * url)
|
|
||||||
int do_client_notify (char * url)
|
int do_client_notify (char * url)
|
||||||
{
|
{
|
||||||
//url and absoulte path to download dir
|
get (g_strdup(url), NULL);
|
||||||
//get ("http://juliansparber.com/index.html", "./test_download");
|
|
||||||
get (g_strdup(url),"./test_download");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int do_downloading (char * url)
|
int do_downloading (char * url, char * file_name)
|
||||||
{
|
{
|
||||||
g_print("Downloading url %s\n", url);
|
g_print("Downloading url %s\n", url);
|
||||||
//get (g_strdup(url),"./test_download");
|
//get (g_strdup(url),"./test_download");
|
||||||
get ("http://juliansparber.com/index.html", "./test_download");
|
//get ("http://juliansparber.com/index.html", "./test_download");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,5 +113,5 @@ int do_downloading (char * url)
|
|||||||
/*int main () {
|
/*int main () {
|
||||||
get ("http://juliansparber.com/index.html", "./test_download");
|
get ("http://juliansparber.com/index.html", "./test_download");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define __GET_H
|
#define __GET_H
|
||||||
|
|
||||||
|
|
||||||
extern int do_downloading(char *);
|
extern int do_downloading(char *, const char *);
|
||||||
extern int do_client_notify(char *);
|
extern int do_client_notify(char *);
|
||||||
|
|
||||||
#endif /* __GET_H */
|
#endif /* __GET_H */
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
Name=Teleport
|
Name=Teleport
|
||||||
Exec=/home/tobi/code/teleport/src/teleportapp
|
Exec=/home/julian/Projects/teleport/src/teleportapp
|
||||||
Icon=utilities-terminal
|
Icon=utilities-terminal
|
||||||
Type=Application
|
Type=Application
|
||||||
Categories=GTK;GNOME;Utility;
|
Categories=GTK;GNOME;Utility;
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ do_get_response_json (SoupServer *server, SoupMessage *msg, const char *path)
|
|||||||
}
|
}
|
||||||
static void handle_incoming_file(const char * hash, const char * name, const char * size, const char * origin) {
|
static void handle_incoming_file(const char * hash, const char * name, const char * size, const char * origin) {
|
||||||
//If the user accepts the file
|
//If the user accepts the file
|
||||||
do_downloading(g_strdup_printf("http://%s:%d/transfer/%s", origin, port, hash));
|
do_downloading(g_strdup_printf("http://%s:%d/transfer/%s", origin, port, hash), name);
|
||||||
g_print("Got a new file form %s with size:%s with title: %s\n", origin, size, name);
|
g_print("Got a new file form %s with size:%s with title: %s\n", origin, size, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +320,8 @@ int addRouteToServer(char *name, char *file_to_send, char *destination) {
|
|||||||
//send notification of avabile file to the client
|
//send notification of avabile file to the client
|
||||||
//For getting file size
|
//For getting file size
|
||||||
//https://developer.gnome.org/gio/stable/GFile.html#g-file-query-info
|
//https://developer.gnome.org/gio/stable/GFile.html#g-file-query-info
|
||||||
do_client_notify(g_strdup_printf("http://%s:%d/?token=%s&size=0&name=%s\n", destination, port, name, file_to_send));
|
do_client_notify(g_strdup_printf("http://%s:%d/?token=%s&size=0&name=%s\n", destination, port,
|
||||||
|
name, file_to_send));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,13 @@
|
|||||||
#include "publish.h"
|
#include "publish.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NOTIFY_USER, NOTIFY_FINISED, N_SIGNALS
|
||||||
|
};
|
||||||
|
|
||||||
static TeleportAppWindow *win;
|
static TeleportAppWindow *win;
|
||||||
|
static GApplication *application;
|
||||||
|
static gint signalIds [N_SIGNALS];
|
||||||
|
|
||||||
struct _TeleportApp
|
struct _TeleportApp
|
||||||
{
|
{
|
||||||
@@ -17,6 +23,32 @@ struct _TeleportApp
|
|||||||
G_DEFINE_TYPE(TeleportApp, teleport_app, GTK_TYPE_APPLICATION);
|
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)
|
||||||
|
{
|
||||||
|
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 name) {
|
gboolean mainLoopAddPeerCallback (gpointer name) {
|
||||||
update_remote_device_list(win, (char*)name);
|
update_remote_device_list(win, (char*)name);
|
||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
@@ -35,6 +67,10 @@ void callback_remove_peer(GObject * instance, char * name, TeleportAppWindow * w
|
|||||||
g_idle_add(mainLoopRemovePeerCallback, g_strdup(name));
|
g_idle_add(mainLoopRemovePeerCallback, g_strdup(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void callback_notify_user(GObject * instance, char * name, TeleportAppWindow * win ) {
|
||||||
|
create_user_notification("icon.png", 2000, "Mark's laptop");
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
teleport_app_init (TeleportApp *app)
|
teleport_app_init (TeleportApp *app)
|
||||||
{
|
{
|
||||||
@@ -52,6 +88,7 @@ teleport_app_activate (GApplication *app)
|
|||||||
|
|
||||||
g_signal_connect (peerList, "addpeer", (GCallback)callback_add_peer, win);
|
g_signal_connect (peerList, "addpeer", (GCallback)callback_add_peer, win);
|
||||||
g_signal_connect (peerList, "removepeer", (GCallback)callback_remove_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);
|
/*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_name(peerList, 0, NULL));
|
||||||
g_print("Data: %s\n", teleport_peer_get_ip(peerList, 0, NULL));
|
g_print("Data: %s\n", teleport_peer_get_ip(peerList, 0, NULL));
|
||||||
@@ -60,14 +97,7 @@ teleport_app_activate (GApplication *app)
|
|||||||
run_http_server();
|
run_http_server();
|
||||||
run_avahi_publish_service("Angela's (self)");
|
run_avahi_publish_service("Angela's (self)");
|
||||||
run_avahi_service(peerList);
|
run_avahi_service(peerList);
|
||||||
GNotification *notification = g_notification_new ("Hello world!");
|
application = app;
|
||||||
g_notification_set_body (notification, "This is an example notification.");
|
|
||||||
GIcon *icon = g_themed_icon_new ("dialog-information");
|
|
||||||
g_notification_set_icon (notification, icon);
|
|
||||||
g_notification_add_button (notification, "5 minutes", "app.reply-5-minutes");
|
|
||||||
g_application_send_notification (app, NULL, notification);
|
|
||||||
g_object_unref (icon);
|
|
||||||
g_object_unref (notification);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -96,6 +126,19 @@ teleport_app_class_init (TeleportAppClass *class)
|
|||||||
{
|
{
|
||||||
G_APPLICATION_CLASS (class)->activate = teleport_app_activate;
|
G_APPLICATION_CLASS (class)->activate = teleport_app_activate;
|
||||||
G_APPLICATION_CLASS (class)->open = teleport_app_open;
|
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 *
|
TeleportApp *
|
||||||
@@ -106,3 +149,5 @@ teleport_app_new (void)
|
|||||||
"flags", G_APPLICATION_HANDLES_OPEN,
|
"flags", G_APPLICATION_HANDLES_OPEN,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user