aboutsummaryrefslogtreecommitdiff
path: root/plugins/http-files/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/http-files/src')
-rw-r--r--plugins/http-files/src/contact_titlebar_entry.vala72
-rw-r--r--plugins/http-files/src/file_provider.vala36
-rw-r--r--plugins/http-files/src/manager.vala64
-rw-r--r--plugins/http-files/src/plugin.vala4
4 files changed, 41 insertions, 135 deletions
diff --git a/plugins/http-files/src/contact_titlebar_entry.vala b/plugins/http-files/src/contact_titlebar_entry.vala
deleted file mode 100644
index e5b82abe..00000000
--- a/plugins/http-files/src/contact_titlebar_entry.vala
+++ /dev/null
@@ -1,72 +0,0 @@
-using Gtk;
-
-using Dino.Entities;
-
-namespace Dino.Plugins.HttpFiles {
-
-public class ConversationsTitlebarEntry : Plugins.ConversationTitlebarEntry, Object {
- public string id { get { return "send_files"; } }
-
- StreamInteractor stream_interactor;
-
- public ConversationsTitlebarEntry(StreamInteractor stream_interactor) {
- this.stream_interactor = stream_interactor;
- }
-
- public double order { get { return 4; } }
- public Plugins.ConversationTitlebarWidget get_widget(WidgetType type) {
- if (type == WidgetType.GTK) {
- return new ConversationTitlebarWidget(stream_interactor) { visible=true };
- }
- return null;
- }
-}
-
-public class ConversationTitlebarWidget : Button, Plugins.ConversationTitlebarWidget {
-
- private Conversation? conversation;
- private StreamInteractor stream_interactor;
-
- public ConversationTitlebarWidget(StreamInteractor stream_interactor) {
- this.stream_interactor = stream_interactor;
- image = new Image.from_icon_name("mail-attachment-symbolic", IconSize.MENU);
- clicked.connect(on_clicked);
- stream_interactor.get_module(Manager.IDENTITY).upload_available.connect(on_upload_available);
- }
-
- public void on_clicked() {
- FileChooserNative chooser = new FileChooserNative (
- "Select file", get_toplevel() as Window, FileChooserAction.OPEN,
- "Select", "Cancel");
- long max_file_size = stream_interactor.get_module(Manager.IDENTITY).get_max_file_size(conversation.account);
- if (max_file_size != -1) {
- FileFilter filter = new FileFilter();
- filter.add_custom(FileFilterFlags.URI, (filter_info) => {
- File file = File.new_for_uri(filter_info.uri);
- FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
- return file_info.get_size() <= max_file_size;
- });
- chooser.set_filter(filter);
- }
- if (chooser.run() == Gtk.ResponseType.ACCEPT) {
- string uri = chooser.get_filename();
- stream_interactor.get_module(Manager.IDENTITY).send(conversation, uri);
- }
- }
-
- public void on_upload_available(Account account) {
- Idle.add(() => {
- if (conversation != null && conversation.account.equals(account)) {
- visible = true;
- }
- return false;
- });
- }
-
- public new void set_conversation(Conversation conversation) {
- this.conversation = conversation;
- visible = stream_interactor.get_module(Manager.IDENTITY).is_upload_available(conversation.account);
- }
-}
-
-}
diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala
index 69ae9218..d327ec5f 100644
--- a/plugins/http-files/src/file_provider.vala
+++ b/plugins/http-files/src/file_provider.vala
@@ -5,7 +5,7 @@ using Dino.Entities;
namespace Dino.Plugins.HttpFiles {
-public class FileProvider : Plugins.FileProvider, Object {
+public class FileProvider : Dino.FileProvider, Object {
public string id { get { return "http"; } }
private StreamInteractor stream_interactor;
@@ -19,15 +19,8 @@ public class FileProvider : Plugins.FileProvider, Object {
this.url_regex = new Regex("""^(?i)\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))$""");
this.file_ext_regex = new Regex("""\.(png|jpg|jpeg|svg|gif)""");
- Application app = GLib.Application.get_default() as Application;
- app.plugin_registry.register_message_display(new FileMessageFilterDisplay(dino_db));
-
stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(check_message);
stream_interactor.get_module(MessageProcessor.IDENTITY).message_sent.connect(check_message);
- stream_interactor.get_module(Manager.IDENTITY).uploading.connect((file_transfer) => {
- file_transfer.provider = 0;
- file_incoming(file_transfer);
- });
stream_interactor.get_module(Manager.IDENTITY).uploaded.connect((file_transfer, url) => {
file_transfer.info = url;
ignore_once.add(url);
@@ -77,31 +70,4 @@ public class FileProvider : Plugins.FileProvider, Object {
}
}
-public class FileMessageFilterDisplay : Plugins.MessageDisplayProvider, Object {
- public string id { get; set; default="file_message_filter"; }
- public double priority { get; set; default=10; }
-
- public Database db;
-
- public FileMessageFilterDisplay(Dino.Database db) {
- this.db = db;
- }
-
- public bool can_display(Entities.Message? message) {
- return message_is_file(message);
- }
-
- public Plugins.MetaConversationItem? get_item(Entities.Message message, Conversation conversation) {
- return null;
- }
-
- private bool message_is_file(Entities.Message message) {
- Qlite.QueryBuilder builder = db.file_transfer.select()
- .with(db.file_transfer.info, "=", message.body)
- .with(db.file_transfer.account_id, "=", message.account.id)
- .with(db.file_transfer.counterpart_id, "=", db.get_jid_id(message.counterpart));
- return builder.count() > 0;
- }
-}
-
}
diff --git a/plugins/http-files/src/manager.vala b/plugins/http-files/src/manager.vala
index b1b7296c..9abf9843 100644
--- a/plugins/http-files/src/manager.vala
+++ b/plugins/http-files/src/manager.vala
@@ -4,44 +4,28 @@ using Gee;
namespace Dino.Plugins.HttpFiles {
-public class Manager : StreamInteractionModule, Object {
+public class Manager : StreamInteractionModule, FileSender, Object {
public static ModuleIdentity<Manager> IDENTITY = new ModuleIdentity<Manager>("http_files");
public string id { get { return IDENTITY.id; } }
- public signal void upload_available(Account account);
public signal void uploading(FileTransfer file_transfer);
public signal void uploaded(FileTransfer file_transfer, string url);
private StreamInteractor stream_interactor;
private HashMap<Account, long> max_file_sizes = new HashMap<Account, long>(Account.hash_func, Account.equals_func);
-
private Manager(StreamInteractor stream_interactor) {
this.stream_interactor = stream_interactor;
+ stream_interactor.get_module(FileManager.IDENTITY).add_sender(this);
stream_interactor.stream_negotiated.connect(on_stream_negotiated);
}
- public void send(Conversation conversation, string file_uri) {
- Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(conversation.account);
+ public void send_file(Conversation conversation, FileTransfer file_transfer) {
+ Xmpp.Core.XmppStream? stream = stream_interactor.get_stream(file_transfer.account);
if (stream != null) {
- File file = File.new_for_path(file_uri);
- FileInfo file_info = file.query_info("*", FileQueryInfoFlags.NONE);
-
- FileTransfer file_transfer = new FileTransfer();
- file_transfer.account = conversation.account;
- file_transfer.counterpart = conversation.counterpart;
- file_transfer.ourpart = conversation.account.bare_jid;
- file_transfer.direction = FileTransfer.DIRECTION_SENT;
- file_transfer.time = new DateTime.now_utc();
- file_transfer.local_time = new DateTime.now_utc();
- file_transfer.encryption = Encryption.NONE;
- file_transfer.file_name = file_info.get_display_name();
- file_transfer.input_stream = file.read();
- file_transfer.mime_type = file_info.get_content_type();
- file_transfer.size = (int)file_info.get_size();
+ file_transfer.provider = 0;
uploading(file_transfer);
-
- stream_interactor.module_manager.get_module(conversation.account, UploadStreamModule.IDENTITY).upload(stream, file_uri,
+ stream_interactor.module_manager.get_module(file_transfer.account, UploadStreamModule.IDENTITY).upload(stream, Path.build_filename(FileManager.get_storage_dir(), file_transfer.path),
(stream, url_down) => {
uploaded(file_transfer, url_down);
stream_interactor.get_module(MessageProcessor.IDENTITY).send_message(url_down, conversation);
@@ -50,13 +34,16 @@ public class Manager : StreamInteractionModule, Object {
file_transfer.state = FileTransfer.State.FAILED;
}
);
-
}
}
- public bool is_upload_available(Account account) {
+ public bool can_send(Conversation conversation, FileTransfer file_transfer) {
+ return true;
+ }
+
+ public bool is_upload_available(Conversation conversation) {
lock (max_file_sizes) {
- return max_file_sizes.has_key(account);
+ return max_file_sizes.has_key(conversation.account);
}
}
@@ -81,4 +68,31 @@ public class Manager : StreamInteractionModule, Object {
}
}
+public class FileMessageFilterDisplay : Plugins.MessageDisplayProvider, Object {
+ public string id { get; set; default="file_message_filter"; }
+ public double priority { get; set; default=10; }
+
+ public Database db;
+
+ public FileMessageFilterDisplay(Dino.Database db) {
+ this.db = db;
+ }
+
+ public bool can_display(Entities.Message? message) {
+ return message_is_file(message);
+ }
+
+ public Plugins.MetaConversationItem? get_item(Entities.Message message, Conversation conversation) {
+ return null;
+ }
+
+ private bool message_is_file(Entities.Message message) {
+ Qlite.QueryBuilder builder = db.file_transfer.select()
+ .with(db.file_transfer.info, "=", message.body)
+ .with(db.file_transfer.account_id, "=", message.account.id)
+ .with(db.file_transfer.counterpart_id, "=", db.get_jid_id(message.counterpart));
+ return builder.count() > 0;
+ }
+}
+
}
diff --git a/plugins/http-files/src/plugin.vala b/plugins/http-files/src/plugin.vala
index d91b0c97..7fc01e65 100644
--- a/plugins/http-files/src/plugin.vala
+++ b/plugins/http-files/src/plugin.vala
@@ -6,7 +6,6 @@ namespace Dino.Plugins.HttpFiles {
public class Plugin : RootInterface, Object {
public Dino.Application app;
- public ConversationsTitlebarEntry conversations_titlebar_entry;
public FileProvider file_provider;
public void registered(Dino.Application app) {
@@ -14,15 +13,14 @@ public class Plugin : RootInterface, Object {
this.app = app;
Manager.start(this.app.stream_interactor);
- conversations_titlebar_entry = new ConversationsTitlebarEntry(app.stream_interactor);
file_provider = new FileProvider(app.stream_interactor, app.db);
- app.plugin_registry.register_contact_titlebar_entry(conversations_titlebar_entry);
app.stream_interactor.module_manager.initialize_account_modules.connect((account, list) => {
list.add(new UploadStreamModule());
});
app.stream_interactor.get_module(FileManager.IDENTITY).add_provider(file_provider);
+ app.plugin_registry.register_message_display(new FileMessageFilterDisplay(app.db));
} catch (Error e) {
print(@"Error initializing http-files: $(e.message)\n");
}