diff --git a/vripper-core/src/main/kotlin/me/vripper/event/Event.kt b/vripper-core/src/main/kotlin/me/vripper/event/Event.kt index c20c4164..b3f4a23e 100644 --- a/vripper-core/src/main/kotlin/me/vripper/event/Event.kt +++ b/vripper-core/src/main/kotlin/me/vripper/event/Event.kt @@ -11,6 +11,7 @@ data class PostUpdateEvent(val posts: List) data class PostDeleteEvent(val postIds: List) data class ImageEvent(val images: List) data class ThreadCreateEvent(val thread: Thread) +data class ThreadUpdateEvent(val thread: Thread) data class ThreadDeleteEvent(val threadId: Long) class ThreadClearEvent data class VGUserLoginEvent(val username: String) diff --git a/vripper-core/src/main/kotlin/me/vripper/parser/PostLookupAPIParser.kt b/vripper-core/src/main/kotlin/me/vripper/parser/PostLookupAPIParser.kt new file mode 100644 index 00000000..1e930368 --- /dev/null +++ b/vripper-core/src/main/kotlin/me/vripper/parser/PostLookupAPIParser.kt @@ -0,0 +1,75 @@ +package me.vripper.parser + +import me.vripper.entities.LogEntry +import me.vripper.exception.DownloadException +import me.vripper.exception.PostParseException +import me.vripper.model.PostItem +import me.vripper.services.* +import me.vripper.utilities.Tasks +import me.vripper.utilities.formatToString +import net.jodah.failsafe.Failsafe +import net.jodah.failsafe.function.CheckedSupplier +import org.apache.hc.client5.http.classic.HttpClient +import org.apache.hc.client5.http.classic.methods.HttpGet +import org.apache.hc.core5.net.URIBuilder +import org.koin.core.component.KoinComponent +import org.koin.core.component.inject +import javax.xml.parsers.SAXParserFactory + +class PostLookupAPIParser(private val threadId: Long, private val postId: Long) : KoinComponent { + private val log by me.vripper.delegate.LoggerDelegate() + private val settingsService: SettingsService by inject() + private val retryPolicyService: RetryPolicyService by inject() + private val httpService: HTTPService by inject() + private val vgAuthService: VGAuthService by inject() + private val dataTransaction: DataTransaction by inject() + + @Throws(PostParseException::class) + fun parse(): PostItem { + log.debug("Parsing post $postId") + val httpGet = + HttpGet(URIBuilder("${settingsService.settings.viperSettings.host}/vr.php").also { + it.setParameter( + "p", postId.toString() + ) + }.build()) + val threadLookupAPIResponseHandler = ThreadLookupAPIResponseHandler() + log.debug("Requesting {}", httpGet) + Tasks.increment() + return try { + Failsafe.with(retryPolicyService.buildGenericRetryPolicy()).onFailure { + log.error( + "parsing failed for thread $threadId, post $postId", it.failure + ) + dataTransaction.saveLog( + LogEntry( + type = LogEntry.Type.POST, status = LogEntry.Status.ERROR, message = """ + Failed to process thread $threadId, post $postId + ${it.failure.formatToString()} + """.trimIndent() + ) + ) + }.get(CheckedSupplier { + val connection: HttpClient = httpService.client + connection.execute( + httpGet, vgAuthService.context + ) { response -> + if (response.code / 100 != 2) { + throw DownloadException("Unexpected response code '${response.code}' for $httpGet") + } + factory.newSAXParser() + .parse(response.entity.content, threadLookupAPIResponseHandler) + threadLookupAPIResponseHandler.result.postItemList.first() + } + }) + } catch (e: Exception) { + throw PostParseException(e) + } finally { + Tasks.decrement() + } + } + + companion object { + private val factory = SAXParserFactory.newInstance() + } +} \ No newline at end of file diff --git a/vripper-core/src/main/kotlin/me/vripper/parser/ThreadLookupAPIParser.kt b/vripper-core/src/main/kotlin/me/vripper/parser/ThreadLookupAPIParser.kt index 6350113c..b53c9f8e 100644 --- a/vripper-core/src/main/kotlin/me/vripper/parser/ThreadLookupAPIParser.kt +++ b/vripper-core/src/main/kotlin/me/vripper/parser/ThreadLookupAPIParser.kt @@ -1,12 +1,12 @@ package me.vripper.parser +import me.vripper.entities.LogEntry import me.vripper.exception.DownloadException import me.vripper.exception.PostParseException import me.vripper.model.ThreadItem -import me.vripper.services.HTTPService -import me.vripper.services.RetryPolicyService -import me.vripper.services.SettingsService -import me.vripper.services.VGAuthService +import me.vripper.services.* +import me.vripper.utilities.Tasks +import me.vripper.utilities.formatToString import net.jodah.failsafe.Failsafe import net.jodah.failsafe.function.CheckedSupplier import org.apache.hc.client5.http.classic.methods.HttpGet @@ -23,6 +23,7 @@ class ThreadLookupAPIParser(private val threadId: Long) : KoinComponent { private val retryPolicyService: RetryPolicyService by inject() private val vgAuthService: VGAuthService by inject() private val settingsService: SettingsService by inject() + private val dataTransaction: DataTransaction by inject() @Throws(PostParseException::class) fun parse(): ThreadItem { @@ -36,12 +37,21 @@ class ThreadLookupAPIParser(private val threadId: Long) : KoinComponent { }.build()) val threadLookupAPIResponseHandler = ThreadLookupAPIResponseHandler() log.debug("Requesting {}", httpGet) + Tasks.increment() return try { Failsafe.with(retryPolicyService.buildGenericRetryPolicy()).onFailure { log.error( "parsing failed for thread $threadId", it.failure ) + dataTransaction.saveLog( + LogEntry( + type = LogEntry.Type.THREAD, status = LogEntry.Status.ERROR, message = """ + Failed to process thread $threadId + ${it.failure.formatToString()} + """.trimIndent() + ) + ) }.get(CheckedSupplier { cm.client.execute( httpGet, vgAuthService.context @@ -58,6 +68,8 @@ class ThreadLookupAPIParser(private val threadId: Long) : KoinComponent { }) } catch (e: Exception) { throw PostParseException(e) + } finally { + Tasks.decrement() } } diff --git a/vripper-core/src/main/kotlin/me/vripper/parser/ThreadLookupAPIResponseHandler.kt b/vripper-core/src/main/kotlin/me/vripper/parser/ThreadLookupAPIResponseHandler.kt index f549dc9b..ca355c94 100644 --- a/vripper-core/src/main/kotlin/me/vripper/parser/ThreadLookupAPIResponseHandler.kt +++ b/vripper-core/src/main/kotlin/me/vripper/parser/ThreadLookupAPIResponseHandler.kt @@ -78,7 +78,7 @@ class ThreadLookupAPIResponseHandler : KoinComponent, DefaultHandler() { postCounter, postTitle, imageItemList.size, - "${settingsService.settings.viperSettings.host}/threads/?p=$postId&viewfull=1#post$postId", + "${settingsService.settings.viperSettings.host}/threads/$threadId?p=$postId&viewfull=1#post$postId", hostMap.toMap().map { Pair(it.key.hostName, it.value) }, securityToken, forum, diff --git a/vripper-core/src/main/kotlin/me/vripper/repositories/ThreadRepository.kt b/vripper-core/src/main/kotlin/me/vripper/repositories/ThreadRepository.kt index 18c2a070..e3a73930 100644 --- a/vripper-core/src/main/kotlin/me/vripper/repositories/ThreadRepository.kt +++ b/vripper-core/src/main/kotlin/me/vripper/repositories/ThreadRepository.kt @@ -5,6 +5,7 @@ import java.util.* interface ThreadRepository { fun save(thread: Thread): Thread + fun update(thread: Thread) fun findByThreadId(threadId: Long): Optional fun findAll(): List fun findById(id: Long): Optional diff --git a/vripper-core/src/main/kotlin/me/vripper/repositories/impl/ThreadRepositoryImpl.kt b/vripper-core/src/main/kotlin/me/vripper/repositories/impl/ThreadRepositoryImpl.kt index de22fb93..b1281a16 100644 --- a/vripper-core/src/main/kotlin/me/vripper/repositories/impl/ThreadRepositoryImpl.kt +++ b/vripper-core/src/main/kotlin/me/vripper/repositories/impl/ThreadRepositoryImpl.kt @@ -19,6 +19,13 @@ class ThreadRepositoryImpl : ThreadRepository { return thread.copy(id = id) } + override fun update(thread: Thread) { + ThreadTable.update({ ThreadTable.id eq thread.id }) { + it[title] = thread.title + it[total] = thread.total + } + } + override fun findByThreadId(threadId: Long): Optional { val result = ThreadTable.select { ThreadTable.threadId eq threadId diff --git a/vripper-core/src/main/kotlin/me/vripper/services/AppEndpointService.kt b/vripper-core/src/main/kotlin/me/vripper/services/AppEndpointService.kt index 817164f3..2cd3f1fa 100644 --- a/vripper-core/src/main/kotlin/me/vripper/services/AppEndpointService.kt +++ b/vripper-core/src/main/kotlin/me/vripper/services/AppEndpointService.kt @@ -1,6 +1,7 @@ package me.vripper.services import me.vripper.download.DownloadService +import me.vripper.entities.LogEntry import me.vripper.exception.PostParseException import me.vripper.model.PostItem import me.vripper.model.ThreadPostId @@ -34,6 +35,13 @@ class AppEndpointService( for (link in urlList) { log.debug("Starting to process thread: $link") if (!link.startsWith(settingsService.settings.viperSettings.host)) { + dataTransaction.saveLog( + LogEntry( + type = LogEntry.Type.SCAN, + status = LogEntry.Status.ERROR, + message = "Invalid link $link, only links starting with ${settingsService.settings.viperSettings.host} can be scanned" + ) + ) continue } var threadId: Long @@ -61,6 +69,13 @@ class AppEndpointService( } } else { log.error("Cannot retrieve thread id from URL $link") + dataTransaction.saveLog( + LogEntry( + type = LogEntry.Type.SCAN, + status = LogEntry.Status.ERROR, + message = "Invalid link $link, link is missing the threadId" + ) + ) continue } } diff --git a/vripper-core/src/main/kotlin/me/vripper/services/DataTransaction.kt b/vripper-core/src/main/kotlin/me/vripper/services/DataTransaction.kt index ce963665..cff0d9a0 100644 --- a/vripper-core/src/main/kotlin/me/vripper/services/DataTransaction.kt +++ b/vripper-core/src/main/kotlin/me/vripper/services/DataTransaction.kt @@ -53,6 +53,13 @@ class DataTransaction( } } + fun update(thread: Thread) { + transaction { threadRepository.update(thread) } + coroutineScope.launch { + eventBus.publishEvent(ThreadUpdateEvent(thread)) + } + } + fun updateImages(images: List) { transaction { imageRepository.update(images) } coroutineScope.launch { diff --git a/vripper-core/src/main/kotlin/me/vripper/services/ThreadCacheService.kt b/vripper-core/src/main/kotlin/me/vripper/services/ThreadCacheService.kt index 13ff7ff1..ad6abee4 100644 --- a/vripper-core/src/main/kotlin/me/vripper/services/ThreadCacheService.kt +++ b/vripper-core/src/main/kotlin/me/vripper/services/ThreadCacheService.kt @@ -36,4 +36,8 @@ class ThreadCacheService(val eventBus: EventBus) { operator fun get(threadId: Long): ThreadItem { return cache[threadId] ?: throw NoSuchElementException("$threadId does not exist") } + + fun getIfPresent(threadId: Long): ThreadItem? { + return cache.getIfPresent(threadId) + } } \ No newline at end of file diff --git a/vripper-core/src/main/kotlin/me/vripper/tasks/AddPostRunnable.kt b/vripper-core/src/main/kotlin/me/vripper/tasks/AddPostRunnable.kt index f74d68e8..43d4eb01 100644 --- a/vripper-core/src/main/kotlin/me/vripper/tasks/AddPostRunnable.kt +++ b/vripper-core/src/main/kotlin/me/vripper/tasks/AddPostRunnable.kt @@ -1,33 +1,23 @@ package me.vripper.tasks import me.vripper.download.DownloadService -import me.vripper.entities.LogEntry.Status.* -import me.vripper.exception.DownloadException -import me.vripper.exception.PostParseException import me.vripper.model.PostItem import me.vripper.model.ThreadPostId -import me.vripper.parser.ThreadLookupAPIResponseHandler -import me.vripper.services.* +import me.vripper.parser.PostLookupAPIParser +import me.vripper.services.DataTransaction +import me.vripper.services.MetadataService +import me.vripper.services.SettingsService +import me.vripper.services.ThreadCacheService import me.vripper.utilities.Tasks -import net.jodah.failsafe.Failsafe -import net.jodah.failsafe.function.CheckedSupplier -import org.apache.hc.client5.http.classic.HttpClient -import org.apache.hc.client5.http.classic.methods.HttpGet -import org.apache.hc.core5.net.URIBuilder import org.koin.core.component.KoinComponent import org.koin.core.component.inject -import java.util.* -import javax.xml.parsers.SAXParserFactory class AddPostRunnable(private val items: List) : KoinComponent, Runnable { private val log by me.vripper.delegate.LoggerDelegate() private val dataTransaction: DataTransaction by inject() private val settingsService: SettingsService by inject() - private val vgAuthService: VGAuthService by inject() - private val httpService: HTTPService by inject() - private val retryPolicyService: RetryPolicyService by inject() private val downloadService: DownloadService by inject() - private val cacheService: ThreadCacheService by inject() + private val threadCacheService: ThreadCacheService by inject() private val metadataService: MetadataService by inject() override fun run() { @@ -40,9 +30,12 @@ class AddPostRunnable(private val items: List) : KoinComponent, Ru continue } - val threadItem = cacheService[threadId] + val threadItem = threadCacheService.getIfPresent(threadId) val postItem: PostItem = - threadItem.postItemList.find { it.postId == postId } ?: parse(postId, threadId) + threadItem?.postItemList?.find { it.postId == postId } ?: PostLookupAPIParser( + threadId, + postId + ).parse() toProcess.add(postItem) } @@ -61,42 +54,4 @@ class AddPostRunnable(private val items: List) : KoinComponent, Ru Tasks.decrement() } } - - @Throws(PostParseException::class) - fun parse(postId: Long, threadId: Long): PostItem { - log.debug("Parsing post $postId") - val httpGet = - HttpGet(URIBuilder("${settingsService.settings.viperSettings.host}/vr.php").also { - it.setParameter( - "p", postId.toString() - ) - }.build()) - val threadLookupAPIResponseHandler = ThreadLookupAPIResponseHandler() - log.debug("Requesting {}", httpGet) - return try { - Failsafe.with(retryPolicyService.buildGenericRetryPolicy()).onFailure { - log.error( - "parsing failed for thread $threadId, post $postId", it.failure - ) - }.get(CheckedSupplier { - val connection: HttpClient = httpService.client - connection.execute( - httpGet, vgAuthService.context - ) { response -> - if (response.code / 100 != 2) { - throw DownloadException("Unexpected response code '${response.code}' for $httpGet") - } - factory.newSAXParser() - .parse(response.entity.content, threadLookupAPIResponseHandler) - threadLookupAPIResponseHandler.result.postItemList.first() - } - }) - } catch (e: Exception) { - throw PostParseException(e) - } - } - - companion object { - private val factory = SAXParserFactory.newInstance() - } } diff --git a/vripper-core/src/main/kotlin/me/vripper/tasks/LeaveThanksRunnable.kt b/vripper-core/src/main/kotlin/me/vripper/tasks/LeaveThanksRunnable.kt index 261f7276..9cf6995e 100644 --- a/vripper-core/src/main/kotlin/me/vripper/tasks/LeaveThanksRunnable.kt +++ b/vripper-core/src/main/kotlin/me/vripper/tasks/LeaveThanksRunnable.kt @@ -1,7 +1,7 @@ package me.vripper.tasks import me.vripper.entities.LogEntry -import me.vripper.entities.LogEntry.Status.* +import me.vripper.entities.LogEntry.Status.ERROR import me.vripper.entities.Post import me.vripper.services.DataTransaction import me.vripper.services.HTTPService @@ -24,47 +24,14 @@ class LeaveThanksRunnable( private val cm: HTTPService by inject() private val settingsService: SettingsService by inject() private val dataTransaction: DataTransaction by inject() - private val logEntry: LogEntry - - init { - logEntry = dataTransaction.saveLog( - LogEntry( - type = LogEntry.Type.THANKS, - status = PENDING, - message = "Leaving thanks for ${post.url}" - ) - ) - } override fun run() { try { Tasks.increment() - dataTransaction.updateLog(logEntry.copy(status = PROCESSING)) - if (!settingsService.settings.viperSettings.login) { - dataTransaction.updateLog( - logEntry.copy( - status = DONE, - message = "Will not send a like for ${post.url}\nAuthentication with ViperGirls option is disabled" - ) - ) + if (!settingsService.settings.viperSettings.login || !authenticated) { return } if (!settingsService.settings.viperSettings.thanks) { - dataTransaction.updateLog( - logEntry.copy( - status = DONE, - message = "Will not send a like for ${post.url}\nLeave thanks option is disabled" - ) - ) - return - } - if (!authenticated) { - dataTransaction.updateLog( - logEntry.copy( - status = DONE, - message = "Will not send a like for ${post.url}\nYou are not authenticated" - ) - ) return } @@ -86,13 +53,12 @@ class LeaveThanksRunnable( ) } cm.client.execute(postThanks, context) { } - dataTransaction.updateLog(logEntry.copy(status = DONE)) } catch (e: Exception) { val error = "Failed to leave a thanks for $post" log.error(error, e) - dataTransaction.updateLog( - logEntry.copy( - status = ERROR, message = """ + dataTransaction.saveLog( + LogEntry( + type = LogEntry.Type.THANKS, status = ERROR, message = """ $error ${e.formatToString()} """.trimIndent() diff --git a/vripper-core/src/main/kotlin/me/vripper/tasks/ThreadLookupRunnable.kt b/vripper-core/src/main/kotlin/me/vripper/tasks/ThreadLookupRunnable.kt index 7b0ba495..041c842d 100644 --- a/vripper-core/src/main/kotlin/me/vripper/tasks/ThreadLookupRunnable.kt +++ b/vripper-core/src/main/kotlin/me/vripper/tasks/ThreadLookupRunnable.kt @@ -1,7 +1,7 @@ package me.vripper.tasks import me.vripper.entities.LogEntry -import me.vripper.entities.LogEntry.Status.* +import me.vripper.entities.LogEntry.Status.ERROR import me.vripper.entities.Thread import me.vripper.model.Settings import me.vripper.model.ThreadItem @@ -25,27 +25,15 @@ class ThreadLookupRunnable(private val threadId: Long, private val settings: Set private val threadCacheService by inject() private val appEndpointService by inject() private val link: String = "${settingsService.settings.viperSettings.host}/threads/$threadId" - private val logEntry: LogEntry - - init { - logEntry = dataTransaction.saveLog( - LogEntry( - type = LogEntry.Type.THREAD, - status = LogEntry.Status.PENDING, - message = "Processing multi-post link $link" - ) - ) - } override fun run() { try { Tasks.increment() - dataTransaction.updateLog(logEntry.copy(status = PROCESSING)) if (dataTransaction.findThreadByThreadId(threadId).isEmpty) { val threadLookupResult = threadCacheService[threadId] if (threadLookupResult.postItemList.isEmpty()) { val message = "Nothing found for $link" - dataTransaction.updateLog(logEntry.copy(status = ERROR, message = message)) + dataTransaction.saveLog(LogEntry(type = LogEntry.Type.THREAD, status = ERROR, message = message)) return } dataTransaction.save( @@ -56,27 +44,16 @@ class ThreadLookupRunnable(private val threadId: Long, private val settings: Set total = threadLookupResult.postItemList.size ) ) - dataTransaction.updateLog( - logEntry.copy( - status = DONE, - message = "Thread scan completed, found ${threadLookupResult.postItemList.size} posts" - ) - ) autostart(threadLookupResult) } else { log.info("Link $link is already loaded") - dataTransaction.updateLog( - logEntry.copy( - status = DONE, message = "$link has already been scanned" - ) - ) } } catch (e: Exception) { - val error = "Error when adding multi-post link $link" + val error = "Error when processing $link" log.error(error, e) - dataTransaction.updateLog( - logEntry.copy( - status = ERROR, message = """ + dataTransaction.saveLog( + LogEntry( + type = LogEntry.Type.THREAD, status = ERROR, message = """ $error ${e.formatToString()} """.trimIndent() diff --git a/vripper-core/src/main/kotlin/me/vripper/utilities/ApplicationProperties.kt b/vripper-core/src/main/kotlin/me/vripper/utilities/ApplicationProperties.kt index a23c76ce..31410193 100644 --- a/vripper-core/src/main/kotlin/me/vripper/utilities/ApplicationProperties.kt +++ b/vripper-core/src/main/kotlin/me/vripper/utilities/ApplicationProperties.kt @@ -1,22 +1,48 @@ package me.vripper.utilities +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import me.vripper.exception.DownloadException +import me.vripper.services.HTTPService +import org.apache.hc.client5.http.classic.methods.HttpGet +import org.apache.hc.core5.http.io.entity.EntityUtils +import org.koin.core.component.KoinComponent +import org.koin.core.component.inject import java.nio.file.Files import java.nio.file.Path import kotlin.io.path.Path import kotlin.io.path.pathString -object ApplicationProperties { +object ApplicationProperties : KoinComponent { const val VERSION: String = "5.3.0" private const val BASE_DIR_NAME: String = "vripper" private val portable = System.getProperty("vripper.portable", "true").toBoolean() private val BASE_DIR: String = getBaseDir() + private val httpService: HTTPService by inject() val VRIPPER_DIR: Path = Path(BASE_DIR, BASE_DIR_NAME) + private val json = Json { + ignoreUnknownKeys = true + } init { Files.createDirectories(VRIPPER_DIR) System.setProperty("VRIPPER_DIR", VRIPPER_DIR.toRealPath().pathString) } + fun latestVersion(): String { + @Serializable + data class ReleaseResponse(@SerialName("tag_name") val tagName: String) + + val httpGet = HttpGet("https://api.github.com/repos/death-claw/vripper-project/releases/latest") + return httpService.client.execute(httpGet) { + if (it.code / 100 != 2) { + throw DownloadException("Unexpected response code '${it.code}' for $httpGet") + } + json.decodeFromString(EntityUtils.toString(it.entity)).tagName + } + } + private fun getBaseDir(): String { return if (portable) { System.getProperty("user.dir") diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/Module.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/Module.kt index aa31c931..db1d5e75 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/Module.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/Module.kt @@ -1,6 +1,6 @@ package me.vripper.gui -import me.vripper.gui.clipboard.ClipboardService +import me.vripper.gui.services.ClipboardService import org.koin.dsl.module val guiModule = module { diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/VripperGuiApplication.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/VripperGuiApplication.kt index 7fa22577..c056e11a 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/VripperGuiApplication.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/VripperGuiApplication.kt @@ -4,9 +4,11 @@ import javafx.application.Application import javafx.scene.image.Image import javafx.stage.Stage import javafx.stage.WindowEvent +import kotlinx.coroutines.* +import me.vripper.gui.components.views.LoadingView +import me.vripper.gui.controller.WidgetsController import me.vripper.gui.event.ApplicationInitialized import me.vripper.gui.listener.GuiStartupLister -import me.vripper.gui.view.LoadingView import me.vripper.listeners.AppLock import me.vripper.utilities.ApplicationProperties.VRIPPER_DIR import me.vripper.utilities.DbUtils @@ -22,10 +24,12 @@ import kotlin.system.exitProcess class VripperGuiApplication : App( LoadingView::class, Styles::class -) { //The application class must be a TornadoFX application and it must have the main view +) { //The application class must be a TornadoFX application, and it must have the main view private var initialized = false private val startupListener = GuiStartupLister() + private val widgetsController: WidgetsController by inject() + private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default) init { APP_INSTANCE = this @@ -33,8 +37,8 @@ class VripperGuiApplication : App( override fun start(stage: Stage) { with(stage) { - width = 1366.0 - height = 768.0 + width = widgetsController.currentSettings.width + height = widgetsController.currentSettings.height minWidth = 800.0 minHeight = 600.0 icons.addAll( @@ -50,6 +54,18 @@ class VripperGuiApplication : App( ) ) } + coroutineScope.launch { + while (isActive) { + if (!stage.isMaximized) { + if (widgetsController.currentSettings.width != stage.width || widgetsController.currentSettings.height != stage.height) { + widgetsController.currentSettings.width = stage.width + widgetsController.currentSettings.height = stage.height + widgetsController.update() + } + } + delay(1_000) + } + } stage.addEventFilter(WindowEvent.WINDOW_SHOWN) { Database.connect("jdbc:h2:file:$VRIPPER_DIR/vripper;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=30000;") DbUtils.update() @@ -68,11 +84,9 @@ class VripperGuiApplication : App( super.start(stage) } - override fun stop() { // On stop, we have to stop spring as well + override fun stop() { + coroutineScope.cancel() super.stop() - if (initialized) { - //CLOSE - } exitProcess(0) } diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/PreviewTableCell.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/cells/PreviewTableCell.kt similarity index 61% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/PreviewTableCell.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/cells/PreviewTableCell.kt index 30cd4b87..52094ba1 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/PreviewTableCell.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/cells/PreviewTableCell.kt @@ -1,14 +1,16 @@ -package me.vripper.gui.view +package me.vripper.gui.components.cells +import javafx.collections.ObservableList import javafx.geometry.Pos import javafx.scene.control.TableCell import javafx.scene.image.ImageView -class PreviewTableCell : TableCell() { +class PreviewTableCell : TableCell>() { init { alignment = Pos.CENTER } - override fun updateItem(item: String?, empty: Boolean) { + + override fun updateItem(item: ObservableList?, empty: Boolean) { super.updateItem(item, empty) if (!empty) { graphic = ImageView("image.png").apply { fitWidth = 25.0; fitHeight = 25.0 } diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/ProgressTableCell.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/cells/ProgressTableCell.kt similarity index 97% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/ProgressTableCell.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/cells/ProgressTableCell.kt index 0e1e60f1..496e9b38 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/ProgressTableCell.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/cells/ProgressTableCell.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view +package me.vripper.gui.components.cells import javafx.beans.value.ObservableValue import javafx.event.EventHandler diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/StatusTableCell.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/cells/StatusTableCell.kt similarity index 96% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/StatusTableCell.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/cells/StatusTableCell.kt index ec47f56c..c353ec82 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/StatusTableCell.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/cells/StatusTableCell.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view +package me.vripper.gui.components.cells import javafx.geometry.Pos import javafx.scene.control.TableCell diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/AboutFragment.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/AboutFragment.kt new file mode 100644 index 00000000..73a73a3e --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/AboutFragment.kt @@ -0,0 +1,723 @@ +package me.vripper.gui.components.fragments + +import javafx.geometry.Insets +import javafx.scene.control.TabPane +import javafx.scene.text.FontWeight +import me.vripper.gui.utils.openLink +import me.vripper.utilities.ApplicationProperties +import tornadofx.* + +class AboutFragment : Fragment("About") { + + override val root = tabpane() + + init { + with(root) { + tab("About") { + tabClosingPolicy = TabPane.TabClosingPolicy.UNAVAILABLE + hbox { + padding = Insets(15.0, 15.0, 15.0, 15.0) + spacing = 15.0 + imageview("icons/64x64.png") + vbox { + spacing = 5.0 + text("VRipper") { + style { + fontWeight = FontWeight.BOLD + fontSize = Dimension(18.0, Dimension.LinearUnits.px) + } + } + text("Version ${ApplicationProperties.VERSION}") + text("Developed by death-claw and VRipper working group") + hyperlink("Home Page") { + action { + openLink("https://github.com/death-claw/vripper-project") + } + } + } + } + + } + tab("License") { + textarea( + """ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 3 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, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + """.trimIndent() + ) + } + } + } +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/popup/AddView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/AddLinksFragment.kt similarity index 90% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/popup/AddView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/AddLinksFragment.kt index fe788289..bf84b03e 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/popup/AddView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/AddLinksFragment.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.popup +package me.vripper.gui.components.fragments import javafx.beans.property.SimpleStringProperty import javafx.geometry.Pos @@ -8,7 +8,7 @@ import javafx.scene.layout.VBox import me.vripper.gui.controller.PostController import tornadofx.* -class AddView : Fragment("Add thread links") { +class AddLinksFragment : Fragment("Add thread links") { private val textAreaProperty = SimpleStringProperty() private val postController: PostController by inject() diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ColumnSelectionFragment.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ColumnSelectionFragment.kt new file mode 100644 index 00000000..460d9145 --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ColumnSelectionFragment.kt @@ -0,0 +1,19 @@ +package me.vripper.gui.components.fragments + +import javafx.beans.property.SimpleBooleanProperty +import javafx.collections.FXCollections +import tornadofx.Fragment +import tornadofx.listview +import tornadofx.useCheckbox + +class ColumnSelectionFragment : Fragment("Column Selection") { + + val map: MutableMap by param() + + override val root = listview { + items = FXCollections.observableArrayList(map.keys) + useCheckbox { listItem -> + map[listItem]!! + } + } +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/ConnectionSettingsView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ConnectionSettingsFragment.kt similarity index 93% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/ConnectionSettingsView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ConnectionSettingsFragment.kt index 471c2b98..ce38c914 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/ConnectionSettingsView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ConnectionSettingsFragment.kt @@ -1,10 +1,10 @@ -package me.vripper.gui.view.settings +package me.vripper.gui.components.fragments import me.vripper.gui.controller.SettingsController import me.vripper.gui.model.settings.ConnectionSettingsModel import tornadofx.* -class ConnectionSettingsView : View("Connection Settings") { +class ConnectionSettingsFragment : Fragment("Connection Settings") { private val settingsController: SettingsController by inject() val connectionSettingsModel = ConnectionSettingsModel() diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/DownloadSettingsView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/DownloadSettingsFragment.kt similarity index 96% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/DownloadSettingsView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/DownloadSettingsFragment.kt index 5747850a..3834d794 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/DownloadSettingsView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/DownloadSettingsFragment.kt @@ -1,11 +1,11 @@ -package me.vripper.gui.view.settings +package me.vripper.gui.components.fragments import me.vripper.gui.controller.SettingsController import me.vripper.gui.model.settings.DownloadSettingsModel import tornadofx.* -class DownloadSettingsView : View("Download Settings") { +class DownloadSettingsFragment : Fragment("Download Settings") { private val settingsController: SettingsController by inject() val downloadSettingsModel = DownloadSettingsModel() diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/ImagesTableView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ImagesTableFragment.kt similarity index 53% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/ImagesTableView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ImagesTableFragment.kt index 2b01d8f8..630ebdd1 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/ImagesTableView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ImagesTableFragment.kt @@ -1,7 +1,8 @@ -package me.vripper.gui.view.tables +package me.vripper.gui.components.fragments import javafx.collections.FXCollections import javafx.collections.ObservableList +import javafx.event.EventHandler import javafx.geometry.Pos import javafx.scene.control.* import javafx.scene.control.cell.TextFieldTableCell @@ -15,27 +16,27 @@ import kotlinx.coroutines.flow.map import me.vripper.entities.Image import me.vripper.event.EventBus import me.vripper.event.ImageEvent +import me.vripper.gui.components.cells.PreviewTableCell +import me.vripper.gui.components.cells.ProgressTableCell +import me.vripper.gui.components.cells.StatusTableCell import me.vripper.gui.controller.ImageController +import me.vripper.gui.controller.WidgetsController import me.vripper.gui.model.ImageModel -import me.vripper.gui.view.ProgressTableCell -import me.vripper.gui.view.StatusTableCell -import me.vripper.gui.view.openLink +import me.vripper.gui.utils.Preview +import me.vripper.gui.utils.openLink import tornadofx.* -class ImagesTableView : Fragment("Photos") { +class ImagesTableFragment : Fragment("Photos") { private lateinit var tableView: TableView private val imageController: ImageController by inject() + private val widgetsController: WidgetsController by inject() private val eventBus: EventBus by di() - private var items: ObservableList = FXCollections.observableArrayList() private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) - val postId: Long by param() + private val items: ObservableList = FXCollections.observableArrayList() + private var preview: Preview? = null - override fun onDock() { - tableView.prefWidthProperty().bind(root.widthProperty()) - tableView.prefHeightProperty().bind(root.heightProperty()) - modalStage?.width = 550.0 - tableView.placeholder = Label("Loading") + fun setPostId(postId: Long) { coroutineScope.launch { val list = coroutineScope.async { imageController.findImages(postId) @@ -46,7 +47,6 @@ class ImagesTableView : Fragment("Photos") { tableView.placeholder = Label("No content in table") } } - coroutineScope.launch { eventBus.events.filterIsInstance(ImageEvent::class).map { it.copy(images = it.images.filter { image: Image -> image.postId == postId }) @@ -70,6 +70,12 @@ class ImagesTableView : Fragment("Photos") { } } + override fun onDock() { + tableView.prefWidthProperty().bind(root.widthProperty()) + tableView.prefHeightProperty().bind(root.heightProperty()) + modalStage?.width = 550.0 + } + override val root = vbox(alignment = Pos.CENTER_RIGHT) { tableView = tableview(items) { setRowFactory { @@ -89,7 +95,82 @@ class ImagesTableView : Fragment("Photos") { .map { empty -> if (empty) null else contextMenu }) tableRow } + contextMenu = ContextMenu() + contextMenu.items.add(MenuItem("Setup columns").apply { + setOnAction { + find( + mapOf( + ColumnSelectionFragment::map to mapOf( + Pair( + "Preview", + widgetsController.currentSettings.imagesColumnsModel.previewProperty + ), + Pair( + "Index", + widgetsController.currentSettings.imagesColumnsModel.indexProperty + ), + Pair( + "Link", + widgetsController.currentSettings.imagesColumnsModel.linkProperty + ), + Pair( + "Progress", + widgetsController.currentSettings.imagesColumnsModel.progressProperty + ), + Pair( + "Filename", + widgetsController.currentSettings.imagesColumnsModel.filenameProperty + ), + Pair( + "Status", + widgetsController.currentSettings.imagesColumnsModel.statusProperty + ), + Pair( + "Size", + widgetsController.currentSettings.imagesColumnsModel.sizeProperty + ), + Pair( + "Downloaded", + widgetsController.currentSettings.imagesColumnsModel.downloadedProperty + ), + ) + ) + ).openModal() + } + graphic = ImageView("columns.png").apply { + fitWidth = 18.0 + fitHeight = 18.0 + } + }) + column("Preview", ImageModel::thumbUrlProperty) { + visibleProperty().bind(widgetsController.currentSettings.imagesColumnsModel.previewProperty) + prefWidth = 50.0 + cellFactory = Callback { + val cell = PreviewTableCell() + cell.onMouseExited = EventHandler { + preview?.hide() + } + cell.onMouseMoved = EventHandler { + preview?.previewPopup?.apply { + x = it.screenX + 20 + y = it.screenY + 10 + } + } + cell.onMouseEntered = EventHandler { mouseEvent -> + preview?.hide() + if (cell.tableRow.item != null && cell.tableRow.item.thumbUrl.isNotEmpty()) { + preview = Preview(currentStage!!, cell.tableRow.item.thumbUrl) + preview?.previewPopup?.apply { + x = mouseEvent.screenX + 20 + y = mouseEvent.screenY + 10 + } + } + } + cell + } + } column("Index", ImageModel::indexProperty) { + visibleProperty().bind(widgetsController.currentSettings.imagesColumnsModel.indexProperty) prefWidth = 50.0 sortOrder.add(this) cellFactory = Callback { @@ -97,12 +178,14 @@ class ImagesTableView : Fragment("Photos") { } } column("Link", ImageModel::urlProperty) { + visibleProperty().bind(widgetsController.currentSettings.imagesColumnsModel.linkProperty) prefWidth = 200.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("Progress", ImageModel::progressProperty) { + visibleProperty().bind(widgetsController.currentSettings.imagesColumnsModel.progressProperty) prefWidth = 100.0 cellFactory = Callback { val cell = ProgressTableCell() @@ -123,24 +206,28 @@ class ImagesTableView : Fragment("Photos") { } } column("Filename", ImageModel::filenameProperty) { + visibleProperty().bind(widgetsController.currentSettings.imagesColumnsModel.filenameProperty) prefWidth = 150.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("Status", ImageModel::statusProperty) { + visibleProperty().bind(widgetsController.currentSettings.imagesColumnsModel.statusProperty) prefWidth = 50.0 cellFactory = Callback { StatusTableCell() } } column("Size", ImageModel::sizeProperty) { + visibleProperty().bind(widgetsController.currentSettings.imagesColumnsModel.sizeProperty) prefWidth = 75.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("Downloaded", ImageModel::downloadedProperty) { + visibleProperty().bind(widgetsController.currentSettings.imagesColumnsModel.downloadedProperty) prefWidth = 75.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/popup/LogMessageView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/LogMessageFragment.kt similarity index 85% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/popup/LogMessageView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/LogMessageFragment.kt index 3f4832bf..7a6ee433 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/popup/LogMessageView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/LogMessageFragment.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.popup +package me.vripper.gui.components.fragments import javafx.beans.property.SimpleStringProperty import javafx.geometry.Pos @@ -7,7 +7,7 @@ import javafx.scene.layout.VBox import me.vripper.gui.model.LogModel import tornadofx.* -class LogMessageView : Fragment("Log message") { +class LogMessageFragment : Fragment("Log message") { val logModel: LogModel by param() private val textAreaProperty = SimpleStringProperty(logModel.message) diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/PostInfoPanelFragment.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/PostInfoPanelFragment.kt new file mode 100644 index 00000000..26584148 --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/PostInfoPanelFragment.kt @@ -0,0 +1,135 @@ +package me.vripper.gui.components.fragments + +import javafx.scene.image.ImageView +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.filterIsInstance +import kotlinx.coroutines.flow.map +import me.vripper.entities.Metadata +import me.vripper.entities.Post +import me.vripper.event.EventBus +import me.vripper.event.PostUpdateEvent +import me.vripper.gui.controller.PostController +import me.vripper.gui.model.PostModel +import tornadofx.* + +class PostInfoPanelFragment : Fragment() { + private val postController: PostController by inject() + private val eventBus: EventBus by di() + private val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) + private val imagesTableFragment: ImagesTableFragment = find() + private val postModel: PostModel = PostModel( + -1, "", 0.0, "", "", 0, 0, "", "", -1, "", "", "", emptyList(), Metadata(-1, Metadata.Data("", emptyList())) + ) + + override val root = tabpane() + + init { + with(root) { + tabClosingPolicy = javafx.scene.control.TabPane.TabClosingPolicy.UNAVAILABLE + tab("General") { + graphic = ImageView("info.png").apply { + fitWidth = 18.0 + fitHeight = 18.0 + } + scrollpane { + form { + fieldset { + field("Post Link:") { + textfield(postModel.urlProperty) { + isEditable = false + visibleWhen(postModel.urlProperty.isNotEmpty) + } + } + field("Posted By:") { + label(postModel.postedByProperty) + } + field("Title:") { + label(postModel.titleProperty) + } + field("More titles:") { + label(postModel.altTitlesProperty.map { it.joinToString(", ") }) + } + field("Status:") { + label(postModel.statusProperty.map { it -> + it.lowercase().replaceFirstChar { it.uppercase() } + }) + } + + field("Path:") { + label(postModel.pathProperty) + } + field("Total:") { + label(postModel.progressCountProperty) + } + field("Hosts:") { + label(postModel.hostsProperty) + } + + field("Added On:") { + label(postModel.addedOnProperty) + } + } + } + } + } + tab("Photos") { + graphic = ImageView("details.png").apply { + fitWidth = 18.0 + fitHeight = 18.0 + } + add(imagesTableFragment) + } + } + } + + fun setPostId(postId: Long) { + imagesTableFragment.setPostId(postId) + coroutineScope.launch { + val model = postController.find(postId).await() + postModel.apply { + this.postId = model.postId + this.title = model.title + this.progress = model.progress + this.status = model.status.lowercase().replaceFirstChar { it.uppercase() } + this.url = model.url + this.done = model.done + this.total = model.total + this.hosts = model.hosts + this.addedOn = model.addedOn + this.order = model.order + this.path = model.path + this.folderName = model.folderName + this.progressCount = model.progressCount + this.previewList = model.previewList + this.altTitles = model.altTitles + this.postedby = model.postedby + } + } + coroutineScope.launch { + eventBus.events.filterIsInstance(PostUpdateEvent::class) + .map { event -> event.posts.lastOrNull { it.postId == postId } }.collect(::updatePostModel) + } + } + + fun updatePostModel(post: Post?) { + if (post == null) return + runLater { + postModel.status = post.status.stringValue.lowercase().replaceFirstChar { it.uppercase() } + postModel.progressCount = postController.progressCount( + post.total, post.done, post.downloaded + ) + postModel.order = post.rank + 1 + postModel.done = post.done + postModel.progress = postController.progress( + post.total, post.done + ) + postModel.path = post.getDownloadFolder() + postModel.folderName = post.folderName + } + } + + override fun onUndock() { + imagesTableFragment.onUndock() + coroutineScope.cancel() + } +} diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/popup/RenameView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/RenameFragment.kt similarity index 92% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/popup/RenameView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/RenameFragment.kt index 88c4f3b1..bacb8bc4 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/popup/RenameView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/RenameFragment.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.popup +package me.vripper.gui.components.fragments import javafx.beans.property.SimpleStringProperty import javafx.geometry.Pos @@ -6,7 +6,7 @@ import javafx.scene.control.ComboBox import me.vripper.gui.controller.PostController import tornadofx.* -class RenameView : Fragment("Rename download post") { +class RenameFragment : Fragment("Rename download post") { val postId: Long by param() val name: String by param() diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/SettingsView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/SettingsFragment.kt similarity index 66% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/SettingsView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/SettingsFragment.kt index 993e566a..15b35f8a 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/SettingsView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/SettingsFragment.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.settings +package me.vripper.gui.components.fragments import javafx.geometry.Pos import javafx.scene.control.Alert @@ -11,39 +11,43 @@ import me.vripper.gui.controller.SettingsController import tornadofx.* -class SettingsView : Fragment("Settings") { +class SettingsFragment : Fragment("Settings") { private val settingsController: SettingsController by inject() - private val downloadSettingsView: DownloadSettingsView by inject() - private val connectionSettingsView: ConnectionSettingsView by inject() - private val viperSettingsView: ViperSettingsView by inject() - private val systemSettingsView: SystemSettingsView by inject() + private val downloadSettingsFragment: DownloadSettingsFragment = find() + private val connectionSettingsFragment: ConnectionSettingsFragment = find() + private val viperSettingsFragment: ViperSettingsFragment = find() + private val systemSettingsFragment: SystemSettingsFragment = find() override val root = vbox(alignment = Pos.CENTER_RIGHT) { spacing = 5.0 tabpane { tabClosingPolicy = TabPane.TabClosingPolicy.UNAVAILABLE VBox.setVgrow(this, Priority.ALWAYS) - tab { + tab(downloadSettingsFragment.title) { + add(downloadSettingsFragment) val imageView = ImageView("downloads-folder.png") imageView.fitWidth = 18.0 imageView.fitHeight = 18.0 graphic = imageView } - tab { + tab(connectionSettingsFragment.title) { + add(connectionSettingsFragment) val imageView = ImageView("data-transfer.png") imageView.fitWidth = 18.0 imageView.fitHeight = 18.0 graphic = imageView } - tab { + tab(viperSettingsFragment.title) { + add(viperSettingsFragment) val imageView = ImageView("icons/32x32.png") imageView.fitWidth = 18.0 imageView.fitHeight = 18.0 graphic = imageView } - tab { + tab(systemSettingsFragment.title) { + add(systemSettingsFragment) val imageView = ImageView("clipboard.png") imageView.fitWidth = 18.0 imageView.fitHeight = 18.0 @@ -61,10 +65,10 @@ class SettingsView : Fragment("Settings") { action { try { settingsController.saveNewSettings( - downloadSettingsView.downloadSettingsModel, - connectionSettingsView.connectionSettingsModel, - viperSettingsView.viperSettingsModel, - systemSettingsView.systemSettingsModel + downloadSettingsFragment.downloadSettingsModel, + connectionSettingsFragment.connectionSettingsModel, + viperSettingsFragment.viperSettingsModel, + systemSettingsFragment.systemSettingsModel ) close() } catch (e: ValidationException) { diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/SystemSettingsView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/SystemSettingsFragment.kt similarity index 96% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/SystemSettingsView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/SystemSettingsFragment.kt index 6793847c..c015e0eb 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/SystemSettingsView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/SystemSettingsFragment.kt @@ -1,10 +1,10 @@ -package me.vripper.gui.view.settings +package me.vripper.gui.components.fragments import me.vripper.gui.controller.SettingsController import me.vripper.gui.model.settings.SystemSettingsModel import tornadofx.* -class SystemSettingsView : View("System Settings") { +class SystemSettingsFragment : Fragment("System Settings") { private val settingsController: SettingsController by inject() val systemSettingsModel = SystemSettingsModel() diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/ThreadSelectionTableView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ThreadSelectionTableFragment.kt similarity index 68% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/ThreadSelectionTableView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ThreadSelectionTableFragment.kt index 1d9739cb..e02ac21d 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/ThreadSelectionTableView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ThreadSelectionTableFragment.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.tables +package me.vripper.gui.components.fragments import javafx.beans.property.SimpleStringProperty import javafx.event.EventHandler @@ -9,17 +9,19 @@ import javafx.scene.image.ImageView import javafx.scene.input.MouseButton import javafx.util.Callback import kotlinx.coroutines.* +import me.vripper.gui.components.cells.PreviewTableCell import me.vripper.gui.controller.ThreadController +import me.vripper.gui.controller.WidgetsController import me.vripper.gui.model.ThreadSelectionModel -import me.vripper.gui.view.Preview -import me.vripper.gui.view.PreviewTableCell -import me.vripper.gui.view.openLink +import me.vripper.gui.utils.Preview +import me.vripper.gui.utils.openLink import tornadofx.* -class ThreadSelectionTableView : Fragment("Thread") { +class ThreadSelectionTableFragment : Fragment("Thread") { private lateinit var tableView: TableView private val threadController: ThreadController by inject() + private val widgetsController: WidgetsController by inject() private var items = SortedFilteredList() private var preview: Preview? = null private val searchInput = SimpleStringProperty() @@ -79,7 +81,43 @@ class ThreadSelectionTableView : Fragment("Thread") { tableRow } + contextMenu = ContextMenu() + contextMenu.items.add(MenuItem("Setup columns").apply { + setOnAction { + find( + mapOf( + ColumnSelectionFragment::map to mapOf( + Pair( + "Preview", + widgetsController.currentSettings.threadSelectionColumnsModel.previewProperty + ), + Pair( + "Post Index", + widgetsController.currentSettings.threadSelectionColumnsModel.indexProperty + ), + Pair( + "Title", + widgetsController.currentSettings.threadSelectionColumnsModel.titleProperty + ), + Pair( + "URL", + widgetsController.currentSettings.threadSelectionColumnsModel.linkProperty + ), + Pair( + "Hosts", + widgetsController.currentSettings.threadSelectionColumnsModel.hostsProperty + ), + ) + ) + ).openModal() + } + graphic = ImageView("columns.png").apply { + fitWidth = 18.0 + fitHeight = 18.0 + } + }) column("Preview", ThreadSelectionModel::previewListProperty) { + visibleProperty().bind(widgetsController.currentSettings.threadSelectionColumnsModel.previewProperty) cellFactory = Callback { val cell = PreviewTableCell() cell.onMouseExited = EventHandler { @@ -105,24 +143,28 @@ class ThreadSelectionTableView : Fragment("Thread") { } } column("Post Index", ThreadSelectionModel::indexProperty) { + visibleProperty().bind(widgetsController.currentSettings.threadSelectionColumnsModel.indexProperty) sortOrder.add(this) cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("Title", ThreadSelectionModel::titleProperty) { + visibleProperty().bind(widgetsController.currentSettings.threadSelectionColumnsModel.titleProperty) prefWidth = 200.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("URL", ThreadSelectionModel::urlProperty) { + visibleProperty().bind(widgetsController.currentSettings.threadSelectionColumnsModel.linkProperty) prefWidth = 200.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("Hosts", ThreadSelectionModel::hostsProperty) { + visibleProperty().bind(widgetsController.currentSettings.threadSelectionColumnsModel.hostsProperty) cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/ViperSettingsView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ViperSettingsFragment.kt similarity index 94% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/ViperSettingsView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ViperSettingsFragment.kt index 0a84ae96..ae84f161 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/settings/ViperSettingsView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/fragments/ViperSettingsFragment.kt @@ -1,11 +1,11 @@ -package me.vripper.gui.view.settings +package me.vripper.gui.components.fragments import javafx.collections.FXCollections import me.vripper.gui.controller.SettingsController import me.vripper.gui.model.settings.ViperSettingsModel import tornadofx.* -class ViperSettingsView : View("Viper Settings") { +class ViperSettingsFragment : Fragment("Viper Settings") { private val settingsController: SettingsController by inject() val viperSettingsModel = ViperSettingsModel() val proxies = FXCollections.observableArrayList() diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/ActionBarView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/ActionBarView.kt similarity index 67% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/ActionBarView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/ActionBarView.kt index fd45b288..3e6e78ca 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/ActionBarView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/ActionBarView.kt @@ -1,8 +1,10 @@ -package me.vripper.gui.view.actionbar +package me.vripper.gui.components.views import javafx.scene.control.ContentDisplay +import javafx.scene.input.KeyCode +import javafx.scene.input.KeyCodeCombination import me.vripper.gui.Styles -import me.vripper.gui.view.settings.SettingsView +import me.vripper.gui.components.fragments.SettingsFragment import tornadofx.* class ActionBarView : View() { @@ -19,9 +21,10 @@ class ActionBarView : View() { } addClass(Styles.actionBarButton) contentDisplay = ContentDisplay.GRAPHIC_ONLY - tooltip("Open settings menu") + tooltip("Open settings menu [S]") + shortcut(KeyCodeCombination(KeyCode.S)) action { - find().openModal()?.apply { + find().openModal()?.apply { minWidth = 600.0 minHeight = 400.0 } diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/AddActionsView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/AddActionsView.kt similarity index 74% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/AddActionsView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/AddActionsView.kt index 345a8580..f0db76eb 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/AddActionsView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/AddActionsView.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.actionbar +package me.vripper.gui.components.views import javafx.geometry.Orientation import javafx.scene.control.ContentDisplay @@ -6,7 +6,7 @@ import javafx.scene.input.KeyCode import javafx.scene.input.KeyCodeCombination import javafx.scene.input.KeyCombination import me.vripper.gui.Styles -import me.vripper.gui.view.popup.AddView +import me.vripper.gui.components.fragments.AddLinksFragment import tornadofx.* class AddActionsView : View() { @@ -19,11 +19,12 @@ class AddActionsView : View() { } addClass(Styles.actionBarButton) contentDisplay = ContentDisplay.GRAPHIC_ONLY - tooltip("Add new links [Ctrl+L]") + tooltip("Add links [Ctrl+L]") shortcut(KeyCodeCombination(KeyCode.L, KeyCombination.CONTROL_DOWN)) action { - find().input.clear() - find().openModal() + find().apply { + input.clear() + }.openModal() } } separator(Orientation.VERTICAL) diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/AppView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/AppView.kt new file mode 100644 index 00000000..4578629e --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/AppView.kt @@ -0,0 +1,132 @@ +package me.vripper.gui.components.views + +import javafx.geometry.Orientation +import javafx.scene.control.SplitPane +import javafx.scene.layout.HBox +import javafx.scene.layout.Priority +import javafx.scene.layout.VBox +import kotlinx.coroutines.* +import me.vripper.gui.components.fragments.PostInfoPanelFragment +import me.vripper.gui.controller.MainController +import me.vripper.gui.controller.WidgetsController +import me.vripper.gui.model.PostModel +import tornadofx.* + +class AppView : View() { + + override val root = VBox() + private val mainController: MainController by inject() + private val postsTableView: PostsTableView by inject() + private val menuBarView: MenuBarView by inject() + private val actionBarView: ActionBarView by inject() + private val statusBarView: StatusBarView by inject() + private val mainView: MainView by inject() + private val widgetsController: WidgetsController by inject() + private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) + private var infoPanelView = HBox() + private var splitpane: SplitPane + private var lastSelectedInfoPanelTab = 0 + + init { + title = "VRipper ${mainController.version}" + setPostIdToInfoPanelView(null) + with(root) { + add(menuBarView) + if (widgetsController.currentSettings.visibleToolbarPanel) { + add(actionBarView) + } + splitpane = splitpane { + add(mainView) + if (widgetsController.currentSettings.visibleInfoPanel) { + add(infoPanelView) + setDividerPositions(widgetsController.currentSettings.infoPanelDividerPosition) + } + orientation = Orientation.VERTICAL + vboxConstraints { vGrow = Priority.ALWAYS } + } + if (widgetsController.currentSettings.visibleStatusBarPanel) { + add(statusBarView) + } + prefWidth = widgetsController.currentSettings.width + prefHeight = widgetsController.currentSettings.height + } + } + + override fun onDock() { + coroutineScope.launch { + var lastDividerPosition = widgetsController.currentSettings.infoPanelDividerPosition + while (isActive) { + if (widgetsController.currentSettings.visibleInfoPanel) { + val dividerPosition = splitpane.dividerPositions.firstOrNull() + if (dividerPosition != null && lastDividerPosition != dividerPosition) { + lastDividerPosition = dividerPosition + widgetsController.currentSettings.infoPanelDividerPosition = lastDividerPosition + widgetsController.update() + } + } + delay(1_000) + } + } + postsTableView.tableView.selectionModel.selectedItemProperty().onChange { + setPostIdToInfoPanelView(it) + } + mainView.root.selectionModel.selectedIndexProperty().onChange { + if (it == 0 && widgetsController.currentSettings.visibleInfoPanel) { + val selectedItem = postsTableView.tableView.selectedItem + setPostIdToInfoPanelView(selectedItem) + splitpane.add(infoPanelView) + splitpane.setDividerPositions(widgetsController.currentSettings.infoPanelDividerPosition) + } else { + splitpane.items.remove(infoPanelView) + infoPanelView.clear() + } + } + widgetsController.currentSettings.visibleInfoPanelProperty.onChange { + if (mainView.root.selectionModel.selectedIndex != 0) return@onChange + if (it) { + val selectedItem = postsTableView.tableView.selectedItem + setPostIdToInfoPanelView(selectedItem) + splitpane.add(infoPanelView) + splitpane.setDividerPositions(widgetsController.currentSettings.infoPanelDividerPosition) + } else { + splitpane.items.remove(infoPanelView) + infoPanelView.clear() + } + } + widgetsController.currentSettings.visibleToolbarPanelProperty.onChange { + if (it) { + root.children.add(1, actionBarView.root) + } else { + root.children.remove(actionBarView.root) + } + } + widgetsController.currentSettings.visibleStatusBarPanelProperty.onChange { + if (it) { + root.children.add(statusBarView.root) + } else { + root.children.remove(statusBarView.root) + } + } + } + + private fun setPostIdToInfoPanelView(it: PostModel?) { + if (!widgetsController.currentSettings.visibleInfoPanel) { + return + } + val postInfoPanelFragment = find() + if (it != null) { + postInfoPanelFragment.setPostId(it.postId) + } + postInfoPanelFragment.root.hgrow = Priority.ALWAYS + postInfoPanelFragment.root.selectionModel.select(lastSelectedInfoPanelTab) + postInfoPanelFragment.root.selectionModel.selectedIndexProperty().onChange { + lastSelectedInfoPanelTab = it + } + infoPanelView.clear() + infoPanelView.add(postInfoPanelFragment) + } + + override fun onUndock() { + coroutineScope.cancel() + } +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/DownloadActionsView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/DownloadActionsView.kt similarity index 98% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/DownloadActionsView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/DownloadActionsView.kt index a1f32207..6cd249c2 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/DownloadActionsView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/DownloadActionsView.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.actionbar +package me.vripper.gui.components.views import javafx.beans.property.SimpleBooleanProperty import javafx.geometry.Orientation @@ -14,7 +14,6 @@ import kotlinx.coroutines.launch import me.vripper.gui.Styles import me.vripper.gui.controller.GlobalStateController import me.vripper.gui.controller.PostController -import me.vripper.gui.view.tables.PostsTableView import tornadofx.* class DownloadActionsView : View() { diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/LoadingView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/LoadingView.kt similarity index 94% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/LoadingView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/LoadingView.kt index 77baf5ed..f57c7cda 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/LoadingView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/LoadingView.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view +package me.vripper.gui.components.views import javafx.scene.control.ProgressIndicator.INDETERMINATE_PROGRESS import javafx.scene.effect.DropShadow diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/LogActionsView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/LogActionsView.kt similarity index 92% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/LogActionsView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/LogActionsView.kt index 3a719302..d3bde290 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/LogActionsView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/LogActionsView.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.actionbar +package me.vripper.gui.components.views import javafx.scene.control.ButtonType import javafx.scene.control.ContentDisplay @@ -7,7 +7,6 @@ import javafx.scene.input.KeyCodeCombination import javafx.scene.input.KeyCombination import me.vripper.gui.Styles import me.vripper.gui.controller.LogController -import me.vripper.gui.view.tables.LogTableView import tornadofx.* class LogActionsView : View() { diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/LogTableView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/LogTableView.kt similarity index 62% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/LogTableView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/LogTableView.kt index a5187b07..c87d292e 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/LogTableView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/LogTableView.kt @@ -1,20 +1,24 @@ -package me.vripper.gui.view.tables +package me.vripper.gui.components.views import javafx.scene.control.* +import javafx.scene.image.ImageView import kotlinx.coroutines.* import kotlinx.coroutines.flow.filterIsInstance import me.vripper.event.EventBus import me.vripper.event.LogCreateEvent import me.vripper.event.LogDeleteEvent import me.vripper.event.LogUpdateEvent +import me.vripper.gui.components.fragments.ColumnSelectionFragment +import me.vripper.gui.components.fragments.LogMessageFragment import me.vripper.gui.controller.LogController +import me.vripper.gui.controller.WidgetsController import me.vripper.gui.model.LogModel -import me.vripper.gui.view.popup.LogMessageView import tornadofx.* class LogTableView : View() { private val logController: LogController by inject() + private val widgetsController: WidgetsController by inject() private val eventBus: EventBus by di() private lateinit var tableView: TableView private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) @@ -86,20 +90,55 @@ class LogTableView : View() { } tableRow } + contextMenu = ContextMenu() + contextMenu.items.add(MenuItem("Setup columns").apply { + setOnAction { + find( + mapOf( + ColumnSelectionFragment::map to mapOf( + Pair( + "Time", + widgetsController.currentSettings.logsColumnsModel.timeProperty + ), + Pair( + "Type", + widgetsController.currentSettings.logsColumnsModel.typeProperty + ), + Pair( + "Status", + widgetsController.currentSettings.logsColumnsModel.statusProperty + ), + Pair( + "Message", + widgetsController.currentSettings.logsColumnsModel.messageProperty + ), + ) + ) + ).openModal() + } + graphic = ImageView("columns.png").apply { + fitWidth = 18.0 + fitHeight = 18.0 + } + }) column("Time", LogModel::timeProperty) { + visibleProperty().bind(widgetsController.currentSettings.logsColumnsModel.timeProperty) id = "time" prefWidth = 150.0 sortType = TableColumn.SortType.DESCENDING } column("Type", LogModel::typeProperty) { + visibleProperty().bind(widgetsController.currentSettings.logsColumnsModel.typeProperty) id = "type" isSortable = false } column("Status", LogModel::statusProperty) { + visibleProperty().bind(widgetsController.currentSettings.logsColumnsModel.statusProperty) id = "status" isSortable = false } column("Message", LogModel::messageProperty) { + visibleProperty().bind(widgetsController.currentSettings.logsColumnsModel.messageProperty) id = "message" prefWidth = 300.0 isSortable = false @@ -108,7 +147,7 @@ class LogTableView : View() { } private fun openLog(item: LogModel) { - find(mapOf(LogMessageView::logModel to item)).openModal()?.apply { + find(mapOf(LogMessageFragment::logModel to item)).openModal()?.apply { minWidth = 600.0 minHeight = 400.0 } diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/main/MainView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/MainView.kt similarity index 85% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/main/MainView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/MainView.kt index 67faa0a9..e679053c 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/main/MainView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/MainView.kt @@ -1,15 +1,8 @@ -package me.vripper.gui.view.main +package me.vripper.gui.components.views import javafx.scene.control.TabPane import javafx.scene.image.ImageView import javafx.util.Duration -import me.vripper.gui.view.actionbar.ActionBarView -import me.vripper.gui.view.actionbar.DownloadActionsView -import me.vripper.gui.view.actionbar.LogActionsView -import me.vripper.gui.view.actionbar.ThreadActionsView -import me.vripper.gui.view.tables.LogTableView -import me.vripper.gui.view.tables.PostsTableView -import me.vripper.gui.view.tables.ThreadTableView import tornadofx.* class MainView : View("Center view") { diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/MenuBarView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/MenuBarView.kt new file mode 100644 index 00000000..34504671 --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/MenuBarView.kt @@ -0,0 +1,220 @@ +package me.vripper.gui.components.views + +import javafx.beans.property.SimpleBooleanProperty +import javafx.scene.control.ButtonType +import javafx.scene.input.KeyCode +import javafx.scene.input.KeyCodeCombination +import javafx.scene.input.KeyCombination +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.launch +import me.vripper.gui.VripperGuiApplication +import me.vripper.gui.components.fragments.AboutFragment +import me.vripper.gui.components.fragments.AddLinksFragment +import me.vripper.gui.components.fragments.SettingsFragment +import me.vripper.gui.controller.GlobalStateController +import me.vripper.gui.controller.PostController +import me.vripper.gui.controller.WidgetsController +import me.vripper.gui.utils.openLink +import me.vripper.utilities.ApplicationProperties +import tornadofx.* + +class MenuBarView : View() { + + private val globalStateController: GlobalStateController by inject() + private val postController: PostController by inject() + private val postsTableView: PostsTableView by inject() + private val downloadActiveProperty = SimpleBooleanProperty(true) + private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) + private val widgetsController: WidgetsController by inject() + + init { + downloadActiveProperty.bind(globalStateController.globalState.runningProperty.greaterThan(0)) + } + + override val root = menubar { + menu("File") { + item("Add links", KeyCodeCombination(KeyCode.L, KeyCombination.CONTROL_DOWN)).apply { + graphic = imageview("plus.png") { + fitWidth = 18.0 + fitHeight = 18.0 + } + action { + find().apply { + input.clear() + }.openModal() + } + } + separator() + item("Start All", KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN)).apply { + graphic = imageview("end.png") { + fitWidth = 18.0 + fitHeight = 18.0 + } + disableWhen(downloadActiveProperty) + action { + postController.startAll() + } + } + item("Stop All", KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN)).apply { + graphic = imageview("stop.png") { + fitWidth = 18.0 + fitHeight = 18.0 + } + disableWhen(downloadActiveProperty.not()) + action { + postController.stopAll() + } + } + item("Start", KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN)).apply { + graphic = imageview("play.png") { + fitWidth = 18.0 + fitHeight = 18.0 + } + enableWhen( + postsTableView.tableView.selectionModel.selectedItems.sizeProperty.greaterThan( + 0 + ) + ) + action { + postsTableView.startSelected() + } + } + item("Stop", KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN)).apply { + graphic = imageview("pause.png") { + fitWidth = 18.0 + fitHeight = 18.0 + } + enableWhen( + postsTableView.tableView.selectionModel.selectedItems.sizeProperty.greaterThan( + 0 + ) + ) + action { + postsTableView.stopSelected() + } + } + item("Rename", KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN)).apply { + graphic = imageview("edit.png") { + fitWidth = 18.0 + fitHeight = 18.0 + } + enableWhen( + postsTableView.tableView.selectionModel.selectedItems.sizeProperty.greaterThan( + 0 + ) + ) + action { + postsTableView.renameSelected() + } + } + item("Delete", KeyCodeCombination(KeyCode.DELETE)).apply { + graphic = imageview("trash.png") { + fitWidth = 18.0 + fitHeight = 18.0 + } + enableWhen( + postsTableView.tableView.selectionModel.selectedItems.sizeProperty.greaterThan( + 0 + ) + ) + action { + postsTableView.deleteSelected() + } + } + item("Clear", KeyCodeCombination(KeyCode.DELETE, KeyCombination.CONTROL_DOWN)).apply { + graphic = imageview("broom.png") { + fitWidth = 18.0 + fitHeight = 18.0 + } + action { + confirm( + "Clean finished posts", "Confirm removal of finished posts", ButtonType.YES, ButtonType.NO + ) { + coroutineScope.launch { + val clearPosts = postController.clearPosts().await() + coroutineScope.launch { + runLater { + postsTableView.tableView.items.removeIf { clearPosts.contains(it.postId) } + } + } + } + } + } + } + separator() + item("Settings", KeyCodeCombination(KeyCode.S)).apply { + graphic = imageview("settings.png") { + fitWidth = 18.0 + fitHeight = 18.0 + } + action { + find().openModal()?.apply { + minWidth = 600.0 + minHeight = 400.0 + } + } + } + separator() + item("Exit", KeyCodeCombination(KeyCode.X, KeyCombination.CONTROL_DOWN)).apply { + graphic = imageview("close.png") { + fitWidth = 18.0 + fitHeight = 18.0 + } + action { + VripperGuiApplication.APP_INSTANCE.stop() + } + } + } + menu("View") { + checkmenuitem( + "Toolbar", KeyCodeCombination(KeyCode.F6) + ).bind(widgetsController.currentSettings.visibleToolbarPanelProperty) + checkmenuitem( + "Info Panel", KeyCodeCombination(KeyCode.F7) + ).bind(widgetsController.currentSettings.visibleInfoPanelProperty) + checkmenuitem( + "Status bar", KeyCodeCombination(KeyCode.F8) + ).bind(widgetsController.currentSettings.visibleStatusBarPanelProperty) + } + menu("Help") { + item("Check for updates").apply { + imageview("available-updates.png") { fitWidth = 18.0; fitHeight = 18.0 } + action { + val latestVersion = ApplicationProperties.latestVersion() + val currentVersion = ApplicationProperties.VERSION + + if (latestVersion > currentVersion) { + information( + header = "Please update to the latest version of VRipper v$latestVersion", + content = "Do you want to go to the release page ?", + title = "VRipper updates", + buttons = arrayOf(ButtonType.YES, ButtonType.NO), + ) { + if (it == ButtonType.YES) { + openLink("https://github.com/death-claw/vripper-project/releases/tag/$latestVersion") + } + } + } else { + information( + header = "No updates have been found", + content = "You are running the latest version of VRipper.", + title = "VRipper updates" + ) + } + } + } + separator() + item("About").apply { + imageview("about.png") { fitWidth = 18.0; fitHeight = 18.0 } + action { + find().openModal()?.apply { + this.minWidth = 550.0 + this.minHeight = 200.0 + } + } + } + } + } +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/PostsTableView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/PostsTableView.kt similarity index 71% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/PostsTableView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/PostsTableView.kt index a1b18782..2b1b0c0e 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/PostsTableView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/PostsTableView.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.tables +package me.vripper.gui.components.views import javafx.collections.FXCollections import javafx.collections.ObservableList @@ -16,16 +16,25 @@ import kotlinx.coroutines.flow.filterIsInstance import kotlinx.coroutines.launch import me.vripper.event.* import me.vripper.event.EventBus -import me.vripper.gui.clipboard.ClipboardService +import me.vripper.gui.components.cells.PreviewTableCell +import me.vripper.gui.components.cells.ProgressTableCell +import me.vripper.gui.components.cells.StatusTableCell +import me.vripper.gui.components.fragments.AddLinksFragment +import me.vripper.gui.components.fragments.ColumnSelectionFragment +import me.vripper.gui.components.fragments.RenameFragment import me.vripper.gui.controller.PostController +import me.vripper.gui.controller.WidgetsController import me.vripper.gui.model.PostModel -import me.vripper.gui.view.* -import me.vripper.gui.view.popup.RenameView +import me.vripper.gui.services.ClipboardService +import me.vripper.gui.utils.Preview +import me.vripper.gui.utils.openFileDirectory +import me.vripper.gui.utils.openLink import tornadofx.* class PostsTableView : View() { private val postController: PostController by inject() + private val widgetsController: WidgetsController by inject() private val clipboardService: ClipboardService by di() private val eventBus: EventBus by di() private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) @@ -58,7 +67,7 @@ class PostsTableView : View() { coroutineScope.launch { eventBus.events.filterIsInstance(PostCreateEvent::class).collect { postEvents -> - val add = postEvents.posts.map { postController.mapper(it.id) } + val add = postEvents.posts.map { postController.mapper(it.postId) } runLater { tableView.items.addAll(add) } @@ -97,18 +106,15 @@ class PostsTableView : View() { } } coroutineScope.launch { - eventBus.events.filterIsInstance(MetadataUpdateEvent::class) - .collect { metadataUpdateEvent -> - runLater { - val postModel = - items.find { it.postId == metadataUpdateEvent.metadata.postId } - ?: return@runLater + eventBus.events.filterIsInstance(MetadataUpdateEvent::class).collect { metadataUpdateEvent -> + runLater { + val postModel = items.find { it.postId == metadataUpdateEvent.metadata.postId } ?: return@runLater - postModel.altTitles = - FXCollections.observableArrayList(metadataUpdateEvent.metadata.data.resolvedNames) - postModel.postedby = metadataUpdateEvent.metadata.data.postedBy - } + postModel.altTitles = + FXCollections.observableArrayList(metadataUpdateEvent.metadata.data.resolvedNames) + postModel.postedby = metadataUpdateEvent.metadata.data.postedBy } + } } } @@ -117,11 +123,6 @@ class PostsTableView : View() { selectionModel.selectionMode = SelectionMode.MULTIPLE setRowFactory { val tableRow = TableRow() - tableRow.setOnMouseClicked { - if (it.clickCount == 2 && tableRow.item != null) { - openPhotos(tableRow.item.postId) - } - } val startItem = MenuItem("Start").apply { setOnAction { @@ -163,16 +164,6 @@ class PostsTableView : View() { } } - val detailsItem = MenuItem("Images").apply { - setOnAction { - openPhotos(tableRow.item.postId) - } - graphic = ImageView("details.png").apply { - fitWidth = 18.0 - fitHeight = 18.0 - } - } - val locationItem = MenuItem("Open containing folder").apply { setOnAction { openFileDirectory(tableRow.item.path) @@ -195,20 +186,64 @@ class PostsTableView : View() { val contextMenu = ContextMenu() contextMenu.items.addAll( - startItem, - stopItem, - renameItem, - deleteItem, - SeparatorMenuItem(), - detailsItem, - locationItem, - urlItem + startItem, stopItem, renameItem, deleteItem, SeparatorMenuItem(), locationItem, urlItem ) - tableRow.contextMenuProperty().bind(tableRow.emptyProperty() - .map { empty -> if (empty) null else contextMenu }) + tableRow.contextMenuProperty() + .bind(tableRow.emptyProperty().map { empty -> if (empty) null else contextMenu }) tableRow } + contextMenu = ContextMenu() + contextMenu.items.addAll(MenuItem( + "Add links", + ImageView("plus.png").apply { fitWidth = 18.0; fitHeight = 18.0 }).apply { + action { + find().apply { + input.clear() + }.openModal() + } + }, SeparatorMenuItem(), MenuItem("Setup columns").apply { + setOnAction { + find( + mapOf( + ColumnSelectionFragment::map to mapOf( + Pair( + "Preview", widgetsController.currentSettings.postsColumnsModel.previewProperty + ), + Pair( + "Title", widgetsController.currentSettings.postsColumnsModel.titleProperty + ), + Pair( + "Progress", widgetsController.currentSettings.postsColumnsModel.progressProperty + ), + Pair( + "Status", widgetsController.currentSettings.postsColumnsModel.statusProperty + ), + Pair( + "Path", widgetsController.currentSettings.postsColumnsModel.pathProperty + ), + Pair( + "Total", widgetsController.currentSettings.postsColumnsModel.totalProperty + ), + Pair( + "Hosts", widgetsController.currentSettings.postsColumnsModel.hostsProperty + ), + Pair( + "Added On", widgetsController.currentSettings.postsColumnsModel.addedOnProperty + ), + Pair( + "Order", widgetsController.currentSettings.postsColumnsModel.orderProperty + ), + ) + ) + ).openModal() + } + graphic = ImageView("columns.png").apply { + fitWidth = 18.0 + fitHeight = 18.0 + } + }) column("Preview", PostModel::previewListProperty) { + visibleProperty().bind(widgetsController.currentSettings.postsColumnsModel.previewProperty) prefWidth = 50.0 cellFactory = Callback { val cell = PreviewTableCell() @@ -235,12 +270,14 @@ class PostsTableView : View() { } } column("Title", PostModel::titleProperty) { + visibleProperty().bind(widgetsController.currentSettings.postsColumnsModel.titleProperty) prefWidth = 250.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("Progress", PostModel::progressProperty) { + visibleProperty().bind(widgetsController.currentSettings.postsColumnsModel.progressProperty) prefWidth = 100.0 cellFactory = Callback { val cell = ProgressTableCell() @@ -272,8 +309,6 @@ class PostsTableView : View() { this@tableview.selectionModel.select(cell.tableRow.index) } } - - 2 -> openPhotos(cell.tableRow.item.postId) } } @@ -284,42 +319,42 @@ class PostsTableView : View() { } } column("Status", PostModel::statusProperty) { + visibleProperty().bind(widgetsController.currentSettings.postsColumnsModel.statusProperty) prefWidth = 50.0 cellFactory = Callback { StatusTableCell() } } column("Path", PostModel::pathProperty) { + visibleProperty().bind(widgetsController.currentSettings.postsColumnsModel.pathProperty) prefWidth = 250.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("Total", PostModel::progressCountProperty) { + visibleProperty().bind(widgetsController.currentSettings.postsColumnsModel.totalProperty) prefWidth = 150.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("Hosts", PostModel::hostsProperty) { + visibleProperty().bind(widgetsController.currentSettings.postsColumnsModel.hostsProperty) prefWidth = 100.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("Added On", PostModel::addedOnProperty) { - prefWidth = 100.0 - cellFactory = Callback { - TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } - } - } - column("Posted By", PostModel::postedByProperty) { + visibleProperty().bind(widgetsController.currentSettings.postsColumnsModel.addedOnProperty) prefWidth = 100.0 cellFactory = Callback { TextFieldTableCell().apply { alignment = Pos.CENTER_LEFT } } } column("Order", PostModel::orderProperty) { + visibleProperty().bind(widgetsController.currentSettings.postsColumnsModel.orderProperty) prefWidth = 50.0 sortOrder.add(this) cellFactory = Callback { @@ -330,11 +365,11 @@ class PostsTableView : View() { } private fun rename(post: PostModel) { - find( + find( mapOf( - RenameView::postId to post.postId, - RenameView::name to post.folderName, - RenameView::altTitles to post.altTitles + RenameFragment::postId to post.postId, + RenameFragment::name to post.folderName, + RenameFragment::altTitles to post.altTitles ) ).openModal()?.apply { minWidth = 450.0 @@ -370,11 +405,4 @@ class PostsTableView : View() { val postIdList = tableView.selectionModel.selectedItems.map { it.postId } postController.start(postIdList) } - - private fun openPhotos(postId: Long) { - find(mapOf(ImagesTableView::postId to postId)).openModal()?.apply { - minWidth = 800.0 - minHeight = 600.0 - } - } } \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/status/StatusBarView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/StatusBarView.kt similarity index 97% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/status/StatusBarView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/StatusBarView.kt index b60d74b9..ead76855 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/status/StatusBarView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/StatusBarView.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.status +package me.vripper.gui.components.views import javafx.geometry.Orientation import javafx.geometry.Pos diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/ThreadActionsView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/ThreadActionsView.kt similarity index 95% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/ThreadActionsView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/ThreadActionsView.kt index 521e972e..84ada736 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/actionbar/ThreadActionsView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/ThreadActionsView.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.actionbar +package me.vripper.gui.components.views import javafx.scene.control.ButtonType import javafx.scene.control.ContentDisplay @@ -7,7 +7,6 @@ import javafx.scene.input.KeyCodeCombination import javafx.scene.input.KeyCombination import me.vripper.gui.Styles import me.vripper.gui.controller.ThreadController -import me.vripper.gui.view.tables.ThreadTableView import tornadofx.* class ThreadActionsView : View() { diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/ThreadTableView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/ThreadTableView.kt similarity index 66% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/ThreadTableView.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/components/views/ThreadTableView.kt index 31be60f0..71e3ba6c 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/tables/ThreadTableView.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/components/views/ThreadTableView.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.view.tables +package me.vripper.gui.components.views import javafx.collections.FXCollections import javafx.collections.ObservableList @@ -10,14 +10,18 @@ import me.vripper.event.EventBus import me.vripper.event.ThreadClearEvent import me.vripper.event.ThreadCreateEvent import me.vripper.event.ThreadDeleteEvent +import me.vripper.gui.components.fragments.ColumnSelectionFragment +import me.vripper.gui.components.fragments.ThreadSelectionTableFragment import me.vripper.gui.controller.ThreadController +import me.vripper.gui.controller.WidgetsController import me.vripper.gui.model.ThreadModel -import me.vripper.gui.view.openLink +import me.vripper.gui.utils.openLink import tornadofx.* class ThreadTableView : View() { private val threadController: ThreadController by inject() + private val widgetsController: WidgetsController by inject() private val eventBus: EventBus by di() private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) lateinit var tableView: TableView @@ -54,6 +58,15 @@ class ThreadTableView : View() { } } + coroutineScope.launch { + eventBus.events.filterIsInstance(ThreadCreateEvent::class).collect { + val threadModelMapper = threadController.threadModelMapper(it.thread) + runLater { + items.add(threadModelMapper) + } + } + } + coroutineScope.launch { eventBus.events.filterIsInstance(ThreadDeleteEvent::class).collect { event -> runLater { @@ -115,17 +128,45 @@ class ThreadTableView : View() { val contextMenu = ContextMenu() contextMenu.items.addAll(selectItem, urlItem, SeparatorMenuItem(), deleteItem) - tableRow.contextMenuProperty().bind(tableRow.emptyProperty() - .map { empty -> if (empty) null else contextMenu }) + tableRow.contextMenuProperty() + .bind(tableRow.emptyProperty().map { empty -> if (empty) null else contextMenu }) tableRow } + contextMenu = ContextMenu() + contextMenu.items.add(MenuItem("Setup columns").apply { + setOnAction { + find( + mapOf( + ColumnSelectionFragment::map to mapOf( + Pair( + "Title", widgetsController.currentSettings.threadsColumnsModel.titleProperty + ), + Pair( + "URL", widgetsController.currentSettings.threadsColumnsModel.linkProperty + ), + Pair( + "Count", widgetsController.currentSettings.threadsColumnsModel.countProperty + ), + ) + ) + ).openModal() + } + graphic = ImageView("columns.png").apply { + fitWidth = 18.0 + fitHeight = 18.0 + } + }) column("Title", ThreadModel::titleProperty) { + visibleProperty().bind(widgetsController.currentSettings.threadsColumnsModel.titleProperty) prefWidth = 350.0 } column("URL", ThreadModel::linkProperty) { + visibleProperty().bind(widgetsController.currentSettings.threadsColumnsModel.linkProperty) prefWidth = 350.0 } - column("Count", ThreadModel::totalProperty) + column("Count", ThreadModel::totalProperty) { + visibleProperty().bind(widgetsController.currentSettings.threadsColumnsModel.countProperty) + } } } @@ -142,7 +183,7 @@ class ThreadTableView : View() { } private fun selectPosts(threadId: Long) { - find(mapOf(ThreadSelectionTableView::threadId to threadId)).openModal() + find(mapOf(ThreadSelectionTableFragment::threadId to threadId)).openModal() ?.apply { minWidth = 600.0 minHeight = 400.0 diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/controller/ImageController.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/controller/ImageController.kt index 86940580..8905f0c3 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/controller/ImageController.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/controller/ImageController.kt @@ -3,7 +3,7 @@ package me.vripper.gui.controller import me.vripper.entities.Image import me.vripper.gui.model.ImageModel import me.vripper.services.DataTransaction -import tornadofx.* +import tornadofx.Controller class ImageController : Controller() { @@ -22,7 +22,8 @@ class ImageController : Controller() { it.status.name, it.size, it.downloaded, - it.filename + it.filename, + it.thumbUrl ) } diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/controller/PostController.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/controller/PostController.kt index 7e98199e..7771016d 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/controller/PostController.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/controller/PostController.kt @@ -7,7 +7,7 @@ import me.vripper.gui.model.PostModel import me.vripper.services.AppEndpointService import me.vripper.services.DataTransaction import me.vripper.utilities.formatSI -import tornadofx.* +import tornadofx.Controller import java.time.format.DateTimeFormatter class PostController : Controller() { @@ -57,12 +57,16 @@ class PostController : Controller() { } } + fun find(postId: Long): Deferred { + return coroutineScope.async { mapper(postId) } + } + fun findAllPosts(): Deferred> { - return coroutineScope.async { dataTransaction.findAllPosts().map { it.id }.map(::mapper) } + return coroutineScope.async { dataTransaction.findAllPosts().map { it.postId }.map(::mapper) } } - fun mapper(id: Long): PostModel { - val post = dataTransaction.findPostById(id).orElseThrow() + fun mapper(postId: Long): PostModel { + val post = dataTransaction.findPostByPostId(postId).orElseThrow() val metadata = dataTransaction.findMetadataByPostId(post.postId) return PostModel( post.postId, diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/controller/WidgetsController.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/controller/WidgetsController.kt new file mode 100644 index 00000000..2b0a0aea --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/controller/WidgetsController.kt @@ -0,0 +1,280 @@ +package me.vripper.gui.controller + +import kotlinx.serialization.Serializable +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json +import me.vripper.gui.model.WidgetsViewModel +import me.vripper.utilities.ApplicationProperties +import tornadofx.Controller +import tornadofx.onChange +import java.nio.file.Files + +private val WIDGETS_CONFIG_PATH = ApplicationProperties.VRIPPER_DIR.resolve("widgets-config.json") + +class WidgetsController : Controller() { + + private val json = Json { + prettyPrint = true + allowSpecialFloatingPointValues = true + ignoreUnknownKeys = true + encodeDefaults = true + } + + @Serializable + data class ThreadSelectionTableColumns( + val preview: Boolean = true, + val index: Boolean = true, + val title: Boolean = true, + val link: Boolean = true, + val hosts: Boolean = true, + ) + + @Serializable + data class LogsTableColumns( + val time: Boolean = true, + val type: Boolean = true, + val status: Boolean = true, + val message: Boolean = true, + ) + + @Serializable + data class ThreadsTableColumns( + val title: Boolean = true, + val link: Boolean = true, + val count: Boolean = true, + ) + + @Serializable + data class PostsTableColumns( + val preview: Boolean = true, + val title: Boolean = true, + val progress: Boolean = true, + val status: Boolean = true, + val path: Boolean = true, + val total: Boolean = true, + val hosts: Boolean = true, + val addedOn: Boolean = true, + val order: Boolean = true, + ) + + @Serializable + data class ImagesTableColumns( + val preview: Boolean = true, + val index: Boolean = true, + val link: Boolean = true, + val progress: Boolean = true, + val filename: Boolean = true, + val status: Boolean = true, + val size: Boolean = true, + val downloaded: Boolean = true, + ) + + @Serializable + data class WidgetsSettings( + val visibleInfoPanel: Boolean = true, + val visibleToolbarPanel: Boolean = true, + val visibleStatusBarPanel: Boolean = true, + val infoPanelDividerPosition: Double = 0.7, + val width: Double = 1366.0, + val height: Double = 768.0, + val postsTableColumns: PostsTableColumns = PostsTableColumns(), + val imagesTableColumns: ImagesTableColumns = ImagesTableColumns(), + val threadsTableColumns: ThreadsTableColumns = ThreadsTableColumns(), + val logsTableColumns: LogsTableColumns = LogsTableColumns(), + val threadSelectionColumns: ThreadSelectionTableColumns = ThreadSelectionTableColumns(), + ) + + var currentSettings: WidgetsViewModel = loadSettings().let { + WidgetsViewModel( + it.visibleInfoPanel, + it.visibleToolbarPanel, + it.visibleStatusBarPanel, + it.infoPanelDividerPosition, + it.width, + it.height, + it.postsTableColumns, + it.imagesTableColumns, + it.threadsTableColumns, + it.logsTableColumns, + it.threadSelectionColumns + ) + } + + init { + currentSettings.visibleInfoPanelProperty.onChange { + update() + } + currentSettings.visibleToolbarPanelProperty.onChange { + update() + } + currentSettings.visibleStatusBarPanelProperty.onChange { + update() + } + currentSettings.postsColumnsModel.previewProperty.onChange { + update() + } + currentSettings.postsColumnsModel.progressProperty.onChange { + update() + } + currentSettings.postsColumnsModel.addedOnProperty.onChange { + update() + } + currentSettings.postsColumnsModel.hostsProperty.onChange { + update() + } + currentSettings.postsColumnsModel.orderProperty.onChange { + update() + } + currentSettings.postsColumnsModel.pathProperty.onChange { + update() + } + currentSettings.postsColumnsModel.statusProperty.onChange { + update() + } + currentSettings.postsColumnsModel.titleProperty.onChange { + update() + } + currentSettings.postsColumnsModel.totalProperty.onChange { + update() + } + currentSettings.imagesColumnsModel.previewProperty.onChange { + update() + } + currentSettings.imagesColumnsModel.indexProperty.onChange { + update() + } + currentSettings.imagesColumnsModel.linkProperty.onChange { + update() + } + currentSettings.imagesColumnsModel.progressProperty.onChange { + update() + } + currentSettings.imagesColumnsModel.filenameProperty.onChange { + update() + } + currentSettings.imagesColumnsModel.statusProperty.onChange { + update() + } + currentSettings.imagesColumnsModel.sizeProperty.onChange { + update() + } + currentSettings.imagesColumnsModel.downloadedProperty.onChange { + update() + } + currentSettings.threadsColumnsModel.titleProperty.onChange { + update() + } + currentSettings.threadsColumnsModel.linkProperty.onChange { + update() + } + currentSettings.threadsColumnsModel.countProperty.onChange { + update() + } + currentSettings.threadSelectionColumnsModel.previewProperty.onChange { + update() + } + currentSettings.threadSelectionColumnsModel.indexProperty.onChange { + update() + } + currentSettings.threadSelectionColumnsModel.titleProperty.onChange { + update() + } + currentSettings.threadSelectionColumnsModel.linkProperty.onChange { + update() + } + currentSettings.threadSelectionColumnsModel.hostsProperty.onChange { + update() + } + currentSettings.logsColumnsModel.timeProperty.onChange { + update() + } + currentSettings.logsColumnsModel.typeProperty.onChange { + update() + } + currentSettings.logsColumnsModel.statusProperty.onChange { + update() + } + currentSettings.logsColumnsModel.messageProperty.onChange { + update() + } + } + + private fun loadSettings(): WidgetsSettings { + if (!Files.exists(WIDGETS_CONFIG_PATH)) { + val widgetsSettings = WidgetsSettings() + currentSettings = WidgetsViewModel( + widgetsSettings.visibleInfoPanel, + widgetsSettings.visibleToolbarPanel, + widgetsSettings.visibleStatusBarPanel, + widgetsSettings.infoPanelDividerPosition, + widgetsSettings.width, + widgetsSettings.height, + widgetsSettings.postsTableColumns, + widgetsSettings.imagesTableColumns, + widgetsSettings.threadsTableColumns, + widgetsSettings.logsTableColumns, + widgetsSettings.threadSelectionColumns + ) + synchronized(this) { + update() + } + } + return (json.decodeFromString(Files.readString(WIDGETS_CONFIG_PATH)) as WidgetsSettings) + + } + + @Synchronized + fun update() { + Files.writeString( + WIDGETS_CONFIG_PATH, json.encodeToString( + WidgetsSettings( + currentSettings.visibleInfoPanel, + currentSettings.visibleToolbarPanel, + currentSettings.visibleStatusBarPanel, + currentSettings.infoPanelDividerPosition, + currentSettings.width, + currentSettings.height, + PostsTableColumns( + currentSettings.postsColumnsModel.preview, + currentSettings.postsColumnsModel.title, + currentSettings.postsColumnsModel.progress, + currentSettings.postsColumnsModel.status, + currentSettings.postsColumnsModel.path, + currentSettings.postsColumnsModel.total, + currentSettings.postsColumnsModel.hosts, + currentSettings.postsColumnsModel.addedOn, + currentSettings.postsColumnsModel.order, + ), + ImagesTableColumns( + currentSettings.imagesColumnsModel.preview, + currentSettings.imagesColumnsModel.index, + currentSettings.imagesColumnsModel.link, + currentSettings.imagesColumnsModel.progress, + currentSettings.imagesColumnsModel.filename, + currentSettings.imagesColumnsModel.status, + currentSettings.imagesColumnsModel.size, + currentSettings.imagesColumnsModel.downloaded, + ), + ThreadsTableColumns( + currentSettings.threadsColumnsModel.title, + currentSettings.threadsColumnsModel.link, + currentSettings.threadsColumnsModel.count, + ), + LogsTableColumns( + currentSettings.logsColumnsModel.time, + currentSettings.logsColumnsModel.type, + currentSettings.logsColumnsModel.status, + currentSettings.logsColumnsModel.message, + ), + ThreadSelectionTableColumns( + currentSettings.threadSelectionColumnsModel.preview, + currentSettings.threadSelectionColumnsModel.index, + currentSettings.threadSelectionColumnsModel.title, + currentSettings.threadSelectionColumnsModel.link, + currentSettings.threadSelectionColumnsModel.hosts, + ) + ) + ) + ) + } +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/model/ImageModel.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/model/ImageModel.kt index 964d1127..8d2ac99c 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/model/ImageModel.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/model/ImageModel.kt @@ -1,11 +1,11 @@ package me.vripper.gui.model -import javafx.beans.property.SimpleDoubleProperty -import javafx.beans.property.SimpleIntegerProperty -import javafx.beans.property.SimpleLongProperty -import javafx.beans.property.SimpleStringProperty +import javafx.beans.property.* +import javafx.collections.FXCollections +import javafx.collections.ObservableList import me.vripper.utilities.formatSI -import tornadofx.* +import tornadofx.getValue +import tornadofx.setValue class ImageModel( id: Long, @@ -15,7 +15,8 @@ class ImageModel( status: String, size: Long, downloaded: Long, - filename: String + filename: String, + thumbUrl: String, ) { val idProperty = SimpleLongProperty(id) @@ -36,6 +37,9 @@ class ImageModel( val filenameProperty = SimpleStringProperty(filename) var filename: String by filenameProperty + val thumbUrlProperty = SimpleListProperty(FXCollections.observableArrayList(thumbUrl)) + var thumbUrl: ObservableList by thumbUrlProperty + val sizeProperty = SimpleStringProperty(size.formatSI()) var size = size set(value) { diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/model/ImagesColumnsModel.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/model/ImagesColumnsModel.kt new file mode 100644 index 00000000..ae46e21f --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/model/ImagesColumnsModel.kt @@ -0,0 +1,40 @@ +package me.vripper.gui.model + +import javafx.beans.property.SimpleBooleanProperty +import tornadofx.getValue +import tornadofx.setValue + +class ImagesColumnsModel( + preview: Boolean, + index: Boolean, + link: Boolean, + progress: Boolean, + filename: Boolean, + status: Boolean, + size: Boolean, + downloaded: Boolean, +) { + val previewProperty = SimpleBooleanProperty(preview) + var preview: Boolean by previewProperty + + val indexProperty = SimpleBooleanProperty(index) + var index: Boolean by indexProperty + + val linkProperty = SimpleBooleanProperty(link) + var link: Boolean by linkProperty + + val progressProperty = SimpleBooleanProperty(progress) + var progress: Boolean by progressProperty + + val filenameProperty = SimpleBooleanProperty(filename) + var filename: Boolean by filenameProperty + + val statusProperty = SimpleBooleanProperty(status) + var status: Boolean by statusProperty + + val sizeProperty = SimpleBooleanProperty(size) + var size: Boolean by sizeProperty + + val downloadedProperty = SimpleBooleanProperty(downloaded) + var downloaded: Boolean by downloadedProperty +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/model/LogsColumnsModel.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/model/LogsColumnsModel.kt new file mode 100644 index 00000000..48ad382e --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/model/LogsColumnsModel.kt @@ -0,0 +1,24 @@ +package me.vripper.gui.model + +import javafx.beans.property.SimpleBooleanProperty +import tornadofx.getValue +import tornadofx.setValue + +class LogsColumnsModel( + time: Boolean, + type: Boolean, + status: Boolean, + message: Boolean, +) { + val timeProperty = SimpleBooleanProperty(time) + var time: Boolean by timeProperty + + val typeProperty = SimpleBooleanProperty(type) + var type: Boolean by typeProperty + + val statusProperty = SimpleBooleanProperty(status) + var status: Boolean by statusProperty + + val messageProperty = SimpleBooleanProperty(message) + var message: Boolean by messageProperty +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostModel.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostModel.kt index 0a1b40f4..7435cb1d 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostModel.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostModel.kt @@ -4,7 +4,8 @@ import javafx.beans.property.* import javafx.collections.FXCollections import javafx.collections.ObservableList import me.vripper.entities.Metadata -import tornadofx.* +import tornadofx.getValue +import tornadofx.setValue class PostModel( postId: Long, @@ -62,8 +63,8 @@ class PostModel( val progressCountProperty = SimpleStringProperty(progressCount) var progressCount: String by progressCountProperty - val previewListProperty = SimpleStringProperty(previewList.joinToString("|")) - var previewList: List = previewListProperty.value.split("|") + val previewListProperty = SimpleListProperty(FXCollections.observableArrayList(previewList)) + var previewList: ObservableList by previewListProperty val altTitlesProperty = SimpleListProperty(FXCollections.observableArrayList(metadata.data.resolvedNames)) diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostsColumnsModel.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostsColumnsModel.kt new file mode 100644 index 00000000..b7516dfe --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/model/PostsColumnsModel.kt @@ -0,0 +1,44 @@ +package me.vripper.gui.model + +import javafx.beans.property.SimpleBooleanProperty +import tornadofx.getValue +import tornadofx.setValue + +class PostsColumnsModel( + preview: Boolean, + title: Boolean, + progress: Boolean, + status: Boolean, + path: Boolean, + total: Boolean, + hosts: Boolean, + addedOn: Boolean, + order: Boolean, +) { + val previewProperty = SimpleBooleanProperty(preview) + var preview: Boolean by previewProperty + + val titleProperty = SimpleBooleanProperty(title) + var title: Boolean by titleProperty + + val progressProperty = SimpleBooleanProperty(progress) + var progress: Boolean by progressProperty + + val statusProperty = SimpleBooleanProperty(status) + var status: Boolean by statusProperty + + val pathProperty = SimpleBooleanProperty(path) + var path: Boolean by pathProperty + + val totalProperty = SimpleBooleanProperty(total) + var total: Boolean by totalProperty + + val hostsProperty = SimpleBooleanProperty(hosts) + var hosts: Boolean by hostsProperty + + val addedOnProperty = SimpleBooleanProperty(addedOn) + var addedOn: Boolean by addedOnProperty + + val orderProperty = SimpleBooleanProperty(order) + var order: Boolean by orderProperty +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/model/ThreadSelectionColumnsModel.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/model/ThreadSelectionColumnsModel.kt new file mode 100644 index 00000000..60c8acfc --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/model/ThreadSelectionColumnsModel.kt @@ -0,0 +1,28 @@ +package me.vripper.gui.model + +import javafx.beans.property.SimpleBooleanProperty +import tornadofx.getValue +import tornadofx.setValue + +class ThreadSelectionColumnsModel( + preview: Boolean, + index: Boolean, + title: Boolean, + link: Boolean, + hosts: Boolean, +) { + val previewProperty = SimpleBooleanProperty(preview) + var preview: Boolean by previewProperty + + val indexProperty = SimpleBooleanProperty(index) + var index: Boolean by indexProperty + + val titleProperty = SimpleBooleanProperty(title) + var title: Boolean by titleProperty + + val linkProperty = SimpleBooleanProperty(link) + var link: Boolean by linkProperty + + val hostsProperty = SimpleBooleanProperty(hosts) + var hosts: Boolean by hostsProperty +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/model/ThreadSelectionModel.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/model/ThreadSelectionModel.kt index 594f7aa1..d0bab79c 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/model/ThreadSelectionModel.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/model/ThreadSelectionModel.kt @@ -1,7 +1,10 @@ package me.vripper.gui.model import javafx.beans.property.SimpleIntegerProperty +import javafx.beans.property.SimpleListProperty import javafx.beans.property.SimpleStringProperty +import javafx.collections.FXCollections +import javafx.collections.ObservableList import tornadofx.getValue import tornadofx.setValue @@ -26,6 +29,6 @@ class ThreadSelectionModel( val hostsProperty = SimpleStringProperty(hosts.joinToString(", ") { "${it.first} (${it.second})" }) var hosts: String by hostsProperty - val previewListProperty = SimpleStringProperty(previewList.joinToString("|")) - var previewList: List = previewListProperty.value.split("|") + val previewListProperty = SimpleListProperty(FXCollections.observableArrayList(previewList)) + var previewList: ObservableList by previewListProperty } diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/model/ThreadsColumnsModel.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/model/ThreadsColumnsModel.kt new file mode 100644 index 00000000..1934d397 --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/model/ThreadsColumnsModel.kt @@ -0,0 +1,20 @@ +package me.vripper.gui.model + +import javafx.beans.property.SimpleBooleanProperty +import tornadofx.getValue +import tornadofx.setValue + +class ThreadsColumnsModel( + title: Boolean, + link: Boolean, + count: Boolean, +) { + val titleProperty = SimpleBooleanProperty(title) + var title: Boolean by titleProperty + + val linkProperty = SimpleBooleanProperty(link) + var link: Boolean by linkProperty + + val countProperty = SimpleBooleanProperty(count) + var count: Boolean by countProperty +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/model/WidgetsViewModel.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/model/WidgetsViewModel.kt new file mode 100644 index 00000000..eb760a3f --- /dev/null +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/model/WidgetsViewModel.kt @@ -0,0 +1,83 @@ +package me.vripper.gui.model + +import javafx.beans.property.SimpleBooleanProperty +import javafx.beans.property.SimpleDoubleProperty +import me.vripper.gui.controller.WidgetsController +import tornadofx.getValue +import tornadofx.setValue + +class WidgetsViewModel( + visibleInfoPanel: Boolean, + visibleToolbarPanel: Boolean, + visibleStatusBarPanel: Boolean, + infoPanelDividerPosition: Double, + width: Double, + height: Double, + postsTableColumns: WidgetsController.PostsTableColumns, + imagesTableColumns: WidgetsController.ImagesTableColumns, + threadsTableColumns: WidgetsController.ThreadsTableColumns, + logsTableColumns: WidgetsController.LogsTableColumns, + threadSelectionColumns: WidgetsController.ThreadSelectionTableColumns, +) { + val visibleInfoPanelProperty = SimpleBooleanProperty(visibleInfoPanel) + var visibleInfoPanel: Boolean by visibleInfoPanelProperty + + val visibleToolbarPanelProperty = SimpleBooleanProperty(visibleToolbarPanel) + var visibleToolbarPanel: Boolean by visibleToolbarPanelProperty + + val visibleStatusBarPanelProperty = SimpleBooleanProperty(visibleStatusBarPanel) + var visibleStatusBarPanel: Boolean by visibleStatusBarPanelProperty + + val infoPanelDividerPositionProperty = SimpleDoubleProperty(infoPanelDividerPosition) + var infoPanelDividerPosition: Double by infoPanelDividerPositionProperty + + val widthProperty = SimpleDoubleProperty(width) + var width: Double by widthProperty + + val heightProperty = SimpleDoubleProperty(height) + var height: Double by heightProperty + + val postsColumnsModel = PostsColumnsModel( + postsTableColumns.preview, + postsTableColumns.title, + postsTableColumns.progress, + postsTableColumns.status, + postsTableColumns.path, + postsTableColumns.total, + postsTableColumns.hosts, + postsTableColumns.addedOn, + postsTableColumns.order, + ) + + val imagesColumnsModel = ImagesColumnsModel( + imagesTableColumns.preview, + imagesTableColumns.index, + imagesTableColumns.link, + imagesTableColumns.progress, + imagesTableColumns.filename, + imagesTableColumns.status, + imagesTableColumns.size, + imagesTableColumns.downloaded, + ) + + val threadsColumnsModel = ThreadsColumnsModel( + threadsTableColumns.title, + threadsTableColumns.link, + threadsTableColumns.count, + ) + + val logsColumnsModel = LogsColumnsModel( + logsTableColumns.time, + logsTableColumns.type, + logsTableColumns.status, + logsTableColumns.message, + ) + + val threadSelectionColumnsModel = ThreadSelectionColumnsModel( + threadSelectionColumns.preview, + threadSelectionColumns.index, + threadSelectionColumns.title, + threadSelectionColumns.link, + threadSelectionColumns.hosts, + ) +} \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/clipboard/ClipboardService.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/services/ClipboardService.kt similarity index 96% rename from vripper-gui/src/main/kotlin/me/vripper/gui/clipboard/ClipboardService.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/services/ClipboardService.kt index 888520f4..a890ac24 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/clipboard/ClipboardService.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/services/ClipboardService.kt @@ -1,4 +1,4 @@ -package me.vripper.gui.clipboard +package me.vripper.gui.services import javafx.scene.input.Clipboard import kotlinx.coroutines.* @@ -8,7 +8,7 @@ import me.vripper.event.SettingsUpdateEvent import me.vripper.model.Settings import me.vripper.services.AppEndpointService import me.vripper.services.SettingsService -import tornadofx.* +import tornadofx.runLater class ClipboardService( private val appEndpointService: AppEndpointService, diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/CommonUtils.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/utils/CommonUtils.kt similarity index 89% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/CommonUtils.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/utils/CommonUtils.kt index 2803a398..66768180 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/CommonUtils.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/utils/CommonUtils.kt @@ -1,8 +1,7 @@ -package me.vripper.gui.view +package me.vripper.gui.utils import com.sun.jna.WString import me.vripper.gui.VripperGuiApplication -import me.vripper.gui.utils.Shell32 fun openFileDirectory(path: String) { val os = System.getProperty("os.name") diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/Preview.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/utils/Preview.kt similarity index 54% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/Preview.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/utils/Preview.kt index 64fbc51e..921c232f 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/Preview.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/utils/Preview.kt @@ -1,6 +1,7 @@ -package me.vripper.gui.view +package me.vripper.gui.utils -import javafx.scene.control.ProgressIndicator +import javafx.collections.FXCollections +import javafx.collections.ObservableList import javafx.scene.image.Image import javafx.scene.image.ImageView import javafx.scene.layout.HBox @@ -8,21 +9,38 @@ import javafx.stage.Popup import javafx.stage.Stage import kotlinx.coroutines.* import me.vripper.delegate.LoggerDelegate -import me.vripper.gui.view.PreviewCache.previewDispatcher -import tornadofx.add +import tornadofx.bind import tornadofx.runLater +import tornadofx.sortWith import java.io.ByteArrayInputStream -class Preview(private val owner: Stage, private val images: List) { +class Preview(owner: Stage, private val images: List) { + private var hBox: HBox = HBox() private val log by LoggerDelegate() private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) val previewPopup = Popup() init { - previewPopup.content.add(ProgressIndicator().apply { prefWidth = 25.0; prefHeight = 25.0 }) + val loaded: ObservableList> = FXCollections.observableArrayList() + hBox.children.bind(loaded) { + it.first + } + previewPopup.content.add(hBox) previewPopup.show(owner) - show() + coroutineScope.launch { + images.forEachIndexed { index, url -> + coroutineScope.launch { + val imageView = previewLoading(url).await() + if (imageView != null) { + runLater { + loaded.add(Pair(imageView, index)) + loaded.sortWith { o1, o2 -> o1.second.compareTo(o2.second) } + } + } + } + } + } } fun hide() { @@ -30,30 +48,9 @@ class Preview(private val owner: Stage, private val images: List) { previewPopup.hide() } - private fun show() { - coroutineScope.launch(Dispatchers.Default) { - yield() - val imageViewList = images.map { - withTimeout(10_000L) { - previewLoading(it) - } - }.mapNotNull { - it.await() - } - yield() - runLater { - val hBox = HBox() - imageViewList.forEach { hBox.add(it) } - previewPopup.content.clear() - previewPopup.content.add(hBox) - previewPopup.show(owner) - } - } - } - private fun previewLoading(url: String): Deferred { - return coroutineScope.async(previewDispatcher) { - val imageView = try { + return coroutineScope.async { + try { ByteArrayInputStream(PreviewCache.cache[url]).use { ImageView(Image(it)).apply { isPreserveRatio = true @@ -61,7 +58,7 @@ class Preview(private val owner: Stage, private val images: List) { fitWidth = if (image.width > 200.0) { if (image.width > image.height) 200.0 * image.width / image.height else 200.0 } else { - 200.0 + image.width } } } @@ -69,7 +66,6 @@ class Preview(private val owner: Stage, private val images: List) { log.warn("Failed to load preview $url") null } - imageView } } } \ No newline at end of file diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/PreviewCache.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/utils/PreviewCache.kt similarity index 84% rename from vripper-gui/src/main/kotlin/me/vripper/gui/view/PreviewCache.kt rename to vripper-gui/src/main/kotlin/me/vripper/gui/utils/PreviewCache.kt index 4132748b..2ccad3f9 100644 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/PreviewCache.kt +++ b/vripper-gui/src/main/kotlin/me/vripper/gui/utils/PreviewCache.kt @@ -1,20 +1,17 @@ -package me.vripper.gui.view +package me.vripper.gui.utils import com.github.benmanes.caffeine.cache.Caffeine import com.github.benmanes.caffeine.cache.LoadingCache -import kotlinx.coroutines.asCoroutineDispatcher import me.vripper.services.SettingsService import me.vripper.utilities.hash256 import org.koin.core.component.KoinComponent import org.koin.core.component.inject import java.net.URI import java.nio.file.Files -import java.util.concurrent.Executors import kotlin.io.path.Path object PreviewCache : KoinComponent { - val previewDispatcher = Executors.newCachedThreadPool().asCoroutineDispatcher() private val settingsService: SettingsService by inject() private val cachePath = Path(settingsService.settings.systemSettings.cachePath) @@ -26,7 +23,7 @@ object PreviewCache : KoinComponent { .newBuilder() .weigher { _: String, value: ByteArray -> value.size } .maximumWeight(1024 * 1024 * 100) - .build(::load) + .build(PreviewCache::load) private fun load(url: String): ByteArray { val path = cachePath.resolve(url.hash256()) diff --git a/vripper-gui/src/main/kotlin/me/vripper/gui/view/AppView.kt b/vripper-gui/src/main/kotlin/me/vripper/gui/view/AppView.kt deleted file mode 100644 index 62bfc0df..00000000 --- a/vripper-gui/src/main/kotlin/me/vripper/gui/view/AppView.kt +++ /dev/null @@ -1,23 +0,0 @@ -package me.vripper.gui.view - -import me.vripper.gui.controller.MainController -import me.vripper.gui.view.actionbar.ActionBarView -import me.vripper.gui.view.main.MainView -import me.vripper.gui.view.status.StatusBarView -import tornadofx.View -import tornadofx.borderpane - -class AppView : View() { - - private val mainController: MainController by inject() - - init { - title = "VRipper ${mainController.version}" - } - - override val root = borderpane { - top() - center() - bottom() - } -} \ No newline at end of file diff --git a/vripper-gui/src/main/resources/about.png b/vripper-gui/src/main/resources/about.png new file mode 100644 index 00000000..13316bfe Binary files /dev/null and b/vripper-gui/src/main/resources/about.png differ diff --git a/vripper-gui/src/main/resources/available-updates.png b/vripper-gui/src/main/resources/available-updates.png new file mode 100644 index 00000000..5eed64c5 Binary files /dev/null and b/vripper-gui/src/main/resources/available-updates.png differ diff --git a/vripper-gui/src/main/resources/close.png b/vripper-gui/src/main/resources/close.png new file mode 100644 index 00000000..c5fdf224 Binary files /dev/null and b/vripper-gui/src/main/resources/close.png differ diff --git a/vripper-gui/src/main/resources/columns.png b/vripper-gui/src/main/resources/columns.png new file mode 100644 index 00000000..a9a82960 Binary files /dev/null and b/vripper-gui/src/main/resources/columns.png differ diff --git a/vripper-gui/src/main/resources/info.png b/vripper-gui/src/main/resources/info.png new file mode 100644 index 00000000..3d99958b Binary files /dev/null and b/vripper-gui/src/main/resources/info.png differ