Program creation with GTK +

Thank you! I want to make a program for windows using GTK + that downloads a file from the internet by torrent and put it in a specific folder. Can you help?
Last edited on
If you don't need to do it "by torrent" you might be able to do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// clang++ -std=c++11 -Wall gtk_download.cpp `pkg-config --cflags --libs gtk+-3.0`

#include <iostream>
#include <fstream>
#include <gtk/gtk.h>

void download_file(const char* uri, const char* filename) {
    GFile* gf = g_file_new_for_uri(uri);
    GFileInputStream* gfis = g_file_read(gf, nullptr, nullptr);
    GDataInputStream* gdis = g_data_input_stream_new((GInputStream*)gfis);

    char* data = g_data_input_stream_read_upto(gdis, "", -1, nullptr, nullptr, nullptr);
    if (data) {
        std::ofstream(filename) << data;
        free(data);  // I'm assuming 'data' needs to be freed
    }

    // I'm not sure what all needs to be "unrefed"
    g_object_unref(gdis);
    g_object_unref(gfis);
    g_object_unref(gf);
}

int main() {
    download_file("https://developer.gnome.org/gio/2.62/GFile.html", "local.html");
}

Last edited on
Topic archived. No new replies allowed.