mirror of
https://github.com/vanitasvitae/OmemoQRCodeGenerator.git
synced 2024-11-23 12:52:09 +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
|
||||
private JFXToggleButton toggle;
|
||||
|
||||
private QrDisplayController displayController = null;
|
||||
|
||||
public ListViewCell() {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/item.fxml"));
|
||||
fxmlLoader.setController(this);
|
||||
|
@ -38,27 +36,21 @@ public class ListViewCell extends JFXListCell<OmemoIdentity> {
|
|||
}
|
||||
}
|
||||
|
||||
public void setDisplayController(QrDisplayController controller) {
|
||||
this.displayController = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateItem(OmemoIdentity identity, boolean empty) {
|
||||
Repository repository = Repository.getInstance();
|
||||
if (empty) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (id != null) id.setText(Integer.toString(identity.getDevice().getDeviceId()));
|
||||
if (fingerprint != null) fingerprint.setText(identity.getFingerprint().blocksOf8Chars());
|
||||
if (toggle != null) toggle.setSelected(identity.getEnabled());
|
||||
if (hBox != null) setGraphic(hBox);
|
||||
if (toggle != null) {
|
||||
toggle.setOnAction(actionEvent -> {
|
||||
identity.setEnabled(toggle.isSelected());
|
||||
if (displayController != null) {
|
||||
displayController.drawQRCode();
|
||||
}
|
||||
});
|
||||
}
|
||||
id.setText(Integer.toString(identity.getDevice().getDeviceId()));
|
||||
fingerprint.setText(Util.twoLinesFingerprint(identity.getFingerprint()));
|
||||
toggle.setSelected(identity.getEnabled());
|
||||
setGraphic(hBox);
|
||||
|
||||
toggle.setOnAction(actionEvent -> {
|
||||
identity.setEnabled(toggle.isSelected());
|
||||
repository.getIdentities().add(repository.getIdentities().remove(repository.getIdentities().size() -1));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +1,28 @@
|
|||
package de.vanitasvitae.omemoqrgenerator;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.jfoenix.controls.JFXListView;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.input.ScrollEvent;
|
||||
|
||||
public class ListViewController {
|
||||
|
||||
@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
|
||||
void initialize() {
|
||||
Repository repository = Repository.getInstance();
|
||||
listView.setCellFactory(listView -> {
|
||||
ListViewCell cell = new ListViewCell();
|
||||
cell.setDisplayController(displayController);
|
||||
return new ListViewCell();
|
||||
return cell;
|
||||
});
|
||||
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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
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.tcp.XMPPTCPConnection;
|
||||
import org.jivesoftware.smackx.omemo.internal.OmemoDevice;
|
||||
|
@ -14,13 +11,11 @@ import org.jivesoftware.smackx.omemo.trust.OmemoFingerprint;
|
|||
import javafx.application.Application;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
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"));
|
||||
Parent root = loader.load();
|
||||
stage.setMinHeight(600);
|
||||
stage.setMaxHeight(600);
|
||||
stage.setMinWidth(400);
|
||||
stage.setMaxWidth(400);
|
||||
|
||||
// Register ourselves as callback for the login button.
|
||||
LoginController loginController = loader.getController();
|
||||
|
@ -97,21 +94,19 @@ public class Main extends Application implements LoginCallback {
|
|||
|
||||
@Override
|
||||
public void login(String username, String password) {
|
||||
XMPPTCPConnection connection = null;
|
||||
Repository repository = Repository.getInstance();
|
||||
XMPPTCPConnection connection;
|
||||
try {
|
||||
connection = new XMPPTCPConnection(username, password);
|
||||
connection.connect().login();
|
||||
|
||||
if (connection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
BareJid jid = connection.getUser().asBareJid();
|
||||
repository.setJid(connection.getUser().asBareJid());
|
||||
Map<OmemoDevice, OmemoFingerprint> fingerprints = Util.getFingerprints(connection);
|
||||
|
||||
ObservableList<OmemoIdentity> identities = FXCollections.observableArrayList();
|
||||
ObservableList<OmemoIdentity> identities = repository.getIdentities();
|
||||
for (OmemoDevice device : fingerprints.keySet()) {
|
||||
identities.addAll(new OmemoIdentity(device, fingerprints.get(device)));
|
||||
System.out.println(Util.twoLinesFingerprint(fingerprints.get(device)));
|
||||
}
|
||||
|
||||
connection.disconnect(new Presence(Presence.Type.unavailable));
|
||||
|
@ -119,8 +114,6 @@ public class Main extends Application implements LoginCallback {
|
|||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setLocation(getClass().getResource("/fxml/qrdisplay.fxml"));
|
||||
Parent root = loader.load();
|
||||
QrDisplayController controller = loader.getController();
|
||||
controller.setFingerprints(jid, identities);
|
||||
|
||||
Scene scene = new Scene(root, 400, 600);
|
||||
stage.setTitle("OMEMO QR-Code Generator");
|
||||
|
|
|
@ -2,24 +2,19 @@ package de.vanitasvitae.omemoqrgenerator;
|
|||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashSet;
|
||||
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.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
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.fxml.FXML;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
|
||||
public class QrDisplayController {
|
||||
|
||||
|
@ -27,29 +22,29 @@ public class QrDisplayController {
|
|||
private ImageView qr_view;
|
||||
|
||||
@FXML
|
||||
private GridPane listView;
|
||||
private ListView listView;
|
||||
|
||||
@FXML
|
||||
private ListViewController listViewController;
|
||||
|
||||
private BareJid jid;
|
||||
private ObservableList<OmemoIdentity> identities = null;
|
||||
private Repository repository = Repository.getInstance();
|
||||
|
||||
public void setFingerprints(BareJid jid, ObservableList<OmemoIdentity> identities) {
|
||||
this.jid = jid;
|
||||
this.identities = identities;
|
||||
this.listViewController.setDisplayController(this);
|
||||
this.listViewController.setIdentities(this.identities);
|
||||
@FXML
|
||||
public void initialize() {
|
||||
drawQRCode();
|
||||
repository.getIdentities().addListener((ListChangeListener<OmemoIdentity>) change -> 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();
|
||||
|
||||
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()) {
|
||||
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.PubSubManager;
|
||||
|
||||
import org.bouncycastle.util.Strings;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
|
||||
public class Util {
|
||||
|
@ -94,4 +95,11 @@ public class Util {
|
|||
|
||||
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"?>
|
||||
|
||||
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?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>
|
||||
<Label fx:id="id"/>
|
||||
<Label fx:id="fingerprint"/>
|
||||
<JFXToggleButton fx:id="toggle" />
|
||||
<AnchorPane prefHeight="67.0" prefWidth="300.0" maxWidth="350">
|
||||
<children>
|
||||
<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>
|
||||
</HBox>
|
||||
|
|
|
@ -1,16 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import com.jfoenix.controls.JFXListView?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
|
||||
<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" />
|
||||
<columnConstraints>
|
||||
<ColumnConstraints />
|
||||
</columnConstraints>
|
||||
<rowConstraints>
|
||||
<RowConstraints />
|
||||
</rowConstraints>
|
||||
</GridPane>
|
||||
|
||||
<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" />
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
|
||||
<VBox xmlns="http://javafx.com/javafx/8.0.162-ea"
|
||||
xmlns:fx="http://javafx.com/fxml/1"
|
||||
alignment="CENTER" minHeight="400.0" minWidth="600.0"
|
||||
prefHeight="400.0" prefWidth="600.0"
|
||||
alignment="CENTER"
|
||||
minHeight="600.0" minWidth="400.0"
|
||||
prefHeight="600.0" prefWidth="400.0"
|
||||
fx:controller="de.vanitasvitae.omemoqrgenerator.LoginController">
|
||||
<children>
|
||||
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0">
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?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>
|
||||
<ImageView fx:id="qr_view"/>
|
||||
<fx:include fx:id="listView" source="listview.fxml"/>
|
||||
<ImageView fx:id="qr_view" />
|
||||
<fx:include fx:id="listView" source="listview.fxml" />
|
||||
</children>
|
||||
</VBox>
|
||||
|
|
Loading…
Reference in a new issue