-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (67 loc) · 2.09 KB
/
main.cpp
File metadata and controls
80 lines (67 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "compose.hpp"
#include "message.hpp"
#include "message_parser.hpp"
#include "message_printer.hpp"
#include <iterator>
#include <iostream>
#include <fstream>
#include <gtkmm/main.h>
#include <gtkmm/messagedialog.h>
std::string out_file_name;
Compose::Compose *compose;
void save_message(Glib::RefPtr<Compose::Message> message) {
std::ofstream ofs;
if (out_file_name == "") {
std::cout << message;
compose->hide();
return;
}
ofs.open(out_file_name.c_str(), std::ios_base::trunc);
ofs << message;
ofs.flush();
ofs.close();
compose->hide();
}
void cancel_message() {
Gtk::MessageDialog dialog(*compose,
"Are you sure you want to cancel?", false,
Gtk::MESSAGE_QUESTION,
Gtk::BUTTONS_OK_CANCEL);
dialog.set_secondary_text("All changes will be lost.");
switch (dialog.run()) {
case Gtk::RESPONSE_CANCEL:
return;
case Gtk::RESPONSE_OK:
compose->hide();
return;
default:
std::cerr << "cancel_message: unknown response from Gtk::MessageDialog" << std::endl;
}
}
int main(int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
Glib::RefPtr<Compose::Message> message(new Compose::Message());
compose = new Compose::Compose();
if (argc < 2) {
std::cin.unsetf(std::ios_base::skipws);
parse_message(std::istream_iterator<char>(std::cin), std::istream_iterator<char>(), message);
} else {
std::ifstream infile(argv[1]);
infile.unsetf(std::ios_base::skipws);
parse_message(std::istream_iterator<char>(infile), std::istream_iterator<char>(), message);
out_file_name = argv[1];
}
message->set_headers_visible(false);
message->set_header_visible("from", true);
message->set_header_visible("to", true);
message->set_header_visible("reply-to", true);
message->set_header_visible("subject", true);
message->set_header_visible("cc", true);
compose->set_message(message);
compose->signal_send().connect(sigc::ptr_fun(save_message));
compose->signal_cancel().connect(sigc::ptr_fun(cancel_message));
Gtk::Main::run(*compose);
Glib::Error::register_cleanup();
Glib::wrap_register_cleanup();
gdk_exit(0);
}