Преглед на файлове

Merge pull request #333 from deltachat/set-stock-translations

adapt to new set-stock-translations api
björn petersen преди 5 години
родител
ревизия
93fa67d734

+ 37 - 1
deltachat-ios/AppDelegate.swift

@@ -32,7 +32,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     private func getCoreInfo() -> [[String]] {
         if let cString = dc_get_info(mailboxPointer) {
             let info = String(cString: cString)
-            free(cString)
+            dc_str_unref(cString)
             logger.info(info)
             return info.components(separatedBy: "\n").map { val in
                 val.components(separatedBy: "=")
@@ -73,6 +73,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         appCoordinator.start()
         UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
         start()
+        setStockTranslations()
         if !isConfigured {
             appCoordinator.presentLoginController()
         }
@@ -145,6 +146,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         _ = dc_open(mailboxPointer, dbfile(), nil)
     }
 
+    func setStockTranslations() {
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_NOMESSAGES), String.localized("chat_no_messages"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_SELF), String.localized("self"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_DRAFT), String.localized("draft"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_VOICEMESSAGE), String.localized("voice_message"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_DEADDROP), String.localized("chat_contact_request"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_IMAGE), String.localized("image"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_VIDEO), String.localized("video"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_AUDIO), String.localized("audio"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_FILE), String.localized("file"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_STATUSLINE), String.localized("pref_default_status_text"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_NEWGROUPDRAFT), String.localized("group_hello_draft"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_MSGGRPNAME), String.localized("systemmsg_group_name_changed"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_MSGGRPIMGCHANGED), String.localized("systemmsg_group_image_changed"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_MSGADDMEMBER), String.localized("systemmsg_member_added"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_MSGDELMEMBER), String.localized("systemmsg_member_removed"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_MSGGROUPLEFT), String.localized("systemmsg_group_left"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_GIF), String.localized("gif"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_CANTDECRYPT_MSG_BODY), String.localized("systemmsg_cannot_decrypt"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_READRCPT), String.localized("systemmsg_read_receipt_subject"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_READRCPT_MAILBODY), String.localized("systemmsg_read_receipt_body"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_MSGGRPIMGDELETED), String.localized("systemmsg_group_image_deleted"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_CONTACT_VERIFIED), String.localized("contact_verified"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_CONTACT_NOT_VERIFIED), String.localized("contact_not_verified"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_CONTACT_SETUP_CHANGED), String.localized("contact_setup_changed"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_ARCHIVEDCHATS), String.localized("chat_archived_chats_title"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_AC_SETUP_MSG_SUBJECT), String.localized("autocrypt_asm_subject"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_AC_SETUP_MSG_BODY), String.localized("autocrypt_asm_general_body"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_SELFTALK_SUBTITLE), String.localized("chat_self_talk_subtitle"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_CANNOT_LOGIN), String.localized("login_error_cannot_login"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_SERVER_RESPONSE), String.localized("login_error_server_response"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_MSGACTIONBYUSER), String.localized("systemmsg_action_by_user"))
+        dc_set_stock_translation(mailboxPointer, UInt32(DC_STR_MSGACTIONBYME), String.localized("systemmsg_action_by_me"))
+    }
+
     func stop() {
         state = .background
 

+ 1 - 1
deltachat-ios/Controller/AccountSetupController.swift

@@ -579,7 +579,7 @@ class AccountSetupController: UITableViewController {
 
             if let cString = dc_imex_has_backup(mailboxPointer, documents[0]) {
                 let file = String(cString: cString)
-                free(cString)
+                dc_str_unref(cString)
                 logger.info("restoring backup: \(file)")
                 showProgressHud()
                 dc_imex(mailboxPointer, DC_IMEX_IMPORT_BACKUP, file, nil)

+ 1 - 1
deltachat-ios/Controller/ChatViewController.swift

@@ -200,7 +200,7 @@ class ChatViewController: MessagesViewController {
         if let draft = dc_get_draft(mailboxPointer, UInt32(chatId)) {
             if let cString = dc_msg_get_text(draft) {
                 let swiftString = String(cString: cString)
-                free(cString)
+                dc_str_unref(cString)
                 dc_msg_unref(draft)
                 return swiftString
             }

+ 20 - 20
deltachat-ios/DC/Wrapper.swift

@@ -38,7 +38,7 @@ class DcContext {
     func getSecurejoinQr (chatId: Int) -> String? {
         if let cString = dc_get_securejoin_qr(self.contextPointer, UInt32(chatId)) {
             let swiftString = String(cString: cString)
-            free(cString)
+            dc_str_unref(cString)
             return swiftString
         }
         return nil
@@ -59,7 +59,7 @@ class DcContext {
     func getMsgInfo(msgId: Int) -> String {
         if let cString = dc_get_msg_info(self.contextPointer, UInt32(msgId)) {
             let swiftString = String(cString: cString)
-            free(cString)
+            dc_str_unref(cString)
             return swiftString
         }
         return "ErrGetMsgInfo"
@@ -68,7 +68,7 @@ class DcContext {
     func initiateKeyTransfer() -> String? {
         if let cString = dc_initiate_key_transfer(self.contextPointer) {
             let swiftString = String(cString: cString)
-            free(cString)
+            dc_str_unref(cString)
             return swiftString
         }
         return nil
@@ -83,7 +83,7 @@ class DcConfig {
     private class func getConfig(_ key: String) -> String? {
         guard let cString = dc_get_config(mailboxPointer, key) else { return nil }
         let value = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         if value.isEmpty {
             return nil
         }
@@ -372,7 +372,7 @@ class DcChat {
     var name: String {
         guard let cString = dc_chat_get_name(chatPointer) else { return "" }
         let swiftString = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         return swiftString
     }
 
@@ -399,7 +399,7 @@ class DcChat {
     lazy var profileImage: UIImage? = { [unowned self] in
         guard let cString = dc_chat_get_profile_image(chatPointer) else { return nil }
         let filename = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         let path: URL = URL(fileURLWithPath: filename, isDirectory: false)
         if path.isFileURL {
             do {
@@ -417,7 +417,7 @@ class DcChat {
     var subtitle: String? {
         if let cString = dc_chat_get_subtitle(chatPointer) {
             let str = String(cString: cString)
-            free(cString)
+            dc_str_unref(cString)
             return str.isEmpty ? nil : str
         }
         return nil
@@ -526,7 +526,7 @@ class DcMsg: MessageType {
     var text: String? {
         guard let cString = dc_msg_get_text(messagePointer) else { return nil }
         let swiftString = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         return swiftString
     }
 
@@ -584,7 +584,7 @@ class DcMsg: MessageType {
     var file: String? {
         if let cString = dc_msg_get_file(messagePointer) {
             let str = String(cString: cString)
-            free(cString)
+            dc_str_unref(cString)
             return str.isEmpty ? nil : str
         }
 
@@ -594,7 +594,7 @@ class DcMsg: MessageType {
     var filemime: String? {
         if let cString = dc_msg_get_filemime(messagePointer) {
             let str = String(cString: cString)
-            free(cString)
+            dc_str_unref(cString)
             return str.isEmpty ? nil : str
         }
 
@@ -604,7 +604,7 @@ class DcMsg: MessageType {
     var filename: String? {
         if let cString = dc_msg_get_filename(messagePointer) {
             let str = String(cString: cString)
-            free(cString)
+            dc_str_unref(cString)
             return str.isEmpty ? nil : str
         }
 
@@ -663,14 +663,14 @@ class DcMsg: MessageType {
     var setupCodeBegin: String {
         guard let cString = dc_msg_get_setupcodebegin(messagePointer) else { return "" }
         let swiftString = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         return swiftString
     }
 
     func summary(chars: Int) -> String? {
         guard let cString = dc_msg_get_summarytext(messagePointer, Int32(chars)) else { return nil }
         let swiftString = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         return swiftString
     }
 
@@ -694,28 +694,28 @@ class DcContact {
     var displayName: String {
         guard let cString = dc_contact_get_display_name(contactPointer) else { return "" }
         let swiftString = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         return swiftString
     }
 
     var nameNAddr: String {
         guard let cString = dc_contact_get_name_n_addr(contactPointer) else { return "" }
         let swiftString = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         return swiftString
     }
 
     var name: String {
         guard let cString = dc_contact_get_name(contactPointer) else { return "" }
         let swiftString = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         return swiftString
     }
 
     var email: String {
         guard let cString = dc_contact_get_addr(contactPointer) else { return "" }
         let swiftString = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         return swiftString
     }
 
@@ -730,7 +730,7 @@ class DcContact {
     lazy var profileImage: UIImage? = { [unowned self] in
         guard let cString = dc_contact_get_profile_image(contactPointer) else { return nil }
         let filename = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         let path: URL = URL(fileURLWithPath: filename, isDirectory: false)
         if path.isFileURL {
             do {
@@ -780,7 +780,7 @@ class DcLot {
     var text1: String? {
         guard let cString = dc_lot_get_text1(dcLotPointer) else { return nil }
         let swiftString = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         return swiftString
     }
 
@@ -791,7 +791,7 @@ class DcLot {
     var text2: String? {
         guard let cString = dc_lot_get_text2(dcLotPointer) else { return nil }
         let swiftString = String(cString: cString)
-        free(cString)
+        dc_str_unref(cString)
         return swiftString
     }
 

+ 0 - 40
deltachat-ios/DC/events.swift

@@ -166,46 +166,6 @@ public func callbackSwift(event: CInt, data1: CUnsignedLong, data2: CUnsignedLon
             )
         }
 
-    case DC_EVENT_GET_STRING:
-        var string = ""
-        switch Int32(data1) {
-        case DC_STR_NOMESSAGES: string = String.localized("chat_no_messages")
-        case DC_STR_SELF: string = String.localized("self")
-        case DC_STR_DRAFT: string = String.localized("draft")
-        case DC_STR_MEMBER: return nil // we create this string in hackPluralsString()
-        case DC_STR_VOICEMESSAGE: string = String.localized("voice_message")
-        case DC_STR_DEADDROP: string = String.localized("chat_contact_request")
-        case DC_STR_IMAGE: string = String.localized("image")
-        case DC_STR_VIDEO: string = String.localized("video")
-        case DC_STR_AUDIO: string = String.localized("audio")
-        case DC_STR_FILE: string = String.localized("file")
-        case DC_STR_STATUSLINE: string = String.localized("pref_default_status_text")
-        case DC_STR_NEWGROUPDRAFT: string = String.localized("group_hello_draft")
-        case DC_STR_MSGGRPNAME: string = String.localized("systemmsg_group_name_changed")
-        case DC_STR_MSGGRPIMGCHANGED: string = String.localized("systemmsg_group_image_changed")
-        case DC_STR_MSGADDMEMBER: string = String.localized("systemmsg_member_added")
-        case DC_STR_MSGDELMEMBER: string = String.localized("systemmsg_member_removed")
-        case DC_STR_MSGGROUPLEFT: string = String.localized("systemmsg_group_left")
-        case DC_STR_GIF: string = String.localized("gif")
-        case DC_STR_CANTDECRYPT_MSG_BODY: string = String.localized("systemmsg_cannot_decrypt")
-        case DC_STR_READRCPT: string = String.localized("systemmsg_read_receipt_subject")
-        case DC_STR_READRCPT_MAILBODY: string = String.localized("systemmsg_read_receipt_body")
-        case DC_STR_MSGGRPIMGDELETED: string = String.localized("systemmsg_group_image_deleted")
-        case DC_STR_CONTACT_VERIFIED: string = String.localized("contact_verified")
-        case DC_STR_CONTACT_NOT_VERIFIED: string = String.localized("contact_not_verified")
-        case DC_STR_CONTACT_SETUP_CHANGED: string = String.localized("contact_setup_changed")
-        case DC_STR_ARCHIVEDCHATS: string = String.localized("chat_archived_chats_title")
-        case DC_STR_AC_SETUP_MSG_SUBJECT: string = String.localized("autocrypt_asm_subject")
-        case DC_STR_AC_SETUP_MSG_BODY: string = String.localized("autocrypt_asm_general_body")
-        case DC_STR_SELFTALK_SUBTITLE: string = String.localized("chat_self_talk_subtitle")
-        case DC_STR_CANNOT_LOGIN: string = String.localized("login_error_cannot_login")
-        case DC_STR_SERVER_RESPONSE: string = String.localized("login_error_server_response")
-        case DC_STR_MSGACTIONBYUSER: string = String.localized("systemmsg_action_by_user")
-        case DC_STR_MSGACTIONBYME: string = String.localized("systemmsg_action_by_me")
-        default: return nil
-        }
-        return UnsafePointer(strdup(string))
-
     default:
         logger.warning("unknown event: \(event)")
     }