GtkWidget* avator_frame_new()In addition, There are "avatar.jpg" and "db.txt", and they are needed to demonstrate feedback form in action. The following is the contain of db.txt:
GtkWidget* oneFeedback(char* vote, char* feed)
char *truncate(size_t start, size_t stop, const char *input, char *output, size_t size)
GtkWidget* feedback_entry_new()
GtkWidget* ffgenerater(GtkWidget *button, gpointer data)
[A]:<8>:{A would be great, if it can do this.}
[B]:<8>:{B would be great, if it can do this.}
[B]:<7>:{B would be great, if it can do that.}
[A]:<7>:{A would be great, if it can do that.}
[A]:<4>:{Instead of doing that, you can do this.}
Each line in db.txt represent one feedback from one user, and the following is the description of each line in db.txt:
[function-in-Sample]::{feedback-from-user-about-function}
To demonstrate how feedbackform.h works, there is a sample.c file which represents a generic application which needs user feedback for its functionality. To call methods inside freedbackform.h, the sample.h must includes feedbackform.h as a library. After that, the sample.c can call the ffgenerater method within its body. Whenever the ffgenerater method is called within the sample.h, it generates the complete feedback form. The following is the contain of the ffgenerater method:
GtkWidget* ffgenerater(GtkWidget *button, gpointer data)
{
g_print("The current function for feedback: %s\n", (char *) data);
GtkWidget *window;
GtkWidget *vbox0, *vbox, *hbox;
GtkWidget *frame;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Feedback");
gtk_window_set_default_size(GTK_WINDOW(window), 500, 500);
vbox0 = gtk_vbox_new(FALSE, 0);
vbox = gtk_vbox_new(FALSE, 0);
frame = gtk_frame_new("Feedback from others...");
gtk_container_add(GTK_CONTAINER(window), vbox0);
gtk_box_pack_start(GTK_BOX(vbox0),avator_frame_new(), TRUE, TRUE, 10);
gtk_box_pack_start(GTK_BOX(vbox0),frame, TRUE, TRUE, 5);
gtk_box_pack_start(GTK_BOX(vbox0),feedback_entry_new(), TRUE, TRUE, 10);
gtk_container_add(GTK_CONTAINER(frame), vbox);
FILE *file=fopen("db.txt","r");
char tmp[256]={0x0};
while(file!=NULL && fgets(tmp, sizeof(tmp),file)!=NULL)
{
if (strstr(tmp, (char *) data))
{
char vote[10], feedback[40];
gtk_box_pack_start(GTK_BOX(vbox), oneFeedback(truncate(strrchr(tmp,'<')-tmp+1,strrchr(tmp,'>')-tmp,tmp,vote,sizeof vote), truncate(strrchr(tmp,'{')-tmp+1,strrchr(tmp,'}')-tmp,tmp,feedback,sizeof feedback)), TRUE, TRUE, 5);
}
}
if(file!=NULL) fclose(file);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
The feedback form interface is consisting 3 portion: Introduction, Feedback Form others (users), and New Feedback Entry. The Introduction portion is generated by the avator_frame_new method. The following is the contain of the avator_frame_new method:
GtkWidget* avator_frame_new()
{
GtkWidget *frame, *hbox, *image, *message;
image = gtk_image_new_from_file("avatar.jpg");
message = gtk_label_new ("Hi! I'm hoping that with your help\n we can improve this program.");
frame = gtk_frame_new("Introduction");
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER(frame), hbox);
gtk_box_pack_start(GTK_BOX(hbox), image, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), message, TRUE, TRUE, 0);
return frame;
}
The avator_frame_new method imports "avatar.jpg" and shows a short message from the developer. This method is called by the ffgenerater method.
The Feedback From Other portion is generated by the main body of the ffgenerater method with support of the truncate method and the oneFeedback method. The db.txt is read to retrieve feedbacks from other users to disply in the FeedBack From Other portion.
The following is body of oneFeedback method:
GtkWidget* oneFeedback(char* vote, char* feed)
{
GtkWidget *frame, *hbox;
GtkWidget *gtkVote, *gtkFeed;
GtkWidget *vote_button;
strcat(vote, " people like it. \nCLICK TO VOTE!!");
vote_button = gtk_button_new_with_label(vote);
frame = gtk_frame_new("");
hbox = gtk_hbox_new (FALSE, 0);
gtkVote = gtk_label_new (vote);
gtkFeed = gtk_label_new (feed);
gtk_container_add (GTK_CONTAINER(frame), hbox);
gtk_box_pack_start(GTK_BOX(hbox), vote_button, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), gtkFeed, TRUE, TRUE, 0);
return frame;
}
And the following is the body of the truncate method:
char *truncate(size_t start, size_t stop, const char *input, char *output, size_t size)
{
int count = stop - start;
if (count >= --size)
count = size;
sprintf(output, "%.*s", count, input + start);
return output;
}
The New Feedback Entry portion is generated by feedback_entry_new method. The feedback_entry_new method displays a list of feedback question and provide textfields for feedback input. This method is called by the ffgenerater method, and the following is the contain of the feedback_entry_new method:
GtkWidget* feedback_entry_new()
{
GtkWidget *frame;
GtkWidget *vbox;
GtkWidget *label1, *label2, *label3, *label4, *entry1, *entry2, *entry3, *entry4;
GtkWidget *submit_button;
label1 = gtk_label_new ("I would appreciate you including your email address\n so I can contact you for further assisstance. (optional)");
label2 = gtk_label_new ("Please describe how this function helped or hindered\n the completion of your task?");
label3 = gtk_label_new ("Did this function do what you expected?");
label4 = gtk_label_new ("Can you tell us what enhanced your experience or feel\n needs to be improved.");
// Create the entry widgets for 4 feedback questions
entry1 = gtk_entry_new();
entry2 = gtk_entry_new();
entry3 = gtk_entry_new();
entry4 = gtk_entry_new();
// Create submit button
submit_button = gtk_button_new();
submit_button = gtk_button_new_with_label("Submit feedback!");
g_signal_connect(GTK_OBJECT(submit_button), "clicked", G_CALLBACK(gtk_main_quit), NULL);
frame = gtk_frame_new("New feedback entry");
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER(frame), vbox);
gtk_box_pack_start(GTK_BOX(vbox), label1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), entry1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), label2, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), entry2, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), label3, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), entry3, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), label4, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), entry4, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), submit_button, TRUE, TRUE, 0);
return frame;
}
This feedback form application (feedbackform.h) is written in C with GTK library. Since GTK is licensed under GNU Lesser General Public License and this application is written using GTK, this application is considered to be FOSS. Any developer is welcome to modify its source code or to implement it into her own program.