File: linux.c

package info (click to toggle)
hivelytracker 0+git20180223-3
  • links: PTS
  • area: main
  • in suites: buster
  • size: 3,092 kB
  • sloc: ansic: 19,601; objc: 434; cpp: 175; makefile: 88
file content (159 lines) | stat: -rw-r--r-- 4,520 bytes parent folder | download | duplicates (2)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>

#include <SDL/SDL.h>
#include "sdl_wrapper.h"

#include <gtk/gtk.h>

typedef Uint32   uint32;
typedef Sint32   int32;
typedef char     TEXT;

int32 gui_req( uint32 img, TEXT *title, TEXT *reqtxt, TEXT *buttons )
{
  GtkWidget *dialog = NULL;
  GtkButtonsType btns = strcmp((char*)buttons, "OK") ? GTK_BUTTONS_OK_CANCEL : GTK_BUTTONS_OK;
  GtkMessageType mtyp = GTK_MESSAGE_INFO;
  SDL_bool result = SDL_FALSE;
  gint res;

  dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, mtyp, btns, "%s", reqtxt);
  gtk_window_set_title(GTK_WINDOW (dialog), title);
  res = gtk_dialog_run(GTK_DIALOG (dialog));
  if ((res == GTK_RESPONSE_OK) || (res == GTK_RESPONSE_YES) || (res == GTK_RESPONSE_ACCEPT))
    result = SDL_TRUE;
  
  gtk_widget_destroy(dialog);
  while (gtk_events_pending())
    gtk_main_iteration();

  return result;
}

BOOL directoryrequester( char *title, char *path )
{
  GtkWidget *dialog;
  GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
  BOOL result = FALSE;

  dialog = gtk_file_chooser_dialog_new(title,
				       NULL,
				       action,
				       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
				       NULL);

  gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);

  if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  {
    char *filename;
    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
    strncpy(path, filename, 512);
    path[511] = 0;
    g_free(filename);
    result = TRUE;
  }
  
  gtk_widget_destroy(dialog);
  while (gtk_events_pending())
    gtk_main_iteration();

  return result;
}


#define FR_HVLSAVE 0
#define FR_AHXSAVE 1
#define FR_INSSAVE 2
#define FR_MODLOAD 3
#define FR_INSLOAD 4

char *filerequester( char *title, char *path, char *fname, int type )
{
  GtkWidget *dialog;
  GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
  GtkFileFilter *filter = NULL, *allfilter = gtk_file_filter_new();
  char *result = NULL;
  char *accept_str = GTK_STOCK_OPEN;

  gtk_file_filter_set_name(allfilter, "All files");
  gtk_file_filter_add_pattern(allfilter, "*");

  switch( type )
  {
    case FR_HVLSAVE:
      action = GTK_FILE_CHOOSER_ACTION_SAVE;
      accept_str = GTK_STOCK_SAVE;
      filter = gtk_file_filter_new();
      gtk_file_filter_set_name(filter, "HVL module (*.hvl)");
      gtk_file_filter_add_pattern(filter, "*.hvl");
      break;
    
    case FR_AHXSAVE:
      action = GTK_FILE_CHOOSER_ACTION_SAVE;
      accept_str = GTK_STOCK_SAVE;
      filter = gtk_file_filter_new();
      gtk_file_filter_set_name(filter, "AHX module (*.ahx)");
      gtk_file_filter_add_pattern(filter, "*.ahx");
      break;

    case FR_INSSAVE:
      action = GTK_FILE_CHOOSER_ACTION_SAVE;
      accept_str = GTK_STOCK_SAVE;
    case FR_INSLOAD:
      filter = gtk_file_filter_new();
      gtk_file_filter_set_name(filter, "Instrument (*.ins)");
      gtk_file_filter_add_pattern(filter, "*.ins");
      break;

    case FR_MODLOAD:
      filter = gtk_file_filter_new();
      gtk_file_filter_set_name(filter, "Modules (*.ahx, *.hvl, *.mod)");
      gtk_file_filter_add_pattern(filter, "*.ahx");
      gtk_file_filter_add_pattern(filter, "*.hvl");
      gtk_file_filter_add_pattern(filter, "*.mod");
      break;

    default:
      break;
  }

  dialog = gtk_file_chooser_dialog_new(title,
				       NULL,
				       action,
				       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				       accept_str, GTK_RESPONSE_ACCEPT,
				       NULL);

  gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
  if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
    gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), fname);

  if (filter)
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
  gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), allfilter);

  if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  {
    char *filename;
    int i;
    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
    result = malloc(strlen(filename)+1);    
    strcpy(result, filename);
    g_free(filename);
  }
  
  gtk_widget_destroy(dialog);
  while (gtk_events_pending())
    gtk_main_iteration();

  return result;
}