` that follows it).
+ val zoneMatch = Regex("class=\"edit-zone\"[^>]*>").find(s)
+ if (zoneMatch != null) {
+ s = s.substring(zoneMatch.range.last + 1)
+ val floatIdx = s.indexOf("
= 0) s = s.substring(0, floatIdx)
+ }
+
+ s = s.replace(Regex("
", RegexOption.IGNORE_CASE), "\n")
+ s = s.replace(Regex("(div|p|li|ul|ol|tr|h[1-6])>", RegexOption.IGNORE_CASE), "\n")
+ s = s.replace(Regex("<[^>]+>"), "")
+ s = decodeEntities(s)
+
+ // Normalise whitespace: drop trailing spaces per line, collapse
+ // runs of 2+ blank lines to a single blank line.
+ val lines = s.replace("\r", "").split('\n').map { it.trimEnd() }
+ val collapsed = StringBuilder()
+ var blanks = 0
+ for (line in lines) {
+ if (line.isEmpty()) {
+ blanks++
+ if (blanks <= 1) collapsed.append('\n')
+ } else {
+ blanks = 0
+ collapsed.append(line).append('\n')
+ }
+ }
+ return collapsed.toString().trim()
+ }
+
+ /** Decode the named + numeric HTML entities a Carnet body can contain. */
+ private fun decodeEntities(input: String): String {
+ if (!input.contains('&')) return input
+ val sb = StringBuilder(input.length)
+ var i = 0
+ while (i < input.length) {
+ val c = input[i]
+ if (c == '&') {
+ val semi = input.indexOf(';', i + 1)
+ if (semi in (i + 1)..(i + 12)) {
+ val entity = input.substring(i, semi + 1)
+ val decoded = NAMED_ENTITIES[entity] ?: numericEntity(entity)
+ if (decoded != null) {
+ sb.append(decoded)
+ i = semi + 1
+ continue
+ }
+ }
+ }
+ sb.append(c)
+ i++
+ }
+ return sb.toString()
+ }
+
+ private fun numericEntity(entity: String): String? {
+ if (!entity.startsWith("") || !entity.endsWith(";")) return null
+ val body = entity.substring(2, entity.length - 1)
+ return try {
+ val code = if (body.startsWith("x") || body.startsWith("X")) {
+ body.substring(1).toLong(16)
+ } else {
+ body.toLong()
+ }
+ if (code in 0..0x10FFFF) String(Character.toChars(code.toInt())) else null
+ } catch (_: NumberFormatException) {
+ null
+ }
+ }
+
+ private val NAMED_ENTITIES = mapOf(
+ " " to " ",
+ "&" to "&",
+ "<" to "<",
+ ">" to ">",
+ """ to "\"",
+ "'" to "'",
+ "'" to "'",
+ "©" to "\u00A9",
+ "®" to "\u00AE",
+ "™" to "\u2122",
+ "…" to "\u2026",
+ "—" to "\u2014",
+ "–" to "\u2013",
+ "’" to "\u2019",
+ "‘" to "\u2018",
+ "”" to "\u201D",
+ "“" to "\u201C",
+ )
+
+ }
+
+ // --- Data ----------------------------------------------------------------
+
+ /** A parsed, ready-to-persist Carnet note. */
+ data class ParsedSqd(
+ val content: String,
+ val createdAt: Long,
+ val updatedAt: Long,
+ val isFavorite: Boolean,
+ val color: NoteColor,
+ val type: NoteType,
+ val keywords: List
,
+ val attachments: List,
+ ) {
+ fun hasContent(): Boolean = content.isNotBlank() || attachments.isNotEmpty()
+ }
+
+ /** A single attachment (file name + raw bytes) inside a `.sqd`'s `data/`. */
+ data class Attachment(val displayName: String, val bytes: ByteArray)
+
+ @Serializable
+ private data class CarnetMetadata(
+ @SerialName("creation_date") val creationDate: Long = 0,
+ @SerialName("last_modification_date") val lastModificationDate: Long = 0,
+ val keywords: List = emptyList(),
+ val rating: Int = -1,
+ val color: String = "none",
+ val urls: Map = emptyMap(),
+ val todolists: List = emptyList(),
+ )
+
+ @Serializable
+ private data class CarnetTodo(
+ val id: String = "",
+ val todo: List = emptyList(),
+ val done: List = emptyList(),
+ )
+}
+
+
+
diff --git a/composeApp/src/main/kotlin/org/incido/compose/di/AppContainer.kt b/composeApp/src/main/kotlin/org/incido/compose/di/AppContainer.kt
index cb7d6f2..55e68e4 100644
--- a/composeApp/src/main/kotlin/org/incido/compose/di/AppContainer.kt
+++ b/composeApp/src/main/kotlin/org/incido/compose/di/AppContainer.kt
@@ -11,6 +11,7 @@ import org.incido.data.crypto.NoteCryptoService
import org.incido.data.repository.NoteRepositoryImpl
import org.incido.domain.repository.NoteRepository
import org.incido.compose.data.backup.BackupManager
+import org.incido.compose.data.backup.CarnetImporter
import org.incido.compose.data.security.AesGcmFieldCipher
import org.incido.compose.data.security.EncryptionVerifier
import org.incido.compose.data.security.ObjectBoxKeyProvider
@@ -78,6 +79,10 @@ class AppContainer(context: Context) {
val backupManager: BackupManager = BackupManager(appContext, noteRepository)
+ /** v0.3.9.0 — Carnet / QuickNote `.sqd` archive importer. */
+ val carnetImporter: CarnetImporter = CarnetImporter(appContext, noteRepository)
+
+
/** Migration sweep + startup integrity checker for the note store. */
val noteCryptoService = NoteCryptoService(boxStore, cipherHolder)
diff --git a/composeApp/src/main/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt b/composeApp/src/main/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt
index f379111..b12974e 100644
--- a/composeApp/src/main/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt
+++ b/composeApp/src/main/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt
@@ -122,6 +122,15 @@ fun SettingsScreen(
var showRecoveryImportWarning by remember { mutableStateOf(false) }
// SAF launchers
+ // v0.3.9.0 — Carnet / QuickNote archive importer. Picks a .zip (or a
+ // lone .sqd) and imports it directly; no passphrase, additive.
+ val carnetImportLauncher = rememberLauncherForActivityResult(
+ contract = ActivityResultContracts.OpenDocument(),
+ ) { uri ->
+ if (uri == null) return@rememberLauncherForActivityResult
+ scope.launch { viewModel.importCarnet(uri) }
+ }
+
val exportLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.CreateDocument("application/json"),
) { uri ->
@@ -296,6 +305,12 @@ fun SettingsScreen(
securityManager?.beginExternalActivity()
importLauncher.launch(arrayOf("application/json", "*/*"))
},
+ onImportCarnet = {
+ securityManager?.beginExternalActivity()
+ carnetImportLauncher.launch(
+ arrayOf("application/zip", "application/x-zip-compressed", "application/octet-stream", "*/*"),
+ )
+ },
)
AboutSection(
version = SettingsViewModel.APP_VERSION,
@@ -825,6 +840,7 @@ private fun SecuritySection(
private fun BackupSection(
onExport: () -> Unit,
onImport: () -> Unit,
+ onImportCarnet: () -> Unit,
) {
SettingsSection(title = "Backup & Restore") {
Column(
@@ -846,6 +862,9 @@ private fun BackupSection(
OutlinedButton(onClick = onImport, modifier = Modifier.fillMaxWidth()) {
Text("Import from file…")
}
+ OutlinedButton(onClick = onImportCarnet, modifier = Modifier.fillMaxWidth()) {
+ Text("Import 3rd Party Notes")
+ }
}
}
}
diff --git a/composeApp/src/main/kotlin/org/incido/compose/ui/settings/SettingsViewModel.kt b/composeApp/src/main/kotlin/org/incido/compose/ui/settings/SettingsViewModel.kt
index 2502570..b6f80f3 100644
--- a/composeApp/src/main/kotlin/org/incido/compose/ui/settings/SettingsViewModel.kt
+++ b/composeApp/src/main/kotlin/org/incido/compose/ui/settings/SettingsViewModel.kt
@@ -14,6 +14,7 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import org.incido.compose.IncidoApplication
import org.incido.compose.data.backup.BackupManager
+import org.incido.compose.data.backup.CarnetImporter
import org.incido.compose.data.security.AesGcmFieldCipher
import org.incido.compose.data.security.EncryptionVerifier
import org.incido.compose.data.security.ObjectBoxKeyProvider
@@ -46,6 +47,7 @@ class SettingsViewModel(
private val security: SecurityManager,
private val objectBoxKeyProvider: ObjectBoxKeyProvider,
private val backupManager: BackupManager,
+ private val carnetImporter: CarnetImporter,
private val noteCryptoService: NoteCryptoService,
private val cipherHolder: CipherHolder,
private val encryptionVerifier: EncryptionVerifier,
@@ -245,6 +247,25 @@ class SettingsViewModel(
_snackbar.value = "Imported $count note(s)."
}
+ /**
+ * v0.3.9.0 — import a Carnet / QuickNote archive (`.zip` of `*.sqd`, or a
+ * single `.sqd`) picked via SAF. Additive — existing notes are kept.
+ * Failures are caught and surfaced via the snackbar so a bad file never
+ * crashes the app.
+ */
+ suspend fun importCarnet(uri: android.net.Uri) {
+ try {
+ val count = carnetImporter.import(uri)
+ _snackbar.value = if (count > 0) {
+ "Imported $count Carnet note(s)."
+ } else {
+ "No Carnet notes found in that file."
+ }
+ } catch (e: Exception) {
+ _snackbar.value = "Carnet import failed: ${e.message ?: "unreadable file"}"
+ }
+ }
+
// --- v0.3.6.0 recovery key ---
/**
@@ -344,6 +365,7 @@ class SettingsViewModel(
security = c.securityManager,
objectBoxKeyProvider = c.objectBoxKeyProvider,
backupManager = c.backupManager,
+ carnetImporter = c.carnetImporter,
noteCryptoService = c.noteCryptoService,
cipherHolder = c.cipherHolder,
encryptionVerifier = c.encryptionVerifier,