0

I have a problem I need help with. I'm making a C program that will be able to encrypt and decrypt using either DES or RSA. For making a GUI mostly because the lack of a better option, I went with GTK, but I need some guidance on how to store text from an entry on pressing a button.

So if the user types in something to a given entry field and presses "Encrypt", I need to store what he wrote in somehow, as I need to make the actual encryption, but couldn't find a suitable command for this. The only thing I could do was to get it written to the console which is not really helpful, plus I need to get the actual encrypted message back to another Entry.

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

2

the best way to work with an editing widget like gtkTextView and this GtkEntry , use their buffer for getting data from user input and to send data from back end. For GtkEntry , you should use GtkEntryBuffer , there you can find functions to play with text.Whatever you insert in this buffer , will appear on GUI of GtkEntry. Use following functions for getting data and sending , To Get Data --> "gtk_entry_buffer_get_text ()" To Send Data --> "gtk_entry_buffer_set_text ()"

You can Add button labeled as send and add callback function in which you can get the data or send the data to or from GtkEntry.

Also for an encryption you can use input hints in GtkEntry where you can select password mode which help you to hide whatever you write or display in GtkEntry.

M.Shah
  • 111
  • 1
  • 9
  • 1
    Thank you Shah, eventually I got everything to work, althought not exactly how I wanted. Finished college since, and haven't had to use it since that, but thank you for helping nonetheless. – Tamás Lehoczky Jul 12 '17 at 13:51
  • Your welcome and please don't forget to vote @TamásLehoczky – M.Shah Jul 13 '17 at 06:30
0

Easy, I understand that you know how to catch clicked signal for your button, in your callback:
1.- Grab the user input with gtk_label_get_text. Since the function returns a const string, you need to make a copy of it with functions like g_strdup or save it in another buffer to process the encryption.
2.- Encrypt the string.
3.- Send back the encrypted string with gtk_label_set_text

Joel
  • 1,805
  • 1
  • 22
  • 22
  • Thank you for the answer! I'd like to ask a few questions as I started using GTK only the other day, and it's still a bit iffy for me. I have the function `static void enter_callback( GtkWidget *widget, GtkWidget *entry ) { const gchar *entry_text; entry_text = gtk_entry_get_text (GTK_ENTRY (entry)); printf ("Entry contents: %s\n", entry_text); }` that catches the text written into the entry. How can I send it back? Also, from what I understand, I need to make most of the encryption in the functions written by me, and not in the main program. Is this correct? – Tamás Lehoczky Mar 06 '16 at 16:08
  • For sending back, see #3 on my answer. The encryption is done by you or a 3rd library...I'm not sure what do you mean "not in the main program". – Joel Mar 06 '16 at 16:13
  • I meant main function, sorry. Thanks for your help again! – Tamás Lehoczky Mar 06 '16 at 16:16
  • You can write it anywhere of the source code, as long as work as you expected and don't produce segment falls or memory leaks :p, don't forget to accept the awnser, if it solves your main question. – Joel Mar 06 '16 at 16:21
  • Thanks again. I'm not entirely sure how to pass it back, as G_CALLBACK is a bit of a mistery for me still, but I'll try to solve it. – Tamás Lehoczky Mar 06 '16 at 16:26
  • G_CALLBACK tells to g_signal_connect where is the function location of the callback....function. Try to read a good tutorial, I love [ZetCode](http://zetcode.com/gui/gtk2/) – Joel Mar 06 '16 at 16:29