Initial commit
commit
d23de0ce40
|
@ -0,0 +1,66 @@
|
|||
project (RMail)
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
|
||||
cmake_policy(SET CMP0046 NEW)
|
||||
cmake_policy(SET CMP0063 NEW)
|
||||
set(QT_MIN_VERSION "5.3.0")
|
||||
set(KF5_MIN_VERSION "5.2.0")
|
||||
|
||||
find_package(ECM 1.0.0 REQUIRED NO_MODULE)
|
||||
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
include(ExternalProject)
|
||||
include(KDEInstallDirs)
|
||||
include(KDECMakeSettings)
|
||||
include(KDECompilerSettings)
|
||||
include(FeatureSummary)
|
||||
|
||||
set_directory_properties(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/Rust)
|
||||
|
||||
ExternalProject_Add(
|
||||
rust
|
||||
DOWNLOAD_COMMAND ""
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND cargo build
|
||||
COMMAND cargo build --release
|
||||
BINARY_DIR "${CMAKE_SOURCE_DIR}/common-rust"
|
||||
INSTALL_COMMAND ""
|
||||
LOG_BUILD ON)
|
||||
|
||||
|
||||
# Find Qt modules
|
||||
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
|
||||
Core # QCommandLineParser, QStringLiteral
|
||||
Widgets # QApplication
|
||||
)
|
||||
|
||||
# Find KDE modules
|
||||
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
|
||||
CoreAddons # KAboutData
|
||||
I18n # KLocalizedString
|
||||
WidgetsAddons # KMessageBox
|
||||
)
|
||||
|
||||
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||
|
||||
set(RMail_SRCS src/main.cpp)
|
||||
|
||||
add_executable(RMail ${RMail_SRCS})
|
||||
|
||||
add_dependencies(RMail rust)
|
||||
|
||||
target_link_libraries(RMail
|
||||
Qt5::Widgets
|
||||
KF5::CoreAddons
|
||||
KF5::I18n
|
||||
KF5::WidgetsAddons
|
||||
debug "${CMAKE_SOURCE_DIR}/common-rust/target/debug/librust.a"
|
||||
optimized "${CMAKE_SOURCE_DIR}/common-rust/target/release/librust.a"
|
||||
)
|
||||
|
||||
set_target_properties(RMail PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
)
|
||||
|
||||
install(TARGETS RMail ${INSTALL_TARGETS_DEFAULT_ARGS})
|
|
@ -0,0 +1,3 @@
|
|||
# RMail
|
||||
|
||||
A very simple proof of concept to parse mail with rust and show it in a qt ui.
|
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
libc = "*"
|
||||
|
||||
[lib]
|
||||
name = "rust"
|
||||
crate-type = ["staticlib"]
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
extern crate libc;
|
||||
|
||||
use std::slice;
|
||||
use std::ffi::CString;
|
||||
use std::ffi::CStr;
|
||||
use libc::{uint8_t, c_char, uint32_t, uint16_t, size_t};
|
||||
|
||||
pub struct Hello {
|
||||
hello: String
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn add(lhs: u32, rhs: u32) -> u32 {
|
||||
lhs + rhs
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn hello_new() -> *mut Hello {
|
||||
let s = String::from("hello");
|
||||
Box::into_raw(Box::new(Hello { hello: s }))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn hello_set(ptr: *mut Hello, s: *const uint16_t, len: size_t) {
|
||||
let (hello, data) = unsafe {
|
||||
(&mut *ptr, slice::from_raw_parts(s, len as usize))
|
||||
};
|
||||
hello.hello = String::from_utf16_lossy(data);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn hello_size(ptr: *mut Hello) -> size_t {
|
||||
let hello = unsafe {
|
||||
&mut *ptr
|
||||
};
|
||||
hello.hello.len()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn hello_get(ptr: *mut Hello) -> *const uint8_t {
|
||||
let hello = unsafe {
|
||||
&mut *ptr
|
||||
};
|
||||
hello.hello.as_ptr()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn hello_free(ptr: *mut Hello) {
|
||||
if ptr.is_null() { return }
|
||||
unsafe { Box::from_raw(ptr); }
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/bash
|
||||
nix-shell -p qtcreator cmake ninja gcc rustc cargo qt5.full extra-cmake-modules kdeFrameworks.kwidgetsaddons kdeFrameworks.kcoreaddons kdeFrameworks.ki18n appstream
|
|
@ -0,0 +1,62 @@
|
|||
#include "rust.h"
|
||||
#include <cstdlib>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <KAboutData>
|
||||
#include <KLocalizedString>
|
||||
#include <KMessageBox>
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
KLocalizedString::setApplicationDomain("RMail");
|
||||
|
||||
KAboutData aboutData(
|
||||
// The program name used internally. (componentName)
|
||||
QStringLiteral("RMail"),
|
||||
// A displayable program name string. (displayName)
|
||||
i18n("RMail"),
|
||||
// The program version string. (version)
|
||||
QStringLiteral("0.1"),
|
||||
// Short description of what the app does. (shortDescription)
|
||||
i18n("Displays a mails from a maildir"),
|
||||
// The license this code is released under
|
||||
KAboutLicense::GPL,
|
||||
// Copyright Statement (copyrightStatement = QString())
|
||||
i18n("(c) 2017"),
|
||||
// Optional text shown in the About box.
|
||||
// Can contain any information desired. (otherText)
|
||||
i18n("Some text..."),
|
||||
// The program homepage string. (homePageAddress = QString())
|
||||
QStringLiteral("http://kde.org/"),
|
||||
// The bug report email address
|
||||
// (bugsEmailAddress = QLatin1String("submit@bugs.kde.org")
|
||||
QStringLiteral("submit@bugs.kde.org"));
|
||||
aboutData.addAuthor(i18n("Jos van den Oever"), i18n("Task"), QStringLiteral("your@email.com"),
|
||||
QStringLiteral("http://vandenoever.info"), QStringLiteral("OSC Username"));
|
||||
KAboutData::setApplicationData(aboutData);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
aboutData.setupCommandLine(&parser);
|
||||
parser.process(app);
|
||||
aboutData.processCommandLine(&parser);
|
||||
|
||||
void* hello = hello_new();
|
||||
QString qhello = QString::fromUtf8(hello_get(hello), hello_size(hello));
|
||||
hello_set(hello, qhello.utf16(), qhello.size());
|
||||
hello_free(hello);
|
||||
|
||||
KGuiItem yesButton( i18n( "hello" ), QString(),
|
||||
i18n( "This is a tooltip" ),
|
||||
i18n( "This is a WhatsThis help text." ) );
|
||||
|
||||
add(0, 1);
|
||||
|
||||
return
|
||||
KMessageBox::questionYesNo
|
||||
(0, i18n( "Hello World" ), i18n( "Hello" ), yesButton )
|
||||
== KMessageBox::Yes? EXIT_SUCCESS: EXIT_FAILURE;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#include <cstdint>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C" {
|
||||
uint32_t add(uint32_t lhs, uint32_t rhs);
|
||||
void* hello_new();
|
||||
void hello_set(void*, const uint16_t *, size_t);
|
||||
size_t hello_size(void*);
|
||||
const char* hello_get(void*);
|
||||
void hello_free(void *);
|
||||
}
|
Loading…
Reference in New Issue