14#include <nlohmann/json.hpp>
19#include "style_css.hpp"
48 auto css_provider = Gtk::CssProvider::create();
50 css_provider->load_from_data(css_data);
51 auto display = Gdk::Display::get_default();
52 Gtk::StyleContext::add_provider_for_display(
54 }
catch (
const Glib::FileError &e) {
55 std::cerr <<
"Failed to load CSS data: " << e.what() <<
'\n';
57 std::cerr <<
"Unknown error occurred while loading CSS.\n";
60 set_title(
"GitHub User Fetcher");
61 set_default_size(400, 300);
63 box.set_orientation(Gtk::Orientation::VERTICAL);
66 entry.set_placeholder_text(
"Enter GitHub username...");
69 button.set_label(
"Fetch User");
74 Gtk::PolicyType::AUTOMATIC);
79 text_view.set_wrap_mode(Gtk::WrapMode::WORD);
81 button.signal_clicked().connect(
99 std::string username =
entry.get_text();
100 if (username.empty()) {
105 text_view.get_buffer()->set_text(
"Fetching...");
107 std::thread([
this, username]() {
109 User user = User::fetch_github_user(username);
110 nlohmann::json json = {{
"login", user.
login},
115 std::string result = json.dump(4);
117 Glib::signal_idle().connect_once(
118 [
this, result]() {
text_view.get_buffer()->set_text(result); });
120 }
catch (
const std::exception &e) {
121 std::string error_msg = std::string(
"Error: ") + e.what();
122 Glib::signal_idle().connect_once([
this, error_msg]() {
123 text_view.get_buffer()->set_text(error_msg);
147int main(
int argc,
char *argv[]) {
148 auto app = Gtk::Application::create(
"com.example.githubuserfetcher");
150 app->signal_activate().connect([&]() {
152 app->add_window(window);
156 return app->run(argc, argv);
Main application window for the GitHub user fetcher GUI.
Gtk::TextView text_view
Text view to display results or messages.
Gtk::Box box
Container for layout.
Gtk::Button button
Button to trigger fetch.
void on_button_clicked()
Event handler for the fetch button.
void show_message(const std::string &msg)
Displays a message in the text view area.
Gtk::ScrolledWindow scrolled_window
Scrollable container for text_view.
Gtk::Entry entry
Text field for GitHub username input.
GitHubUserFetcherWindow()
Constructs the main window, sets up widgets and signals.
#define GTK_STYLE_PROVIDER_PRIORITY_USER
Structure representing a GitHub user.
const char * name
Full name.
const char * login
GitHub username.
const char * location
User's location.
const char * company
Company name.