Esempio n. 1
0
void win_chat_set_typing(const gchar *id, gboolean on)
{
	Chat *c;
	GtkWidget *img;
	GdkPixbuf *pb;
	gchar *s;

	c = win_chat_get(id, FALSE, FALSE);
	if (c == NULL)
		return;

	img = lookup_widget(GTK_WIDGET(c->win), "image_typing");
	if (on == TRUE) {
		pb = typing_on_pixbuf;
		s = toutf("Twój rozmówca pisze wiadomo¶æ");
	} else {
		pb = typing_off_pixbuf;
		s = toutf("Je¶li lampka siê zapali oznacza to, ¿e Twój "
			"rozmówca w³a¶nie pisze wiadomo¶æ");
	}

	gtk_image_set_from_pixbuf(GTK_IMAGE(img), pb);
	gtk_widget_queue_draw(img);

	img = lookup_widget(GTK_WIDGET(c->win), "eventbox_typing");

	gtk_tooltips_set_tip(tooltips, img, s, NULL);
	g_free(s);
}
Esempio n. 2
0
void
removeall(char *p)
{
	WinRune *r, *r1;
	DWORD attr;
	char *q, *qt, *elem;
	HANDLE h;
	WIN32_FIND_DATAW data;
	
	r = torune(p);
	attr = GetFileAttributesW(r);
	if(attr == INVALID_FILE_ATTRIBUTES || !(attr & FILE_ATTRIBUTE_DIRECTORY)) {
		DeleteFileW(r);
		free(r);
		return;
	}

	q = smprint("%s\\*", p);
	r1 = torune(q);
	free(q);
	h = FindFirstFileW(r1, &data);
	if(h == INVALID_HANDLE_VALUE)
		goto done;
	do{
		q = toutf(data.cFileName);
		elem = strrchr(q, '\\');
		if(elem != nil)
			elem++;
		else
			elem = q;
		if(strcmp(elem, ".") == 0 || strcmp(elem, "..") == 0) {
			free(q);
			continue;
		}
		qt = smprint("%s\\%s", p, q);
		free(q);
		removeall(qt);
		free(qt);
	}while(FindNextFileW(h, &data));
	FindClose(h);

done:
	free(r1);
	RemoveDirectoryW(r);
	free(r);
}
Esempio n. 3
0
char*
mktempdir(void)
{
	WinRune buf[1024];
	WinRune tmp[MAX_PATH];
	WinRune golink[] = {'g', 'o', 'l', 'i', 'n', 'k', '\0'};
	int n;
	
	n = GetTempPathW(nelem(buf), buf);
	if(n <= 0)
		return nil;
	buf[n] = '\0';
	
	if(GetTempFileNameW(buf, golink, 0, tmp) == 0)
		return nil;
	DeleteFileW(tmp);
	if(!CreateDirectoryW(tmp, nil))
		return nil;
	
	return toutf(tmp);
}
Esempio n. 4
0
void win_desc_show()
{
	GtkWidget *b;
	GdkPixbuf *pb;
	guint status = o2_get_status();
	gchar *desc;

	if(win_desc != NULL)
		gtk_widget_show_all(win_desc);

	win_desc = create_win_desc();
	gtk_widget_show_all(win_desc);

	pb = gtk_image_get_pixbuf(GTK_IMAGE(get_status_icon(o2_get_status())));
	gtk_window_set_icon(GTK_WINDOW(win_desc), pb);

	b = lookup_widget(win_desc, "radio_avail");
	g_signal_connect(G_OBJECT(b), "toggled",
		G_CALLBACK(radio_clicked_cb), "1");
	if(status == TLEN_PRESENCE_AVAILABLE)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), TRUE);

	b = lookup_widget(win_desc, "radio_chatty");
	g_signal_connect(G_OBJECT(b), "toggled",
		G_CALLBACK(radio_clicked_cb), "2");
	if(status == TLEN_PRESENCE_CHATTY)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), TRUE);

	b = lookup_widget(win_desc, "radio_dnd");
	g_signal_connect(G_OBJECT(b), "toggled",
		G_CALLBACK(radio_clicked_cb), "3");
	if(status == TLEN_PRESENCE_DND)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), TRUE);

	b = lookup_widget(win_desc, "radio_away");
	g_signal_connect(G_OBJECT(b), "toggled",
		G_CALLBACK(radio_clicked_cb), "4");
	if(status == TLEN_PRESENCE_AWAY)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), TRUE);

	b = lookup_widget(win_desc, "radio_bbl");
	g_signal_connect(G_OBJECT(b), "toggled",
		G_CALLBACK(radio_clicked_cb), "5");
	if(status == TLEN_PRESENCE_EXT_AWAY)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), TRUE);

	b = lookup_widget(win_desc, "radio_invisible");
	g_signal_connect(G_OBJECT(b), "toggled",
		G_CALLBACK(radio_clicked_cb), "6");
	if(status == TLEN_PRESENCE_INVISIBLE)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), TRUE);

	b = lookup_widget(win_desc, "radio_unavail");
	g_signal_connect(G_OBJECT(b), "toggled",
		G_CALLBACK(radio_clicked_cb), "7");
	if(status == TLEN_PRESENCE_UNAVAILABLE)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b), TRUE);

	b = lookup_widget(win_desc, "image_status");

	gtk_image_set_from_pixbuf(GTK_IMAGE(b), pb);
	gtk_widget_queue_draw(b);

	b = lookup_widget(win_desc, "entry_desc");
	desc = toutf(o2_get_desc());
	if(desc != NULL) {
		gtk_entry_set_text(GTK_ENTRY(b), desc);
	}
	g_free(desc);
	gtk_widget_grab_focus(b);

	b = lookup_widget(win_desc, "btn_ustaw");
	g_signal_connect(G_OBJECT(b), "clicked",
		G_CALLBACK(accept_clicked_cb), NULL);

	b = lookup_widget(win_desc, "btn_anuluj");
	g_signal_connect(G_OBJECT(b), "clicked",
		G_CALLBACK(cancel_clicked_cb), NULL);

	g_signal_connect(G_OBJECT(win_desc), "delete_event",
		G_CALLBACK(cancel_clicked_cb), NULL);
}
Esempio n. 5
0
Chat * win_chat_create(const gchar *id)
{
	GtkWidget *scroll;
	Chat *c;
	GtkWidget *b;
	gchar *s;
	
	c = (Chat *)g_malloc(sizeof(Chat));
	c->id = g_strdup(id);
	c->enter_sends = pref_chat_enter_sends;
	
	c->blink_state = BlinkOff;
	c->need_blinking = FALSE;

	c->notify_sent = FALSE;

	c->user = user_get(id);

	c->win = GTK_WINDOW(create_win_chat());
	g_assert(c->win != NULL);
	
	scroll = lookup_widget(GTK_WIDGET(c->win), "scroll_output");
	g_assert(scroll != NULL);
	c->input = GTK_TEXT_VIEW(lookup_widget(GTK_WIDGET(c->win), "input"));
	g_assert(c->input != NULL);

	c->output = GTK_HTML(glen_html_new());
	g_assert(c->output != NULL);
	gtk_widget_set_name(GTK_WIDGET(c->output), "output");
	
	gtk_widget_set(GTK_WIDGET(c->output), "can-focus", FALSE, NULL);

	gtk_container_add(GTK_CONTAINER(scroll), GTK_WIDGET(c->output));

	gtk_widget_show(GTK_WIDGET(c->output));

	c->stream = glen_html_begin(c->output);
//	gtk_html_write(c->output, c->stream, header, strlen(header));

/* ustaw pixbuf dla 'lampki' */
	b = lookup_widget(GTK_WIDGET(c->win), "image_typing");
	g_assert(b != NULL);
	gtk_image_set_from_pixbuf(GTK_IMAGE(b), typing_off_pixbuf);

/* callbacki do przyciskow */
	b = lookup_widget(GTK_WIDGET(c->win), "clear_btn");
	g_assert(b != NULL);
	g_signal_connect(G_OBJECT(b), "clicked",
		G_CALLBACK(clear_btn_clicked_cb), (gpointer)c);

	b = lookup_widget(GTK_WIDGET(c->win), "send_btn");
	g_assert(b != NULL);
	g_signal_connect(G_OBJECT(b), "clicked",
		G_CALLBACK(send_btn_clicked_cb), (gpointer)c);

	b = lookup_widget(GTK_WIDGET(c->win), "close_btn");
	g_assert(b != NULL);
	g_signal_connect(G_OBJECT(b), "clicked",
		G_CALLBACK(close_btn_clicked_cb), (gpointer)c);

	b = lookup_widget(GTK_WIDGET(c->win), "enter_sends_btn");
	g_assert(b != NULL);
	g_signal_connect(G_OBJECT(b), "toggled",
		G_CALLBACK(enter_sends_btn_cb), (gpointer)c);
	
/* reszta */
	b = lookup_widget(GTK_WIDGET(c->win), "input");
	g_assert(b != NULL);
	g_signal_connect(G_OBJECT(b), "key_press_event",
		G_CALLBACK(input_key_press_cb), (gpointer)c);
	g_signal_connect(G_OBJECT(b), "copy_clipboard",
		G_CALLBACK(input_copy_clipboard_cb), (gpointer)c);
	
	gtk_widget_grab_focus(b);

	g_signal_connect(G_OBJECT(c->win), "delete_event",
		G_CALLBACK(delete_win_cb), c);
//	g_signal_connect(G_OBJECT(c->win), "window_state_event",
//		G_CALLBACK(window_state_cb), c);
	g_signal_connect_after(G_OBJECT(c->win), "visibility_notify_event",
		G_CALLBACK(visibility_changed_cb), c);
	g_signal_connect(G_OBJECT(c->win), "focus_in_event",
		G_CALLBACK(focus_in_cb), c);

	/* ustaw tooltip dla 'lampki */
	b = lookup_widget(GTK_WIDGET(c->win), "eventbox_typing");
	g_assert(b != NULL);
	s = toutf("Je¶li lampka zapali siê oznacza to, ¿e Twój "
		"rozmówca w³a¶nie pisze wiadomo¶æ");
	gtk_tooltips_set_tip(tooltips, b, s, NULL);
	g_free(s);
	
	return c;
}
Esempio n. 6
0
static void create_menu()
{
	GtkWidget *i;
	gchar *s;

	menu = GTK_MENU(gtk_menu_new());
	g_assert(menu != NULL);

	s = toutf("_Dostêpny");
	i = gtk_image_menu_item_new_with_mnemonic(s);
	g_free(s);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), i);
	g_signal_connect_swapped(G_OBJECT(i), "activate",
		G_CALLBACK(menu_item_cb), "1");
	gtk_widget_show(i);
	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(i),
		get_status_icon_new(TLEN_PRESENCE_AVAILABLE));
	
	s = toutf("_Porozmawiajmy");
	i = gtk_image_menu_item_new_with_mnemonic(s);
	g_free(s);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), i);
	g_signal_connect_swapped(G_OBJECT(i), "activate",
		G_CALLBACK(menu_item_cb), "2");
	gtk_widget_show(i);
	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(i),
		get_status_icon_new(TLEN_PRESENCE_CHATTY));

	s = toutf("_Jestem zajêty");
	i = gtk_image_menu_item_new_with_mnemonic(s);
	g_free(s);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), i);
	g_signal_connect_swapped(G_OBJECT(i), "activate",
		G_CALLBACK(menu_item_cb), "3");
	gtk_widget_show(i);
	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(i),
		get_status_icon_new(TLEN_PRESENCE_DND));

	s = toutf("_Zaraz wracam");
	i = gtk_image_menu_item_new_with_mnemonic(s);
	g_free(s);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), i);
	g_signal_connect_swapped(G_OBJECT(i), "activate",
		G_CALLBACK(menu_item_cb), "4");
	gtk_widget_show(i);
	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(i),
		get_status_icon_new(TLEN_PRESENCE_AWAY));

	s = toutf("_Wrócê pó¼niej");
	i = gtk_image_menu_item_new_with_mnemonic(s);
	g_free(s);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), i);
	g_signal_connect_swapped(G_OBJECT(i), "activate",
		G_CALLBACK(menu_item_cb), "5");
	gtk_widget_show(i);
	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(i),
		get_status_icon_new(TLEN_PRESENCE_EXT_AWAY));

	s = toutf("_Niewidoczny");
	i = gtk_image_menu_item_new_with_mnemonic(s);
	g_free(s);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), i);
	g_signal_connect_swapped(G_OBJECT(i), "activate",
		G_CALLBACK(menu_item_cb), "6");
	gtk_widget_show(i);
	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(i),
		get_status_icon_new(TLEN_PRESENCE_INVISIBLE));

	s = toutf("Niedostêpn_y");
	i = gtk_image_menu_item_new_with_mnemonic(s);
	g_free(s);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), i);
	g_signal_connect_swapped(G_OBJECT(i), "activate",
		G_CALLBACK(menu_item_cb), "7");
	gtk_widget_show(i);
	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(i),
		get_status_icon_new(TLEN_PRESENCE_UNAVAILABLE));

	/* separator */
	i = gtk_menu_item_new();
	gtk_container_add(GTK_CONTAINER(menu), i);
	gtk_widget_set_sensitive(i, FALSE);
	gtk_widget_show(i);

	s = toutf("_Ustaw stan opisowy");
	i = gtk_menu_item_new_with_mnemonic(s);
	g_free(s);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), i);
	g_signal_connect_swapped(G_OBJECT(i), "activate",
		G_CALLBACK(menu_item_cb), "8");
	gtk_widget_show(i);
	
	/* separator */
	i = gtk_menu_item_new();
	gtk_container_add(GTK_CONTAINER(menu), i);
	gtk_widget_set_sensitive(i, FALSE);
	gtk_widget_show(i);
	
	s = toutf("_Koniec");
	i = gtk_menu_item_new_with_mnemonic(s);
	g_free(s);
	gtk_menu_shell_append(GTK_MENU_SHELL(menu), i);
	g_signal_connect_swapped(G_OBJECT(i), "activate",
		G_CALLBACK(menu_item_cb), "9");
	gtk_widget_show(i);
}
////////////////////////////////////////////////////////////////////////////////
// correct_reads
//
// Correct the reads in the file 'fqf' using the data structure of trusted
// kmers 'trusted', matrix of nt->nt error rates 'ntnt_prob' and prior nt
// probabilities 'prior_prob'.  'starts' and 'counts' help openMP parallelize
// the read processing.  If 'pairedend_code' is 0, the reads are not paired;
// if it's 1, this file is the first of a pair so print all reads and withold
// combining; if it's 2, the file is the second of a pair so print all reads
// and then combine both 1 and 2.
////////////////////////////////////////////////////////////////////////////////
static void correct_reads(string fqf, int pe_code, bithash * trusted, vector<streampos> & starts, vector<unsigned long long> & counts, double ntnt_prob[Read::max_qual][4][4], double prior_prob[4]) {
  // output directory
  struct stat st_file_info;
  string path_suffix = split(fqf,'/').back();
  string out_dir("."+path_suffix);
  if(stat(out_dir.c_str(), &st_file_info) == 0) {
    cerr << "Hidden temporary directory " << out_dir << " already exists and will be used" << endl;
  } else {
    if(mkdir(out_dir.c_str(), S_IRWXU) == -1) {
      cerr << "Failed to create hidden temporary directory " << out_dir << endl;
      exit(EXIT_FAILURE);
    }
  }

  // collect stats
  stats * thread_stats = new stats[omp_get_max_threads()];

  unsigned int chunk = 0;
#pragma omp parallel //shared(trusted)
  {
    int tid = omp_get_thread_num();
    
    // input
    ifstream reads_in(fqf.c_str());
    
    unsigned int tchunk;
    string header,ntseq,mid,strqual,corseq;
    int trim_length;
    char* nti;
    Read *r;

    #pragma omp critical
    tchunk = chunk++;

    while(tchunk < starts.size()) {
      reads_in.seekg(starts[tchunk]);

      // output
      string toutf(out_dir+"/");
      stringstream tconvert;
      tconvert << tchunk;
      toutf += tconvert.str();

      if(overwrite_temp || stat(toutf.c_str(), &st_file_info) == -1) {
	ofstream reads_out(toutf.c_str());
	//cout << toutf << endl;

	// output log
	string tlogf = toutf + ".log";
	ofstream corlog_out;
	if(out_log) {
	  corlog_out.open(tlogf.c_str());
	}

	unsigned long long tcount = 0;
	while(getline(reads_in, header)) {
	  //cout << tid << " " << header << endl;
	
	  // get sequence
	  getline(reads_in, ntseq);
	  //cout << ntseq << endl;
	
	  // convert ntseq to iseq
	  vector<unsigned int> iseq;
	  for(int i = 0; i < ntseq.size(); i++) {
	    nti = strchr(nts, ntseq[i]);	
	    iseq.push_back(nti - nts);
	  }

	  // get quality values
	  getline(reads_in,mid);
	  //cout << mid << endl;
	  getline(reads_in,strqual);
	  //cout << strqual << endl;

	  vector<int> untrusted;

	  if(iseq.size() < trim_t)
	    trim_length = 0;
	  else {
	    for(int i = 0; i < iseq.size()-k+1; i++) {
	      if(!trusted->check(&iseq[i])) {
		untrusted.push_back(i);
	      }
	    }

	    trim_length = quick_trim(strqual, untrusted);
	    //trim_length = iseq.size();
	  }

	  // fix error reads
	  if(untrusted.size() > 0) {
	    r = new Read(header, &iseq[0], strqual, untrusted, trim_length);
	    corseq = r->correct(trusted, ntnt_prob, prior_prob);

	    // output read w/ trim and corrections
	    output_read(reads_out, corlog_out, pe_code, header, ntseq, mid, strqual, corseq, thread_stats[tid]);
	  
	    delete r;
	  } else {
	    output_read(reads_out, corlog_out, pe_code, header, ntseq, mid, strqual, ntseq.substr(0,trim_length), thread_stats[tid]);
	    // output read as trimmed
	    /*
	      if(contrail_out)
	      reads_out << header << "\t" << ntseq.substr(0,trim_length) << endl;
	      else
	      reads_out << header << endl << ntseq.substr(0,trim_length) << endl << mid << endl << strqual.substr(0,trim_length) << endl;
	    */
	  }
	
	  if(++tcount == counts[tchunk])
	    break;
	}
	reads_out.close();
      }

#pragma omp critical
      tchunk = chunk++;
    }
    reads_in.close();
  }

  // combine stats
  for(int i = 1; i < omp_get_max_threads(); i++) {
    thread_stats[0].validated += thread_stats[i].validated;
    thread_stats[0].corrected += thread_stats[i].corrected;
    thread_stats[0].trimmed += thread_stats[i].trimmed;
    thread_stats[0].trimmed_only += thread_stats[i].trimmed_only;
    thread_stats[0].removed += thread_stats[i].removed;
  }

  // print stats
  int suffix_index = fqf.rfind(".");
  string outf;
  if(suffix_index == -1) {
    outf = fqf+".stats.txt";
  } else {
    outf = fqf.substr(0,suffix_index+1) + "stats.txt";
  }
  ofstream stats_out(outf.c_str());
  stats_out << "Validated: " << thread_stats[0].validated << endl;
  stats_out << "Corrected: " << thread_stats[0].corrected << endl;
  stats_out << "Trimmed: " << thread_stats[0].trimmed << endl;
  stats_out << "Trimmed only: " << thread_stats[0].trimmed_only << endl;
  stats_out << "Removed: " << thread_stats[0].removed << endl;
  stats_out.close();
}