diff --git a/telegram-adium/AdiumTelegramAccount.m b/telegram-adium/AdiumTelegramAccount.m index 1e87958..52f45ff 100644 --- a/telegram-adium/AdiumTelegramAccount.m +++ b/telegram-adium/AdiumTelegramAccount.m @@ -22,6 +22,8 @@ #import #import "tgp-ft.h" +#include "telegram-purple.h" + @implementation AdiumTelegramAccount - (const char*)protocolPlugin @@ -44,6 +46,37 @@ return 443; } + +- (void)configurePurpleAccount +{ + [super configurePurpleAccount]; + + purple_account_set_string (account, TGP_KEY_ACCEPT_SECRET_CHATS, + [[self preferenceForKey:@"Telegram:"TGP_KEY_ACCEPT_SECRET_CHATS + group:GROUP_ACCOUNT_STATUS] + UTF8String]); + + purple_account_set_bool (account, TGP_KEY_DISPLAY_READ_NOTIFICATIONS, + [[self preferenceForKey:@"Telegram:"TGP_KEY_DISPLAY_READ_NOTIFICATIONS + group:GROUP_ACCOUNT_STATUS] + boolValue]); + + purple_account_set_bool (account, TGP_KEY_HISTORY_SYNC_ALL, + [[self preferenceForKey:@"Telegram:"TGP_KEY_HISTORY_SYNC_ALL + group:GROUP_ACCOUNT_STATUS] + boolValue]); + + purple_account_set_int (account, TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD, + [[self preferenceForKey:@"Telegram:"TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD + group:GROUP_ACCOUNT_STATUS] + intValue]); + + purple_account_set_int (account, TGP_KEY_INACTIVE_DAYS_OFFLINE, + [[self preferenceForKey:@"Telegram:"TGP_KEY_INACTIVE_DAYS_OFFLINE + group:GROUP_ACCOUNT_STATUS] + intValue]); +} + - (BOOL)canSendOfflineMessageToContact:(AIListContact *)inContact { return YES; diff --git a/telegram-adium/PurpleDefaultsTelegram.plist b/telegram-adium/PurpleDefaultsTelegram.plist new file mode 100644 index 0000000..3a4b87c --- /dev/null +++ b/telegram-adium/PurpleDefaultsTelegram.plist @@ -0,0 +1,16 @@ + + + + + Telegram:accept-secret-chats + ask + Telegram:inactive-days-offline + 7 + Telegram:display-read-notifications + + Telegram:history-retrieve-days + 14 + Telegram:history-sync-all + + + diff --git a/telegram-adium/TelegramAccountView.xib b/telegram-adium/TelegramAccountView.xib new file mode 100644 index 0000000..ad88634 --- /dev/null +++ b/telegram-adium/TelegramAccountView.xib @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/telegram-adium/TelegramAccountViewController.h b/telegram-adium/TelegramAccountViewController.h new file mode 100644 index 0000000..92c571c --- /dev/null +++ b/telegram-adium/TelegramAccountViewController.h @@ -0,0 +1,31 @@ +/* + * Adium is the legal property of its developers, whose names are listed in the copyright file included + * with this source distribution. + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import +#import + +@interface TelegramAccountViewController : PurpleAccountViewController { + IBOutlet NSButton *checkbox_historySyncAll; + IBOutlet NSButton *checkbox_displayReadNotifications; + + IBOutlet NSTextField *textField_maxMsgSplitCount; + IBOutlet NSTextField *textField_inactiveDaysOffline; + IBOutlet NSTextField *textField_historyRetrieveDays; + + IBOutlet NSMatrix *radio_Encryption; +} + +@end diff --git a/telegram-adium/TelegramAccountViewController.m b/telegram-adium/TelegramAccountViewController.m new file mode 100644 index 0000000..adb6915 --- /dev/null +++ b/telegram-adium/TelegramAccountViewController.m @@ -0,0 +1,93 @@ +/* + * Adium is the legal property of its developers, whose names are listed in the copyright file included + * with this source distribution. + * + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program; if not, + * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#import "TelegramAccountViewController.h" +#import "AdiumTelegramAccount.h" + +#import +#import +#import +#import + +#include "telegram-purple.h" + +@implementation TelegramAccountViewController + +- (NSString *)nibName{ + return @"TelegramAccountView"; +} + +- (void)configureForAccount:(AIAccount *)inAccount +{ + [super configureForAccount:inAccount]; + + NSString *acceptSecretChats = [account + preferenceForKey:@"Telegram:"TGP_KEY_ACCEPT_SECRET_CHATS + group:GROUP_ACCOUNT_STATUS] ?: @TGP_DEFAULT_ACCEPT_SECRET_CHATS; + + NSInteger row = 0; + if ([acceptSecretChats isEqual:@"always"]) { + row = 1; + } else if ([acceptSecretChats isEqual:@"never"]) { + row = 2; + } + [radio_Encryption selectCellAtRow:row column:0]; + + id s = [account preferenceForKey:@"Telegram:"TGP_KEY_HISTORY_SYNC_ALL group:GROUP_ACCOUNT_STATUS]; + [checkbox_historySyncAll setState:[s boolValue]]; + + id s4 = [account preferenceForKey:@"Telegram:"TGP_KEY_DISPLAY_READ_NOTIFICATIONS group:GROUP_ACCOUNT_STATUS]; + [checkbox_displayReadNotifications setState:[s4 boolValue]]; + + NSString *inactiveDaysOffline = [account + preferenceForKey:@"Telegram:"TGP_KEY_INACTIVE_DAYS_OFFLINE + group:GROUP_ACCOUNT_STATUS] ?: @""; + [textField_inactiveDaysOffline setStringValue:inactiveDaysOffline]; + + NSString *historyRetrievalThreshold = [account + preferenceForKey:@"Telegram:"TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD + group:GROUP_ACCOUNT_STATUS] ?: @""; + [textField_historyRetrieveDays setStringValue:historyRetrievalThreshold]; +} + +- (void)saveConfiguration +{ + [super saveConfiguration]; + + NSArray *selections = @[@"ask", @"always", @"never"]; + + [account setPreference:selections[[radio_Encryption selectedRow]] + forKey:@"Telegram:"TGP_KEY_ACCEPT_SECRET_CHATS + group:GROUP_ACCOUNT_STATUS]; + + [account setPreference:[NSNumber numberWithBool:[checkbox_historySyncAll state]] + forKey:@"Telegram:"TGP_KEY_HISTORY_SYNC_ALL + group:GROUP_ACCOUNT_STATUS]; + + [account setPreference:[NSNumber numberWithBool:[checkbox_displayReadNotifications state]] + forKey:@"Telegram:"TGP_KEY_DISPLAY_READ_NOTIFICATIONS + group:GROUP_ACCOUNT_STATUS]; + + [account setPreference:[textField_historyRetrieveDays stringValue] + forKey:@"Telegram:"TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD + group:GROUP_ACCOUNT_STATUS]; + + [account setPreference:[textField_inactiveDaysOffline stringValue] + forKey:@"Telegram:"TGP_KEY_INACTIVE_DAYS_OFFLINE + group:GROUP_ACCOUNT_STATUS]; +} + +@end diff --git a/telegram-adium/TelegramService.m b/telegram-adium/TelegramService.m index 1faa49e..7220672 100644 --- a/telegram-adium/TelegramService.m +++ b/telegram-adium/TelegramService.m @@ -18,6 +18,7 @@ #import "TelegramService.h" #import "AdiumTelegramAccount.h" +#import "TelegramAccountViewController.h" #import #import @@ -28,6 +29,9 @@ return [AdiumTelegramAccount class]; } +- (AIAccountViewController *)accountViewController{ + return [TelegramAccountViewController accountViewController]; +} //Service Description - (NSString *)serviceCodeUniqueID{ return @"prpl-telegram"; diff --git a/telegram-adium/telegram-adium.xcodeproj/project.pbxproj b/telegram-adium/telegram-adium.xcodeproj/project.pbxproj index 543223c..8f9dc10 100644 --- a/telegram-adium/telegram-adium.xcodeproj/project.pbxproj +++ b/telegram-adium/telegram-adium.xcodeproj/project.pbxproj @@ -35,6 +35,9 @@ C487A1911A792EA50044F135 /* libglib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C487A18F1A792EA50044F135 /* libglib.framework */; }; C487A1921A792EA50044F135 /* libpurple.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C487A1901A792EA50044F135 /* libpurple.framework */; }; C49A915819BBC5C5001B3DC0 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C49A915719BBC5C5001B3DC0 /* libz.dylib */; }; + C4B4BE2E1AB392F80064AC17 /* TelegramAccountView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C4B4BE2D1AB392F80064AC17 /* TelegramAccountView.xib */; }; + C4B4BE311AB393800064AC17 /* TelegramAccountViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C4B4BE2F1AB393800064AC17 /* TelegramAccountViewController.m */; }; + C4B4BE331AB4536F0064AC17 /* PurpleDefaultsTelegram.plist in Resources */ = {isa = PBXBuildFile; fileRef = C4B4BE321AB4536F0064AC17 /* PurpleDefaultsTelegram.plist */; }; C4D819031A5C85FE0044CBA9 /* lodepng.c in Sources */ = {isa = PBXBuildFile; fileRef = C4D819011A5C85FE0044CBA9 /* lodepng.c */; }; C4D819061A5C862E0044CBA9 /* tgp-structs.c in Sources */ = {isa = PBXBuildFile; fileRef = C4D819041A5C862E0044CBA9 /* tgp-structs.c */; }; C4E528111A8A907200C4B915 /* tgp-ft.c in Sources */ = {isa = PBXBuildFile; fileRef = C4E5280F1A8A907200C4B915 /* tgp-ft.c */; }; @@ -85,6 +88,10 @@ C487A18F1A792EA50044F135 /* libglib.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = libglib.framework; path = Frameworks/Adium/libglib.framework; sourceTree = ""; }; C487A1901A792EA50044F135 /* libpurple.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = libpurple.framework; path = Frameworks/Adium/libpurple.framework; sourceTree = ""; }; C49A915719BBC5C5001B3DC0 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; + C4B4BE2D1AB392F80064AC17 /* TelegramAccountView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TelegramAccountView.xib; sourceTree = ""; }; + C4B4BE2F1AB393800064AC17 /* TelegramAccountViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TelegramAccountViewController.m; sourceTree = ""; }; + C4B4BE301AB393800064AC17 /* TelegramAccountViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TelegramAccountViewController.h; sourceTree = ""; }; + C4B4BE321AB4536F0064AC17 /* PurpleDefaultsTelegram.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = PurpleDefaultsTelegram.plist; sourceTree = ""; }; C4D819011A5C85FE0044CBA9 /* lodepng.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lodepng.c; sourceTree = ""; }; C4D819021A5C85FE0044CBA9 /* lodepng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lodepng.h; sourceTree = ""; }; C4D819041A5C862E0044CBA9 /* tgp-structs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "tgp-structs.c"; path = "../tgp-structs.c"; sourceTree = ""; }; @@ -117,9 +124,10 @@ C410947D19BB2D7D0083BF3F = { isa = PBXGroup; children = ( + C4B4BE321AB4536F0064AC17 /* PurpleDefaultsTelegram.plist */, + C438CE251A12BEAF00E1DA0F /* telegram22.png */, C438CE231A12BEAF00E1DA0F /* telegram.png */, C438CE241A12BEAF00E1DA0F /* telegram16.png */, - C438CE251A12BEAF00E1DA0F /* telegram22.png */, C438CE261A12BEAF00E1DA0F /* telegram48.png */, C410949919BB337A0083BF3F /* TelegramPlugin.h */, C410949A19BB337A0083BF3F /* TelegramPlugin.m */, @@ -127,6 +135,9 @@ C4877C1719BB37EA006FA91F /* TelegramService.m */, C4877C1C19BB676B006FA91F /* AdiumTelegramAccount.h */, C4877C1D19BB676B006FA91F /* AdiumTelegramAccount.m */, + C4B4BE301AB393800064AC17 /* TelegramAccountViewController.h */, + C4B4BE2F1AB393800064AC17 /* TelegramAccountViewController.m */, + C4B4BE2D1AB392F80064AC17 /* TelegramAccountView.xib */, C4BF990319BB8B200038D507 /* telegram-purple */, C410948B19BB2D7D0083BF3F /* telegram-adium */, C410948819BB2D7D0083BF3F /* Frameworks */, @@ -279,11 +290,13 @@ buildActionMask = 2147483647; files = ( C438CE271A12BEAF00E1DA0F /* telegram.png in Resources */, + C4B4BE2E1AB392F80064AC17 /* TelegramAccountView.xib in Resources */, C438CE281A12BEAF00E1DA0F /* telegram16.png in Resources */, C438CE291A12BEAF00E1DA0F /* telegram22.png in Resources */, C438CE2A1A12BEAF00E1DA0F /* telegram48.png in Resources */, C410949019BB2D7D0083BF3F /* InfoPlist.strings in Resources */, C438CE3D1A12C15100E1DA0F /* tg-server.pub in Resources */, + C4B4BE331AB4536F0064AC17 /* PurpleDefaultsTelegram.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -303,6 +316,7 @@ C4E528111A8A907200C4B915 /* tgp-ft.c in Sources */, C438CE361A12C07800E1DA0F /* tgp-timers.c in Sources */, C410949B19BB337A0083BF3F /* TelegramPlugin.m in Sources */, + C4B4BE311AB393800064AC17 /* TelegramAccountViewController.m in Sources */, C4877C1E19BB676B006FA91F /* AdiumTelegramAccount.m in Sources */, C41D58411A16D88E00B22448 /* tgp-2prpl.c in Sources */, C425F9181A7069C300361AFC /* tgp-utils.c in Sources */, diff --git a/telegram-purple.c b/telegram-purple.c index 1cff300..1a8390a 100755 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -815,32 +815,29 @@ static void tgprpl_init (PurplePlugin *plugin) { ADD_VALUE(verification_values, "Always", "always"); ADD_VALUE(verification_values, "Never", "never"); - opt = purple_account_option_list_new ("Accept Secret Chats", "accept-secret-chats", verification_values); + opt = purple_account_option_list_new ("Accept Secret Chats", + TGP_KEY_ACCEPT_SECRET_CHATS, + verification_values); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt); - opt = purple_account_option_int_new ("Display users not seen for (N) days as offline", - "inactive-days-offline", - TGP_DEFAULT_INACTIVE_DAYS_OFFLINE); + opt = purple_account_option_int_new ("Display peers offline after (days)", + TGP_KEY_INACTIVE_DAYS_OFFLINE, + TGP_DEFAULT_INACTIVE_DAYS_OFFLINE); prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt); - opt = purple_account_option_int_new ("Split oversized messages in up to (N) chunks", - "max-msg-split-count", - TGP_DEFAULT_MAX_MSG_SPLIT_COUNT); + opt = purple_account_option_bool_new ("Fetch past history on first login", + TGP_KEY_HISTORY_SYNC_ALL, + TGP_DEFAULT_HISTORY_SYNC_ALL); prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt); - - opt = purple_account_option_int_new ("Don't fetch messages older than (N) days\n" + + opt = purple_account_option_int_new ("Don't fetch messages older than (days)\n" "(0 for unlimited)", - "history-retrieve-days", + TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD, TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD); prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt); - opt = purple_account_option_bool_new ("Fetch past history on first login " - "(Warning, can be slow)", - "history-sync-all", FALSE); - prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt); - - opt = purple_account_option_bool_new ("Display read notifications (annoying)", - "display-read-notifications", + opt = purple_account_option_bool_new ("Display read notifications", + TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD, TGP_DEFAULT_DISPLAY_READ_NOTIFICATIONS); prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt); diff --git a/telegram-purple.h b/telegram-purple.h index 001805e..3fc4992 100644 --- a/telegram-purple.h +++ b/telegram-purple.h @@ -37,11 +37,22 @@ #define TGP_APP_ID 16154 #define TGP_MAX_MSG_SIZE 4096 -#define TGP_DEFAULT_INACTIVE_DAYS_OFFLINE 7 -#define TGP_DEFAULT_DISPLAY_READ_NOTIFICATIONS FALSE #define TGP_DEFAULT_MAX_MSG_SPLIT_COUNT 4 -#define TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD 14 +#define TGP_DEFAULT_ACCEPT_SECRET_CHATS "ask" +#define TGP_KEY_ACCEPT_SECRET_CHATS "accept-secret-chats" + +#define TGP_DEFAULT_INACTIVE_DAYS_OFFLINE 7 +#define TGP_KEY_INACTIVE_DAYS_OFFLINE "inactive-days-offline" + +#define TGP_DEFAULT_DISPLAY_READ_NOTIFICATIONS FALSE +#define TGP_KEY_DISPLAY_READ_NOTIFICATIONS "display-read-notifications" + +#define TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD 14 +#define TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD "history-retrieve-days" + +#define TGP_KEY_HISTORY_SYNC_ALL "history-sync-all" +#define TGP_DEFAULT_HISTORY_SYNC_ALL FALSE void on_chat_get_info (struct tgl_state *TLS, void *extra, int success, struct tgl_chat *C); void on_ready (struct tgl_state *TLS); diff --git a/tgp-msg.c b/tgp-msg.c index 583a6bc..8bc23d7 100644 --- a/tgp-msg.c +++ b/tgp-msg.c @@ -162,9 +162,7 @@ static void tgp_msg_send_done (struct tgl_state *TLS, void *callback_extra, int } static int tgp_msg_send_split (struct tgl_state *TLS, const char *message, tgl_peer_id_t to) { - connection_data *data = TLS->ev_base; - int max = purple_account_get_int (data->pa, "max-msg-split-count", - TGP_DEFAULT_MAX_MSG_SPLIT_COUNT); + int max = TGP_DEFAULT_MAX_MSG_SPLIT_COUNT; if (max < 1) { max = 1; }