Logo Search packages:      
Sourcecode: pan version File versions  Download package

bool PostUI::maybe_post_message ( GMimeMessage *  message  )  [private]

Find the server to use

Make sure the message is OK...

If this is email only, skip the rest of the posting... we only stayed this long to get check_message()

Make sure we're online...

Pop up a ``Posting'' Dialog...

Maybe remember the charsets.

Definition at line 598 of file post-ui.cc.

References pan::Progress::add_listener(), pan::Queue::add_task(), pan::StringView::empty(), pan::Quark::empty(), pan::Data::get_servers(), pan::Queue::is_online(), pan::Profile::posting_server, pan::Queue::set_online(), and pan::StringView::trim().

{
  /**
  ***  Find the server to use
  **/

  // get the profile...
  const Profile profile (get_current_profile ());
  // get the server associated with that profile...
  const Quark& server (profile.posting_server);
  // if the server's invalid, bitch about it to the user
  if (server.empty() || !_data.get_servers().count(server)) {
    GtkWidget * d = gtk_message_dialog_new (
      GTK_WINDOW(_root),
      GTK_DIALOG_DESTROY_WITH_PARENT,
      GTK_MESSAGE_ERROR,
      GTK_BUTTONS_CLOSE,
      _("No posting server is set for this posting profile.\nPlease edit the profile via Edit|Manage Posting Profiles."));
    gtk_dialog_run (GTK_DIALOG(d));
    gtk_widget_destroy (d);
    return false;
  }

  /**
  ***  Make sure the message is OK...
  **/

  if (!check_message (server, message))
    return false;

  /**
  *** If this is email only, skip the rest of the posting...
  *** we only stayed this long to get check_message()
  **/
  const StringView groups (g_mime_message_get_header (message, "Newsgroups"));
  if (groups.empty()) {
    maybe_mail_message (message);
    return true;
  }

  /**
  ***  Make sure we're online...
  **/
  if (!_queue.is_online())
  {
    GtkWidget * d = gtk_message_dialog_new (GTK_WINDOW(_root),
                                            GTK_DIALOG_DESTROY_WITH_PARENT,
                                            GTK_MESSAGE_QUESTION,
                                            GTK_BUTTONS_NONE, NULL);
    HIG :: message_dialog_set_text (GTK_MESSAGE_DIALOG(d),
                             _("Pan is Offline."),
                             _("Go online to post the article?"));
    gtk_dialog_add_button (GTK_DIALOG(d), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
    gtk_dialog_add_action_widget (GTK_DIALOG(d), new_go_online_button(), GTK_RESPONSE_OK);
    const int response = gtk_dialog_run (GTK_DIALOG(d));
    gtk_widget_destroy (d);
    if (response !=  GTK_RESPONSE_OK)
      return false;
    _queue.set_online (true);
  }

  /**
  ***  Pop up a ``Posting'' Dialog...
  **/
  GtkWidget * d = gtk_dialog_new_with_buttons (_("Posting Article"),
                                               GTK_WINDOW(_root),
                                               GTK_DIALOG_DESTROY_WITH_PARENT,
                                               //GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                               NULL);
  char buf[512];
  g_snprintf (buf, sizeof(buf), "<b>%s</b>", _("Posting..."));
  GtkWidget * w = GTK_WIDGET (g_object_new (GTK_TYPE_LABEL, "use-markup", TRUE, "label", buf, NULL));
  gtk_box_pack_start (GTK_BOX(GTK_DIALOG(d)->vbox), w, false, false, PAD_SMALL);
  w = gtk_progress_bar_new ();
  gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR(w), 0.05);
  const guint tag = g_timeout_add (100, pulse_me, w);
  gtk_box_pack_start (GTK_BOX(GTK_DIALOG(d)->vbox), w, false, false, PAD_SMALL);
  g_object_set_data_full (G_OBJECT(d), "progressbar-timeout-tag", GUINT_TO_POINTER(tag), remove_progress_tag);
  _post_dialog = d;
  g_signal_connect (_post_dialog, "destroy", G_CALLBACK(gtk_widget_destroyed), &_post_dialog);
  gtk_widget_show_all (d);
  _post_task = new TaskPost (server, message);
  _post_task->add_listener (this);
  
  _queue.add_task (_post_task, Queue::TOP);

  /**
  ***  Maybe remember the charsets.
  **/
  if (remember_charsets) {
    const char * text = gtk_entry_get_text (GTK_ENTRY(_groups_entry));
    StringView line(text), groupname;
    while (line.pop_token (groupname, ',')) {
      groupname.trim ();
      if (!groupname.empty())
        _group_prefs.set_string (groupname, "character-encoding", _charset);
    }
  }

  return true;
}


Generated by  Doxygen 1.6.0   Back to index