[feat] allow user to click on notification's open btn to open file
This commit is contained in:
1
src/.gitignore
vendored
1
src/.gitignore
vendored
@@ -27,3 +27,4 @@ _libs
|
|||||||
/teleportapp
|
/teleportapp
|
||||||
/teleportapp.o
|
/teleportapp.o
|
||||||
/teleportappwin.o
|
/teleportappwin.o
|
||||||
|
test_download
|
||||||
|
|||||||
29
src/get.c
29
src/get.c
@@ -17,16 +17,17 @@
|
|||||||
|
|
||||||
static SoupSession *session;
|
static SoupSession *session;
|
||||||
static gboolean debug;
|
static gboolean debug;
|
||||||
static gchar *output_direcotry;
|
|
||||||
|
|
||||||
|
int saveFile (SoupMessage *, const gchar *, const gchar *);
|
||||||
int saveFile (SoupMessage *msg, const gchar *output_file_path);
|
gchar * getFilePath (const gchar *, const gchar *);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
finished (SoupSession *session, SoupMessage *msg, gpointer target)
|
finished (SoupSession *session, SoupMessage *msg, gpointer target)
|
||||||
{
|
{
|
||||||
//GVariant *target array: {originDevice, url, filename}
|
//GVariant *target array: {originDevice, url, filename, downloadDirectory}
|
||||||
saveFile(msg,
|
saveFile(msg,
|
||||||
|
(char *) g_variant_get_string (
|
||||||
|
g_variant_get_child_value ((GVariant *) target, 3), NULL),
|
||||||
(char *) g_variant_get_string (
|
(char *) g_variant_get_string (
|
||||||
g_variant_get_child_value ((GVariant *) target, 2), NULL));
|
g_variant_get_child_value ((GVariant *) target, 2), NULL));
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ finished (SoupSession *session, SoupMessage *msg, gpointer target)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
get (char *url, const gchar *outputFilename)
|
get (char *url, const gchar *downloadDirectory, const gchar *outputFilename)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
SoupLogger *logger = NULL;
|
SoupLogger *logger = NULL;
|
||||||
@@ -76,6 +77,7 @@ get (char *url, const gchar *outputFilename)
|
|||||||
g_variant_builder_add (builder, "s", "devicename");
|
g_variant_builder_add (builder, "s", "devicename");
|
||||||
g_variant_builder_add (builder, "s", url);
|
g_variant_builder_add (builder, "s", url);
|
||||||
g_variant_builder_add (builder, "s", outputFilename);
|
g_variant_builder_add (builder, "s", outputFilename);
|
||||||
|
g_variant_builder_add (builder, "s", downloadDirectory);
|
||||||
target = g_variant_new ("as", builder);
|
target = g_variant_new ("as", builder);
|
||||||
g_variant_builder_unref (builder);
|
g_variant_builder_unref (builder);
|
||||||
|
|
||||||
@@ -84,7 +86,7 @@ get (char *url, const gchar *outputFilename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int saveFile (SoupMessage *msg, const gchar *outputFilename) {
|
int saveFile (SoupMessage *msg, const gchar *outputDirectory, const gchar *outputFilename) {
|
||||||
const char *name;
|
const char *name;
|
||||||
FILE *output_file = NULL;
|
FILE *output_file = NULL;
|
||||||
|
|
||||||
@@ -102,9 +104,7 @@ int saveFile (SoupMessage *msg, const gchar *outputFilename) {
|
|||||||
//g_print ("%s: Got a file offered form a other peer. Will not save anything.\n", name);
|
//g_print ("%s: Got a file offered form a other peer. Will not save anything.\n", name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
output_file = fopen (g_strdup_printf("%s%s", output_direcotry,
|
output_file = fopen (getFilePath(outputDirectory, outputFilename), "w");
|
||||||
g_uri_escape_string(outputFilename, NULL, TRUE)),
|
|
||||||
"w");
|
|
||||||
|
|
||||||
if (!output_file)
|
if (!output_file)
|
||||||
g_printerr ("Error trying to create file %s.\n", outputFilename);
|
g_printerr ("Error trying to create file %s.\n", outputFilename);
|
||||||
@@ -125,16 +125,21 @@ int saveFile (SoupMessage *msg, const gchar *outputFilename) {
|
|||||||
|
|
||||||
int do_client_notify (char *url)
|
int do_client_notify (char *url)
|
||||||
{
|
{
|
||||||
get (g_strdup(url), NULL);
|
get (g_strdup(url), NULL, NULL);
|
||||||
g_print("Offering selected file to other machine.\n");
|
g_print("Offering selected file to other machine.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gchar * getFilePath (const gchar *outputDirectory, const gchar *outputFilename) {
|
||||||
|
return g_strdup_printf("%s%s", outputDirectory,
|
||||||
|
g_uri_escape_string(outputFilename, NULL, TRUE));
|
||||||
|
}
|
||||||
int
|
int
|
||||||
do_downloading (const char *originDevice, const char *url, const char *filename)
|
do_downloading (const char *originDevice, const char *url, const char *filename)
|
||||||
{
|
{
|
||||||
output_direcotry = "./test_download/";
|
gchar *outputDirectory = "./test_download/";
|
||||||
g_print("Downloading %s to %s\n", url, g_uri_escape_string(filename, NULL, TRUE));
|
g_print("Downloading %s to %s\n", url, g_uri_escape_string(filename, NULL, TRUE));
|
||||||
get (g_strdup(url), filename);
|
get (g_strdup(url), outputDirectory, filename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,13 @@ void do_nothing_callback (GSimpleAction *simple,
|
|||||||
void open_file_callback (GSimpleAction *simple,
|
void open_file_callback (GSimpleAction *simple,
|
||||||
GVariant *parameter,
|
GVariant *parameter,
|
||||||
gpointer user_data) {
|
gpointer user_data) {
|
||||||
g_print("Open file\n");
|
g_print("Open file\n %s%s",
|
||||||
|
g_variant_get_string (g_variant_get_child_value (parameter, 3), NULL),
|
||||||
|
g_variant_get_string (g_variant_get_child_value (parameter, 2), NULL));
|
||||||
|
|
||||||
|
g_spawn_command_line_async(g_strdup_printf("xdg-open /home/julian/Projects/teleport/src/%s%s",
|
||||||
|
g_variant_get_string (g_variant_get_child_value (parameter, 3), NULL),
|
||||||
|
g_variant_get_string (g_variant_get_child_value (parameter, 2), NULL)), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_user_notification (const char *file_name, const int file_size, const char *origin_device, GVariant *target) {
|
void create_user_notification (const char *file_name, const int file_size, const char *origin_device, GVariant *target) {
|
||||||
@@ -160,7 +166,7 @@ teleport_app_activate (GApplication *app) {
|
|||||||
|
|
||||||
create_finished_notification ("USER", 2000, "FILENAME", value);
|
create_finished_notification ("USER", 2000, "FILENAME", value);
|
||||||
*/
|
*/
|
||||||
do_downloading("Julian", "https://sparber.net", "juliansfile");
|
do_downloading("Julian", "https://sparber.net", "juliansfile.txt");
|
||||||
|
|
||||||
run_http_server();
|
run_http_server();
|
||||||
run_avahi_publish_service((char *) g_get_host_name());
|
run_avahi_publish_service((char *) g_get_host_name());
|
||||||
|
|||||||
Reference in New Issue
Block a user