aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-22 00:07:39 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-06-22 00:07:39 -0700
commit8259b55073f2fdb2c3d301df570412318cdfac27 (patch)
tree5a301800d308b78fdfc93b2b61d97cc06dd351d2 /src
parentdfd47a7ec95e469e33fd40ddc2c1a725fe2da3e2 (diff)
Cleaned implementation of FolderStatus (#120)
Diffstat (limited to 'src')
-rw-r--r--src/async/imap/MCIMAPFolderStatusOperation.cc45
-rw-r--r--src/async/imap/MCIMAPFolderStatusOperation.h16
-rw-r--r--src/core/imap/MCIMAPFolderStatus.cc17
-rw-r--r--src/core/imap/MCIMAPFolderStatus.h1
-rw-r--r--src/objc/imap/MCOIMAPFolderStatus.h3
-rw-r--r--src/objc/imap/MCOIMAPFolderStatus.mm27
-rw-r--r--src/objc/imap/MCOIMAPFolderStatusOperation.mm3
7 files changed, 49 insertions, 63 deletions
diff --git a/src/async/imap/MCIMAPFolderStatusOperation.cc b/src/async/imap/MCIMAPFolderStatusOperation.cc
index 89484624..0ca7d884 100644
--- a/src/async/imap/MCIMAPFolderStatusOperation.cc
+++ b/src/async/imap/MCIMAPFolderStatusOperation.cc
@@ -16,40 +16,12 @@ using namespace mailcore;
IMAPFolderStatusOperation::IMAPFolderStatusOperation()
{
- mUidNext = 0;
- mUidValidity = 0;
- mMessageCount = 0;
- mRecentCount = 0;
- mUnseenCount = 0;
+ mStatus = NULL;
}
IMAPFolderStatusOperation::~IMAPFolderStatusOperation()
{
-}
-
-uint32_t IMAPFolderStatusOperation::uidNext()
-{
- return mUidNext;
-}
-
-uint32_t IMAPFolderStatusOperation::uidValidity()
-{
- return mUidValidity;
-}
-
-uint32_t IMAPFolderStatusOperation::messageCount()
-{
- return mMessageCount;
-}
-
-uint32_t IMAPFolderStatusOperation::recentCount()
-{
- return mRecentCount;
-}
-
-uint32_t IMAPFolderStatusOperation::unseenCount()
-{
- return mUnseenCount;
+ MC_SAFE_RELEASE(mStatus);
}
void IMAPFolderStatusOperation::main()
@@ -68,13 +40,12 @@ void IMAPFolderStatusOperation::main()
return;
}
-
- mUidNext = status->uidNext();
- mUidValidity = status->uidValidity();
- mMessageCount = status->messageCount();
- mRecentCount = status->recentCount();
- mUnseenCount = status->unseenCount();
-
+ MC_SAFE_REPLACE_RETAIN(IMAPFolderStatus, mStatus, status);
setError(error);
}
+IMAPFolderStatus * IMAPFolderStatusOperation::status()
+{
+ return mStatus;
+}
+
diff --git a/src/async/imap/MCIMAPFolderStatusOperation.h b/src/async/imap/MCIMAPFolderStatusOperation.h
index 71811ca7..d8c30fea 100644
--- a/src/async/imap/MCIMAPFolderStatusOperation.h
+++ b/src/async/imap/MCIMAPFolderStatusOperation.h
@@ -17,27 +17,21 @@
namespace mailcore {
+ class IMAPFolderStatus;
+
class IMAPFolderStatusOperation : public IMAPOperation {
public:
IMAPFolderStatusOperation();
virtual ~IMAPFolderStatusOperation();
- virtual uint32_t uidNext();
- virtual uint32_t uidValidity();
- virtual uint32_t messageCount();
- virtual uint32_t recentCount();
- virtual uint32_t unseenCount();
+ // Results.
+ virtual IMAPFolderStatus * status();
public: // subclass behavior
virtual void main();
private:
-
- uint32_t mUidNext;
- uint32_t mUidValidity;
- uint32_t mMessageCount;
- uint32_t mRecentCount;
- uint32_t mUnseenCount;
+ IMAPFolderStatus * mStatus;
};
}
diff --git a/src/core/imap/MCIMAPFolderStatus.cc b/src/core/imap/MCIMAPFolderStatus.cc
index 7b6a8bbd..4b75c1ae 100644
--- a/src/core/imap/MCIMAPFolderStatus.cc
+++ b/src/core/imap/MCIMAPFolderStatus.cc
@@ -36,7 +36,8 @@ IMAPFolderStatus::IMAPFolderStatus(IMAPFolderStatus * other)
}
IMAPFolderStatus::~IMAPFolderStatus()
-{ }
+{
+}
Object * IMAPFolderStatus::copy()
{
@@ -92,3 +93,17 @@ u_int32_t IMAPFolderStatus::uidValidity()
{
return mUidValidity;
}
+
+String * IMAPFolderStatus::description()
+{
+ String * result = String::string();
+ result->appendUTF8Format("<%s:%p msg_count: %u, unseen_count: %u, recent_count: %u, uid_next: %u, uid_validity: %u>",
+ className()->UTF8Characters(),
+ this,
+ (unsigned int) messageCount(),
+ (unsigned int) unseenCount(),
+ (unsigned int) recentCount(),
+ (unsigned int) uidNext(),
+ (unsigned int) uidValidity());
+ return result;
+}
diff --git a/src/core/imap/MCIMAPFolderStatus.h b/src/core/imap/MCIMAPFolderStatus.h
index 818cd790..2343c5d5 100644
--- a/src/core/imap/MCIMAPFolderStatus.h
+++ b/src/core/imap/MCIMAPFolderStatus.h
@@ -41,6 +41,7 @@ namespace mailcore {
public: // subclass behavior
IMAPFolderStatus(IMAPFolderStatus * other);
virtual Object * copy();
+ virtual String * description();
private:
u_int32_t mUnseenCount;
diff --git a/src/objc/imap/MCOIMAPFolderStatus.h b/src/objc/imap/MCOIMAPFolderStatus.h
index fd6a566f..3d64f009 100644
--- a/src/objc/imap/MCOIMAPFolderStatus.h
+++ b/src/objc/imap/MCOIMAPFolderStatus.h
@@ -16,9 +16,6 @@
@interface MCOIMAPFolderStatus : NSObject <NSCopying>
-/** Create an empty instance */
-+ (MCOIMAPFolderStatus *) status;
-
/** The folder's IMAP UIDNEXT value. Used to determine the uid for the next received message. */
@property (nonatomic, assign) uint32_t uidNext;
diff --git a/src/objc/imap/MCOIMAPFolderStatus.mm b/src/objc/imap/MCOIMAPFolderStatus.mm
index 22bc8456..dc018688 100644
--- a/src/objc/imap/MCOIMAPFolderStatus.mm
+++ b/src/objc/imap/MCOIMAPFolderStatus.mm
@@ -17,10 +17,9 @@
mailcore::IMAPFolderStatus *_folderStatus;
}
-+ (MCOIMAPFolderStatus *) status
++ (void) load
{
- mailcore::IMAPFolderStatus folderStatus = new mailcore::IMAPFolderStatus();
- return [[[MCOIMAPFolderStatus alloc] init] autorelease];
+ MCORegisterClass(self, &typeid(nativeType));
}
- (id) initWithMCFolderStatus:(mailcore::IMAPFolderStatus *)status
@@ -33,12 +32,23 @@
return self;
}
+- (void) dealloc
+{
+ MC_SAFE_RELEASE(_folderStatus);
+ [super dealloc];
+}
+
+ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
{
mailcore::IMAPFolderStatus * status = (mailcore::IMAPFolderStatus *) object;
return [[[self alloc] initWithMCFolderStatus:status] autorelease];
}
+- (mailcore::Object *) mco_mcObject
+{
+ return _folderStatus;
+}
+
- (id) copyWithZone:(NSZone *)zone
{
nativeType * nativeObject = (nativeType *) [self mco_mcObject]->copy();
@@ -47,16 +57,15 @@
return [result retain];
}
+- (NSString *) description
+{
+ return MCO_OBJC_BRIDGE_GET(description);
+}
+
MCO_OBJC_SYNTHESIZE_SCALAR(uint32_t, uint32_t, setUnseenCount, unseenCount)
MCO_OBJC_SYNTHESIZE_SCALAR(uint32_t, uint32_t, setMessageCount, messageCount)
MCO_OBJC_SYNTHESIZE_SCALAR(uint32_t, uint32_t, setRecentCount, recentCount)
MCO_OBJC_SYNTHESIZE_SCALAR(uint32_t, uint32_t, setUidNext, uidNext)
MCO_OBJC_SYNTHESIZE_SCALAR(uint32_t, uint32_t, setUidValidity, uidValidity)
-- (void) dealloc
-{
- _folderStatus->release();
- [super dealloc];
-}
-
@end
diff --git a/src/objc/imap/MCOIMAPFolderStatusOperation.mm b/src/objc/imap/MCOIMAPFolderStatusOperation.mm
index f4d82476..c7f5370c 100644
--- a/src/objc/imap/MCOIMAPFolderStatusOperation.mm
+++ b/src/objc/imap/MCOIMAPFolderStatusOperation.mm
@@ -50,8 +50,7 @@ typedef void (^CompletionType)(NSError *error, MCOIMAPFolderStatus *status);
nativeType *op = MCO_NATIVE_INSTANCE;
if (op->error() == mailcore::ErrorNone) {
- MCOIMAPFolderStatus * status = [MCOIMAPFolderStatus mco_objectWithMCObject:op];
-
+ MCOIMAPFolderStatus * status = MCO_TO_OBJC(op->status());
_completionBlock(nil, status);
} else {
_completionBlock([NSError mco_errorWithErrorCode:op->error()], nil);