Exemplo n.º 1
0
/* Helper function to be used with a foreach statement of the model. Checks
 * if a node is checked, and adds it to a list if it is. data us a (GSList**)
 * where the result it to be stored */
static gboolean foldercheck_foreach_update_to_list(GtkTreeModel *model,
						   GtkTreePath *path,
						   GtkTreeIter *iter,
						   gpointer data)
{
  gchar *ident_tree, *ident_list;
  FolderItem *item;
  GSList *walk;
  gboolean toggle_item = FALSE;
  SpecificFolderArrayEntry *entry = (SpecificFolderArrayEntry*) data;

  gtk_tree_model_get(model, iter, FOLDERCHECK_FOLDERITEM, &item, -1);

  if(item->path != NULL)
    ident_tree = folder_item_get_identifier(item);
  else
    return FALSE;

  for(walk = entry->list; walk != NULL; walk = g_slist_next(walk)) {
    FolderItem *list_item = (FolderItem*) walk->data;
    ident_list = folder_item_get_identifier(list_item);
    if(!strcmp2(ident_list,ident_tree)) {
      toggle_item = TRUE;
      g_free(ident_list);
      break;
    }
    g_free(ident_list);
  }
  g_free(ident_tree);

  gtk_tree_store_set(entry->tree_store, iter, FOLDERCHECK_CHECK,
		     toggle_item, -1);

  return FALSE;
}
Exemplo n.º 2
0
static gboolean foldersel_selected(GtkTreeSelection *selection,
				   GtkTreeModel *model, GtkTreePath *path,
				   gboolean currently_selected, gpointer data)
{
	GtkTreeIter iter;
	FolderItem *item = NULL;

	if (currently_selected)
		return TRUE;

	if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path))
		return TRUE;

	gtk_tree_model_get(GTK_TREE_MODEL(tree_store), &iter,
			   FOLDERSEL_FOLDERITEM, &item, -1);

	selected_item = item;
	if (selected_item && selected_item->path) {
		gchar *id;
		id = folder_item_get_identifier(selected_item);
		gtk_entry_set_text(GTK_ENTRY(entry), id);
		g_free(id);
	} else
	if (root_selectable && selected_item && selected_item->folder &&
			(FOLDER_TYPE(selected_item->folder) == F_MH ||
			 FOLDER_TYPE(selected_item->folder) == F_MBOX ||
			 FOLDER_TYPE(selected_item->folder) == F_IMAP)) {
		gchar *id = folder_get_identifier(selected_item->folder);
		gtk_entry_set_text(GTK_ENTRY(entry), id);
		g_free(id);
	} else
		gtk_entry_set_text(GTK_ENTRY(entry), "");

	return TRUE;
}
Exemplo n.º 3
0
static void import_destsel_cb(GtkWidget *widget, gpointer data)
{
	FolderItem *dest;
	gchar *path;

	dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE,
			_("Select folder to import to"));
	if (!dest)
		 return;
	path = folder_item_get_identifier(dest);
	gtk_entry_set_text(GTK_ENTRY(dest_entry), path);
	g_free(path);
}
Exemplo n.º 4
0
static void foldersel_cb(GtkWidget *widget, gpointer data)
{
	GtkWidget *entry = (GtkWidget *) data;
	FolderItem *item;
	gchar *item_id;
	gint newpos = 0;
	
	item = foldersel_folder_sel(NULL, FOLDER_SEL_MOVE, NULL, FALSE);
	if (item && (item_id = folder_item_get_identifier(item)) != NULL) {
		gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
		gtk_editable_insert_text(GTK_EDITABLE(entry), item_id, strlen(item_id), &newpos);
		g_free(item_id);
	}
}
Exemplo n.º 5
0
static void unsubscribe_newsgroup_cb(GtkAction *action, gpointer data)
{
	FolderView *folderview = (FolderView *)data;
	FolderItem *item;
	gchar *name;
	gchar *message;
	gchar *old_id;
	AlertValue avalue;
	MainWindow *mainwin = mainwindow_get_mainwindow();
	
	if (!folderview->selected) return;

	item = folderview_get_selected_item(folderview);
	cm_return_if_fail(item != NULL);

	if (mainwin->lock_count || news_folder_locked(item->folder))
		return;

	cm_return_if_fail(item->folder != NULL);
	cm_return_if_fail(FOLDER_TYPE(item->folder) == F_NEWS);
	cm_return_if_fail(item->folder->account != NULL);

	old_id = folder_item_get_identifier(item);

	name = trim_string(item->path, 32);
	message = g_strdup_printf(_("Really unsubscribe newsgroup '%s'?"), name);
	avalue = alertpanel_full(_("Unsubscribe newsgroup"), message,
		 	         GTK_STOCK_CANCEL, _("_Unsubscribe"), NULL,
							 ALERTFOCUS_FIRST, FALSE, NULL, ALERT_WARNING);
	g_free(message);
	g_free(name);
	if (avalue != G_ALERTALTERNATE) return;

	if (item == folderview_get_opened_item(folderview)) {
		summary_clear_all(folderview->summaryview);
		folderview_close_opened(folderview, TRUE);
	}

	if(item->folder->klass->remove_folder(item->folder, item) < 0) {
		folder_item_scan(item);
		alertpanel_error(_("Can't remove the folder '%s'."), name);
		g_free(old_id);
		return;
	}
	
	folder_write_list();
	
	prefs_filtering_delete_path(old_id);
	g_free(old_id);
}
Exemplo n.º 6
0
void folder_item_prefs_save_config(FolderItem * item)
{	
	gchar * id;

	tmp_prefs = * item->prefs;

	id = folder_item_get_identifier(item);
	if (id == NULL)
		return;

	debug_print("saving prefs for %s\n", id);
	prefs_write_config(param, id, FOLDERITEM_RC);
	g_free(id);
}
Exemplo n.º 7
0
void folder_item_prefs_read_config(FolderItem * item)
{
	gchar * id;
	gchar *rcpath;

	id = folder_item_get_identifier(item);
	folder_item_prefs_clear(&tmp_prefs);
	rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, FOLDERITEM_RC, NULL);
	prefs_read_config(param, id, rcpath, NULL);
	g_free(id);
	g_free(rcpath);

	*item->prefs = tmp_prefs;
}
Exemplo n.º 8
0
static PyObject* ComposeWindow_save_message_to(clawsmail_ComposeWindowObject *self, PyObject *args)
{
  PyObject *arg;

  if(!PyArg_ParseTuple(args, "O", &arg))
    return NULL;

  if(PyString_Check(arg)) {
    GtkEditable *editable;
    gint pos;

    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->compose->savemsg_checkbtn), TRUE);

    editable = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(self->compose->savemsg_combo)));
    gtk_editable_delete_text(editable, 0, -1);
    gtk_editable_insert_text(editable, PyString_AsString(arg), -1, &pos);
  }
  else if(clawsmail_folder_check(arg)) {
    GtkEditable *editable;
    gint pos;

    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->compose->savemsg_checkbtn), TRUE);

    editable = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(self->compose->savemsg_combo)));
    gtk_editable_delete_text(editable, 0, -1);
    gtk_editable_insert_text(editable, folder_item_get_identifier(clawsmail_folder_get_item(arg)), -1, &pos);
  }
  else if (arg == Py_None){
    /* turn off checkbutton */
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self->compose->savemsg_checkbtn), FALSE);
  }
  else {
    PyErr_SetString(PyExc_TypeError, "function takes exactly one argument which may be a folder object, a string, or None");
    return NULL;
  }

  flush_gtk_queue();

  Py_INCREF(Py_None);
  return Py_None;
}
Exemplo n.º 9
0
gint import_mbox(FolderItem *default_dest)
/* return values: -2 skipped/cancelled, -1 error, 0 OK */
{
	gchar *dest_id = NULL;

	import_ok = -2;	// skipped or cancelled

	if (!window) {
		import_create();
	}
	else {
		gtk_widget_show(window);
	}

	gtk_window_set_modal(GTK_WINDOW(window), TRUE);
	change_dir(claws_get_startup_dir());

	if (default_dest && default_dest->path) {
		dest_id = folder_item_get_identifier(default_dest);
	}

	if (dest_id) {
		gtk_entry_set_text(GTK_ENTRY(dest_entry), dest_id);
		g_free(dest_id);
	} else {
		gtk_entry_set_text(GTK_ENTRY(dest_entry), "");
	}
	gtk_entry_set_text(GTK_ENTRY(file_entry), "");
	gtk_widget_grab_focus(file_entry);

	manage_window_set_transient(GTK_WINDOW(window));

	gtk_main();

	gtk_widget_hide(window);
	gtk_window_set_modal(GTK_WINDOW(window), FALSE);

	return import_ok;
}
Exemplo n.º 10
0
static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
{
	gchar *path;
	gchar *pathnew;
	FILE *fp;
	FILE *fpnew;
	gchar buf[POPBUFSIZE];
	gchar uidl[POPBUFSIZE];
	time_t recv_time;
	time_t now;
	gchar partial_recv[POPBUFSIZE];
	int err = -1;
	gchar *filename;
	MsgInfo *tinfo;
	gchar *sanitized_uid = NULL;	

	filename = procmsg_get_message_file_path(msginfo);
	if (!filename) {
		g_warning("can't get message file path.");
		return err;
	}
	tinfo = procheader_parse_file(filename, msginfo->flags, TRUE, TRUE);
	
	if (!tinfo->extradata) {
		g_free(filename);
		return err;
	}

	sanitized_uid = g_strdup(tinfo->extradata->account_login);
	subst_for_filename(sanitized_uid);

	if (!tinfo->extradata->account_server
	||  !tinfo->extradata->account_login
	||  !tinfo->extradata->partial_recv) {
		goto bail;
	}
	path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
			   "uidl", G_DIR_SEPARATOR_S, tinfo->extradata->account_server,
			   "-", sanitized_uid, NULL);

	if ((fp = g_fopen(path, "rb")) == NULL) {
		perror("fopen1");
		if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
		g_free(path);
		path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
				   "uidl-", tinfo->extradata->account_server,
				   "-", tinfo->extradata->account_login, NULL);
		if ((fp = g_fopen(path, "rb")) == NULL) {
			if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
			g_free(path);
			goto bail;
		}
	}

	pathnew = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
			   "uidl", G_DIR_SEPARATOR_S, tinfo->extradata->account_server,
			   "-", sanitized_uid, ".new", NULL);
	
	g_free(sanitized_uid);

	if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
		perror("fopen2");
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}
	
	now = time(NULL);

	while (fgets(buf, sizeof(buf), fp) != NULL) {
		strretchomp(buf);
		recv_time = RECV_TIME_NONE;
		sprintf(partial_recv,"0");
		
		if (sscanf(buf, "%s\t%ld\t%s", 
			   uidl, (long int *) &recv_time, partial_recv) < 2) {
			if (sscanf(buf, "%s", uidl) != 1)
				continue;
			else {
				recv_time = now;
			}
		}
		if (strcmp(tinfo->extradata->partial_recv, uidl)) {
			if (fprintf(fpnew, "%s\t%ld\t%s\n", 
				uidl, (long int) recv_time, partial_recv) < 0) {
				FILE_OP_ERROR(pathnew, "fprintf");
				fclose(fpnew);
				fclose(fp);
				g_free(path);
				g_free(pathnew);
				goto bail;
			}
		} else {
			gchar *stat = NULL;
			if (download == POP3_PARTIAL_DLOAD_DLOAD) {
				gchar *folder_id = folder_item_get_identifier(
							msginfo->folder);
				stat = g_strdup_printf("%s:%d",
					folder_id, msginfo->msgnum);
				g_free(folder_id);
			}
			else if (download == POP3_PARTIAL_DLOAD_UNKN)
				stat = g_strdup("1");
			else if (download == POP3_PARTIAL_DLOAD_DELE)
				stat = g_strdup("0");
			
			if (fprintf(fpnew, "%s\t%ld\t%s\n", 
				uidl, (long int) recv_time, stat) < 0) {
				FILE_OP_ERROR(pathnew, "fprintf");
				fclose(fpnew);
				fclose(fp);
				g_free(path);
				g_free(pathnew);
				goto bail;
			}
			g_free(stat);
		}
	}
	if (fclose(fpnew) == EOF) {
		FILE_OP_ERROR(pathnew, "fclose");
		fclose(fp);
		g_free(path);
		g_free(pathnew);
		goto bail;
	}
	fclose(fp);

	move_file(pathnew, path, TRUE);

	g_free(path);
	g_free(pathnew);
	
	if ((fp = g_fopen(filename,"rb")) == NULL) {
		perror("fopen3");
		goto bail;
	}
	pathnew = g_strdup_printf("%s.new", filename);
	if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
		perror("fopen4");
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}
	
	if (fprintf(fpnew, "SC-Marked-For-Download: %d\n", 
			download) < 0) {
		FILE_OP_ERROR(pathnew, "fprintf");
		fclose(fpnew);
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}
	while (fgets(buf, sizeof(buf)-1, fp) != NULL) {
		if(strlen(buf) > strlen("SC-Marked-For-Download: x\n")
		&& !strncmp(buf, "SC-Marked-For-Download:", 
		            strlen("SC-Marked-For-Download:"))) {
			if (fprintf(fpnew, "%s", 
			 buf+strlen("SC-Marked-For-Download: x\n")) < 0) {
				FILE_OP_ERROR(pathnew, "fprintf");
				fclose(fpnew);
				fclose(fp);
				g_free(pathnew);
				goto bail;
			}
			continue;
		} else if (strlen(buf) == strlen("SC-Marked-For-Download: x\n")
		&& !strncmp(buf, "SC-Marked-For-Download:", 
		            strlen("SC-Marked-For-Download:"))) {
			continue;
		}
		if (fprintf(fpnew, "%s", buf) < 0) {
			FILE_OP_ERROR(pathnew, "fprintf");
			fclose(fpnew);
			fclose(fp);
			g_free(pathnew);
			goto bail;
		}
	}
	if (fclose(fpnew) == EOF) {
		FILE_OP_ERROR(pathnew, "fclose");
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}

	fclose(fp);
	if (rename_force(pathnew, filename) != 0) {
		g_free(pathnew);
		goto bail;
	}

	g_free(pathnew);
	msginfo->planned_download = download;
	msgcache_update_msg(msginfo->folder->cache, msginfo);

	err = 0;
bail:
	g_free(filename);
	procmsg_msginfo_free(&tinfo);
	
	return err;
}
Exemplo n.º 11
0
/* Save selections in a common xml-file. Called when unloading the plugin.
 * This is analog to folder.h::folder_write_list. */
void notification_foldercheck_write_array(void)
{
  gchar *path;
  XMLTag *tag;
  XMLNode *xmlnode;
  GNode *rootnode;
  gint ii;
  PrefFile *pfile;

  /* Do nothing if foldercheck is not in use */
  if(specific_folder_array_size == 0)
    return;

  path = foldercheck_get_array_path();
  if((pfile = prefs_write_open(path)) == NULL) {
    debug_print("Notification Plugin Error: Cannot open "
		"file " FOLDERCHECK_ARRAY " for writing\n");
    return;
  }

  /* XML declarations */
  xml_file_put_xml_decl(pfile->fp);

  /* Build up XML tree */
  
  /* root node */
  tag = xml_tag_new("foldercheckarray");
  xmlnode = xml_node_new(tag, NULL);
  rootnode = g_node_new(xmlnode);

  /* branch nodes */
  for(ii = 0; ii < specific_folder_array_size; ii++) {
    GNode *branchnode;
    GSList *walk;
    SpecificFolderArrayEntry *entry;
  
    entry = foldercheck_get_entry_from_id(ii);
    
    tag = xml_tag_new("branch");
    xml_tag_add_attr(tag, xml_attr_new("name",entry->name));
    xmlnode = xml_node_new(tag, NULL);
    branchnode = g_node_new(xmlnode);
    g_node_append(rootnode, branchnode);

    /* Write out the list as leaf nodes */
    for(walk = entry->list; walk != NULL; walk = g_slist_next(walk)) {
      gchar *identifier;
      GNode *node;
      FolderItem *item = (FolderItem*) walk->data;

      identifier = folder_item_get_identifier(item);

      tag = xml_tag_new("folderitem");
      xml_tag_add_attr(tag, xml_attr_new("identifier", identifier));
      g_free(identifier);
      xmlnode = xml_node_new(tag, NULL);
      node = g_node_new(xmlnode);
      g_node_append(branchnode, node);
    } /* for all list elements in branch node */

  } /* for all branch nodes */

  /* Actual writing and cleanup */
  xml_write_tree(rootnode, pfile->fp);

  if(prefs_file_close(pfile) < 0) {
    debug_print("Notification Plugin Error: Failed to write "
		"file " FOLDERCHECK_ARRAY "\n");
  }

  /* Free XML tree */
  xml_free_tree(rootnode);
}
Exemplo n.º 12
0
static gboolean notification_trayicon_popup_create(MsgInfo *msginfo,
						   NotificationFolderType nftype)
{
  gchar *summary = NULL;
  gchar *utf8_str = NULL;
  GdkPixbuf *pixbuf;
  GList *caps = NULL;
  gboolean support_actions = FALSE;

  /* init libnotify if necessary */
  if(!notify_is_initted()) {
    if(!notify_init("claws-mail")) {
      debug_print("Notification Plugin: Failed to initialize libnotify. "
		  "No popups will be shown.\n");
      return FALSE;
    }
  }

  /* Count messages */
  notification_trayicon_popup_count_msgs(nftype);

  summary  = notification_trayicon_popup_assemble_summary();
  utf8_str = notification_trayicon_popup_assemble_body(msginfo);

#if NOTIFY_CHECK_VERSION(0, 7, 0)
  popup.notification = notify_notification_new(summary, utf8_str, NULL);
#else
  popup.notification = notify_notification_new(summary, utf8_str, NULL, NULL);
  notify_notification_attach_to_status_icon(popup.notification, trayicon);
#endif

  g_free(summary);
  g_free(utf8_str);

  caps = notify_get_server_caps();
    if(caps != NULL) {
      GList *c;
      for(c = caps; c != NULL; c = c->next) {
	if(strcmp((char*)c->data, "actions") == 0 ) {
	  support_actions = TRUE;
	  break;
        }
      }

    g_list_foreach(caps, (GFunc)g_free, NULL);
    g_list_free(caps);
  }

  /* Default action */
  if (support_actions)
    notify_notification_add_action(popup.notification,
				   "default", "Present main window",
				   (NotifyActionCallback)
				   notification_trayicon_popup_default_action_cb,
				   GINT_TO_POINTER(nftype),
				   notification_trayicon_popup_free_func);

  if(popup.notification == NULL) {
    debug_print("Notification Plugin: Failed to create a new notification.\n");
    return FALSE;
  }

  /* Icon */
  pixbuf = NULL;
#ifndef USE_NEW_ADDRBOOK
  if(msginfo && msginfo->from) {
    gchar *icon_path;
    icon_path = addrindex_get_picture_file(msginfo->from);
    if(is_file_exist(icon_path)) {
      GError *error = NULL;
      gint w, h;

      gdk_pixbuf_get_file_info(icon_path, &w, &h);
      if((w > 64) || (h > 64))
	pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_path,
						   64, 64, TRUE, &error);
      else
	pixbuf = gdk_pixbuf_new_from_file(icon_path, &error);

      if(!pixbuf) {
	debug_print("Could not load picture file: %s\n",
		    error ? error->message : "no details");
	g_error_free(error);
      }
    }
    else
      debug_print("Picture path does not exist: %s\n",icon_path);
    g_free(icon_path);
  }
#endif
  if(!pixbuf)
    pixbuf = g_object_ref(notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64));

  if(pixbuf) {
    notify_notification_set_icon_from_pixbuf(popup.notification, pixbuf);
    g_object_unref(pixbuf);
  }
  else /* This is not fatal */
    debug_print("Notification plugin: Icon could not be loaded.\n");

  /* timeout */
  notify_notification_set_timeout(popup.notification, notify_config.trayicon_popup_timeout);

  /* Category */
  notify_notification_set_category(popup.notification, "email.arrived");

  /* get notified on bubble close */
  g_signal_connect(G_OBJECT(popup.notification), "closed", G_CALLBACK(popup_timeout_fun), NULL);

  /* Show the popup */
  notify_notification_set_hint_string(popup.notification, "desktop-entry", "claws-mail");
  if(!notify_notification_show(popup.notification, &(popup.error))) {
    debug_print("Notification Plugin: Failed to send notification: %s\n",
		popup.error->message);
    g_clear_error(&(popup.error));
    g_object_unref(G_OBJECT(popup.notification));
    popup.notification = NULL;
    return FALSE;
  }

  /* Store path to message */
  if(nftype == F_TYPE_MAIL) {
    if(msginfo->folder && msginfo->folder) {
      gchar *ident;
      ident = folder_item_get_identifier(msginfo->folder);
      popup.msg_path = g_strdup_printf("%s%s%u", ident,G_DIR_SEPARATOR_S,
				       msginfo->msgnum);
      g_free(ident);
    }
    else
      popup.msg_path = NULL;
  }

  debug_print("Notification Plugin: Popup created with libnotify.\n");

  return TRUE;
}
Exemplo n.º 13
0
void notification_trayicon_msg(MsgInfo *msginfo)
{
#ifndef HAVE_LIBNOTIFY
  return;

#else
  FolderType ftype;
  NotificationFolderType nftype;
  gchar *uistr;

  nftype = F_TYPE_MAIL;

  if(!msginfo || !notify_config.trayicon_enabled ||
     !notify_config.trayicon_popup_enabled ||
     !MSG_IS_NEW(msginfo->flags))
    return;

  if(notify_config.trayicon_folder_specific) {
    guint id;
    GSList *list;
    gchar *identifier;
    gboolean found = FALSE;

    if(!(msginfo->folder))
      return;

    identifier = folder_item_get_identifier(msginfo->folder);

    id =
      notification_register_folder_specific_list
      (TRAYICON_SPECIFIC_FOLDER_ID_STR);
    list = notification_foldercheck_get_list(id);
    for(; (list != NULL) && !found; list = g_slist_next(list)) {
      gchar *list_identifier;
      FolderItem *list_item = (FolderItem*) list->data;

      list_identifier = folder_item_get_identifier(list_item);
      if(!strcmp2(list_identifier, identifier))
	found = TRUE;

      g_free(list_identifier);
    }
    g_free(identifier);

    if(!found)
      return;
  } /* folder specific */

  ftype = msginfo->folder->folder->klass->type;

  G_LOCK(trayicon_popup);
  /* Check out which type to notify about */
  switch(ftype) {
  case F_MH:
  case F_MBOX:
  case F_MAILDIR:
  case F_IMAP:
    nftype = F_TYPE_MAIL;
    break;
  case F_NEWS:
    nftype = F_TYPE_NEWS;
    break;
  case F_UNKNOWN:
    if((uistr = msginfo->folder->folder->klass->uistr) == NULL) {
      G_UNLOCK(trayicon_popup);
      return;
    }
    else if(!strcmp(uistr, "vCalendar"))
      nftype = F_TYPE_CALENDAR;
    else if(!strcmp(uistr, "RSSyl"))
      nftype = F_TYPE_RSS;
    else {
      debug_print("Notification Plugin: Unknown folder type %d\n",ftype);
      G_UNLOCK(trayicon_popup);
      return;
    }
    break;
  default:
    debug_print("Notification Plugin: Unknown folder type %d\n",ftype);
    G_UNLOCK(trayicon_popup);
    return;
  }


  notification_trayicon_popup_add_msg(msginfo, nftype);

  G_UNLOCK(trayicon_popup);

#endif /* HAVE_LIBNOTIFY */
}
Exemplo n.º 14
0
void notification_popup_msg(MsgInfo *msginfo)
{
  FolderType ftype;
#if HAVE_LIBNOTIFY
  gchar *uistr;
#else
  NotificationPopup *ppopup;
  gboolean retval;
#endif
  NotificationFolderType nftype;

  nftype = F_TYPE_MAIL;

  if(!msginfo || !notify_config.popup_show)
    return;

  if(notify_config.popup_folder_specific) {
    guint id;
    GSList *list;
    gchar *identifier;
    gboolean found = FALSE;

    if(!(msginfo->folder))
      return;

    identifier = folder_item_get_identifier(msginfo->folder);

    id =
      notification_register_folder_specific_list(POPUP_SPECIFIC_FOLDER_ID_STR);
    list = notification_foldercheck_get_list(id);
    for(; (list != NULL) && !found; list = g_slist_next(list)) {
      gchar *list_identifier;
      FolderItem *list_item = (FolderItem*) list->data;

      list_identifier = folder_item_get_identifier(list_item);
      if(!strcmp2(list_identifier, identifier))
	found = TRUE;

      g_free(list_identifier);
    }
    g_free(identifier);

    if(!found)
      return;
  }

  ftype = msginfo->folder->folder->klass->type;

  G_LOCK(popup);
#ifdef HAVE_LIBNOTIFY
  /* Check out which type to notify about */
  switch(ftype) {
  case F_MH:
  case F_MBOX:
  case F_MAILDIR:
  case F_IMAP:
    nftype = F_TYPE_MAIL;
    break;
  case F_NEWS:
    nftype = F_TYPE_NEWS;
    break;
  case F_UNKNOWN:
    if((uistr = msginfo->folder->folder->klass->uistr) == NULL) {
      G_UNLOCK(popup);
      return;
    }
    else if(!strcmp(uistr, "vCalendar"))
      nftype = F_TYPE_CALENDAR;
    else if(!strcmp(uistr, "RSSyl"))
      nftype = F_TYPE_RSS;
    else {
      debug_print("Notification Plugin: Unknown folder type %d\n",ftype);
      G_UNLOCK(popup);
      return;
    }
    break;
  default:
    debug_print("Notification Plugin: Unknown folder type %d\n",ftype);
    G_UNLOCK(popup);
    return;
  }

  notification_libnotify_add_msg(msginfo, nftype);
#else /* !HAVE_LIBNOTIFY */
  ppopup = &popup;
  retval = notification_popup_add_msg(msginfo);

  /* Renew timeout only when the above call was successful */
  if(retval) {
    if(ppopup->timeout_id)
      g_source_remove(ppopup->timeout_id);
    ppopup->timeout_id = g_timeout_add(notify_config.popup_timeout,
                       popup_timeout_fun,
                       GINT_TO_POINTER(nftype));
  }

  #endif /* !HAVE_LIBNOTIFY */

  G_UNLOCK(popup);

#ifndef HAVE_LIBNOTIFY
  /* GUI update */
  while(gtk_events_pending())
    gtk_main_iteration();
#endif /* !HAVE_LIBNOTIFY */

}
Exemplo n.º 15
0
static gboolean notification_popup_create(MsgInfo *msginfo)
{
  GdkColor bg;
  GdkColor fg;
  NotificationPopup *ppopup;

  g_return_val_if_fail(msginfo, FALSE);

  ppopup = &popup;

  /* Window */
  ppopup->window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "notification_popup");
  gtk_window_set_decorated(GTK_WINDOW(ppopup->window), FALSE);
  gtk_window_set_keep_above(GTK_WINDOW(ppopup->window), TRUE);
  gtk_window_set_accept_focus(GTK_WINDOW(ppopup->window), FALSE);
  gtk_window_set_skip_taskbar_hint(GTK_WINDOW(ppopup->window), TRUE);
  gtk_window_set_skip_pager_hint(GTK_WINDOW(ppopup->window), TRUE);
  gtk_window_move(GTK_WINDOW(ppopup->window), notify_config.popup_root_x,
		  notify_config.popup_root_y);
  gtk_window_resize(GTK_WINDOW(ppopup->window), notify_config.popup_width, 1);
  if(notify_config.popup_sticky)
    gtk_window_stick(GTK_WINDOW(ppopup->window));
  /* Signals */
  gtk_widget_set_events(ppopup->window,
			GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
  g_signal_connect(ppopup->window, "button_press_event",
		   G_CALLBACK(notification_popup_button), NULL);

  /* Event box */
  ppopup->event_box = gtk_event_box_new();
  gtk_container_add(GTK_CONTAINER(ppopup->window), ppopup->event_box);

  /* Frame */
  ppopup->frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type(GTK_FRAME(ppopup->frame), GTK_SHADOW_ETCHED_OUT);
  gtk_container_add(GTK_CONTAINER(ppopup->event_box), ppopup->frame);

  /* Vbox with labels */
  ppopup->vbox = gtk_vbox_new(FALSE, 2);
  gtk_container_set_border_width(GTK_CONTAINER(ppopup->vbox), 5);
  ppopup->label1 = gtk_label_new(msginfo->from ?
                                 msginfo->from : _("(No From)"));
  gtk_box_pack_start(GTK_BOX(ppopup->vbox), ppopup->label1, FALSE, FALSE, 0);

  ppopup->label2 = gtk_label_new(msginfo->subject ?
                                 msginfo->subject : _("(No Subject)"));
  gtk_box_pack_start(GTK_BOX(ppopup->vbox), ppopup->label2, FALSE, FALSE, 0);

  gtk_container_add(GTK_CONTAINER(ppopup->frame), ppopup->vbox);
  gtk_widget_set_size_request(ppopup->vbox, notify_config.popup_width, -1);

  /* Color */
  if(notify_config.popup_enable_colors) {
    gtkut_convert_int_to_gdk_color(notify_config.popup_color_bg,&bg);
    gtkut_convert_int_to_gdk_color(notify_config.popup_color_fg,&fg);
    gtk_widget_modify_bg(ppopup->event_box,GTK_STATE_NORMAL,&bg);
    gtk_widget_modify_fg(ppopup->label1,GTK_STATE_NORMAL,&fg);
    gtk_widget_modify_fg(ppopup->label2,GTK_STATE_NORMAL,&fg);
  }

  gtk_widget_show_all(ppopup->window);

  ppopup->count = 1;

  if(msginfo->folder && msginfo->folder->name) {
      gchar *ident;
      ident = folder_item_get_identifier(msginfo->folder);
      ppopup->msg_path = g_strdup_printf("%s%s%u", ident,G_DIR_SEPARATOR_S,
					 msginfo->msgnum);
      g_free(ident);
  }

  return TRUE;
}
Exemplo n.º 16
0
static gboolean notification_libnotify_create(MsgInfo *msginfo,
					      NotificationFolderType nftype)
{
  GdkPixbuf *pixbuf;
  NotificationPopup *ppopup;
  gchar *summary = NULL;
  gchar *text = NULL;
  gchar *utf8_str = NULL;
  gchar *subj = NULL;
  gchar *from = NULL;
  gchar *foldname = NULL;
  GList *caps = NULL;
  gboolean support_actions = FALSE;

  g_return_val_if_fail(msginfo, FALSE);

  ppopup = &(popup[nftype]);

  /* init libnotify if necessary */
  if(!notify_is_initted()) {
    if(!notify_init("claws-mail")) {
      debug_print("Notification Plugin: Failed to initialize libnotify. "
		  "No popup will be shown.\n");
      return FALSE;
    }
  }

  switch(nftype) {
  case F_TYPE_MAIL:
    summary = _("New Mail message");
    from    = notification_libnotify_sanitize_str(msginfo->from ?
                                                  msginfo->from : _("(No From)"));
    subj    = notification_libnotify_sanitize_str(msginfo->subject ?
                                                  msginfo->subject : _("(No Subject)"));
	if (notify_config.popup_display_folder_name) {
		foldname = notification_libnotify_sanitize_str(msginfo->folder->path);
    	text = g_strconcat(from,"\n\n", subj, "\n\n", foldname, NULL);
	}
	else
		text = g_strconcat(from, "\n\n",subj, NULL);

    /* Make sure text is valid UTF8 */
    utf8_str = notification_validate_utf8_str(text);
    g_free(text);

    if(from) g_free(from);
    if(subj) g_free(subj);
    if(foldname) g_free(foldname);
    break;
  case F_TYPE_NEWS:
    summary = _("New News post");
    utf8_str    = g_strdup(_("A new message arrived"));
    break;
  case F_TYPE_CALENDAR:
    summary = _("New Calendar message");
    utf8_str    = g_strdup(_("A new calendar message arrived"));
    break;
  case F_TYPE_RSS:
    summary = _("New RSS feed article");
    utf8_str = g_strdup(_("A new article in a RSS feed arrived"));
    break;
  default:
    summary = _("New unknown message");
    utf8_str = g_strdup(_("Unknown message type arrived"));
    break;
  }

  ppopup->notification = notify_notification_new(summary, utf8_str, NULL
#if !NOTIFY_CHECK_VERSION(0, 7, 0)
      , NULL
#endif
      );
  g_free(utf8_str);
  if(ppopup->notification == NULL) {
    debug_print("Notification Plugin: Failed to create a new "
		"notification.\n");
    return FALSE;
  }

  caps = notify_get_server_caps();
    if(caps != NULL) {
      GList *c;
      for(c = caps; c != NULL; c = c->next) {
	if(strcmp((char*)c->data, "actions") == 0 ) {
	  support_actions = TRUE;
	  break;
        }
      }

    g_list_foreach(caps, (GFunc)g_free, NULL);
    g_list_free(caps);
  }

  /* Default action */
  if (support_actions)
    notify_notification_add_action(ppopup->notification,
				   "default", _("Present main window"),
				   (NotifyActionCallback)default_action_cb,
				   GINT_TO_POINTER(nftype),
				   notification_libnotify_free_func);

  /* Icon */
  pixbuf = NULL;
#ifndef USE_ALT_ADDRBOOK
  if(msginfo && msginfo->from) {
    gchar *icon_path;
    icon_path = addrindex_get_picture_file(msginfo->from);
    if(is_file_exist(icon_path)) {
      GError *error = NULL;
      gint w, h;

      gdk_pixbuf_get_file_info(icon_path, &w, &h);
      if((w > 64) || (h > 64))
	pixbuf = gdk_pixbuf_new_from_file_at_scale(icon_path,
						   64, 64, TRUE, &error);
      else
	pixbuf = gdk_pixbuf_new_from_file(icon_path, &error);

      if(!pixbuf) {
	debug_print("Could not load picture file: %s\n",
		    error ? error->message : "no details");
	g_error_free(error);
      }
    }
    else
      debug_print("Picture path does not exist: %s\n",icon_path);
    g_free(icon_path);
  }
#endif
  if(!pixbuf)
   pixbuf = g_object_ref(notification_pixbuf_get(NOTIFICATION_CM_LOGO_64x64));

  if(pixbuf) {
    notify_notification_set_icon_from_pixbuf(ppopup->notification, pixbuf);
    g_object_unref(pixbuf);
  }
  else /* This is not fatal */
    debug_print("Notification plugin: Icon could not be loaded.\n");

  /* timeout */
  notify_notification_set_timeout(ppopup->notification, notify_config.popup_timeout);

  /* Category */
  notify_notification_set_category(ppopup->notification, "email.arrived");

  /* get notified on bubble close */
  g_signal_connect(G_OBJECT(popup->notification), "closed", G_CALLBACK(popup_timeout_fun), NULL);

  /* Show the popup */
  notify_notification_set_hint_string(ppopup->notification, "desktop-entry", "claws-mail");
  if(!notify_notification_show(ppopup->notification, &(ppopup->error))) {
    debug_print("Notification Plugin: Failed to send notification: %s\n",
		ppopup->error->message);
    g_clear_error(&(ppopup->error));
    g_object_unref(G_OBJECT(ppopup->notification));
    ppopup->notification = NULL;
    return FALSE;
  }

  debug_print("Notification Plugin: Popup created with libnotify.\n");
  ppopup->count = 1;

  /* Store path to message */
  if(nftype == F_TYPE_MAIL) {
    if(msginfo && msginfo->folder) {
      gchar *ident;
      ident = folder_item_get_identifier(msginfo->folder);
      ppopup->msg_path = g_strdup_printf("%s%s%u", ident,G_DIR_SEPARATOR_S,
					 msginfo->msgnum);
      g_free(ident);
    }
    else
      ppopup->msg_path = NULL;
  }

  return TRUE;
}