Esempio n. 1
0
 def run(self):
     try:
         user = foursquare.get_user(self.userId, foursquare.ForceFetch)
         photo = user['user']['photo']
         foursquare.image(photo)
         self.__parent.hideWaitingDialog.emit()
         self.__parent.showUser.emit()
     except IOError:
         self.__parent.hideWaitingDialog.emit()
         self.__parent.networkError.emit()
     self.exec_()
     self.exit(0)
Esempio n. 2
0
 def run(self):
     try:
         venue = foursquare.venues_venue(self.venueId, foursquare.ForceFetch)
         if 'mayor' in venue:
             if 'user' in venue['mayor']:
                 print "there's a mayor!"
                 foursquare.image(venue['mayor']['user']['photo'])
         self.__parent.hideWaitingDialog.emit()
         # This tiny sleep in necesary to (a) Avoid an Xorg warning, (b) achieve a smoother transition
         time.sleep(0.15)
         self.__parent.showMoreInfo.emit()
     except IOError:
         self.__parent.hideWaitingDialog.emit()
         self.__parent.networkError.emit()
     self.exec_()
     self.exit(0)
Esempio n. 3
0
    def __updateInfo(self, initial=False):
        if not initial:
            self.user = foursquare.get_user("self", foursquare.CacheOrGet)['user']
        if self.manualUpdate:
            QMaemo5InformationBox.information(self, "Stats updated!", 1500)
            self.manualUpdate = False

        badges = "<b>" + str(self.user['badges']['count']) + "</b> badges"
        mayorships = "<b>" + str(self.user['mayorships']['count']) + "</b> mayorships"
        checkins = "<b>" + str(self.user['checkins']['count']) + "</b> checkins"

        if 'items' in self.user['checkins']:
            location = self.user['checkins']['items'][0]['venue']['name']
            lastSeen = self.user['checkins']['items'][0]['createdAt']
            lastSeen = datetime.fromtimestamp(lastSeen).strftime("%Y-%m-%d %X")
            location = "Last seen @" + location # + "</b>, at <i>" + lastSeen + "</i>"
        else:
            location = "Never checked in anywhere!"


        text = location + "<br>" + badges + " | " + mayorships + " | " + checkins
        self.textLabel.setText(text)

        self.photo = QImage(foursquare.image(self.user['photo']))
        self.photo_label.setPixmap(QPixmap(self.photo))
Esempio n. 4
0
	def data(self, index, role=Qt.DisplayRole):
		venue = self.venues[index.row()]['venue']
		if role == Qt.DisplayRole:
			name = venue['name']
			if len(name) > 72:
				name = name[0:70]
			address = "(no address)"
			if 'address' in venue['location']:
				address = venue['location']['address']
				if len(address) > 72:
					address = address[0:70]
			distance = ""
			if 'distance' in venue['location']:
				distance = " (" + str(venue['location']['distance']) + " metres away)"
			return name + "\n  " + address + distance
		elif role == Qt.DecorationRole:
			if len(venue['categories']) > 0:
				prefix = venue['categories'][0]['icon']['prefix']
				extension = venue['categories'][0]['icon']['name']
				image_url = prefix + "64" + extension
			else:
				image_url = "https://foursquare.com/img/categories/none_64.png"
			return QIcon(foursquare.image(image_url))
			
		elif role == VenueListModel.VenueRole:
			return venue
Esempio n. 5
0
    def __init__(self, user, parent=None):
        super(UserProfile, self).__init__(parent)

        name = user['user']['firstName']
        if 'lastName' in user['user']:
            name += " " + user['user']['lastName']

        description = ""
        if 'homeCity' in user['user']:
            description += "From " + user['user']['homeCity']

        location = ""
        # FIXME: this may fail!
        location = user['user']['checkins']['items'][0]['venue']['name']
        lastSeen = user['user']['checkins']['items'][0]['createdAt']
        lastSeen = datetime.fromtimestamp(lastSeen).strftime("%d %b, %H:%M")
        location = "Last seen at <b>" +  location + "</b>, at <i>" + lastSeen + "</i>"

        description = description + "<br>" + location

        self.descriptionLabel = QLabel(description)
        self.descriptionLabel.setWordWrap(True)

        self.photo_label = QLabel()
        self.photo = QImage(foursquare.image(user['user']['photo']))
        self.photo_label.setPixmap(QPixmap(self.photo))

        profileLayout = QGridLayout()
        self.setLayout(profileLayout)

        profileLayout.addWidget(self.photo_label, 0, 0, 2, 1)
        profileLayout.addWidget(Title(name), 0, 1)
        profileLayout.addWidget(self.descriptionLabel, 1, 1)

        profileLayout.setColumnStretch(1, 5)
Esempio n. 6
0
	def data(self, index, role=Qt.DisplayRole):
		if role == Qt.DisplayRole:
			return self.categories[index.row()]['name']
		elif role == Qt.DecorationRole:
			prefix = self.categories[index.row()]['icon']['prefix']
			extension = self.categories[index.row()]['icon']['name']
			return QIcon(foursquare.image(prefix + "64" + extension))
		elif role == CategoryModel.CategoryRole:
			return self.categories[index.row()]
		elif role == CategoryModel.SubCategoriesRole:
			return self.categories[index.row()]['categories']
Esempio n. 7
0
 def data(self, index, role=Qt.DisplayRole):
     user = self.users[index.row()]['user']
     if role == Qt.DisplayRole:
         text = user['firstName']
         if 'lastName' in user:
             text += " " + user['lastName']
         score = self.users[index.row()]['scores']
         text += "\n  " + str(score['recent']) + "/" + str(score['max']) + " (" + str(score['checkinsCount']) + " checkins" + ")"
         return text
     elif role == Qt.DecorationRole:
         return QIcon(foursquare.image(user['photo']))
     elif role == UserListModel.UserRole:
         return self.users[index.row()]
Esempio n. 8
0
	def __init__(self, parent, venue, fullDetails):
		super(VenueDetailsWindow, self).__init__(parent)
		self.venue = venue

		self.fullDetails = fullDetails

		self.setWindowTitle(venue['name'])

		self.centralWidget = QWidget()
		self.setCentralWidget(self.centralWidget)

		layout = QVBoxLayout()
		layout.setSpacing(0)
		layout.setContentsMargins(11, 11, 11, 11)
		self.centralWidget.setLayout(layout)

		self.container = QWidget()

		self.scrollArea = QScrollArea()
		self.scrollArea.setWidget(self.container)
		self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

		layout.addWidget(self.scrollArea)

		self.scrollArea.setWidgetResizable(True)

		gridLayout = QGridLayout()
		self.container.setLayout(gridLayout)

		# name
		name = venue['name']
		if len(venue['categories']) > 0:
			name += " (" + venue['categories'][0]['name'] + ")"

		# address
		address = ""
		if 'address' in venue['location']:
			address = venue['location']['address']

		if 'crossStreet' in venue['location']:
			if address != "":
				address += ", "
			address += venue['location']['crossStreet']

		# address2
		address2 = ""
		if 'postalCode' in venue['location']:
			address2 = venue['location']['postalCode']

		if 'city' in venue['location']:
			if address2 != "":
				address2 += ", "
			address2 += venue['location']['city']

		# times
		if 'beenHere' in venue:
			if isinstance(venue['beenHere'], int):
				count = venue['beenHere']
			else:
				count = venue['beenHere']['count']
			times = "<b>You've been here "
			if count == 1:
				times += "once"
			else:
				times += str(count) + " times"
			times += "</b>"
		else:
			times = "<b>You've never been here</b>"

		checkin_button = QPushButton("Check-in")
		self.connect(checkin_button, SIGNAL("clicked()"), self.checkin)

		self.checkinDone = Signal()
		self.connect(self, SIGNAL("checkinDone(str)"), self.__checkinDone)

		i = 0
		gridLayout.addWidget(checkin_button, i, 1)
		self.shoutText = QLineEdit(self)
		self.shoutText.setPlaceholderText("Shout something")
		gridLayout.addWidget(self.shoutText, i, 0)
		i += 1
		gridLayout.addWidget(Title(name, self), i, 0, 1, 2)
		i += 1
		gridLayout.addWidget(QLabel(address, self), i, 0, 1, 2)
		i += 1
		gridLayout.addWidget(QLabel(address2, self), i, 0, 1, 2)
		for item in venue['categories']:
			if 'primary' in item and item['primary'] == "true":
				i += 1
				gridLayout.addWidget(QLabel(item['name'], self), i, 0, 1, 2)
		i += 1
		gridLayout.addWidget(Ruler(), i, 0, 1, 2)

		if 'description' in venue:
			i += 1
			description_label = QLabel(venue['description'])
			description_label.setWordWrap(True)
			gridLayout.addWidget(description_label, i, 0, 1, 2)
			i += 1
			gridLayout.addWidget(Ruler(), i, 0, 1, 2)

		i += 1
		gridLayout.addWidget(QLabel(times, self), i, 0)
		i += 1
		gridLayout.addWidget(QLabel("Total Checkins: " + str(venue['stats']['checkinsCount']), self), i, 0)
		i += 1
		gridLayout.addWidget(QLabel("Total Visitors: " + str(venue['stats']['usersCount']), self), i, 0)

		if 'hereNow' in venue:
			hereNow = venue['hereNow']['count']
			if hereNow == 0:
				hereNow = "There's no one here now."
			elif hereNow == 1:
				hereNow = "There's just one person here now."
			else:
				hereNow = "There are " + repr(hereNow) + " people here now."
			i += 1
			gridLayout.addWidget(QLabel(hereNow, self), i, 0)

		if 'phone' in venue['contact']:
			i += 1
			phoneCallButton = QPushButton("Call (" + venue['contact']['formattedPhone'] + ")")
			phoneCallButton.setIcon(QIcon.fromTheme("general_call"))
			self.connect(phoneCallButton, SIGNAL("clicked()"), self.startPhoneCall)
			gridLayout.addWidget(phoneCallButton, i, 0, 1, 2)

		if 'url' in venue:
			i += 1
			websiteButton = QPushButton("Visit Website")
			websiteButton.setIcon(QIcon.fromTheme("general_web"))
			self.connect(websiteButton, SIGNAL("clicked()"), self.openUrl)
			gridLayout.addWidget(websiteButton, i, 0, 1, 2)

		if 'mayor' in venue:
			if 'user' in venue['mayor']:
				mayorName = venue['mayor']['user']['firstName']
				mayorCount = venue['mayor']['count']
				mayorText = mayorName + " is the mayor with " + str(mayorCount) + " checkins!"
				mayorButton = QPushButton()
				mayorButton.setText(mayorText)
				mayorButton.setIcon(QIcon(foursquare.image(venue['mayor']['user']['photo'])))
			else:
				mayorButton = QLabel("This venue has no mayor")
			i += 1
			gridLayout.addWidget(mayorButton, i, 0, 1, 2)

		# TODO: menu
		# TODO: specials

		if 'tips' in venue:
			i += 1
			if venue['tips']['count'] == 0:
				gridLayout.addWidget(QLabel("<b>There isn't a single tip!</b>", self), i, 0)
			else:
				if venue['tips']['count'] == 1:
					gridLayout.addWidget(QLabel("<b>Just one tip</b>", self), i, 0)
				else:
					gridLayout.addWidget(QLabel("<b>" + str(venue['tips']['count']) + " tips</b>", self), i, 0)
				for group in venue['tips']['groups']:
					for tip in group['items']:
						i += 1
						gridLayout.addWidget(Tip(tip), i, 0, 1, 2)
						i += 1
						line = QFrame()
						line.setFrameShape(QFrame.HLine)
						line.setMaximumWidth(QApplication.desktop().screenGeometry().width() * 0.5)
						gridLayout.addWidget(line, i, 0, 1, 2)

			i += 1
			gridLayout.addWidget(NewTipWidget(venue['id'], self), i, 0, 1, 2)

		if not fullDetails:
			info_button_label = "Fetch full details"
		else:
			info_button_label = "Refresh venue details"
		more_info_button = QPushButton(info_button_label)
		more_info_button.setIcon(QIcon.fromTheme("general_refresh"))
		self.connect(more_info_button, SIGNAL("clicked()"), self.more_info)

		i += 1
		gridLayout.addWidget(more_info_button, i, 0, 1, 2)

		showMoreInfo = Signal()
		self.connect(self, SIGNAL("showMoreInfo()"), self.more_info)
Esempio n. 9
0
    def __init__(self, user, parent):
        super(UserDetailsWindow, self).__init__(parent)

        self.user = user

        self.centralWidget = QWidget()
        self.setCentralWidget(self.centralWidget)

        layout = QVBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(11, 11, 11, 11)
        self.centralWidget.setLayout(layout)

        self.container = QWidget()
        self.scrollArea = QScrollArea()
        self.scrollArea.setWidget(self.container)
        self.scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        layout.addWidget(self.scrollArea)
        self.scrollArea.setWidgetResizable(True)

        gridLayout = QGridLayout()
        self.container.setLayout(gridLayout)

        firstName = user['user']['firstName']
        name = firstName
        if 'lastName' in user['user']:
            name += " " + user['user']['lastName']
        self.setWindowTitle(name)

        photo_label = QLabel()
        photo = QImage(foursquare.image(self.user['user']['photo']))
        photo_label.setPixmap(QPixmap(photo))

        i = 0
        gridLayout.addWidget(UserProfile(user), i, 0, 1, 2)

        ### checkin button
        if user['user']['relationship'] != "self":
            i += 1
            self.shoutText = QLineEdit(self)
            self.shoutText.setPlaceholderText("Shout something")
            gridLayout.addWidget(self.shoutText, i, 0)

            checkinButton = QPushButton("Check-in with " + firstName)
            self.connect(checkinButton, SIGNAL("clicked()"), self.checkin)
            gridLayout.addWidget(checkinButton, i, 1)

        # TODO!
        #if user['user']['relationship'] == "friend":
        #    i += 1
        #    gridLayout.addWidget(QLabel("TODO: Unfriend"), i, 0, 1, 2)
        elif user['user']['relationship'] == "self":
            i += 1
            gridLayout.addWidget(QLabel("It's you!"), i, 0, 1, 2)
        if user['user']['id'] == "17270875":
            i += 1
            gridLayout.addWidget(QLabel("<b>This is the UberSquare developer!</b>"), i, 0, 1, 2)

        i += 1
        checkins = user['user']['checkins']['count']
        gridLayout.addWidget(QLabel(str(checkins) + " checkins"), i, 0)
        i += 1
        badges = user['user']['badges']['count']
        gridLayout.addWidget(QLabel(str(badges) + " badges"), i, 0)
        i += 1
        mayorships = user['user']['mayorships']['count']
        if mayorships > 0:
            mayorshipsButton = QPushButton(str(mayorships) + " mayorships")
            mayorshipsButton.setIcon(QIcon(foursquare.image("https://foursquare.com/img/points/mayor.png")))
            self.connect(mayorshipsButton, SIGNAL("clicked()"), self.mayorships_pushed)
            gridLayout.addWidget(mayorshipsButton, i, 0, 1, 2)
        else:
            gridLayout.addWidget(QLabel("No mayorships"), i, 0)
        i += 1

        # TODO!
        #gridLayout.addWidget(QPushButton("TODO: See places " + firstName + " has been to."), i, 0, 1, 2)
        #i += 1

        update_user_button = QPushButton("Refresh user details")
        update_user_button.setIcon(QIcon.fromTheme("general_refresh"))
        self.connect(update_user_button, SIGNAL("clicked()"), self.__update)
        gridLayout.addWidget(update_user_button, i, 0, 1, 2)

        showUser = Signal()
        self.connect(self, SIGNAL("showUser()"), self.__showUser)