00001 import org.gnu.pilotlink.*;
00002 import java.io.*;
00003 import java.util.*;
00004 import javax.swing.*;
00005 import java.awt.*;
00012 public class adrtest {
00018 public static void main(String args[]) {
00019 test tst=new test();
00020 JFrame frame = new JFrame("Progress");
00021 frame.getContentPane().setLayout(new BorderLayout());
00022 JLabel txt = new JLabel("Reading in");
00023 frame.getContentPane().add(txt, BorderLayout.NORTH);
00024 JProgressBar progress = new JProgressBar(0, 100);
00025 frame.getContentPane().add(progress, BorderLayout.CENTER);
00026 frame.setSize(300, 50);
00027 frame.setVisible(true);
00028 String port;
00029 if (args.length==0) {
00030 port="/dev/usb/tts/1";
00031 } else {
00032 port=args[0];
00033 }
00034 File p=new File(port);
00035 System.out.println("looking for file "+port);
00036 if (!p.exists()) {
00037 System.out.println("File does not exist... USB? Waiting for port to appear");
00038
00039 while (!p.exists()) {
00040 System.out.print(".");
00041 try {
00042 Thread.sleep(1000);
00043 } catch (Exception e) {}
00044 }
00045 }
00046 PilotLink pl = null;
00047 try {
00048 pl = new PilotLink(port);
00049 if (!pl.isConnected()) {
00050 System.out.println("Something went wrong. Check output!");
00051 System.exit(1);
00052 }
00053 } catch (Exception e) {
00054 e.printStackTrace();
00055 System.exit(1);
00056 }
00057 try {
00058 User u = pl.getUserInfo();
00059 System.out.println("User: " + u.getName());
00060 System.out.println("Last Synchronization Date: " + u.getLastSyncDate());
00061 } catch (PilotLinkException e) {
00062 e.printStackTrace();
00063 }
00064
00065 System.out.println("GEtting App...");
00066 pl.getAppInfoBlock("AddressDB");
00067
00068 try {
00069 SysInfo si = pl.getSysInfo();
00070 System.out.println("Product ID: '" + si.getProdID() + "'");
00071 System.out.println("Rom Version: " + si.getRomVersion());
00072 } catch (PilotLinkException e) {
00073 e.printStackTrace();
00074 }
00075 try {
00076 System.out.println("Opening DatebookDB");
00077 int dbhAdr=pl.openDB("AddressDB");
00078 System.out.println("addresses opened!");
00079 Record r=pl.getRecordByIndex(dbhAdr,0);
00080
00081
00082 AddressRecord adrRecord;
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 progress.setMaximum(pl.getRecordCount(dbhAdr));
00105 for (int i=0; i<pl.getRecordCount(dbhAdr); i++) {
00106 r=pl.getRecordByIndex(dbhAdr,i);
00107 progress.setValue(i);
00108 if (r==null) {
00109 System.out.println("Fehler beim einlesen...");
00110 break;
00111 }
00112 if (r.getBuffer()==null || r.getBuffer().length==0) {
00113 System.out.println("0-sized record? Deleting...");
00114 pl.deleteRecordById(dbhAdr,r.getId());
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124 adrRecord=new AddressRecord(r);
00125
00126
00127
00128
00129 System.out.println("Name: "+adrRecord.getField(0)+" "+adrRecord.getField(1)+" "+adrRecord.getField(2));
00130 if (adrRecord.isDeleted()) {
00131
00132 System.out.println("IS DELETED!");
00133 }
00134 }
00135
00136
00137
00138
00139
00140
00141
00142 } catch (Exception e){
00143 e.printStackTrace();
00144 }
00145
00146 try {
00147 pl.endSync();
00148 } catch (PilotLinkException e) {
00149 e.printStackTrace();
00150 }
00151 pl.close();
00152
00153 frame.dispose();
00154 System.exit(0);
00155 }
00156
00157
00158
00159
00160 }
00161