/*
     This file is part of anastasis-gtk.
     Copyright (C) 2020-2021 Anastasis SARL

     Anastasis is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     Anastasis is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with Anastasis; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     Boston, MA 02110-1301, USA.
*/

/**
 * @file src/include/anastasis-gtk_helper.h
 * @brief Definition of helpers.
 * @author Christian Grothoff
 * @author Dennis Neufeld
 */
#ifndef ANASTASIS_GTK_HELPER_H
#define ANASTASIS_GTK_HELPER_H
#include <gtk/gtk.h>
#include <anastasis/anastasis_service.h>
#include <anastasis/anastasis_redux.h>
#include "anastasis-gtk.h"
#include <gdk-pixbuf/gdk-pixbuf.h>


/**
 * true if we are currently showing an error message.
 */
extern bool AG_have_error;


/**
 * Hide widget of the given @a name of the main window
 *
 * @param name widget to hide
 */
void
AG_hide (const char *name);


/**
 * Show widget of the given @a name of the main window
 *
 * @param name widget to show
 */
void
AG_show (const char *name);


/**
 * Make widget of the given @a name of the main window insensitive.
 *
 * @param name widget to make insensitive
 */
void
AG_insensitive (const char *name);


/**
 * Make widget of the given @a name of the main window sensitive.
 *
 * @param name widget to make sensitive
 */
void
AG_sensitive (const char *name);


/**
 * Make the 'next' button sensitive (and trigger it via 'Return').
 */
void
AG_enable_next (void);


/**
 * Make widget of the given @a name the focus.
 *
 * @param name widget to focus
 */
void
AG_focus (const char *name);


/**
 * Thaw the user interface.
 */
void
AG_thaw (void);


/**
 * Freeze the user interface while the action completes.
 */
void
AG_freeze (void);


/**
 * Hide all of the children of the container widget @a name in the main window.
 *
 * @param name name of the object
 */
void
AG_hide_children (const char *name);


/**
 * Make all of the children of the container widget @a name in the main window
 * insensitive.
 *
 * @param name name of the object
 */
void
AG_insensitive_children (const char *name);


/**
 * Show all of the children of the container widget @a name in the main window.
 *
 * @param name name of the object
 */
void
AG_show_children (const char *name);


/**
 * Get an object from the main window.
 *
 * @param name name of the object
 * @return NULL on error
 */
GObject *
GCG_get_main_window_object (const char *name);


/**
 * Checks the actual state. True, if state is correct, else false.
 *
 * @param state the state to check
 * @param expected_state the expected state as string
 * @return bool
 */
bool
AG_check_state (json_t *state,
                const char *expected_state);


/**
 * Hides all frames;
 */
void
AG_hide_all_frames (void);


/**
 * Show error message.
 *
 * @param format format string
 * @param ... arguments for format string
 */
void
AG_error (const char *format,
          ...)
__attribute__ ((format (printf, 1, 2)));


/**
 * Stop showing error message.
 */
void
AG_error_clear (void);


/**
 * Setup QR code image for a widget @a w.
 *
 * @param w widget to use to determine screen resolution
 * @param text text to encode
 * @param text_size number of bytes in @a text
 * @return NULL on failure
 */
GdkPixbuf *
AG_setup_qrcode (GtkWidget *w,
                 const char *text,
                 size_t text_size);


/**
 * Display @a pb in the GtkImage @a img.  GTK4 images render paintables,
 * so the pixbuf is wrapped in a texture first.
 *
 * @param img image widget to update
 * @param pb pixbuf to show
 */
void
AG_image_set_from_pixbuf (GtkImage *img,
                          GdkPixbuf *pb);


/**
 * Expand base @a name of a widget based on the @a type to
 * create the name of the widget with the data.
 *
 * @param name base name of the widget
 * @param type type of the widget
 * @return NULL on error
 */
char *
AG_expand_name (const char *name,
                const char *type);


#endif
