Commits

Hector Miuler Malpica Gallegos committed 6b9b8b5

Se agrego jodatimes para poder manejar las interfaces y se agrego boton para limpiar la grilla.

Comments (0)

Files changed (2)

     "io.netty" % "netty" % "4.0.0.Alpha5",
     "ch.qos.logback" % "logback-classic" % "1.0.7",
     "org.slf4j" % "slf4j-api" % "1.6.6",
-    "javax.mail" % "mail" % "1.4.5"
+    "javax.mail" % "mail" % "1.4.5",
+    "joda-time" % "joda-time" % "2.1",
+    "org.joda" % "joda-convert" % "1.2"
 //    "org.apache.james" % "apache-mime4j" % "0.7.2"
 )
 

src/main/scala/com/miuler/mocksmtp/gui/MainGUI.scala

 import java.io.ByteArrayInputStream
 import com.trolltech.qt.gui.QPalette.ColorRole
 import com.trolltech.qt.core.Qt
-import java.util.Date
 import javax.mail.Session
 import javax.mail.internet.MimeMessage
 import java.util.Properties
+import org.joda.time.DateTime
 
 /**
  * Created with IntelliJ IDEA.
     btnStopSMTP.toggle()
     btnStopSMTP.setDisabled(true)
     btnStopSMTP.toggled.connect(this, "stopSMTP()")
+
+    val btnClean = new QPushButton("Borrar correos")
+    btnClean.clicked.connect(this, "cleanEmails()")
     // =========================================================================
 
     // =========================================================================
     treeView.setAlternatingRowColors(true)
     treeView.setModel(model)
     treeView.setSortingEnabled(true)
-    treeView.sortByColumn(1, Qt.SortOrder.AscendingOrder)
+    treeView.sortByColumn(0, Qt.SortOrder.AscendingOrder)
     treeView.setMinimumSize(300, 200) //TODO: @Miuler: Esto es para evitar un error en algunas maquinas
     // =========================================================================
 
     val hlayout = new QHBoxLayout()
     hlayout.addWidget(btnInitSMTP)
     hlayout.addWidget(btnStopSMTP)
+    hlayout.addWidget(btnClean)
     hlayout.addWidget(lcd)
     // =========================================================================
 
   }
 
   def addEmail(msg: String) {
-    log.debug("email_string: {}", msg)
     val email = new MimeMessage(session, new ByteArrayInputStream(msg.getBytes()))
+    val date = new DateTime()
 
-    log.debug("email: {}", email)
-    log.debug("email.getContent: {}", email.getContent())
-    log.debug("email.getSubject: {}", email.getSubject())
     emails.append(email)
     model.insertRow(0)
     model.setData(model.index(0, 0), model.rowCount())
-    model.setData(model.index(0, 1), new Date toString)
+    //model.setData(model.index(0, 1), DateTimeFormat.forPattern("M-dd HH:mm").print(date))
+    model.setData(model.index(0, 1), date.toString("M-dd HH:mm"))
     model.setData(model.index(0, 2), email.getSubject())
-    model.setData(model.index(0, 3), email)
-    lcd.display(emails.size)
+    model.setData(model.index(0, 3), date)
+    model.setData(model.index(0, 4), email)
+    lcd.display(model.rowCount())
+  }
+
+  def cleanEmails() {
+    emails.clear()
+    model.removeRows(0, model.rowCount())
+    lcd.display(0)
   }
 
 }