mirror of
https://github.com/vanitasvitae/OmemoQRCodeGenerator.git
synced 2024-11-27 06:42:07 +01:00
Some quick reworkings. FP selection is working!
This commit is contained in:
parent
4309af9e7a
commit
696352aaa8
10 changed files with 122 additions and 97 deletions
|
@ -23,8 +23,6 @@ public class ListViewCell extends JFXListCell<OmemoIdentity> {
|
||||||
@FXML
|
@FXML
|
||||||
private JFXToggleButton toggle;
|
private JFXToggleButton toggle;
|
||||||
|
|
||||||
private QrDisplayController displayController = null;
|
|
||||||
|
|
||||||
public ListViewCell() {
|
public ListViewCell() {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/item.fxml"));
|
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/item.fxml"));
|
||||||
fxmlLoader.setController(this);
|
fxmlLoader.setController(this);
|
||||||
|
@ -38,27 +36,21 @@ public class ListViewCell extends JFXListCell<OmemoIdentity> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisplayController(QrDisplayController controller) {
|
|
||||||
this.displayController = controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateItem(OmemoIdentity identity, boolean empty) {
|
public void updateItem(OmemoIdentity identity, boolean empty) {
|
||||||
|
Repository repository = Repository.getInstance();
|
||||||
if (empty) {
|
if (empty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id != null) id.setText(Integer.toString(identity.getDevice().getDeviceId()));
|
id.setText(Integer.toString(identity.getDevice().getDeviceId()));
|
||||||
if (fingerprint != null) fingerprint.setText(identity.getFingerprint().blocksOf8Chars());
|
fingerprint.setText(Util.twoLinesFingerprint(identity.getFingerprint()));
|
||||||
if (toggle != null) toggle.setSelected(identity.getEnabled());
|
toggle.setSelected(identity.getEnabled());
|
||||||
if (hBox != null) setGraphic(hBox);
|
setGraphic(hBox);
|
||||||
if (toggle != null) {
|
|
||||||
toggle.setOnAction(actionEvent -> {
|
toggle.setOnAction(actionEvent -> {
|
||||||
identity.setEnabled(toggle.isSelected());
|
identity.setEnabled(toggle.isSelected());
|
||||||
if (displayController != null) {
|
repository.getIdentities().add(repository.getIdentities().remove(repository.getIdentities().size() -1));
|
||||||
displayController.drawQRCode();
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,28 @@
|
||||||
package de.vanitasvitae.omemoqrgenerator;
|
package de.vanitasvitae.omemoqrgenerator;
|
||||||
|
|
||||||
import java.util.Collection;
|
import javafx.event.EventHandler;
|
||||||
|
|
||||||
import com.jfoenix.controls.JFXListView;
|
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.scene.input.ScrollEvent;
|
||||||
|
|
||||||
public class ListViewController {
|
public class ListViewController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private JFXListView<OmemoIdentity> listView;
|
private ListView<OmemoIdentity> listView;
|
||||||
|
|
||||||
private ObservableList<OmemoIdentity> identities = FXCollections.observableArrayList();
|
|
||||||
|
|
||||||
private QrDisplayController displayController = null;
|
|
||||||
|
|
||||||
public void setDisplayController(QrDisplayController controller) {
|
|
||||||
this.displayController = controller;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdentities(Collection<OmemoIdentity> identities) {
|
|
||||||
this.identities.clear();
|
|
||||||
this.identities.addAll(identities);
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void initialize() {
|
void initialize() {
|
||||||
|
Repository repository = Repository.getInstance();
|
||||||
listView.setCellFactory(listView -> {
|
listView.setCellFactory(listView -> {
|
||||||
ListViewCell cell = new ListViewCell();
|
ListViewCell cell = new ListViewCell();
|
||||||
cell.setDisplayController(displayController);
|
return cell;
|
||||||
return new ListViewCell();
|
});
|
||||||
|
listView.setItems(repository.getIdentities());
|
||||||
|
listView.addEventFilter(ScrollEvent.SCROLL, event -> {
|
||||||
|
if (event.getDeltaX() != 0) {
|
||||||
|
event.consume();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
listView.setItems(identities);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package de.vanitasvitae.omemoqrgenerator;
|
package de.vanitasvitae.omemoqrgenerator;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackConfiguration;
|
import org.jivesoftware.smack.SmackConfiguration;
|
||||||
import org.jivesoftware.smack.SmackException;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
import org.jivesoftware.smack.packet.Presence;
|
||||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||||
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||||
|
@ -14,13 +11,11 @@ import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.jxmpp.jid.BareJid;
|
import org.jxmpp.jid.BareJid;
|
||||||
import org.jxmpp.stringprep.XmppStringprepException;
|
|
||||||
|
|
||||||
public class Main extends Application implements LoginCallback {
|
public class Main extends Application implements LoginCallback {
|
||||||
|
|
||||||
|
@ -83,7 +78,9 @@ public class Main extends Application implements LoginCallback {
|
||||||
loader.setLocation(getClass().getResource("/fxml/login.fxml"));
|
loader.setLocation(getClass().getResource("/fxml/login.fxml"));
|
||||||
Parent root = loader.load();
|
Parent root = loader.load();
|
||||||
stage.setMinHeight(600);
|
stage.setMinHeight(600);
|
||||||
|
stage.setMaxHeight(600);
|
||||||
stage.setMinWidth(400);
|
stage.setMinWidth(400);
|
||||||
|
stage.setMaxWidth(400);
|
||||||
|
|
||||||
// Register ourselves as callback for the login button.
|
// Register ourselves as callback for the login button.
|
||||||
LoginController loginController = loader.getController();
|
LoginController loginController = loader.getController();
|
||||||
|
@ -97,21 +94,19 @@ public class Main extends Application implements LoginCallback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void login(String username, String password) {
|
public void login(String username, String password) {
|
||||||
XMPPTCPConnection connection = null;
|
Repository repository = Repository.getInstance();
|
||||||
|
XMPPTCPConnection connection;
|
||||||
try {
|
try {
|
||||||
connection = new XMPPTCPConnection(username, password);
|
connection = new XMPPTCPConnection(username, password);
|
||||||
connection.connect().login();
|
connection.connect().login();
|
||||||
|
|
||||||
if (connection == null) {
|
repository.setJid(connection.getUser().asBareJid());
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BareJid jid = connection.getUser().asBareJid();
|
|
||||||
Map<OmemoDevice, OmemoFingerprint> fingerprints = Util.getFingerprints(connection);
|
Map<OmemoDevice, OmemoFingerprint> fingerprints = Util.getFingerprints(connection);
|
||||||
|
|
||||||
ObservableList<OmemoIdentity> identities = FXCollections.observableArrayList();
|
ObservableList<OmemoIdentity> identities = repository.getIdentities();
|
||||||
for (OmemoDevice device : fingerprints.keySet()) {
|
for (OmemoDevice device : fingerprints.keySet()) {
|
||||||
identities.addAll(new OmemoIdentity(device, fingerprints.get(device)));
|
identities.addAll(new OmemoIdentity(device, fingerprints.get(device)));
|
||||||
|
System.out.println(Util.twoLinesFingerprint(fingerprints.get(device)));
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.disconnect(new Presence(Presence.Type.unavailable));
|
connection.disconnect(new Presence(Presence.Type.unavailable));
|
||||||
|
@ -119,8 +114,6 @@ public class Main extends Application implements LoginCallback {
|
||||||
FXMLLoader loader = new FXMLLoader();
|
FXMLLoader loader = new FXMLLoader();
|
||||||
loader.setLocation(getClass().getResource("/fxml/qrdisplay.fxml"));
|
loader.setLocation(getClass().getResource("/fxml/qrdisplay.fxml"));
|
||||||
Parent root = loader.load();
|
Parent root = loader.load();
|
||||||
QrDisplayController controller = loader.getController();
|
|
||||||
controller.setFingerprints(jid, identities);
|
|
||||||
|
|
||||||
Scene scene = new Scene(root, 400, 600);
|
Scene scene = new Scene(root, 400, 600);
|
||||||
stage.setTitle("OMEMO QR-Code Generator");
|
stage.setTitle("OMEMO QR-Code Generator");
|
||||||
|
|
|
@ -2,24 +2,19 @@ package de.vanitasvitae.omemoqrgenerator;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
|
||||||
import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.WriterException;
|
import com.google.zxing.WriterException;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
import com.google.zxing.qrcode.QRCodeWriter;
|
import com.google.zxing.qrcode.QRCodeWriter;
|
||||||
import javafx.collections.ObservableList;
|
import com.jfoenix.controls.JFXListView;
|
||||||
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.embed.swing.SwingFXUtils;
|
import javafx.embed.swing.SwingFXUtils;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import org.jxmpp.jid.BareJid;
|
|
||||||
|
|
||||||
public class QrDisplayController {
|
public class QrDisplayController {
|
||||||
|
|
||||||
|
@ -27,29 +22,29 @@ public class QrDisplayController {
|
||||||
private ImageView qr_view;
|
private ImageView qr_view;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private GridPane listView;
|
private ListView listView;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ListViewController listViewController;
|
private ListViewController listViewController;
|
||||||
|
|
||||||
private BareJid jid;
|
private Repository repository = Repository.getInstance();
|
||||||
private ObservableList<OmemoIdentity> identities = null;
|
|
||||||
|
|
||||||
public void setFingerprints(BareJid jid, ObservableList<OmemoIdentity> identities) {
|
@FXML
|
||||||
this.jid = jid;
|
public void initialize() {
|
||||||
this.identities = identities;
|
|
||||||
this.listViewController.setDisplayController(this);
|
|
||||||
this.listViewController.setIdentities(this.identities);
|
|
||||||
drawQRCode();
|
drawQRCode();
|
||||||
|
repository.getIdentities().addListener((ListChangeListener<OmemoIdentity>) change -> drawQRCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawQRCode() {
|
public void drawQRCode() {
|
||||||
int width = 300, height = 300;
|
System.out.println("Draw!");
|
||||||
|
Repository repository = Repository.getInstance();
|
||||||
|
|
||||||
|
int width = 360, height = 360;
|
||||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||||
|
|
||||||
String content = "xmpp:" + jid.toString();
|
String content = "xmpp:" + repository.getJid().toString();
|
||||||
|
|
||||||
Iterator<OmemoIdentity> iterator = identities.iterator();
|
Iterator<OmemoIdentity> iterator = repository.getIdentities().iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
OmemoIdentity first = iterator.next();
|
OmemoIdentity first = iterator.next();
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package de.vanitasvitae.omemoqrgenerator;
|
||||||
|
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import org.jxmpp.jid.BareJid;
|
||||||
|
|
||||||
|
public class Repository {
|
||||||
|
|
||||||
|
private static Repository INSTANCE;
|
||||||
|
|
||||||
|
private final ObservableList<OmemoIdentity> IDENTITIES = FXCollections.observableArrayList();
|
||||||
|
private BareJid JID = null;
|
||||||
|
|
||||||
|
private Repository() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Repository getInstance() {
|
||||||
|
if (INSTANCE == null) {
|
||||||
|
INSTANCE = new Repository();
|
||||||
|
}
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BareJid getJid() {
|
||||||
|
return JID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJid(BareJid jid) {
|
||||||
|
this.JID = jid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObservableList<OmemoIdentity> getIdentities() {
|
||||||
|
return IDENTITIES;
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ import org.jivesoftware.smackx.pubsub.PayloadItem;
|
||||||
import org.jivesoftware.smackx.pubsub.PubSubException;
|
import org.jivesoftware.smackx.pubsub.PubSubException;
|
||||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||||
|
|
||||||
|
import org.bouncycastle.util.Strings;
|
||||||
import org.jxmpp.jid.BareJid;
|
import org.jxmpp.jid.BareJid;
|
||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
|
@ -94,4 +95,11 @@ public class Util {
|
||||||
|
|
||||||
return items.get(items.size() - 1).getPayload();
|
return items.get(items.size() - 1).getPayload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String twoLinesFingerprint(OmemoFingerprint fingerprint) {
|
||||||
|
String blocks = fingerprint.blocksOf8Chars();
|
||||||
|
String out = blocks.substring(0, 35);
|
||||||
|
out = out + "\n" + blocks.substring(36);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,31 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
|
||||||
<?import javafx.scene.control.Label?>
|
|
||||||
<?import javafx.scene.layout.HBox?>
|
|
||||||
<?import com.jfoenix.controls.JFXToggleButton?>
|
<?import com.jfoenix.controls.JFXToggleButton?>
|
||||||
<HBox xmlns:fx="http://javafx.com/fxml" fx:id="hBox">
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
|
<HBox fx:id="hBox" xmlns="http://javafx.com/javafx/8.0.162-ea" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="id"/>
|
<AnchorPane prefHeight="67.0" prefWidth="300.0" maxWidth="350">
|
||||||
<Label fx:id="fingerprint"/>
|
<children>
|
||||||
<JFXToggleButton fx:id="toggle" />
|
<Label fx:id="id" alignment="BASELINE_RIGHT" text="1429677125" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="5.0" right="5.0" />
|
||||||
|
</padding>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="fingerprint" layoutX="100.0" prefHeight="44.0" prefWidth="288.0" AnchorPane.bottomAnchor="23.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
|
||||||
|
</padding>
|
||||||
|
<font>
|
||||||
|
<Font name="Bitstream Vera Sans Mono" size="13.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
|
<JFXToggleButton fx:id="toggle" alignment="CENTER_RIGHT" contentDisplay="GRAPHIC_ONLY" selected="true" text="ToggleButton" />
|
||||||
</children>
|
</children>
|
||||||
</HBox>
|
</HBox>
|
||||||
|
|
|
@ -1,16 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import com.jfoenix.controls.JFXListView?>
|
<?import javafx.scene.control.ListView?>
|
||||||
<?import javafx.scene.layout.ColumnConstraints?>
|
|
||||||
<?import javafx.scene.layout.GridPane?>
|
|
||||||
<?import javafx.scene.layout.RowConstraints?>
|
|
||||||
|
|
||||||
<GridPane alignment="CENTER" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.162-ea" fx:controller="de.vanitasvitae.omemoqrgenerator.ListViewController">
|
|
||||||
<JFXListView fx:id="listView" minWidth="400.0" prefWidth="400.0" />
|
<ListView fx:id="listView" maxHeight="200" maxWidth="400.0" minHeight="200.0" minWidth="400.0" prefHeight="200.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.162-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.vanitasvitae.omemoqrgenerator.ListViewController" />
|
||||||
<columnConstraints>
|
|
||||||
<ColumnConstraints />
|
|
||||||
</columnConstraints>
|
|
||||||
<rowConstraints>
|
|
||||||
<RowConstraints />
|
|
||||||
</rowConstraints>
|
|
||||||
</GridPane>
|
|
||||||
|
|
|
@ -9,8 +9,9 @@
|
||||||
|
|
||||||
<VBox xmlns="http://javafx.com/javafx/8.0.162-ea"
|
<VBox xmlns="http://javafx.com/javafx/8.0.162-ea"
|
||||||
xmlns:fx="http://javafx.com/fxml/1"
|
xmlns:fx="http://javafx.com/fxml/1"
|
||||||
alignment="CENTER" minHeight="400.0" minWidth="600.0"
|
alignment="CENTER"
|
||||||
prefHeight="400.0" prefWidth="600.0"
|
minHeight="600.0" minWidth="400.0"
|
||||||
|
prefHeight="600.0" prefWidth="400.0"
|
||||||
fx:controller="de.vanitasvitae.omemoqrgenerator.LoginController">
|
fx:controller="de.vanitasvitae.omemoqrgenerator.LoginController">
|
||||||
<children>
|
<children>
|
||||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
<?import javafx.scene.image.ImageView?>
|
<?import javafx.scene.image.ImageView?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<VBox alignment="TOP_CENTER" minHeight="400.0" minWidth="600.0" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.162-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.vanitasvitae.omemoqrgenerator.QrDisplayController">
|
|
||||||
|
<VBox alignment="TOP_CENTER" style="-fx-background-color: #FFFFFF;" xmlns="http://javafx.com/javafx/8.0.162-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.vanitasvitae.omemoqrgenerator.QrDisplayController">
|
||||||
<children>
|
<children>
|
||||||
<ImageView fx:id="qr_view"/>
|
<ImageView fx:id="qr_view" />
|
||||||
<fx:include fx:id="listView" source="listview.fxml"/>
|
<fx:include fx:id="listView" source="listview.fxml" />
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
|
|
Loading…
Reference in a new issue